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 #include "render/rs_dot_matrix_shader.h"
16 #include "platform/common/rs_log.h"
17 #include "ge_visual_effect_impl.h"
18
19 namespace OHOS {
20 namespace Rosen {
21
RSDotMatrixShader()22 RSDotMatrixShader::RSDotMatrixShader()
23 {
24 type_ = ShaderType::DOT_MATRIX;
25 }
26
RSDotMatrixShader(Drawing::Color dotColor,float dotSpacing,float dotRadius,Drawing::Color bgColor)27 RSDotMatrixShader::RSDotMatrixShader(Drawing::Color dotColor, float dotSpacing, float dotRadius, Drawing::Color bgColor)
28 {
29 DotMatrixNormalParams normalParams {dotColor, dotSpacing, dotRadius, bgColor};
30 if (params_) {
31 params_->normalParams_ = normalParams;
32 }
33 type_ = ShaderType::DOT_MATRIX;
34 }
35
MakeDrawingShader(const RectF & rect,float progress)36 void RSDotMatrixShader::MakeDrawingShader(const RectF& rect, float progress)
37 {
38 Drawing::Rect drawingRect = Drawing::Rect(rect.GetLeft(), rect.GetTop(), rect.GetRight(), rect.GetBottom());
39 if (geShader_) {
40 geShader_->MakeDrawingShader(drawingRect, progress);
41 }
42 }
43
GetDrawingShader() const44 const std::shared_ptr<Drawing::ShaderEffect>& RSDotMatrixShader::GetDrawingShader() const
45 {
46 if (geShader_) {
47 return geShader_->GetDrawingShader();
48 }
49 return RSShader::GetDrawingShader();
50 }
51
SetNormalParams(Drawing::Color dotColor,float dotSpacing,float dotRadius,Drawing::Color bgColor)52 void RSDotMatrixShader::SetNormalParams(Drawing::Color dotColor, float dotSpacing, float dotRadius,
53 Drawing::Color bgColor)
54 {
55 DotMatrixNormalParams normalParams {dotColor, dotSpacing, dotRadius, bgColor};
56 if (params_) {
57 params_->normalParams_ = normalParams;
58 }
59 }
60
SetNoneEffect()61 void RSDotMatrixShader::SetNoneEffect()
62 {
63 if (params_) {
64 params_->effectType_ = DotMatrixEffectType::NONE;
65 }
66 }
SetRotateEffect(const RotateEffectParams & rotateParams)67 void RSDotMatrixShader::SetRotateEffect(const RotateEffectParams& rotateParams)
68 {
69 if (params_) {
70 params_->rotateEffectParams_ = rotateParams;
71 params_->effectType_ = DotMatrixEffectType::ROTATE;
72 }
73 }
74
SetRippleEffect(const RippleEffectParams & rippleParams)75 void RSDotMatrixShader::SetRippleEffect(const RippleEffectParams& rippleParams)
76 {
77 if (params_) {
78 params_->rippleEffectParams_ = rippleParams;
79 params_->effectType_ = DotMatrixEffectType::RIPPLE;
80 }
81 }
82
Marshalling(Parcel & parcel)83 bool RSDotMatrixShader::Marshalling(Parcel& parcel)
84 {
85 if (!params_) {
86 return false;
87 }
88
89 return params_->Marshalling(parcel);
90 }
91
Unmarshalling(Parcel & parcel,bool & needReset)92 bool RSDotMatrixShader::Unmarshalling(Parcel& parcel, bool& needReset)
93 {
94 needReset = false;
95 params_ = std::make_shared<DotMatrixShaderParams>();
96 if (!params_) {
97 return false;
98 }
99
100 if (!params_->Unmarshalling(parcel)) {
101 ROSEN_LOGE("unirender: RSDotMatrixShader::Unmarshalling failed");
102 return false;
103 }
104
105 geShader_ = GEXDotMatrixShader::CreateDynamicImpl(params_->normalParams_);
106 if (!geShader_) {
107 ROSEN_LOGE("unirender: RSDotMatrixShader::Unmarshalling CreateDynamicImpl failed");
108 return false;
109 }
110 if (params_->effectType_ == DotMatrixEffectType::ROTATE) {
111 geShader_->SetRotateEffect(params_->rotateEffectParams_);
112 } else if (params_->effectType_ == DotMatrixEffectType::RIPPLE) {
113 geShader_->SetRippleEffect(params_->rippleEffectParams_);
114 }
115 return true;
116 }
117
118 } // namespace Rosen
119 } // namespace OHOS