1 /*
2  * Copyright (c) 2023 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 "core/interfaces/native/node/render_node_modifier.h"
16 
17 #include <cstdint>
18 #include <optional>
19 
20 #include "base/geometry/dimension.h"
21 #include "base/geometry/ng/rect_t.h"
22 #include "base/geometry/shape.h"
23 #include "base/memory/ace_type.h"
24 #include "base/utils/utils.h"
25 #include "core/components/common/layout/constants.h"
26 #include "core/components/common/properties/color.h"
27 #include "core/components_ng/base/frame_node.h"
28 #include "core/components_ng/base/ui_node.h"
29 #include "core/components_ng/layout/layout_property.h"
30 #include "core/components_ng/pattern/render_node/render_node_pattern.h"
31 #include "core/components_ng/pattern/render_node/render_node_properties.h"
32 #include "core/components_ng/property/border_property.h"
33 #include "core/components_ng/render/render_context.h"
34 #include "core/interfaces/arkoala/arkoala_api.h"
35 
36 namespace OHOS::Ace::NG {
37 namespace {
38 enum class LengthMetricsUnit : int32_t { DEFAULT = 0, PX };
39 
ConvertLengthMetricsUnitToDimensionUnit(int32_t unitValue,DimensionUnit defaultUnit)40 DimensionUnit ConvertLengthMetricsUnitToDimensionUnit(int32_t unitValue, DimensionUnit defaultUnit)
41 {
42     auto lengthMetricsUnit = static_cast<LengthMetricsUnit>(unitValue);
43     switch (lengthMetricsUnit) {
44         case LengthMetricsUnit::PX:
45             return DimensionUnit::PX;
46         default:
47             return defaultUnit;
48     }
49     return defaultUnit;
50 }
51 } // namespace
52 constexpr int TOP_LEFT_X_VALUE = 0;
53 constexpr int TOP_LEFT_Y_VALUE = 1;
54 constexpr int TOP_RIGHT_X_VALUE = 2;
55 constexpr int TOP_RIGHT_Y_VALUE = 3;
56 constexpr int BOTTOM_LEFT_X_VALUE = 4;
57 constexpr int BOTTOM_LEFT_Y_VALUE = 5;
58 constexpr int BOTTOM_RIGHT_X_VALUE = 6;
59 constexpr int BOTTOM_RIGHT_Y_VALUE = 7;
60 constexpr int LEFT_VALUE = 8;
61 constexpr int TOP_VALUE = 9;
62 constexpr int WIDTH_VALUE = 10;
63 constexpr int HEIGHT_VALUE = 11;
64 
GetRenderContext(UINode * node)65 RefPtr<RenderContext> GetRenderContext(UINode* node)
66 {
67     auto* frameNode = AceType::DynamicCast<FrameNode>(node);
68     CHECK_NULL_RETURN(frameNode, nullptr);
69     CHECK_NULL_RETURN(node->GetTag() != "BuilderProxyNode", nullptr);
70     auto context = frameNode->GetRenderContext();
71     return context;
72 }
73 
AppendChild(ArkUINodeHandle node,ArkUINodeHandle child)74 void AppendChild(ArkUINodeHandle node, ArkUINodeHandle child)
75 {
76     auto* currentNode = reinterpret_cast<UINode*>(node);
77     auto* childNode = reinterpret_cast<UINode*>(child);
78     auto childRef = Referenced::Claim<UINode>(childNode);
79     currentNode->AddChild(childRef);
80     currentNode->MarkNeedFrameFlushDirty(NG::PROPERTY_UPDATE_MEASURE);
81 }
82 
InsertChildAfter(ArkUINodeHandle node,ArkUINodeHandle child,ArkUINodeHandle sibling)83 void InsertChildAfter(ArkUINodeHandle node, ArkUINodeHandle child, ArkUINodeHandle sibling)
84 {
85     auto* currentNode = reinterpret_cast<UINode*>(node);
86     auto* childNode = reinterpret_cast<UINode*>(child);
87     auto index = -1;
88     auto* siblingNode = reinterpret_cast<UINode*>(sibling);
89     index = currentNode->GetChildIndex(Referenced::Claim<UINode>(siblingNode));
90     currentNode->AddChild(Referenced::Claim<UINode>(childNode), index + 1);
91     currentNode->MarkNeedFrameFlushDirty(NG::PROPERTY_UPDATE_MEASURE);
92 }
93 
RemoveChild(ArkUINodeHandle node,ArkUINodeHandle child)94 void RemoveChild(ArkUINodeHandle node, ArkUINodeHandle child)
95 {
96     auto* currentNode = reinterpret_cast<UINode*>(node);
97     auto* childNode = reinterpret_cast<UINode*>(child);
98     currentNode->RemoveChild(Referenced::Claim<UINode>(childNode));
99     currentNode->MarkNeedFrameFlushDirty(NG::PROPERTY_UPDATE_MEASURE);
100 }
101 
ClearChildren(ArkUINodeHandle node)102 void ClearChildren(ArkUINodeHandle node)
103 {
104     auto* currentNode = reinterpret_cast<UINode*>(node);
105     currentNode->Clean();
106     currentNode->MarkNeedFrameFlushDirty(NG::PROPERTY_UPDATE_MEASURE);
107 }
108 
SetClipToFrame(ArkUINodeHandle node,ArkUI_Bool useClip)109 void SetClipToFrame(ArkUINodeHandle node, ArkUI_Bool useClip)
110 {
111     auto* currentNode = reinterpret_cast<UINode*>(node);
112     auto renderContext = GetRenderContext(currentNode);
113     CHECK_NULL_VOID(renderContext);
114     renderContext->SetClipToFrame(useClip);
115     renderContext->RequestNextFrame();
116 }
117 
SetRotation(ArkUINodeHandle node,ArkUI_Float32 rotationX,ArkUI_Float32 rotationY,ArkUI_Float32 rotationZ,ArkUI_Int32 unitValue)118 void SetRotation(ArkUINodeHandle node, ArkUI_Float32 rotationX, ArkUI_Float32 rotationY, ArkUI_Float32 rotationZ,
119     ArkUI_Int32 unitValue)
120 {
121     auto* currentNode = reinterpret_cast<UINode*>(node);
122     auto renderContext = GetRenderContext(currentNode);
123     CHECK_NULL_VOID(renderContext);
124     DimensionUnit unit = ConvertLengthMetricsUnitToDimensionUnit(unitValue, DimensionUnit::VP);
125     Dimension first = Dimension(rotationX, unit);
126     Dimension second = Dimension(rotationY, unit);
127     Dimension third = Dimension(rotationZ, unit);
128     renderContext->SetRotation(first.ConvertToPx(), second.ConvertToPx(), third.ConvertToPx());
129     renderContext->RequestNextFrame();
130 }
131 
SetShadowColor(ArkUINodeHandle node,uint32_t color)132 void SetShadowColor(ArkUINodeHandle node, uint32_t color)
133 {
134     auto* currentNode = reinterpret_cast<UINode*>(node);
135     auto renderContext = GetRenderContext(currentNode);
136     CHECK_NULL_VOID(renderContext);
137     renderContext->SetShadowColor(color);
138     renderContext->RequestNextFrame();
139 }
140 
SetShadowOffset(ArkUINodeHandle node,ArkUI_Float32 offsetX,ArkUI_Float32 offsetY,ArkUI_Int32 unitValue)141 void SetShadowOffset(ArkUINodeHandle node, ArkUI_Float32 offsetX, ArkUI_Float32 offsetY, ArkUI_Int32 unitValue)
142 {
143     auto* currentNode = reinterpret_cast<UINode*>(node);
144     auto renderContext = GetRenderContext(currentNode);
145     CHECK_NULL_VOID(renderContext);
146     DimensionUnit unit = ConvertLengthMetricsUnitToDimensionUnit(unitValue, DimensionUnit::VP);
147     Dimension first = Dimension(offsetX, unit);
148     Dimension second = Dimension(offsetY, unit);
149     renderContext->SetShadowOffset(first.ConvertToPx(), second.ConvertToPx());
150     renderContext->RequestNextFrame();
151 }
152 
SetLabel(ArkUINodeHandle node,ArkUI_CharPtr label)153 void SetLabel(ArkUINodeHandle node, ArkUI_CharPtr label)
154 {
155     auto* currentNode = AceType::DynamicCast<FrameNode>(reinterpret_cast<UINode*>(node));
156     CHECK_NULL_VOID(currentNode);
157     auto pattern = currentNode->GetPattern<NG::RenderNodePattern>();
158     CHECK_NULL_VOID(pattern);
159     pattern->SetLabel(std::string(label));
160 }
161 
SetShadowAlpha(ArkUINodeHandle node,ArkUI_Float32 alpha)162 void SetShadowAlpha(ArkUINodeHandle node, ArkUI_Float32 alpha)
163 {
164     auto* currentNode = reinterpret_cast<UINode*>(node);
165     auto renderContext = GetRenderContext(currentNode);
166     CHECK_NULL_VOID(renderContext);
167     renderContext->SetShadowAlpha(alpha);
168     renderContext->RequestNextFrame();
169 }
170 
SetShadowElevation(ArkUINodeHandle node,ArkUI_Float32 elevation)171 void SetShadowElevation(ArkUINodeHandle node, ArkUI_Float32 elevation)
172 {
173     auto* currentNode = reinterpret_cast<UINode*>(node);
174     auto renderContext = GetRenderContext(currentNode);
175     CHECK_NULL_VOID(renderContext);
176     renderContext->SetShadowElevation(elevation);
177     renderContext->RequestNextFrame();
178 }
179 
SetShadowRadius(ArkUINodeHandle node,ArkUI_Float32 radius)180 void SetShadowRadius(ArkUINodeHandle node, ArkUI_Float32 radius)
181 {
182     auto* currentNode = reinterpret_cast<UINode*>(node);
183     auto renderContext = GetRenderContext(currentNode);
184     CHECK_NULL_VOID(renderContext);
185     renderContext->SetShadowRadius(radius);
186     renderContext->RequestNextFrame();
187 }
188 
Invalidate(ArkUINodeHandle node)189 void Invalidate(ArkUINodeHandle node)
190 {
191     auto* frameNode = reinterpret_cast<FrameNode*>(node);
192     CHECK_NULL_VOID(frameNode);
193     auto pattern = frameNode->GetPattern<RenderNodePattern>();
194     CHECK_NULL_VOID(pattern);
195     auto renderContext = frameNode->GetRenderContext();
196     CHECK_NULL_VOID(renderContext);
197     pattern->Invalidate();
198     renderContext->RequestNextFrame();
199 }
200 
SetScale(ArkUINodeHandle node,ArkUI_Float32 scaleX,ArkUI_Float32 scaleY)201 void SetScale(ArkUINodeHandle node, ArkUI_Float32 scaleX, ArkUI_Float32 scaleY)
202 {
203     auto* currentNode = reinterpret_cast<UINode*>(node);
204     auto renderContext = GetRenderContext(currentNode);
205     CHECK_NULL_VOID(renderContext);
206     renderContext->SetScale(scaleX, scaleY);
207     renderContext->RequestNextFrame();
208 }
209 
SetRenderNodeBackgroundColor(ArkUINodeHandle node,uint32_t colorValue)210 void SetRenderNodeBackgroundColor(ArkUINodeHandle node, uint32_t colorValue)
211 {
212     auto* currentNode = reinterpret_cast<UINode*>(node);
213     auto renderContext = GetRenderContext(currentNode);
214     CHECK_NULL_VOID(renderContext);
215     renderContext->SetBackgroundColor(colorValue);
216     renderContext->RequestNextFrame();
217 }
218 
SetPivot(ArkUINodeHandle node,ArkUI_Float32 pivotX,ArkUI_Float32 pivotY)219 void SetPivot(ArkUINodeHandle node, ArkUI_Float32 pivotX, ArkUI_Float32 pivotY)
220 {
221     auto* currentNode = reinterpret_cast<UINode*>(node);
222     auto renderContext = GetRenderContext(currentNode);
223     CHECK_NULL_VOID(renderContext);
224     renderContext->SetRenderPivot(pivotX, pivotY);
225     renderContext->RequestNextFrame();
226 }
227 
SetFrame(ArkUINodeHandle node,ArkUI_Float32 positionX,ArkUI_Float32 positionY,ArkUI_Float32 width,ArkUI_Float32 height)228 void SetFrame(
229     ArkUINodeHandle node, ArkUI_Float32 positionX, ArkUI_Float32 positionY, ArkUI_Float32 width, ArkUI_Float32 height)
230 {
231     auto* currentNode = reinterpret_cast<UINode*>(node);
232     auto renderContext = GetRenderContext(currentNode);
233     CHECK_NULL_VOID(renderContext);
234     renderContext->SetFrame(Dimension(positionX, DimensionUnit::VP).ConvertToPx(),
235         Dimension(positionY, DimensionUnit::VP).ConvertToPx(), Dimension(width, DimensionUnit::VP).ConvertToPx(),
236         Dimension(height, DimensionUnit::VP).ConvertToPx());
237     renderContext->RequestNextFrame();
238 }
239 
SetSize(ArkUINodeHandle node,ArkUI_Float32 width,ArkUI_Float32 height,ArkUI_Int32 unitValue)240 void SetSize(ArkUINodeHandle node, ArkUI_Float32 width, ArkUI_Float32 height, ArkUI_Int32 unitValue)
241 {
242     auto* currentNode = reinterpret_cast<UINode*>(node);
243     auto* frameNode = AceType::DynamicCast<FrameNode>(currentNode);
244     CHECK_NULL_VOID(frameNode);
245     CHECK_NULL_VOID(frameNode->GetTag() != "BuilderProxyNode");
246     auto layoutProperty = frameNode->GetLayoutProperty();
247     CHECK_NULL_VOID(layoutProperty);
248     DimensionUnit unit = ConvertLengthMetricsUnitToDimensionUnit(unitValue, DimensionUnit::VP);
249     layoutProperty->UpdateUserDefinedIdealSize(
250         CalcSize(CalcLength(width, unit), CalcLength(height, unit)));
251     frameNode->MarkDirtyNode(NG::PROPERTY_UPDATE_MEASURE);
252 }
253 
SetPosition(ArkUINodeHandle node,ArkUI_Float32 xAxis,ArkUI_Float32 yAxis,ArkUI_Int32 unitValue)254 void SetPosition(ArkUINodeHandle node, ArkUI_Float32 xAxis, ArkUI_Float32 yAxis, ArkUI_Int32 unitValue)
255 {
256     auto* currentNode = reinterpret_cast<UINode*>(node);
257     auto* frameNode = AceType::DynamicCast<FrameNode>(currentNode);
258     CHECK_NULL_VOID(frameNode);
259     CHECK_NULL_VOID(frameNode->GetTag() != "BuilderProxyNode");
260     const auto& renderContext = GetRenderContext(currentNode);
261     CHECK_NULL_VOID(renderContext);
262     renderContext->ResetPosition();
263 
264     DimensionUnit unit = ConvertLengthMetricsUnitToDimensionUnit(unitValue, DimensionUnit::VP);
265     Dimension x = Dimension(xAxis, unit);
266     Dimension y = Dimension(yAxis, unit);
267     OffsetT<Dimension> value(x, y);
268     renderContext->UpdatePosition(value);
269     renderContext->RequestNextFrame();
270 }
271 
SetOpacity(ArkUINodeHandle node,ArkUI_Float32 opacity)272 void SetOpacity(ArkUINodeHandle node, ArkUI_Float32 opacity)
273 {
274     auto* currentNode = reinterpret_cast<UINode*>(node);
275     auto renderContext = GetRenderContext(currentNode);
276     CHECK_NULL_VOID(renderContext);
277     renderContext->SetOpacity(opacity);
278     renderContext->RequestNextFrame();
279 }
280 
SetTranslate(ArkUINodeHandle node,ArkUI_Float32 translateX,ArkUI_Float32 translateY,ArkUI_Float32 translateZ)281 void SetTranslate(ArkUINodeHandle node, ArkUI_Float32 translateX, ArkUI_Float32 translateY, ArkUI_Float32 translateZ)
282 {
283     auto* currentNode = reinterpret_cast<UINode*>(node);
284     auto renderContext = GetRenderContext(currentNode);
285     CHECK_NULL_VOID(renderContext);
286     renderContext->SetTranslate(translateX, translateY, translateZ);
287     renderContext->RequestNextFrame();
288 }
289 
SetBorderStyle(ArkUINodeHandle node,ArkUI_Int32 left,ArkUI_Int32 top,ArkUI_Int32 right,ArkUI_Int32 bottom)290 void SetBorderStyle(ArkUINodeHandle node, ArkUI_Int32 left, ArkUI_Int32 top, ArkUI_Int32 right, ArkUI_Int32 bottom)
291 {
292     auto* currentNode = reinterpret_cast<UINode*>(node);
293     auto renderContext = GetRenderContext(currentNode);
294     CHECK_NULL_VOID(renderContext);
295     BorderStyleProperty borderStyleProperty {
296         .styleLeft = static_cast<BorderStyle>(left),
297         .styleRight = static_cast<BorderStyle>(right),
298         .styleTop = static_cast<BorderStyle>(top),
299         .styleBottom = static_cast<BorderStyle>(bottom),
300         .multiValued = true
301     };
302     renderContext->UpdateBorderStyle(borderStyleProperty);
303 }
304 
SetBorderWidth(ArkUINodeHandle node,ArkUI_Float32 left,ArkUI_Float32 top,ArkUI_Float32 right,ArkUI_Float32 bottom,ArkUI_Int32 unitValue)305 void SetBorderWidth(ArkUINodeHandle node, ArkUI_Float32 left, ArkUI_Float32 top, ArkUI_Float32 right,
306     ArkUI_Float32 bottom, ArkUI_Int32 unitValue)
307 {
308     auto* currentNode = reinterpret_cast<UINode*>(node);
309     CHECK_NULL_VOID(currentNode);
310     auto renderContext = GetRenderContext(currentNode);
311     CHECK_NULL_VOID(renderContext);
312     auto* frameNode = reinterpret_cast<FrameNode*>(currentNode);
313     auto layoutProperty = frameNode->GetLayoutProperty<LayoutProperty>();
314     DimensionUnit unit = ConvertLengthMetricsUnitToDimensionUnit(unitValue, DimensionUnit::VP);
315     BorderWidthProperty borderWidthProperty {
316         .leftDimen = Dimension(left, unit),
317         .topDimen = Dimension(top, unit),
318         .rightDimen = Dimension(right, unit),
319         .bottomDimen = Dimension(bottom, unit),
320         .multiValued = true
321     };
322     layoutProperty->UpdateBorderWidth(borderWidthProperty);
323     frameNode->MarkDirtyNode();
324     renderContext->SetBorderWidth(borderWidthProperty);
325 }
326 
SetBorderColor(ArkUINodeHandle node,uint32_t left,uint32_t top,uint32_t right,uint32_t bottom)327 void SetBorderColor(ArkUINodeHandle node, uint32_t left, uint32_t top, uint32_t right, uint32_t bottom)
328 {
329     auto* currentNode = reinterpret_cast<UINode*>(node);
330     CHECK_NULL_VOID(currentNode);
331     auto renderContext = GetRenderContext(currentNode);
332     CHECK_NULL_VOID(renderContext);
333 
334     BorderColorProperty borderColorProperty {
335         .leftColor = Color(left),
336         .rightColor = Color(right),
337         .topColor = Color(top),
338         .bottomColor = Color(bottom),
339         .multiValued = true
340     };
341     renderContext->UpdateBorderColor(borderColorProperty);
342 }
343 
SetBorderRadius(ArkUINodeHandle node,ArkUI_Float32 topLeft,ArkUI_Float32 topRight,ArkUI_Float32 bottomLeft,ArkUI_Float32 bottomRight,ArkUI_Int32 unitValue)344 void SetBorderRadius(ArkUINodeHandle node, ArkUI_Float32 topLeft, ArkUI_Float32 topRight, ArkUI_Float32 bottomLeft,
345     ArkUI_Float32 bottomRight, ArkUI_Int32 unitValue)
346 {
347     auto* currentNode = reinterpret_cast<UINode*>(node);
348     CHECK_NULL_VOID(currentNode);
349     auto renderContext = GetRenderContext(currentNode);
350     CHECK_NULL_VOID(renderContext);
351     DimensionUnit unit = ConvertLengthMetricsUnitToDimensionUnit(unitValue, DimensionUnit::VP);
352     BorderRadiusProperty borderRadiusProperty(Dimension(topLeft, unit),
353         Dimension(topRight, unit), Dimension(bottomRight, unit),
354         Dimension(bottomLeft, unit));
355     renderContext->UpdateBorderRadius(borderRadiusProperty);
356 }
357 
SetRectMask(ArkUINodeHandle node,ArkUI_Float32 rectX,ArkUI_Float32 rectY,ArkUI_Float32 rectW,ArkUI_Float32 rectH,ArkUI_Uint32 fillColor,ArkUI_Uint32 strokeColor,ArkUI_Float32 strokeWidth)358 void SetRectMask(ArkUINodeHandle node,
359     ArkUI_Float32 rectX, ArkUI_Float32 rectY, ArkUI_Float32 rectW, ArkUI_Float32 rectH,
360     ArkUI_Uint32 fillColor, ArkUI_Uint32 strokeColor, ArkUI_Float32 strokeWidth)
361 {
362     auto* currentNode = reinterpret_cast<UINode*>(node);
363     CHECK_NULL_VOID(currentNode);
364     auto renderContext = GetRenderContext(currentNode);
365     CHECK_NULL_VOID(renderContext);
366 
367     RectF rect(rectX, rectY, rectW, rectH);
368     ShapeMaskProperty property { fillColor, strokeColor, strokeWidth };
369     renderContext->SetRectMask(rect, property);
370     renderContext->RequestNextFrame();
371 }
372 
SetCircleMask(ArkUINodeHandle node,ArkUI_Float32 centerXValue,ArkUI_Float32 centerYValue,ArkUI_Float32 radiusValue,ArkUI_Uint32 fillColor,ArkUI_Uint32 strokeColor,ArkUI_Float32 strokeWidth)373 void SetCircleMask(ArkUINodeHandle node,
374     ArkUI_Float32 centerXValue, ArkUI_Float32 centerYValue, ArkUI_Float32 radiusValue,
375     ArkUI_Uint32 fillColor, ArkUI_Uint32 strokeColor, ArkUI_Float32 strokeWidth)
376 {
377     auto* currentNode = reinterpret_cast<UINode*>(node);
378     CHECK_NULL_VOID(currentNode);
379     auto renderContext = GetRenderContext(currentNode);
380     CHECK_NULL_VOID(renderContext);
381 
382     Circle circle;
383     Dimension centerX(centerXValue, DimensionUnit::PX);
384     circle.SetAxisX(centerX);
385     Dimension centerY(centerYValue, DimensionUnit::PX);
386     circle.SetAxisY(centerY);
387     Dimension radius(radiusValue, DimensionUnit::PX);
388     circle.SetRadius(radius);
389 
390     ShapeMaskProperty property { fillColor, strokeColor, strokeWidth };
391 
392     renderContext->SetCircleMask(circle, property);
393     renderContext->RequestNextFrame();
394 }
395 
SetRoundRectMask(ArkUINodeHandle node,const ArkUI_Float32 * roundRect,const ArkUI_Uint32 roundRectSize,ArkUI_Uint32 fillColor,ArkUI_Uint32 strokeColor,ArkUI_Float32 strokeWidth)396 void SetRoundRectMask(ArkUINodeHandle node, const ArkUI_Float32* roundRect, const ArkUI_Uint32 roundRectSize,
397     ArkUI_Uint32 fillColor, ArkUI_Uint32 strokeColor, ArkUI_Float32 strokeWidth)
398 {
399     auto* currentNode = reinterpret_cast<UINode*>(node);
400     CHECK_NULL_VOID(currentNode);
401     auto renderContext = GetRenderContext(currentNode);
402     CHECK_NULL_VOID(renderContext);
403 
404     RoundRect roundRectInstance;
405     roundRectInstance.SetCornerRadius(RoundRect::CornerPos::TOP_LEFT_POS,
406         roundRect[TOP_LEFT_X_VALUE], roundRect[TOP_LEFT_Y_VALUE]);
407     roundRectInstance.SetCornerRadius(RoundRect::CornerPos::TOP_RIGHT_POS,
408         roundRect[TOP_RIGHT_X_VALUE], roundRect[TOP_RIGHT_Y_VALUE]);
409     roundRectInstance.SetCornerRadius(RoundRect::CornerPos::BOTTOM_LEFT_POS,
410         roundRect[BOTTOM_LEFT_X_VALUE], roundRect[BOTTOM_LEFT_Y_VALUE]);
411     roundRectInstance.SetCornerRadius(RoundRect::CornerPos::BOTTOM_RIGHT_POS,
412         roundRect[BOTTOM_RIGHT_X_VALUE], roundRect[BOTTOM_RIGHT_Y_VALUE]);
413 
414     RectF rect(roundRect[LEFT_VALUE], roundRect[TOP_VALUE], roundRect[WIDTH_VALUE], roundRect[HEIGHT_VALUE]);
415     roundRectInstance.SetRect(rect);
416 
417     ShapeMaskProperty property { fillColor, strokeColor, strokeWidth };
418 
419     renderContext->SetRoundRectMask(roundRectInstance, property);
420     renderContext->RequestNextFrame();
421 }
422 
SetOvalMask(ArkUINodeHandle node,ArkUI_Float32 rectX,ArkUI_Float32 rectY,ArkUI_Float32 rectW,ArkUI_Float32 rectH,ArkUI_Uint32 fillColor,ArkUI_Uint32 strokeColor,ArkUI_Float32 strokeWidth)423 void SetOvalMask(ArkUINodeHandle node,
424     ArkUI_Float32 rectX, ArkUI_Float32 rectY, ArkUI_Float32 rectW, ArkUI_Float32 rectH,
425     ArkUI_Uint32 fillColor, ArkUI_Uint32 strokeColor, ArkUI_Float32 strokeWidth)
426 {
427     auto* currentNode = reinterpret_cast<UINode*>(node);
428     CHECK_NULL_VOID(currentNode);
429     auto renderContext = GetRenderContext(currentNode);
430     CHECK_NULL_VOID(renderContext);
431 
432     RectF rect(rectX, rectY, rectW, rectH);
433     ShapeMaskProperty property { fillColor, strokeColor, strokeWidth };
434     renderContext->SetOvalMask(rect, property);
435     renderContext->RequestNextFrame();
436 }
437 
SetCommandPathMask(ArkUINodeHandle node,ArkUI_CharPtr commands,ArkUI_Uint32 fillColor,ArkUI_Uint32 strokeColor,ArkUI_Float32 strokeWidth)438 void SetCommandPathMask(ArkUINodeHandle node, ArkUI_CharPtr commands, ArkUI_Uint32 fillColor, ArkUI_Uint32 strokeColor,
439     ArkUI_Float32 strokeWidth)
440 {
441     auto* currentNode = reinterpret_cast<UINode*>(node);
442     CHECK_NULL_VOID(currentNode);
443     auto renderContext = GetRenderContext(currentNode);
444     CHECK_NULL_VOID(renderContext);
445 
446     ShapeMaskProperty property { fillColor, strokeColor, strokeWidth };
447     renderContext->SetCommandPathMask(std::string(commands), property);
448     renderContext->RequestNextFrame();
449 }
450 
SetRectClip(ArkUINodeHandle node,ArkUI_Float32 rectX,ArkUI_Float32 rectY,ArkUI_Float32 rectW,ArkUI_Float32 rectH)451 void SetRectClip(
452     ArkUINodeHandle node, ArkUI_Float32 rectX, ArkUI_Float32 rectY, ArkUI_Float32 rectW, ArkUI_Float32 rectH)
453 {
454     auto* currentNode = reinterpret_cast<UINode*>(node);
455     CHECK_NULL_VOID(currentNode);
456     auto renderContext = GetRenderContext(currentNode);
457     CHECK_NULL_VOID(renderContext);
458 
459     RectF rect(rectX, rectY, rectW, rectH);
460     renderContext->ClipWithRect(rect);
461     renderContext->RequestNextFrame();
462 }
463 
SetCircleClip(ArkUINodeHandle node,ArkUI_Float32 centerXValue,ArkUI_Float32 centerYValue,ArkUI_Float32 radiusValue)464 void SetCircleClip(
465     ArkUINodeHandle node, ArkUI_Float32 centerXValue, ArkUI_Float32 centerYValue, ArkUI_Float32 radiusValue)
466 {
467     auto* currentNode = reinterpret_cast<UINode*>(node);
468     CHECK_NULL_VOID(currentNode);
469     auto renderContext = GetRenderContext(currentNode);
470     CHECK_NULL_VOID(renderContext);
471 
472     Circle circle;
473     Dimension centerX(centerXValue, DimensionUnit::PX);
474     circle.SetAxisX(centerX);
475     Dimension centerY(centerYValue, DimensionUnit::PX);
476     circle.SetAxisY(centerY);
477     Dimension radius(radiusValue, DimensionUnit::PX);
478     circle.SetRadius(radius);
479 
480     renderContext->ClipWithCircle(circle);
481     renderContext->RequestNextFrame();
482 }
483 
SetRoundRectClip(ArkUINodeHandle node,const ArkUI_Float32 * roundRect,const ArkUI_Uint32 roundRectSize)484 void SetRoundRectClip(ArkUINodeHandle node, const ArkUI_Float32* roundRect, const ArkUI_Uint32 roundRectSize)
485 {
486     auto* currentNode = reinterpret_cast<UINode*>(node);
487     CHECK_NULL_VOID(currentNode);
488     auto renderContext = GetRenderContext(currentNode);
489     CHECK_NULL_VOID(renderContext);
490 
491     RoundRect roundRectInstance;
492     roundRectInstance.SetCornerRadius(
493         RoundRect::CornerPos::TOP_LEFT_POS, roundRect[TOP_LEFT_X_VALUE], roundRect[TOP_LEFT_Y_VALUE]);
494     roundRectInstance.SetCornerRadius(
495         RoundRect::CornerPos::TOP_RIGHT_POS, roundRect[TOP_RIGHT_X_VALUE], roundRect[TOP_RIGHT_Y_VALUE]);
496     roundRectInstance.SetCornerRadius(
497         RoundRect::CornerPos::BOTTOM_LEFT_POS, roundRect[BOTTOM_LEFT_X_VALUE], roundRect[BOTTOM_LEFT_Y_VALUE]);
498     roundRectInstance.SetCornerRadius(
499         RoundRect::CornerPos::BOTTOM_RIGHT_POS, roundRect[BOTTOM_RIGHT_X_VALUE], roundRect[BOTTOM_RIGHT_Y_VALUE]);
500 
501     RectF rect(roundRect[LEFT_VALUE], roundRect[TOP_VALUE], roundRect[WIDTH_VALUE], roundRect[HEIGHT_VALUE]);
502     roundRectInstance.SetRect(rect);
503 
504     renderContext->ClipWithRoundRect(roundRectInstance);
505     renderContext->RequestNextFrame();
506 }
507 
SetOvalClip(ArkUINodeHandle node,ArkUI_Float32 rectX,ArkUI_Float32 rectY,ArkUI_Float32 rectW,ArkUI_Float32 rectH)508 void SetOvalClip(
509     ArkUINodeHandle node, ArkUI_Float32 rectX, ArkUI_Float32 rectY, ArkUI_Float32 rectW, ArkUI_Float32 rectH)
510 {
511     auto* currentNode = reinterpret_cast<UINode*>(node);
512     CHECK_NULL_VOID(currentNode);
513     auto renderContext = GetRenderContext(currentNode);
514     CHECK_NULL_VOID(renderContext);
515 
516     RectF rect(rectX, rectY, rectW, rectH);
517     renderContext->ClipWithOval(rect);
518     renderContext->RequestNextFrame();
519 }
520 
SetCommandPathClip(ArkUINodeHandle node,ArkUI_CharPtr commands)521 void SetCommandPathClip(ArkUINodeHandle node, ArkUI_CharPtr commands)
522 {
523     auto* currentNode = reinterpret_cast<UINode*>(node);
524     CHECK_NULL_VOID(currentNode);
525     auto renderContext = GetRenderContext(currentNode);
526     CHECK_NULL_VOID(renderContext);
527 
528     renderContext->SetClipBoundsWithCommands(std::string(commands));
529     renderContext->RequestNextFrame();
530 }
531 
SetMarkNodeGroup(ArkUINodeHandle node,ArkUI_Bool isNodeGroup)532 void SetMarkNodeGroup(ArkUINodeHandle node, ArkUI_Bool isNodeGroup)
533 {
534     auto* currentNode = reinterpret_cast<UINode*>(node);
535     CHECK_NULL_VOID(currentNode);
536     auto renderContext = GetRenderContext(currentNode);
537     CHECK_NULL_VOID(renderContext);
538 
539     renderContext->SetMarkNodeGroup(isNodeGroup);
540     renderContext->RequestNextFrame();
541 }
542 
543 namespace NodeModifier {
GetRenderNodeModifier()544 const ArkUIRenderNodeModifier* GetRenderNodeModifier()
545 {
546     static const ArkUIRenderNodeModifier modifier = { AppendChild, InsertChildAfter, RemoveChild, ClearChildren,
547         SetClipToFrame, SetRotation, SetShadowColor, SetShadowOffset, SetLabel, SetShadowAlpha, SetShadowElevation,
548         SetShadowRadius, Invalidate, SetScale, SetRenderNodeBackgroundColor, SetPivot, SetFrame, SetSize, SetOpacity,
549         SetTranslate, SetBorderStyle, SetBorderWidth, SetBorderColor, SetBorderRadius, SetRectMask, SetCircleMask,
550         SetRoundRectMask, SetOvalMask, SetCommandPathMask, SetRectClip, SetCircleClip, SetRoundRectClip, SetOvalClip,
551         SetCommandPathClip, SetPosition, SetMarkNodeGroup };
552 
553     return &modifier;
554 }
555 
GetCJUIRenderNodeModifier()556 const CJUIRenderNodeModifier* GetCJUIRenderNodeModifier()
557 {
558     static const CJUIRenderNodeModifier modifier = { AppendChild, InsertChildAfter, RemoveChild, ClearChildren,
559         SetClipToFrame, SetRotation, SetShadowColor, SetShadowOffset, SetShadowAlpha, SetShadowElevation,
560         SetShadowRadius, Invalidate, SetScale, SetRenderNodeBackgroundColor, SetPivot, SetFrame, SetSize, SetOpacity,
561         SetTranslate, SetBorderStyle, SetBorderWidth, SetBorderColor, SetBorderRadius, SetRectMask, SetCircleMask,
562         SetRoundRectMask, SetOvalMask, SetCommandPathMask, SetPosition, SetMarkNodeGroup };
563 
564     return &modifier;
565 }
566 }
567 } // namespace OHOS::Ace::NG
568