• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 
16 #include "ui/rs_node.h"
17 
18 #include <algorithm>
19 #include <vector>
20 #include <memory>
21 #include <sstream>
22 #include <string>
23 #include <vector>
24 
25 #include "feature/hyper_graphic_manager/rs_frame_rate_policy.h"
26 #include "rs_trace.h"
27 #include "sandbox_utils.h"
28 #include "ui_effect/mask/include/ripple_mask_para.h"
29 #include "ui_effect/property/include/rs_ui_filter_base.h"
30 #include "ui_effect/property/include/rs_ui_shader_base.h"
31 
32 #include "animation/rs_animation.h"
33 #include "animation/rs_animation_callback.h"
34 #include "animation/rs_animation_group.h"
35 #include "animation/rs_implicit_animation_param.h"
36 #include "animation/rs_implicit_animator.h"
37 #include "animation/rs_implicit_animator_map.h"
38 #include "animation/rs_render_particle_animation.h"
39 #include "command/rs_base_node_command.h"
40 #include "command/rs_node_command.h"
41 #include "common/rs_color.h"
42 #include "common/rs_common_def.h"
43 #include "common/rs_obj_abs_geometry.h"
44 #include "common/rs_optional_trace.h"
45 #include "common/rs_vector4.h"
46 #include "feature/composite_layer/rs_composite_layer_utils.h"
47 #include "modifier/rs_modifier_manager_map.h"
48 #include "modifier/rs_property.h"
49 #include "modifier_ng/appearance/rs_alpha_modifier.h"
50 #include "modifier_ng/appearance/rs_background_filter_modifier.h"
51 #include "modifier_ng/appearance/rs_blend_modifier.h"
52 #include "modifier_ng/appearance/rs_border_modifier.h"
53 #include "modifier_ng/appearance/rs_compositing_filter_modifier.h"
54 #include "modifier_ng/appearance/rs_dynamic_light_up_modifier.h"
55 #include "modifier_ng/appearance/rs_foreground_filter_modifier.h"
56 #include "modifier_ng/appearance/rs_hdr_brightness_modifier.h"
57 #include "modifier_ng/appearance/rs_mask_modifier.h"
58 #include "modifier_ng/appearance/rs_outline_modifier.h"
59 #include "modifier_ng/appearance/rs_particle_effect_modifier.h"
60 #include "modifier_ng/appearance/rs_pixel_stretch_modifier.h"
61 #include "modifier_ng/appearance/rs_point_light_modifier.h"
62 #include "modifier_ng/appearance/rs_shadow_modifier.h"
63 #include "modifier_ng/appearance/rs_use_effect_modifier.h"
64 #include "modifier_ng/appearance/rs_visibility_modifier.h"
65 #include "modifier_ng/background/rs_background_color_modifier.h"
66 #include "modifier_ng/background/rs_background_image_modifier.h"
67 #include "modifier_ng/background/rs_background_ng_shader_modifier.h"
68 #include "modifier_ng/background/rs_background_shader_modifier.h"
69 #include "modifier_ng/custom/rs_custom_modifier.h"
70 #include "modifier_ng/foreground/rs_env_foreground_color_modifier.h"
71 #include "modifier_ng/foreground/rs_foreground_color_modifier.h"
72 #include "modifier_ng/foreground/rs_foreground_shader_modifier.h"
73 #include "modifier_ng/geometry/rs_bounds_clip_modifier.h"
74 #include "modifier_ng/geometry/rs_bounds_modifier.h"
75 #include "modifier_ng/geometry/rs_frame_clip_modifier.h"
76 #include "modifier_ng/geometry/rs_frame_modifier.h"
77 #include "modifier_ng/geometry/rs_transform_modifier.h"
78 #include "modifier_ng/rs_modifier_ng.h"
79 #include "pipeline/rs_node_map.h"
80 #include "platform/common/rs_log.h"
81 #include "render/rs_blur_filter.h"
82 #include "render/rs_border_light_shader.h"
83 #include "render/rs_filter.h"
84 #include "render/rs_material_filter.h"
85 #include "render/rs_path.h"
86 #include "transaction/rs_transaction_proxy.h"
87 #include "ui/rs_canvas_drawing_node.h"
88 #include "ui/rs_canvas_node.h"
89 #include "ui/rs_display_node.h"
90 #include "ui/rs_effect_node.h"
91 #include "ui/rs_proxy_node.h"
92 #include "ui/rs_root_node.h"
93 #include "ui/rs_surface_node.h"
94 #include "ui/rs_ui_context.h"
95 #include "ui/rs_ui_director.h"
96 #include "ui/rs_ui_patten_vec.h"
97 
98 #ifdef RS_ENABLE_VK
99 #include "modifier_render_thread/rs_modifiers_draw.h"
100 #endif
101 
102 #ifdef _WIN32
103 #include <windows.h>
104 #define gettid GetCurrentThreadId
105 #endif
106 
107 #ifdef __APPLE__
108 #define gettid getpid
109 #endif
110 
111 #ifdef __gnu_linux__
112 #include <sys/syscall.h>
113 #include <sys/types.h>
114 #define gettid []() -> int32_t { return static_cast<int32_t>(syscall(SYS_gettid)); }
115 #endif
116 
117 #undef LOG_TAG
118 #define LOG_TAG "RSNode"
119 
120 namespace OHOS {
121 namespace Rosen {
122 namespace {
123 static bool g_isUniRenderEnabled = false;
124 static const std::unordered_map<RSUINodeType, std::string> RSUINodeTypeStrs = {
125     {RSUINodeType::UNKNOW,              "UNKNOW"},
126     {RSUINodeType::DISPLAY_NODE,        "DisplayNode"},
127     {RSUINodeType::RS_NODE,             "RsNode"},
128     {RSUINodeType::SURFACE_NODE,        "SurfaceNode"},
129     {RSUINodeType::PROXY_NODE,          "ProxyNode"},
130     {RSUINodeType::CANVAS_NODE,         "CanvasNode"},
131     {RSUINodeType::ROOT_NODE,           "RootNode"},
132     {RSUINodeType::EFFECT_NODE,         "EffectNode"},
133     {RSUINodeType::CANVAS_DRAWING_NODE, "CanvasDrawingNode"},
134 };
135 
136 std::once_flag flag_;
137 } // namespace
138 
RSNode(bool isRenderServiceNode,NodeId id,bool isTextureExportNode,std::shared_ptr<RSUIContext> rsUIContext,bool isOnTheTree)139 RSNode::RSNode(bool isRenderServiceNode, NodeId id, bool isTextureExportNode, std::shared_ptr<RSUIContext> rsUIContext,
140     bool isOnTheTree)
141     : isRenderServiceNode_(isRenderServiceNode), isTextureExportNode_(isTextureExportNode), id_(id),
142       rsUIContext_(rsUIContext), stagingPropertiesExtractor_(id, rsUIContext),
143       showingPropertiesFreezer_(id, rsUIContext), isOnTheTree_(isOnTheTree)
144 {
145     InitUniRenderEnabled();
146     if (auto rsUIContextPtr = rsUIContext_.lock()) {
147         auto transaction = rsUIContextPtr->GetRSTransaction();
148         if (transaction != nullptr && g_isUniRenderEnabled && isTextureExportNode) {
149             std::call_once(flag_, [transaction]() {
150                 auto renderThreadClient = RSIRenderClient::CreateRenderThreadClient();
151                 transaction->SetRenderThreadClient(renderThreadClient);
152             });
153         }
154         hasCreateRenderNodeInRT_ = isTextureExportNode;
155         hasCreateRenderNodeInRS_ = !hasCreateRenderNodeInRT_;
156         return;
157     }
158     if (g_isUniRenderEnabled && isTextureExportNode) {
159         std::call_once(flag_, []() {
160             auto renderThreadClient = RSIRenderClient::CreateRenderThreadClient();
161             auto transactionProxy = RSTransactionProxy::GetInstance();
162             if (transactionProxy != nullptr) {
163                 transactionProxy->SetRenderThreadClient(renderThreadClient);
164             }
165         });
166     }
167     hasCreateRenderNodeInRT_ = isTextureExportNode;
168     hasCreateRenderNodeInRS_ = !hasCreateRenderNodeInRT_;
169 }
170 
RSNode(bool isRenderServiceNode,bool isTextureExportNode,std::shared_ptr<RSUIContext> rsUIContext,bool isOnTheTree)171 RSNode::RSNode(bool isRenderServiceNode, bool isTextureExportNode, std::shared_ptr<RSUIContext> rsUIContext,
172     bool isOnTheTree)
173     : RSNode(isRenderServiceNode, GenerateId(), isTextureExportNode, rsUIContext, isOnTheTree) {}
174 
~RSNode()175 RSNode::~RSNode()
176 {
177     if (!FallbackAnimationsToContext()) {
178         FallbackAnimationsToRoot();
179     }
180     ClearAllModifiers();
181 #ifdef RS_ENABLE_VK
182     RSModifiersDraw::EraseOffTreeNode(instanceId_, id_);
183     if (RSSystemProperties::GetHybridRenderEnabled()) {
184         RSModifiersDraw::EraseDrawRegions(id_);
185     }
186 #endif
187 
188     // break current (ui) parent-child relationship.
189     // render nodes will check if its child is expired and remove it, no need to manually remove it here.
190     SharedPtr parentPtr = parent_.lock();
191     if (parentPtr) {
192         parentPtr->children_.erase(std::remove_if(parentPtr->children_.begin(), parentPtr->children_.end(),
193                                                   [](const auto& child) { return child.expired(); }),
194             parentPtr->children_.end());
195     }
196     auto rsUIContext = rsUIContext_.lock();
197     // To prevent a process from repeatedly serializing and generating different node objects, it is necessary to place
198     // the nodes in a globally static map. Therefore, when disassembling, the global map needs to be deleted
199     if (skipDestroyCommandInDestructor_ && rsUIContext) {
200         RSNodeMap::MutableInstance().UnregisterNode(id_);
201     }
202     if (rsUIContext != nullptr) {
203         // tell RT/RS to destroy related render node
204         rsUIContext->GetMutableNodeMap().UnregisterNode(id_);
205         auto transaction = rsUIContext->GetRSTransaction();
206         if (transaction == nullptr || skipDestroyCommandInDestructor_) {
207             RS_LOGD("RSNode::~RSNode stop destroy proxy:%{public}d, skip: %{public}d", transaction == nullptr,
208                 skipDestroyCommandInDestructor_);
209             return;
210         }
211         std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeDestroy>(id_);
212         transaction->AddCommand(command, IsRenderServiceNode());
213         if ((IsRenderServiceNode() && hasCreateRenderNodeInRT_) ||
214             (!IsRenderServiceNode() && hasCreateRenderNodeInRS_)) {
215             command = std::make_unique<RSBaseNodeDestroy>(id_);
216             transaction->AddCommand(command, !IsRenderServiceNode());
217         }
218     } else {
219         RSNodeMap::MutableInstance().UnregisterNode(id_);
220         // tell RT/RS to destroy related render node
221         auto transactionProxy = RSTransactionProxy::GetInstance();
222         if (transactionProxy == nullptr || skipDestroyCommandInDestructor_) {
223             RS_LOGD("RSNode::~RSNode stop destroy proxy:%{public}d, skip: %{public}d", transactionProxy == nullptr,
224                 skipDestroyCommandInDestructor_);
225             return;
226         }
227         std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeDestroy>(id_);
228         transactionProxy->AddCommand(command, IsRenderServiceNode());
229         if ((IsRenderServiceNode() && hasCreateRenderNodeInRT_) ||
230             (!IsRenderServiceNode() && hasCreateRenderNodeInRS_)) {
231             command = std::make_unique<RSBaseNodeDestroy>(id_);
232             transactionProxy->AddCommand(command, !IsRenderServiceNode());
233         }
234     }
235 }
236 
GetRSTransaction() const237 std::shared_ptr<RSTransactionHandler> RSNode::GetRSTransaction() const
238 {
239     auto rsUIContext = rsUIContext_.lock();
240     if (!rsUIContext) {
241         return nullptr;
242     }
243     return rsUIContext->GetRSTransaction();
244 }
245 
OpenImplicitAnimation(const RSAnimationTimingProtocol & timingProtocol,const RSAnimationTimingCurve & timingCurve,const std::function<void ()> & finishCallback)246 void RSNode::OpenImplicitAnimation(const RSAnimationTimingProtocol& timingProtocol,
247     const RSAnimationTimingCurve& timingCurve, const std::function<void()>& finishCallback)
248 {
249     auto implicitAnimator = RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
250     if (implicitAnimator == nullptr) {
251         ROSEN_LOGE("Failed to open implicit animation, implicit animator is null!");
252         return;
253     }
254 
255     std::shared_ptr<AnimationFinishCallback> animationFinishCallback;
256     if (finishCallback != nullptr) {
257         animationFinishCallback =
258             std::make_shared<AnimationFinishCallback>(finishCallback, timingProtocol.GetFinishCallbackType());
259     }
260     implicitAnimator->OpenImplicitAnimation(timingProtocol, timingCurve, std::move(animationFinishCallback));
261 }
262 
OpenImplicitAnimation(const std::shared_ptr<RSUIContext> rsUIContext,const RSAnimationTimingProtocol & timingProtocol,const RSAnimationTimingCurve & timingCurve,const std::function<void ()> & finishCallback)263 void RSNode::OpenImplicitAnimation(const std::shared_ptr<RSUIContext> rsUIContext,
264     const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve,
265     const std::function<void()>& finishCallback)
266 {
267     auto implicitAnimator =
268         rsUIContext ? rsUIContext->GetRSImplicitAnimator() : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
269     if (implicitAnimator == nullptr) {
270         ROSEN_LOGE("Failed to open implicit animation, implicit animator is null!");
271         return;
272     }
273 
274     std::shared_ptr<AnimationFinishCallback> animationFinishCallback;
275     if (finishCallback != nullptr) {
276         animationFinishCallback =
277             std::make_shared<AnimationFinishCallback>(finishCallback, timingProtocol.GetFinishCallbackType());
278     }
279     implicitAnimator->OpenImplicitAnimation(timingProtocol, timingCurve, std::move(animationFinishCallback));
280 }
281 
CloseImplicitAnimation()282 std::vector<std::shared_ptr<RSAnimation>> RSNode::CloseImplicitAnimation()
283 {
284     auto implicitAnimator = RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
285     if (implicitAnimator == nullptr) {
286         ROSEN_LOGE("Failed to close implicit animation, implicit animator is null!");
287         return {};
288     }
289 
290     return implicitAnimator->CloseImplicitAnimation();
291 }
292 
CloseImplicitAnimation(const std::shared_ptr<RSUIContext> rsUIContext)293 std::vector<std::shared_ptr<RSAnimation>> RSNode::CloseImplicitAnimation(const std::shared_ptr<RSUIContext> rsUIContext)
294 {
295     auto implicitAnimator =
296         rsUIContext ? rsUIContext->GetRSImplicitAnimator() : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
297     if (implicitAnimator == nullptr) {
298         ROSEN_LOGE("multi-instance Failed to close implicit animation, implicit animator is null!");
299         return {};
300     }
301 
302     return implicitAnimator->CloseImplicitAnimation();
303 }
304 
CloseImplicitCancelAnimation()305 bool RSNode::CloseImplicitCancelAnimation()
306 {
307     auto implicitAnimator = RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
308     if (implicitAnimator == nullptr) {
309         ROSEN_LOGE("Failed to close implicit animation for cancel, implicit animator is null!");
310         return false;
311     }
312 
313     return implicitAnimator->CloseImplicitCancelAnimation() == CancelAnimationStatus::SUCCESS ? true : false;
314 }
315 
CloseImplicitCancelAnimation(const std::shared_ptr<RSUIContext> rsUIContext)316 bool RSNode::CloseImplicitCancelAnimation(const std::shared_ptr<RSUIContext> rsUIContext)
317 {
318     auto implicitAnimator =
319         rsUIContext ? rsUIContext->GetRSImplicitAnimator() : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
320     if (implicitAnimator == nullptr) {
321         ROSEN_LOGE("multi-instance Failed to close implicit animation for cancel, implicit animator is null!");
322         return false;
323     }
324 
325     return implicitAnimator->CloseImplicitCancelAnimation() == CancelAnimationStatus::SUCCESS ? true : false;
326 }
327 
CloseImplicitCancelAnimationReturnStatus(const std::shared_ptr<RSUIContext> rsUIContext)328 CancelAnimationStatus RSNode::CloseImplicitCancelAnimationReturnStatus(const std::shared_ptr<RSUIContext> rsUIContext)
329 {
330     auto implicitAnimator =
331         rsUIContext ? rsUIContext->GetRSImplicitAnimator() : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
332     if (implicitAnimator == nullptr) {
333         ROSEN_LOGE("multi-instance Failed to close implicit animation for cancel, implicit animator is null!");
334         return CancelAnimationStatus::NULL_ANIMATOR;
335     }
336 
337     return implicitAnimator->CloseImplicitCancelAnimation();
338 }
339 
SetFrameNodeInfo(int32_t id,std::string tag)340 void RSNode::SetFrameNodeInfo(int32_t id, std::string tag)
341 {
342     frameNodeId_ = id;
343     frameNodeTag_ = tag;
344 #ifdef SUBTREE_PARALLEL_ENABLE
345     MarkRepaintBoundary(tag);
346 #endif
347 }
348 
GetFrameNodeId()349 int32_t RSNode::GetFrameNodeId()
350 {
351     return frameNodeId_;
352 }
353 
GetFrameNodeTag()354 std::string RSNode::GetFrameNodeTag()
355 {
356     return frameNodeTag_;
357 }
358 
AddKeyFrame(float fraction,const RSAnimationTimingCurve & timingCurve,const PropertyCallback & propertyCallback)359 void RSNode::AddKeyFrame(
360     float fraction, const RSAnimationTimingCurve& timingCurve, const PropertyCallback& propertyCallback)
361 {
362     auto implicitAnimator = RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
363     if (implicitAnimator == nullptr) {
364         ROSEN_LOGE("Failed to add keyframe, implicit animator is null!");
365         return;
366     }
367 
368     implicitAnimator->BeginImplicitKeyFrameAnimation(fraction, timingCurve);
369     propertyCallback();
370     implicitAnimator->EndImplicitKeyFrameAnimation();
371 }
372 
AddKeyFrame(const std::shared_ptr<RSUIContext> rsUIContext,float fraction,const RSAnimationTimingCurve & timingCurve,const PropertyCallback & propertyCallback)373 void RSNode::AddKeyFrame(const std::shared_ptr<RSUIContext> rsUIContext,
374     float fraction, const RSAnimationTimingCurve& timingCurve, const PropertyCallback& propertyCallback)
375 {
376     auto implicitAnimator = rsUIContext ? rsUIContext->GetRSImplicitAnimator()
377                                         : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
378     if (implicitAnimator == nullptr) {
379         ROSEN_LOGE("Failed to add keyframe, implicit animator is null!");
380         return;
381     }
382 
383     implicitAnimator->BeginImplicitKeyFrameAnimation(fraction, timingCurve);
384     propertyCallback();
385     implicitAnimator->EndImplicitKeyFrameAnimation();
386 }
387 
AddKeyFrame(float fraction,const PropertyCallback & propertyCallback)388 void RSNode::AddKeyFrame(float fraction, const PropertyCallback& propertyCallback)
389 {
390     auto implicitAnimator = RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
391     if (implicitAnimator == nullptr) {
392         ROSEN_LOGE("Failed to add keyframe, implicit animator is null!");
393         return;
394     }
395 
396     implicitAnimator->BeginImplicitKeyFrameAnimation(fraction);
397     propertyCallback();
398     implicitAnimator->EndImplicitKeyFrameAnimation();
399 }
400 
AddKeyFrame(const std::shared_ptr<RSUIContext> rsUIContext,float fraction,const PropertyCallback & propertyCallback)401 void RSNode::AddKeyFrame(const std::shared_ptr<RSUIContext> rsUIContext,
402     float fraction, const PropertyCallback& propertyCallback)
403 {
404     auto implicitAnimator = rsUIContext ? rsUIContext->GetRSImplicitAnimator()
405                                         : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
406     if (implicitAnimator == nullptr) {
407         ROSEN_LOGE("Failed to add keyframe, implicit animator is null!");
408         return;
409     }
410 
411     implicitAnimator->BeginImplicitKeyFrameAnimation(fraction);
412     propertyCallback();
413     implicitAnimator->EndImplicitKeyFrameAnimation();
414 }
415 
AddDurationKeyFrame(int duration,const RSAnimationTimingCurve & timingCurve,const PropertyCallback & propertyCallback)416 void RSNode::AddDurationKeyFrame(
417     int duration, const RSAnimationTimingCurve& timingCurve, const PropertyCallback& propertyCallback)
418 {
419     auto implicitAnimator = RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
420     if (implicitAnimator == nullptr) {
421         ROSEN_LOGE("Failed to add keyframe, implicit animator is null!");
422         return;
423     }
424 
425     implicitAnimator->BeginImplicitDurationKeyFrameAnimation(duration, timingCurve);
426     propertyCallback();
427     implicitAnimator->EndImplicitDurationKeyFrameAnimation();
428 }
429 
AddDurationKeyFrame(const std::shared_ptr<RSUIContext> rsUIContext,int duration,const RSAnimationTimingCurve & timingCurve,const PropertyCallback & propertyCallback)430 void RSNode::AddDurationKeyFrame(const std::shared_ptr<RSUIContext> rsUIContext,
431     int duration, const RSAnimationTimingCurve& timingCurve, const PropertyCallback& propertyCallback)
432 {
433     auto implicitAnimator = rsUIContext ? rsUIContext->GetRSImplicitAnimator()
434                                         : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
435     if (implicitAnimator == nullptr) {
436         ROSEN_LOGE("Failed to add keyframe, implicit animator is null!");
437         return;
438     }
439 
440     implicitAnimator->BeginImplicitDurationKeyFrameAnimation(duration, timingCurve);
441     propertyCallback();
442     implicitAnimator->EndImplicitDurationKeyFrameAnimation();
443 }
444 
IsImplicitAnimationOpen()445 bool RSNode::IsImplicitAnimationOpen()
446 {
447     auto implicitAnimator = RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
448     return implicitAnimator && implicitAnimator->NeedImplicitAnimation();
449 }
450 
IsImplicitAnimationOpen(const std::shared_ptr<RSUIContext> rsUIContext)451 bool RSNode::IsImplicitAnimationOpen(const std::shared_ptr<RSUIContext> rsUIContext)
452 {
453     auto implicitAnimator = rsUIContext ? rsUIContext->GetRSImplicitAnimator()
454                                         : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
455     return implicitAnimator && implicitAnimator->NeedImplicitAnimation();
456 }
457 
Animate(const RSAnimationTimingProtocol & timingProtocol,const RSAnimationTimingCurve & timingCurve,const PropertyCallback & propertyCallback,const std::function<void ()> & finishCallback,const std::function<void ()> & repeatCallback)458 std::vector<std::shared_ptr<RSAnimation>> RSNode::Animate(const RSAnimationTimingProtocol& timingProtocol,
459     const RSAnimationTimingCurve& timingCurve, const PropertyCallback& propertyCallback,
460     const std::function<void()>& finishCallback, const std::function<void()>& repeatCallback)
461 {
462     if (propertyCallback == nullptr) {
463         ROSEN_LOGE("Failed to add curve animation, property callback is null!");
464         return {};
465     }
466 
467     auto implicitAnimator = RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
468     if (implicitAnimator == nullptr) {
469         ROSEN_LOGE("Failed to open implicit animation, implicit animator is null!");
470         return {};
471     }
472     std::shared_ptr<AnimationFinishCallback> animationFinishCallback;
473     if (finishCallback != nullptr) {
474         animationFinishCallback =
475             std::make_shared<AnimationFinishCallback>(finishCallback, timingProtocol.GetFinishCallbackType());
476     }
477     std::shared_ptr<AnimationRepeatCallback> animationRepeatCallback;
478     if (repeatCallback != nullptr) {
479         animationRepeatCallback = std::make_shared<AnimationRepeatCallback>(repeatCallback);
480     }
481     implicitAnimator->OpenImplicitAnimation(
482         timingProtocol, timingCurve, std::move(animationFinishCallback), std::move(animationRepeatCallback));
483     propertyCallback();
484     return implicitAnimator->CloseImplicitAnimation();
485 }
486 
Animate(const std::shared_ptr<RSUIContext> rsUIContext,const RSAnimationTimingProtocol & timingProtocol,const RSAnimationTimingCurve & timingCurve,const PropertyCallback & propertyCallback,const std::function<void ()> & finishCallback,const std::function<void ()> & repeatCallback)487 std::vector<std::shared_ptr<RSAnimation>> RSNode::Animate(const std::shared_ptr<RSUIContext> rsUIContext,
488     const RSAnimationTimingProtocol& timingProtocol,
489     const RSAnimationTimingCurve& timingCurve, const PropertyCallback& propertyCallback,
490     const std::function<void()>& finishCallback, const std::function<void()>& repeatCallback)
491 {
492     if (propertyCallback == nullptr) {
493         ROSEN_LOGE("Failed to add curve animation, property callback is null!");
494         return {};
495     }
496 
497     auto implicitAnimator = rsUIContext ? rsUIContext->GetRSImplicitAnimator()
498                                         : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
499     if (implicitAnimator == nullptr) {
500         ROSEN_LOGE("Failed to open implicit animation, implicit animator is null!");
501         return {};
502     }
503     std::shared_ptr<AnimationFinishCallback> animationFinishCallback;
504     if (finishCallback != nullptr) {
505         animationFinishCallback =
506             std::make_shared<AnimationFinishCallback>(finishCallback, timingProtocol.GetFinishCallbackType());
507     }
508     std::shared_ptr<AnimationRepeatCallback> animationRepeatCallback;
509     if (repeatCallback != nullptr) {
510         animationRepeatCallback = std::make_shared<AnimationRepeatCallback>(repeatCallback);
511     }
512     implicitAnimator->OpenImplicitAnimation(
513         timingProtocol, timingCurve, std::move(animationFinishCallback), std::move(animationRepeatCallback));
514     propertyCallback();
515     return implicitAnimator->CloseImplicitAnimation();
516 }
517 
AnimateWithCurrentOptions(const PropertyCallback & propertyCallback,const std::function<void ()> & finishCallback,bool timingSensitive)518 std::vector<std::shared_ptr<RSAnimation>> RSNode::AnimateWithCurrentOptions(
519     const PropertyCallback& propertyCallback, const std::function<void()>& finishCallback, bool timingSensitive)
520 {
521     if (propertyCallback == nullptr) {
522         ROSEN_LOGE("Failed to add curve animation, property callback is null!");
523         return {};
524     }
525     if (finishCallback == nullptr) {
526         ROSEN_LOGE("Failed to add curve animation, finish callback is null!");
527         propertyCallback();
528         return {};
529     }
530 
531     auto implicitAnimator = RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
532     if (implicitAnimator == nullptr) {
533         ROSEN_LOGE("Failed to open implicit animation, implicit animator is null!");
534         propertyCallback();
535         return {};
536     }
537     auto finishCallbackType =
538         timingSensitive ? FinishCallbackType::TIME_SENSITIVE : FinishCallbackType::TIME_INSENSITIVE;
539     // re-use the current options and replace the finish callback
540     auto animationFinishCallback = std::make_shared<AnimationFinishCallback>(finishCallback, finishCallbackType);
541     implicitAnimator->OpenImplicitAnimation(std::move(animationFinishCallback));
542     propertyCallback();
543     return implicitAnimator->CloseImplicitAnimation();
544 }
545 
AnimateWithCurrentOptions(const std::shared_ptr<RSUIContext> rsUIContext,const PropertyCallback & propertyCallback,const std::function<void ()> & finishCallback,bool timingSensitive)546 std::vector<std::shared_ptr<RSAnimation>> RSNode::AnimateWithCurrentOptions(
547     const std::shared_ptr<RSUIContext> rsUIContext, const PropertyCallback& propertyCallback,
548     const std::function<void()>& finishCallback, bool timingSensitive)
549 {
550     if (propertyCallback == nullptr) {
551         ROSEN_LOGE("Failed to add curve animation, property callback is null!");
552         return {};
553     }
554     if (finishCallback == nullptr) {
555         ROSEN_LOGE("Failed to add curve animation, finish callback is null!");
556         propertyCallback();
557         return {};
558     }
559 
560     auto implicitAnimator = rsUIContext ? rsUIContext->GetRSImplicitAnimator()
561                                         : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
562     if (implicitAnimator == nullptr) {
563         ROSEN_LOGE("Failed to open implicit animation, implicit animator is null!");
564         propertyCallback();
565         return {};
566     }
567     auto finishCallbackType =
568         timingSensitive ? FinishCallbackType::TIME_SENSITIVE : FinishCallbackType::TIME_INSENSITIVE;
569     // re-use the current options and replace the finish callback
570     auto animationFinishCallback = std::make_shared<AnimationFinishCallback>(finishCallback, finishCallbackType);
571     implicitAnimator->OpenImplicitAnimation(std::move(animationFinishCallback));
572     propertyCallback();
573     return implicitAnimator->CloseImplicitAnimation();
574 }
575 
AnimateWithCurrentCallback(const RSAnimationTimingProtocol & timingProtocol,const RSAnimationTimingCurve & timingCurve,const PropertyCallback & propertyCallback)576 std::vector<std::shared_ptr<RSAnimation>> RSNode::AnimateWithCurrentCallback(
577     const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve,
578     const PropertyCallback& propertyCallback)
579 {
580     if (propertyCallback == nullptr) {
581         ROSEN_LOGE("Failed to add curve animation, property callback is null!");
582         return {};
583     }
584 
585     auto implicitAnimator = RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
586     if (implicitAnimator == nullptr) {
587         ROSEN_LOGE("Failed to open implicit animation, implicit animator is null!");
588         return {};
589     }
590     // re-use the current finish callback and replace the options
591     implicitAnimator->OpenImplicitAnimation(timingProtocol, timingCurve);
592     propertyCallback();
593     return implicitAnimator->CloseImplicitAnimation();
594 }
595 
AnimateWithCurrentCallback(const std::shared_ptr<RSUIContext> rsUIContext,const RSAnimationTimingProtocol & timingProtocol,const RSAnimationTimingCurve & timingCurve,const PropertyCallback & propertyCallback)596 std::vector<std::shared_ptr<RSAnimation>> RSNode::AnimateWithCurrentCallback(
597     const std::shared_ptr<RSUIContext> rsUIContext,
598     const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve,
599     const PropertyCallback& propertyCallback)
600 {
601     if (propertyCallback == nullptr) {
602         ROSEN_LOGE("Failed to add curve animation, property callback is null!");
603         return {};
604     }
605 
606     auto implicitAnimator = rsUIContext ? rsUIContext->GetRSImplicitAnimator()
607                                         : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
608     if (implicitAnimator == nullptr) {
609         ROSEN_LOGE("Failed to open implicit animation, implicit animator is null!");
610         return {};
611     }
612     // re-use the current finish callback and replace the options
613     implicitAnimator->OpenImplicitAnimation(timingProtocol, timingCurve);
614     propertyCallback();
615     return implicitAnimator->CloseImplicitAnimation();
616 }
617 
ExecuteWithoutAnimation(const PropertyCallback & callback,const std::shared_ptr<RSUIContext> rsUIContext,std::shared_ptr<RSImplicitAnimator> implicitAnimator)618 void RSNode::ExecuteWithoutAnimation(
619     const PropertyCallback& callback, const std::shared_ptr<RSUIContext> rsUIContext,
620     std::shared_ptr<RSImplicitAnimator> implicitAnimator)
621 {
622     if (callback == nullptr) {
623         ROSEN_LOGE("Failed to execute without animation, property callback is null!");
624         return;
625     }
626     if (implicitAnimator == nullptr) {
627         implicitAnimator = rsUIContext ? rsUIContext->GetRSImplicitAnimator()
628                                        : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
629     }
630     if (implicitAnimator == nullptr) {
631         callback();
632     } else {
633         implicitAnimator->ExecuteWithoutAnimation(callback);
634     }
635 }
636 
FallbackAnimationsToContext()637 bool RSNode::FallbackAnimationsToContext()
638 {
639     auto rsUIContext = rsUIContext_.lock();
640     if (rsUIContext == nullptr) {
641         return false;
642     }
643     std::unique_lock<std::recursive_mutex> lock(animationMutex_);
644     for (auto& [animationId, animation] : animations_) {
645         rsUIContext->AddAnimationInner(std::move(animation));
646     }
647     animations_.clear();
648     return true;
649 }
650 
FallbackAnimationsToRoot()651 void RSNode::FallbackAnimationsToRoot()
652 {
653     auto target = RSNodeMap::Instance().GetAnimationFallbackNode(); // delete
654     if (target == nullptr) {
655         ROSEN_LOGE("Failed to move animation to root, root node is null!");
656         return;
657     }
658     std::unique_lock<std::recursive_mutex> lock(animationMutex_);
659     for (auto& [animationId, animation] : animations_) {
660         RSNodeMap::MutableInstance().RegisterAnimationInstanceId(animationId, id_, instanceId_); // delete
661         target->AddAnimationInner(std::move(animation));
662     }
663     animations_.clear();
664 }
665 
AddAnimationInner(const std::shared_ptr<RSAnimation> & animation)666 void RSNode::AddAnimationInner(const std::shared_ptr<RSAnimation>& animation)
667 {
668     std::unique_lock<std::recursive_mutex> lock(animationMutex_);
669     animations_.emplace(animation->GetId(), animation);
670     animatingPropertyNum_[animation->GetPropertyId()]++;
671     SetDrawNode();
672     SetDrawNodeType(DrawNodeType::DrawPropertyType);
673 }
674 
RemoveAnimationInner(const std::shared_ptr<RSAnimation> & animation)675 void RSNode::RemoveAnimationInner(const std::shared_ptr<RSAnimation>& animation)
676 {
677     std::unique_lock<std::recursive_mutex> lock(animationMutex_);
678     if (auto it = animatingPropertyNum_.find(animation->GetPropertyId()); it != animatingPropertyNum_.end()) {
679         it->second--;
680         if (it->second == 0) {
681             animatingPropertyNum_.erase(it);
682             animation->SetPropertyOnAllAnimationFinish();
683         }
684     }
685     animations_.erase(animation->GetId());
686 }
687 
FinishAnimationByProperty(const PropertyId & id)688 void RSNode::FinishAnimationByProperty(const PropertyId& id)
689 {
690     std::unique_lock<std::recursive_mutex> lock(animationMutex_);
691     for (const auto& [animationId, animation] : animations_) {
692         if (animation->GetPropertyId() == id) {
693             animation->Finish();
694         }
695     }
696 }
697 
CancelAnimationByProperty(const PropertyId & id,const bool needForceSync)698 void RSNode::CancelAnimationByProperty(const PropertyId& id, const bool needForceSync)
699 {
700     std::vector<std::shared_ptr<RSAnimation>> toBeRemoved;
701     {
702         std::unique_lock<std::recursive_mutex> lock(animationMutex_);
703         animatingPropertyNum_.erase(id);
704         EraseIf(animations_, [id, &toBeRemoved](const auto& pair) {
705             if (pair.second && (pair.second->GetPropertyId() == id)) {
706                 toBeRemoved.emplace_back(pair.second);
707                 return true;
708             }
709             return false;
710         });
711     }
712     // Destroy the cancelled animations outside the lock, since destroying them may trigger OnFinish callbacks, and
713     // callbacks may add/remove other animations, doing this with the lock would cause a deadlock.
714     toBeRemoved.clear();
715 
716     if (needForceSync) {
717         // Avoid animation on current property not cancelled in RS
718         std::unique_ptr<RSCommand> command = std::make_unique<RSAnimationCancel>(id_, id);
719         AddCommand(command, IsRenderServiceNode(), GetFollowType(), id_);
720         if (NeedForcedSendToRemote()) {
721             std::unique_ptr<RSCommand> commandForRemote = std::make_unique<RSAnimationCancel>(id_, id);
722             AddCommand(commandForRemote, true, GetFollowType(), id_);
723         }
724     }
725 }
726 
GetStagingProperties() const727 const RSModifierExtractor& RSNode::GetStagingProperties() const
728 {
729     return stagingPropertiesExtractor_;
730 }
731 
GetShowingProperties() const732 const RSShowingPropertiesFreezer& RSNode::GetShowingProperties() const
733 {
734     return showingPropertiesFreezer_;
735 }
736 
AddAnimation(const std::shared_ptr<RSAnimation> & animation,bool isStartAnimation)737 void RSNode::AddAnimation(const std::shared_ptr<RSAnimation>& animation, bool isStartAnimation)
738 {
739     if (animation == nullptr) {
740         ROSEN_LOGE("Failed to add animation, animation is null!");
741         return;
742     }
743 
744     auto animationId = animation->GetId();
745     {
746         std::unique_lock<std::recursive_mutex> lock(animationMutex_);
747         if (animations_.find(animationId) != animations_.end()) {
748             ROSEN_LOGE("Failed to add animation, animation already exists!");
749             return;
750         }
751     }
752 
753     // Note: Animation cancellation logic is now handled by RSImplicitAnimator. The code below might cause Spring
754     // Animations with a zero duration to not inherit velocity correctly, an issue slated for future resolution.
755     // This code is retained to ensure backward compatibility with specific arkui component animations.
756     if (animation->GetDuration() <= 0 && id_ != 0) {
757         FinishAnimationByProperty(animation->GetPropertyId());
758     }
759 
760     AddAnimationInner(animation);
761 
762     animation->StartInner(shared_from_this());
763     if (!isStartAnimation) {
764         animation->Pause();
765     }
766 }
767 
RemoveAllAnimations()768 void RSNode::RemoveAllAnimations()
769 {
770     std::unique_lock<std::recursive_mutex> lock(animationMutex_);
771     for (const auto& [id, animation] : animations_) {
772         RemoveAnimation(animation);
773     }
774 }
775 
RemoveAnimation(const std::shared_ptr<RSAnimation> & animation)776 void RSNode::RemoveAnimation(const std::shared_ptr<RSAnimation>& animation)
777 {
778     if (animation == nullptr) {
779         ROSEN_LOGE("Failed to remove animation, animation is null!");
780         return;
781     }
782 
783     {
784         std::unique_lock<std::recursive_mutex> lock(animationMutex_);
785         if (animations_.find(animation->GetId()) == animations_.end()) {
786             ROSEN_LOGE("Failed to remove animation, animation not exists!");
787             return;
788         }
789     }
790     animation->Finish();
791 }
792 
SetMotionPathOption(const std::shared_ptr<RSMotionPathOption> & motionPathOption)793 void RSNode::SetMotionPathOption(const std::shared_ptr<RSMotionPathOption>& motionPathOption)
794 {
795     motionPathOption_ = motionPathOption;
796     UpdateModifierMotionPathOption();
797 }
798 
SetMagnifierParams(const std::shared_ptr<RSMagnifierParams> & para)799 void RSNode::SetMagnifierParams(const std::shared_ptr<RSMagnifierParams>& para)
800 {
801     SetPropertyNG<ModifierNG::RSBackgroundFilterModifier, &ModifierNG::RSBackgroundFilterModifier::SetMagnifierParams>(
802         para);
803 }
804 
GetMotionPathOption() const805 const std::shared_ptr<RSMotionPathOption> RSNode::GetMotionPathOption() const
806 {
807     return motionPathOption_;
808 }
809 
HasPropertyAnimation(const PropertyId & id)810 bool RSNode::HasPropertyAnimation(const PropertyId& id)
811 {
812     std::unique_lock<std::recursive_mutex> lock(animationMutex_);
813     auto it = animatingPropertyNum_.find(id);
814     return it != animatingPropertyNum_.end() && it->second > 0;
815 }
816 
GetAnimationByPropertyId(const PropertyId & id)817 std::vector<AnimationId> RSNode::GetAnimationByPropertyId(const PropertyId& id)
818 {
819     std::unique_lock<std::recursive_mutex> lock(animationMutex_);
820     std::vector<AnimationId> animations;
821     for (auto& [animateId, animation] : animations_) {
822         if (animation->GetPropertyId() == id) {
823             animations.push_back(animateId);
824         }
825     }
826     return animations;
827 }
828 
IsGeometryDirty() const829 bool RSNode::IsGeometryDirty() const
830 {
831     return dirtyType_ & static_cast<uint32_t>(NodeDirtyType::GEOMETRY);
832 }
833 
IsAppearanceDirty() const834 bool RSNode::IsAppearanceDirty() const
835 {
836     return dirtyType_ & static_cast<uint32_t>(NodeDirtyType::APPEARANCE);
837 }
838 
MarkDirty(NodeDirtyType type,bool isDirty)839 void RSNode::MarkDirty(NodeDirtyType type, bool isDirty)
840 {
841     if (isDirty) {
842         dirtyType_ |= static_cast<uint32_t>(type);
843     } else {
844         dirtyType_ &= ~static_cast<uint32_t>(type);
845     }
846 }
847 
GetGlobalPositionX() const848 float RSNode::GetGlobalPositionX() const
849 {
850     return globalPositionX_;
851 }
852 
GetGlobalPositionY() const853 float RSNode::GetGlobalPositionY() const
854 {
855     return globalPositionY_;
856 }
857 
GetLocalGeometry() const858 std::shared_ptr<RSObjAbsGeometry> RSNode::GetLocalGeometry() const
859 {
860     return localGeometry_;
861 }
862 
GetGlobalGeometry() const863 std::shared_ptr<RSObjAbsGeometry> RSNode::GetGlobalGeometry() const
864 {
865     return globalGeometry_;
866 }
867 
UpdateLocalGeometry()868 void RSNode::UpdateLocalGeometry()
869 {
870     if (!IsGeometryDirty()) {
871         return;
872     }
873     localGeometry_ = std::make_shared<RSObjAbsGeometry>();
874     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
875     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
876     for (const auto& [_, modifierNG] : modifiersNG_) {
877         if (modifierNG->GetType() == ModifierNG::RSModifierType::BOUNDS) {
878             auto boundsModifierNG = std::static_pointer_cast<ModifierNG::RSBoundsModifier>(modifierNG);
879             boundsModifierNG->ApplyGeometry(localGeometry_);
880         }
881         if (modifierNG->GetType() == ModifierNG::RSModifierType::TRANSFORM) {
882             auto transformModifierNG = std::static_pointer_cast<ModifierNG::RSTransformModifier>(modifierNG);
883             transformModifierNG->ApplyGeometry(localGeometry_);
884         }
885     }
886 }
887 
UpdateGlobalGeometry(const std::shared_ptr<RSObjAbsGeometry> & parentGlobalGeometry)888 void RSNode::UpdateGlobalGeometry(const std::shared_ptr<RSObjAbsGeometry>& parentGlobalGeometry)
889 {
890     if (parentGlobalGeometry == nullptr || localGeometry_ == nullptr) {
891         return;
892     }
893     if (globalGeometry_ == nullptr) {
894         globalGeometry_ = std::make_shared<RSObjAbsGeometry>();
895     }
896     *globalGeometry_ = *localGeometry_;
897     globalGeometry_->UpdateMatrix(&parentGlobalGeometry->GetAbsMatrix(), std::nullopt);
898 
899     float parentGlobalPositionX = 0.f;
900     float parentGlobalPositionY = 0.f;
901     auto parent = GetParent();
902     if (parent) {
903         parentGlobalPositionX = parent->globalPositionX_;
904         parentGlobalPositionY = parent->globalPositionY_;
905     }
906     globalPositionX_ = parentGlobalPositionX + localGeometry_->GetX();
907     globalPositionY_ = parentGlobalPositionY + localGeometry_->GetY();
908 }
909 
910 bool RSNode::isNeedCallbackNodeChange_ = true;
SetNeedCallbackNodeChange(bool needCallback)911 void RSNode::SetNeedCallbackNodeChange(bool needCallback)
912 {
913     isNeedCallbackNodeChange_ = needCallback;
914 }
915 
916 // Notifies UI observer about page node modifications.
NotifyPageNodeChanged()917 void RSNode::NotifyPageNodeChanged()
918 {
919     if (isNeedCallbackNodeChange_ && propertyNodeChangeCallback_) {
920         propertyNodeChangeCallback_();
921     }
922 }
923 
924 template<typename ModifierType, auto Setter, typename T>
SetPropertyNG(T value)925 void RSNode::SetPropertyNG(T value)
926 {
927     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
928     auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierType::Type)];
929     // Create corresponding modifier if not exist
930     if (modifier == nullptr) {
931         modifier = std::make_shared<ModifierType>();
932         (*std::static_pointer_cast<ModifierType>(modifier).*Setter)(value);
933         AddModifier(modifier);
934     } else {
935         (*std::static_pointer_cast<ModifierType>(modifier).*Setter)(value);
936         NotifyPageNodeChanged();
937     }
938 }
939 
940 template<typename ModifierType, auto Setter, typename T>
SetPropertyNG(T value,bool animatable)941 void RSNode::SetPropertyNG(T value, bool animatable)
942 {
943     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
944     auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierType::Type)];
945     // Create corresponding modifier if not exist
946     if (modifier == nullptr) {
947         modifier = std::make_shared<ModifierType>();
948         (*std::static_pointer_cast<ModifierType>(modifier).*Setter)(value, animatable);
949         AddModifier(modifier);
950     } else {
951         (*std::static_pointer_cast<ModifierType>(modifier).*Setter)(value, animatable);
952         NotifyPageNodeChanged();
953     }
954 }
955 
956 template<typename ModifierType, auto Setter, typename T>
SetUIFilterPropertyNG(T value)957 void RSNode::SetUIFilterPropertyNG(T value)
958 {
959     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
960     auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierType::Type)];
961     // Create corresponding modifier if not exist
962     if (modifier == nullptr) {
963         modifier = std::make_shared<ModifierType>();
964         AddModifier(modifier);
965     }
966     (*std::static_pointer_cast<ModifierType>(modifier).*Setter)(value);
967 }
968 
969 // alpha
SetAlpha(float alpha)970 void RSNode::SetAlpha(float alpha)
971 {
972     SetPropertyNG<ModifierNG::RSAlphaModifier, &ModifierNG::RSAlphaModifier::SetAlpha>(alpha);
973     if (alpha < 1) {
974         SetDrawNode();
975         SetDrawNodeType(DrawNodeType::DrawPropertyType);
976     }
977 }
978 
SetAlphaOffscreen(bool alphaOffscreen)979 void RSNode::SetAlphaOffscreen(bool alphaOffscreen)
980 {
981     SetPropertyNG<ModifierNG::RSAlphaModifier, &ModifierNG::RSAlphaModifier::SetAlphaOffscreen>(alphaOffscreen);
982 }
983 
984 // Bounds
SetBounds(const Vector4f & bounds)985 void RSNode::SetBounds(const Vector4f& bounds)
986 {
987     if (auto surfaceNode = ReinterpretCastTo<RSSurfaceNode>()) {
988         auto compositeLayerUtils = surfaceNode->GetCompositeLayerUtils();
989         if (compositeLayerUtils) {
990             compositeLayerUtils->UpdateVirtualNodeBounds(bounds);
991         }
992     }
993     SetPropertyNG<ModifierNG::RSBoundsModifier, &ModifierNG::RSBoundsModifier::SetBounds>(bounds);
994     OnBoundsSizeChanged();
995     if (bounds.x_ != 0 || bounds.y_ != 0) {
996         SetDrawNode();
997         SetDrawNodeType(DrawNodeType::MergeableType);
998     }
999 }
1000 
SetBounds(float positionX,float positionY,float width,float height)1001 void RSNode::SetBounds(float positionX, float positionY, float width, float height)
1002 {
1003     SetBounds({ positionX, positionY, width, height });
1004 }
1005 
SetBoundsWidth(float width)1006 void RSNode::SetBoundsWidth(float width)
1007 {
1008     std::shared_ptr<RSAnimatableProperty<Vector4f>> property;
1009     {
1010         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1011         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1012         auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::BOUNDS)];
1013         if (modifier == nullptr || !modifier->HasProperty(ModifierNG::RSPropertyType::BOUNDS)) {
1014             SetBounds(0.f, 0.f, width, 0.f);
1015             return;
1016         }
1017         property = std::static_pointer_cast<RSAnimatableProperty<Vector4f>>(
1018             modifier->GetProperty(ModifierNG::RSPropertyType::BOUNDS));
1019     }
1020 
1021     if (property == nullptr) {
1022         return;
1023     }
1024     auto bounds = property->Get();
1025     bounds.z_ = width;
1026     property->Set(bounds);
1027     OnBoundsSizeChanged();
1028 }
1029 
SetBoundsHeight(float height)1030 void RSNode::SetBoundsHeight(float height)
1031 {
1032     std::shared_ptr<RSAnimatableProperty<Vector4f>> property;
1033     {
1034         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1035         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1036         auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::BOUNDS)];
1037         if (modifier == nullptr || !modifier->HasProperty(ModifierNG::RSPropertyType::BOUNDS)) {
1038             SetBounds(0.f, 0.f, 0.f, height);
1039             return;
1040         }
1041         property = std::static_pointer_cast<RSAnimatableProperty<Vector4f>>(
1042             modifier->GetProperty(ModifierNG::RSPropertyType::BOUNDS));
1043     }
1044 
1045     if (property == nullptr) {
1046         return;
1047     }
1048     auto bounds = property->Get();
1049     bounds.w_ = height;
1050     property->Set(bounds);
1051     OnBoundsSizeChanged();
1052 }
1053 
1054 // Frame
SetFrame(const Vector4f & bounds)1055 void RSNode::SetFrame(const Vector4f& bounds)
1056 {
1057     SetPropertyNG<ModifierNG::RSFrameModifier, &ModifierNG::RSFrameModifier::SetFrame>(bounds);
1058     if (bounds.x_ != 0 || bounds.y_ != 0) {
1059         SetDrawNode();
1060         SetDrawNodeType(DrawNodeType::MergeableType);
1061     }
1062 }
1063 
SetFrame(float positionX,float positionY,float width,float height)1064 void RSNode::SetFrame(float positionX, float positionY, float width, float height)
1065 {
1066     SetFrame({ positionX, positionY, width, height });
1067 }
1068 
SetFramePositionX(float positionX)1069 void RSNode::SetFramePositionX(float positionX)
1070 {
1071     std::shared_ptr<RSAnimatableProperty<Vector4f>> property;
1072     {
1073         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1074         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1075         auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::FRAME)];
1076         if (modifier == nullptr || !modifier->HasProperty(ModifierNG::RSPropertyType::FRAME)) {
1077             SetFrame(positionX, 0.f, 0.f, 0.f);
1078             return;
1079         }
1080         property = std::static_pointer_cast<RSAnimatableProperty<Vector4f>>(
1081             modifier->GetProperty(ModifierNG::RSPropertyType::FRAME));
1082     }
1083 
1084     if (property == nullptr) {
1085         return;
1086     }
1087     auto frame = property->Get();
1088     frame.x_ = positionX;
1089     property->Set(frame);
1090     SetDrawNode();
1091     SetDrawNodeType(DrawNodeType::MergeableType);
1092 }
1093 
SetFramePositionY(float positionY)1094 void RSNode::SetFramePositionY(float positionY)
1095 {
1096     std::shared_ptr<RSAnimatableProperty<Vector4f>> property;
1097     {
1098         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1099         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1100         auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::FRAME)];
1101         if (modifier == nullptr || !modifier->HasProperty(ModifierNG::RSPropertyType::FRAME)) {
1102             SetFrame(0.f, positionY, 0.f, 0.f);
1103             return;
1104         }
1105         property = std::static_pointer_cast<RSAnimatableProperty<Vector4f>>(
1106             modifier->GetProperty(ModifierNG::RSPropertyType::FRAME));
1107     }
1108 
1109     if (property == nullptr) {
1110         return;
1111     }
1112     auto frame = property->Get();
1113     frame.y_ = positionY;
1114     property->Set(frame);
1115     SetDrawNode();
1116     SetDrawNodeType(DrawNodeType::MergeableType);
1117 }
1118 
SetSandBox(std::optional<Vector2f> parentPosition)1119 void RSNode::SetSandBox(std::optional<Vector2f> parentPosition)
1120 {
1121     if (!parentPosition.has_value()) {
1122         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1123         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1124         auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::TRANSFORM)];
1125         if (modifier != nullptr) {
1126             modifier->DetachProperty(ModifierNG::RSPropertyType::SANDBOX);
1127         }
1128         return;
1129     }
1130     SetPropertyNG<ModifierNG::RSTransformModifier, &ModifierNG::RSTransformModifier::SetSandBox>(
1131         parentPosition.value());
1132 }
1133 
SetPositionZ(float positionZ)1134 void RSNode::SetPositionZ(float positionZ)
1135 {
1136     if (drawNodeChangeCallback_) {
1137         drawNodeChangeCallback_(shared_from_this(), true);
1138     }
1139     SetPropertyNG<ModifierNG::RSTransformModifier, &ModifierNG::RSTransformModifier::SetPositionZ>(positionZ);
1140 }
1141 
SetPositionZApplicableCamera3D(bool isApplicable)1142 void RSNode::SetPositionZApplicableCamera3D(bool isApplicable)
1143 {
1144     SetPropertyNG<ModifierNG::RSTransformModifier, &ModifierNG::RSTransformModifier::SetPositionZApplicableCamera3D>(
1145         isApplicable);
1146 }
1147 
1148 // pivot
SetPivot(const Vector2f & pivot)1149 void RSNode::SetPivot(const Vector2f& pivot)
1150 {
1151     SetPropertyNG<ModifierNG::RSTransformModifier, &ModifierNG::RSTransformModifier::SetPivot>(pivot, true);
1152 }
1153 
SetPivot(float pivotX,float pivotY)1154 void RSNode::SetPivot(float pivotX, float pivotY)
1155 {
1156     SetPivot({ pivotX, pivotY });
1157 }
1158 
SetPivotX(float pivotX)1159 void RSNode::SetPivotX(float pivotX)
1160 {
1161     std::shared_ptr<RSAnimatableProperty<Vector2f>> property;
1162     {
1163         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1164         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1165         auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::TRANSFORM)];
1166         if (modifier == nullptr || !modifier->HasProperty(ModifierNG::RSPropertyType::PIVOT)) {
1167             SetPivot(pivotX, 0.5f);
1168             return;
1169         }
1170         property = std::static_pointer_cast<RSAnimatableProperty<Vector2f>>(
1171             modifier->GetProperty(ModifierNG::RSPropertyType::PIVOT));
1172     }
1173     if (property == nullptr) {
1174         return;
1175     }
1176     auto pivot = property->Get();
1177     pivot.x_ = pivotX;
1178     property->Set(pivot);
1179 }
1180 
SetPivotY(float pivotY)1181 void RSNode::SetPivotY(float pivotY)
1182 {
1183     std::shared_ptr<RSAnimatableProperty<Vector2f>> property;
1184     {
1185         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1186         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1187         auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::TRANSFORM)];
1188         if (modifier == nullptr || !modifier->HasProperty(ModifierNG::RSPropertyType::PIVOT)) {
1189             SetPivot(0.5f, pivotY);
1190             return;
1191         }
1192         property = std::static_pointer_cast<RSAnimatableProperty<Vector2f>>(
1193             modifier->GetProperty(ModifierNG::RSPropertyType::PIVOT));
1194     }
1195     if (property == nullptr) {
1196         return;
1197     }
1198     auto pivot = property->Get();
1199     pivot.y_ = pivotY;
1200     property->Set(pivot);
1201 }
1202 
SetPivotZ(const float pivotZ)1203 void RSNode::SetPivotZ(const float pivotZ)
1204 {
1205     SetPropertyNG<ModifierNG::RSTransformModifier, &ModifierNG::RSTransformModifier::SetPivotZ>(pivotZ);
1206 }
1207 
SetCornerRadius(float cornerRadius)1208 void RSNode::SetCornerRadius(float cornerRadius)
1209 {
1210     SetCornerRadius(Vector4f(cornerRadius));
1211 }
1212 
SetCornerRadius(const Vector4f & cornerRadius)1213 void RSNode::SetCornerRadius(const Vector4f& cornerRadius)
1214 {
1215     SetPropertyNG<ModifierNG::RSBoundsClipModifier, &ModifierNG::RSBoundsClipModifier::SetCornerRadius>(cornerRadius);
1216 }
1217 
1218 // transform
SetRotation(const Quaternion & quaternion)1219 void RSNode::SetRotation(const Quaternion& quaternion)
1220 {
1221     SetPropertyNG<ModifierNG::RSTransformModifier, &ModifierNG::RSTransformModifier::SetQuaternion>(quaternion);
1222 }
1223 
SetRotation(float degree)1224 void RSNode::SetRotation(float degree)
1225 {
1226     SetPropertyNG<ModifierNG::RSTransformModifier, &ModifierNG::RSTransformModifier::SetRotation>(degree);
1227 }
1228 
SetRotation(float degreeX,float degreeY,float degreeZ)1229 void RSNode::SetRotation(float degreeX, float degreeY, float degreeZ)
1230 {
1231     SetRotationX(degreeX);
1232     SetRotationY(degreeY);
1233     SetRotation(degreeZ);
1234 }
1235 
SetRotationX(float degree)1236 void RSNode::SetRotationX(float degree)
1237 {
1238     SetPropertyNG<ModifierNG::RSTransformModifier, &ModifierNG::RSTransformModifier::SetRotationX>(degree);
1239 }
1240 
SetRotationY(float degree)1241 void RSNode::SetRotationY(float degree)
1242 {
1243     SetPropertyNG<ModifierNG::RSTransformModifier, &ModifierNG::RSTransformModifier::SetRotationY>(degree);
1244 }
1245 
SetCameraDistance(float cameraDistance)1246 void RSNode::SetCameraDistance(float cameraDistance)
1247 {
1248     SetPropertyNG<ModifierNG::RSTransformModifier, &ModifierNG::RSTransformModifier::SetCameraDistance>(cameraDistance);
1249 }
1250 
SetTranslate(const Vector2f & translate)1251 void RSNode::SetTranslate(const Vector2f& translate)
1252 {
1253     SetPropertyNG<ModifierNG::RSTransformModifier, &ModifierNG::RSTransformModifier::SetTranslate>(translate);
1254 }
1255 
SetTranslate(float translateX,float translateY,float translateZ)1256 void RSNode::SetTranslate(float translateX, float translateY, float translateZ)
1257 {
1258     SetTranslate({ translateX, translateY });
1259     SetTranslateZ(translateZ);
1260 }
1261 
SetTranslateX(float translate)1262 void RSNode::SetTranslateX(float translate)
1263 {
1264     std::shared_ptr<RSAnimatableProperty<Vector2f>> property;
1265     {
1266         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1267         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1268         auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::TRANSFORM)];
1269         if (modifier == nullptr || !modifier->HasProperty(ModifierNG::RSPropertyType::TRANSLATE)) {
1270             SetTranslate({ translate, 0.f });
1271             return;
1272         }
1273         property = std::static_pointer_cast<RSAnimatableProperty<Vector2f>>(
1274             modifier->GetProperty(ModifierNG::RSPropertyType::TRANSLATE));
1275     }
1276 
1277     if (property == nullptr) {
1278         return;
1279     }
1280     auto trans = property->Get();
1281     trans.x_ = translate;
1282     property->Set(trans);
1283 }
1284 
SetTranslateY(float translate)1285 void RSNode::SetTranslateY(float translate)
1286 {
1287     std::shared_ptr<RSAnimatableProperty<Vector2f>> property;
1288     {
1289         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1290         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1291         auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::TRANSFORM)];
1292         if (modifier == nullptr || !modifier->HasProperty(ModifierNG::RSPropertyType::TRANSLATE)) {
1293             SetTranslate({ 0.f, translate });
1294             return;
1295         }
1296         property = std::static_pointer_cast<RSAnimatableProperty<Vector2f>>(
1297             modifier->GetProperty(ModifierNG::RSPropertyType::TRANSLATE));
1298     }
1299 
1300     if (property == nullptr) {
1301         return;
1302     }
1303     auto trans = property->Get();
1304     trans.y_ = translate;
1305     property->Set(trans);
1306 }
1307 
SetTranslateZ(float translate)1308 void RSNode::SetTranslateZ(float translate)
1309 {
1310     SetPropertyNG<ModifierNG::RSTransformModifier, &ModifierNG::RSTransformModifier::SetTranslateZ>(translate);
1311 }
1312 
SetScale(float scale)1313 void RSNode::SetScale(float scale)
1314 {
1315     SetScale({ scale, scale });
1316 }
1317 
SetScale(float scaleX,float scaleY)1318 void RSNode::SetScale(float scaleX, float scaleY)
1319 {
1320     SetScale({ scaleX, scaleY });
1321 }
1322 
SetScale(const Vector2f & scale)1323 void RSNode::SetScale(const Vector2f& scale)
1324 {
1325     SetPropertyNG<ModifierNG::RSTransformModifier, &ModifierNG::RSTransformModifier::SetScale>(scale);
1326 }
1327 
SetScaleX(float scaleX)1328 void RSNode::SetScaleX(float scaleX)
1329 {
1330     std::shared_ptr<RSAnimatableProperty<Vector2f>> property;
1331     {
1332         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1333         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1334         auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::TRANSFORM)];
1335         if (modifier == nullptr || !modifier->HasProperty(ModifierNG::RSPropertyType::SCALE)) {
1336             SetScale(scaleX, 1.f);
1337             return;
1338         }
1339         property = std::static_pointer_cast<RSAnimatableProperty<Vector2f>>(
1340             modifier->GetProperty(ModifierNG::RSPropertyType::SCALE));
1341     }
1342 
1343     if (property == nullptr) {
1344         return;
1345     }
1346     auto scale = property->Get();
1347     scale.x_ = scaleX;
1348     property->Set(scale);
1349 }
1350 
SetScaleY(float scaleY)1351 void RSNode::SetScaleY(float scaleY)
1352 {
1353     std::shared_ptr<RSAnimatableProperty<Vector2f>> property;
1354     {
1355         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1356         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1357         auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::TRANSFORM)];
1358         if (modifier == nullptr || !modifier->HasProperty(ModifierNG::RSPropertyType::SCALE)) {
1359             SetScale(1.f, scaleY);
1360             return;
1361         }
1362         property = std::static_pointer_cast<RSAnimatableProperty<Vector2f>>(
1363             modifier->GetProperty(ModifierNG::RSPropertyType::SCALE));
1364     }
1365 
1366     if (property == nullptr) {
1367         return;
1368     }
1369     auto scale = property->Get();
1370     scale.y_ = scaleY;
1371     property->Set(scale);
1372 }
1373 
SetScaleZ(float scaleZ)1374 void RSNode::SetScaleZ(float scaleZ)
1375 {
1376     SetPropertyNG<ModifierNG::RSTransformModifier, &ModifierNG::RSTransformModifier::SetScaleZ>(scaleZ);
1377 }
1378 
SetSkew(float skew)1379 void RSNode::SetSkew(float skew)
1380 {
1381     SetSkew({ skew, skew, skew });
1382 }
1383 
SetSkew(float skewX,float skewY)1384 void RSNode::SetSkew(float skewX, float skewY)
1385 {
1386     SetSkew({ skewX, skewY, 0.f });
1387 }
1388 
SetSkew(float skewX,float skewY,float skewZ)1389 void RSNode::SetSkew(float skewX, float skewY, float skewZ)
1390 {
1391     SetSkew({ skewX, skewY, skewZ });
1392 }
1393 
SetSkew(const Vector3f & skew)1394 void RSNode::SetSkew(const Vector3f& skew)
1395 {
1396     SetPropertyNG<ModifierNG::RSTransformModifier, &ModifierNG::RSTransformModifier::SetSkew>(skew);
1397 }
1398 
SetSkewX(float skewX)1399 void RSNode::SetSkewX(float skewX)
1400 {
1401     std::shared_ptr<RSAnimatableProperty<Vector3f>> property;
1402     {
1403         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1404         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1405         auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::TRANSFORM)];
1406         if (modifier == nullptr || !modifier->HasProperty(ModifierNG::RSPropertyType::SKEW)) {
1407             SetSkew(skewX, 0.f);
1408             return;
1409         }
1410         property = std::static_pointer_cast<RSAnimatableProperty<Vector3f>>(
1411             modifier->GetProperty(ModifierNG::RSPropertyType::SKEW));
1412     }
1413 
1414     if (property == nullptr) {
1415         return;
1416     }
1417     auto skew = property->Get();
1418     skew.x_ = skewX;
1419     property->Set(skew);
1420 }
1421 
SetSkewY(float skewY)1422 void RSNode::SetSkewY(float skewY)
1423 {
1424     std::shared_ptr<RSAnimatableProperty<Vector3f>> property;
1425     {
1426         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1427         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1428         auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::TRANSFORM)];
1429         if (modifier == nullptr || !modifier->HasProperty(ModifierNG::RSPropertyType::SKEW)) {
1430             SetSkew(0.f, skewY);
1431             return;
1432         }
1433         property = std::static_pointer_cast<RSAnimatableProperty<Vector3f>>(
1434             modifier->GetProperty(ModifierNG::RSPropertyType::SKEW));
1435     }
1436     if (property == nullptr) {
1437         return;
1438     }
1439     auto skew = property->Get();
1440     skew.y_ = skewY;
1441     property->Set(skew);
1442 }
1443 
SetSkewZ(float skewZ)1444 void RSNode::SetSkewZ(float skewZ)
1445 {
1446     std::shared_ptr<RSAnimatableProperty<Vector3f>> property;
1447     {
1448         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1449         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1450         auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::TRANSFORM)];
1451         if (modifier == nullptr || !modifier->HasProperty(ModifierNG::RSPropertyType::SKEW)) {
1452             SetSkew(0.f, 0.f, skewZ);
1453             return;
1454         }
1455         property = std::static_pointer_cast<RSAnimatableProperty<Vector3f>>(
1456             modifier->GetProperty(ModifierNG::RSPropertyType::SKEW));
1457     }
1458 
1459     if (property == nullptr) {
1460         return;
1461     }
1462     auto skew = property->Get();
1463     skew.z_ = skewZ;
1464     property->Set(skew);
1465 }
1466 
SetRSUIContext(std::shared_ptr<RSUIContext> rsUIContext)1467 void RSNode::SetRSUIContext(std::shared_ptr<RSUIContext> rsUIContext)
1468 {
1469     if (rsUIContext == nullptr) {
1470         return;
1471     }
1472     auto preUIContext = rsUIContext_.lock();
1473     if ((preUIContext != nullptr) && (preUIContext == rsUIContext)) {
1474         return;
1475     }
1476 
1477     // if have old rsContext, should remove nodeId from old nodeMap and travel child
1478     if (preUIContext != nullptr) {
1479         // step1 remove node from old context
1480         preUIContext->GetMutableNodeMap().UnregisterNode(id_);
1481         // sync child
1482         for (uint32_t index = 0; index < children_.size(); index++) {
1483             if (auto childPtr = children_[index].lock()) {
1484                 childPtr->SetRSUIContext(rsUIContext);
1485             }
1486         }
1487     }
1488 
1489     RSModifierExtractor rsModifierExtractor(id_, rsUIContext);
1490     stagingPropertiesExtractor_ = rsModifierExtractor;
1491     RSShowingPropertiesFreezer showingPropertiesFreezer(id_, rsUIContext);
1492     showingPropertiesFreezer_ = showingPropertiesFreezer;
1493 
1494     // step2 sign
1495     rsUIContext_ = rsUIContext;
1496     // step3 register node to new nodeMap and move the command to the new RSUIContext
1497     RegisterNodeMap();
1498     if (preUIContext != nullptr) {
1499         auto preTransaction = preUIContext->GetRSTransaction();
1500         auto curTransaction = rsUIContext->GetRSTransaction();
1501         if (preTransaction && curTransaction) {
1502             preTransaction->MoveCommandByNodeId(curTransaction, id_);
1503         }
1504     }
1505     SetUIContextToken();
1506 }
1507 
SetPersp(float persp)1508 void RSNode::SetPersp(float persp)
1509 {
1510     SetPersp({ persp, persp, 0.f, 1.f });
1511 }
1512 
SetPersp(float perspX,float perspY)1513 void RSNode::SetPersp(float perspX, float perspY)
1514 {
1515     SetPersp({ perspX, perspY, 0.f, 1.f });
1516 }
1517 
SetPersp(float perspX,float perspY,float perspZ,float perspW)1518 void RSNode::SetPersp(float perspX, float perspY, float perspZ, float perspW)
1519 {
1520     SetPersp({ perspX, perspY, perspZ, perspW });
1521 }
1522 
SetPersp(const Vector4f & persp)1523 void RSNode::SetPersp(const Vector4f& persp)
1524 {
1525     SetPropertyNG<ModifierNG::RSTransformModifier, &ModifierNG::RSTransformModifier::SetPersp>(persp);
1526 }
1527 
SetPerspX(float perspX)1528 void RSNode::SetPerspX(float perspX)
1529 {
1530     std::shared_ptr<RSAnimatableProperty<Vector4f>> property;
1531     {
1532         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1533         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1534         auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::TRANSFORM)];
1535         if (modifier == nullptr || !modifier->HasProperty(ModifierNG::RSPropertyType::PERSP)) {
1536             SetPersp({ perspX, 0.f, 0.0f, 1.0f });
1537             return;
1538         }
1539         property = std::static_pointer_cast<RSAnimatableProperty<Vector4f>>(
1540             modifier->GetProperty(ModifierNG::RSPropertyType::PERSP));
1541     }
1542 
1543     if (property == nullptr) {
1544         return;
1545     }
1546     auto persp = property->Get();
1547     persp.x_ = perspX;
1548     property->Set(persp);
1549 }
1550 
SetPerspY(float perspY)1551 void RSNode::SetPerspY(float perspY)
1552 {
1553     std::shared_ptr<RSAnimatableProperty<Vector4f>> property;
1554     {
1555         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1556         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1557         auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::TRANSFORM)];
1558         if (modifier == nullptr || !modifier->HasProperty(ModifierNG::RSPropertyType::PERSP)) {
1559             SetPersp({ 0.f, perspY, 0.f, 1.f });
1560             return;
1561         }
1562         property = std::static_pointer_cast<RSAnimatableProperty<Vector4f>>(
1563             modifier->GetProperty(ModifierNG::RSPropertyType::PERSP));
1564     }
1565     if (property == nullptr) {
1566         return;
1567     }
1568     auto persp = property->Get();
1569     persp.y_ = perspY;
1570     property->Set(persp);
1571 }
1572 
SetPerspZ(float perspZ)1573 void RSNode::SetPerspZ(float perspZ)
1574 {
1575     std::shared_ptr<RSAnimatableProperty<Vector4f>> property;
1576     {
1577         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1578         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1579         auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::TRANSFORM)];
1580         if (modifier == nullptr || !modifier->HasProperty(ModifierNG::RSPropertyType::PERSP)) {
1581             SetPersp({ 0.f, 0.f, perspZ, 1.f });
1582             return;
1583         }
1584         property = std::static_pointer_cast<RSAnimatableProperty<Vector4f>>(
1585             modifier->GetProperty(ModifierNG::RSPropertyType::PERSP));
1586     }
1587     if (property == nullptr) {
1588         return;
1589     }
1590     auto persp = property->Get();
1591     persp.z_ = perspZ;
1592     property->Set(persp);
1593 }
1594 
SetPerspW(float perspW)1595 void RSNode::SetPerspW(float perspW)
1596 {
1597     std::shared_ptr<RSAnimatableProperty<Vector4f>> property;
1598     {
1599         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1600         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1601         auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::TRANSFORM)];
1602         if (modifier == nullptr || !modifier->HasProperty(ModifierNG::RSPropertyType::PERSP)) {
1603             SetPersp({ 0.f, 0.f, 0.f, perspW });
1604             return;
1605         }
1606         property = std::static_pointer_cast<RSAnimatableProperty<Vector4f>>(
1607             modifier->GetProperty(ModifierNG::RSPropertyType::PERSP));
1608     }
1609     if (property == nullptr) {
1610         return;
1611     }
1612     auto persp = property->Get();
1613     persp.w_ = perspW;
1614     property->Set(persp);
1615 }
1616 
1617 // Set the foreground color of the control
SetEnvForegroundColor(uint32_t colorValue)1618 void RSNode::SetEnvForegroundColor(uint32_t colorValue)
1619 {
1620     auto color = Color::FromArgbInt(colorValue);
1621     SetPropertyNG<ModifierNG::RSEnvForegroundColorModifier,
1622         &ModifierNG::RSEnvForegroundColorModifier::SetEnvForegroundColor>(color);
1623 }
1624 
1625 // Set the foreground color strategy of the control
SetEnvForegroundColorStrategy(ForegroundColorStrategyType strategyType)1626 void RSNode::SetEnvForegroundColorStrategy(ForegroundColorStrategyType strategyType)
1627 {
1628     SetPropertyNG<ModifierNG::RSEnvForegroundColorModifier,
1629         &ModifierNG::RSEnvForegroundColorModifier::SetEnvForegroundColorStrategy>(strategyType);
1630 }
1631 
1632 // Set ParticleParams
SetParticleParams(std::vector<ParticleParams> & particleParams,const std::function<void ()> & finishCallback)1633 void RSNode::SetParticleParams(std::vector<ParticleParams>& particleParams, const std::function<void()>& finishCallback)
1634 {
1635     std::vector<std::shared_ptr<ParticleRenderParams>> particlesRenderParams;
1636     for (size_t i = 0; i < particleParams.size(); i++) {
1637         particlesRenderParams.push_back(particleParams[i].SetParamsToRenderParticle());
1638     }
1639 
1640     SetParticleDrawRegion(particleParams);
1641     auto property = std::make_shared<RSProperty<int>>();
1642     auto propertyId = property->GetId();
1643     auto uiAnimation = std::make_shared<RSAnimationGroup>();
1644     auto animationId = uiAnimation->GetId();
1645     AddAnimation(uiAnimation);
1646     if (finishCallback != nullptr) {
1647         uiAnimation->SetFinishCallback(std::make_shared<AnimationFinishCallback>(finishCallback));
1648     }
1649     auto animation =
1650         std::make_shared<RSRenderParticleAnimation>(animationId, propertyId, std::move(particlesRenderParams));
1651     ModifierId modifierId = ModifierNG::RSModifier::GenerateModifierId();
1652     std::unique_ptr<RSCommand> command = std::make_unique<RSAnimationCreateParticleNG>(GetId(), modifierId, animation);
1653     AddCommand(command, IsRenderServiceNode(), GetFollowType(), GetId());
1654     if (NeedForcedSendToRemote()) {
1655         std::unique_ptr<RSCommand> cmdForRemote =
1656             std::make_unique<RSAnimationCreateParticleNG>(GetId(), modifierId, animation);
1657         AddCommand(cmdForRemote, true, GetFollowType(), GetId());
1658     }
1659 }
1660 
SetParticleDrawRegion(std::vector<ParticleParams> & particleParams)1661 void RSNode::SetParticleDrawRegion(std::vector<ParticleParams>& particleParams)
1662 {
1663     Vector4f bounds = GetStagingProperties().GetBounds();
1664     float boundsRight = bounds.x_ + bounds.z_;
1665     float boundsBottom = bounds.y_ + bounds.w_;
1666     size_t emitterCount = particleParams.size();
1667     std::vector<float> left(emitterCount);
1668     std::vector<float> top(emitterCount);
1669     std::vector<float> right(emitterCount);
1670     std::vector<float> bottom(emitterCount);
1671     for (size_t i = 0; i < emitterCount; i++) {
1672         auto particleType = particleParams[i].emitterConfig_.type_;
1673         auto position = particleParams[i].emitterConfig_.position_;
1674         auto emitSize = particleParams[i].emitterConfig_.emitSize_;
1675         float scaleMax = particleParams[i].scale_.val_.end_;
1676         if (particleType == ParticleType::POINTS) {
1677             auto diameMax = particleParams[i].emitterConfig_.radius_ * 2 * scaleMax; // diameter = 2 * radius
1678             left[i] = std::min(bounds.x_ - diameMax, bounds.x_ + position.x_ - diameMax);
1679             top[i] = std::min(bounds.y_ - diameMax, bounds.y_ + position.y_ - diameMax);
1680             right[i] = std::max(boundsRight + diameMax + diameMax, position.x_ + emitSize.x_ + diameMax + diameMax);
1681             bottom[i] = std::max(boundsBottom + diameMax + diameMax, position.y_ + emitSize.y_ + diameMax + diameMax);
1682         } else {
1683             float imageSizeWidth = 0.f;
1684             float imageSizeHeight = 0.f;
1685             auto image = particleParams[i].emitterConfig_.image_;
1686             auto imageSize = particleParams[i].emitterConfig_.imageSize_;
1687             if (image == nullptr)
1688                 continue;
1689             auto pixelMap = image->GetPixelMap();
1690             if (pixelMap != nullptr) {
1691                 imageSizeWidth = std::max(imageSize.x_, static_cast<float>(pixelMap->GetWidth()));
1692                 imageSizeHeight = std::max(imageSize.y_, static_cast<float>(pixelMap->GetHeight()));
1693             }
1694             float imageSizeWidthMax = imageSizeWidth * scaleMax;
1695             float imageSizeHeightMax = imageSizeHeight * scaleMax;
1696             left[i] = std::min(bounds.x_ - imageSizeWidthMax, bounds.x_ + position.x_ - imageSizeWidthMax);
1697             top[i] = std::min(bounds.y_ - imageSizeHeightMax, bounds.y_ + position.y_ - imageSizeHeightMax);
1698             right[i] = std::max(boundsRight + imageSizeWidthMax + imageSizeWidthMax,
1699                 position.x_ + emitSize.x_ + imageSizeWidthMax + imageSizeWidthMax);
1700             bottom[i] = std::max(boundsBottom + imageSizeHeightMax + imageSizeHeightMax,
1701                 position.y_ + emitSize.y_ + imageSizeHeightMax + imageSizeHeightMax);
1702         }
1703     }
1704     if (emitterCount != 0) {
1705         float l = *std::min_element(left.begin(), left.end());
1706         float t = *std::min_element(top.begin(), top.end());
1707         boundsRight = *std::max_element(right.begin(), right.end());
1708         boundsBottom = *std::max_element(bottom.begin(), bottom.end());
1709         SetDrawRegion(std::make_shared<RectF>(l - bounds.x_, t - bounds.y_, boundsRight - l, boundsBottom - t));
1710     }
1711 }
1712 
1713 // Update Particle Emitter
SetEmitterUpdater(const std::vector<std::shared_ptr<EmitterUpdater>> & para)1714 void RSNode::SetEmitterUpdater(const std::vector<std::shared_ptr<EmitterUpdater>>& para)
1715 {
1716     SetPropertyNG<ModifierNG::RSParticleEffectModifier, &ModifierNG::RSParticleEffectModifier::SetEmitterUpdater>(para);
1717 }
1718 
1719 // Set Particle Noise Field
SetParticleNoiseFields(const std::shared_ptr<ParticleNoiseFields> & para)1720 void RSNode::SetParticleNoiseFields(const std::shared_ptr<ParticleNoiseFields>& para)
1721 {
1722     SetPropertyNG<ModifierNG::RSParticleEffectModifier, &ModifierNG::RSParticleEffectModifier::SetParticleNoiseFields>(
1723         para);
1724 }
1725 
1726 // foreground
SetForegroundColor(uint32_t colorValue)1727 void RSNode::SetForegroundColor(uint32_t colorValue)
1728 {
1729     auto color = Color::FromArgbInt(colorValue);
1730     SetPropertyNG<ModifierNG::RSForegroundColorModifier, &ModifierNG::RSForegroundColorModifier::SetForegroundColor>(
1731         color);
1732 }
1733 
SetBackgroundColor(uint32_t colorValue)1734 void RSNode::SetBackgroundColor(uint32_t colorValue)
1735 {
1736     auto color = Color::FromArgbInt(colorValue);
1737     SetBackgroundColor(color);
1738 }
1739 
SetBackgroundColor(RSColor color)1740 void RSNode::SetBackgroundColor(RSColor color)
1741 {
1742 #ifndef ROSEN_CROSS_PLATFORM
1743     color.ConvertToP3ColorSpace();
1744 #endif
1745     SetPropertyNG<ModifierNG::RSBackgroundColorModifier, &ModifierNG::RSBackgroundColorModifier::SetBackgroundColor>(
1746         color);
1747     if (color.GetAlpha() > 0) {
1748         SetDrawNode();
1749         SetDrawNodeType(DrawNodeType::DrawPropertyType);
1750     }
1751 }
1752 
SetBackgroundShader(const std::shared_ptr<RSShader> & shader)1753 void RSNode::SetBackgroundShader(const std::shared_ptr<RSShader>& shader)
1754 {
1755     SetPropertyNG<ModifierNG::RSBackgroundShaderModifier, &ModifierNG::RSBackgroundShaderModifier::SetBackgroundShader>(
1756         shader);
1757 }
1758 
SetBackgroundShaderProgress(const float & progress)1759 void RSNode::SetBackgroundShaderProgress(const float& progress)
1760 {
1761     SetPropertyNG<ModifierNG::RSBackgroundShaderModifier,
1762         &ModifierNG::RSBackgroundShaderModifier::SetBackgroundShaderProgress>(progress);
1763 }
1764 
1765 // background
SetBgImage(const std::shared_ptr<RSImage> & image)1766 void RSNode::SetBgImage(const std::shared_ptr<RSImage>& image)
1767 {
1768     if (image) {
1769         image->SetNodeId(GetId());
1770     }
1771     SetPropertyNG<ModifierNG::RSBackgroundImageModifier, &ModifierNG::RSBackgroundImageModifier::SetBgImage>(image);
1772 }
1773 
SetBgImageInnerRect(const Vector4f & rect)1774 void RSNode::SetBgImageInnerRect(const Vector4f& rect)
1775 {
1776     SetPropertyNG<ModifierNG::RSBackgroundImageModifier, &ModifierNG::RSBackgroundImageModifier::SetBgImageInnerRect>(
1777         rect);
1778 }
1779 
SetBgImageSize(float width,float height)1780 void RSNode::SetBgImageSize(float width, float height)
1781 {
1782     SetBgImageWidth(width);
1783     SetBgImageHeight(height);
1784 }
1785 
SetBgImageWidth(float width)1786 void RSNode::SetBgImageWidth(float width)
1787 {
1788     SetPropertyNG<ModifierNG::RSBackgroundImageModifier, &ModifierNG::RSBackgroundImageModifier::SetBgImageWidth>(
1789         width);
1790 }
1791 
SetBgImageHeight(float height)1792 void RSNode::SetBgImageHeight(float height)
1793 {
1794     SetPropertyNG<ModifierNG::RSBackgroundImageModifier, &ModifierNG::RSBackgroundImageModifier::SetBgImageHeight>(
1795         height);
1796 }
1797 
SetBgImagePosition(float positionX,float positionY)1798 void RSNode::SetBgImagePosition(float positionX, float positionY)
1799 {
1800     SetBgImagePositionX(positionX);
1801     SetBgImagePositionY(positionY);
1802 }
1803 
SetBgImagePositionX(float positionX)1804 void RSNode::SetBgImagePositionX(float positionX)
1805 {
1806     SetPropertyNG<ModifierNG::RSBackgroundImageModifier, &ModifierNG::RSBackgroundImageModifier::SetBgImagePositionX>(
1807         positionX);
1808 }
1809 
SetBgImagePositionY(float positionY)1810 void RSNode::SetBgImagePositionY(float positionY)
1811 {
1812     SetPropertyNG<ModifierNG::RSBackgroundImageModifier, &ModifierNG::RSBackgroundImageModifier::SetBgImagePositionY>(
1813         positionY);
1814 }
1815 
1816 // set inner border color
SetBorderColor(uint32_t colorValue)1817 void RSNode::SetBorderColor(uint32_t colorValue)
1818 {
1819     SetBorderColor(colorValue, colorValue, colorValue, colorValue);
1820 }
1821 
1822 // set inner border color
SetBorderColor(uint32_t left,uint32_t top,uint32_t right,uint32_t bottom)1823 void RSNode::SetBorderColor(uint32_t left, uint32_t top, uint32_t right, uint32_t bottom)
1824 {
1825     Vector4<Color> color(Color::FromArgbInt(left), Color::FromArgbInt(top),
1826                          Color::FromArgbInt(right), Color::FromArgbInt(bottom));
1827     SetBorderColor(color);
1828 }
1829 
1830 // set inner border color
SetBorderColor(const Vector4<Color> & color)1831 void RSNode::SetBorderColor(const Vector4<Color>& color)
1832 {
1833     SetPropertyNG<ModifierNG::RSBorderModifier, &ModifierNG::RSBorderModifier::SetBorderColor>(color);
1834 }
1835 
1836 // set inner border width
SetBorderWidth(float width)1837 void RSNode::SetBorderWidth(float width)
1838 {
1839     SetBorderWidth(width, width, width, width);
1840 }
1841 
1842 // set inner border width
SetBorderWidth(float left,float top,float right,float bottom)1843 void RSNode::SetBorderWidth(float left, float top, float right, float bottom)
1844 {
1845     Vector4f width(left, top, right, bottom);
1846     SetBorderWidth(width);
1847 }
1848 
1849 // set inner border width
SetBorderWidth(const Vector4f & width)1850 void RSNode::SetBorderWidth(const Vector4f& width)
1851 {
1852     SetPropertyNG<ModifierNG::RSBorderModifier, &ModifierNG::RSBorderModifier::SetBorderWidth>(width);
1853 }
1854 
1855 // set inner border style
SetBorderStyle(uint32_t styleValue)1856 void RSNode::SetBorderStyle(uint32_t styleValue)
1857 {
1858     SetBorderStyle(styleValue, styleValue, styleValue, styleValue);
1859 }
1860 
1861 // set inner border style
SetBorderStyle(uint32_t left,uint32_t top,uint32_t right,uint32_t bottom)1862 void RSNode::SetBorderStyle(uint32_t left, uint32_t top, uint32_t right, uint32_t bottom)
1863 {
1864     Vector4<uint32_t> style(left, top, right, bottom);
1865     SetPropertyNG<ModifierNG::RSBorderModifier, &ModifierNG::RSBorderModifier::SetBorderStyle>(style);
1866 }
1867 
1868 // set inner border style
SetBorderStyle(const Vector4<BorderStyle> & style)1869 void RSNode::SetBorderStyle(const Vector4<BorderStyle>& style)
1870 {
1871     Vector4<uint32_t> borderStyle(static_cast<uint32_t>(style.x_), static_cast<uint32_t>(style.y_),
1872         static_cast<uint32_t>(style.z_), static_cast<uint32_t>(style.w_));
1873     SetPropertyNG<ModifierNG::RSBorderModifier, &ModifierNG::RSBorderModifier::SetBorderStyle>(borderStyle);
1874 }
1875 
1876 // set dash width for border
SetBorderDashWidth(const Vector4f & dashWidth)1877 void RSNode::SetBorderDashWidth(const Vector4f& dashWidth)
1878 {
1879     SetPropertyNG<ModifierNG::RSBorderModifier, &ModifierNG::RSBorderModifier::SetBorderDashWidth>(dashWidth);
1880 }
1881 
1882 // set dash gap for border
SetBorderDashGap(const Vector4f & dashGap)1883 void RSNode::SetBorderDashGap(const Vector4f& dashGap)
1884 {
1885     SetPropertyNG<ModifierNG::RSBorderModifier, &ModifierNG::RSBorderModifier::SetBorderDashGap>(dashGap);
1886 }
1887 
SetOuterBorderColor(const Vector4<Color> & color)1888 void RSNode::SetOuterBorderColor(const Vector4<Color>& color)
1889 {
1890     SetOutlineColor(color);
1891 }
1892 
SetOuterBorderWidth(const Vector4f & width)1893 void RSNode::SetOuterBorderWidth(const Vector4f& width)
1894 {
1895     SetOutlineWidth(width);
1896 }
1897 
SetOuterBorderStyle(const Vector4<BorderStyle> & style)1898 void RSNode::SetOuterBorderStyle(const Vector4<BorderStyle>& style)
1899 {
1900     SetOutlineStyle(style);
1901 }
1902 
SetOuterBorderRadius(const Vector4f & radius)1903 void RSNode::SetOuterBorderRadius(const Vector4f& radius)
1904 {
1905     SetOutlineRadius(radius);
1906 }
1907 
SetOutlineColor(const Vector4<Color> & color)1908 void RSNode::SetOutlineColor(const Vector4<Color>& color)
1909 {
1910     SetPropertyNG<ModifierNG::RSOutlineModifier, &ModifierNG::RSOutlineModifier::SetOutlineColor>(color);
1911 }
1912 
SetOutlineWidth(const Vector4f & width)1913 void RSNode::SetOutlineWidth(const Vector4f& width)
1914 {
1915     SetPropertyNG<ModifierNG::RSOutlineModifier, &ModifierNG::RSOutlineModifier::SetOutlineWidth>(width);
1916 }
1917 
SetOutlineStyle(const Vector4<BorderStyle> & style)1918 void RSNode::SetOutlineStyle(const Vector4<BorderStyle>& style)
1919 {
1920     Vector4<uint32_t> styles(static_cast<uint32_t>(style.x_), static_cast<uint32_t>(style.y_),
1921         static_cast<uint32_t>(style.z_), static_cast<uint32_t>(style.w_));
1922     SetPropertyNG<ModifierNG::RSOutlineModifier, &ModifierNG::RSOutlineModifier::SetOutlineStyle>(styles);
1923 }
1924 
SetOutlineDashWidth(const Vector4f & dashWidth)1925 void RSNode::SetOutlineDashWidth(const Vector4f& dashWidth)
1926 {
1927     SetPropertyNG<ModifierNG::RSOutlineModifier, &ModifierNG::RSOutlineModifier::SetOutlineDashWidth>(dashWidth);
1928 }
1929 
SetOutlineDashGap(const Vector4f & dashGap)1930 void RSNode::SetOutlineDashGap(const Vector4f& dashGap)
1931 {
1932     SetPropertyNG<ModifierNG::RSOutlineModifier, &ModifierNG::RSOutlineModifier::SetOutlineDashGap>(dashGap);
1933 }
1934 
SetOutlineRadius(const Vector4f & radius)1935 void RSNode::SetOutlineRadius(const Vector4f& radius)
1936 {
1937     SetPropertyNG<ModifierNG::RSOutlineModifier, &ModifierNG::RSOutlineModifier::SetOutlineRadius>(radius);
1938 }
1939 
SetUIBackgroundFilter(const OHOS::Rosen::Filter * backgroundFilter)1940 void RSNode::SetUIBackgroundFilter(const OHOS::Rosen::Filter* backgroundFilter)
1941 {
1942     if (backgroundFilter == nullptr) {
1943         ROSEN_LOGE("Failed to set backgroundFilter, backgroundFilter is null!");
1944         return;
1945     }
1946     std::shared_ptr<RSNGFilterBase> headFilter = nullptr;
1947     auto filterParas = backgroundFilter->GetAllPara();
1948     for (auto it = filterParas.begin(); it != filterParas.end(); ++it) {
1949         auto filterPara = *it;
1950         if (filterPara == nullptr) {
1951             continue;
1952         }
1953         if (auto curFilter = RSNGFilterBase::Create(filterPara)) {
1954             if (headFilter) {
1955                 headFilter->Append(curFilter);
1956             } else {
1957                 headFilter = curFilter; // init headFilter
1958             }
1959             continue;
1960         }
1961         switch (filterPara->GetParaType()) {
1962             case FilterPara::BLUR : {
1963                 auto filterBlurPara = std::static_pointer_cast<FilterBlurPara>(filterPara);
1964                 auto blurRadius = filterBlurPara->GetRadius();
1965                 SetBackgroundBlurRadiusX(blurRadius);
1966                 SetBackgroundBlurRadiusY(blurRadius);
1967                 break;
1968             }
1969             case FilterPara::WATER_RIPPLE : {
1970                 auto waterRipplePara = std::static_pointer_cast<WaterRipplePara>(filterPara);
1971                 auto waveCount = waterRipplePara->GetWaveCount();
1972                 auto rippleCenterX = waterRipplePara->GetRippleCenterX();
1973                 auto rippleCenterY = waterRipplePara->GetRippleCenterY();
1974                 auto progress = waterRipplePara->GetProgress();
1975                 auto rippleMode = waterRipplePara->GetRippleMode();
1976                 RSWaterRipplePara params { waveCount, rippleCenterX, rippleCenterY, rippleMode };
1977                 SetWaterRippleParams(params, progress);
1978                 break;
1979             }
1980 
1981             default:
1982                 break;
1983         }
1984     }
1985     SetBackgroundNGFilter(headFilter);
1986 }
1987 
SetUICompositingFilter(const OHOS::Rosen::Filter * compositingFilter)1988 void RSNode::SetUICompositingFilter(const OHOS::Rosen::Filter* compositingFilter)
1989 {
1990     if (compositingFilter == nullptr) {
1991         ROSEN_LOGE("Failed to set compositingFilter, compositingFilter is null!");
1992         return;
1993     }
1994     // To do: generate composed filter here. Now we just set compositing blur in v1.0.
1995     auto filterParas = compositingFilter->GetAllPara();
1996     for (const auto& filterPara : filterParas) {
1997         if (filterPara->GetParaType() == FilterPara::BLUR) {
1998             auto filterBlurPara = std::static_pointer_cast<FilterBlurPara>(filterPara);
1999             auto blurRadius = filterBlurPara->GetRadius();
2000             SetForegroundBlurRadiusX(blurRadius);
2001             SetForegroundBlurRadiusY(blurRadius);
2002         }
2003         if (filterPara->GetParaType() == FilterPara::PIXEL_STRETCH) {
2004             auto pixelStretchPara = std::static_pointer_cast<PixelStretchPara>(filterPara);
2005             auto stretchPercent = pixelStretchPara->GetStretchPercent();
2006             SetPixelStretchPercent(stretchPercent, pixelStretchPara->GetTileMode());
2007         }
2008         if (filterPara->GetParaType() == FilterPara::RADIUS_GRADIENT_BLUR) {
2009             auto radiusGradientBlurPara = std::static_pointer_cast<RadiusGradientBlurPara>(filterPara);
2010             auto rsLinearGradientBlurPara = std::make_shared<RSLinearGradientBlurPara>(
2011                 radiusGradientBlurPara->GetBlurRadius(),
2012                 radiusGradientBlurPara->GetFractionStops(),
2013                 radiusGradientBlurPara->GetDirection());
2014             rsLinearGradientBlurPara->isRadiusGradient_ = true;
2015             SetLinearGradientBlurPara(rsLinearGradientBlurPara);
2016         }
2017     }
2018 }
2019 
SetUIForegroundFilter(const OHOS::Rosen::Filter * foregroundFilter)2020 void RSNode::SetUIForegroundFilter(const OHOS::Rosen::Filter* foregroundFilter)
2021 {
2022     if (foregroundFilter == nullptr) {
2023         ROSEN_LOGE("Failed to set foregroundFilter, foregroundFilter is null!");
2024         return;
2025     }
2026     // To do: generate composed filter here. Now we just set foreground blur in v1.0.
2027     std::shared_ptr<RSNGFilterBase> headFilter = nullptr;
2028     auto& filterParas = foregroundFilter->GetAllPara();
2029     for (const auto& filterPara : filterParas) {
2030         if (filterPara == nullptr) {
2031             continue;
2032         }
2033         if (auto curFilter = RSNGFilterBase::Create(filterPara)) {
2034             if (headFilter) {
2035                 headFilter->Append(curFilter);
2036             } else {
2037                 headFilter = curFilter; // init headFilter
2038             }
2039             continue;
2040         }
2041         if (filterPara->GetParaType() == FilterPara::BLUR) {
2042             auto filterBlurPara = std::static_pointer_cast<FilterBlurPara>(filterPara);
2043             auto blurRadius = filterBlurPara->GetRadius();
2044             SetForegroundEffectRadius(blurRadius);
2045         }
2046         if (filterPara->GetParaType() == FilterPara::FLY_OUT) {
2047             auto flyOutPara = std::static_pointer_cast<FlyOutPara>(filterPara);
2048             auto flyMode = flyOutPara->GetFlyMode();
2049             auto degree = flyOutPara->GetDegree();
2050             RSFlyOutPara rs_fly_out_param = { flyMode };
2051             SetFlyOutParams(rs_fly_out_param, degree);
2052         }
2053         if (filterPara->GetParaType() == FilterPara::DISTORT) {
2054             auto distortPara = std::static_pointer_cast<DistortPara>(filterPara);
2055             auto distortionK = distortPara->GetDistortionK();
2056             SetDistortionK(distortionK);
2057         }
2058         if (filterPara->GetParaType() == FilterPara::HDR_BRIGHTNESS_RATIO) {
2059             auto hdrBrightnessRatioPara = std::static_pointer_cast<HDRBrightnessRatioPara>(filterPara);
2060             auto brightnessRatio = hdrBrightnessRatioPara->GetBrightnessRatio();
2061             SetHDRUIBrightness(brightnessRatio);
2062         }
2063     }
2064     SetForegroundNGFilter(headFilter);
2065 }
2066 
SetHDRUIBrightness(float hdrUIBrightness)2067 void RSNode::SetHDRUIBrightness(float hdrUIBrightness)
2068 {
2069     SetPropertyNG<ModifierNG::RSHDRBrightnessModifier, &ModifierNG::RSHDRBrightnessModifier::SetHDRUIBrightness>(
2070         hdrUIBrightness);
2071 }
2072 
SetVisualEffect(const VisualEffect * visualEffect)2073 void RSNode::SetVisualEffect(const VisualEffect* visualEffect)
2074 {
2075     if (visualEffect == nullptr) {
2076         ROSEN_LOGE("Failed to set visualEffect, visualEffect is null!");
2077         return;
2078     }
2079     // To do: generate composed visual effect here. Now we just set background brightness in v1.0.
2080     auto visualEffectParas = visualEffect->GetAllPara();
2081     bool hasHdrBrightnessBlender = false;
2082     for (const auto& visualEffectPara : visualEffectParas) {
2083         if (visualEffectPara == nullptr) {
2084             continue;
2085         }
2086         if (visualEffectPara->GetParaType() == VisualEffectPara::BORDER_LIGHT_EFFECT) {
2087             SetBackgroundNGShader(RSNGShaderBase::Create(visualEffectPara));
2088         }
2089         if (visualEffectPara->GetParaType() == VisualEffectPara::COLOR_GRADIENT_EFFECT) {
2090             std::shared_ptr<RSNGShaderBase> headVisualEffect = RSNGShaderBase::Create(visualEffectPara);
2091             SetBackgroundNGShader(headVisualEffect);
2092         }
2093 
2094         if (visualEffectPara->GetParaType() != VisualEffectPara::BACKGROUND_COLOR_EFFECT) {
2095             continue;
2096         }
2097         auto backgroundColorEffectPara = std::static_pointer_cast<BackgroundColorEffectPara>(visualEffectPara);
2098         auto blender = backgroundColorEffectPara->GetBlender();
2099         auto brightnessBlender = std::static_pointer_cast<BrightnessBlender>(blender);
2100         if (brightnessBlender == nullptr) {
2101             continue;
2102         }
2103         if (brightnessBlender->GetHdr() && ROSEN_GNE(brightnessBlender->GetFraction(), 0.0f)) {
2104             hasHdrBrightnessBlender = true;
2105         }
2106         auto fraction = brightnessBlender->GetFraction();
2107         SetBgBrightnessFract(fraction);
2108         SetBgBrightnessParams({ brightnessBlender->GetLinearRate(), brightnessBlender->GetDegree(),
2109             brightnessBlender->GetCubicRate(), brightnessBlender->GetQuadRate(), brightnessBlender->GetSaturation(),
2110             { brightnessBlender->GetPositiveCoeff().data_[0], brightnessBlender->GetPositiveCoeff().data_[1],
2111                 brightnessBlender->GetPositiveCoeff().data_[2] },
2112             { brightnessBlender->GetNegativeCoeff().data_[0], brightnessBlender->GetNegativeCoeff().data_[1],
2113                 brightnessBlender->GetNegativeCoeff().data_[2] } });
2114     }
2115 }
2116 
SetBorderLightShader(std::shared_ptr<VisualEffectPara> visualEffectPara)2117 void RSNode::SetBorderLightShader(std::shared_ptr<VisualEffectPara> visualEffectPara)
2118 {
2119     if (visualEffectPara == nullptr) {
2120         ROSEN_LOGE("RSNode::SetBorderLightShader: visualEffectPara is null!");
2121         return;
2122     }
2123     auto borderLightEffectPara = std::static_pointer_cast<BorderLightEffectPara>(visualEffectPara);
2124     Vector3f rotationAngle;
2125     float cornerRadius = 1.0f;
2126     RSBorderLightParams borderLightParam = {
2127         borderLightEffectPara->GetLightPosition(),
2128         borderLightEffectPara->GetLightColor(),
2129         borderLightEffectPara->GetLightIntensity(),
2130         borderLightEffectPara->GetLightWidth(),
2131         rotationAngle,
2132         cornerRadius
2133     };
2134     auto borderLightShader = std::make_shared<RSBorderLightShader>();
2135     borderLightShader->SetRSBorderLightParams(borderLightParam);
2136     SetBackgroundShader(borderLightShader);
2137 }
2138 
SetBlender(const Blender * blender)2139 void RSNode::SetBlender(const Blender* blender)
2140 {
2141     if (blender == nullptr) {
2142         ROSEN_LOGE("RSNode::SetBlender: blender is null!");
2143         return;
2144     }
2145 
2146     if (Blender::BRIGHTNESS_BLENDER == blender->GetBlenderType()) {
2147         auto brightnessBlender = static_cast<const BrightnessBlender*>(blender);
2148         if (brightnessBlender != nullptr) {
2149             SetFgBrightnessFract(brightnessBlender->GetFraction());
2150             SetFgBrightnessParams({ brightnessBlender->GetLinearRate(), brightnessBlender->GetDegree(),
2151                 brightnessBlender->GetCubicRate(), brightnessBlender->GetQuadRate(), brightnessBlender->GetSaturation(),
2152                 { brightnessBlender->GetPositiveCoeff().x_, brightnessBlender->GetPositiveCoeff().y_,
2153                     brightnessBlender->GetPositiveCoeff().z_ },
2154                 { brightnessBlender->GetNegativeCoeff().x_, brightnessBlender->GetNegativeCoeff().y_,
2155                     brightnessBlender->GetNegativeCoeff().z_ }});
2156             if (brightnessBlender->GetHdr()) {
2157                 SetFgBrightnessHdr(brightnessBlender->GetHdr());
2158             }
2159         }
2160     } else if (Blender::SHADOW_BLENDER == blender->GetBlenderType()) {
2161         auto shadowBlender = static_cast<const ShadowBlender*>(blender);
2162         if (shadowBlender != nullptr) {
2163             SetShadowBlenderParams({ shadowBlender->GetCubicCoeff(), shadowBlender->GetQuadraticCoeff(),
2164                 shadowBlender->GetLinearCoeff(), shadowBlender->GetConstantTerm() });
2165         }
2166     }
2167 }
2168 
SetShadowBlenderParams(const RSShadowBlenderPara & params)2169 void RSNode::SetShadowBlenderParams(const RSShadowBlenderPara& params)
2170 {
2171     SetPropertyNG<ModifierNG::RSBlendModifier, &ModifierNG::RSBlendModifier::SetShadowBlenderParams>(params);
2172 }
2173 
SetForegroundEffectRadius(const float blurRadius)2174 void RSNode::SetForegroundEffectRadius(const float blurRadius)
2175 {
2176     SetPropertyNG<ModifierNG::RSForegroundFilterModifier,
2177         &ModifierNG::RSForegroundFilterModifier::SetForegroundEffectRadius>(blurRadius);
2178 }
2179 
SetBackgroundFilter(const std::shared_ptr<RSFilter> & backgroundFilter)2180 void RSNode::SetBackgroundFilter(const std::shared_ptr<RSFilter>& backgroundFilter)
2181 {
2182     if (backgroundFilter == nullptr) {
2183         SetBackgroundBlurRadius(0.f);
2184         SetBackgroundBlurSaturation(1.f);
2185         SetBackgroundBlurBrightness(1.f);
2186         SetBackgroundBlurMaskColor(RSColor());
2187         SetBackgroundBlurColorMode(BLUR_COLOR_MODE::DEFAULT);
2188         SetBackgroundBlurRadiusX(0.f);
2189         SetBackgroundBlurRadiusY(0.f);
2190     } else if (backgroundFilter->GetFilterType() == RSFilter::MATERIAL) {
2191         auto materialFilter = std::static_pointer_cast<RSMaterialFilter>(backgroundFilter);
2192         float Radius = materialFilter->GetRadius();
2193         float Saturation = materialFilter->GetSaturation();
2194         float Brightness = materialFilter->GetBrightness();
2195         Color MaskColor = materialFilter->GetMaskColor();
2196         int ColorMode = materialFilter->GetColorMode();
2197         bool disableSystemAdaptation = materialFilter->GetDisableSystemAdaptation();
2198         SetBackgroundBlurRadius(Radius);
2199         SetBackgroundBlurSaturation(Saturation);
2200         SetBackgroundBlurBrightness(Brightness);
2201         SetBackgroundBlurMaskColor(MaskColor);
2202         SetBackgroundBlurColorMode(ColorMode);
2203         SetBgBlurDisableSystemAdaptation(disableSystemAdaptation);
2204     } else if (backgroundFilter->GetFilterType() == RSFilter::BLUR) {
2205         auto blurFilter = std::static_pointer_cast<RSBlurFilter>(backgroundFilter);
2206         float blurRadiusX = blurFilter->GetBlurRadiusX();
2207         float blurRadiusY = blurFilter->GetBlurRadiusY();
2208         bool disableSystemAdaptation = blurFilter->GetDisableSystemAdaptation();
2209         SetBackgroundBlurRadiusX(blurRadiusX);
2210         SetBackgroundBlurRadiusY(blurRadiusY);
2211         SetBgBlurDisableSystemAdaptation(disableSystemAdaptation);
2212     }
2213 }
2214 
SetBackgroundNGFilter(const std::shared_ptr<RSNGFilterBase> & backgroundFilter)2215 void RSNode::SetBackgroundNGFilter(const std::shared_ptr<RSNGFilterBase>& backgroundFilter)
2216 {
2217     if (!backgroundFilter) {
2218         ROSEN_LOGW("RSNode::SetBackgroundNGFilter background filter is nullptr");
2219         auto& modifier =
2220             modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::BACKGROUND_FILTER)];
2221         if (modifier != nullptr) {
2222             modifier->DetachProperty(ModifierNG::RSPropertyType::BACKGROUND_NG_FILTER);
2223         }
2224         return;
2225     }
2226     SetPropertyNG<ModifierNG::RSBackgroundFilterModifier,
2227         &ModifierNG::RSBackgroundFilterModifier::SetNGFilterBase>(backgroundFilter);
2228 }
2229 
SetForegroundNGFilter(const std::shared_ptr<RSNGFilterBase> & foregroundFilter)2230 void RSNode::SetForegroundNGFilter(const std::shared_ptr<RSNGFilterBase>& foregroundFilter)
2231 {
2232     if (!foregroundFilter) {
2233         ROSEN_LOGW("RSNode::SetForegroundNGFilter background filter is nullptr");
2234         auto& modifier =
2235             modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::FOREGROUND_FILTER)];
2236         if (modifier != nullptr) {
2237             modifier->DetachProperty(ModifierNG::RSPropertyType::FOREGROUND_NG_FILTER);
2238         }
2239         return;
2240     }
2241     SetPropertyNG<ModifierNG::RSForegroundFilterModifier,
2242         &ModifierNG::RSForegroundFilterModifier::SetNGFilterBase>(foregroundFilter);
2243 }
2244 
SetBackgroundNGShader(const std::shared_ptr<RSNGShaderBase> & backgroundShader)2245 void RSNode::SetBackgroundNGShader(const std::shared_ptr<RSNGShaderBase>& backgroundShader)
2246 {
2247     if (!backgroundShader) {
2248         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
2249         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2250         auto& modifier =
2251             modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::BACKGROUND_NG_SHADER)];
2252         if (modifier == nullptr || !modifier->HasProperty(ModifierNG::RSPropertyType::BACKGROUND_NG_SHADER)) {
2253             return;
2254         }
2255         modifier->DetachProperty(ModifierNG::RSPropertyType::BACKGROUND_NG_SHADER);
2256         return;
2257     }
2258     SetPropertyNG<ModifierNG::RSBackgroundNGShaderModifier,
2259         &ModifierNG::RSBackgroundNGShaderModifier::SetBackgroundNGShader>(backgroundShader);
2260 }
2261 
SetForegroundShader(const std::shared_ptr<RSNGShaderBase> & foregroundShader)2262 void RSNode::SetForegroundShader(const std::shared_ptr<RSNGShaderBase>& foregroundShader)
2263 {
2264     if (!foregroundShader) {
2265         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
2266         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2267         auto& modifier =
2268             modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierNG::RSModifierType::FOREGROUND_SHADER)];
2269         if (modifier == nullptr || !modifier->HasProperty(ModifierNG::RSPropertyType::FOREGROUND_SHADER)) {
2270             return;
2271         }
2272         modifier->DetachProperty(ModifierNG::RSPropertyType::FOREGROUND_SHADER);
2273         return;
2274     }
2275     SetPropertyNG<ModifierNG::RSForegroundShaderModifier,
2276         &ModifierNG::RSForegroundShaderModifier::SetForegroundShader>(foregroundShader);
2277 }
2278 
SetFilter(const std::shared_ptr<RSFilter> & filter)2279 void RSNode::SetFilter(const std::shared_ptr<RSFilter>& filter)
2280 {
2281     if (filter == nullptr) {
2282         SetForegroundBlurRadius(0.f);
2283         SetForegroundBlurSaturation(1.f);
2284         SetForegroundBlurBrightness(1.f);
2285         SetForegroundBlurMaskColor(RSColor());
2286         SetForegroundBlurColorMode(BLUR_COLOR_MODE::DEFAULT);
2287         SetForegroundBlurRadiusX(0.f);
2288         SetForegroundBlurRadiusY(0.f);
2289     } else if (filter->GetFilterType() == RSFilter::MATERIAL) {
2290         auto materialFilter = std::static_pointer_cast<RSMaterialFilter>(filter);
2291         float Radius = materialFilter->GetRadius();
2292         float Saturation = materialFilter->GetSaturation();
2293         float Brightness = materialFilter->GetBrightness();
2294         Color MaskColor = materialFilter->GetMaskColor();
2295         int ColorMode = materialFilter->GetColorMode();
2296         bool disableSystemAdaptation = materialFilter->GetDisableSystemAdaptation();
2297         SetForegroundBlurRadius(Radius);
2298         SetForegroundBlurSaturation(Saturation);
2299         SetForegroundBlurBrightness(Brightness);
2300         SetForegroundBlurMaskColor(MaskColor);
2301         SetForegroundBlurColorMode(ColorMode);
2302         SetFgBlurDisableSystemAdaptation(disableSystemAdaptation);
2303     } else if (filter->GetFilterType() == RSFilter::BLUR) {
2304         auto blurFilter = std::static_pointer_cast<RSBlurFilter>(filter);
2305         float blurRadiusX = blurFilter->GetBlurRadiusX();
2306         float blurRadiusY = blurFilter->GetBlurRadiusY();
2307         bool disableSystemAdaptation = blurFilter->GetDisableSystemAdaptation();
2308         SetForegroundBlurRadiusX(blurRadiusX);
2309         SetForegroundBlurRadiusY(blurRadiusY);
2310         SetFgBlurDisableSystemAdaptation(disableSystemAdaptation);
2311     }
2312 }
2313 
SetLinearGradientBlurPara(const std::shared_ptr<RSLinearGradientBlurPara> & para)2314 void RSNode::SetLinearGradientBlurPara(const std::shared_ptr<RSLinearGradientBlurPara>& para)
2315 {
2316     SetPropertyNG<ModifierNG::RSCompositingFilterModifier,
2317         &ModifierNG::RSCompositingFilterModifier::SetLinearGradientBlurPara>(para);
2318 }
2319 
SetMotionBlurPara(const float radius,const Vector2f & anchor)2320 void RSNode::SetMotionBlurPara(const float radius, const Vector2f& anchor)
2321 {
2322     Vector2f anchor1 = { anchor[0], anchor[1] };
2323     std::shared_ptr<MotionBlurParam> para = std::make_shared<MotionBlurParam>(radius, anchor1);
2324     SetPropertyNG<ModifierNG::RSForegroundFilterModifier, &ModifierNG::RSForegroundFilterModifier::SetMotionBlurParam>(
2325         para);
2326 }
2327 
SetDynamicLightUpRate(const float rate)2328 void RSNode::SetDynamicLightUpRate(const float rate)
2329 {
2330     SetPropertyNG<ModifierNG::RSDynamicLightUpModifier, &ModifierNG::RSDynamicLightUpModifier::SetDynamicLightUpRate>(
2331         rate);
2332 }
2333 
SetDynamicLightUpDegree(const float lightUpDegree)2334 void RSNode::SetDynamicLightUpDegree(const float lightUpDegree)
2335 {
2336     SetPropertyNG<ModifierNG::RSDynamicLightUpModifier, &ModifierNG::RSDynamicLightUpModifier::SetDynamicLightUpDegree>(
2337         lightUpDegree);
2338 }
2339 
SetFgBrightnessParams(const RSDynamicBrightnessPara & params)2340 void RSNode::SetFgBrightnessParams(const RSDynamicBrightnessPara& params)
2341 {
2342     // Compatible with original interfaces
2343     SetFgBrightnessRates(params.rates_);
2344     SetFgBrightnessSaturation(params.saturation_);
2345     SetFgBrightnessPosCoeff(params.posCoeff_);
2346     SetFgBrightnessNegCoeff(params.negCoeff_);
2347 }
2348 
SetFgBrightnessRates(const Vector4f & rates)2349 void RSNode::SetFgBrightnessRates(const Vector4f& rates)
2350 {
2351     SetPropertyNG<ModifierNG::RSBlendModifier, &ModifierNG::RSBlendModifier::SetFgBrightnessRates>(rates);
2352 }
2353 
SetFgBrightnessSaturation(const float & saturation)2354 void RSNode::SetFgBrightnessSaturation(const float& saturation)
2355 {
2356     SetPropertyNG<ModifierNG::RSBlendModifier, &ModifierNG::RSBlendModifier::SetFgBrightnessSaturation>(saturation);
2357 }
2358 
SetFgBrightnessPosCoeff(const Vector4f & coeff)2359 void RSNode::SetFgBrightnessPosCoeff(const Vector4f& coeff)
2360 {
2361     SetPropertyNG<ModifierNG::RSBlendModifier, &ModifierNG::RSBlendModifier::SetFgBrightnessPosCoeff>(coeff);
2362 }
2363 
SetFgBrightnessNegCoeff(const Vector4f & coeff)2364 void RSNode::SetFgBrightnessNegCoeff(const Vector4f& coeff)
2365 {
2366     SetPropertyNG<ModifierNG::RSBlendModifier, &ModifierNG::RSBlendModifier::SetFgBrightnessNegCoeff>(coeff);
2367 }
2368 
SetFgBrightnessFract(const float & fract)2369 void RSNode::SetFgBrightnessFract(const float& fract)
2370 {
2371     SetPropertyNG<ModifierNG::RSBlendModifier, &ModifierNG::RSBlendModifier::SetFgBrightnessFract>(fract);
2372 }
2373 
SetFgBrightnessHdr(const bool hdr)2374 void RSNode::SetFgBrightnessHdr(const bool hdr)
2375 {
2376     SetPropertyNG<ModifierNG::RSBlendModifier, &ModifierNG::RSBlendModifier::SetFgBrightnessHdr>(hdr);
2377 }
2378 
SetBgBrightnessParams(const RSDynamicBrightnessPara & params)2379 void RSNode::SetBgBrightnessParams(const RSDynamicBrightnessPara& params)
2380 {
2381     // Compatible with original interfaces
2382     SetBgBrightnessRates(params.rates_);
2383     SetBgBrightnessSaturation(params.saturation_);
2384     SetBgBrightnessPosCoeff(params.posCoeff_);
2385     SetBgBrightnessNegCoeff(params.negCoeff_);
2386 }
2387 
SetBgBrightnessRates(const Vector4f & rates)2388 void RSNode::SetBgBrightnessRates(const Vector4f& rates)
2389 {
2390     SetPropertyNG<ModifierNG::RSBackgroundColorModifier, &ModifierNG::RSBackgroundColorModifier::SetBgBrightnessRates>(
2391         rates);
2392 }
2393 
SetBgBrightnessSaturation(const float & saturation)2394 void RSNode::SetBgBrightnessSaturation(const float& saturation)
2395 {
2396     SetPropertyNG<ModifierNG::RSBackgroundColorModifier,
2397         &ModifierNG::RSBackgroundColorModifier::SetBgBrightnessSaturation>(saturation);
2398 }
2399 
SetBgBrightnessPosCoeff(const Vector4f & coeff)2400 void RSNode::SetBgBrightnessPosCoeff(const Vector4f& coeff)
2401 {
2402     SetPropertyNG<ModifierNG::RSBackgroundColorModifier,
2403         &ModifierNG::RSBackgroundColorModifier::SetBgBrightnessPosCoeff>(coeff);
2404 }
2405 
SetBgBrightnessNegCoeff(const Vector4f & coeff)2406 void RSNode::SetBgBrightnessNegCoeff(const Vector4f& coeff)
2407 {
2408     SetPropertyNG<ModifierNG::RSBackgroundColorModifier,
2409         &ModifierNG::RSBackgroundColorModifier::SetBgBrightnessNegCoeff>(coeff);
2410 }
2411 
SetBgBrightnessFract(const float & fract)2412 void RSNode::SetBgBrightnessFract(const float& fract)
2413 {
2414     SetPropertyNG<ModifierNG::RSBackgroundColorModifier, &ModifierNG::RSBackgroundColorModifier::SetBgBrightnessFract>(
2415         fract);
2416 }
2417 
SetGreyCoef(const Vector2f greyCoef)2418 void RSNode::SetGreyCoef(const Vector2f greyCoef)
2419 {
2420     SetPropertyNG<ModifierNG::RSBackgroundFilterModifier, &ModifierNG::RSBackgroundFilterModifier::SetGreyCoef>(
2421         greyCoef);
2422 }
2423 
SetCompositingFilter(const std::shared_ptr<RSFilter> & compositingFilter)2424 void RSNode::SetCompositingFilter(const std::shared_ptr<RSFilter>& compositingFilter) {}
2425 
SetShadowColor(uint32_t colorValue)2426 void RSNode::SetShadowColor(uint32_t colorValue)
2427 {
2428     auto color = Color::FromArgbInt(colorValue);
2429     SetPropertyNG<ModifierNG::RSShadowModifier, &ModifierNG::RSShadowModifier::SetShadowColor>(color);
2430 }
2431 
SetShadowOffset(float offsetX,float offsetY)2432 void RSNode::SetShadowOffset(float offsetX, float offsetY)
2433 {
2434     SetShadowOffsetX(offsetX);
2435     SetShadowOffsetY(offsetY);
2436 }
2437 
SetShadowOffsetX(float offsetX)2438 void RSNode::SetShadowOffsetX(float offsetX)
2439 {
2440     SetPropertyNG<ModifierNG::RSShadowModifier, &ModifierNG::RSShadowModifier::SetShadowOffsetX>(offsetX);
2441 }
2442 
SetShadowOffsetY(float offsetY)2443 void RSNode::SetShadowOffsetY(float offsetY)
2444 {
2445     SetPropertyNG<ModifierNG::RSShadowModifier, &ModifierNG::RSShadowModifier::SetShadowOffsetY>(offsetY);
2446 }
2447 
SetShadowAlpha(float alpha)2448 void RSNode::SetShadowAlpha(float alpha)
2449 {
2450     SetPropertyNG<ModifierNG::RSShadowModifier, &ModifierNG::RSShadowModifier::SetShadowAlpha>(alpha);
2451 }
2452 
SetShadowElevation(float elevation)2453 void RSNode::SetShadowElevation(float elevation)
2454 {
2455     SetPropertyNG<ModifierNG::RSShadowModifier, &ModifierNG::RSShadowModifier::SetShadowRadius>(0);
2456     SetPropertyNG<ModifierNG::RSShadowModifier, &ModifierNG::RSShadowModifier::SetShadowElevation>(elevation);
2457 }
2458 
SetShadowRadius(float radius)2459 void RSNode::SetShadowRadius(float radius)
2460 {
2461     SetPropertyNG<ModifierNG::RSShadowModifier, &ModifierNG::RSShadowModifier::SetShadowElevation>(0);
2462     SetPropertyNG<ModifierNG::RSShadowModifier, &ModifierNG::RSShadowModifier::SetShadowRadius>(radius);
2463 }
2464 
SetShadowPath(const std::shared_ptr<RSPath> & shadowPath)2465 void RSNode::SetShadowPath(const std::shared_ptr<RSPath>& shadowPath)
2466 {
2467     SetPropertyNG<ModifierNG::RSShadowModifier, &ModifierNG::RSShadowModifier::SetShadowPath>(shadowPath);
2468 }
2469 
SetShadowMask(bool shadowMask)2470 void RSNode::SetShadowMask(bool shadowMask)
2471 {
2472     SetShadowMaskStrategy(shadowMask ? SHADOW_MASK_STRATEGY::MASK_BLUR : SHADOW_MASK_STRATEGY::MASK_NONE);
2473 }
2474 
SetShadowMaskStrategy(SHADOW_MASK_STRATEGY strategy)2475 void RSNode::SetShadowMaskStrategy(SHADOW_MASK_STRATEGY strategy)
2476 {
2477     SetPropertyNG<ModifierNG::RSShadowModifier, &ModifierNG::RSShadowModifier::SetShadowMask>(strategy);
2478 }
2479 
SetShadowIsFilled(bool shadowIsFilled)2480 void RSNode::SetShadowIsFilled(bool shadowIsFilled)
2481 {
2482     SetPropertyNG<ModifierNG::RSShadowModifier, &ModifierNG::RSShadowModifier::SetShadowIsFilled>(shadowIsFilled);
2483 }
2484 
SetShadowColorStrategy(int shadowColorStrategy)2485 void RSNode::SetShadowColorStrategy(int shadowColorStrategy)
2486 {
2487     SetPropertyNG<ModifierNG::RSShadowModifier, &ModifierNG::RSShadowModifier::SetShadowColorStrategy>(
2488         shadowColorStrategy);
2489 }
2490 
SetFrameGravity(Gravity gravity)2491 void RSNode::SetFrameGravity(Gravity gravity)
2492 {
2493     SetPropertyNG<ModifierNG::RSFrameClipModifier, &ModifierNG::RSFrameClipModifier::SetFrameGravity>(gravity);
2494 }
2495 
SetClipRRect(const Vector4f & clipRect,const Vector4f & clipRadius)2496 void RSNode::SetClipRRect(const Vector4f& clipRect, const Vector4f& clipRadius)
2497 {
2498     SetClipRRect(std::make_shared<RRect>(clipRect, clipRadius));
2499 }
2500 
SetClipRRect(const std::shared_ptr<RRect> & rrect)2501 void RSNode::SetClipRRect(const std::shared_ptr<RRect>& rrect)
2502 {
2503     SetPropertyNG<ModifierNG::RSBoundsClipModifier, &ModifierNG::RSBoundsClipModifier::SetClipRRect>(rrect);
2504 }
2505 
SetClipBounds(const std::shared_ptr<RSPath> & path)2506 void RSNode::SetClipBounds(const std::shared_ptr<RSPath>& path)
2507 {
2508     SetPropertyNG<ModifierNG::RSBoundsClipModifier, &ModifierNG::RSBoundsClipModifier::SetClipBounds>(path);
2509 }
2510 
SetClipToBounds(bool clipToBounds)2511 void RSNode::SetClipToBounds(bool clipToBounds)
2512 {
2513     SetPropertyNG<ModifierNG::RSBoundsClipModifier, &ModifierNG::RSBoundsClipModifier::SetClipToBounds>(clipToBounds);
2514 }
2515 
SetClipToFrame(bool clipToFrame)2516 void RSNode::SetClipToFrame(bool clipToFrame)
2517 {
2518     SetPropertyNG<ModifierNG::RSFrameClipModifier, &ModifierNG::RSFrameClipModifier::SetClipToFrame>(clipToFrame);
2519 }
2520 
SetCustomClipToFrame(const Vector4f & clipRect)2521 void RSNode::SetCustomClipToFrame(const Vector4f& clipRect)
2522 {
2523     SetPropertyNG<ModifierNG::RSFrameClipModifier, &ModifierNG::RSFrameClipModifier::SetCustomClipToFrame>(clipRect);
2524 }
2525 
SetHDRBrightness(const float & hdrBrightness)2526 void RSNode::SetHDRBrightness(const float& hdrBrightness)
2527 {
2528     SetPropertyNG<ModifierNG::RSHDRBrightnessModifier, &ModifierNG::RSHDRBrightnessModifier::SetHDRBrightness>(
2529         hdrBrightness);
2530 }
2531 
SetHDRBrightnessFactor(float factor)2532 void RSNode::SetHDRBrightnessFactor(float factor)
2533 {
2534     if (!IsInstanceOf<RSDisplayNode>()) {
2535         ROSEN_LOGE("SetHDRBrightnessFactor only can be used by RSDisplayNode");
2536         return;
2537     }
2538     SetPropertyNG<ModifierNG::RSHDRBrightnessModifier, &ModifierNG::RSHDRBrightnessModifier::SetHDRBrightnessFactor>(
2539         factor);
2540 }
2541 
SetVisible(bool visible)2542 void RSNode::SetVisible(bool visible)
2543 {
2544     // kick off transition only if it's on tree(has valid parent) and visibility is changed.
2545     if (transitionEffect_ != nullptr && GetParent() != nullptr && visible != GetStagingProperties().GetVisible()) {
2546         NotifyTransition(transitionEffect_, visible);
2547     }
2548 
2549     SetPropertyNG<ModifierNG::RSVisibilityModifier, &ModifierNG::RSVisibilityModifier::SetVisible>(visible);
2550 }
2551 
SetMask(const std::shared_ptr<RSMask> & mask)2552 void RSNode::SetMask(const std::shared_ptr<RSMask>& mask)
2553 {
2554     SetPropertyNG<ModifierNG::RSMaskModifier, &ModifierNG::RSMaskModifier::SetMask>(mask);
2555 }
2556 
SetUseEffect(bool useEffect)2557 void RSNode::SetUseEffect(bool useEffect)
2558 {
2559     SetPropertyNG<ModifierNG::RSUseEffectModifier, &ModifierNG::RSUseEffectModifier::SetUseEffect>(useEffect);
2560 }
2561 
SetUseEffectType(UseEffectType useEffectType)2562 void RSNode::SetUseEffectType(UseEffectType useEffectType)
2563 {
2564     SetPropertyNG<ModifierNG::RSUseEffectModifier, &ModifierNG::RSUseEffectModifier::SetUseEffectType>(useEffectType);
2565 }
2566 
SetAlwaysSnapshot(bool enable)2567 void RSNode::SetAlwaysSnapshot(bool enable)
2568 {
2569     SetPropertyNG<ModifierNG::RSBackgroundFilterModifier, &ModifierNG::RSBackgroundFilterModifier::SetAlwaysSnapshot>(
2570         enable);
2571 }
2572 
SetUseShadowBatching(bool useShadowBatching)2573 void RSNode::SetUseShadowBatching(bool useShadowBatching)
2574 {
2575     SetPropertyNG<ModifierNG::RSShadowModifier, &ModifierNG::RSShadowModifier::SetUseShadowBatching>(useShadowBatching);
2576 }
2577 
SetColorBlendMode(RSColorBlendMode colorBlendMode)2578 void RSNode::SetColorBlendMode(RSColorBlendMode colorBlendMode)
2579 {
2580     SetPropertyNG<ModifierNG::RSBlendModifier, &ModifierNG::RSBlendModifier::SetColorBlendMode>(colorBlendMode);
2581 }
2582 
SetColorBlendApplyType(RSColorBlendApplyType colorBlendApplyType)2583 void RSNode::SetColorBlendApplyType(RSColorBlendApplyType colorBlendApplyType)
2584 {
2585     SetPropertyNG<ModifierNG::RSBlendModifier, &ModifierNG::RSBlendModifier::SetColorBlendApplyType>(
2586         colorBlendApplyType);
2587 }
2588 
SetPixelStretch(const Vector4f & stretchSize,Drawing::TileMode stretchTileMode)2589 void RSNode::SetPixelStretch(const Vector4f& stretchSize, Drawing::TileMode stretchTileMode)
2590 {
2591     SetPropertyNG<ModifierNG::RSPixelStretchModifier, &ModifierNG::RSPixelStretchModifier::SetPixelStretchSize>(
2592         stretchSize);
2593     SetPropertyNG<ModifierNG::RSPixelStretchModifier, &ModifierNG::RSPixelStretchModifier::SetPixelStretchTileMode>(
2594         static_cast<int>(stretchTileMode));
2595 }
2596 
SetPixelStretchPercent(const Vector4f & stretchPercent,Drawing::TileMode stretchTileMode)2597 void RSNode::SetPixelStretchPercent(const Vector4f& stretchPercent, Drawing::TileMode stretchTileMode)
2598 {
2599     SetPropertyNG<ModifierNG::RSPixelStretchModifier, &ModifierNG::RSPixelStretchModifier::SetPixelStretchPercent>(
2600         stretchPercent);
2601     SetPropertyNG<ModifierNG::RSPixelStretchModifier, &ModifierNG::RSPixelStretchModifier::SetPixelStretchTileMode>(
2602         static_cast<int>(stretchTileMode));
2603 }
2604 
SetWaterRippleParams(const RSWaterRipplePara & params,float progress)2605 void RSNode::SetWaterRippleParams(const RSWaterRipplePara& params, float progress)
2606 {
2607     SetPropertyNG<ModifierNG::RSBackgroundFilterModifier,
2608         &ModifierNG::RSBackgroundFilterModifier::SetWaterRippleParams>(params);
2609     SetPropertyNG<ModifierNG::RSBackgroundFilterModifier,
2610         &ModifierNG::RSBackgroundFilterModifier::SetWaterRippleProgress>(progress);
2611 }
2612 
SetFlyOutParams(const RSFlyOutPara & params,float degree)2613 void RSNode::SetFlyOutParams(const RSFlyOutPara& params, float degree)
2614 {
2615     SetPropertyNG<ModifierNG::RSForegroundFilterModifier, &ModifierNG::RSForegroundFilterModifier::SetFlyOutParams>(
2616         params);
2617     SetPropertyNG<ModifierNG::RSForegroundFilterModifier, &ModifierNG::RSForegroundFilterModifier::SetFlyOutDegree>(
2618         degree);
2619 }
2620 
SetDistortionK(const float distortionK)2621 void RSNode::SetDistortionK(const float distortionK)
2622 {
2623     SetPropertyNG<ModifierNG::RSForegroundFilterModifier, &ModifierNG::RSForegroundFilterModifier::SetDistortionK>(
2624         distortionK);
2625 }
2626 
SetFreeze(bool isFreeze)2627 void RSNode::SetFreeze(bool isFreeze)
2628 {
2629     ROSEN_LOGE("SetFreeze only support RSSurfaceNode and RSCanvasNode in uniRender");
2630 }
2631 
SetNodeName(const std::string & nodeName)2632 void RSNode::SetNodeName(const std::string& nodeName)
2633 {
2634     if (nodeName_ != nodeName) {
2635         nodeName_ = nodeName;
2636         std::unique_ptr<RSCommand> command = std::make_unique<RSSetNodeName>(GetId(), nodeName_);
2637         AddCommand(command, IsRenderServiceNode());
2638     }
2639 }
2640 
SetTakeSurfaceForUIFlag()2641 void RSNode::SetTakeSurfaceForUIFlag()
2642 {
2643     std::unique_ptr<RSCommand> command = std::make_unique<RSSetTakeSurfaceForUIFlag>(GetId());
2644     auto transaction = GetRSTransaction();
2645     if (transaction != nullptr) {
2646         transaction->AddCommand(command, IsRenderServiceNode());
2647         ROSEN_LOGW("OffScreenIsSync SetTakeSurfaceForUIFlag AddCommand be processed. nodeId: [%{public}" PRIu64 "]"
2648             ", IsRenderServiceNode: [%{public}s]", GetId(), IsRenderServiceNode() ? "true" : "false");
2649         transaction->FlushImplicitTransaction();
2650     } else {
2651         auto transactionProxy = RSTransactionProxy::GetInstance();
2652         if (transactionProxy != nullptr) {
2653             transactionProxy->AddCommand(command, IsRenderServiceNode());
2654             ROSEN_LOGW("OffScreenIsSync SetTakeSurfaceForUIFlag AddCommand be processed. nodeId:[%{public}" PRIu64 "]"
2655                 ", IsRenderServiceNode: [%{public}s] (Proxy)", GetId(), IsRenderServiceNode() ? "true" : "false");
2656             transactionProxy->FlushImplicitTransaction();
2657         }
2658     }
2659 }
2660 
SetSpherizeDegree(float spherizeDegree)2661 void RSNode::SetSpherizeDegree(float spherizeDegree)
2662 {
2663     SetPropertyNG<ModifierNG::RSForegroundFilterModifier, &ModifierNG::RSForegroundFilterModifier::SetSpherize>(
2664         spherizeDegree);
2665 }
2666 
SetAttractionEffect(float fraction,const Vector2f & destinationPoint)2667 void RSNode::SetAttractionEffect(float fraction, const Vector2f& destinationPoint)
2668 {
2669     SetAttractionEffectFraction(fraction);
2670     SetAttractionEffectDstPoint(destinationPoint);
2671 }
2672 
SetAttractionEffectFraction(float fraction)2673 void RSNode::SetAttractionEffectFraction(float fraction)
2674 {
2675     SetPropertyNG<ModifierNG::RSForegroundFilterModifier,
2676         &ModifierNG::RSForegroundFilterModifier::SetAttractionFraction>(fraction);
2677 }
2678 
SetAttractionEffectDstPoint(const Vector2f & destinationPoint)2679 void RSNode::SetAttractionEffectDstPoint(const Vector2f& destinationPoint)
2680 {
2681     SetPropertyNG<ModifierNG::RSForegroundFilterModifier,
2682         &ModifierNG::RSForegroundFilterModifier::SetAttractionDstPoint>(destinationPoint);
2683 }
2684 
NotifyTransition(const std::shared_ptr<const RSTransitionEffect> & effect,bool isTransitionIn)2685 void RSNode::NotifyTransition(const std::shared_ptr<const RSTransitionEffect>& effect, bool isTransitionIn)
2686 {
2687     auto rsUIContext = rsUIContext_.lock();
2688     auto implicitAnimator = rsUIContext ? rsUIContext->GetRSImplicitAnimator()
2689                                         : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
2690     if (implicitAnimator == nullptr) {
2691         ROSEN_LOGE("Failed to notify transition, implicit animator is null!");
2692         return;
2693     }
2694 
2695     if (!implicitAnimator->NeedImplicitAnimation()) {
2696         return;
2697     }
2698 
2699     auto& customEffects = isTransitionIn ? effect->customTransitionInEffects_ : effect->customTransitionOutEffects_;
2700     // temporary close the implicit animation
2701     ExecuteWithoutAnimation(
2702         [&customEffects] {
2703             for (auto& customEffect : customEffects) {
2704                 customEffect->Active();
2705             }
2706         },
2707         rsUIContext, implicitAnimator);
2708 
2709     implicitAnimator->BeginImplicitTransition(effect, isTransitionIn);
2710     for (auto& customEffect : customEffects) {
2711         customEffect->Identity();
2712     }
2713     implicitAnimator->CreateImplicitTransition(*this);
2714     implicitAnimator->EndImplicitTransition();
2715 }
2716 
OnAddChildren()2717 void RSNode::OnAddChildren()
2718 {
2719     // kick off transition only if it's visible.
2720     if (transitionEffect_ != nullptr && GetStagingProperties().GetVisible()) {
2721         NotifyTransition(transitionEffect_, true);
2722     }
2723 }
2724 
OnRemoveChildren()2725 void RSNode::OnRemoveChildren()
2726 {
2727     // kick off transition only if it's visible.
2728     if (transitionEffect_ != nullptr && GetStagingProperties().GetVisible()) {
2729         NotifyTransition(transitionEffect_, false);
2730     }
2731 }
2732 
SetBackgroundBlurRadius(float radius)2733 void RSNode::SetBackgroundBlurRadius(float radius)
2734 {
2735     SetPropertyNG<ModifierNG::RSBackgroundFilterModifier,
2736         &ModifierNG::RSBackgroundFilterModifier::SetBackgroundBlurRadius>(radius);
2737 }
2738 
SetBackgroundBlurSaturation(float saturation)2739 void RSNode::SetBackgroundBlurSaturation(float saturation)
2740 {
2741     SetPropertyNG<ModifierNG::RSBackgroundFilterModifier,
2742         &ModifierNG::RSBackgroundFilterModifier::SetBackgroundBlurSaturation>(saturation);
2743 }
2744 
SetBackgroundBlurBrightness(float brightness)2745 void RSNode::SetBackgroundBlurBrightness(float brightness)
2746 {
2747     SetPropertyNG<ModifierNG::RSBackgroundFilterModifier,
2748         &ModifierNG::RSBackgroundFilterModifier::SetBackgroundBlurBrightness>(brightness);
2749 }
2750 
SetBackgroundBlurMaskColor(Color maskColor)2751 void RSNode::SetBackgroundBlurMaskColor(Color maskColor)
2752 {
2753     SetPropertyNG<ModifierNG::RSBackgroundFilterModifier,
2754         &ModifierNG::RSBackgroundFilterModifier::SetBackgroundBlurMaskColor>(maskColor);
2755 }
2756 
SetBackgroundBlurColorMode(int colorMode)2757 void RSNode::SetBackgroundBlurColorMode(int colorMode)
2758 {
2759     SetPropertyNG<ModifierNG::RSBackgroundFilterModifier,
2760         &ModifierNG::RSBackgroundFilterModifier::SetBackgroundBlurColorMode>(colorMode);
2761 }
2762 
SetBackgroundBlurRadiusX(float blurRadiusX)2763 void RSNode::SetBackgroundBlurRadiusX(float blurRadiusX)
2764 {
2765     SetPropertyNG<ModifierNG::RSBackgroundFilterModifier,
2766         &ModifierNG::RSBackgroundFilterModifier::SetBackgroundBlurRadiusX>(blurRadiusX);
2767 }
2768 
SetBackgroundBlurRadiusY(float blurRadiusY)2769 void RSNode::SetBackgroundBlurRadiusY(float blurRadiusY)
2770 {
2771     SetPropertyNG<ModifierNG::RSBackgroundFilterModifier,
2772         &ModifierNG::RSBackgroundFilterModifier::SetBackgroundBlurRadiusY>(blurRadiusY);
2773 }
2774 
SetBgBlurDisableSystemAdaptation(bool disableSystemAdaptation)2775 void RSNode::SetBgBlurDisableSystemAdaptation(bool disableSystemAdaptation)
2776 {
2777     SetPropertyNG<ModifierNG::RSBackgroundFilterModifier,
2778         &ModifierNG::RSBackgroundFilterModifier::SetBgBlurDisableSystemAdaptation>(disableSystemAdaptation);
2779 }
2780 
SetForegroundBlurRadius(float radius)2781 void RSNode::SetForegroundBlurRadius(float radius)
2782 {
2783     SetPropertyNG<ModifierNG::RSCompositingFilterModifier,
2784         &ModifierNG::RSCompositingFilterModifier::SetForegroundBlurRadius>(radius);
2785 }
2786 
SetForegroundBlurSaturation(float saturation)2787 void RSNode::SetForegroundBlurSaturation(float saturation)
2788 {
2789     SetPropertyNG<ModifierNG::RSCompositingFilterModifier,
2790         &ModifierNG::RSCompositingFilterModifier::SetForegroundBlurSaturation>(saturation);
2791 }
2792 
SetForegroundBlurBrightness(float brightness)2793 void RSNode::SetForegroundBlurBrightness(float brightness)
2794 {
2795     SetPropertyNG<ModifierNG::RSCompositingFilterModifier,
2796         &ModifierNG::RSCompositingFilterModifier::SetForegroundBlurBrightness>(brightness);
2797 }
2798 
SetForegroundBlurMaskColor(Color maskColor)2799 void RSNode::SetForegroundBlurMaskColor(Color maskColor)
2800 {
2801     SetPropertyNG<ModifierNG::RSCompositingFilterModifier,
2802         &ModifierNG::RSCompositingFilterModifier::SetForegroundBlurMaskColor>(maskColor);
2803 }
2804 
SetForegroundBlurColorMode(int colorMode)2805 void RSNode::SetForegroundBlurColorMode(int colorMode)
2806 {
2807     SetPropertyNG<ModifierNG::RSCompositingFilterModifier,
2808         &ModifierNG::RSCompositingFilterModifier::SetForegroundBlurColorMode>(colorMode);
2809 }
2810 
SetForegroundBlurRadiusX(float blurRadiusX)2811 void RSNode::SetForegroundBlurRadiusX(float blurRadiusX)
2812 {
2813     SetPropertyNG<ModifierNG::RSCompositingFilterModifier,
2814         &ModifierNG::RSCompositingFilterModifier::SetForegroundBlurRadiusX>(blurRadiusX);
2815 }
2816 
SetForegroundBlurRadiusY(float blurRadiusY)2817 void RSNode::SetForegroundBlurRadiusY(float blurRadiusY)
2818 {
2819     SetPropertyNG<ModifierNG::RSCompositingFilterModifier,
2820         &ModifierNG::RSCompositingFilterModifier::SetForegroundBlurRadiusY>(blurRadiusY);
2821 }
2822 
SetFgBlurDisableSystemAdaptation(bool disableSystemAdaptation)2823 void RSNode::SetFgBlurDisableSystemAdaptation(bool disableSystemAdaptation)
2824 {
2825     SetPropertyNG<ModifierNG::RSCompositingFilterModifier,
2826         &ModifierNG::RSCompositingFilterModifier::SetFgBlurDisableSystemAdaptation>(disableSystemAdaptation);
2827 }
2828 
AnimationCallback(AnimationId animationId,AnimationCallbackEvent event)2829 bool RSNode::AnimationCallback(AnimationId animationId, AnimationCallbackEvent event)
2830 {
2831     std::shared_ptr<RSAnimation> animation = nullptr;
2832     {
2833         std::unique_lock<std::recursive_mutex> lock(animationMutex_);
2834         auto animationItr = animations_.find(animationId);
2835         if (animationItr == animations_.end()) {
2836             ROSEN_LOGE("Failed to find animation[%{public}" PRIu64 "]!", animationId);
2837             return false;
2838         }
2839         animation = animationItr->second;
2840     }
2841 
2842     if (animation == nullptr) {
2843         ROSEN_LOGE("Failed to callback animation[%{public}" PRIu64 "], animation is null!", animationId);
2844         return false;
2845     }
2846     if (event == FINISHED) {
2847         RemoveAnimationInner(animation);
2848         animation->CallFinishCallback();
2849         return true;
2850     } else if (event == REPEAT_FINISHED) {
2851         animation->CallRepeatCallback();
2852         return true;
2853     } else if (event == LOGICALLY_FINISHED) {
2854         animation->CallLogicallyFinishCallback();
2855         return true;
2856     }
2857     ROSEN_LOGE("Failed to callback animation event[%{public}d], event is null!", event);
2858     return false;
2859 }
2860 
SetPaintOrder(bool drawContentLast)2861 void RSNode::SetPaintOrder(bool drawContentLast)
2862 {
2863     drawContentLast_ = drawContentLast;
2864 }
2865 
ClearAllModifiers()2866 void RSNode::ClearAllModifiers()
2867 {
2868     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
2869     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2870     for (auto [id, modifier] : modifiersNG_) {
2871         if (modifier) {
2872             modifier->OnDetach();
2873         }
2874     }
2875     modifiersNG_.clear();
2876     modifiersTypeMap_.clear();
2877     properties_.clear();
2878 }
2879 
DoFlushModifier()2880 void RSNode::DoFlushModifier()
2881 {
2882     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
2883     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2884     auto transactionProxy = RSTransactionProxy::GetInstance();
2885     if (transactionProxy == nullptr) {
2886         return;
2887     }
2888     if (!modifiersNG_.empty()) {
2889         std::unique_ptr<RSCommand> removeAllModifiersCommand = std::make_unique<RSRemoveAllModifiersNG>(GetId());
2890         AddCommand(removeAllModifiersCommand, IsRenderServiceNode(), GetFollowType(), GetId());
2891         for (const auto& [_, modifier] : modifiersNG_) {
2892             std::unique_ptr<RSCommand> command =
2893                 std::make_unique<RSAddModifierNG>(GetId(), modifier->CreateRenderModifier());
2894             AddCommand(command, IsRenderServiceNode(), GetFollowType(), GetId());
2895         }
2896     }
2897 }
2898 
GetModifier(const PropertyId & propertyId)2899 const std::shared_ptr<RSModifier> RSNode::GetModifier(const PropertyId& propertyId)
2900 {
2901     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
2902     CHECK_FALSE_RETURN_VALUE(CheckMultiThreadAccess(__func__), nullptr);
2903     auto iter = modifiers_.find(propertyId);
2904     if (iter != modifiers_.end()) {
2905         return iter->second;
2906     }
2907 
2908     return {};
2909 }
2910 
GetProperty(const PropertyId & propertyId)2911 const std::shared_ptr<RSPropertyBase> RSNode::GetProperty(const PropertyId& propertyId)
2912 {
2913     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
2914     CHECK_FALSE_RETURN_VALUE(CheckMultiThreadAccess(__func__), nullptr);
2915     auto iter = properties_.find(propertyId);
2916     if (iter != properties_.end()) {
2917         return iter->second;
2918     }
2919 
2920     return {};
2921 }
2922 
RegisterProperty(std::shared_ptr<RSPropertyBase> property)2923 void RSNode::RegisterProperty(std::shared_ptr<RSPropertyBase> property)
2924 {
2925     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
2926     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2927     if (property) {
2928         properties_.emplace(property->GetId(), property);
2929     }
2930 }
2931 
UnregisterProperty(const PropertyId & propertyId)2932 void RSNode::UnregisterProperty(const PropertyId& propertyId)
2933 {
2934     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
2935     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2936     auto iter = properties_.find(propertyId);
2937     if (iter != properties_.end()) {
2938         properties_.erase(iter);
2939     }
2940 }
2941 
GetModifierByType(const ModifierNG::RSModifierType & type)2942 const std::shared_ptr<ModifierNG::RSModifier> RSNode::GetModifierByType(const ModifierNG::RSModifierType& type)
2943 {
2944     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
2945     CHECK_FALSE_RETURN_VALUE(CheckMultiThreadAccess(__func__), nullptr);
2946     for (auto [id, modifier] : modifiersNG_) {
2947         if (modifier && modifier->GetType() == type) {
2948             return modifier;
2949         }
2950     }
2951     return {};
2952 }
2953 
UpdateModifierMotionPathOption()2954 void RSNode::UpdateModifierMotionPathOption()
2955 {
2956     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
2957     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2958     SetMotionPathOptionToProperty(ModifierNG::RSModifierType::BOUNDS, ModifierNG::RSPropertyType::BOUNDS);
2959     SetMotionPathOptionToProperty(ModifierNG::RSModifierType::FRAME, ModifierNG::RSPropertyType::FRAME);
2960     SetMotionPathOptionToProperty(ModifierNG::RSModifierType::TRANSFORM, ModifierNG::RSPropertyType::TRANSLATE);
2961     for (const auto& [_, property] : properties_) {
2962         if (property->IsPathAnimatable()) {
2963             property->SetMotionPathOption(motionPathOption_);
2964         }
2965     }
2966 }
2967 
SetMotionPathOptionToProperty(const ModifierNG::RSModifierType & modifierType,const ModifierNG::RSPropertyType & propertyType)2968 void RSNode::SetMotionPathOptionToProperty(
2969     const ModifierNG::RSModifierType& modifierType, const ModifierNG::RSPropertyType& propertyType)
2970 {
2971     auto& property = GetPropertyByType(modifierType, propertyType);
2972     if (!property) {
2973         return;
2974     }
2975     property->SetMotionPathOption(motionPathOption_);
2976 }
2977 
CheckMultiThreadAccess(const std::string & func) const2978 bool RSNode::CheckMultiThreadAccess(const std::string& func) const
2979 {
2980     if (isSkipCheckInMultiInstance_) {
2981         return true;
2982     }
2983     auto rsContext = rsUIContext_.lock();
2984     if (rsContext == nullptr) {
2985         return true;
2986     }
2987 #ifdef ROSEN_OHOS
2988     thread_local auto tid = gettid();
2989     if ((tid != ExtractTid(rsContext->GetToken()))) {
2990         ROSEN_LOGE("RSNode::CheckMultiThreadAccess nodeId is %{public}" PRIu64 ", func:%{public}s is not "
2991                    "correspond tid is "
2992                    "%{public}d context "
2993                    "tid is %{public}d"
2994                    "nodeType is %{public}d",
2995             GetId(),
2996             func.c_str(),
2997             tid,
2998             ExtractTid(rsContext->GetToken()),
2999             GetType());
3000         return false;
3001     }
3002 #endif
3003     return true;
3004 }
3005 
SetSkipCheckInMultiInstance(bool isSkipCheckInMultiInstance)3006 void RSNode::SetSkipCheckInMultiInstance(bool isSkipCheckInMultiInstance)
3007 {
3008     isSkipCheckInMultiInstance_ = isSkipCheckInMultiInstance;
3009 }
3010 
UpdateOcclusionCullingStatus(bool enable,NodeId keyOcclusionNodeId)3011 void RSNode::UpdateOcclusionCullingStatus(bool enable, NodeId keyOcclusionNodeId)
3012 {
3013     std::unique_ptr<RSCommand> command =
3014         std::make_unique<RSUpdateOcclusionCullingStatus>(GetId(), enable, keyOcclusionNodeId);
3015     AddCommand(command, IsRenderServiceNode());
3016 }
3017 
GetModifierIds() const3018 std::vector<PropertyId> RSNode::GetModifierIds() const
3019 {
3020     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
3021     std::vector<PropertyId> ids;
3022     CHECK_FALSE_RETURN_VALUE(CheckMultiThreadAccess(__func__), ids);
3023     for (const auto& [id, _] : modifiers_) {
3024         ids.push_back(id);
3025     }
3026     return ids;
3027 }
3028 
MarkAllExtendModifierDirty()3029 void RSNode::MarkAllExtendModifierDirty()
3030 {
3031     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
3032     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3033     if (extendModifierIsDirty_) {
3034         return;
3035     }
3036 
3037     auto rsUIContext = rsUIContext_.lock();
3038     auto modifierManager = rsUIContext ? rsUIContext->GetRSModifierManager()
3039                                        : RSModifierManagerMap::Instance()->GetModifierManager(gettid());
3040     extendModifierIsDirty_ = true;
3041     for (auto& [id, modifier] : modifiersNG_) {
3042         if (modifier->GetType() < ModifierNG::RSModifierType::TRANSITION_STYLE) {
3043             continue;
3044         }
3045         modifier->SetDirty(true, modifierManager);
3046     }
3047 }
3048 
ResetExtendModifierDirty()3049 void RSNode::ResetExtendModifierDirty()
3050 {
3051     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3052     extendModifierIsDirty_ = false;
3053 }
3054 
SetIsCustomTextType(bool isCustomTextType)3055 void RSNode::SetIsCustomTextType(bool isCustomTextType)
3056 {
3057     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3058     isCustomTextType_ = isCustomTextType;
3059 }
3060 
GetIsCustomTextType()3061 bool RSNode::GetIsCustomTextType()
3062 {
3063     return isCustomTextType_;
3064 }
3065 
SetIsCustomTypeface(bool isCustomTypeface)3066 void RSNode::SetIsCustomTypeface(bool isCustomTypeface)
3067 {
3068     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3069     isCustomTypeface_ = isCustomTypeface;
3070 }
3071 
GetIsCustomTypeface()3072 bool RSNode::GetIsCustomTypeface()
3073 {
3074     return isCustomTypeface_;
3075 }
3076 
SetDrawRegion(std::shared_ptr<RectF> rect)3077 void RSNode::SetDrawRegion(std::shared_ptr<RectF> rect)
3078 {
3079     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3080     if (drawRegion_ != rect) {
3081         drawRegion_ = rect;
3082         std::unique_ptr<RSCommand> command = std::make_unique<RSSetDrawRegion>(GetId(), rect);
3083         AddCommand(command, IsRenderServiceNode(), GetFollowType(), GetId());
3084 #ifdef RS_ENABLE_VK
3085         if (RSSystemProperties::GetHybridRenderEnabled() && !drawRegion_->IsEmpty()) {
3086             RSModifiersDraw::AddDrawRegions(id_, drawRegion_);
3087         }
3088 #endif
3089     }
3090 }
3091 
SetNeedUseCmdlistDrawRegion(bool needUseCmdlistDrawRegion)3092 void RSNode::SetNeedUseCmdlistDrawRegion(bool needUseCmdlistDrawRegion)
3093 {
3094     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3095     std::unique_ptr<RSCommand> command =
3096         std::make_unique<RSSetNeedUseCmdlistDrawRegion>(GetId(), needUseCmdlistDrawRegion);
3097     AddCommand(command, IsRenderServiceNode(), GetFollowType(), GetId());
3098 }
3099 
RegisterTransitionPair(NodeId inNodeId,NodeId outNodeId,const bool isInSameWindow)3100 void RSNode::RegisterTransitionPair(NodeId inNodeId, NodeId outNodeId, const bool isInSameWindow)
3101 {
3102     std::unique_ptr<RSCommand> command =
3103         std::make_unique<RSRegisterGeometryTransitionNodePair>(inNodeId, outNodeId, isInSameWindow);
3104     auto transactionProxy = RSTransactionProxy::GetInstance();
3105     if (transactionProxy != nullptr) {
3106         transactionProxy->AddCommand(command, true);
3107     }
3108 }
3109 
UnregisterTransitionPair(NodeId inNodeId,NodeId outNodeId)3110 void RSNode::UnregisterTransitionPair(NodeId inNodeId, NodeId outNodeId)
3111 {
3112     std::unique_ptr<RSCommand> command =
3113         std::make_unique<RSUnregisterGeometryTransitionNodePair>(inNodeId, outNodeId);
3114     auto transactionProxy = RSTransactionProxy::GetInstance();
3115     if (transactionProxy != nullptr) {
3116         transactionProxy->AddCommand(command, true);
3117     }
3118 }
3119 
RegisterTransitionPair(const std::shared_ptr<RSUIContext> rsUIContext,NodeId inNodeId,NodeId outNodeId,const bool isInSameWindow)3120 void RSNode::RegisterTransitionPair(const std::shared_ptr<RSUIContext> rsUIContext, NodeId inNodeId, NodeId outNodeId,
3121     const bool isInSameWindow)
3122 {
3123     if (rsUIContext == nullptr) {
3124         ROSEN_LOGD("RSNode::RegisterTransitionPair, rsUIContext is nullptr");
3125         RegisterTransitionPair(inNodeId, outNodeId, isInSameWindow);
3126         return;
3127     }
3128     std::unique_ptr<RSCommand> command = std::make_unique<RSRegisterGeometryTransitionNodePair>(inNodeId, outNodeId,
3129         isInSameWindow);
3130     auto transaction = rsUIContext->GetRSTransaction();
3131     if (transaction != nullptr) {
3132         transaction->AddCommand(command, true);
3133     }
3134 }
3135 
UnregisterTransitionPair(const std::shared_ptr<RSUIContext> rsUIContext,NodeId inNodeId,NodeId outNodeId)3136 void RSNode::UnregisterTransitionPair(const std::shared_ptr<RSUIContext> rsUIContext, NodeId inNodeId, NodeId outNodeId)
3137 {
3138     if (rsUIContext == nullptr) {
3139         ROSEN_LOGD("RSNode::UnregisterTransitionPair, rsUIContext is nullptr");
3140         UnregisterTransitionPair(inNodeId, outNodeId);
3141         return;
3142     }
3143     std::unique_ptr<RSCommand> command = std::make_unique<RSUnregisterGeometryTransitionNodePair>(inNodeId, outNodeId);
3144     auto transaction = rsUIContext->GetRSTransaction();
3145     if (transaction != nullptr) {
3146         transaction->AddCommand(command, true);
3147     }
3148 }
3149 
MarkNodeGroup(bool isNodeGroup,bool isForced,bool includeProperty)3150 void RSNode::MarkNodeGroup(bool isNodeGroup, bool isForced, bool includeProperty)
3151 {
3152     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3153     if (isNodeGroup_ == isNodeGroup) {
3154         return;
3155     }
3156     if (!isForced && !RSSystemProperties::GetNodeGroupGroupedByUIEnabled()) {
3157         return;
3158     }
3159     isNodeGroup_ = isNodeGroup;
3160     std::unique_ptr<RSCommand> command = std::make_unique<RSMarkNodeGroup>(GetId(), isNodeGroup, isForced,
3161         includeProperty);
3162     AddCommand(command, IsRenderServiceNode());
3163     if (isNodeGroup_) {
3164         SetDrawNode();
3165         if (GetParent()) {
3166             GetParent()->SetDrawNode();
3167         }
3168     }
3169 }
3170 
MarkNodeSingleFrameComposer(bool isNodeSingleFrameComposer)3171 void RSNode::MarkNodeSingleFrameComposer(bool isNodeSingleFrameComposer)
3172 {
3173     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3174     if (isNodeSingleFrameComposer_ != isNodeSingleFrameComposer) {
3175         isNodeSingleFrameComposer_ = isNodeSingleFrameComposer;
3176         std::unique_ptr<RSCommand> command =
3177             std::make_unique<RSMarkNodeSingleFrameComposer>(GetId(), isNodeSingleFrameComposer, GetRealPid());
3178         AddCommand(command, IsRenderServiceNode());
3179     }
3180 }
3181 
MarkRepaintBoundary(const std::string & tag)3182 void RSNode::MarkRepaintBoundary(const std::string& tag)
3183 {
3184     bool isRepaintBoundary = CheckRbPatten(tag);
3185     if (isRepaintBoundary_ == isRepaintBoundary) {
3186         return;
3187     }
3188     isRepaintBoundary_ = isRepaintBoundary;
3189     std::unique_ptr<RSCommand> command = std::make_unique<RSMarkRepaintBoundary>(id_, isRepaintBoundary_);
3190     AddCommand(command, IsRenderServiceNode());
3191 }
3192 
MarkSuggestOpincNode(bool isOpincNode,bool isNeedCalculate)3193 void RSNode::MarkSuggestOpincNode(bool isOpincNode, bool isNeedCalculate)
3194 {
3195     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3196     if (isSuggestOpincNode_ == isOpincNode) {
3197         return;
3198     }
3199     isSuggestOpincNode_ = isOpincNode;
3200     std::unique_ptr<RSCommand> command = std::make_unique<RSMarkSuggestOpincNode>(GetId(),
3201         isOpincNode, isNeedCalculate);
3202     AddCommand(command, IsRenderServiceNode());
3203     if (isSuggestOpincNode_) {
3204         SetDrawNode();
3205         if (GetParent()) {
3206             GetParent()->SetDrawNode();
3207         }
3208     }
3209 }
3210 
MarkUifirstNode(bool isUifirstNode)3211 void RSNode::MarkUifirstNode(bool isUifirstNode)
3212 {
3213     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3214     if (isUifirstNode_ == isUifirstNode) {
3215         return;
3216     }
3217     isUifirstNode_ = isUifirstNode;
3218     std::unique_ptr<RSCommand> command = std::make_unique<RSMarkUifirstNode>(GetId(), isUifirstNode);
3219     AddCommand(command, IsRenderServiceNode());
3220 }
3221 
MarkUifirstNode(bool isForceFlag,bool isUifirstEnable)3222 void RSNode::MarkUifirstNode(bool isForceFlag, bool isUifirstEnable)
3223 {
3224     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3225     if (isForceFlag == isForceFlag_ && isUifirstEnable_ == isUifirstEnable) {
3226         return;
3227     }
3228     isForceFlag_ = isForceFlag;
3229     isUifirstEnable_ = isUifirstEnable;
3230     std::unique_ptr<RSCommand> command = std::make_unique<RSForceUifirstNode>(GetId(), isForceFlag, isUifirstEnable);
3231     AddCommand(command, IsRenderServiceNode());
3232 }
3233 
SetDrawNode()3234 void RSNode::SetDrawNode()
3235 {
3236     if (isDrawNode_) {
3237         return;
3238     }
3239     isDrawNode_ = true;
3240     if (drawNodeChangeCallback_) {
3241         drawNodeChangeCallback_(shared_from_this(), false);
3242     }
3243 }
3244 
GetIsDrawn()3245 bool RSNode::GetIsDrawn()
3246 {
3247     return isDrawNode_;
3248 }
3249 
3250 
3251 /**
3252  * @brief Sets the drawing type of RSnode
3253  *
3254  * This function is used to set the corresponding draw type when
3255  * adding draw properties to RSnode, so that it is easy to identify
3256  * which draw nodes are really needed.
3257  *
3258  * @param nodeType The type of node that needs to be set.
3259  *
3260 */
SetDrawNodeType(DrawNodeType nodeType)3261 void RSNode::SetDrawNodeType(DrawNodeType nodeType)
3262 {
3263     // Assign values according to the priority rules
3264     if (nodeType <= drawNodeType_) {
3265         return;
3266     }
3267     drawNodeType_ = nodeType;
3268     if (RSSystemProperties::ViewDrawNodeType()) {
3269         SyncDrawNodeType(nodeType);
3270     }
3271 }
3272 
GetDrawNodeType() const3273 DrawNodeType RSNode::GetDrawNodeType() const
3274 {
3275     return drawNodeType_;
3276 }
3277 
SyncDrawNodeType(DrawNodeType nodeType)3278 void RSNode::SyncDrawNodeType(DrawNodeType nodeType)
3279 {
3280     std::unique_ptr<RSCommand> command =
3281         std::make_unique<RSSetDrawNodeType>(GetId(), nodeType);
3282     if (AddCommand(command, true)) {
3283         ROSEN_LOGD("RSNode::SyncDrawNodeType nodeType: %{public}d", nodeType);
3284     }
3285 }
3286 
SetUIFirstSwitch(RSUIFirstSwitch uiFirstSwitch)3287 void RSNode::SetUIFirstSwitch(RSUIFirstSwitch uiFirstSwitch)
3288 {
3289     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3290     if (uiFirstSwitch_ == uiFirstSwitch) {
3291         return;
3292     }
3293     uiFirstSwitch_ = uiFirstSwitch;
3294     std::unique_ptr<RSCommand> command = std::make_unique<RSSetUIFirstSwitch>(GetId(), uiFirstSwitch);
3295     AddCommand(command, IsRenderServiceNode());
3296 }
3297 
SetLightIntensity(float lightIntensity)3298 void RSNode::SetLightIntensity(float lightIntensity)
3299 {
3300     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3301     SetPropertyNG<ModifierNG::RSPointLightModifier, &ModifierNG::RSPointLightModifier::SetLightIntensity>(
3302         lightIntensity);
3303 }
3304 
SetLightColor(uint32_t lightColorValue)3305 void RSNode::SetLightColor(uint32_t lightColorValue)
3306 {
3307     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3308     auto lightColor = Color::FromArgbInt(lightColorValue);
3309     SetPropertyNG<ModifierNG::RSPointLightModifier, &ModifierNG::RSPointLightModifier::SetLightColor>(lightColor);
3310 }
3311 
SetLightPosition(float positionX,float positionY,float positionZ)3312 void RSNode::SetLightPosition(float positionX, float positionY, float positionZ)
3313 {
3314     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3315     SetLightPosition(Vector4f(positionX, positionY, positionZ, 0.f));
3316 }
3317 
SetLightPosition(const Vector4f & lightPosition)3318 void RSNode::SetLightPosition(const Vector4f& lightPosition)
3319 {
3320     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3321     SetPropertyNG<ModifierNG::RSPointLightModifier, &ModifierNG::RSPointLightModifier::SetLightPosition>(lightPosition);
3322 }
3323 
SetIlluminatedBorderWidth(float illuminatedBorderWidth)3324 void RSNode::SetIlluminatedBorderWidth(float illuminatedBorderWidth)
3325 {
3326     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3327     SetPropertyNG<ModifierNG::RSPointLightModifier, &ModifierNG::RSPointLightModifier::SetIlluminatedBorderWidth>(
3328         illuminatedBorderWidth);
3329 }
3330 
SetIlluminatedType(uint32_t illuminatedType)3331 void RSNode::SetIlluminatedType(uint32_t illuminatedType)
3332 {
3333     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3334     SetPropertyNG<ModifierNG::RSPointLightModifier, &ModifierNG::RSPointLightModifier::SetIlluminatedType>(
3335         illuminatedType);
3336 }
3337 
SetBloom(float bloomIntensity)3338 void RSNode::SetBloom(float bloomIntensity)
3339 {
3340     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3341     SetPropertyNG<ModifierNG::RSPointLightModifier, &ModifierNG::RSPointLightModifier::SetBloom>(bloomIntensity);
3342 }
3343 
SetAiInvert(const Vector4f & aiInvert)3344 void RSNode::SetAiInvert(const Vector4f& aiInvert)
3345 {
3346     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3347     SetPropertyNG<ModifierNG::RSCompositingFilterModifier, &ModifierNG::RSCompositingFilterModifier::SetAiInvert>(
3348         aiInvert);
3349 }
3350 
SetGrayScale(float grayScale)3351 void RSNode::SetGrayScale(float grayScale)
3352 {
3353     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3354     SetPropertyNG<ModifierNG::RSCompositingFilterModifier, &ModifierNG::RSCompositingFilterModifier::SetGrayScale>(
3355         grayScale);
3356 }
3357 
SetBrightness(float brightness)3358 void RSNode::SetBrightness(float brightness)
3359 {
3360     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3361     SetPropertyNG<ModifierNG::RSCompositingFilterModifier, &ModifierNG::RSCompositingFilterModifier::SetBrightness>(
3362         brightness);
3363 }
3364 
SetContrast(float contrast)3365 void RSNode::SetContrast(float contrast)
3366 {
3367     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3368     SetPropertyNG<ModifierNG::RSCompositingFilterModifier, &ModifierNG::RSCompositingFilterModifier::SetContrast>(
3369         contrast);
3370 }
3371 
SetSaturate(float saturate)3372 void RSNode::SetSaturate(float saturate)
3373 {
3374     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3375     SetPropertyNG<ModifierNG::RSCompositingFilterModifier, &ModifierNG::RSCompositingFilterModifier::SetSaturate>(
3376         saturate);
3377 }
3378 
SetSepia(float sepia)3379 void RSNode::SetSepia(float sepia)
3380 {
3381     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3382     SetPropertyNG<ModifierNG::RSCompositingFilterModifier, &ModifierNG::RSCompositingFilterModifier::SetSepia>(sepia);
3383 }
3384 
SetInvert(float invert)3385 void RSNode::SetInvert(float invert)
3386 {
3387     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3388     SetPropertyNG<ModifierNG::RSCompositingFilterModifier, &ModifierNG::RSCompositingFilterModifier::SetInvert>(invert);
3389 }
3390 
SetHueRotate(float hueRotate)3391 void RSNode::SetHueRotate(float hueRotate)
3392 {
3393     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3394     SetPropertyNG<ModifierNG::RSCompositingFilterModifier, &ModifierNG::RSCompositingFilterModifier::SetHueRotate>(
3395         hueRotate);
3396 }
3397 
SetColorBlend(uint32_t colorValue)3398 void RSNode::SetColorBlend(uint32_t colorValue)
3399 {
3400     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3401     auto colorBlend = Color::FromArgbInt(colorValue);
3402     SetPropertyNG<ModifierNG::RSCompositingFilterModifier, &ModifierNG::RSCompositingFilterModifier::SetColorBlend>(
3403         colorBlend);
3404 }
3405 
SetLightUpEffectDegree(float lightUpEffectDegree)3406 void RSNode::SetLightUpEffectDegree(float lightUpEffectDegree)
3407 {
3408     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3409     SetPropertyNG<ModifierNG::RSCompositingFilterModifier,
3410         &ModifierNG::RSCompositingFilterModifier::SetLightUpEffectDegree>(lightUpEffectDegree);
3411 }
3412 
SetDynamicDimDegree(const float dimDegree)3413 void RSNode::SetDynamicDimDegree(const float dimDegree)
3414 {
3415     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3416     SetPropertyNG<ModifierNG::RSCompositingFilterModifier,
3417         &ModifierNG::RSCompositingFilterModifier::SetDynamicDimDegree>(dimDegree);
3418 }
3419 
SetSystemBarEffect()3420 void RSNode::SetSystemBarEffect()
3421 {
3422     SetPropertyNG<ModifierNG::RSBackgroundFilterModifier, &ModifierNG::RSBackgroundFilterModifier::SetSystemBarEffect>(
3423         true);
3424 }
3425 
CalcExpectedFrameRate(const std::string & scene,float speed)3426 int32_t RSNode::CalcExpectedFrameRate(const std::string& scene, float speed)
3427 {
3428     auto preferredFps = RSFrameRatePolicy::GetInstance()->GetPreferredFps(scene, speed);
3429     return preferredFps;
3430 }
3431 
SetOutOfParent(OutOfParentType outOfParent)3432 void RSNode::SetOutOfParent(OutOfParentType outOfParent)
3433 {
3434     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3435     if (outOfParent != outOfParent_) {
3436         outOfParent_ = outOfParent;
3437 
3438         std::unique_ptr<RSCommand> command = std::make_unique<RSSetOutOfParent>(GetId(), outOfParent);
3439         AddCommand(command, IsRenderServiceNode());
3440     }
3441 }
3442 
GenerateId()3443 NodeId RSNode::GenerateId()
3444 {
3445     static pid_t pid_ = GetRealPid();
3446     static std::atomic<uint32_t> currentId_ = 1; // surfaceNode is seted correctly during boot when currentId is 1
3447 
3448     auto currentId = currentId_.fetch_add(1, std::memory_order_relaxed);
3449     if (currentId == UINT32_MAX) {
3450         // [PLANNING]:process the overflow situations
3451         ROSEN_LOGE("Node Id overflow");
3452     }
3453 
3454     // concat two 32-bit numbers to one 64-bit number
3455     return ((NodeId)pid_ << 32) | currentId;
3456 }
3457 
InitUniRenderEnabled()3458 void RSNode::InitUniRenderEnabled()
3459 {
3460     static bool inited = false;
3461     if (!inited) {
3462         inited = true;
3463         g_isUniRenderEnabled = RSSystemProperties::GetUniRenderEnabled();
3464         ROSEN_LOGD("RSNode::InitUniRenderEnabled:%{public}d", g_isUniRenderEnabled);
3465     }
3466 }
3467 
3468 
3469 // RSNode::~RSNode()
3470 // {
3471 
3472 // }
3473 
IsUniRenderEnabled() const3474 bool RSNode::IsUniRenderEnabled() const
3475 {
3476     return g_isUniRenderEnabled;
3477 }
3478 
IsRenderServiceNode() const3479 bool RSNode::IsRenderServiceNode() const
3480 {
3481     return (g_isUniRenderEnabled || isRenderServiceNode_) && (!isTextureExportNode_);
3482 }
3483 
SetIsOnTheTree(bool flag)3484 void RSNode::SetIsOnTheTree(bool flag)
3485 {
3486     NotifyPageNodeChanged();
3487     if (isOnTheTree_ == flag && isOnTheTreeInit_ == true) {
3488         return;
3489     }
3490     isOnTheTreeInit_ = true;
3491     isOnTheTree_ = flag;
3492 #ifdef RS_ENABLE_VK
3493     if (!flag) {
3494         RSModifiersDraw::InsertOffTreeNode(instanceId_, id_);
3495     } else {
3496         RSModifiersDraw::EraseOffTreeNode(instanceId_, id_);
3497     }
3498 #endif
3499     for (auto child : children_) {
3500         auto childPtr = child.lock();
3501         if (childPtr == nullptr) {
3502             continue;
3503         }
3504         childPtr->SetIsOnTheTree(flag);
3505     }
3506 }
3507 
AddChild(SharedPtr child,int index)3508 void RSNode::AddChild(SharedPtr child, int index)
3509 {
3510     if (child == nullptr) {
3511         ROSEN_LOGE("RSNode::AddChild, child is nullptr");
3512         return;
3513     }
3514     if (!IsTextureExportNode() && child->IsTextureExportNode() && AddCompositeNodeChild(child, index)) {
3515         return;
3516     }
3517     if (child->parent_.lock().get() == this) {
3518         ROSEN_LOGD("RSNode::AddChild, child already exist");
3519         return;
3520     }
3521     if (child->GetType() == RSUINodeType::DISPLAY_NODE) {
3522         // Disallow to add display node as child.
3523         return;
3524     }
3525     if (frameNodeId_ < 0) {
3526         child->SetDrawNode();
3527     }
3528     NodeId childId = child->GetId();
3529     if (child->parent_.lock()) {
3530         child->RemoveFromTree();
3531     }
3532 
3533     if (index < 0 || index >= static_cast<int>(children_.size())) {
3534         children_.push_back(child);
3535     } else {
3536         children_.insert(children_.begin() + index, child);
3537     }
3538     child->SetParent(weak_from_this());
3539     if (isTextureExportNode_ != child->isTextureExportNode_) {
3540         child->SyncTextureExport(isTextureExportNode_);
3541     }
3542     child->OnAddChildren();
3543     child->MarkDirty(NodeDirtyType::APPEARANCE, true);
3544     // construct command using child's GetHierarchyCommandNodeId(), not GetId()
3545     childId = child->GetHierarchyCommandNodeId();
3546     std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeAddChild>(id_, childId, index);
3547 
3548     AddCommand(command, IsRenderServiceNode(), GetFollowType(), id_);
3549     if (child->GetRSUIContext() != GetRSUIContext()) {
3550         if (auto surfaceNode = child->ReinterpretCastTo<RSSurfaceNode>()) {
3551             ROSEN_LOGI("RSNode::AddChild, ParentId:%{public}" PRIu64 ", ParentUIContext is %{public}" PRIu64
3552                        " SurfaceNode:[Id: %{public}" PRIu64 ", name: %{public}s uiContext is %{public}" PRIu64 "]",
3553                 id_, GetRSUIContext() ? GetRSUIContext()->GetToken() : 0, surfaceNode->GetId(),
3554                 surfaceNode->GetName().c_str(),
3555                 surfaceNode->GetRSUIContext() ? surfaceNode->GetRSUIContext()->GetToken() : 0);
3556             RS_TRACE_NAME_FMT("RSNode::AddChild, ParentId:%" PRIu64 ", ParentUIContext is %" PRIu64
3557                               " SurfaceNode:[Id: %" PRIu64 ", name: %s uiContext is %" PRIu64 "]",
3558                 id_, GetRSUIContext() ? GetRSUIContext()->GetToken() : 0, surfaceNode->GetId(),
3559                 surfaceNode->GetName().c_str(),
3560                 surfaceNode->GetRSUIContext() ? surfaceNode->GetRSUIContext()->GetToken() : 0);
3561         }
3562         std::unique_ptr<RSCommand> child_command = std::make_unique<RSBaseNodeAddChild>(id_, childId, index);
3563         child->AddCommand(child_command, IsRenderServiceNode(), GetFollowType(), id_);
3564     }
3565     if (child->GetType() == RSUINodeType::SURFACE_NODE) {
3566         auto surfaceNode = RSBaseNode::ReinterpretCast<RSSurfaceNode>(child);
3567         ROSEN_LOGI("RSNode::AddChild, Id: %{public}" PRIu64 ", SurfaceNode:[Id: %{public}" PRIu64 ", name: %{public}s]",
3568             id_, childId, surfaceNode->GetName().c_str());
3569         RS_TRACE_NAME_FMT("RSNode::AddChild, Id: %" PRIu64 ", SurfaceNode:[Id: %" PRIu64 ", name: %s]",
3570             id_, childId, surfaceNode->GetName().c_str());
3571     }
3572     child->SetIsOnTheTree(isOnTheTree_);
3573 }
3574 
AddCompositeNodeChild(SharedPtr node,int index)3575 bool RSNode::AddCompositeNodeChild(SharedPtr node, int index)
3576 {
3577     if (!node) {
3578         return false;
3579     }
3580     auto surfaceNode = node->ReinterpretCastTo<RSSurfaceNode>();
3581     if (!surfaceNode) {
3582         return false;
3583     }
3584     auto compositeLayerUtils = surfaceNode->GetCompositeLayerUtils();
3585     if (compositeLayerUtils) {
3586         auto compositeNode = compositeLayerUtils->GetCompositeNode();
3587         if (compositeNode) {
3588             compositeNode->RemoveFromTree();
3589             RSBaseNode::AddChild(compositeNode, index);
3590             return true;
3591         }
3592     }
3593     return false;
3594 }
3595 
MoveChild(SharedPtr child,int index)3596 void RSNode::MoveChild(SharedPtr child, int index)
3597 {
3598     if (child == nullptr || child->parent_.lock().get() != this) {
3599         ROSEN_LOGD("RSNode::MoveChild, not valid child");
3600         return;
3601     }
3602     NodeId childId = child->GetId();
3603     auto itr = std::find_if(
3604         children_.begin(), children_.end(), [&](WeakPtr& ptr) -> bool { return ROSEN_EQ<RSNode>(ptr, child); });
3605     if (itr == children_.end()) {
3606         ROSEN_LOGD("RSNode::MoveChild, not child");
3607         return;
3608     }
3609     children_.erase(itr);
3610     if (index < 0 || index >= static_cast<int>(children_.size())) {
3611         children_.push_back(child);
3612     } else {
3613         children_.insert(children_.begin() + index, child);
3614     }
3615     // construct command using child's GetHierarchyCommandNodeId(), not GetId()
3616     childId = child->GetHierarchyCommandNodeId();
3617     std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeMoveChild>(id_, childId, index);
3618 
3619     AddCommand(command, IsRenderServiceNode(), GetFollowType(), id_);
3620     child->SetIsOnTheTree(isOnTheTree_);
3621 }
3622 
RemoveChild(SharedPtr child)3623 void RSNode::RemoveChild(SharedPtr child)
3624 {
3625     if (child == nullptr || child->parent_.lock().get() != this) {
3626         ROSEN_LOGI("RSNode::RemoveChild, child is nullptr");
3627         return;
3628     }
3629     NodeId childId = child->GetId();
3630     RemoveChildByNode(child);
3631     child->OnRemoveChildren();
3632     child->parent_.reset();
3633     child->MarkDirty(NodeDirtyType::APPEARANCE, true);
3634     // construct command using child's GetHierarchyCommandNodeId(), not GetId()
3635     childId = child->GetHierarchyCommandNodeId();
3636     std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeRemoveChild>(id_, childId);
3637     AddCommand(command, IsRenderServiceNode(), GetFollowType(), id_);
3638 
3639     if (child->GetType() == RSUINodeType::SURFACE_NODE) {
3640         auto surfaceNode = RSBaseNode::ReinterpretCast<RSSurfaceNode>(child);
3641         ROSEN_LOGI("RSNode::RemoveChild, Id: %{public}" PRIu64 ", SurfaceNode:[Id: %{public}" PRIu64 ", "
3642             "name: %{public}s]", id_, childId, surfaceNode->GetName().c_str());
3643         RS_TRACE_NAME_FMT("RSNode::RemoveChild, Id: %" PRIu64 ", SurfaceNode:[Id: %" PRIu64 ", name: %s]",
3644             id_, childId, surfaceNode->GetName().c_str());
3645     }
3646     child->SetIsOnTheTree(false);
3647 }
3648 
RemoveChildByNodeSelf(WeakPtr child)3649 void RSNode::RemoveChildByNodeSelf(WeakPtr child)
3650 {
3651     SharedPtr childPtr = child.lock();
3652     if (childPtr) {
3653         RemoveChild(childPtr);
3654     } else {
3655         ROSEN_LOGE("RSNode::RemoveChildByNodeSelf, childId not found");
3656     }
3657 }
3658 
AddCrossParentChild(SharedPtr child,int index)3659 void RSNode::AddCrossParentChild(SharedPtr child, int index)
3660 {
3661     // AddCrossParentChild only used as: the child is under multiple parents(e.g. a window cross multi-screens),
3662     // so this child will not remove from the old parent.
3663     if (child == nullptr) {
3664         ROSEN_LOGE("RSNode::AddCrossScreenChild, child is nullptr");
3665         return;
3666     }
3667     if (!this->IsInstanceOf<RSDisplayNode>()) {
3668         ROSEN_LOGE("RSNode::AddCrossScreenChild, only displayNode support AddCrossScreenChild");
3669         return;
3670     }
3671     NodeId childId = child->GetId();
3672 
3673     if (index < 0 || index >= static_cast<int>(children_.size())) {
3674         children_.push_back(child);
3675     } else {
3676         children_.insert(children_.begin() + index, child);
3677     }
3678     child->SetParent(weak_from_this());
3679     child->OnAddChildren();
3680     child->MarkDirty(NodeDirtyType::APPEARANCE, true);
3681     // construct command using child's GetHierarchyCommandNodeId(), not GetId()
3682     childId = child->GetHierarchyCommandNodeId();
3683     std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeAddCrossParentChild>(id_, childId, index);
3684 
3685     AddCommand(command, IsRenderServiceNode(), GetFollowType(), id_);
3686     child->SetIsOnTheTree(isOnTheTree_);
3687 }
3688 
RemoveCrossParentChild(SharedPtr child,SharedPtr newParent)3689 void RSNode::RemoveCrossParentChild(SharedPtr child, SharedPtr newParent)
3690 {
3691     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3692     // RemoveCrossParentChild only used as: the child is under multiple parents(e.g. a window cross multi-screens),
3693     // set the newParentId to rebuild the parent-child relationship.
3694     if (child == nullptr) {
3695         ROSEN_LOGI("RSNode::RemoveCrossScreenChild, child is nullptr");
3696         return;
3697     }
3698     if (!this->IsInstanceOf<RSDisplayNode>()) {
3699         ROSEN_LOGE("RSNode::RemoveCrossScreenChild, only displayNode support RemoveCrossScreenChild");
3700         return;
3701     }
3702     RemoveChildByNode(child);
3703     child->OnRemoveChildren();
3704     child->SetParent(newParent);
3705     child->MarkDirty(NodeDirtyType::APPEARANCE, true);
3706 
3707     // construct command using child's GetHierarchyCommandNodeId(), not GetId()
3708     NodeId childId = child->GetHierarchyCommandNodeId();
3709     std::unique_ptr<RSCommand> command =
3710         std::make_unique<RSBaseNodeRemoveCrossParentChild>(id_, childId, newParent->GetId());
3711     AddCommand(command, IsRenderServiceNode(), GetFollowType(), id_);
3712 }
3713 
SetIsCrossNode(bool isCrossNode)3714 void RSNode::SetIsCrossNode(bool isCrossNode)
3715 {
3716     std::unique_ptr<RSCommand> command =
3717         std::make_unique<RSBaseNodeSetIsCrossNode>(GetId(), isCrossNode);
3718     AddCommand(command);
3719 }
3720 
AddCrossScreenChild(SharedPtr child,int index,bool autoClearCloneNode)3721 void RSNode::AddCrossScreenChild(SharedPtr child, int index, bool autoClearCloneNode)
3722 {
3723     if (child == nullptr) {
3724         ROSEN_LOGE("RSNode::AddCrossScreenChild, child is nullptr");
3725         return;
3726     }
3727     if (!this->IsInstanceOf<RSDisplayNode>()) {
3728         ROSEN_LOGE("RSNode::AddCrossScreenChild, only displayNode support AddCrossScreenChild");
3729         return;
3730     }
3731 
3732     if (!child->IsInstanceOf<RSSurfaceNode>()) {
3733         ROSEN_LOGE("RSNode::AddCrossScreenChild, child shoult be RSSurfaceNode");
3734         return;
3735     }
3736     // construct command using child's GetHierarchyCommandNodeId(), not GetId()
3737     NodeId childId = child->GetHierarchyCommandNodeId();
3738     // Generate an id on the client and create a clone node on the server based on the id.
3739     std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeAddCrossScreenChild>(id_, childId,
3740         GenerateId(), index, autoClearCloneNode);
3741     AddCommand(command, IsRenderServiceNode(), GetFollowType(), id_);
3742 }
3743 
RemoveCrossScreenChild(SharedPtr child)3744 void RSNode::RemoveCrossScreenChild(SharedPtr child)
3745 {
3746     if (child == nullptr) {
3747         ROSEN_LOGE("RSNode::RemoveCrossScreenChild, child is nullptr");
3748         return;
3749     }
3750     if (!this->IsInstanceOf<RSDisplayNode>()) {
3751         ROSEN_LOGE("RSNode::RemoveCrossScreenChild, only displayNode support RemoveCrossScreenChild");
3752         return;
3753     }
3754 
3755     if (!child->IsInstanceOf<RSSurfaceNode>()) {
3756         ROSEN_LOGE("RSNode::RemoveCrossScreenChild, child shoult be RSSurfaceNode");
3757         return;
3758     }
3759     // construct command using child's GetHierarchyCommandNodeId(), not GetId()
3760     NodeId childId = child->GetHierarchyCommandNodeId();
3761     std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeRemoveCrossScreenChild>(id_, childId);
3762     AddCommand(command, IsRenderServiceNode(), GetFollowType(), id_);
3763 }
3764 
RemoveChildByNode(SharedPtr child)3765 void RSNode::RemoveChildByNode(SharedPtr child)
3766 {
3767     if (child == nullptr) {
3768         RS_LOGE("RemoveChildByNode %{public}" PRIu64 " failed:nullptr", GetId());
3769         return;
3770     }
3771     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3772     auto itr = std::find_if(
3773         children_.begin(), children_.end(), [&](WeakPtr &ptr) -> bool {return ROSEN_EQ<RSNode>(ptr, child);});
3774     if (itr != children_.end()) {
3775         RS_OPTIONAL_TRACE_NAME_FMT(
3776             "RSNode::RemoveChildByNode parent:%" PRIu64 ", child:%" PRIu64, GetId(), child->GetId());
3777         children_.erase(itr);
3778     } else {
3779         RS_TRACE_NAME_FMT(
3780             "RSNode::RemoveChildByNode failed:%" PRIu64 " not children of %" PRIu64, child->GetId(), GetId());
3781     }
3782 }
3783 
RemoveFromTree()3784 void RSNode::RemoveFromTree()
3785 {
3786     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3787     RS_OPTIONAL_TRACE_NAME_FMT("RSNode::RemoveFromTree id:%" PRIu64 "", GetId());
3788     MarkDirty(NodeDirtyType::APPEARANCE, true);
3789     auto parentPtr = parent_.lock();
3790     if (parentPtr) {
3791         if (auto surfaceNode = ReinterpretCastTo<RSSurfaceNode>()) {
3792             ROSEN_LOGI("RSNode::RemoveFromTree, ParentId:%{public}" PRIu64 ", ParentUIContext is %{public}" PRIu64
3793                        " SurfaceNode:[Id: %{public}" PRIu64 ", name: %{public}s uiContext is %{public}" PRIu64 "]",
3794                 parentPtr->GetId(), parentPtr->GetRSUIContext() ? parentPtr->GetRSUIContext()->GetToken() : 0,
3795                 surfaceNode->GetId(), surfaceNode->GetName().c_str(),
3796                 surfaceNode->GetRSUIContext() ? surfaceNode->GetRSUIContext()->GetToken() : 0);
3797             RS_TRACE_NAME_FMT("RSNode::RemoveFromTree, ParentId:%" PRIu64 ", ParentUIContext is %" PRIu64
3798                               " SurfaceNode:[Id: %" PRIu64 ", name: %s uiContext is %" PRIu64 "]",
3799                 parentPtr->GetId(), parentPtr->GetRSUIContext() ? parentPtr->GetRSUIContext()->GetToken() : 0,
3800                 surfaceNode->GetId(), surfaceNode->GetName().c_str(),
3801                 surfaceNode->GetRSUIContext() ? surfaceNode->GetRSUIContext()->GetToken() : 0);
3802         }
3803         parentPtr->RemoveChildByNode(shared_from_this());
3804         OnRemoveChildren();
3805         parent_.reset();
3806     }
3807     // construct command using own GetHierarchyCommandNodeId(), not GetId()
3808     auto nodeId = GetHierarchyCommandNodeId();
3809     std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeRemoveFromTree>(nodeId);
3810     // always send Remove-From-Tree command
3811     AddCommand(command, IsRenderServiceNode(), GetFollowType(), nodeId);
3812     SetIsOnTheTree(false);
3813 }
3814 
ClearChildren()3815 void RSNode::ClearChildren()
3816 {
3817     RS_OPTIONAL_TRACE_NAME_FMT("RSNode::ClearChildren id:%" PRIu64 "", GetId());
3818     for (auto child : children_) {
3819         auto childPtr = child.lock();
3820         if (childPtr) {
3821             childPtr->SetIsOnTheTree(false);
3822             childPtr->parent_.reset();
3823             childPtr->MarkDirty(NodeDirtyType::APPEARANCE, true);
3824         }
3825     }
3826     children_.clear();
3827     // construct command using own GetHierarchyCommandNodeId(), not GetId()
3828     auto nodeId = GetHierarchyCommandNodeId();
3829     std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeClearChild>(nodeId);
3830     AddCommand(command, IsRenderServiceNode(), GetFollowType(), nodeId);
3831 }
3832 
SetExportTypeChangedCallback(ExportTypeChangedCallback callback)3833 void RSNode::SetExportTypeChangedCallback(ExportTypeChangedCallback callback)
3834 {
3835     exportTypeChangedCallback_ = callback;
3836 }
3837 
SetTextureExport(bool isTextureExportNode)3838 void RSNode::SetTextureExport(bool isTextureExportNode)
3839 {
3840     if (isTextureExportNode == isTextureExportNode_) {
3841         return;
3842     }
3843     isTextureExportNode_ = isTextureExportNode;
3844     if (!IsUniRenderEnabled()) {
3845         return;
3846     }
3847     if (exportTypeChangedCallback_) {
3848         exportTypeChangedCallback_(isTextureExportNode);
3849     }
3850     if ((isTextureExportNode_ && !hasCreateRenderNodeInRT_) ||
3851         (!isTextureExportNode_ && !hasCreateRenderNodeInRS_)) {
3852         CreateRenderNodeForTextureExportSwitch();
3853     }
3854     DoFlushModifier();
3855 }
3856 
SyncTextureExport(bool isTextureExportNode)3857 void RSNode::SyncTextureExport(bool isTextureExportNode)
3858 {
3859     if (isTextureExportNode == isTextureExportNode_) {
3860         return;
3861     }
3862     SetTextureExport(isTextureExportNode);
3863     for (uint32_t index = 0; index < children_.size(); index++) {
3864         auto childPtr = children_[index].lock();
3865         if (childPtr) {
3866             childPtr->SyncTextureExport(isTextureExportNode);
3867             std::unique_ptr<RSCommand> command =
3868                 std::make_unique<RSBaseNodeAddChild>(id_, childPtr->GetHierarchyCommandNodeId(), index);
3869             AddCommand(command, IsRenderServiceNode(), GetFollowType(), id_);
3870         }
3871     }
3872 }
3873 
GetChildByIndex(int index) const3874 RSNode::SharedPtr RSNode::GetChildByIndex(int index) const
3875 {
3876     int childrenTotal = static_cast<int>(children_.size());
3877     if (childrenTotal <= 0 || index < -1 || index >= childrenTotal) {
3878         return nullptr;
3879     }
3880     if (index == -1) {
3881         return children_.back().lock();
3882     }
3883     return children_.at(index).lock();
3884 }
3885 
SetParent(WeakPtr parent)3886 void RSNode::SetParent(WeakPtr parent)
3887 {
3888     parent_ = parent;
3889 }
3890 
GetParent()3891 RSNode::SharedPtr RSNode::GetParent()
3892 {
3893     return parent_.lock();
3894 }
3895 
DumpTree(int depth,std::string & out) const3896 void RSNode::DumpTree(int depth, std::string& out) const
3897 {
3898     for (int i = 0; i < depth; i++) {
3899         out += "  ";
3900     }
3901     out += "| ";
3902     Dump(out);
3903     for (auto child : children_) {
3904         auto childPtr = child.lock();
3905         if (childPtr) {
3906             out += "\n";
3907             childPtr->DumpTree(depth + 1, out);
3908         }
3909     }
3910 }
3911 
DumpModifiers(std::string & out) const3912 void RSNode::DumpModifiers(std::string& out) const
3913 {
3914     const auto& modifiers = modifiersNG_;
3915     for (const auto& [id, modifier] : modifiers) {
3916         if (modifier == nullptr) {
3917             continue;
3918         }
3919         auto renderModifier = modifier->CreateRenderModifier();
3920         if (renderModifier == nullptr) {
3921             continue;
3922         }
3923         renderModifier->Dump(out, ",");
3924     }
3925 }
3926 
Dump(std::string & out) const3927 void RSNode::Dump(std::string& out) const
3928 {
3929     auto iter = RSUINodeTypeStrs.find(GetType());
3930     auto rsUIContextPtr = rsUIContext_.lock();
3931     out += (iter != RSUINodeTypeStrs.end() ? iter->second : "RSNode");
3932     out += "[" + std::to_string(id_);
3933     out += "], parent[" + std::to_string(parent_.lock() ? parent_.lock()->GetId() : -1);
3934     out += "], instanceId[" + std::to_string(instanceId_);
3935     out += "], UIContext[" + (rsUIContextPtr ? std::to_string(rsUIContextPtr->GetToken()) : "null");
3936     if (auto node = ReinterpretCastTo<RSSurfaceNode>()) {
3937         out += "], name[" + node->GetName();
3938     } else if (!nodeName_.empty()) {
3939         out += "], nodeName[" + nodeName_;
3940     }
3941     out += "], frameNodeId[" + std::to_string(frameNodeId_);
3942     out += "], frameNodeTag[" + frameNodeTag_;
3943     out += "], extendModifierIsDirty[";
3944     out += extendModifierIsDirty_ ? "true" : "false";
3945     out += "], isNodeGroup[";
3946     out += isNodeGroup_ ? "true" : "false";
3947     out += "], isSingleFrameComposer[";
3948     out += isNodeSingleFrameComposer_ ? "true" : "false";
3949     out += "], isSuggestOpincNode[";
3950     out += isSuggestOpincNode_ ? "true" : "false";
3951     out += "], isUifirstNode[";
3952     out += isUifirstNode_ ? "true" : "false";
3953     out += "], drawRegion[";
3954     if (drawRegion_) {
3955         out += "x:" + std::to_string(drawRegion_->GetLeft());
3956         out += " y:" + std::to_string(drawRegion_->GetTop());
3957         out += " width:" + std::to_string(drawRegion_->GetWidth());
3958         out += " height:" + std::to_string(drawRegion_->GetHeight());
3959     } else {
3960         out += "null";
3961     }
3962     out += "], outOfParent[" + std::to_string(static_cast<int>(outOfParent_));
3963     out += "], hybridRenderCanvas[";
3964     out += hybridRenderCanvas_ ? "true" : "false";
3965     out += "], animations[";
3966     for (const auto& [id, anim] : animations_) {
3967         out += "{id:" + std::to_string(id);
3968         out += " propId:" + std::to_string(anim->GetPropertyId());
3969         out += "} ";
3970     }
3971     if (!animations_.empty()) {
3972         out.pop_back();
3973     }
3974 
3975     out += "], modifiers[";
3976     DumpModifiers(out);
3977     out += "]";
3978 }
3979 
DumpNode(int depth) const3980 std::string RSNode::DumpNode(int depth) const
3981 {
3982     std::stringstream ss;
3983     auto it = RSUINodeTypeStrs.find(GetType());
3984     if (it == RSUINodeTypeStrs.end()) {
3985         return "";
3986     }
3987     ss << it->second << "[" << std::to_string(id_) << "] child[";
3988     for (auto child : children_) {
3989         ss << std::to_string(child.lock() ? child.lock()->GetId() : -1) << " ";
3990     }
3991     ss << "]";
3992 
3993     if (!animations_.empty()) {
3994         ss << " animation:" << std::to_string(animations_.size());
3995     }
3996     for (const auto& [animationId, animation] : animations_) {
3997         if (animation) {
3998             ss << " animationInfo:" << animation->DumpAnimation();
3999         }
4000     }
4001     auto rsUIContextPtr = rsUIContext_.lock();
4002     ss << " token:" << (rsUIContextPtr ? std::to_string(rsUIContextPtr->GetToken()) : "null");
4003     ss << " " << GetStagingProperties().Dump();
4004     return ss.str();
4005 }
4006 
IsInstanceOf(RSUINodeType type) const4007 bool RSNode::IsInstanceOf(RSUINodeType type) const
4008 {
4009     auto targetType = static_cast<uint32_t>(type);
4010     auto instanceType = static_cast<uint32_t>(GetType());
4011     // use bitmask to check whether the instance is a subclass of the target type
4012     return (instanceType & targetType) == targetType;
4013 }
4014 
4015 template<typename T>
IsInstanceOf() const4016 bool RSNode::IsInstanceOf() const
4017 {
4018     return IsInstanceOf(T::Type);
4019 }
4020 
4021 // explicit instantiation with all render node types
4022 template bool RSNode::IsInstanceOf<RSDisplayNode>() const;
4023 template bool RSNode::IsInstanceOf<RSSurfaceNode>() const;
4024 template bool RSNode::IsInstanceOf<RSProxyNode>() const;
4025 template bool RSNode::IsInstanceOf<RSCanvasNode>() const;
4026 template bool RSNode::IsInstanceOf<RSRootNode>() const;
4027 template bool RSNode::IsInstanceOf<RSCanvasDrawingNode>() const;
4028 template bool RSNode::IsInstanceOf<RSEffectNode>() const;
4029 
SetInstanceId(int32_t instanceId)4030 void RSNode::SetInstanceId(int32_t instanceId)
4031 {
4032     instanceId_ = instanceId;
4033     auto rsUIContext = rsUIContext_.lock();
4034     // use client multi don’t need
4035     if (rsUIContext == nullptr) {
4036         RSNodeMap::MutableInstance().RegisterNodeInstanceId(id_, instanceId_);
4037     }
4038 }
4039 
AddCommand(std::unique_ptr<RSCommand> & command,bool isRenderServiceCommand,FollowType followType,NodeId nodeId) const4040 bool RSNode::AddCommand(std::unique_ptr<RSCommand>& command, bool isRenderServiceCommand,
4041     FollowType followType, NodeId nodeId) const
4042 {
4043     auto transaction = GetRSTransaction();
4044     if (transaction != nullptr) {
4045         transaction->AddCommand(command, isRenderServiceCommand, followType, nodeId);
4046     } else {
4047         auto transactionProxy = RSTransactionProxy::GetInstance();
4048         if (!transactionProxy) {
4049             RS_LOGE("transactionProxy is nullptr");
4050             return false;
4051         }
4052         transactionProxy->AddCommand(command, isRenderServiceCommand, followType, nodeId);
4053     }
4054     return true;
4055 }
4056 
SetUIContextToken()4057 void RSNode::SetUIContextToken()
4058 {
4059     if (GetRSUIContext()) {
4060         std::unique_ptr<RSCommand> command = std::make_unique<RSSetUIContextToken>(id_, GetRSUIContext()->GetToken());
4061         AddCommand(command, IsRenderServiceNode(), GetFollowType(), id_);
4062     }
4063 }
4064 
4065 DrawNodeChangeCallback RSNode::drawNodeChangeCallback_ = nullptr;
SetDrawNodeChangeCallback(DrawNodeChangeCallback callback)4066 void RSNode::SetDrawNodeChangeCallback(DrawNodeChangeCallback callback)
4067 {
4068     if (drawNodeChangeCallback_) {
4069         return;
4070     }
4071     drawNodeChangeCallback_ = callback;
4072 }
4073 
4074 PropertyNodeChangeCallback RSNode::propertyNodeChangeCallback_ = nullptr;
4075 
4076 // Sets the callback function for property node change events.
SetPropertyNodeChangeCallback(PropertyNodeChangeCallback callback)4077 void RSNode::SetPropertyNodeChangeCallback(PropertyNodeChangeCallback callback)
4078 {
4079     if (propertyNodeChangeCallback_) {
4080         return;
4081     }
4082     propertyNodeChangeCallback_ = callback;
4083 }
4084 
AddModifier(const std::shared_ptr<ModifierNG::RSModifier> modifier)4085 void RSNode::AddModifier(const std::shared_ptr<ModifierNG::RSModifier> modifier)
4086 {
4087     {
4088         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
4089         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
4090         if (modifier == nullptr) {
4091             RS_LOGE("RSNode::AddModifier: null modifier, nodeId=%{public}" PRIu64, id_);
4092             return;
4093         }
4094         if (modifiersNG_.count(modifier->GetId())) {
4095             return;
4096         }
4097         modifier->OnAttach(*this); // Attach properties of modifier here
4098         auto modifierType = modifier->GetType();
4099         if (modifierType == ModifierNG::RSModifierType::NODE_MODIFIER) {
4100             return;
4101         }
4102         if (modifierType != ModifierNG::RSModifierType::BOUNDS && modifierType != ModifierNG::RSModifierType::FRAME &&
4103             modifierType != ModifierNG::RSModifierType::BACKGROUND_COLOR &&
4104             modifierType != ModifierNG::RSModifierType::ALPHA) {
4105             SetDrawNode();
4106             SetDrawNodeType(DrawNodeType::DrawPropertyType);
4107             if (modifierType == ModifierNG::RSModifierType::TRANSFORM) {
4108                 SetDrawNodeType(DrawNodeType::GeometryPropertyType);
4109             }
4110         }
4111         NotifyPageNodeChanged();
4112         modifiersNG_.emplace(modifier->GetId(), modifier);
4113     }
4114     std::unique_ptr<RSCommand> command = std::make_unique<RSAddModifierNG>(id_, modifier->CreateRenderModifier());
4115     AddCommand(command, IsRenderServiceNode(), GetFollowType(), id_);
4116     if (NeedForcedSendToRemote()) {
4117         std::unique_ptr<RSCommand> cmdForRemote =
4118             std::make_unique<RSAddModifierNG>(id_, modifier->CreateRenderModifier());
4119         AddCommand(cmdForRemote, true, GetFollowType(), id_);
4120     }
4121 }
4122 
RemoveModifier(const std::shared_ptr<ModifierNG::RSModifier> modifier)4123 void RSNode::RemoveModifier(const std::shared_ptr<ModifierNG::RSModifier> modifier)
4124 {
4125     {
4126         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
4127         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
4128         if (modifier == nullptr || !modifiersNG_.count(modifier->GetId())) {
4129             RS_LOGE("RSNode::RemoveModifier: null modifier or modifier not exist.");
4130             return;
4131         }
4132         modifiersNG_.erase(modifier->GetId());
4133     }
4134     modifier->OnDetach(); // Detach properties of modifier here
4135     std::unique_ptr<RSCommand> command =
4136         std::make_unique<RSRemoveModifierNG>(id_, modifier->GetType(), modifier->GetId());
4137     AddCommand(command, IsRenderServiceNode(), GetFollowType(), id_);
4138     if (NeedForcedSendToRemote()) {
4139         std::unique_ptr<RSCommand> cmdForRemote =
4140             std::make_unique<RSRemoveModifierNG>(id_, modifier->GetType(), modifier->GetId());
4141         AddCommand(cmdForRemote, true, GetFollowType(), id_);
4142     }
4143 }
4144 
GetPropertyById(const PropertyId & propertyId)4145 const std::shared_ptr<RSPropertyBase> RSNode::GetPropertyById(const PropertyId& propertyId)
4146 {
4147     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
4148     CHECK_FALSE_RETURN_VALUE(CheckMultiThreadAccess(__func__), nullptr);
4149     auto iter = properties_.find(propertyId);
4150     if (iter != properties_.end()) {
4151         return iter->second;
4152     }
4153     return {};
4154 }
4155 
GetPropertyByType(const ModifierNG::RSModifierType & modifierType,const ModifierNG::RSPropertyType & propertyType)4156 const std::shared_ptr<RSPropertyBase> RSNode::GetPropertyByType(
4157     const ModifierNG::RSModifierType& modifierType, const ModifierNG::RSPropertyType& propertyType)
4158 {
4159     auto& modifier = modifiersNGCreatedBySetter_[static_cast<uint16_t>(modifierType)];
4160     if (!modifier) {
4161         return {};
4162     }
4163     return modifier->GetProperty(propertyType);
4164 }
4165 } // namespace Rosen
4166 } // namespace OHOS
4167