• 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 
20 namespace OHOS {
21 namespace Rosen {
22 
23 constexpr uint32_t MARSHALLING_SIZE_MAX_LIMIT = 100;  // 100 max length
24 
Marshalling(Parcel & parcel)25 bool RotateEffectParams::Marshalling(Parcel& parcel)
26 {
27     if (!parcel.WriteUint32((uint32_t)pathDirection_)) {
28         return false;
29     }
30     auto size = (uint32_t)effectColors_.size();
31     if (size > MARSHALLING_SIZE_MAX_LIMIT) {
32         GE_LOGE("RotateEffectParams::Marshalling effectColors size exceeded the limit.");
33         return false;
34     }
35     if (!parcel.WriteUint32(size)) {
36         return false;
37     }
38     for (auto color : effectColors_) {
39         if (!parcel.WriteUint32((uint32_t)color.CastToColorQuad())) {
40             return false;
41         }
42     }
43     return true;
44 }
45 
Unmarshalling(Parcel & parcel)46 bool RotateEffectParams::Unmarshalling(Parcel& parcel)
47 {
48     uint32_t valueUint32 = 0;
49     if (!parcel.ReadUint32(valueUint32)) {
50         return false;
51     }
52     pathDirection_ = static_cast<DotMatrixDirection>(valueUint32);
53     uint32_t size = 0;
54     if (!parcel.ReadUint32(size)) {
55         return false;
56     }
57     if (size > MARSHALLING_SIZE_MAX_LIMIT) {
58         GE_LOGE("RotateEffectParams::Unmarshalling effectColors size exceeded the limit.");
59         return false;
60     }
61     effectColors_.clear();
62     for (uint32_t i = 0; i < size; i++) {
63         if (!parcel.ReadUint32(valueUint32)) {
64             return false;
65         }
66         effectColors_.emplace_back(Drawing::Color(valueUint32));
67     }
68     return true;
69 }
70 
Marshalling(Parcel & parcel)71 bool RippleEffectParams::Marshalling(Parcel& parcel)
72 {
73     auto size = (uint32_t)effectColors_.size();
74     if (size > MARSHALLING_SIZE_MAX_LIMIT) {
75         GE_LOGE("RippleEffectParams::Marshalling effectColors size exceeded the limit.");
76         return false;
77     }
78     if (!parcel.WriteUint32(size)) {
79         return false;
80     }
81     for (auto color : effectColors_) {
82         if (!parcel.WriteUint32((uint32_t)color.CastToColorQuad())) {
83             return false;
84         }
85     }
86 
87     size = (uint32_t)colorFractions_.size();
88     if (size > MARSHALLING_SIZE_MAX_LIMIT) {
89         GE_LOGE("RippleEffectParams::Marshalling colorFractions size exceeded the limit.");
90         return false;
91     }
92     if (!parcel.WriteUint32(size)) {
93         return false;
94     }
95     for (auto colorFraction : colorFractions_) {
96         if (!parcel.WriteFloat(colorFraction)) {
97             return false;
98         }
99     }
100 
101     size = startPoints_.size();
102     if (size > MARSHALLING_SIZE_MAX_LIMIT) {
103         GE_LOGE("RippleEffectParams::Marshalling startPoints size exceeded the limit.");
104         return false;
105     }
106     if (!parcel.WriteUint32(size)) {
107         return false;
108     }
109     for (auto startPoint : startPoints_) {
110         if (!parcel.WriteFloat(startPoint.GetX()) || !parcel.WriteFloat(startPoint.GetY())) {
111             return false;
112         }
113     }
114 
115     return parcel.WriteFloat(pathWidth_) && parcel.WriteBool(inverseEffect_);
116 }
117 
Unmarshalling(Parcel & parcel)118 bool RippleEffectParams::Unmarshalling(Parcel& parcel)
119 {
120     uint32_t size = 0;
121     if (!parcel.ReadUint32(size)) {
122         return false;
123     }
124     if (size > MARSHALLING_SIZE_MAX_LIMIT) {
125         GE_LOGE("RippleEffectParams::Unmarshalling effectColors size exceeded the limit.");
126         return false;
127     }
128     uint32_t valueUint32 = 0;
129     effectColors_.clear();
130     for (uint32_t i = 0; i < size; i++) {
131         if (!parcel.ReadUint32(valueUint32)) {
132             return false;
133         }
134         effectColors_.emplace_back(Drawing::Color(valueUint32));
135     }
136 
137     if (!parcel.ReadUint32(size)) {
138         return false;
139     }
140     if (size > MARSHALLING_SIZE_MAX_LIMIT) {
141         GE_LOGE("RippleEffectParams::Unmarshalling colorFractions size exceeded the limit.");
142         return false;
143     }
144     float valueFloat = 0.f;
145     colorFractions_.clear();
146     for (uint32_t i = 0; i < size; i++) {
147         if (!parcel.ReadFloat(valueFloat)) {
148             return false;
149         }
150         colorFractions_.emplace_back(valueFloat);
151     }
152 
153     if (!parcel.ReadUint32(size)) {
154         return false;
155     }
156     if (size > MARSHALLING_SIZE_MAX_LIMIT) {
157         GE_LOGE("RippleEffectParams::Unmarshalling startPoints size exceeded the limit.");
158         return false;
159     }
160     float valueFloatTwo = 0.f;
161     startPoints_.clear();
162     for (uint32_t i = 0; i < size; i++) {
163         if (!parcel.ReadFloat(valueFloat) || !parcel.ReadFloat(valueFloatTwo)) {
164             return false;
165         }
166         startPoints_.emplace_back(Drawing::Point(valueFloat, valueFloatTwo));
167     }
168 
169     return parcel.ReadFloat(pathWidth_) && parcel.ReadBool(inverseEffect_);
170 }
171 
Marshalling(Parcel & parcel)172 bool DotMatrixNormalParams::Marshalling(Parcel& parcel)
173 {
174     if (!parcel.WriteUint32((uint32_t)dotColor_.CastToColorQuad())) {
175         return false;
176     }
177     if (!parcel.WriteFloat(dotSpacing_) || !parcel.WriteFloat(dotRadius_)) {
178         return false;
179     }
180     if (!parcel.WriteUint32(bgColor_.CastToColorQuad())) {
181         return false;
182     }
183     return true;
184 }
185 
Unmarshalling(Parcel & parcel)186 bool DotMatrixNormalParams::Unmarshalling(Parcel& parcel)
187 {
188     uint32_t valueUint32 = 0;
189     uint32_t valueUint32Two = 0;
190     if (!parcel.ReadUint32(valueUint32) || !parcel.ReadFloat(dotSpacing_) || !parcel.ReadFloat(dotRadius_) ||
191         !parcel.ReadUint32(valueUint32Two)) {
192         return false;
193     }
194     dotColor_ = Drawing::Color(valueUint32);
195     bgColor_ = Drawing::Color(valueUint32Two);
196     return true;
197 }
198 
Marshalling(Parcel & parcel)199 bool DotMatrixShaderParams::Marshalling(Parcel& parcel)
200 {
201     if (!normalParams_.Marshalling(parcel) || !parcel.WriteUint32((uint32_t)effectType_)) {
202         return false;
203     }
204 
205     if (effectType_ == DotMatrixEffectType::ROTATE) {
206         return rotateEffectParams_.Marshalling(parcel);
207     }
208 
209     if (effectType_ == DotMatrixEffectType::RIPPLE) {
210         return rippleEffectParams_.Marshalling(parcel);
211     }
212     return true;
213 }
214 
Unmarshalling(Parcel & parcel)215 bool DotMatrixShaderParams::Unmarshalling(Parcel& parcel)
216 {
217     if (!normalParams_.Unmarshalling(parcel)) {
218         return false;
219     }
220 
221     effectType_ = (DotMatrixEffectType)parcel.ReadUint32();
222     if (effectType_ == DotMatrixEffectType::ROTATE) {
223         return rotateEffectParams_.Unmarshalling(parcel);
224     }
225 
226     if (effectType_ == DotMatrixEffectType::RIPPLE) {
227         return rippleEffectParams_.Unmarshalling(parcel);
228     }
229     return true;
230 }
231 
Marshalling(Parcel & parcel)232 bool GEXFlowLightSweepParams::Marshalling(Parcel& parcel)
233 {
234     uint32_t effectColorsSize = static_cast<uint32_t>(effectColors_.size());
235     if (effectColorsSize > MARSHALLING_SIZE_MAX_LIMIT) {
236         GE_LOGE("GEXFlowLightSweepParams::Marshalling effectColors size exceeded the limit.");
237         return false;
238     }
239 
240     if (!parcel.WriteUint32(effectColorsSize)) {
241         return false;
242     }
243 
244     for (size_t i = 0; i < effectColorsSize; i++) {
245         if (!parcel.WriteUint32((uint32_t)effectColors_[i].first.CastToColorQuad())) {
246             return false;
247         }
248         if (!parcel.WriteFloat(effectColors_[i].second)) {
249             return false;
250         }
251     }
252 
253     return true;
254 }
255 
Unmarshalling(Parcel & parcel)256 bool GEXFlowLightSweepParams::Unmarshalling(Parcel& parcel)
257 {
258         uint32_t effectColorsSize = 0;
259         if (!parcel.ReadUint32(effectColorsSize)) {
260             return false;
261         }
262         if (effectColorsSize > MARSHALLING_SIZE_MAX_LIMIT) {
263             GE_LOGE("GEXFlowLightSweepParams::Unmarshalling effectColors size exceeded the limit.");
264             return false;
265         }
266 
267         uint32_t valueUint32 = 0;
268         float valueFloat = 0.f;
269         effectColors_.clear();
270         effectColors_.reserve(effectColorsSize);
271         for (size_t i = 0; i < effectColorsSize; i++) {
272             if (!parcel.ReadUint32(valueUint32) || !parcel.ReadFloat(valueFloat)) {
273                 return false;
274             }
275             std::pair<Drawing::Color, float> effectColor;
276             effectColor.first = Drawing::Color(valueUint32);
277             effectColor.second = valueFloat;
278 
279             effectColors_.emplace_back(effectColor);
280         }
281 
282         return true;
283 }
284 } // namespace Rosen
285 } // namespace OHOS
286