1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "render/rs_flow_light_sweep_shader.h"
17 #include "platform/common/rs_log.h"
18 #include "ge_visual_effect_impl.h"
19
20 namespace OHOS {
21 namespace Rosen {
22
RSFlowLightSweepShader(const std::vector<std::pair<Drawing::Color,float>> & effectColors)23 RSFlowLightSweepShader::RSFlowLightSweepShader(const std::vector<std::pair<Drawing::Color, float>>& effectColors)
24 {
25 params_->effectColors_ = effectColors;
26 type_ = ShaderType::FLOW_LIGHT_SWEEP;
27 }
28
MakeDrawingShader(const RectF & rect,float progress)29 void RSFlowLightSweepShader::MakeDrawingShader(const RectF& rect, float progress)
30 {
31 Drawing::Rect drawingRect = Drawing::Rect(rect.GetLeft(), rect.GetTop(), rect.GetRight(), rect.GetBottom());
32 if (geShader_) {
33 geShader_->MakeDrawingShader(drawingRect, progress);
34 }
35 type_ = ShaderType::FLOW_LIGHT_SWEEP;
36 }
37
GetDrawingShader() const38 const std::shared_ptr<Drawing::ShaderEffect>& RSFlowLightSweepShader::GetDrawingShader() const
39 {
40 if (geShader_) {
41 return geShader_->GetDrawingShader();
42 }
43 return RSShader::GetDrawingShader();
44 }
45
Marshalling(Parcel & parcel)46 bool RSFlowLightSweepShader::Marshalling(Parcel& parcel)
47 {
48 if (!params_) {
49 return false;
50 }
51
52 return params_->Marshalling(parcel);
53 }
54
Unmarshalling(Parcel & parcel,bool & needReset)55 bool RSFlowLightSweepShader::Unmarshalling(Parcel& parcel, bool& needReset)
56 {
57 needReset = false;
58 params_ = std::make_shared<GEXFlowLightSweepParams>();
59 if (!params_) {
60 return false;
61 }
62 if (!params_->Unmarshalling(parcel)) {
63 ROSEN_LOGD("RSFlowLightSweepShader::Unmarshalling failed");
64 return false;
65 }
66
67 geShader_ = GEXFlowLightSweepShader::CreateDynamicImpl(params_->effectColors_);
68 if (!geShader_) {
69 ROSEN_LOGD("RSFlowLightSweepShader::Unmarshalling CreateDynamicImpl failed");
70 return false;
71 }
72
73 return true;
74 }
75
76 } // namespace Rosen
77 } // namespace OHOS
78