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 "core/common/builder_util.h"
18 #include "core/components_ng/pattern/render_node/render_node_pattern.h"
19
20 namespace OHOS::Ace::NG {
21 namespace {
22 enum class LengthMetricsUnit : int32_t { DEFAULT = 0, PX };
23
ConvertLengthMetricsUnitToDimensionUnit(int32_t unitValue,DimensionUnit defaultUnit)24 DimensionUnit ConvertLengthMetricsUnitToDimensionUnit(int32_t unitValue, DimensionUnit defaultUnit)
25 {
26 auto lengthMetricsUnit = static_cast<LengthMetricsUnit>(unitValue);
27 switch (lengthMetricsUnit) {
28 case LengthMetricsUnit::PX:
29 return DimensionUnit::PX;
30 default:
31 return defaultUnit;
32 }
33 return defaultUnit;
34 }
35 } // namespace
36 constexpr int TOP_LEFT_X_VALUE = 0;
37 constexpr int TOP_LEFT_Y_VALUE = 1;
38 constexpr int TOP_RIGHT_X_VALUE = 2;
39 constexpr int TOP_RIGHT_Y_VALUE = 3;
40 constexpr int BOTTOM_LEFT_X_VALUE = 4;
41 constexpr int BOTTOM_LEFT_Y_VALUE = 5;
42 constexpr int BOTTOM_RIGHT_X_VALUE = 6;
43 constexpr int BOTTOM_RIGHT_Y_VALUE = 7;
44 constexpr int LEFT_VALUE = 8;
45 constexpr int TOP_VALUE = 9;
46 constexpr int WIDTH_VALUE = 10;
47 constexpr int HEIGHT_VALUE = 11;
48
GetRenderContext(UINode * node)49 RefPtr<RenderContext> GetRenderContext(UINode* node)
50 {
51 auto* frameNode = AceType::DynamicCast<FrameNode>(node);
52 CHECK_NULL_RETURN(frameNode, nullptr);
53 CHECK_NULL_RETURN(node->GetTag() != "BuilderProxyNode", nullptr);
54 auto context = frameNode->GetRenderContext();
55 return context;
56 }
57
AddBuilderNode(ArkUINodeHandle node,ArkUINodeHandle child)58 void AddBuilderNode(ArkUINodeHandle node, ArkUINodeHandle child)
59 {
60 auto* currentNode = reinterpret_cast<UINode*>(node);
61 CHECK_NULL_VOID(currentNode);
62 auto* childNode = reinterpret_cast<UINode*>(child);
63 CHECK_NULL_VOID(childNode);
64 auto childRef = Referenced::Claim<UINode>(childNode);
65 CHECK_NULL_VOID(childRef);
66 auto parentNode = childRef->GetParent();
67 CHECK_NULL_VOID(parentNode && parentNode == currentNode);
68 std::list<RefPtr<UINode>> nodes;
69 BuilderUtils::GetBuilderNodes(childRef, nodes);
70 BuilderUtils::AddBuilderToParent(parentNode, nodes);
71 }
72
AppendChild(ArkUINodeHandle node,ArkUINodeHandle child)73 void AppendChild(ArkUINodeHandle node, ArkUINodeHandle child)
74 {
75 auto* currentNode = reinterpret_cast<UINode*>(node);
76 auto* childNode = reinterpret_cast<UINode*>(child);
77 auto childRef = Referenced::Claim<UINode>(childNode);
78 currentNode->AddChild(childRef);
79 currentNode->MarkNeedFrameFlushDirty(NG::PROPERTY_UPDATE_MEASURE);
80 }
81
InsertChildAfter(ArkUINodeHandle node,ArkUINodeHandle child,ArkUINodeHandle sibling)82 void InsertChildAfter(ArkUINodeHandle node, ArkUINodeHandle child, ArkUINodeHandle sibling)
83 {
84 auto* currentNode = reinterpret_cast<UINode*>(node);
85 auto* childNode = reinterpret_cast<UINode*>(child);
86 auto index = -1;
87 auto* siblingNode = reinterpret_cast<UINode*>(sibling);
88 index = currentNode->GetChildIndex(Referenced::Claim<UINode>(siblingNode));
89 currentNode->AddChild(Referenced::Claim<UINode>(childNode), index + 1);
90 currentNode->MarkNeedFrameFlushDirty(NG::PROPERTY_UPDATE_MEASURE);
91 }
92
RemoveBuilderNode(ArkUINodeHandle node,ArkUINodeHandle child)93 void RemoveBuilderNode(ArkUINodeHandle node, ArkUINodeHandle child)
94 {
95 auto* currentNode = reinterpret_cast<UINode*>(node);
96 CHECK_NULL_VOID(currentNode);
97 auto* childNode = reinterpret_cast<UINode*>(child);
98 CHECK_NULL_VOID(childNode);
99 auto childRef = Referenced::Claim<UINode>(childNode);
100 CHECK_NULL_VOID(childRef);
101 auto parentNode = childRef->GetParent();
102 CHECK_NULL_VOID(parentNode && parentNode == currentNode);
103 std::list<RefPtr<UINode>> nodes;
104 BuilderUtils::GetBuilderNodes(childRef, nodes);
105 BuilderUtils::RemoveBuilderFromParent(parentNode, nodes);
106 }
107
RemoveChild(ArkUINodeHandle node,ArkUINodeHandle child)108 void RemoveChild(ArkUINodeHandle node, ArkUINodeHandle child)
109 {
110 auto* currentNode = reinterpret_cast<UINode*>(node);
111 auto* childNode = reinterpret_cast<UINode*>(child);
112 currentNode->RemoveChild(Referenced::Claim<UINode>(childNode));
113 currentNode->MarkNeedFrameFlushDirty(NG::PROPERTY_UPDATE_MEASURE);
114 }
115
ClearBuilderNode(ArkUINodeHandle node)116 void ClearBuilderNode(ArkUINodeHandle node)
117 {
118 auto* currentNode = reinterpret_cast<UINode*>(node);
119 CHECK_NULL_VOID(currentNode);
120 auto currentRef = Referenced::Claim<UINode>(currentNode);
121 std::list<RefPtr<NG::UINode>> nodes;
122 CHECK_NULL_VOID(currentRef);
123 for (const auto& child : currentRef->GetChildren()) {
124 BuilderUtils::GetBuilderNodes(child, nodes);
125 }
126 BuilderUtils::RemoveBuilderFromParent(currentRef, nodes);
127 }
128
ClearChildren(ArkUINodeHandle node)129 void ClearChildren(ArkUINodeHandle node)
130 {
131 auto* currentNode = reinterpret_cast<UINode*>(node);
132 currentNode->Clean();
133 currentNode->MarkNeedFrameFlushDirty(NG::PROPERTY_UPDATE_MEASURE);
134 }
135
SetClipToFrame(ArkUINodeHandle node,ArkUI_Bool useClip)136 void SetClipToFrame(ArkUINodeHandle node, ArkUI_Bool useClip)
137 {
138 auto* currentNode = reinterpret_cast<UINode*>(node);
139 auto renderContext = GetRenderContext(currentNode);
140 CHECK_NULL_VOID(renderContext);
141 renderContext->SetClipToFrame(useClip);
142 renderContext->RequestNextFrame();
143 }
144
SetRotation(ArkUINodeHandle node,ArkUI_Float32 rotationX,ArkUI_Float32 rotationY,ArkUI_Float32 rotationZ,ArkUI_Int32 unitValue)145 void SetRotation(ArkUINodeHandle node, ArkUI_Float32 rotationX, ArkUI_Float32 rotationY, ArkUI_Float32 rotationZ,
146 ArkUI_Int32 unitValue)
147 {
148 auto* currentNode = reinterpret_cast<UINode*>(node);
149 auto renderContext = GetRenderContext(currentNode);
150 CHECK_NULL_VOID(renderContext);
151 DimensionUnit unit = ConvertLengthMetricsUnitToDimensionUnit(unitValue, DimensionUnit::VP);
152 Dimension first = Dimension(rotationX, unit);
153 Dimension second = Dimension(rotationY, unit);
154 Dimension third = Dimension(rotationZ, unit);
155 renderContext->SetRotation(first.ConvertToPx(), second.ConvertToPx(), third.ConvertToPx());
156 renderContext->RequestNextFrame();
157 }
158
SetShadowColor(ArkUINodeHandle node,uint32_t color)159 void SetShadowColor(ArkUINodeHandle node, uint32_t color)
160 {
161 auto* currentNode = reinterpret_cast<UINode*>(node);
162 auto renderContext = GetRenderContext(currentNode);
163 CHECK_NULL_VOID(renderContext);
164 renderContext->SetShadowColor(color);
165 renderContext->RequestNextFrame();
166 }
167
SetShadowOffset(ArkUINodeHandle node,ArkUI_Float32 offsetX,ArkUI_Float32 offsetY,ArkUI_Int32 unitValue)168 void SetShadowOffset(ArkUINodeHandle node, ArkUI_Float32 offsetX, ArkUI_Float32 offsetY, ArkUI_Int32 unitValue)
169 {
170 auto* currentNode = reinterpret_cast<UINode*>(node);
171 auto renderContext = GetRenderContext(currentNode);
172 CHECK_NULL_VOID(renderContext);
173 DimensionUnit unit = ConvertLengthMetricsUnitToDimensionUnit(unitValue, DimensionUnit::VP);
174 Dimension first = Dimension(offsetX, unit);
175 Dimension second = Dimension(offsetY, unit);
176 renderContext->SetShadowOffset(first.ConvertToPx(), second.ConvertToPx());
177 renderContext->RequestNextFrame();
178 }
179
SetLabel(ArkUINodeHandle node,ArkUI_CharPtr label)180 void SetLabel(ArkUINodeHandle node, ArkUI_CharPtr label)
181 {
182 auto* currentNode = AceType::DynamicCast<FrameNode>(reinterpret_cast<UINode*>(node));
183 CHECK_NULL_VOID(currentNode);
184 auto pattern = currentNode->GetPattern<NG::RenderNodePattern>();
185 CHECK_NULL_VOID(pattern);
186 pattern->SetLabel(std::string(label));
187 }
188
SetShadowAlpha(ArkUINodeHandle node,ArkUI_Float32 alpha)189 void SetShadowAlpha(ArkUINodeHandle node, ArkUI_Float32 alpha)
190 {
191 auto* currentNode = reinterpret_cast<UINode*>(node);
192 auto renderContext = GetRenderContext(currentNode);
193 CHECK_NULL_VOID(renderContext);
194 renderContext->SetShadowAlpha(alpha);
195 renderContext->RequestNextFrame();
196 }
197
SetShadowElevation(ArkUINodeHandle node,ArkUI_Float32 elevation)198 void SetShadowElevation(ArkUINodeHandle node, ArkUI_Float32 elevation)
199 {
200 auto* currentNode = reinterpret_cast<UINode*>(node);
201 auto renderContext = GetRenderContext(currentNode);
202 CHECK_NULL_VOID(renderContext);
203 renderContext->SetShadowElevation(elevation);
204 renderContext->RequestNextFrame();
205 }
206
SetShadowRadius(ArkUINodeHandle node,ArkUI_Float32 radius)207 void SetShadowRadius(ArkUINodeHandle node, ArkUI_Float32 radius)
208 {
209 auto* currentNode = reinterpret_cast<UINode*>(node);
210 auto renderContext = GetRenderContext(currentNode);
211 CHECK_NULL_VOID(renderContext);
212 renderContext->SetShadowRadius(radius);
213 renderContext->RequestNextFrame();
214 }
215
Invalidate(ArkUINodeHandle node)216 void Invalidate(ArkUINodeHandle node)
217 {
218 auto* frameNode = reinterpret_cast<FrameNode*>(node);
219 CHECK_NULL_VOID(frameNode);
220 auto pattern = frameNode->GetPattern<RenderNodePattern>();
221 CHECK_NULL_VOID(pattern);
222 auto renderContext = frameNode->GetRenderContext();
223 CHECK_NULL_VOID(renderContext);
224 pattern->Invalidate();
225 renderContext->RequestNextFrame();
226 }
227
SetScale(ArkUINodeHandle node,ArkUI_Float32 scaleX,ArkUI_Float32 scaleY)228 void SetScale(ArkUINodeHandle node, ArkUI_Float32 scaleX, ArkUI_Float32 scaleY)
229 {
230 auto* currentNode = reinterpret_cast<UINode*>(node);
231 auto renderContext = GetRenderContext(currentNode);
232 CHECK_NULL_VOID(renderContext);
233 renderContext->SetScale(scaleX, scaleY);
234 renderContext->RequestNextFrame();
235 }
236
SetRenderNodeBackgroundColor(ArkUINodeHandle node,uint32_t colorValue)237 void SetRenderNodeBackgroundColor(ArkUINodeHandle node, uint32_t colorValue)
238 {
239 auto* currentNode = reinterpret_cast<UINode*>(node);
240 auto renderContext = GetRenderContext(currentNode);
241 CHECK_NULL_VOID(renderContext);
242 renderContext->SetBackgroundColor(colorValue);
243 renderContext->RequestNextFrame();
244 }
245
SetPivot(ArkUINodeHandle node,ArkUI_Float32 pivotX,ArkUI_Float32 pivotY)246 void SetPivot(ArkUINodeHandle node, ArkUI_Float32 pivotX, ArkUI_Float32 pivotY)
247 {
248 auto* currentNode = reinterpret_cast<UINode*>(node);
249 auto renderContext = GetRenderContext(currentNode);
250 CHECK_NULL_VOID(renderContext);
251 renderContext->SetRenderPivot(pivotX, pivotY);
252 renderContext->RequestNextFrame();
253 }
254
SetFrame(ArkUINodeHandle node,ArkUI_Float32 positionX,ArkUI_Float32 positionY,ArkUI_Float32 width,ArkUI_Float32 height)255 void SetFrame(
256 ArkUINodeHandle node, ArkUI_Float32 positionX, ArkUI_Float32 positionY, ArkUI_Float32 width, ArkUI_Float32 height)
257 {
258 auto* currentNode = reinterpret_cast<UINode*>(node);
259 auto renderContext = GetRenderContext(currentNode);
260 CHECK_NULL_VOID(renderContext);
261 renderContext->SetFrame(Dimension(positionX, DimensionUnit::VP).ConvertToPx(),
262 Dimension(positionY, DimensionUnit::VP).ConvertToPx(), Dimension(width, DimensionUnit::VP).ConvertToPx(),
263 Dimension(height, DimensionUnit::VP).ConvertToPx());
264 renderContext->RequestNextFrame();
265 }
266
SetSize(ArkUINodeHandle node,ArkUI_Float32 width,ArkUI_Float32 height,ArkUI_Int32 unitValue)267 void SetSize(ArkUINodeHandle node, ArkUI_Float32 width, ArkUI_Float32 height, ArkUI_Int32 unitValue)
268 {
269 auto* currentNode = reinterpret_cast<UINode*>(node);
270 auto* frameNode = AceType::DynamicCast<FrameNode>(currentNode);
271 CHECK_NULL_VOID(frameNode);
272 CHECK_NULL_VOID(frameNode->GetTag() != "BuilderProxyNode");
273 auto layoutProperty = frameNode->GetLayoutProperty();
274 CHECK_NULL_VOID(layoutProperty);
275 DimensionUnit unit = ConvertLengthMetricsUnitToDimensionUnit(unitValue, DimensionUnit::VP);
276 layoutProperty->UpdateUserDefinedIdealSize(
277 CalcSize(CalcLength(width, unit), CalcLength(height, unit)));
278 frameNode->MarkDirtyNode(NG::PROPERTY_UPDATE_MEASURE);
279 }
280
SetPosition(ArkUINodeHandle node,ArkUI_Float32 xAxis,ArkUI_Float32 yAxis,ArkUI_Int32 unitValue)281 void SetPosition(ArkUINodeHandle node, ArkUI_Float32 xAxis, ArkUI_Float32 yAxis, ArkUI_Int32 unitValue)
282 {
283 auto* currentNode = reinterpret_cast<UINode*>(node);
284 auto* frameNode = AceType::DynamicCast<FrameNode>(currentNode);
285 CHECK_NULL_VOID(frameNode);
286 CHECK_NULL_VOID(frameNode->GetTag() != "BuilderProxyNode");
287 const auto& renderContext = GetRenderContext(currentNode);
288 CHECK_NULL_VOID(renderContext);
289 renderContext->ResetPosition();
290
291 DimensionUnit unit = ConvertLengthMetricsUnitToDimensionUnit(unitValue, DimensionUnit::VP);
292 Dimension x = Dimension(xAxis, unit);
293 Dimension y = Dimension(yAxis, unit);
294 OffsetT<Dimension> value(x, y);
295 renderContext->UpdatePosition(value);
296 renderContext->RequestNextFrame();
297 }
298
SetOpacity(ArkUINodeHandle node,ArkUI_Float32 opacity)299 void SetOpacity(ArkUINodeHandle node, ArkUI_Float32 opacity)
300 {
301 auto* currentNode = reinterpret_cast<UINode*>(node);
302 auto renderContext = GetRenderContext(currentNode);
303 CHECK_NULL_VOID(renderContext);
304 renderContext->SetOpacity(opacity);
305 renderContext->RequestNextFrame();
306 }
307
SetTranslate(ArkUINodeHandle node,ArkUI_Float32 translateX,ArkUI_Float32 translateY,ArkUI_Float32 translateZ)308 void SetTranslate(ArkUINodeHandle node, ArkUI_Float32 translateX, ArkUI_Float32 translateY, ArkUI_Float32 translateZ)
309 {
310 auto* currentNode = reinterpret_cast<UINode*>(node);
311 auto renderContext = GetRenderContext(currentNode);
312 CHECK_NULL_VOID(renderContext);
313 renderContext->SetTranslate(translateX, translateY, translateZ);
314 renderContext->RequestNextFrame();
315 }
316
SetBorderStyle(ArkUINodeHandle node,ArkUI_Int32 left,ArkUI_Int32 top,ArkUI_Int32 right,ArkUI_Int32 bottom)317 void SetBorderStyle(ArkUINodeHandle node, ArkUI_Int32 left, ArkUI_Int32 top, ArkUI_Int32 right, ArkUI_Int32 bottom)
318 {
319 auto* currentNode = reinterpret_cast<UINode*>(node);
320 auto renderContext = GetRenderContext(currentNode);
321 CHECK_NULL_VOID(renderContext);
322 BorderStyleProperty borderStyleProperty {
323 .styleLeft = static_cast<BorderStyle>(left),
324 .styleRight = static_cast<BorderStyle>(right),
325 .styleTop = static_cast<BorderStyle>(top),
326 .styleBottom = static_cast<BorderStyle>(bottom),
327 .multiValued = true
328 };
329 renderContext->UpdateBorderStyle(borderStyleProperty);
330 }
331
SetBorderWidth(ArkUINodeHandle node,ArkUI_Float32 left,ArkUI_Float32 top,ArkUI_Float32 right,ArkUI_Float32 bottom,ArkUI_Int32 unitValue)332 void SetBorderWidth(ArkUINodeHandle node, ArkUI_Float32 left, ArkUI_Float32 top, ArkUI_Float32 right,
333 ArkUI_Float32 bottom, ArkUI_Int32 unitValue)
334 {
335 auto* currentNode = reinterpret_cast<UINode*>(node);
336 CHECK_NULL_VOID(currentNode);
337 auto renderContext = GetRenderContext(currentNode);
338 CHECK_NULL_VOID(renderContext);
339 auto* frameNode = reinterpret_cast<FrameNode*>(currentNode);
340 auto layoutProperty = frameNode->GetLayoutProperty<LayoutProperty>();
341 DimensionUnit unit = ConvertLengthMetricsUnitToDimensionUnit(unitValue, DimensionUnit::VP);
342 BorderWidthProperty borderWidthProperty {
343 .leftDimen = Dimension(left, unit),
344 .topDimen = Dimension(top, unit),
345 .rightDimen = Dimension(right, unit),
346 .bottomDimen = Dimension(bottom, unit),
347 .multiValued = true
348 };
349 layoutProperty->UpdateBorderWidth(borderWidthProperty);
350 frameNode->MarkDirtyNode();
351 renderContext->SetBorderWidth(borderWidthProperty);
352 }
353
SetBorderColor(ArkUINodeHandle node,uint32_t left,uint32_t top,uint32_t right,uint32_t bottom)354 void SetBorderColor(ArkUINodeHandle node, uint32_t left, uint32_t top, uint32_t right, uint32_t bottom)
355 {
356 auto* currentNode = reinterpret_cast<UINode*>(node);
357 CHECK_NULL_VOID(currentNode);
358 auto renderContext = GetRenderContext(currentNode);
359 CHECK_NULL_VOID(renderContext);
360
361 BorderColorProperty borderColorProperty {
362 .leftColor = Color(left),
363 .rightColor = Color(right),
364 .topColor = Color(top),
365 .bottomColor = Color(bottom),
366 .multiValued = true
367 };
368 renderContext->UpdateBorderColor(borderColorProperty);
369 }
370
SetBorderRadius(ArkUINodeHandle node,ArkUI_Float32 topLeft,ArkUI_Float32 topRight,ArkUI_Float32 bottomLeft,ArkUI_Float32 bottomRight,ArkUI_Int32 unitValue)371 void SetBorderRadius(ArkUINodeHandle node, ArkUI_Float32 topLeft, ArkUI_Float32 topRight, ArkUI_Float32 bottomLeft,
372 ArkUI_Float32 bottomRight, ArkUI_Int32 unitValue)
373 {
374 auto* currentNode = reinterpret_cast<UINode*>(node);
375 CHECK_NULL_VOID(currentNode);
376 auto renderContext = GetRenderContext(currentNode);
377 CHECK_NULL_VOID(renderContext);
378 DimensionUnit unit = ConvertLengthMetricsUnitToDimensionUnit(unitValue, DimensionUnit::VP);
379 BorderRadiusProperty borderRadiusProperty(Dimension(topLeft, unit),
380 Dimension(topRight, unit), Dimension(bottomRight, unit),
381 Dimension(bottomLeft, unit));
382 renderContext->UpdateBorderRadius(borderRadiusProperty);
383 }
384
SetRectMask(ArkUINodeHandle node,ArkUI_Float32 rectX,ArkUI_Float32 rectY,ArkUI_Float32 rectW,ArkUI_Float32 rectH,ArkUI_Uint32 fillColor,ArkUI_Uint32 strokeColor,ArkUI_Float32 strokeWidth)385 void SetRectMask(ArkUINodeHandle node,
386 ArkUI_Float32 rectX, ArkUI_Float32 rectY, ArkUI_Float32 rectW, ArkUI_Float32 rectH,
387 ArkUI_Uint32 fillColor, ArkUI_Uint32 strokeColor, ArkUI_Float32 strokeWidth)
388 {
389 auto* currentNode = reinterpret_cast<UINode*>(node);
390 CHECK_NULL_VOID(currentNode);
391 auto renderContext = GetRenderContext(currentNode);
392 CHECK_NULL_VOID(renderContext);
393
394 RectF rect(rectX, rectY, rectW, rectH);
395 ShapeMaskProperty property { fillColor, strokeColor, strokeWidth };
396 renderContext->SetRectMask(rect, property);
397 renderContext->RequestNextFrame();
398 }
399
SetCircleMask(ArkUINodeHandle node,ArkUI_Float32 centerXValue,ArkUI_Float32 centerYValue,ArkUI_Float32 radiusValue,ArkUI_Uint32 fillColor,ArkUI_Uint32 strokeColor,ArkUI_Float32 strokeWidth)400 void SetCircleMask(ArkUINodeHandle node,
401 ArkUI_Float32 centerXValue, ArkUI_Float32 centerYValue, ArkUI_Float32 radiusValue,
402 ArkUI_Uint32 fillColor, ArkUI_Uint32 strokeColor, ArkUI_Float32 strokeWidth)
403 {
404 auto* currentNode = reinterpret_cast<UINode*>(node);
405 CHECK_NULL_VOID(currentNode);
406 auto renderContext = GetRenderContext(currentNode);
407 CHECK_NULL_VOID(renderContext);
408
409 Circle circle;
410 Dimension centerX(centerXValue, DimensionUnit::PX);
411 circle.SetAxisX(centerX);
412 Dimension centerY(centerYValue, DimensionUnit::PX);
413 circle.SetAxisY(centerY);
414 Dimension radius(radiusValue, DimensionUnit::PX);
415 circle.SetRadius(radius);
416
417 ShapeMaskProperty property { fillColor, strokeColor, strokeWidth };
418
419 renderContext->SetCircleMask(circle, property);
420 renderContext->RequestNextFrame();
421 }
422
SetRoundRectMask(ArkUINodeHandle node,const ArkUI_Float32 * roundRect,const ArkUI_Uint32 roundRectSize,ArkUI_Uint32 fillColor,ArkUI_Uint32 strokeColor,ArkUI_Float32 strokeWidth)423 void SetRoundRectMask(ArkUINodeHandle node, const ArkUI_Float32* roundRect, const ArkUI_Uint32 roundRectSize,
424 ArkUI_Uint32 fillColor, ArkUI_Uint32 strokeColor, ArkUI_Float32 strokeWidth)
425 {
426 auto* currentNode = reinterpret_cast<UINode*>(node);
427 CHECK_NULL_VOID(currentNode);
428 auto renderContext = GetRenderContext(currentNode);
429 CHECK_NULL_VOID(renderContext);
430
431 RoundRect roundRectInstance;
432 roundRectInstance.SetCornerRadius(RoundRect::CornerPos::TOP_LEFT_POS,
433 roundRect[TOP_LEFT_X_VALUE], roundRect[TOP_LEFT_Y_VALUE]);
434 roundRectInstance.SetCornerRadius(RoundRect::CornerPos::TOP_RIGHT_POS,
435 roundRect[TOP_RIGHT_X_VALUE], roundRect[TOP_RIGHT_Y_VALUE]);
436 roundRectInstance.SetCornerRadius(RoundRect::CornerPos::BOTTOM_LEFT_POS,
437 roundRect[BOTTOM_LEFT_X_VALUE], roundRect[BOTTOM_LEFT_Y_VALUE]);
438 roundRectInstance.SetCornerRadius(RoundRect::CornerPos::BOTTOM_RIGHT_POS,
439 roundRect[BOTTOM_RIGHT_X_VALUE], roundRect[BOTTOM_RIGHT_Y_VALUE]);
440
441 RectF rect(roundRect[LEFT_VALUE], roundRect[TOP_VALUE], roundRect[WIDTH_VALUE], roundRect[HEIGHT_VALUE]);
442 roundRectInstance.SetRect(rect);
443
444 ShapeMaskProperty property { fillColor, strokeColor, strokeWidth };
445
446 renderContext->SetRoundRectMask(roundRectInstance, property);
447 renderContext->RequestNextFrame();
448 }
449
SetOvalMask(ArkUINodeHandle node,ArkUI_Float32 rectX,ArkUI_Float32 rectY,ArkUI_Float32 rectW,ArkUI_Float32 rectH,ArkUI_Uint32 fillColor,ArkUI_Uint32 strokeColor,ArkUI_Float32 strokeWidth)450 void SetOvalMask(ArkUINodeHandle node,
451 ArkUI_Float32 rectX, ArkUI_Float32 rectY, ArkUI_Float32 rectW, ArkUI_Float32 rectH,
452 ArkUI_Uint32 fillColor, ArkUI_Uint32 strokeColor, ArkUI_Float32 strokeWidth)
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 ShapeMaskProperty property { fillColor, strokeColor, strokeWidth };
461 renderContext->SetOvalMask(rect, property);
462 renderContext->RequestNextFrame();
463 }
464
SetCommandPathMask(ArkUINodeHandle node,ArkUI_CharPtr commands,ArkUI_Uint32 fillColor,ArkUI_Uint32 strokeColor,ArkUI_Float32 strokeWidth)465 void SetCommandPathMask(ArkUINodeHandle node, ArkUI_CharPtr commands, ArkUI_Uint32 fillColor, ArkUI_Uint32 strokeColor,
466 ArkUI_Float32 strokeWidth)
467 {
468 auto* currentNode = reinterpret_cast<UINode*>(node);
469 CHECK_NULL_VOID(currentNode);
470 auto renderContext = GetRenderContext(currentNode);
471 CHECK_NULL_VOID(renderContext);
472
473 ShapeMaskProperty property { fillColor, strokeColor, strokeWidth };
474 renderContext->SetCommandPathMask(std::string(commands), property);
475 renderContext->RequestNextFrame();
476 }
477
SetRectClip(ArkUINodeHandle node,ArkUI_Float32 rectX,ArkUI_Float32 rectY,ArkUI_Float32 rectW,ArkUI_Float32 rectH)478 void SetRectClip(
479 ArkUINodeHandle node, ArkUI_Float32 rectX, ArkUI_Float32 rectY, ArkUI_Float32 rectW, ArkUI_Float32 rectH)
480 {
481 auto* currentNode = reinterpret_cast<UINode*>(node);
482 CHECK_NULL_VOID(currentNode);
483 auto renderContext = GetRenderContext(currentNode);
484 CHECK_NULL_VOID(renderContext);
485
486 RectF rect(rectX, rectY, rectW, rectH);
487 renderContext->ClipWithRect(rect);
488 renderContext->RequestNextFrame();
489 }
490
SetCircleClip(ArkUINodeHandle node,ArkUI_Float32 centerXValue,ArkUI_Float32 centerYValue,ArkUI_Float32 radiusValue)491 void SetCircleClip(
492 ArkUINodeHandle node, ArkUI_Float32 centerXValue, ArkUI_Float32 centerYValue, ArkUI_Float32 radiusValue)
493 {
494 auto* currentNode = reinterpret_cast<UINode*>(node);
495 CHECK_NULL_VOID(currentNode);
496 auto renderContext = GetRenderContext(currentNode);
497 CHECK_NULL_VOID(renderContext);
498
499 Circle circle;
500 Dimension centerX(centerXValue, DimensionUnit::PX);
501 circle.SetAxisX(centerX);
502 Dimension centerY(centerYValue, DimensionUnit::PX);
503 circle.SetAxisY(centerY);
504 Dimension radius(radiusValue, DimensionUnit::PX);
505 circle.SetRadius(radius);
506
507 renderContext->ClipWithCircle(circle);
508 renderContext->RequestNextFrame();
509 }
510
SetRoundRectClip(ArkUINodeHandle node,const ArkUI_Float32 * roundRect,const ArkUI_Uint32 roundRectSize)511 void SetRoundRectClip(ArkUINodeHandle node, const ArkUI_Float32* roundRect, const ArkUI_Uint32 roundRectSize)
512 {
513 auto* currentNode = reinterpret_cast<UINode*>(node);
514 CHECK_NULL_VOID(currentNode);
515 auto renderContext = GetRenderContext(currentNode);
516 CHECK_NULL_VOID(renderContext);
517
518 RoundRect roundRectInstance;
519 roundRectInstance.SetCornerRadius(
520 RoundRect::CornerPos::TOP_LEFT_POS, roundRect[TOP_LEFT_X_VALUE], roundRect[TOP_LEFT_Y_VALUE]);
521 roundRectInstance.SetCornerRadius(
522 RoundRect::CornerPos::TOP_RIGHT_POS, roundRect[TOP_RIGHT_X_VALUE], roundRect[TOP_RIGHT_Y_VALUE]);
523 roundRectInstance.SetCornerRadius(
524 RoundRect::CornerPos::BOTTOM_LEFT_POS, roundRect[BOTTOM_LEFT_X_VALUE], roundRect[BOTTOM_LEFT_Y_VALUE]);
525 roundRectInstance.SetCornerRadius(
526 RoundRect::CornerPos::BOTTOM_RIGHT_POS, roundRect[BOTTOM_RIGHT_X_VALUE], roundRect[BOTTOM_RIGHT_Y_VALUE]);
527
528 RectF rect(roundRect[LEFT_VALUE], roundRect[TOP_VALUE], roundRect[WIDTH_VALUE], roundRect[HEIGHT_VALUE]);
529 roundRectInstance.SetRect(rect);
530
531 renderContext->ClipWithRoundRect(roundRectInstance);
532 renderContext->RequestNextFrame();
533 }
534
SetOvalClip(ArkUINodeHandle node,ArkUI_Float32 rectX,ArkUI_Float32 rectY,ArkUI_Float32 rectW,ArkUI_Float32 rectH)535 void SetOvalClip(
536 ArkUINodeHandle node, ArkUI_Float32 rectX, ArkUI_Float32 rectY, ArkUI_Float32 rectW, ArkUI_Float32 rectH)
537 {
538 auto* currentNode = reinterpret_cast<UINode*>(node);
539 CHECK_NULL_VOID(currentNode);
540 auto renderContext = GetRenderContext(currentNode);
541 CHECK_NULL_VOID(renderContext);
542
543 RectF rect(rectX, rectY, rectW, rectH);
544 renderContext->ClipWithOval(rect);
545 renderContext->RequestNextFrame();
546 }
547
SetCommandPathClip(ArkUINodeHandle node,ArkUI_CharPtr commands)548 void SetCommandPathClip(ArkUINodeHandle node, ArkUI_CharPtr commands)
549 {
550 auto* currentNode = reinterpret_cast<UINode*>(node);
551 CHECK_NULL_VOID(currentNode);
552 auto renderContext = GetRenderContext(currentNode);
553 CHECK_NULL_VOID(renderContext);
554
555 renderContext->SetClipBoundsWithCommands(std::string(commands));
556 renderContext->RequestNextFrame();
557 }
558
SetMarkNodeGroup(ArkUINodeHandle node,ArkUI_Bool isNodeGroup)559 void SetMarkNodeGroup(ArkUINodeHandle node, ArkUI_Bool isNodeGroup)
560 {
561 auto* currentNode = reinterpret_cast<UINode*>(node);
562 CHECK_NULL_VOID(currentNode);
563 auto renderContext = GetRenderContext(currentNode);
564 CHECK_NULL_VOID(renderContext);
565
566 renderContext->SetMarkNodeGroup(isNodeGroup);
567 auto* frameNode = AceType::DynamicCast<FrameNode>(currentNode);
568 if (frameNode) {
569 frameNode->SetApplicationRenderGroupMarked(true);
570 }
571 renderContext->RequestNextFrame();
572 }
573
SetTransformScale(ArkUINodeHandle node,ArkUI_Float32 xF,ArkUI_Float32 yF)574 void SetTransformScale(ArkUINodeHandle node, ArkUI_Float32 xF, ArkUI_Float32 yF)
575 {
576 auto* currentNode = reinterpret_cast<UINode*>(node);
577 CHECK_NULL_VOID(currentNode);
578 auto renderContext = GetRenderContext(currentNode);
579 CHECK_NULL_VOID(renderContext);
580
581 VectorF scaleValue = VectorF(xF, yF);
582 renderContext->UpdateTransformScale(scaleValue);
583 renderContext->RequestNextFrame();
584 }
585
GetNodeTypeInRenderNode(ArkUINodeHandle node)586 ArkUI_CharPtr GetNodeTypeInRenderNode(ArkUINodeHandle node)
587 {
588 auto* currentNode = reinterpret_cast<UINode*>(node);
589 CHECK_NULL_RETURN(currentNode, "");
590 static std::string nodeType = currentNode->GetTag();
591 return nodeType.c_str();
592 }
593
594 namespace NodeModifier {
GetRenderNodeModifier()595 const ArkUIRenderNodeModifier* GetRenderNodeModifier()
596 {
597 CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
598 static const ArkUIRenderNodeModifier modifier = {
599 .addBuilderNode = AddBuilderNode,
600 .appendChild = AppendChild,
601 .insertChildAfter = InsertChildAfter,
602 .removeBuilderNode = RemoveBuilderNode,
603 .removeChild = RemoveChild,
604 .clearBuilderNode = ClearBuilderNode,
605 .clearChildren = ClearChildren,
606 .setClipToFrame = SetClipToFrame,
607 .setRotation = SetRotation,
608 .setShadowColor = SetShadowColor,
609 .setShadowOffset = SetShadowOffset,
610 .setLabel = SetLabel,
611 .setShadowAlpha = SetShadowAlpha,
612 .setShadowElevation = SetShadowElevation,
613 .setShadowRadius = SetShadowRadius,
614 .invalidate = Invalidate,
615 .setScale = SetScale,
616 .setRenderNodeBackgroundColor = SetRenderNodeBackgroundColor,
617 .setPivot = SetPivot,
618 .setFrame = SetFrame,
619 .setSize = SetSize,
620 .setOpacity = SetOpacity,
621 .setTranslate = SetTranslate,
622 .setBorderStyle = SetBorderStyle,
623 .setBorderWidth = SetBorderWidth,
624 .setBorderColor = SetBorderColor,
625 .setBorderRadius = SetBorderRadius,
626 .setRectMask = SetRectMask,
627 .setCircleMask = SetCircleMask,
628 .setRoundRectMask = SetRoundRectMask,
629 .setOvalMask = SetOvalMask,
630 .setCommandPathMask = SetCommandPathMask,
631 .setRectClip = SetRectClip,
632 .setCircleClip = SetCircleClip,
633 .setRoundRectClip = SetRoundRectClip,
634 .setOvalClip = SetOvalClip,
635 .setCommandPathClip = SetCommandPathClip,
636 .setPosition = SetPosition,
637 .setMarkNodeGroup = SetMarkNodeGroup,
638 .setTransformScale = SetTransformScale,
639 .getNodeType = GetNodeTypeInRenderNode,
640 };
641 CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
642
643 return &modifier;
644 }
645
GetCJUIRenderNodeModifier()646 const CJUIRenderNodeModifier* GetCJUIRenderNodeModifier()
647 {
648 CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
649 static const CJUIRenderNodeModifier modifier = {
650 .appendChild = AppendChild,
651 .insertChildAfter = InsertChildAfter,
652 .removeChild = RemoveChild,
653 .clearChildren = ClearChildren,
654 .setClipToFrame = SetClipToFrame,
655 .setRotation = SetRotation,
656 .setShadowColor = SetShadowColor,
657 .setShadowOffset = SetShadowOffset,
658 .setShadowAlpha = SetShadowAlpha,
659 .setShadowElevation = SetShadowElevation,
660 .setShadowRadius = SetShadowRadius,
661 .invalidate = Invalidate,
662 .setScale = SetScale,
663 .setRenderNodeBackgroundColor = SetRenderNodeBackgroundColor,
664 .setPivot = SetPivot,
665 .setFrame = SetFrame,
666 .setSize = SetSize,
667 .setOpacity = SetOpacity,
668 .setTranslate = SetTranslate,
669 .setBorderStyle = SetBorderStyle,
670 .setBorderWidth = SetBorderWidth,
671 .setBorderColor = SetBorderColor,
672 .setBorderRadius = SetBorderRadius,
673 .setRectMask = SetRectMask,
674 .setCircleMask = SetCircleMask,
675 .setRoundRectMask = SetRoundRectMask,
676 .setOvalMask = SetOvalMask,
677 .setCommandPathMask = SetCommandPathMask,
678 .setPosition = SetPosition,
679 .setMarkNodeGroup = SetMarkNodeGroup,
680 };
681 CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
682
683 return &modifier;
684 }
685 }
686 } // namespace OHOS::Ace::NG
687