• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "ge_log.h"
17 #include "ext/gex_dot_matrix_shader.h"
18 #include "ext/gex_flow_light_sweep_shader.h"
19 #include "ext/gex_complex_shader.h"
20 #include "transaction/rs_marshalling_helper.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 
25 constexpr uint32_t MARSHALLING_SIZE_MAX_LIMIT = 100;  // 100 max length
26 
Marshalling(Parcel & parcel)27 bool RotateEffectParams::Marshalling(Parcel& parcel)
28 {
29     if (!parcel.WriteUint32((uint32_t)pathDirection_)) {
30         GE_LOGE("RotateEffectParams::Marshalling Write pathDirection failed!");
31         return false;
32     }
33     auto size = (uint32_t)effectColors_.size();
34     if (size > MARSHALLING_SIZE_MAX_LIMIT) {
35         GE_LOGE("RotateEffectParams::Marshalling effectColors size exceeded the limit.");
36         return false;
37     }
38     if (!parcel.WriteUint32(size)) {
39         GE_LOGE("RotateEffectParams::Marshalling Write size failed!");
40         return false;
41     }
42     for (auto color : effectColors_) {
43         if (!parcel.WriteUint32((uint32_t)color.CastToColorQuad())) {
44             GE_LOGE("RotateEffectParams::Marshalling Write color failed!");
45             return false;
46         }
47     }
48     return true;
49 }
50 
Unmarshalling(Parcel & parcel)51 bool RotateEffectParams::Unmarshalling(Parcel& parcel)
52 {
53     uint32_t valueUint32 = 0;
54     if (!parcel.ReadUint32(valueUint32)) {
55         GE_LOGE("RotateEffectParams::Unmarshalling Read pathDirection failed!");
56         return false;
57     }
58     pathDirection_ = static_cast<DotMatrixDirection>(valueUint32);
59     uint32_t size = 0;
60     if (!parcel.ReadUint32(size)) {
61         GE_LOGE("RotateEffectParams::Unmarshalling Read size failed!");
62         return false;
63     }
64     if (size > MARSHALLING_SIZE_MAX_LIMIT) {
65         GE_LOGE("RotateEffectParams::Unmarshalling effectColors size exceeded the limit.");
66         return false;
67     }
68     effectColors_.clear();
69     for (uint32_t i = 0; i < size; i++) {
70         if (!parcel.ReadUint32(valueUint32)) {
71             GE_LOGE("RotateEffectParams::Unmarshalling Read effectColors failed!");
72             return false;
73         }
74         effectColors_.emplace_back(Drawing::Color(valueUint32));
75     }
76     return true;
77 }
78 
Marshalling(Parcel & parcel)79 bool RippleEffectParams::Marshalling(Parcel& parcel)
80 {
81     auto size = (uint32_t)effectColors_.size();
82     if (size > MARSHALLING_SIZE_MAX_LIMIT) {
83         GE_LOGE("RippleEffectParams::Marshalling effectColors size exceeded the limit.");
84         return false;
85     }
86     if (!parcel.WriteUint32(size)) {
87         GE_LOGE("RippleEffectParams::Marshalling Write effectColorsSize failed!");
88         return false;
89     }
90     for (auto color : effectColors_) {
91         if (!parcel.WriteUint32((uint32_t)color.CastToColorQuad())) {
92             GE_LOGE("RippleEffectParams::Marshalling Write effectColors failed!");
93             return false;
94         }
95     }
96 
97     size = (uint32_t)colorFractions_.size();
98     if (size > MARSHALLING_SIZE_MAX_LIMIT) {
99         GE_LOGE("RippleEffectParams::Marshalling colorFractions size exceeded the limit.");
100         return false;
101     }
102     if (!parcel.WriteUint32(size)) {
103         GE_LOGE("RippleEffectParams::Marshalling Write colorFractionsSize failed!");
104         return false;
105     }
106     for (auto colorFraction : colorFractions_) {
107         if (!parcel.WriteFloat(colorFraction)) {
108             GE_LOGE("RippleEffectParams::Marshalling Write colorFraction failed!");
109             return false;
110         }
111     }
112 
113     size = startPoints_.size();
114     if (size > MARSHALLING_SIZE_MAX_LIMIT) {
115         GE_LOGE("RippleEffectParams::Marshalling startPoints size exceeded the limit.");
116         return false;
117     }
118     if (!parcel.WriteUint32(size)) {
119         GE_LOGE("RippleEffectParams::Marshalling Write startPointsSize failed!");
120         return false;
121     }
122     for (auto startPoint : startPoints_) {
123         if (!parcel.WriteFloat(startPoint.GetX()) || !parcel.WriteFloat(startPoint.GetY())) {
124             GE_LOGE("RippleEffectParams::Marshalling Write startPointX or startPointY failed!");
125             return false;
126         }
127     }
128     bool success = parcel.WriteFloat(pathWidth_) && parcel.WriteBool(inverseEffect_);
129     if (!success) {
130         GE_LOGE("RippleEffectParams::Marshalling Write pathWidth or inverseEffect failed!");
131     }
132     return success;
133 }
134 
Unmarshalling(Parcel & parcel)135 bool RippleEffectParams::Unmarshalling(Parcel& parcel)
136 {
137     uint32_t size = 0;
138     if (!parcel.ReadUint32(size)) {
139         GE_LOGE("RippleEffectParams::Unmarshalling Read size failed!");
140         return false;
141     }
142     if (size > MARSHALLING_SIZE_MAX_LIMIT) {
143         GE_LOGE("RippleEffectParams::Unmarshalling effectColors size exceeded the limit.");
144         return false;
145     }
146     uint32_t valueUint32 = 0;
147     effectColors_.clear();
148     for (uint32_t i = 0; i < size; i++) {
149         if (!parcel.ReadUint32(valueUint32)) {
150             GE_LOGE("RippleEffectParams::Unmarshalling Read effectColors failed!");
151             return false;
152         }
153         effectColors_.emplace_back(Drawing::Color(valueUint32));
154     }
155 
156     if (!parcel.ReadUint32(size)) {
157         GE_LOGE("RippleEffectParams::Unmarshalling Read size failed!");
158         return false;
159     }
160     if (size > MARSHALLING_SIZE_MAX_LIMIT) {
161         GE_LOGE("RippleEffectParams::Unmarshalling colorFractions size exceeded the limit.");
162         return false;
163     }
164     float valueFloat = 0.f;
165     colorFractions_.clear();
166     for (uint32_t i = 0; i < size; i++) {
167         if (!parcel.ReadFloat(valueFloat)) {
168             GE_LOGE("RippleEffectParams::Unmarshalling Read colorFractions failed!");
169             return false;
170         }
171         colorFractions_.emplace_back(valueFloat);
172     }
173 
174     if (!parcel.ReadUint32(size)) {
175         GE_LOGE("RippleEffectParams::Unmarshalling Read startPoints size failed!");
176         return false;
177     }
178     if (size > MARSHALLING_SIZE_MAX_LIMIT) {
179         GE_LOGE("RippleEffectParams::Unmarshalling startPoints size exceeded the limit.");
180         return false;
181     }
182     float valueFloatTwo = 0.f;
183     startPoints_.clear();
184     for (uint32_t i = 0; i < size; i++) {
185         if (!parcel.ReadFloat(valueFloat) || !parcel.ReadFloat(valueFloatTwo)) {
186             GE_LOGE("RippleEffectParams::Unmarshalling Read valueFloat or valueFloatTwo failed!");
187             return false;
188         }
189         startPoints_.emplace_back(Drawing::Point(valueFloat, valueFloatTwo));
190     }
191     bool success = parcel.ReadFloat(pathWidth_) && parcel.ReadBool(inverseEffect_);
192     if (!success) {
193         GE_LOGE("RippleEffectParams::Unmarshalling Read pathWidth or inverseEffect failed!");
194     }
195     return success;
196 }
197 
Marshalling(Parcel & parcel)198 bool DotMatrixNormalParams::Marshalling(Parcel& parcel)
199 {
200     if (!parcel.WriteUint32((uint32_t)dotColor_.CastToColorQuad())) {
201         GE_LOGE("DotMatrixNormalParams::Marshalling Write dotColor failed!");
202         return false;
203     }
204     if (!parcel.WriteFloat(dotSpacing_) || !parcel.WriteFloat(dotRadius_)) {
205         GE_LOGE("DotMatrixNormalParams::Marshalling Write dotSpacing or dotRadius failed!");
206         return false;
207     }
208     if (!parcel.WriteUint32(bgColor_.CastToColorQuad())) {
209         GE_LOGE("DotMatrixNormalParams::Marshalling Write bgColor failed!");
210         return false;
211     }
212     return true;
213 }
214 
Unmarshalling(Parcel & parcel)215 bool DotMatrixNormalParams::Unmarshalling(Parcel& parcel)
216 {
217     uint32_t valueUint32 = 0;
218     uint32_t valueUint32Two = 0;
219     if (!parcel.ReadUint32(valueUint32) || !parcel.ReadFloat(dotSpacing_) || !parcel.ReadFloat(dotRadius_) ||
220         !parcel.ReadUint32(valueUint32Two)) {
221         GE_LOGE("DotMatrixNormalParams::Unmarshalling Read parcel failed!");
222         return false;
223     }
224     dotColor_ = Drawing::Color(valueUint32);
225     bgColor_ = Drawing::Color(valueUint32Two);
226     return true;
227 }
228 
Marshalling(Parcel & parcel)229 bool DotMatrixShaderParams::Marshalling(Parcel& parcel)
230 {
231     if (!normalParams_.Marshalling(parcel) || !parcel.WriteUint32((uint32_t)effectType_)) {
232         GE_LOGE("DotMatrixShaderParams::Marshalling Read effectType failed!");
233         return false;
234     }
235 
236     if (effectType_ == DotMatrixEffectType::ROTATE) {
237         return rotateEffectParams_.Marshalling(parcel);
238     }
239 
240     if (effectType_ == DotMatrixEffectType::RIPPLE) {
241         return rippleEffectParams_.Marshalling(parcel);
242     }
243     return true;
244 }
245 
Unmarshalling(Parcel & parcel)246 bool DotMatrixShaderParams::Unmarshalling(Parcel& parcel)
247 {
248     if (!normalParams_.Unmarshalling(parcel)) {
249         return false;
250     }
251 
252     effectType_ = (DotMatrixEffectType)parcel.ReadUint32();
253     if (effectType_ == DotMatrixEffectType::ROTATE) {
254         return rotateEffectParams_.Unmarshalling(parcel);
255     }
256 
257     if (effectType_ == DotMatrixEffectType::RIPPLE) {
258         return rippleEffectParams_.Unmarshalling(parcel);
259     }
260     return true;
261 }
262 
Marshalling(Parcel & parcel)263 bool GEXFlowLightSweepParams::Marshalling(Parcel& parcel)
264 {
265     uint32_t effectColorsSize = static_cast<uint32_t>(effectColors_.size());
266     if (effectColorsSize > MARSHALLING_SIZE_MAX_LIMIT) {
267         GE_LOGE("GEXFlowLightSweepParams::Marshalling effectColors size exceeded the limit.");
268         return false;
269     }
270 
271     if (!parcel.WriteUint32(effectColorsSize)) {
272         GE_LOGE("GEXFlowLightSweepParams::Marshalling Write effectColorsSize failed!");
273         return false;
274     }
275 
276     for (size_t i = 0; i < effectColorsSize; i++) {
277         if (!parcel.WriteUint32((uint32_t)effectColors_[i].first.CastToColorQuad())) {
278             GE_LOGE("GEXFlowLightSweepParams::Marshalling Write effectColorsFirst failed!");
279             return false;
280         }
281         if (!parcel.WriteFloat(effectColors_[i].second)) {
282             GE_LOGE("GEXFlowLightSweepParams::Marshalling Write effectColorsSecond failed!");
283             return false;
284         }
285     }
286 
287     return true;
288 }
289 
Unmarshalling(Parcel & parcel)290 bool GEXFlowLightSweepParams::Unmarshalling(Parcel& parcel)
291 {
292         uint32_t effectColorsSize = 0;
293         if (!parcel.ReadUint32(effectColorsSize)) {
294             GE_LOGE("GEXFlowLightSweepParams::Unmarshalling Read effectColorsSize failed!");
295             return false;
296         }
297         if (effectColorsSize > MARSHALLING_SIZE_MAX_LIMIT) {
298             GE_LOGE("GEXFlowLightSweepParams::Unmarshalling effectColors size exceeded the limit.");
299             return false;
300         }
301 
302         uint32_t valueUint32 = 0;
303         float valueFloat = 0.f;
304         effectColors_.clear();
305         effectColors_.reserve(effectColorsSize);
306         for (size_t i = 0; i < effectColorsSize; i++) {
307             if (!parcel.ReadUint32(valueUint32) || !parcel.ReadFloat(valueFloat)) {
308                 GE_LOGE("GEXFlowLightSweepParams::Unmarshalling Read effectColor failed!");
309                 return false;
310             }
311             std::pair<Drawing::Color, float> effectColor;
312             effectColor.first = Drawing::Color(valueUint32);
313             effectColor.second = valueFloat;
314 
315             effectColors_.emplace_back(effectColor);
316         }
317 
318         return true;
319 }
320 
Marshalling(Parcel & parcel)321 bool GEXComplexShaderParams::Marshalling(Parcel& parcel)
322 {
323     if (!parcel.WriteUint32(static_cast<uint32_t>(type_))) {
324         return false;
325     }
326 
327     auto paramsSize = static_cast<uint32_t>(params_.size());
328     if (!parcel.WriteUint32(paramsSize)) {
329         return false;
330     }
331 
332     for (const auto &elem : params_) {
333         if (!parcel.WriteFloat(elem)) {
334             return false;
335         }
336     }
337 
338     return true;
339 }
340 
Unmarshalling(Parcel & parcel)341 bool GEXComplexShaderParams::Unmarshalling(Parcel& parcel)
342 {
343     uint32_t typeVal;
344     float floatVal;
345     uint32_t intVal;
346     if (!parcel.ReadUint32(typeVal)) {
347         GE_LOGE("GEXComplexShaderParams::Unmarshalling Read typeVal failed!");
348         return false;
349     }
350     static constexpr uint32_t ValidEnumMin = static_cast<uint32_t>(GexComplexShaderType::NONE);
351     static constexpr uint32_t ValidEnumMax = static_cast<uint32_t>(GexComplexShaderType::MAX);
352     if (typeVal >= ValidEnumMin && typeVal < ValidEnumMax) {
353         if (!parcel.ReadUint32(intVal)) {
354             GE_LOGE("GEXComplexShaderParams::Unmarshalling Read type_ failed!");
355             return false;
356         }
357         type_ = GexComplexShaderType{intVal};
358         if (!parcel.ReadUint32(intVal)) {
359             GE_LOGE("GEXComplexShaderParams::Unmarshalling Read paramsSize failed!");
360             return false;
361         }
362         uint32_t paramsSize = intVal;
363         for (auto i = 0u; i < paramsSize; i++) {
364             if (!parcel.ReadFloat(floatVal)) {
365                 GE_LOGE("GEXComplexShaderParams::Unmarshalling Read float failed!");
366                 return false;
367             }
368             params_.emplace_back(floatVal);
369         }
370         return true;
371     }
372     return false;
373 }
374 } // namespace Rosen
375 } // namespace OHOS
376