• 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 <memory>
20 #include <sstream>
21 #include <string>
22 
23 #include "rs_trace.h"
24 #include "sandbox_utils.h"
25 
26 #include "animation/rs_animation.h"
27 #include "animation/rs_animation_group.h"
28 #include "animation/rs_animation_callback.h"
29 #include "animation/rs_implicit_animator.h"
30 #include "animation/rs_implicit_animator_map.h"
31 #include "animation/rs_render_particle_animation.h"
32 #include "command/rs_base_node_command.h"
33 #include "command/rs_node_command.h"
34 #include "common/rs_color.h"
35 #include "common/rs_common_def.h"
36 #include "common/rs_obj_abs_geometry.h"
37 #include "common/rs_vector4.h"
38 #include "modifier/rs_modifier.h"
39 #include "modifier/rs_modifier_manager_map.h"
40 #include "modifier/rs_property.h"
41 #include "modifier/rs_property_modifier.h"
42 #include "pipeline/rs_node_map.h"
43 #include "platform/common/rs_log.h"
44 #include "render/rs_filter.h"
45 #include "render/rs_material_filter.h"
46 #include "render/rs_blur_filter.h"
47 #include "render/rs_path.h"
48 #include "transaction/rs_transaction_proxy.h"
49 #include "ui/rs_canvas_drawing_node.h"
50 #include "ui/rs_canvas_node.h"
51 #include "ui/rs_display_node.h"
52 #include "feature/hyper_graphic_manager/rs_frame_rate_policy.h"
53 #include "ui/rs_proxy_node.h"
54 #include "ui/rs_root_node.h"
55 #include "ui/rs_surface_node.h"
56 #include "ui/rs_ui_context.h"
57 #include "ui/rs_ui_director.h"
58 
59 #ifdef _WIN32
60 #include <windows.h>
61 #define gettid GetCurrentThreadId
62 #endif
63 
64 #ifdef __APPLE__
65 #define gettid getpid
66 #endif
67 
68 #ifdef __gnu_linux__
69 #include <sys/types.h>
70 #include <sys/syscall.h>
71 #define gettid []() -> int32_t { return static_cast<int32_t>(syscall(SYS_gettid)); }
72 #endif
73 
74 namespace OHOS {
75 namespace Rosen {
76 namespace {
77 static bool g_isUniRenderEnabled = false;
78 static const std::unordered_map<RSUINodeType, std::string> RSUINodeTypeStrs = {
79     {RSUINodeType::UNKNOW,              "UNKNOW"},
80     {RSUINodeType::DISPLAY_NODE,        "DisplayNode"},
81     {RSUINodeType::RS_NODE,             "RsNode"},
82     {RSUINodeType::SURFACE_NODE,        "SurfaceNode"},
83     {RSUINodeType::PROXY_NODE,          "ProxyNode"},
84     {RSUINodeType::CANVAS_NODE,         "CanvasNode"},
85     {RSUINodeType::ROOT_NODE,           "RootNode"},
86     {RSUINodeType::EFFECT_NODE,         "EffectNode"},
87     {RSUINodeType::CANVAS_DRAWING_NODE, "CanvasDrawingNode"},
88 };
89 std::once_flag flag_;
IsPathAnimatableModifier(const RSModifierType & type)90 bool IsPathAnimatableModifier(const RSModifierType& type)
91 {
92     if (type == RSModifierType::BOUNDS || type == RSModifierType::FRAME || type == RSModifierType::TRANSLATE) {
93         return true;
94     }
95     return false;
96 }
97 }
98 
RSNode(bool isRenderServiceNode,NodeId id,bool isTextureExportNode,std::shared_ptr<RSUIContext> rsUIContext)99 RSNode::RSNode(bool isRenderServiceNode, NodeId id, bool isTextureExportNode, std::shared_ptr<RSUIContext> rsUIContext)
100     : isRenderServiceNode_(isRenderServiceNode), isTextureExportNode_(isTextureExportNode), id_(id),
101       rsUIContext_(rsUIContext), stagingPropertiesExtractor_(id, rsUIContext),
102       showingPropertiesFreezer_(id, rsUIContext)
103 {
104     InitUniRenderEnabled();
105 
106     if (rsUIContext_.lock() != nullptr) {
107         auto transaction = rsUIContext_.lock()->GetRSTransaction();
108         if (transaction != nullptr && g_isUniRenderEnabled && isTextureExportNode) {
109             std::call_once(flag_, [transaction]() {
110                 auto renderThreadClient = RSIRenderClient::CreateRenderThreadClient();
111                 transaction->SetRenderThreadClient(renderThreadClient);
112             });
113         }
114         hasCreateRenderNodeInRT_ = isTextureExportNode;
115         hasCreateRenderNodeInRS_ = !hasCreateRenderNodeInRT_;
116         return;
117     }
118     if (g_isUniRenderEnabled && isTextureExportNode) {
119         std::call_once(flag_, []() {
120             auto renderThreadClient = RSIRenderClient::CreateRenderThreadClient();
121             auto transactionProxy = RSTransactionProxy::GetInstance();
122             if (transactionProxy != nullptr) {
123                 transactionProxy->SetRenderThreadClient(renderThreadClient);
124             }
125         });
126     }
127     hasCreateRenderNodeInRT_ = isTextureExportNode;
128     hasCreateRenderNodeInRS_ = !hasCreateRenderNodeInRT_;
129 }
130 
RSNode(bool isRenderServiceNode,bool isTextureExportNode,std::shared_ptr<RSUIContext> rsUIContext)131 RSNode::RSNode(bool isRenderServiceNode, bool isTextureExportNode, std::shared_ptr<RSUIContext> rsUIContext)
132     : RSNode(isRenderServiceNode, GenerateId(), isTextureExportNode, rsUIContext) {}
133 
~RSNode()134 RSNode::~RSNode()
135 {
136     if (!FallbackAnimationsToContext()) {
137         FallbackAnimationsToRoot();
138     }
139     ClearAllModifiers();
140 
141     // break current (ui) parent-child relationship.
142     // render nodes will check if its child is expired and remove it, no need to manually remove it here.
143     SharedPtr parentPtr;
144     auto rsUIContext = rsUIContext_.lock();
145     if (rsUIContext != nullptr) {
146         parentPtr = rsUIContext->GetNodeMap().GetNode(parent_);
147         // tell RT/RS to destroy related render node
148         rsUIContext->GetMutableNodeMap().UnregisterNode(id_);
149         auto transaction = rsUIContext->GetRSTransaction();
150         if (transaction == nullptr || skipDestroyCommandInDestructor_) {
151             return;
152         }
153         std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeDestroy>(id_);
154         transaction->AddCommand(command, IsRenderServiceNode());
155         if ((IsRenderServiceNode() && hasCreateRenderNodeInRT_) ||
156             (!IsRenderServiceNode() && hasCreateRenderNodeInRS_)) {
157             command = std::make_unique<RSBaseNodeDestroy>(id_);
158             transaction->AddCommand(command, !IsRenderServiceNode());
159         }
160     } else {
161         parentPtr = RSNodeMap::Instance().GetNode(parent_);
162         RSNodeMap::MutableInstance().UnregisterNode(id_);
163         // tell RT/RS to destroy related render node
164         auto transactionProxy = RSTransactionProxy::GetInstance();
165         if (transactionProxy == nullptr || skipDestroyCommandInDestructor_) {
166             return;
167         }
168         std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeDestroy>(id_);
169         transactionProxy->AddCommand(command, IsRenderServiceNode());
170         if ((IsRenderServiceNode() && hasCreateRenderNodeInRT_) ||
171             (!IsRenderServiceNode() && hasCreateRenderNodeInRS_)) {
172             command = std::make_unique<RSBaseNodeDestroy>(id_);
173             transactionProxy->AddCommand(command, !IsRenderServiceNode());
174         }
175     }
176     if (parentPtr) {
177         parentPtr->RemoveChildById(id_);
178     }
179 }
180 
GetRSTransaction() const181 std::shared_ptr<RSTransactionHandler> RSNode::GetRSTransaction() const
182 {
183     auto rsUIContext = rsUIContext_.lock();
184     if (!rsUIContext) {
185         return nullptr;
186     }
187     return rsUIContext->GetRSTransaction();
188 }
189 
OpenImplicitAnimation(const RSAnimationTimingProtocol & timingProtocol,const RSAnimationTimingCurve & timingCurve,const std::function<void ()> & finishCallback)190 void RSNode::OpenImplicitAnimation(const RSAnimationTimingProtocol& timingProtocol,
191     const RSAnimationTimingCurve& timingCurve, const std::function<void()>& finishCallback)
192 {
193     auto implicitAnimator = RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
194     if (implicitAnimator == nullptr) {
195         ROSEN_LOGE("Failed to open implicit animation, implicit animator is null!");
196         return;
197     }
198 
199     std::shared_ptr<AnimationFinishCallback> animationFinishCallback;
200     if (finishCallback != nullptr) {
201         animationFinishCallback =
202             std::make_shared<AnimationFinishCallback>(finishCallback, timingProtocol.GetFinishCallbackType());
203     }
204     implicitAnimator->OpenImplicitAnimation(timingProtocol, timingCurve, std::move(animationFinishCallback));
205 }
206 
OpenImplicitAnimation(const std::shared_ptr<RSUIContext> rsUIContext,const RSAnimationTimingProtocol & timingProtocol,const RSAnimationTimingCurve & timingCurve,const std::function<void ()> & finishCallback)207 void RSNode::OpenImplicitAnimation(const std::shared_ptr<RSUIContext> rsUIContext,
208     const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve,
209     const std::function<void()>& finishCallback)
210 {
211     auto implicitAnimator =
212         rsUIContext ? rsUIContext->GetRSImplicitAnimator() : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
213     if (implicitAnimator == nullptr) {
214         ROSEN_LOGE("Failed to open implicit animation, implicit animator is null!");
215         return;
216     }
217 
218     std::shared_ptr<AnimationFinishCallback> animationFinishCallback;
219     if (finishCallback != nullptr) {
220         animationFinishCallback =
221             std::make_shared<AnimationFinishCallback>(finishCallback, timingProtocol.GetFinishCallbackType());
222     }
223     implicitAnimator->OpenImplicitAnimation(timingProtocol, timingCurve, std::move(animationFinishCallback));
224 }
225 
CloseImplicitAnimation()226 std::vector<std::shared_ptr<RSAnimation>> RSNode::CloseImplicitAnimation()
227 {
228     auto implicitAnimator = RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
229     if (implicitAnimator == nullptr) {
230         ROSEN_LOGE("Failed to close implicit animation, implicit animator is null!");
231         return {};
232     }
233 
234     return implicitAnimator->CloseImplicitAnimation();
235 }
236 
CloseImplicitAnimation(const std::shared_ptr<RSUIContext> rsUIContext)237 std::vector<std::shared_ptr<RSAnimation>> RSNode::CloseImplicitAnimation(const std::shared_ptr<RSUIContext> rsUIContext)
238 {
239     auto implicitAnimator =
240         rsUIContext ? rsUIContext->GetRSImplicitAnimator() : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
241     if (implicitAnimator == nullptr) {
242         ROSEN_LOGE("multi-instance Failed to close implicit animation, implicit animator is null!");
243         return {};
244     }
245 
246     return implicitAnimator->CloseImplicitAnimation();
247 }
248 
CloseImplicitCancelAnimation()249 bool RSNode::CloseImplicitCancelAnimation()
250 {
251     auto implicitAnimator = RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
252     if (implicitAnimator == nullptr) {
253         ROSEN_LOGE("Failed to close implicit animation for cancel, implicit animator is null!");
254         return false;
255     }
256 
257     return implicitAnimator->CloseImplicitCancelAnimation();
258 }
259 
CloseImplicitCancelAnimation(const std::shared_ptr<RSUIContext> rsUIContext)260 bool RSNode::CloseImplicitCancelAnimation(const std::shared_ptr<RSUIContext> rsUIContext)
261 {
262     auto implicitAnimator =
263         rsUIContext ? rsUIContext->GetRSImplicitAnimator() : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
264     if (implicitAnimator == nullptr) {
265         ROSEN_LOGE("multi-instance Failed to close implicit animation for cancel, implicit animator is null!");
266         return false;
267     }
268 
269     return implicitAnimator->CloseImplicitCancelAnimation();
270 }
271 
SetFrameNodeInfo(int32_t id,std::string tag)272 void RSNode::SetFrameNodeInfo(int32_t id, std::string tag)
273 {
274     frameNodeId_ = id;
275     frameNodeTag_ = tag;
276 }
277 
GetFrameNodeId()278 int32_t RSNode::GetFrameNodeId()
279 {
280     return frameNodeId_;
281 }
282 
GetFrameNodeTag()283 std::string RSNode::GetFrameNodeTag()
284 {
285     return frameNodeTag_;
286 }
287 
AddKeyFrame(float fraction,const RSAnimationTimingCurve & timingCurve,const PropertyCallback & propertyCallback)288 void RSNode::AddKeyFrame(
289     float fraction, const RSAnimationTimingCurve& timingCurve, const PropertyCallback& propertyCallback)
290 {
291     auto implicitAnimator = RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
292     if (implicitAnimator == nullptr) {
293         ROSEN_LOGE("Failed to add keyframe, implicit animator is null!");
294         return;
295     }
296 
297     implicitAnimator->BeginImplicitKeyFrameAnimation(fraction, timingCurve);
298     propertyCallback();
299     implicitAnimator->EndImplicitKeyFrameAnimation();
300 }
301 
AddKeyFrame(const std::shared_ptr<RSUIContext> rsUIContext,float fraction,const RSAnimationTimingCurve & timingCurve,const PropertyCallback & propertyCallback)302 void RSNode::AddKeyFrame(const std::shared_ptr<RSUIContext> rsUIContext,
303     float fraction, const RSAnimationTimingCurve& timingCurve, const PropertyCallback& propertyCallback)
304 {
305     auto implicitAnimator = rsUIContext ? rsUIContext->GetRSImplicitAnimator()
306                                         : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
307     if (implicitAnimator == nullptr) {
308         ROSEN_LOGE("Failed to add keyframe, implicit animator is null!");
309         return;
310     }
311 
312     implicitAnimator->BeginImplicitKeyFrameAnimation(fraction, timingCurve);
313     propertyCallback();
314     implicitAnimator->EndImplicitKeyFrameAnimation();
315 }
316 
AddKeyFrame(float fraction,const PropertyCallback & propertyCallback)317 void RSNode::AddKeyFrame(float fraction, const PropertyCallback& propertyCallback)
318 {
319     auto implicitAnimator = RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
320     if (implicitAnimator == nullptr) {
321         ROSEN_LOGE("Failed to add keyframe, implicit animator is null!");
322         return;
323     }
324 
325     implicitAnimator->BeginImplicitKeyFrameAnimation(fraction);
326     propertyCallback();
327     implicitAnimator->EndImplicitKeyFrameAnimation();
328 }
329 
AddKeyFrame(const std::shared_ptr<RSUIContext> rsUIContext,float fraction,const PropertyCallback & propertyCallback)330 void RSNode::AddKeyFrame(const std::shared_ptr<RSUIContext> rsUIContext,
331     float fraction, const PropertyCallback& propertyCallback)
332 {
333     auto implicitAnimator = rsUIContext ? rsUIContext->GetRSImplicitAnimator()
334                                         : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
335     if (implicitAnimator == nullptr) {
336         ROSEN_LOGE("Failed to add keyframe, implicit animator is null!");
337         return;
338     }
339 
340     implicitAnimator->BeginImplicitKeyFrameAnimation(fraction);
341     propertyCallback();
342     implicitAnimator->EndImplicitKeyFrameAnimation();
343 }
344 
AddDurationKeyFrame(int duration,const RSAnimationTimingCurve & timingCurve,const PropertyCallback & propertyCallback)345 void RSNode::AddDurationKeyFrame(
346     int duration, const RSAnimationTimingCurve& timingCurve, const PropertyCallback& propertyCallback)
347 {
348     auto implicitAnimator = RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
349     if (implicitAnimator == nullptr) {
350         ROSEN_LOGE("Failed to add keyframe, implicit animator is null!");
351         return;
352     }
353 
354     implicitAnimator->BeginImplicitDurationKeyFrameAnimation(duration, timingCurve);
355     propertyCallback();
356     implicitAnimator->EndImplicitDurationKeyFrameAnimation();
357 }
358 
AddDurationKeyFrame(const std::shared_ptr<RSUIContext> rsUIContext,int duration,const RSAnimationTimingCurve & timingCurve,const PropertyCallback & propertyCallback)359 void RSNode::AddDurationKeyFrame(const std::shared_ptr<RSUIContext> rsUIContext,
360     int duration, const RSAnimationTimingCurve& timingCurve, const PropertyCallback& propertyCallback)
361 {
362     auto implicitAnimator = rsUIContext ? rsUIContext->GetRSImplicitAnimator()
363                                         : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
364     if (implicitAnimator == nullptr) {
365         ROSEN_LOGE("Failed to add keyframe, implicit animator is null!");
366         return;
367     }
368 
369     implicitAnimator->BeginImplicitDurationKeyFrameAnimation(duration, timingCurve);
370     propertyCallback();
371     implicitAnimator->EndImplicitDurationKeyFrameAnimation();
372 }
373 
IsImplicitAnimationOpen()374 bool RSNode::IsImplicitAnimationOpen()
375 {
376     auto implicitAnimator = RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
377     return implicitAnimator && implicitAnimator->NeedImplicitAnimation();
378 }
379 
IsImplicitAnimationOpen(const std::shared_ptr<RSUIContext> rsUIContext)380 bool RSNode::IsImplicitAnimationOpen(const std::shared_ptr<RSUIContext> rsUIContext)
381 {
382     auto implicitAnimator = rsUIContext ? rsUIContext->GetRSImplicitAnimator()
383                                         : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
384     return implicitAnimator && implicitAnimator->NeedImplicitAnimation();
385 }
386 
Animate(const RSAnimationTimingProtocol & timingProtocol,const RSAnimationTimingCurve & timingCurve,const PropertyCallback & propertyCallback,const std::function<void ()> & finishCallback,const std::function<void ()> & repeatCallback)387 std::vector<std::shared_ptr<RSAnimation>> RSNode::Animate(const RSAnimationTimingProtocol& timingProtocol,
388     const RSAnimationTimingCurve& timingCurve, const PropertyCallback& propertyCallback,
389     const std::function<void()>& finishCallback, const std::function<void()>& repeatCallback)
390 {
391     if (propertyCallback == nullptr) {
392         ROSEN_LOGE("Failed to add curve animation, property callback is null!");
393         return {};
394     }
395 
396     auto implicitAnimator = RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
397     if (implicitAnimator == nullptr) {
398         ROSEN_LOGE("Failed to open implicit animation, implicit animator is null!");
399         return {};
400     }
401     std::shared_ptr<AnimationFinishCallback> animationFinishCallback;
402     if (finishCallback != nullptr) {
403         animationFinishCallback =
404             std::make_shared<AnimationFinishCallback>(finishCallback, timingProtocol.GetFinishCallbackType());
405     }
406     std::shared_ptr<AnimationRepeatCallback> animationRepeatCallback;
407     if (repeatCallback != nullptr) {
408         animationRepeatCallback = std::make_shared<AnimationRepeatCallback>(repeatCallback);
409     }
410     implicitAnimator->OpenImplicitAnimation(
411         timingProtocol, timingCurve, std::move(animationFinishCallback), std::move(animationRepeatCallback));
412     propertyCallback();
413     return implicitAnimator->CloseImplicitAnimation();
414 }
415 
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)416 std::vector<std::shared_ptr<RSAnimation>> RSNode::Animate(const std::shared_ptr<RSUIContext> rsUIContext,
417     const RSAnimationTimingProtocol& timingProtocol,
418     const RSAnimationTimingCurve& timingCurve, const PropertyCallback& propertyCallback,
419     const std::function<void()>& finishCallback, const std::function<void()>& repeatCallback)
420 {
421     if (propertyCallback == nullptr) {
422         ROSEN_LOGE("Failed to add curve animation, property callback is null!");
423         return {};
424     }
425 
426     auto implicitAnimator = rsUIContext ? rsUIContext->GetRSImplicitAnimator()
427                                         : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
428     if (implicitAnimator == nullptr) {
429         ROSEN_LOGE("Failed to open implicit animation, implicit animator is null!");
430         return {};
431     }
432     std::shared_ptr<AnimationFinishCallback> animationFinishCallback;
433     if (finishCallback != nullptr) {
434         animationFinishCallback =
435             std::make_shared<AnimationFinishCallback>(finishCallback, timingProtocol.GetFinishCallbackType());
436     }
437     std::shared_ptr<AnimationRepeatCallback> animationRepeatCallback;
438     if (repeatCallback != nullptr) {
439         animationRepeatCallback = std::make_shared<AnimationRepeatCallback>(repeatCallback);
440     }
441     implicitAnimator->OpenImplicitAnimation(
442         timingProtocol, timingCurve, std::move(animationFinishCallback), std::move(animationRepeatCallback));
443     propertyCallback();
444     return implicitAnimator->CloseImplicitAnimation();
445 }
446 
AnimateWithCurrentOptions(const PropertyCallback & propertyCallback,const std::function<void ()> & finishCallback,bool timingSensitive)447 std::vector<std::shared_ptr<RSAnimation>> RSNode::AnimateWithCurrentOptions(
448     const PropertyCallback& propertyCallback, const std::function<void()>& finishCallback, bool timingSensitive)
449 {
450     if (propertyCallback == nullptr) {
451         ROSEN_LOGE("Failed to add curve animation, property callback is null!");
452         return {};
453     }
454     if (finishCallback == nullptr) {
455         ROSEN_LOGE("Failed to add curve animation, finish callback is null!");
456         propertyCallback();
457         return {};
458     }
459 
460     auto implicitAnimator = RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
461     if (implicitAnimator == nullptr) {
462         ROSEN_LOGE("Failed to open implicit animation, implicit animator is null!");
463         propertyCallback();
464         return {};
465     }
466     auto finishCallbackType =
467         timingSensitive ? FinishCallbackType::TIME_SENSITIVE : FinishCallbackType::TIME_INSENSITIVE;
468     // re-use the current options and replace the finish callback
469     auto animationFinishCallback = std::make_shared<AnimationFinishCallback>(finishCallback, finishCallbackType);
470     implicitAnimator->OpenImplicitAnimation(std::move(animationFinishCallback));
471     propertyCallback();
472     return implicitAnimator->CloseImplicitAnimation();
473 }
474 
AnimateWithCurrentOptions(const std::shared_ptr<RSUIContext> rsUIContext,const PropertyCallback & propertyCallback,const std::function<void ()> & finishCallback,bool timingSensitive)475 std::vector<std::shared_ptr<RSAnimation>> RSNode::AnimateWithCurrentOptions(
476     const std::shared_ptr<RSUIContext> rsUIContext, const PropertyCallback& propertyCallback,
477     const std::function<void()>& finishCallback, bool timingSensitive)
478 {
479     if (propertyCallback == nullptr) {
480         ROSEN_LOGE("Failed to add curve animation, property callback is null!");
481         return {};
482     }
483     if (finishCallback == nullptr) {
484         ROSEN_LOGE("Failed to add curve animation, finish callback is null!");
485         propertyCallback();
486         return {};
487     }
488 
489     auto implicitAnimator = rsUIContext ? rsUIContext->GetRSImplicitAnimator()
490                                         : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
491     if (implicitAnimator == nullptr) {
492         ROSEN_LOGE("Failed to open implicit animation, implicit animator is null!");
493         propertyCallback();
494         return {};
495     }
496     auto finishCallbackType =
497         timingSensitive ? FinishCallbackType::TIME_SENSITIVE : FinishCallbackType::TIME_INSENSITIVE;
498     // re-use the current options and replace the finish callback
499     auto animationFinishCallback = std::make_shared<AnimationFinishCallback>(finishCallback, finishCallbackType);
500     implicitAnimator->OpenImplicitAnimation(std::move(animationFinishCallback));
501     propertyCallback();
502     return implicitAnimator->CloseImplicitAnimation();
503 }
504 
AnimateWithCurrentCallback(const RSAnimationTimingProtocol & timingProtocol,const RSAnimationTimingCurve & timingCurve,const PropertyCallback & propertyCallback)505 std::vector<std::shared_ptr<RSAnimation>> RSNode::AnimateWithCurrentCallback(
506     const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve,
507     const PropertyCallback& propertyCallback)
508 {
509     if (propertyCallback == nullptr) {
510         ROSEN_LOGE("Failed to add curve animation, property callback is null!");
511         return {};
512     }
513 
514     auto implicitAnimator = RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
515     if (implicitAnimator == nullptr) {
516         ROSEN_LOGE("Failed to open implicit animation, implicit animator is null!");
517         return {};
518     }
519     // re-use the current finish callback and replace the options
520     implicitAnimator->OpenImplicitAnimation(timingProtocol, timingCurve);
521     propertyCallback();
522     return implicitAnimator->CloseImplicitAnimation();
523 }
524 
AnimateWithCurrentCallback(const std::shared_ptr<RSUIContext> rsUIContext,const RSAnimationTimingProtocol & timingProtocol,const RSAnimationTimingCurve & timingCurve,const PropertyCallback & propertyCallback)525 std::vector<std::shared_ptr<RSAnimation>> RSNode::AnimateWithCurrentCallback(
526     const std::shared_ptr<RSUIContext> rsUIContext,
527     const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve,
528     const PropertyCallback& propertyCallback)
529 {
530     if (propertyCallback == nullptr) {
531         ROSEN_LOGE("Failed to add curve animation, property callback is null!");
532         return {};
533     }
534 
535     auto implicitAnimator = rsUIContext ? rsUIContext->GetRSImplicitAnimator()
536                                         : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
537     if (implicitAnimator == nullptr) {
538         ROSEN_LOGE("Failed to open implicit animation, implicit animator is null!");
539         return {};
540     }
541     // re-use the current finish callback and replace the options
542     implicitAnimator->OpenImplicitAnimation(timingProtocol, timingCurve);
543     propertyCallback();
544     return implicitAnimator->CloseImplicitAnimation();
545 }
546 
ExecuteWithoutAnimation(const PropertyCallback & callback,const std::shared_ptr<RSUIContext> rsUIContext,std::shared_ptr<RSImplicitAnimator> implicitAnimator)547 void RSNode::ExecuteWithoutAnimation(
548     const PropertyCallback& callback, const std::shared_ptr<RSUIContext> rsUIContext,
549     std::shared_ptr<RSImplicitAnimator> implicitAnimator)
550 {
551     if (callback == nullptr) {
552         ROSEN_LOGE("Failed to execute without animation, property callback is null!");
553         return;
554     }
555     if (implicitAnimator == nullptr) {
556         implicitAnimator = rsUIContext ? rsUIContext->GetRSImplicitAnimator()
557                                        : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
558     }
559     if (implicitAnimator == nullptr) {
560         callback();
561     } else {
562         implicitAnimator->ExecuteWithoutAnimation(callback);
563     }
564 }
565 
FallbackAnimationsToContext()566 bool RSNode::FallbackAnimationsToContext()
567 {
568     auto rsUIContext = rsUIContext_.lock();
569     if (rsUIContext == nullptr) {
570         return false;
571     }
572     std::unique_lock<std::recursive_mutex> lock(animationMutex_);
573     for (auto& [animationId, animation] : animations_) {
574         if (animation && animation->GetRepeatCount() == -1) {
575             continue;
576         }
577         rsUIContext->AddAnimationInner(std::move(animation));
578     }
579     animations_.clear();
580     return true;
581 }
582 
FallbackAnimationsToRoot()583 void RSNode::FallbackAnimationsToRoot()
584 {
585     auto target = RSNodeMap::Instance().GetAnimationFallbackNode(); // delete
586     if (target == nullptr) {
587         ROSEN_LOGE("Failed to move animation to root, root node is null!");
588         return;
589     }
590     std::unique_lock<std::recursive_mutex> lock(animationMutex_);
591     for (auto& [animationId, animation] : animations_) {
592         if (animation && animation->GetRepeatCount() == -1) {
593             continue;
594         }
595         RSNodeMap::MutableInstance().RegisterAnimationInstanceId(animationId, id_, instanceId_); // delete
596         target->AddAnimationInner(std::move(animation));
597     }
598     animations_.clear();
599 }
600 
AddAnimationInner(const std::shared_ptr<RSAnimation> & animation)601 void RSNode::AddAnimationInner(const std::shared_ptr<RSAnimation>& animation)
602 {
603     std::unique_lock<std::recursive_mutex> lock(animationMutex_);
604     animations_.emplace(animation->GetId(), animation);
605     animatingPropertyNum_[animation->GetPropertyId()]++;
606     SetDrawNode();
607 }
608 
RemoveAnimationInner(const std::shared_ptr<RSAnimation> & animation)609 void RSNode::RemoveAnimationInner(const std::shared_ptr<RSAnimation>& animation)
610 {
611     std::unique_lock<std::recursive_mutex> lock(animationMutex_);
612     if (auto it = animatingPropertyNum_.find(animation->GetPropertyId()); it != animatingPropertyNum_.end()) {
613         it->second--;
614         if (it->second == 0) {
615             animatingPropertyNum_.erase(it);
616             animation->SetPropertyOnAllAnimationFinish();
617         }
618     }
619     animations_.erase(animation->GetId());
620 }
621 
FinishAnimationByProperty(const PropertyId & id)622 void RSNode::FinishAnimationByProperty(const PropertyId& id)
623 {
624     std::unique_lock<std::recursive_mutex> lock(animationMutex_);
625     for (const auto& [animationId, animation] : animations_) {
626         if (animation->GetPropertyId() == id) {
627             animation->Finish();
628         }
629     }
630 }
631 
CancelAnimationByProperty(const PropertyId & id,const bool needForceSync)632 void RSNode::CancelAnimationByProperty(const PropertyId& id, const bool needForceSync)
633 {
634     std::vector<std::shared_ptr<RSAnimation>> toBeRemoved;
635     {
636         std::unique_lock<std::recursive_mutex> lock(animationMutex_);
637         animatingPropertyNum_.erase(id);
638         EraseIf(animations_, [id, &toBeRemoved](const auto& pair) {
639             if (pair.second && (pair.second->GetPropertyId() == id)) {
640                 toBeRemoved.emplace_back(pair.second);
641                 return true;
642             }
643             return false;
644         });
645     }
646     // Destroy the cancelled animations outside the lock, since destroying them may trigger OnFinish callbacks, and
647     // callbacks may add/remove other animations, doing this with the lock would cause a deadlock.
648     toBeRemoved.clear();
649 
650     if (needForceSync) {
651         // Avoid animation on current property not cancelled in RS
652         std::unique_ptr<RSCommand> command = std::make_unique<RSAnimationCancel>(id_, id);
653         AddCommand(command, IsRenderServiceNode(), GetFollowType(), id_);
654         if (NeedForcedSendToRemote()) {
655             std::unique_ptr<RSCommand> commandForRemote = std::make_unique<RSAnimationCancel>(id_, id);
656             AddCommand(commandForRemote, true, GetFollowType(), id_);
657         }
658     }
659 }
660 
GetStagingProperties() const661 const RSModifierExtractor& RSNode::GetStagingProperties() const
662 {
663     return stagingPropertiesExtractor_;
664 }
665 
GetShowingProperties() const666 const RSShowingPropertiesFreezer& RSNode::GetShowingProperties() const
667 {
668     return showingPropertiesFreezer_;
669 }
670 
AddAnimation(const std::shared_ptr<RSAnimation> & animation,bool isStartAnimation)671 void RSNode::AddAnimation(const std::shared_ptr<RSAnimation>& animation, bool isStartAnimation)
672 {
673     if (animation == nullptr) {
674         ROSEN_LOGE("Failed to add animation, animation is null!");
675         return;
676     }
677 
678     auto animationId = animation->GetId();
679     {
680         std::unique_lock<std::recursive_mutex> lock(animationMutex_);
681         if (animations_.find(animationId) != animations_.end()) {
682             ROSEN_LOGE("Failed to add animation, animation already exists!");
683             return;
684         }
685     }
686 
687     // Note: Animation cancellation logic is now handled by RSImplicitAnimator. The code below might cause Spring
688     // Animations with a zero duration to not inherit velocity correctly, an issue slated for future resolution.
689     // This code is retained to ensure backward compatibility with specific arkui component animations.
690     if (animation->GetDuration() <= 0 && id_ != 0) {
691         FinishAnimationByProperty(animation->GetPropertyId());
692     }
693 
694     AddAnimationInner(animation);
695 
696     animation->StartInner(shared_from_this());
697     if (!isStartAnimation) {
698         animation->Pause();
699     }
700 }
701 
RemoveAllAnimations()702 void RSNode::RemoveAllAnimations()
703 {
704     std::unique_lock<std::recursive_mutex> lock(animationMutex_);
705     for (const auto& [id, animation] : animations_) {
706         RemoveAnimation(animation);
707     }
708 }
709 
RemoveAnimation(const std::shared_ptr<RSAnimation> & animation)710 void RSNode::RemoveAnimation(const std::shared_ptr<RSAnimation>& animation)
711 {
712     if (animation == nullptr) {
713         ROSEN_LOGE("Failed to remove animation, animation is null!");
714         return;
715     }
716 
717     {
718         std::unique_lock<std::recursive_mutex> lock(animationMutex_);
719         if (animations_.find(animation->GetId()) == animations_.end()) {
720             ROSEN_LOGE("Failed to remove animation, animation not exists!");
721             return;
722         }
723     }
724     animation->Finish();
725 }
726 
SetMotionPathOption(const std::shared_ptr<RSMotionPathOption> & motionPathOption)727 void RSNode::SetMotionPathOption(const std::shared_ptr<RSMotionPathOption>& motionPathOption)
728 {
729     motionPathOption_ = motionPathOption;
730     UpdateModifierMotionPathOption();
731 }
732 
SetMagnifierParams(const std::shared_ptr<RSMagnifierParams> & para)733 void RSNode::SetMagnifierParams(const std::shared_ptr<RSMagnifierParams>& para)
734 {
735     SetProperty<RSMagnifierParamsModifier, RSProperty<std::shared_ptr<RSMagnifierParams>>>(
736         RSModifierType::MAGNIFIER_PARA, para);
737 }
738 
GetMotionPathOption() const739 const std::shared_ptr<RSMotionPathOption> RSNode::GetMotionPathOption() const
740 {
741     return motionPathOption_;
742 }
743 
HasPropertyAnimation(const PropertyId & id)744 bool RSNode::HasPropertyAnimation(const PropertyId& id)
745 {
746     std::unique_lock<std::recursive_mutex> lock(animationMutex_);
747     auto it = animatingPropertyNum_.find(id);
748     return it != animatingPropertyNum_.end() && it->second > 0;
749 }
750 
GetAnimationByPropertyId(const PropertyId & id)751 std::vector<AnimationId> RSNode::GetAnimationByPropertyId(const PropertyId& id)
752 {
753     std::unique_lock<std::recursive_mutex> lock(animationMutex_);
754     std::vector<AnimationId> animations;
755     for (auto& [animateId, animation] : animations_) {
756         if (animation->GetPropertyId() == id) {
757             animations.push_back(animateId);
758         }
759     }
760     return animations;
761 }
762 
IsGeometryDirty() const763 bool RSNode::IsGeometryDirty() const
764 {
765     return dirtyType_ & static_cast<uint32_t>(NodeDirtyType::GEOMETRY);
766 }
767 
IsAppearanceDirty() const768 bool RSNode::IsAppearanceDirty() const
769 {
770     return dirtyType_ & static_cast<uint32_t>(NodeDirtyType::APPEARANCE);
771 }
772 
MarkDirty(NodeDirtyType type,bool isDirty)773 void RSNode::MarkDirty(NodeDirtyType type, bool isDirty)
774 {
775     if (isDirty) {
776         dirtyType_ |= static_cast<uint32_t>(type);
777     } else {
778         dirtyType_ &= ~static_cast<uint32_t>(type);
779     }
780 }
781 
GetGlobalPositionX() const782 float RSNode::GetGlobalPositionX() const
783 {
784     return globalPositionX_;
785 }
786 
GetGlobalPositionY() const787 float RSNode::GetGlobalPositionY() const
788 {
789     return globalPositionY_;
790 }
791 
GetLocalGeometry() const792 std::shared_ptr<RSObjAbsGeometry> RSNode::GetLocalGeometry() const
793 {
794     return localGeometry_;
795 }
796 
GetGlobalGeometry() const797 std::shared_ptr<RSObjAbsGeometry> RSNode::GetGlobalGeometry() const
798 {
799     return globalGeometry_;
800 }
801 
UpdateLocalGeometry()802 void RSNode::UpdateLocalGeometry()
803 {
804     if (!IsGeometryDirty()) {
805         return;
806     }
807     localGeometry_ = std::make_shared<RSObjAbsGeometry>();
808     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
809     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
810     for (const auto& [_, modifier] : modifiers_) {
811         if (modifier->GetPropertyModifierType() == RSPropertyModifierType::GEOMETRY) {
812             modifier->Apply(localGeometry_);
813         }
814     }
815 }
816 
UpdateGlobalGeometry(const std::shared_ptr<RSObjAbsGeometry> & parentGlobalGeometry)817 void RSNode::UpdateGlobalGeometry(const std::shared_ptr<RSObjAbsGeometry>& parentGlobalGeometry)
818 {
819     if (parentGlobalGeometry == nullptr || localGeometry_ == nullptr) {
820         return;
821     }
822     if (globalGeometry_ == nullptr) {
823         globalGeometry_ = std::make_shared<RSObjAbsGeometry>();
824     }
825     *globalGeometry_ = *localGeometry_;
826     globalGeometry_->UpdateMatrix(&parentGlobalGeometry->GetAbsMatrix(), std::nullopt);
827 
828     float parentGlobalPositionX = 0.f;
829     float parentGlobalPositionY = 0.f;
830     auto parent = GetParent();
831     if (parent) {
832         parentGlobalPositionX = parent->globalPositionX_;
833         parentGlobalPositionY = parent->globalPositionY_;
834     }
835     globalPositionX_ = parentGlobalPositionX + localGeometry_->GetX();
836     globalPositionY_ = parentGlobalPositionY + localGeometry_->GetY();
837 }
838 
839 template<typename ModifierName, typename PropertyName, typename T>
SetProperty(RSModifierType modifierType,T value)840 void RSNode::SetProperty(RSModifierType modifierType, T value)
841 {
842     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
843     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
844     auto iter = propertyModifiers_.find(modifierType);
845     if (iter != propertyModifiers_.end()) {
846         auto property = std::static_pointer_cast<PropertyName>(iter->second->GetProperty());
847         if (property == nullptr) {
848             ROSEN_LOGE("RSNode::SetProperty: failed to set property, property is null!");
849             return;
850         }
851         property->Set(value);
852         return;
853     }
854     auto property = std::make_shared<PropertyName>(value);
855     auto propertyModifier = std::make_shared<ModifierName>(property);
856     propertyModifiers_.emplace(modifierType, propertyModifier);
857     AddModifier(propertyModifier);
858 }
859 
860 // alpha
SetAlpha(float alpha)861 void RSNode::SetAlpha(float alpha)
862 {
863     SetProperty<RSAlphaModifier, RSAnimatableProperty<float>>(RSModifierType::ALPHA, alpha);
864     if (alpha < 1) {
865         SetDrawNode();
866     }
867 }
868 
SetAlphaOffscreen(bool alphaOffscreen)869 void RSNode::SetAlphaOffscreen(bool alphaOffscreen)
870 {
871     SetProperty<RSAlphaOffscreenModifier, RSProperty<bool>>(RSModifierType::ALPHA_OFFSCREEN, alphaOffscreen);
872 }
873 
874 // Bounds
SetBounds(const Vector4f & bounds)875 void RSNode::SetBounds(const Vector4f& bounds)
876 {
877     SetProperty<RSBoundsModifier, RSAnimatableProperty<Vector4f>>(RSModifierType::BOUNDS, bounds);
878     OnBoundsSizeChanged();
879     if (GetStagingProperties().GetBounds().x_ != 0 || GetStagingProperties().GetBounds().y_ != 0) {
880         SetDrawNode();
881     }
882 }
883 
SetBounds(float positionX,float positionY,float width,float height)884 void RSNode::SetBounds(float positionX, float positionY, float width, float height)
885 {
886     SetBounds({ positionX, positionY, width, height });
887 }
888 
SetBoundsWidth(float width)889 void RSNode::SetBoundsWidth(float width)
890 {
891     std::shared_ptr<RSAnimatableProperty<Vector4f>> property;
892     {
893         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
894         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
895         auto iter = propertyModifiers_.find(RSModifierType::BOUNDS);
896         if (iter == propertyModifiers_.end()) {
897             SetBounds(0.f, 0.f, width, 0.f);
898             return;
899         }
900         property = std::static_pointer_cast<RSAnimatableProperty<Vector4f>>(iter->second->GetProperty());
901     }
902 
903     if (property == nullptr) {
904         return;
905     }
906     auto bounds = property->Get();
907     bounds.z_ = width;
908     property->Set(bounds);
909     OnBoundsSizeChanged();
910 }
911 
SetBoundsHeight(float height)912 void RSNode::SetBoundsHeight(float height)
913 {
914     std::shared_ptr<RSAnimatableProperty<Vector4f>> property;
915     {
916         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
917         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
918         auto iter = propertyModifiers_.find(RSModifierType::BOUNDS);
919         if (iter == propertyModifiers_.end()) {
920             SetBounds(0.f, 0.f, 0.f, height);
921             return;
922         }
923         property = std::static_pointer_cast<RSAnimatableProperty<Vector4f>>(iter->second->GetProperty());
924     }
925 
926     if (property == nullptr) {
927         return;
928     }
929     auto bounds = property->Get();
930     bounds.w_ = height;
931     property->Set(bounds);
932     OnBoundsSizeChanged();
933 }
934 
935 // Frame
SetFrame(const Vector4f & bounds)936 void RSNode::SetFrame(const Vector4f& bounds)
937 {
938     SetProperty<RSFrameModifier, RSAnimatableProperty<Vector4f>>(RSModifierType::FRAME, bounds);
939     if (GetStagingProperties().GetFrame().x_ != GetStagingProperties().GetBounds().x_
940         || GetStagingProperties().GetFrame().y_ != GetStagingProperties().GetBounds().y_) {
941         SetDrawNode();
942     }
943 }
944 
SetFrame(float positionX,float positionY,float width,float height)945 void RSNode::SetFrame(float positionX, float positionY, float width, float height)
946 {
947     SetFrame({ positionX, positionY, width, height });
948 }
949 
SetFramePositionX(float positionX)950 void RSNode::SetFramePositionX(float positionX)
951 {
952     std::shared_ptr<RSAnimatableProperty<Vector4f>> property;
953     {
954         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
955         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
956         auto iter = propertyModifiers_.find(RSModifierType::FRAME);
957         if (iter == propertyModifiers_.end()) {
958             SetFrame(positionX, 0.f, 0.f, 0.f);
959             return;
960         }
961         property = std::static_pointer_cast<RSAnimatableProperty<Vector4f>>(iter->second->GetProperty());
962     }
963 
964     if (property == nullptr) {
965         return;
966     }
967     auto frame = property->Get();
968     frame.x_ = positionX;
969     property->Set(frame);
970     SetDrawNode();
971 }
972 
SetFramePositionY(float positionY)973 void RSNode::SetFramePositionY(float positionY)
974 {
975     std::shared_ptr<RSAnimatableProperty<Vector4f>> property;
976     {
977         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
978         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
979         auto iter = propertyModifiers_.find(RSModifierType::FRAME);
980         if (iter == propertyModifiers_.end()) {
981             SetFrame(0.f, positionY, 0.f, 0.f);
982             return;
983         }
984         property = std::static_pointer_cast<RSAnimatableProperty<Vector4f>>(iter->second->GetProperty());
985     }
986 
987     if (property == nullptr) {
988         return;
989     }
990     auto frame = property->Get();
991     frame.y_ = positionY;
992     property->Set(frame);
993     SetDrawNode();
994 }
995 
SetSandBox(std::optional<Vector2f> parentPosition)996 void RSNode::SetSandBox(std::optional<Vector2f> parentPosition)
997 {
998     if (!parentPosition.has_value()) {
999         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1000         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1001         auto iter = propertyModifiers_.find(RSModifierType::SANDBOX);
1002         if (iter != propertyModifiers_.end()) {
1003             RemoveModifier(iter->second);
1004             propertyModifiers_.erase(iter);
1005         }
1006         return;
1007     }
1008     SetProperty<RSSandBoxModifier, RSAnimatableProperty<Vector2f>>(RSModifierType::SANDBOX, parentPosition.value());
1009 }
1010 
SetPositionZ(float positionZ)1011 void RSNode::SetPositionZ(float positionZ)
1012 {
1013     if (drawNodeChangeCallback_) {
1014         drawNodeChangeCallback_(shared_from_this(), true);
1015     }
1016     SetProperty<RSPositionZModifier, RSAnimatableProperty<float>>(RSModifierType::POSITION_Z, positionZ);
1017 }
1018 
SetPositionZApplicableCamera3D(bool isApplicable)1019 void RSNode::SetPositionZApplicableCamera3D(bool isApplicable)
1020 {
1021     SetProperty<RSPositionZApplicableCamera3DModifier, RSProperty<bool>>(
1022         RSModifierType::POSITION_Z_APPLICABLE_CAMERA3D, isApplicable);
1023 }
1024 
1025 // pivot
SetPivot(const Vector2f & pivot)1026 void RSNode::SetPivot(const Vector2f& pivot)
1027 {
1028     SetProperty<RSPivotModifier, RSAnimatableProperty<Vector2f>>(RSModifierType::PIVOT, pivot);
1029 }
1030 
SetPivot(float pivotX,float pivotY)1031 void RSNode::SetPivot(float pivotX, float pivotY)
1032 {
1033     SetPivot({ pivotX, pivotY });
1034 }
1035 
SetPivotX(float pivotX)1036 void RSNode::SetPivotX(float pivotX)
1037 {
1038     std::shared_ptr<RSAnimatableProperty<Vector2f>> property;
1039     {
1040         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1041         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1042         auto iter = propertyModifiers_.find(RSModifierType::PIVOT);
1043         if (iter == propertyModifiers_.end()) {
1044             SetPivot(pivotX, 0.5f);
1045             return;
1046         }
1047         property = std::static_pointer_cast<RSAnimatableProperty<Vector2f>>(iter->second->GetProperty());
1048     }
1049 
1050     if (property == nullptr) {
1051         return;
1052     }
1053     auto pivot = property->Get();
1054     pivot.x_ = pivotX;
1055     property->Set(pivot);
1056 }
1057 
SetPivotY(float pivotY)1058 void RSNode::SetPivotY(float pivotY)
1059 {
1060     std::shared_ptr<RSAnimatableProperty<Vector2f>> property;
1061     {
1062         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1063         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1064         auto iter = propertyModifiers_.find(RSModifierType::PIVOT);
1065         if (iter == propertyModifiers_.end()) {
1066             SetPivot(0.5f, pivotY);
1067             return;
1068         }
1069         property = std::static_pointer_cast<RSAnimatableProperty<Vector2f>>(iter->second->GetProperty());
1070     }
1071 
1072     if (property == nullptr) {
1073         return;
1074     }
1075     auto pivot = property->Get();
1076     pivot.y_ = pivotY;
1077     property->Set(pivot);
1078 }
1079 
SetPivotZ(const float pivotZ)1080 void RSNode::SetPivotZ(const float pivotZ)
1081 {
1082     SetProperty<RSPivotZModifier, RSAnimatableProperty<float>>(RSModifierType::PIVOT_Z, pivotZ);
1083 }
1084 
SetCornerRadius(float cornerRadius)1085 void RSNode::SetCornerRadius(float cornerRadius)
1086 {
1087     SetCornerRadius(Vector4f(cornerRadius));
1088 }
1089 
SetCornerRadius(const Vector4f & cornerRadius)1090 void RSNode::SetCornerRadius(const Vector4f& cornerRadius)
1091 {
1092     SetProperty<RSCornerRadiusModifier, RSAnimatableProperty<Vector4f>>(RSModifierType::CORNER_RADIUS, cornerRadius);
1093 }
1094 
1095 // transform
SetRotation(const Quaternion & quaternion)1096 void RSNode::SetRotation(const Quaternion& quaternion)
1097 {
1098     SetProperty<RSQuaternionModifier, RSAnimatableProperty<Quaternion>>(RSModifierType::QUATERNION, quaternion);
1099 }
1100 
SetRotation(float degree)1101 void RSNode::SetRotation(float degree)
1102 {
1103     SetProperty<RSRotationModifier, RSAnimatableProperty<float>>(RSModifierType::ROTATION, degree);
1104 }
1105 
SetRotation(float degreeX,float degreeY,float degreeZ)1106 void RSNode::SetRotation(float degreeX, float degreeY, float degreeZ)
1107 {
1108     SetRotationX(degreeX);
1109     SetRotationY(degreeY);
1110     SetRotation(degreeZ);
1111 }
1112 
SetRotationX(float degree)1113 void RSNode::SetRotationX(float degree)
1114 {
1115     SetProperty<RSRotationXModifier, RSAnimatableProperty<float>>(RSModifierType::ROTATION_X, degree);
1116 }
1117 
SetRotationY(float degree)1118 void RSNode::SetRotationY(float degree)
1119 {
1120     SetProperty<RSRotationYModifier, RSAnimatableProperty<float>>(RSModifierType::ROTATION_Y, degree);
1121 }
1122 
SetCameraDistance(float cameraDistance)1123 void RSNode::SetCameraDistance(float cameraDistance)
1124 {
1125     SetProperty<RSCameraDistanceModifier, RSAnimatableProperty<float>>(RSModifierType::CAMERA_DISTANCE, cameraDistance);
1126 }
1127 
SetTranslate(const Vector2f & translate)1128 void RSNode::SetTranslate(const Vector2f& translate)
1129 {
1130     SetProperty<RSTranslateModifier, RSAnimatableProperty<Vector2f>>(RSModifierType::TRANSLATE, translate);
1131 }
1132 
SetTranslate(float translateX,float translateY,float translateZ)1133 void RSNode::SetTranslate(float translateX, float translateY, float translateZ)
1134 {
1135     SetTranslate({ translateX, translateY });
1136     SetTranslateZ(translateZ);
1137 }
1138 
SetTranslateX(float translate)1139 void RSNode::SetTranslateX(float translate)
1140 {
1141     std::shared_ptr<RSAnimatableProperty<Vector2f>> property;
1142     {
1143         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1144         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1145         auto iter = propertyModifiers_.find(RSModifierType::TRANSLATE);
1146         if (iter == propertyModifiers_.end()) {
1147             SetTranslate({ translate, 0.f });
1148             return;
1149         }
1150         property = std::static_pointer_cast<RSAnimatableProperty<Vector2f>>(iter->second->GetProperty());
1151     }
1152 
1153     if (property == nullptr) {
1154         return;
1155     }
1156     auto trans = property->Get();
1157     trans.x_ = translate;
1158     property->Set(trans);
1159 }
1160 
SetTranslateY(float translate)1161 void RSNode::SetTranslateY(float translate)
1162 {
1163     std::shared_ptr<RSAnimatableProperty<Vector2f>> property;
1164     {
1165         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1166         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1167         auto iter = propertyModifiers_.find(RSModifierType::TRANSLATE);
1168         if (iter == propertyModifiers_.end()) {
1169             SetTranslate({ 0.f, translate });
1170             return;
1171         }
1172         property = std::static_pointer_cast<RSAnimatableProperty<Vector2f>>(iter->second->GetProperty());
1173     }
1174 
1175     if (property == nullptr) {
1176         return;
1177     }
1178     auto trans = property->Get();
1179     trans.y_ = translate;
1180     property->Set(trans);
1181 }
1182 
SetTranslateZ(float translate)1183 void RSNode::SetTranslateZ(float translate)
1184 {
1185     SetProperty<RSTranslateZModifier, RSAnimatableProperty<float>>(RSModifierType::TRANSLATE_Z, translate);
1186 }
1187 
SetScale(float scale)1188 void RSNode::SetScale(float scale)
1189 {
1190     SetScale({ scale, scale });
1191 }
1192 
SetScale(float scaleX,float scaleY)1193 void RSNode::SetScale(float scaleX, float scaleY)
1194 {
1195     SetScale({ scaleX, scaleY });
1196 }
1197 
SetScale(const Vector2f & scale)1198 void RSNode::SetScale(const Vector2f& scale)
1199 {
1200     SetProperty<RSScaleModifier, RSAnimatableProperty<Vector2f>>(RSModifierType::SCALE, scale);
1201 }
1202 
SetScaleX(float scaleX)1203 void RSNode::SetScaleX(float scaleX)
1204 {
1205     std::shared_ptr<RSAnimatableProperty<Vector2f>> property;
1206     {
1207         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1208         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1209         auto iter = propertyModifiers_.find(RSModifierType::SCALE);
1210         if (iter == propertyModifiers_.end()) {
1211             SetScale(scaleX, 1.f);
1212             return;
1213         }
1214         property = std::static_pointer_cast<RSAnimatableProperty<Vector2f>>(iter->second->GetProperty());
1215     }
1216 
1217     if (property == nullptr) {
1218         return;
1219     }
1220     auto scale = property->Get();
1221     scale.x_ = scaleX;
1222     property->Set(scale);
1223 }
1224 
SetScaleY(float scaleY)1225 void RSNode::SetScaleY(float scaleY)
1226 {
1227     std::shared_ptr<RSAnimatableProperty<Vector2f>> property;
1228     {
1229         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1230         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1231         auto iter = propertyModifiers_.find(RSModifierType::SCALE);
1232         if (iter == propertyModifiers_.end()) {
1233             SetScale(1.f, scaleY);
1234             return;
1235         }
1236         property = std::static_pointer_cast<RSAnimatableProperty<Vector2f>>(iter->second->GetProperty());
1237     }
1238 
1239     if (property == nullptr) {
1240         return;
1241     }
1242     auto scale = property->Get();
1243     scale.y_ = scaleY;
1244     property->Set(scale);
1245 }
1246 
SetScaleZ(const float & scaleZ)1247 void RSNode::SetScaleZ(const float& scaleZ)
1248 {
1249     SetProperty<RSScaleZModifier, RSAnimatableProperty<float>>(RSModifierType::SCALE_Z, scaleZ);
1250 }
1251 
SetSkew(float skew)1252 void RSNode::SetSkew(float skew)
1253 {
1254     SetSkew({ skew, skew, skew });
1255 }
1256 
SetSkew(float skewX,float skewY)1257 void RSNode::SetSkew(float skewX, float skewY)
1258 {
1259     SetSkew({ skewX, skewY, 0.f });
1260 }
1261 
SetSkew(float skewX,float skewY,float skewZ)1262 void RSNode::SetSkew(float skewX, float skewY, float skewZ)
1263 {
1264     SetSkew({ skewX, skewY, skewZ });
1265 }
1266 
SetSkew(const Vector3f & skew)1267 void RSNode::SetSkew(const Vector3f& skew)
1268 {
1269     SetProperty<RSSkewModifier, RSAnimatableProperty<Vector3f>>(RSModifierType::SKEW, skew);
1270 }
1271 
SetSkewX(float skewX)1272 void RSNode::SetSkewX(float skewX)
1273 {
1274     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1275     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1276     auto iter = propertyModifiers_.find(RSModifierType::SKEW);
1277     if (iter == propertyModifiers_.end()) {
1278         SetSkew(skewX, 0.f);
1279         return;
1280     }
1281 
1282     auto property = std::static_pointer_cast<RSAnimatableProperty<Vector3f>>(iter->second->GetProperty());
1283     if (property == nullptr) {
1284         return;
1285     }
1286     auto skew = property->Get();
1287     skew.x_ = skewX;
1288     property->Set(skew);
1289 }
1290 
SetSkewY(float skewY)1291 void RSNode::SetSkewY(float skewY)
1292 {
1293     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1294     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1295     auto iter = propertyModifiers_.find(RSModifierType::SKEW);
1296     if (iter == propertyModifiers_.end()) {
1297         SetSkew(0.f, skewY);
1298         return;
1299     }
1300 
1301     auto property = std::static_pointer_cast<RSAnimatableProperty<Vector3f>>(iter->second->GetProperty());
1302     if (property == nullptr) {
1303         return;
1304     }
1305     auto skew = property->Get();
1306     skew.y_ = skewY;
1307     property->Set(skew);
1308 }
1309 
SetRSUIContext(std::shared_ptr<RSUIContext> rsUIContext)1310 void RSNode::SetRSUIContext(std::shared_ptr<RSUIContext> rsUIContext)
1311 {
1312     if (rsUIContext == nullptr) {
1313         return;
1314     }
1315     auto rsContext = rsUIContext_.lock();
1316     if ((rsContext != nullptr) && (rsContext == rsUIContext)) {
1317         return;
1318     }
1319 
1320     RSModifierExtractor rsModifierExtractor(id_, rsUIContext);
1321     stagingPropertiesExtractor_ = rsModifierExtractor;
1322     RSShowingPropertiesFreezer showingPropertiesFreezer(id_, rsUIContext);
1323     showingPropertiesFreezer_ = showingPropertiesFreezer;
1324     // step1 register node to new nodeMap
1325     RegisterNodeMap();
1326 
1327     // if have old rsContext, should remove nodeId from old nodeMap and travel child
1328     if (rsContext != nullptr) {
1329         // step2 remove node from old context
1330         rsContext->GetMutableNodeMap().UnregisterNode(id_);
1331         // sync child
1332         for (uint32_t index = 0; index < children_.size(); index++) {
1333             if (auto childPtr = rsContext->GetNodeMap().GetNode(children_[index])) {
1334                 childPtr->SetRSUIContext(rsUIContext);
1335             }
1336         }
1337     }
1338     // step3 sign
1339     rsUIContext_ = rsUIContext;
1340 }
1341 
SetSkewZ(float skewZ)1342 void RSNode::SetSkewZ(float skewZ)
1343 {
1344     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1345     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1346     auto iter = propertyModifiers_.find(RSModifierType::SKEW);
1347     if (iter == propertyModifiers_.end()) {
1348         SetSkew(0.f, 0.f, skewZ);
1349         return;
1350     }
1351 
1352     auto property = std::static_pointer_cast<RSAnimatableProperty<Vector3f>>(iter->second->GetProperty());
1353     if (property == nullptr) {
1354         return;
1355     }
1356     auto skew = property->Get();
1357     skew.z_ = skewZ;
1358     property->Set(skew);
1359 }
1360 
SetPersp(float persp)1361 void RSNode::SetPersp(float persp)
1362 {
1363     SetPersp({ persp, persp, 0.f, 1.f });
1364 }
1365 
SetPersp(float perspX,float perspY)1366 void RSNode::SetPersp(float perspX, float perspY)
1367 {
1368     SetPersp({ perspX, perspY, 0.f, 1.f });
1369 }
1370 
SetPersp(float perspX,float perspY,float perspZ,float perspW)1371 void RSNode::SetPersp(float perspX, float perspY, float perspZ, float perspW)
1372 {
1373     SetPersp({ perspX, perspY, perspZ, perspW });
1374 }
1375 
SetPersp(const Vector4f & persp)1376 void RSNode::SetPersp(const Vector4f& persp)
1377 {
1378     SetProperty<RSPerspModifier, RSAnimatableProperty<Vector4f>>(RSModifierType::PERSP, persp);
1379 }
1380 
SetPerspX(float perspX)1381 void RSNode::SetPerspX(float perspX)
1382 {
1383     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1384     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1385     auto iter = propertyModifiers_.find(RSModifierType::PERSP);
1386     if (iter == propertyModifiers_.end()) {
1387         SetPersp({perspX, 0.f, 0.0f, 1.0f});
1388         return;
1389     }
1390 
1391     auto property = std::static_pointer_cast<RSAnimatableProperty<Vector4f>>(iter->second->GetProperty());
1392     if (property == nullptr) {
1393         return;
1394     }
1395     auto persp = property->Get();
1396     persp.x_ = perspX;
1397     property->Set(persp);
1398 }
1399 
SetPerspY(float perspY)1400 void RSNode::SetPerspY(float perspY)
1401 {
1402     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1403     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
1404     auto iter = propertyModifiers_.find(RSModifierType::PERSP);
1405     if (iter == propertyModifiers_.end()) {
1406         SetPersp({0.f, perspY, 0.f, 1.f});
1407         return;
1408     }
1409 
1410     auto property = std::static_pointer_cast<RSAnimatableProperty<Vector4f>>(iter->second->GetProperty());
1411     if (property == nullptr) {
1412         return;
1413     }
1414     auto persp = property->Get();
1415     persp.y_ = perspY;
1416     property->Set(persp);
1417 }
1418 
SetPerspZ(float perspZ)1419 void RSNode::SetPerspZ(float perspZ)
1420 {
1421     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1422     auto iter = propertyModifiers_.find(RSModifierType::PERSP);
1423     if (iter == propertyModifiers_.end()) {
1424         SetPersp({0.f, 0.f, perspZ, 1.f});
1425         return;
1426     }
1427 
1428     auto property = std::static_pointer_cast<RSAnimatableProperty<Vector4f>>(iter->second->GetProperty());
1429     if (property == nullptr) {
1430         return;
1431     }
1432     auto persp = property->Get();
1433     persp.z_ = perspZ;
1434     property->Set(persp);
1435 }
1436 
SetPerspW(float perspW)1437 void RSNode::SetPerspW(float perspW)
1438 {
1439     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
1440     auto iter = propertyModifiers_.find(RSModifierType::PERSP);
1441     if (iter == propertyModifiers_.end()) {
1442         SetPersp({0.f, 0.f, 0.f, perspW});
1443         return;
1444     }
1445 
1446     auto property = std::static_pointer_cast<RSAnimatableProperty<Vector4f>>(iter->second->GetProperty());
1447     if (property == nullptr) {
1448         return;
1449     }
1450     auto persp = property->Get();
1451     persp.w_ = perspW;
1452     property->Set(persp);
1453 }
1454 
1455 // Set the foreground color of the control
SetEnvForegroundColor(uint32_t colorValue)1456 void RSNode::SetEnvForegroundColor(uint32_t colorValue)
1457 {
1458     auto color = Color::FromArgbInt(colorValue);
1459     SetProperty<RSEnvForegroundColorModifier, RSAnimatableProperty<Color>>(RSModifierType::ENV_FOREGROUND_COLOR, color);
1460 }
1461 
1462 // Set the foreground color strategy of the control
SetEnvForegroundColorStrategy(ForegroundColorStrategyType strategyType)1463 void RSNode::SetEnvForegroundColorStrategy(ForegroundColorStrategyType strategyType)
1464 {
1465     SetProperty<RSEnvForegroundColorStrategyModifier,
1466         RSProperty<ForegroundColorStrategyType>>(RSModifierType::ENV_FOREGROUND_COLOR_STRATEGY, strategyType);
1467 }
1468 
1469 // Set ParticleParams
SetParticleParams(std::vector<ParticleParams> & particleParams,const std::function<void ()> & finishCallback)1470 void RSNode::SetParticleParams(std::vector<ParticleParams>& particleParams, const std::function<void()>& finishCallback)
1471 {
1472     std::vector<std::shared_ptr<ParticleRenderParams>> particlesRenderParams;
1473     for (size_t i = 0; i < particleParams.size(); i++) {
1474         particlesRenderParams.push_back(particleParams[i].SetParamsToRenderParticle());
1475     }
1476 
1477     SetParticleDrawRegion(particleParams);
1478     auto property = std::make_shared<RSPropertyBase>();
1479     auto propertyId = property->GetId();
1480     auto uiAnimation = std::make_shared<RSAnimationGroup>();
1481     auto animationId = uiAnimation->GetId();
1482     AddAnimation(uiAnimation);
1483     if (finishCallback != nullptr) {
1484         uiAnimation->SetFinishCallback(std::make_shared<AnimationFinishCallback>(finishCallback));
1485     }
1486     auto animation =
1487         std::make_shared<RSRenderParticleAnimation>(animationId, propertyId, std::move(particlesRenderParams));
1488 
1489     std::unique_ptr<RSCommand> command = std::make_unique<RSAnimationCreateParticle>(GetId(), animation);
1490     AddCommand(command, IsRenderServiceNode(), GetFollowType(), GetId());
1491     if (NeedForcedSendToRemote()) {
1492         std::unique_ptr<RSCommand> cmdForRemote = std::make_unique<RSAnimationCreateParticle>(GetId(), animation);
1493         AddCommand(cmdForRemote, true, GetFollowType(), GetId());
1494     }
1495 }
1496 
SetParticleDrawRegion(std::vector<ParticleParams> & particleParams)1497 void RSNode::SetParticleDrawRegion(std::vector<ParticleParams>& particleParams)
1498 {
1499     Vector4f bounds = GetStagingProperties().GetBounds();
1500     float boundsRight = bounds.x_ + bounds.z_;
1501     float boundsBottom = bounds.y_ + bounds.w_;
1502     size_t emitterCount = particleParams.size();
1503     std::vector<float> left(emitterCount);
1504     std::vector<float> top(emitterCount);
1505     std::vector<float> right(emitterCount);
1506     std::vector<float> bottom(emitterCount);
1507     for (size_t i = 0; i < emitterCount; i++) {
1508         auto particleType = particleParams[i].emitterConfig_.type_;
1509         auto position = particleParams[i].emitterConfig_.position_;
1510         auto emitSize = particleParams[i].emitterConfig_.emitSize_;
1511         float scaleMax = particleParams[i].scale_.val_.end_;
1512         if (particleType == ParticleType::POINTS) {
1513             auto diameMax = particleParams[i].emitterConfig_.radius_ * 2 * scaleMax; // diameter = 2 * radius
1514             left[i] = std::min(bounds.x_ - diameMax, bounds.x_ + position.x_ - diameMax);
1515             top[i] = std::min(bounds.y_ - diameMax, bounds.y_ + position.y_ - diameMax);
1516             right[i] = std::max(boundsRight + diameMax + diameMax, position.x_ + emitSize.x_ + diameMax + diameMax);
1517             bottom[i] = std::max(boundsBottom + diameMax + diameMax, position.y_ + emitSize.y_ + diameMax + diameMax);
1518         } else {
1519             float imageSizeWidth = 0.f;
1520             float imageSizeHeight = 0.f;
1521             auto image = particleParams[i].emitterConfig_.image_;
1522             auto imageSize = particleParams[i].emitterConfig_.imageSize_;
1523             if (image == nullptr)
1524                 continue;
1525             auto pixelMap = image->GetPixelMap();
1526             if (pixelMap != nullptr) {
1527                 imageSizeWidth = std::max(imageSize.x_, static_cast<float>(pixelMap->GetWidth()));
1528                 imageSizeHeight = std::max(imageSize.y_, static_cast<float>(pixelMap->GetHeight()));
1529             }
1530             float imageSizeWidthMax = imageSizeWidth * scaleMax;
1531             float imageSizeHeightMax = imageSizeHeight * scaleMax;
1532             left[i] = std::min(bounds.x_ - imageSizeWidthMax, bounds.x_ + position.x_ - imageSizeWidthMax);
1533             top[i] = std::min(bounds.y_ - imageSizeHeightMax, bounds.y_ + position.y_ - imageSizeHeightMax);
1534             right[i] = std::max(boundsRight + imageSizeWidthMax + imageSizeWidthMax,
1535                 position.x_ + emitSize.x_ + imageSizeWidthMax + imageSizeWidthMax);
1536             bottom[i] = std::max(boundsBottom + imageSizeHeightMax + imageSizeHeightMax,
1537                 position.y_ + emitSize.y_ + imageSizeHeightMax + imageSizeHeightMax);
1538         }
1539     }
1540     if (emitterCount != 0) {
1541         float l = *std::min_element(left.begin(), left.end());
1542         float t = *std::min_element(top.begin(), top.end());
1543         boundsRight = *std::max_element(right.begin(), right.end());
1544         boundsBottom = *std::max_element(bottom.begin(), bottom.end());
1545         SetDrawRegion(std::make_shared<RectF>(l - bounds.x_, t - bounds.y_, boundsRight - l, boundsBottom - t));
1546     }
1547 }
1548 
1549 // Update Particle Emitter
SetEmitterUpdater(const std::vector<std::shared_ptr<EmitterUpdater>> & para)1550 void RSNode::SetEmitterUpdater(const std::vector<std::shared_ptr<EmitterUpdater>>& para)
1551 {
1552     SetProperty<RSEmitterUpdaterModifier, RSProperty<std::vector<std::shared_ptr<EmitterUpdater>>>>(
1553         RSModifierType::PARTICLE_EMITTER_UPDATER, para);
1554 }
1555 
1556 // Set Particle Noise Field
SetParticleNoiseFields(const std::shared_ptr<ParticleNoiseFields> & para)1557 void RSNode::SetParticleNoiseFields(const std::shared_ptr<ParticleNoiseFields>& para)
1558 {
1559     SetProperty<RSParticleNoiseFieldsModifier, RSProperty<std::shared_ptr<ParticleNoiseFields>>>(
1560         RSModifierType::PARTICLE_NOISE_FIELD, para);
1561 }
1562 
1563 // foreground
SetForegroundColor(uint32_t colorValue)1564 void RSNode::SetForegroundColor(uint32_t colorValue)
1565 {
1566     auto color = Color::FromArgbInt(colorValue);
1567     SetProperty<RSForegroundColorModifier, RSAnimatableProperty<Color>>(RSModifierType::FOREGROUND_COLOR, color);
1568 }
1569 
SetBackgroundColor(uint32_t colorValue)1570 void RSNode::SetBackgroundColor(uint32_t colorValue)
1571 {
1572     auto color = Color::FromArgbInt(colorValue);
1573     SetProperty<RSBackgroundColorModifier, RSAnimatableProperty<Color>>(RSModifierType::BACKGROUND_COLOR, color);
1574     if (color.GetAlpha() > 0) {
1575         SetDrawNode();
1576     }
1577 }
1578 
SetBackgroundShader(const std::shared_ptr<RSShader> & shader)1579 void RSNode::SetBackgroundShader(const std::shared_ptr<RSShader>& shader)
1580 {
1581     SetProperty<RSBackgroundShaderModifier, RSProperty<std::shared_ptr<RSShader>>>(
1582         RSModifierType::BACKGROUND_SHADER, shader);
1583 }
1584 
SetBackgroundShaderProgress(const float & progress)1585 void RSNode::SetBackgroundShaderProgress(const float& progress)
1586 {
1587     SetProperty<RSBackgroundShaderProgressModifier, RSAnimatableProperty<float>>(
1588         RSModifierType::BACKGROUND_SHADER_PROGRESS, progress);
1589 }
1590 
1591 // background
SetBgImage(const std::shared_ptr<RSImage> & image)1592 void RSNode::SetBgImage(const std::shared_ptr<RSImage>& image)
1593 {
1594     if (image) {
1595         image->SetNodeId(GetId());
1596     }
1597     SetProperty<RSBgImageModifier, RSProperty<std::shared_ptr<RSImage>>>(RSModifierType::BG_IMAGE, image);
1598 }
1599 
SetBgImageInnerRect(const Vector4f & rect)1600 void RSNode::SetBgImageInnerRect(const Vector4f& rect)
1601 {
1602     SetProperty<RSBgImageInnerRectModifier, RSAnimatableProperty<Vector4f>>(
1603         RSModifierType::BG_IMAGE_INNER_RECT, rect);
1604 }
1605 
SetBgImageSize(float width,float height)1606 void RSNode::SetBgImageSize(float width, float height)
1607 {
1608     SetBgImageWidth(width);
1609     SetBgImageHeight(height);
1610 }
1611 
SetBgImageWidth(float width)1612 void RSNode::SetBgImageWidth(float width)
1613 {
1614     SetProperty<RSBgImageWidthModifier, RSAnimatableProperty<float>>(RSModifierType::BG_IMAGE_WIDTH, width);
1615 }
1616 
SetBgImageHeight(float height)1617 void RSNode::SetBgImageHeight(float height)
1618 {
1619     SetProperty<RSBgImageHeightModifier, RSAnimatableProperty<float>>(RSModifierType::BG_IMAGE_HEIGHT, height);
1620 }
1621 
SetBgImagePosition(float positionX,float positionY)1622 void RSNode::SetBgImagePosition(float positionX, float positionY)
1623 {
1624     SetBgImagePositionX(positionX);
1625     SetBgImagePositionY(positionY);
1626 }
1627 
SetBgImagePositionX(float positionX)1628 void RSNode::SetBgImagePositionX(float positionX)
1629 {
1630     SetProperty<RSBgImagePositionXModifier, RSAnimatableProperty<float>>(
1631         RSModifierType::BG_IMAGE_POSITION_X, positionX);
1632 }
1633 
SetBgImagePositionY(float positionY)1634 void RSNode::SetBgImagePositionY(float positionY)
1635 {
1636     SetProperty<RSBgImagePositionYModifier, RSAnimatableProperty<float>>(
1637         RSModifierType::BG_IMAGE_POSITION_Y, positionY);
1638 }
1639 
1640 // set inner border color
SetBorderColor(uint32_t colorValue)1641 void RSNode::SetBorderColor(uint32_t colorValue)
1642 {
1643     SetBorderColor(colorValue, colorValue, colorValue, colorValue);
1644 }
1645 
1646 // set inner border color
SetBorderColor(uint32_t left,uint32_t top,uint32_t right,uint32_t bottom)1647 void RSNode::SetBorderColor(uint32_t left, uint32_t top, uint32_t right, uint32_t bottom)
1648 {
1649     Vector4<Color> color(Color::FromArgbInt(left), Color::FromArgbInt(top),
1650                          Color::FromArgbInt(right), Color::FromArgbInt(bottom));
1651     SetBorderColor(color);
1652 }
1653 
1654 // set inner border color
SetBorderColor(const Vector4<Color> & color)1655 void RSNode::SetBorderColor(const Vector4<Color>& color)
1656 {
1657     SetProperty<RSBorderColorModifier, RSAnimatableProperty<Vector4<Color>>>(RSModifierType::BORDER_COLOR, color);
1658 }
1659 
1660 // set inner border width
SetBorderWidth(float width)1661 void RSNode::SetBorderWidth(float width)
1662 {
1663     SetBorderWidth(width, width, width, width);
1664 }
1665 
1666 // set inner border width
SetBorderWidth(float left,float top,float right,float bottom)1667 void RSNode::SetBorderWidth(float left, float top, float right, float bottom)
1668 {
1669     Vector4f width(left, top, right, bottom);
1670     SetBorderWidth(width);
1671 }
1672 
1673 // set inner border width
SetBorderWidth(const Vector4f & width)1674 void RSNode::SetBorderWidth(const Vector4f& width)
1675 {
1676     SetProperty<RSBorderWidthModifier, RSAnimatableProperty<Vector4f>>(RSModifierType::BORDER_WIDTH, width);
1677 }
1678 
1679 // set inner border style
SetBorderStyle(uint32_t styleValue)1680 void RSNode::SetBorderStyle(uint32_t styleValue)
1681 {
1682     SetBorderStyle(styleValue, styleValue, styleValue, styleValue);
1683 }
1684 
1685 // set inner border style
SetBorderStyle(uint32_t left,uint32_t top,uint32_t right,uint32_t bottom)1686 void RSNode::SetBorderStyle(uint32_t left, uint32_t top, uint32_t right, uint32_t bottom)
1687 {
1688     Vector4<BorderStyle> style(static_cast<BorderStyle>(left), static_cast<BorderStyle>(top),
1689                                static_cast<BorderStyle>(right), static_cast<BorderStyle>(bottom));
1690     SetBorderStyle(style);
1691 }
1692 
1693 // set inner border style
SetBorderStyle(const Vector4<BorderStyle> & style)1694 void RSNode::SetBorderStyle(const Vector4<BorderStyle>& style)
1695 {
1696     Vector4<uint32_t> styles(static_cast<uint32_t>(style.x_), static_cast<uint32_t>(style.y_),
1697                              static_cast<uint32_t>(style.z_), static_cast<uint32_t>(style.w_));
1698     SetProperty<RSBorderStyleModifier, RSProperty<Vector4<uint32_t>>>(RSModifierType::BORDER_STYLE, styles);
1699 }
1700 
1701 // set dash width for border
SetBorderDashWidth(const Vector4f & dashWidth)1702 void RSNode::SetBorderDashWidth(const Vector4f& dashWidth)
1703 {
1704     SetProperty<RSBorderDashWidthModifier, RSProperty<Vector4f>>(
1705         RSModifierType::BORDER_DASH_WIDTH, dashWidth);
1706 }
1707 
1708 // set dash gap for border
SetBorderDashGap(const Vector4f & dashGap)1709 void RSNode::SetBorderDashGap(const Vector4f& dashGap)
1710 {
1711     SetProperty<RSBorderDashGapModifier, RSProperty<Vector4f>>(
1712         RSModifierType::BORDER_DASH_GAP, dashGap);
1713 }
1714 
SetOuterBorderColor(const Vector4<Color> & color)1715 void RSNode::SetOuterBorderColor(const Vector4<Color>& color)
1716 {
1717     SetOutlineColor(color);
1718 }
1719 
SetOuterBorderWidth(const Vector4f & width)1720 void RSNode::SetOuterBorderWidth(const Vector4f& width)
1721 {
1722     SetOutlineWidth(width);
1723 }
1724 
SetOuterBorderStyle(const Vector4<BorderStyle> & style)1725 void RSNode::SetOuterBorderStyle(const Vector4<BorderStyle>& style)
1726 {
1727     SetOutlineStyle(style);
1728 }
1729 
SetOuterBorderRadius(const Vector4f & radius)1730 void RSNode::SetOuterBorderRadius(const Vector4f& radius)
1731 {
1732     SetOutlineRadius(radius);
1733 }
1734 
SetOutlineColor(const Vector4<Color> & color)1735 void RSNode::SetOutlineColor(const Vector4<Color>& color)
1736 {
1737     SetProperty<RSOutlineColorModifier, RSAnimatableProperty<Vector4<Color>>>(
1738         RSModifierType::OUTLINE_COLOR, color);
1739 }
1740 
SetOutlineWidth(const Vector4f & width)1741 void RSNode::SetOutlineWidth(const Vector4f& width)
1742 {
1743     SetProperty<RSOutlineWidthModifier, RSAnimatableProperty<Vector4f>>(
1744         RSModifierType::OUTLINE_WIDTH, width);
1745 }
1746 
SetOutlineStyle(const Vector4<BorderStyle> & style)1747 void RSNode::SetOutlineStyle(const Vector4<BorderStyle>& style)
1748 {
1749     Vector4<uint32_t> styles(static_cast<uint32_t>(style.x_), static_cast<uint32_t>(style.y_),
1750                              static_cast<uint32_t>(style.z_), static_cast<uint32_t>(style.w_));
1751     SetProperty<RSOutlineStyleModifier, RSProperty<Vector4<uint32_t>>>(
1752         RSModifierType::OUTLINE_STYLE, styles);
1753 }
1754 
SetOutlineDashWidth(const Vector4f & dashWidth)1755 void RSNode::SetOutlineDashWidth(const Vector4f& dashWidth)
1756 {
1757     SetProperty<RSOutlineDashWidthModifier, RSAnimatableProperty<Vector4f>>(
1758         RSModifierType::OUTLINE_DASH_WIDTH, dashWidth);
1759 }
1760 
SetOutlineDashGap(const Vector4f & dashGap)1761 void RSNode::SetOutlineDashGap(const Vector4f& dashGap)
1762 {
1763     SetProperty<RSOutlineDashGapModifier, RSAnimatableProperty<Vector4f>>(
1764         RSModifierType::OUTLINE_DASH_GAP, dashGap);
1765 }
1766 
SetOutlineRadius(const Vector4f & radius)1767 void RSNode::SetOutlineRadius(const Vector4f& radius)
1768 {
1769     SetProperty<RSOutlineRadiusModifier, RSAnimatableProperty<Vector4f>>(
1770         RSModifierType::OUTLINE_RADIUS, radius);
1771 }
1772 
SetUIBackgroundFilter(const OHOS::Rosen::Filter * backgroundFilter)1773 void RSNode::SetUIBackgroundFilter(const OHOS::Rosen::Filter* backgroundFilter)
1774 {
1775     if (backgroundFilter == nullptr) {
1776         ROSEN_LOGE("Failed to set backgroundFilter, backgroundFilter is null!");
1777         return;
1778     }
1779     // To do: generate composed filter here. Now we just set background blur in v1.0.
1780     auto filterParas = backgroundFilter->GetAllPara();
1781     for (const auto& filterPara : filterParas) {
1782         if (filterPara->GetParaType() == FilterPara::BLUR) {
1783             auto filterBlurPara = std::static_pointer_cast<FilterBlurPara>(filterPara);
1784             auto blurRadius = filterBlurPara->GetRadius();
1785             SetBackgroundBlurRadiusX(blurRadius);
1786             SetBackgroundBlurRadiusY(blurRadius);
1787         }
1788         if (filterPara->GetParaType() == FilterPara::WATER_RIPPLE) {
1789             auto waterRipplePara = std::static_pointer_cast<WaterRipplePara>(filterPara);
1790             auto waveCount = waterRipplePara->GetWaveCount();
1791             auto rippleCenterX = waterRipplePara->GetRippleCenterX();
1792             auto rippleCenterY = waterRipplePara->GetRippleCenterY();
1793             auto progress = waterRipplePara->GetProgress();
1794             auto rippleMode = waterRipplePara->GetRippleMode();
1795             RSWaterRipplePara params = {
1796                 waveCount,
1797                 rippleCenterX,
1798                 rippleCenterY,
1799                 rippleMode
1800             };
1801             SetWaterRippleParams(params, progress);
1802         }
1803     }
1804 }
1805 
SetUICompositingFilter(const OHOS::Rosen::Filter * compositingFilter)1806 void RSNode::SetUICompositingFilter(const OHOS::Rosen::Filter* compositingFilter)
1807 {
1808     if (compositingFilter == nullptr) {
1809         ROSEN_LOGE("Failed to set compositingFilter, compositingFilter is null!");
1810         return;
1811     }
1812     // To do: generate composed filter here. Now we just set compositing blur in v1.0.
1813     auto filterParas = compositingFilter->GetAllPara();
1814     for (const auto& filterPara : filterParas) {
1815         if (filterPara->GetParaType() == FilterPara::BLUR) {
1816             auto filterBlurPara = std::static_pointer_cast<FilterBlurPara>(filterPara);
1817             auto blurRadius = filterBlurPara->GetRadius();
1818             SetForegroundBlurRadiusX(blurRadius);
1819             SetForegroundBlurRadiusY(blurRadius);
1820         }
1821         if (filterPara->GetParaType() == FilterPara::PIXEL_STRETCH) {
1822             auto pixelStretchPara = std::static_pointer_cast<PixelStretchPara>(filterPara);
1823             auto stretchPercent = pixelStretchPara->GetStretchPercent();
1824             SetPixelStretchPercent(stretchPercent, pixelStretchPara->GetTileMode());
1825         }
1826     }
1827 }
1828 
SetUIForegroundFilter(const OHOS::Rosen::Filter * foregroundFilter)1829 void RSNode::SetUIForegroundFilter(const OHOS::Rosen::Filter* foregroundFilter)
1830 {
1831     if (foregroundFilter == nullptr) {
1832         ROSEN_LOGE("Failed to set foregroundFilter, foregroundFilter is null!");
1833         return;
1834     }
1835     // To do: generate composed filter here. Now we just set pixel stretch in v1.0.
1836     auto filterParas = foregroundFilter->GetAllPara();
1837     for (const auto& filterPara : filterParas) {
1838         if (filterPara->GetParaType() == FilterPara::BLUR) {
1839             auto filterBlurPara = std::static_pointer_cast<FilterBlurPara>(filterPara);
1840             auto blurRadius = filterBlurPara->GetRadius();
1841             SetForegroundEffectRadius(blurRadius);
1842         }
1843         if (filterPara->GetParaType() == FilterPara::FLY_OUT) {
1844             auto flyOutPara = std::static_pointer_cast<FlyOutPara>(filterPara);
1845             auto flyMode = flyOutPara->GetFlyMode();
1846             auto degree = flyOutPara->GetDegree();
1847             RSFlyOutPara rs_fly_out_param = {
1848                 flyMode,
1849             };
1850             SetFlyOutParams(rs_fly_out_param, degree);
1851         }
1852         if (filterPara->GetParaType() == FilterPara::DISTORT) {
1853             auto distortPara = std::static_pointer_cast<DistortPara>(filterPara);
1854             auto distortionK = distortPara->GetDistortionK();
1855             SetDistortionK(distortionK);
1856         }
1857     }
1858 }
1859 
SetVisualEffect(const VisualEffect * visualEffect)1860 void RSNode::SetVisualEffect(const VisualEffect* visualEffect)
1861 {
1862     if (visualEffect == nullptr) {
1863         ROSEN_LOGE("Failed to set visualEffect, visualEffect is null!");
1864         return;
1865     }
1866     // To do: generate composed visual effect here. Now we just set background brightness in v1.0.
1867     auto visualEffectParas = visualEffect->GetAllPara();
1868     for (const auto& visualEffectPara : visualEffectParas) {
1869         if (visualEffectPara->GetParaType() != VisualEffectPara::BACKGROUND_COLOR_EFFECT) {
1870             continue;
1871         }
1872         auto backgroundColorEffectPara = std::static_pointer_cast<BackgroundColorEffectPara>(visualEffectPara);
1873         auto blender = backgroundColorEffectPara->GetBlender();
1874         auto brightnessBlender = std::static_pointer_cast<BrightnessBlender>(blender);
1875         if (brightnessBlender == nullptr) {
1876             continue;
1877         }
1878         auto fraction = brightnessBlender->GetFraction();
1879         SetBgBrightnessFract(fraction);
1880         SetBgBrightnessParams({ brightnessBlender->GetLinearRate(), brightnessBlender->GetDegree(),
1881             brightnessBlender->GetCubicRate(), brightnessBlender->GetQuadRate(), brightnessBlender->GetSaturation(),
1882             { brightnessBlender->GetPositiveCoeff().data_[0], brightnessBlender->GetPositiveCoeff().data_[1],
1883                 brightnessBlender->GetPositiveCoeff().data_[2] },
1884             { brightnessBlender->GetNegativeCoeff().data_[0], brightnessBlender->GetNegativeCoeff().data_[1],
1885                 brightnessBlender->GetNegativeCoeff().data_[2] } });
1886     }
1887 }
1888 
SetBlender(const Blender * blender)1889 void RSNode::SetBlender(const Blender* blender)
1890 {
1891     if (blender == nullptr) {
1892         ROSEN_LOGE("RSNode::SetBlender: blender is null!");
1893         return;
1894     }
1895 
1896     if (Blender::BRIGHTNESS_BLENDER == blender->GetBlenderType()) {
1897         auto brightnessBlender = static_cast<const BrightnessBlender*>(blender);
1898         if (brightnessBlender != nullptr) {
1899             SetFgBrightnessFract(brightnessBlender->GetFraction());
1900             SetFgBrightnessParams({ brightnessBlender->GetLinearRate(), brightnessBlender->GetDegree(),
1901                 brightnessBlender->GetCubicRate(), brightnessBlender->GetQuadRate(), brightnessBlender->GetSaturation(),
1902                 { brightnessBlender->GetPositiveCoeff().x_, brightnessBlender->GetPositiveCoeff().y_,
1903                     brightnessBlender->GetPositiveCoeff().z_ },
1904                 { brightnessBlender->GetNegativeCoeff().x_, brightnessBlender->GetNegativeCoeff().y_,
1905                     brightnessBlender->GetNegativeCoeff().z_ } });
1906         }
1907     }
1908 }
1909 
SetForegroundEffectRadius(const float blurRadius)1910 void RSNode::SetForegroundEffectRadius(const float blurRadius)
1911 {
1912     SetProperty<RSForegroundEffectRadiusModifier, RSAnimatableProperty<float>>(
1913         RSModifierType::FOREGROUND_EFFECT_RADIUS, blurRadius);
1914 }
1915 
SetForegroundEffectDisableSystemAdaptation(bool disableSystemAdaptation)1916 void RSNode::SetForegroundEffectDisableSystemAdaptation(bool disableSystemAdaptation)
1917 {
1918     return;
1919 }
1920 
SetBackgroundFilter(const std::shared_ptr<RSFilter> & backgroundFilter)1921 void RSNode::SetBackgroundFilter(const std::shared_ptr<RSFilter>& backgroundFilter)
1922 {
1923     if (backgroundFilter == nullptr) {
1924         SetBackgroundBlurRadius(0.f);
1925         SetBackgroundBlurSaturation(1.f);
1926         SetBackgroundBlurBrightness(1.f);
1927         SetBackgroundBlurMaskColor(RSColor());
1928         SetBackgroundBlurColorMode(BLUR_COLOR_MODE::DEFAULT);
1929         SetBackgroundBlurRadiusX(0.f);
1930         SetBackgroundBlurRadiusY(0.f);
1931     } else if (backgroundFilter->GetFilterType() == RSFilter::MATERIAL) {
1932         auto materialFilter = std::static_pointer_cast<RSMaterialFilter>(backgroundFilter);
1933         float Radius = materialFilter->GetRadius();
1934         float Saturation = materialFilter->GetSaturation();
1935         float Brightness = materialFilter->GetBrightness();
1936         Color MaskColor = materialFilter->GetMaskColor();
1937         int ColorMode = materialFilter->GetColorMode();
1938         SetBackgroundBlurRadius(Radius);
1939         SetBackgroundBlurSaturation(Saturation);
1940         SetBackgroundBlurBrightness(Brightness);
1941         SetBackgroundBlurMaskColor(MaskColor);
1942         SetBackgroundBlurColorMode(ColorMode);
1943     } else if (backgroundFilter->GetFilterType() == RSFilter::BLUR) {
1944         auto blurFilter = std::static_pointer_cast<RSBlurFilter>(backgroundFilter);
1945         float blurRadiusX = blurFilter->GetBlurRadiusX();
1946         float blurRadiusY = blurFilter->GetBlurRadiusY();
1947         SetBackgroundBlurRadiusX(blurRadiusX);
1948         SetBackgroundBlurRadiusY(blurRadiusY);
1949     }
1950 }
1951 
SetFilter(const std::shared_ptr<RSFilter> & filter)1952 void RSNode::SetFilter(const std::shared_ptr<RSFilter>& filter)
1953 {
1954     if (filter == nullptr) {
1955         SetForegroundBlurRadius(0.f);
1956         SetForegroundBlurSaturation(1.f);
1957         SetForegroundBlurBrightness(1.f);
1958         SetForegroundBlurMaskColor(RSColor());
1959         SetForegroundBlurColorMode(BLUR_COLOR_MODE::DEFAULT);
1960         SetForegroundBlurRadiusX(0.f);
1961         SetForegroundBlurRadiusY(0.f);
1962     } else if (filter->GetFilterType() == RSFilter::MATERIAL) {
1963         auto materialFilter = std::static_pointer_cast<RSMaterialFilter>(filter);
1964         float Radius = materialFilter->GetRadius();
1965         float Saturation = materialFilter->GetSaturation();
1966         float Brightness = materialFilter->GetBrightness();
1967         Color MaskColor = materialFilter->GetMaskColor();
1968         int ColorMode = materialFilter->GetColorMode();
1969         SetForegroundBlurRadius(Radius);
1970         SetForegroundBlurSaturation(Saturation);
1971         SetForegroundBlurBrightness(Brightness);
1972         SetForegroundBlurMaskColor(MaskColor);
1973         SetForegroundBlurColorMode(ColorMode);
1974     } else if (filter->GetFilterType() == RSFilter::BLUR) {
1975         auto blurFilter = std::static_pointer_cast<RSBlurFilter>(filter);
1976         float blurRadiusX = blurFilter->GetBlurRadiusX();
1977         float blurRadiusY = blurFilter->GetBlurRadiusY();
1978         SetForegroundBlurRadiusX(blurRadiusX);
1979         SetForegroundBlurRadiusY(blurRadiusY);
1980     }
1981 }
1982 
SetLinearGradientBlurPara(const std::shared_ptr<RSLinearGradientBlurPara> & para)1983 void RSNode::SetLinearGradientBlurPara(const std::shared_ptr<RSLinearGradientBlurPara>& para)
1984 {
1985     SetProperty<RSLinearGradientBlurParaModifier, RSProperty<std::shared_ptr<RSLinearGradientBlurPara>>>(
1986         RSModifierType::LINEAR_GRADIENT_BLUR_PARA, para);
1987 }
1988 
SetMotionBlurPara(const float radius,const Vector2f & anchor)1989 void RSNode::SetMotionBlurPara(const float radius, const Vector2f& anchor)
1990 {
1991     Vector2f anchor1 = {anchor[0], anchor[1]};
1992     std::shared_ptr<MotionBlurParam> para = std::make_shared<MotionBlurParam>(radius, anchor1);
1993     SetProperty<RSMotionBlurParaModifier, RSProperty<std::shared_ptr<MotionBlurParam>>>(
1994         RSModifierType::MOTION_BLUR_PARA, para);
1995 }
1996 
SetDynamicLightUpRate(const float rate)1997 void RSNode::SetDynamicLightUpRate(const float rate)
1998 {
1999     SetProperty<RSDynamicLightUpRateModifier, RSAnimatableProperty<float>>(RSModifierType::DYNAMIC_LIGHT_UP_RATE, rate);
2000 }
2001 
SetDynamicLightUpDegree(const float lightUpDegree)2002 void RSNode::SetDynamicLightUpDegree(const float lightUpDegree)
2003 {
2004     SetProperty<RSDynamicLightUpDegreeModifier,
2005         RSAnimatableProperty<float>>(RSModifierType::DYNAMIC_LIGHT_UP_DEGREE, lightUpDegree);
2006 }
2007 
SetFgBrightnessParams(const RSDynamicBrightnessPara & params)2008 void RSNode::SetFgBrightnessParams(const RSDynamicBrightnessPara& params)
2009 {
2010     // Compatible with original interfaces
2011     SetFgBrightnessRates(params.rates_);
2012     SetFgBrightnessSaturation(params.saturation_);
2013     SetFgBrightnessPosCoeff(params.posCoeff_);
2014     SetFgBrightnessNegCoeff(params.negCoeff_);
2015 }
2016 
SetFgBrightnessRates(const Vector4f & rates)2017 void RSNode::SetFgBrightnessRates(const Vector4f& rates)
2018 {
2019     SetProperty<RSFgBrightnessRatesModifier,
2020         RSAnimatableProperty<Vector4f>>(RSModifierType::FG_BRIGHTNESS_RATES, rates);
2021 }
2022 
SetFgBrightnessSaturation(const float & saturation)2023 void RSNode::SetFgBrightnessSaturation(const float& saturation)
2024 {
2025     SetProperty<RSFgBrightnessSaturationModifier,
2026         RSAnimatableProperty<float>>(RSModifierType::FG_BRIGHTNESS_SATURATION, saturation);
2027 }
2028 
SetFgBrightnessPosCoeff(const Vector4f & coeff)2029 void RSNode::SetFgBrightnessPosCoeff(const Vector4f& coeff)
2030 {
2031     SetProperty<RSFgBrightnessPosCoeffModifier,
2032         RSAnimatableProperty<Vector4f>>(RSModifierType::FG_BRIGHTNESS_POSCOEFF, coeff);
2033 }
2034 
SetFgBrightnessNegCoeff(const Vector4f & coeff)2035 void RSNode::SetFgBrightnessNegCoeff(const Vector4f& coeff)
2036 {
2037     SetProperty<RSFgBrightnessNegCoeffModifier,
2038         RSAnimatableProperty<Vector4f>>(RSModifierType::FG_BRIGHTNESS_NEGCOEFF, coeff);
2039 }
2040 
SetFgBrightnessFract(const float & fract)2041 void RSNode::SetFgBrightnessFract(const float& fract)
2042 {
2043     SetProperty<RSFgBrightnessFractModifier,
2044         RSAnimatableProperty<float>>(RSModifierType::FG_BRIGHTNESS_FRACTION, fract);
2045 }
2046 
SetBgBrightnessParams(const RSDynamicBrightnessPara & params)2047 void RSNode::SetBgBrightnessParams(const RSDynamicBrightnessPara& params)
2048 {
2049     ROSEN_LOGE("LJQDEBUG: params.saturation_ %{public}f", params.saturation_);
2050     // Compatible with original interfaces
2051     SetBgBrightnessRates(params.rates_);
2052     SetBgBrightnessSaturation(params.saturation_);
2053     SetBgBrightnessPosCoeff(params.posCoeff_);
2054     SetBgBrightnessNegCoeff(params.negCoeff_);
2055 }
2056 
SetBgBrightnessRates(const Vector4f & rates)2057 void RSNode::SetBgBrightnessRates(const Vector4f& rates)
2058 {
2059     SetProperty<RSBgBrightnessRatesModifier,
2060         RSAnimatableProperty<Vector4f>>(RSModifierType::BG_BRIGHTNESS_RATES, rates);
2061 }
2062 
SetBgBrightnessSaturation(const float & saturation)2063 void RSNode::SetBgBrightnessSaturation(const float& saturation)
2064 {
2065     SetProperty<RSBgBrightnessSaturationModifier,
2066         RSAnimatableProperty<float>>(RSModifierType::BG_BRIGHTNESS_SATURATION, saturation);
2067 }
2068 
SetBgBrightnessPosCoeff(const Vector4f & coeff)2069 void RSNode::SetBgBrightnessPosCoeff(const Vector4f& coeff)
2070 {
2071     SetProperty<RSBgBrightnessPosCoeffModifier,
2072         RSAnimatableProperty<Vector4f>>(RSModifierType::BG_BRIGHTNESS_POSCOEFF, coeff);
2073 }
2074 
SetBgBrightnessNegCoeff(const Vector4f & coeff)2075 void RSNode::SetBgBrightnessNegCoeff(const Vector4f& coeff)
2076 {
2077     SetProperty<RSBgBrightnessNegCoeffModifier,
2078         RSAnimatableProperty<Vector4f>>(RSModifierType::BG_BRIGHTNESS_NEGCOEFF, coeff);
2079 }
2080 
SetBgBrightnessFract(const float & fract)2081 void RSNode::SetBgBrightnessFract(const float& fract)
2082 {
2083     SetProperty<RSBgBrightnessFractModifier,
2084         RSAnimatableProperty<float>>(RSModifierType::BG_BRIGHTNESS_FRACTION, fract);
2085 }
2086 
SetDynamicDimDegree(const float dimDegree)2087 void RSNode::SetDynamicDimDegree(const float dimDegree)
2088 {
2089     SetProperty<RSDynamicDimDegreeModifier,
2090         RSAnimatableProperty<float>>(RSModifierType::DYNAMIC_DIM_DEGREE, dimDegree);
2091 }
2092 
SetGreyCoef(const Vector2f greyCoef)2093 void RSNode::SetGreyCoef(const Vector2f greyCoef)
2094 {
2095     SetProperty<RSGreyCoefModifier, RSAnimatableProperty<Vector2f>>(RSModifierType::GREY_COEF, greyCoef);
2096 }
2097 
SetCompositingFilter(const std::shared_ptr<RSFilter> & compositingFilter)2098 void RSNode::SetCompositingFilter(const std::shared_ptr<RSFilter>& compositingFilter) {}
2099 
SetShadowColor(uint32_t colorValue)2100 void RSNode::SetShadowColor(uint32_t colorValue)
2101 {
2102     auto color = Color::FromArgbInt(colorValue);
2103     SetProperty<RSShadowColorModifier, RSAnimatableProperty<Color>>(RSModifierType::SHADOW_COLOR, color);
2104 }
2105 
SetShadowOffset(float offsetX,float offsetY)2106 void RSNode::SetShadowOffset(float offsetX, float offsetY)
2107 {
2108     SetShadowOffsetX(offsetX);
2109     SetShadowOffsetY(offsetY);
2110 }
2111 
SetShadowOffsetX(float offsetX)2112 void RSNode::SetShadowOffsetX(float offsetX)
2113 {
2114     SetProperty<RSShadowOffsetXModifier, RSAnimatableProperty<float>>(RSModifierType::SHADOW_OFFSET_X, offsetX);
2115 }
2116 
SetShadowOffsetY(float offsetY)2117 void RSNode::SetShadowOffsetY(float offsetY)
2118 {
2119     SetProperty<RSShadowOffsetYModifier, RSAnimatableProperty<float>>(RSModifierType::SHADOW_OFFSET_Y, offsetY);
2120 }
2121 
SetShadowAlpha(float alpha)2122 void RSNode::SetShadowAlpha(float alpha)
2123 {
2124     SetProperty<RSShadowAlphaModifier, RSAnimatableProperty<float>>(RSModifierType::SHADOW_ALPHA, alpha);
2125 }
2126 
SetShadowElevation(float elevation)2127 void RSNode::SetShadowElevation(float elevation)
2128 {
2129     SetProperty<RSShadowRadiusModifier, RSAnimatableProperty<float>>(RSModifierType::SHADOW_RADIUS, 0);
2130     SetProperty<RSShadowElevationModifier, RSAnimatableProperty<float>>(RSModifierType::SHADOW_ELEVATION, elevation);
2131 }
2132 
SetShadowRadius(float radius)2133 void RSNode::SetShadowRadius(float radius)
2134 {
2135     SetProperty<RSShadowElevationModifier, RSAnimatableProperty<float>>(RSModifierType::SHADOW_ELEVATION, 0);
2136     SetProperty<RSShadowRadiusModifier, RSAnimatableProperty<float>>(RSModifierType::SHADOW_RADIUS, radius);
2137 }
2138 
SetShadowPath(const std::shared_ptr<RSPath> & shadowPath)2139 void RSNode::SetShadowPath(const std::shared_ptr<RSPath>& shadowPath)
2140 {
2141     SetProperty<RSShadowPathModifier, RSProperty<std::shared_ptr<RSPath>>>(RSModifierType::SHADOW_PATH, shadowPath);
2142 }
2143 
SetShadowMask(bool shadowMask)2144 void RSNode::SetShadowMask(bool shadowMask)
2145 {
2146     SetProperty<RSShadowMaskModifier, RSProperty<bool>>(RSModifierType::SHADOW_MASK, shadowMask);
2147 }
2148 
SetShadowIsFilled(bool shadowIsFilled)2149 void RSNode::SetShadowIsFilled(bool shadowIsFilled)
2150 {
2151     SetProperty<RSShadowIsFilledModifier, RSProperty<bool>>(RSModifierType::SHADOW_IS_FILLED, shadowIsFilled);
2152 }
2153 
SetShadowColorStrategy(int shadowColorStrategy)2154 void RSNode::SetShadowColorStrategy(int shadowColorStrategy)
2155 {
2156     SetProperty<RSShadowColorStrategyModifier, RSProperty<int>>(
2157         RSModifierType::SHADOW_COLOR_STRATEGY, shadowColorStrategy);
2158 }
2159 
SetFrameGravity(Gravity gravity)2160 void RSNode::SetFrameGravity(Gravity gravity)
2161 {
2162     ROSEN_LOGD("RSNode::SetFrameGravity, gravity = %{public}d", gravity);
2163     SetProperty<RSFrameGravityModifier, RSProperty<Gravity>>(RSModifierType::FRAME_GRAVITY, gravity);
2164 }
2165 
SetClipRRect(const Vector4f & clipRect,const Vector4f & clipRadius)2166 void RSNode::SetClipRRect(const Vector4f& clipRect, const Vector4f& clipRadius)
2167 {
2168     SetClipRRect(std::make_shared<RRect>(clipRect, clipRadius));
2169 }
2170 
SetClipRRect(const std::shared_ptr<RRect> & rrect)2171 void RSNode::SetClipRRect(const std::shared_ptr<RRect>& rrect)
2172 {
2173     SetProperty<RSClipRRectModifier, RSAnimatableProperty<RRect>>(
2174         RSModifierType::CLIP_RRECT, rrect ? *rrect : RRect());
2175 }
2176 
SetClipBounds(const std::shared_ptr<RSPath> & path)2177 void RSNode::SetClipBounds(const std::shared_ptr<RSPath>& path)
2178 {
2179     SetProperty<RSClipBoundsModifier, RSProperty<std::shared_ptr<RSPath>>>(RSModifierType::CLIP_BOUNDS, path);
2180 }
2181 
SetClipToBounds(bool clipToBounds)2182 void RSNode::SetClipToBounds(bool clipToBounds)
2183 {
2184     SetProperty<RSClipToBoundsModifier, RSProperty<bool>>(RSModifierType::CLIP_TO_BOUNDS, clipToBounds);
2185 }
2186 
SetClipToFrame(bool clipToFrame)2187 void RSNode::SetClipToFrame(bool clipToFrame)
2188 {
2189     SetProperty<RSClipToFrameModifier, RSProperty<bool>>(RSModifierType::CLIP_TO_FRAME, clipToFrame);
2190 }
2191 
SetCustomClipToFrame(const Vector4f & clipRect)2192 void RSNode::SetCustomClipToFrame(const Vector4f& clipRect)
2193 {
2194     SetProperty<RSCustomClipToFrameModifier, RSAnimatableProperty<Vector4f>>(
2195         RSModifierType::CUSTOM_CLIP_TO_FRAME, clipRect);
2196 }
2197 
SetHDRBrightness(const float & hdrBrightness)2198 void RSNode::SetHDRBrightness(const float& hdrBrightness)
2199 {
2200     SetProperty<RSHDRBrightnessModifier, RSAnimatableProperty<float>>(
2201         RSModifierType::HDR_BRIGHTNESS, hdrBrightness);
2202 }
2203 
SetVisible(bool visible)2204 void RSNode::SetVisible(bool visible)
2205 {
2206     // kick off transition only if it's on tree(has valid parent) and visibility is changed.
2207     if (transitionEffect_ != nullptr && GetParent() != nullptr && visible != GetStagingProperties().GetVisible()) {
2208         NotifyTransition(transitionEffect_, visible);
2209     }
2210 
2211     SetProperty<RSVisibleModifier, RSProperty<bool>>(RSModifierType::VISIBLE, visible);
2212 }
2213 
SetMask(const std::shared_ptr<RSMask> & mask)2214 void RSNode::SetMask(const std::shared_ptr<RSMask>& mask)
2215 {
2216     SetProperty<RSMaskModifier, RSProperty<std::shared_ptr<RSMask>>>(RSModifierType::MASK, mask);
2217 }
2218 
SetUseEffect(bool useEffect)2219 void RSNode::SetUseEffect(bool useEffect)
2220 {
2221     SetProperty<RSUseEffectModifier, RSProperty<bool>>(RSModifierType::USE_EFFECT, useEffect);
2222 }
2223 
SetUseEffectType(UseEffectType useEffectType)2224 void RSNode::SetUseEffectType(UseEffectType useEffectType)
2225 {
2226     SetProperty<RSUseEffectTypeModifier, RSProperty<int>>(
2227         RSModifierType::USE_EFFECT_TYPE, static_cast<int>(useEffectType));
2228 }
2229 
SetUseShadowBatching(bool useShadowBatching)2230 void RSNode::SetUseShadowBatching(bool useShadowBatching)
2231 {
2232     SetProperty<RSUseShadowBatchingModifier, RSProperty<bool>>(RSModifierType::USE_SHADOW_BATCHING, useShadowBatching);
2233 }
2234 
SetColorBlendMode(RSColorBlendMode colorBlendMode)2235 void RSNode::SetColorBlendMode(RSColorBlendMode colorBlendMode)
2236 {
2237     SetProperty<RSColorBlendModeModifier, RSProperty<int>>(
2238         RSModifierType::COLOR_BLEND_MODE, static_cast<int>(colorBlendMode));
2239 }
2240 
SetColorBlendApplyType(RSColorBlendApplyType colorBlendApplyType)2241 void RSNode::SetColorBlendApplyType(RSColorBlendApplyType colorBlendApplyType)
2242 {
2243     SetProperty<RSColorBlendApplyTypeModifier, RSProperty<int>>(
2244         RSModifierType::COLOR_BLEND_APPLY_TYPE, static_cast<int>(colorBlendApplyType));
2245 }
2246 
SetPixelStretch(const Vector4f & stretchSize,Drawing::TileMode stretchTileMode)2247 void RSNode::SetPixelStretch(const Vector4f& stretchSize, Drawing::TileMode stretchTileMode)
2248 {
2249     SetProperty<RSPixelStretchModifier, RSAnimatableProperty<Vector4f>>(RSModifierType::PIXEL_STRETCH, stretchSize);
2250     SetProperty<RSPixelStretchTileModeModifier, RSProperty<int>>(
2251         RSModifierType::PIXEL_STRETCH_TILE_MODE, static_cast<int>(stretchTileMode));
2252 }
2253 
SetPixelStretchPercent(const Vector4f & stretchPercent,Drawing::TileMode stretchTileMode)2254 void RSNode::SetPixelStretchPercent(const Vector4f& stretchPercent, Drawing::TileMode stretchTileMode)
2255 {
2256     SetProperty<RSPixelStretchPercentModifier, RSAnimatableProperty<Vector4f>>(RSModifierType::PIXEL_STRETCH_PERCENT,
2257         stretchPercent);
2258     SetProperty<RSPixelStretchTileModeModifier, RSProperty<int>>(
2259         RSModifierType::PIXEL_STRETCH_TILE_MODE, static_cast<int>(stretchTileMode));
2260 }
2261 
SetWaterRippleParams(const RSWaterRipplePara & params,float progress)2262 void RSNode::SetWaterRippleParams(const RSWaterRipplePara& params, float progress)
2263 {
2264     SetProperty<RSWaterRippleParamsModifier,
2265         RSProperty<RSWaterRipplePara>>(RSModifierType::WATER_RIPPLE_PARAMS, params);
2266     SetProperty<RSWaterRippleProgressModifier,
2267         RSAnimatableProperty<float>>(RSModifierType::WATER_RIPPLE_PROGRESS, progress);
2268 }
2269 
SetFlyOutParams(const RSFlyOutPara & params,float degree)2270 void RSNode::SetFlyOutParams(const RSFlyOutPara& params, float degree)
2271 {
2272     SetProperty<RSFlyOutParamsModifier,
2273         RSProperty<RSFlyOutPara>>(RSModifierType::FLY_OUT_PARAMS, params);
2274     SetProperty<RSFlyOutDegreeModifier,
2275         RSAnimatableProperty<float>>(RSModifierType::FLY_OUT_DEGREE, degree);
2276 }
2277 
SetDistortionK(const float distortionK)2278 void RSNode::SetDistortionK(const float distortionK)
2279 {
2280     SetProperty<RSDistortionKModifier, RSAnimatableProperty<float>>(RSModifierType::DISTORTION_K, distortionK);
2281 }
2282 
SetFreeze(bool isFreeze)2283 void RSNode::SetFreeze(bool isFreeze)
2284 {
2285     ROSEN_LOGE("SetFreeze only support RSSurfaceNode and RSCanvasNode in uniRender");
2286 }
2287 
SetNodeName(const std::string & nodeName)2288 void RSNode::SetNodeName(const std::string& nodeName)
2289 {
2290     if (nodeName_ != nodeName) {
2291         nodeName_ = nodeName;
2292         std::unique_ptr<RSCommand> command = std::make_unique<RSSetNodeName>(GetId(), nodeName_);
2293         AddCommand(command, IsRenderServiceNode());
2294     }
2295 }
2296 
SetTakeSurfaceForUIFlag()2297 void RSNode::SetTakeSurfaceForUIFlag()
2298 {
2299     std::unique_ptr<RSCommand> command = std::make_unique<RSSetTakeSurfaceForUIFlag>(GetId());
2300     auto transaction = GetRSTransaction();
2301     if (transaction != nullptr) {
2302         transaction->AddCommand(command, IsRenderServiceNode());
2303         transaction->FlushImplicitTransaction();
2304     } else {
2305         auto transactionProxy = RSTransactionProxy::GetInstance();
2306         if (transactionProxy != nullptr) {
2307             transactionProxy->AddCommand(command, IsRenderServiceNode());
2308             transactionProxy->FlushImplicitTransaction();
2309         }
2310     }
2311 }
2312 
SetSpherizeDegree(float spherizeDegree)2313 void RSNode::SetSpherizeDegree(float spherizeDegree)
2314 {
2315     SetProperty<RSSpherizeModifier, RSAnimatableProperty<float>>(RSModifierType::SPHERIZE, spherizeDegree);
2316 }
2317 
SetAttractionEffect(float fraction,const Vector2f & destinationPoint)2318 void RSNode::SetAttractionEffect(float fraction, const Vector2f& destinationPoint)
2319 {
2320     SetAttractionEffectFraction(fraction);
2321     SetAttractionEffectDstPoint(destinationPoint);
2322 }
2323 
SetAttractionEffectFraction(float fraction)2324 void RSNode::SetAttractionEffectFraction(float fraction)
2325 {
2326     SetProperty<RSAttractionFractionModifier, RSAnimatableProperty<float>>(RSModifierType::ATTRACTION_FRACTION,
2327         fraction);
2328 }
2329 
SetAttractionEffectDstPoint(Vector2f destinationPoint)2330 void RSNode::SetAttractionEffectDstPoint(Vector2f destinationPoint)
2331 {
2332     SetProperty<RSAttractionDstPointModifier, RSAnimatableProperty<Vector2f>>(RSModifierType::ATTRACTION_DSTPOINT,
2333         destinationPoint);
2334 }
2335 
SetLightUpEffectDegree(float LightUpEffectDegree)2336 void RSNode::SetLightUpEffectDegree(float LightUpEffectDegree)
2337 {
2338     SetProperty<RSLightUpEffectModifier, RSAnimatableProperty<float>>(
2339         RSModifierType::LIGHT_UP_EFFECT, LightUpEffectDegree);
2340 }
2341 
NotifyTransition(const std::shared_ptr<const RSTransitionEffect> & effect,bool isTransitionIn)2342 void RSNode::NotifyTransition(const std::shared_ptr<const RSTransitionEffect>& effect, bool isTransitionIn)
2343 {
2344     auto rsUIContext = rsUIContext_.lock();
2345     auto implicitAnimator = rsUIContext ? rsUIContext->GetRSImplicitAnimator()
2346                                         : RSImplicitAnimatorMap::Instance().GetAnimator(gettid());
2347     if (implicitAnimator == nullptr) {
2348         ROSEN_LOGE("Failed to notify transition, implicit animator is null!");
2349         return;
2350     }
2351 
2352     if (!implicitAnimator->NeedImplicitAnimation()) {
2353         return;
2354     }
2355 
2356     auto& customEffects = isTransitionIn ? effect->customTransitionInEffects_ : effect->customTransitionOutEffects_;
2357     // temporary close the implicit animation
2358     ExecuteWithoutAnimation(
2359         [&customEffects] {
2360             for (auto& customEffect : customEffects) {
2361                 customEffect->Active();
2362             }
2363         },
2364         rsUIContext, implicitAnimator);
2365 
2366     implicitAnimator->BeginImplicitTransition(effect, isTransitionIn);
2367     for (auto& customEffect : customEffects) {
2368         customEffect->Identity();
2369     }
2370     implicitAnimator->CreateImplicitTransition(*this);
2371     implicitAnimator->EndImplicitTransition();
2372 }
2373 
OnAddChildren()2374 void RSNode::OnAddChildren()
2375 {
2376     // kick off transition only if it's visible.
2377     if (transitionEffect_ != nullptr && GetStagingProperties().GetVisible()) {
2378         NotifyTransition(transitionEffect_, true);
2379     }
2380 }
2381 
OnRemoveChildren()2382 void RSNode::OnRemoveChildren()
2383 {
2384     // kick off transition only if it's visible.
2385     if (transitionEffect_ != nullptr && GetStagingProperties().GetVisible()) {
2386         NotifyTransition(transitionEffect_, false);
2387     }
2388 }
2389 
SetBackgroundBlurRadius(float radius)2390 void RSNode::SetBackgroundBlurRadius(float radius)
2391 {
2392     SetProperty<RSBackgroundBlurRadiusModifier, RSAnimatableProperty<float>>(
2393         RSModifierType::BACKGROUND_BLUR_RADIUS, radius);
2394 }
2395 
SetBackgroundBlurSaturation(float saturation)2396 void RSNode::SetBackgroundBlurSaturation(float saturation)
2397 {
2398     SetProperty<RSBackgroundBlurSaturationModifier, RSAnimatableProperty<float>>(
2399         RSModifierType::BACKGROUND_BLUR_SATURATION, saturation);
2400 }
2401 
SetBackgroundBlurBrightness(float brightness)2402 void RSNode::SetBackgroundBlurBrightness(float brightness)
2403 {
2404     SetProperty<RSBackgroundBlurBrightnessModifier, RSAnimatableProperty<float>>(
2405         RSModifierType::BACKGROUND_BLUR_BRIGHTNESS, brightness);
2406 }
2407 
SetBackgroundBlurMaskColor(Color maskColor)2408 void RSNode::SetBackgroundBlurMaskColor(Color maskColor)
2409 {
2410     SetProperty<RSBackgroundBlurMaskColorModifier, RSAnimatableProperty<Color>>(
2411         RSModifierType::BACKGROUND_BLUR_MASK_COLOR, maskColor);
2412 }
2413 
SetBackgroundBlurColorMode(int colorMode)2414 void RSNode::SetBackgroundBlurColorMode(int colorMode)
2415 {
2416     SetProperty<RSBackgroundBlurColorModeModifier, RSProperty<int>>(
2417         RSModifierType::BACKGROUND_BLUR_COLOR_MODE, colorMode);
2418 }
2419 
SetBackgroundBlurRadiusX(float blurRadiusX)2420 void RSNode::SetBackgroundBlurRadiusX(float blurRadiusX)
2421 {
2422     SetProperty<RSBackgroundBlurRadiusXModifier, RSAnimatableProperty<float>>(
2423         RSModifierType::BACKGROUND_BLUR_RADIUS_X, blurRadiusX);
2424 }
2425 
SetBackgroundBlurRadiusY(float blurRadiusY)2426 void RSNode::SetBackgroundBlurRadiusY(float blurRadiusY)
2427 {
2428     SetProperty<RSBackgroundBlurRadiusYModifier, RSAnimatableProperty<float>>(
2429         RSModifierType::BACKGROUND_BLUR_RADIUS_Y, blurRadiusY);
2430 }
2431 
SetForegroundBlurRadius(float radius)2432 void RSNode::SetForegroundBlurRadius(float radius)
2433 {
2434     SetProperty<RSForegroundBlurRadiusModifier, RSAnimatableProperty<float>>(
2435         RSModifierType::FOREGROUND_BLUR_RADIUS, radius);
2436 }
2437 
SetForegroundBlurSaturation(float saturation)2438 void RSNode::SetForegroundBlurSaturation(float saturation)
2439 {
2440     SetProperty<RSForegroundBlurSaturationModifier, RSAnimatableProperty<float>>(
2441         RSModifierType::FOREGROUND_BLUR_SATURATION, saturation);
2442 }
2443 
SetForegroundBlurBrightness(float brightness)2444 void RSNode::SetForegroundBlurBrightness(float brightness)
2445 {
2446     SetProperty<RSForegroundBlurBrightnessModifier, RSAnimatableProperty<float>>(
2447         RSModifierType::FOREGROUND_BLUR_BRIGHTNESS, brightness);
2448 }
2449 
SetForegroundBlurMaskColor(Color maskColor)2450 void RSNode::SetForegroundBlurMaskColor(Color maskColor)
2451 {
2452     SetProperty<RSForegroundBlurMaskColorModifier, RSAnimatableProperty<Color>>(
2453         RSModifierType::FOREGROUND_BLUR_MASK_COLOR, maskColor);
2454 }
2455 
SetForegroundBlurColorMode(int colorMode)2456 void RSNode::SetForegroundBlurColorMode(int colorMode)
2457 {
2458     SetProperty<RSForegroundBlurColorModeModifier, RSProperty<int>>(
2459         RSModifierType::FOREGROUND_BLUR_COLOR_MODE, colorMode);
2460 }
2461 
SetForegroundBlurRadiusX(float blurRadiusX)2462 void RSNode::SetForegroundBlurRadiusX(float blurRadiusX)
2463 {
2464     SetProperty<RSForegroundBlurRadiusXModifier, RSAnimatableProperty<float>>(
2465         RSModifierType::FOREGROUND_BLUR_RADIUS_X, blurRadiusX);
2466 }
2467 
SetForegroundBlurRadiusY(float blurRadiusY)2468 void RSNode::SetForegroundBlurRadiusY(float blurRadiusY)
2469 {
2470     SetProperty<RSForegroundBlurRadiusYModifier, RSAnimatableProperty<float>>(
2471         RSModifierType::FOREGROUND_BLUR_RADIUS_Y, blurRadiusY);
2472 }
2473 
AnimationCallback(AnimationId animationId,AnimationCallbackEvent event)2474 bool RSNode::AnimationCallback(AnimationId animationId, AnimationCallbackEvent event)
2475 {
2476     std::shared_ptr<RSAnimation> animation = nullptr;
2477     {
2478         std::unique_lock<std::recursive_mutex> lock(animationMutex_);
2479         auto animationItr = animations_.find(animationId);
2480         if (animationItr == animations_.end()) {
2481             ROSEN_LOGE("Failed to find animation[%{public}" PRIu64 "]!", animationId);
2482             return false;
2483         }
2484         animation = animationItr->second;
2485     }
2486 
2487     if (animation == nullptr) {
2488         ROSEN_LOGE("Failed to callback animation[%{public}" PRIu64 "], animation is null!", animationId);
2489         return false;
2490     }
2491     if (event == FINISHED) {
2492         RemoveAnimationInner(animation);
2493         animation->CallFinishCallback();
2494         return true;
2495     } else if (event == REPEAT_FINISHED) {
2496         animation->CallRepeatCallback();
2497         return true;
2498     } else if (event == LOGICALLY_FINISHED) {
2499         animation->CallLogicallyFinishCallback();
2500         return true;
2501     }
2502     ROSEN_LOGE("Failed to callback animation event[%{public}d], event is null!", event);
2503     return false;
2504 }
2505 
SetPaintOrder(bool drawContentLast)2506 void RSNode::SetPaintOrder(bool drawContentLast)
2507 {
2508     drawContentLast_ = drawContentLast;
2509 }
2510 
ClearAllModifiers()2511 void RSNode::ClearAllModifiers()
2512 {
2513     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
2514     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2515     for (auto [id, modifier] : modifiers_) {
2516         if (modifier) {
2517             modifier->DetachFromNode();
2518         }
2519     }
2520     modifiers_.clear();
2521     propertyModifiers_.clear();
2522     modifiersTypeMap_.clear();
2523 }
2524 
AddModifier(const std::shared_ptr<RSModifier> modifier)2525 void RSNode::AddModifier(const std::shared_ptr<RSModifier> modifier)
2526 {
2527     {
2528         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
2529         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2530         if (!modifier || modifiers_.count(modifier->GetPropertyId())) {
2531             return;
2532         }
2533         if (motionPathOption_ != nullptr && IsPathAnimatableModifier(modifier->GetModifierType())) {
2534             modifier->SetMotionPathOption(motionPathOption_);
2535         }
2536         auto rsnode = std::static_pointer_cast<RSNode>(shared_from_this());
2537         modifier->AttachToNode(rsnode);
2538         modifiers_.emplace(modifier->GetPropertyId(), modifier);
2539         modifiersTypeMap_.emplace((int16_t)modifier->GetModifierType(), modifier);
2540     }
2541     if (modifier->GetModifierType() == RSModifierType::NODE_MODIFIER) {
2542         return;
2543     }
2544     if (modifier->GetModifierType() > RSModifierType::FRAME &&
2545         modifier->GetModifierType() != RSModifierType::BACKGROUND_COLOR &&
2546         modifier->GetModifierType() != RSModifierType::ALPHA &&
2547         modifier->GetModifierType() != RSModifierType::CORNER_RADIUS) {
2548         SetDrawNode();
2549     }
2550     std::unique_ptr<RSCommand> command = std::make_unique<RSAddModifier>(GetId(), modifier->CreateRenderModifier());
2551     AddCommand(command, IsRenderServiceNode(), GetFollowType(), GetId());
2552     if (NeedForcedSendToRemote()) {
2553         std::unique_ptr<RSCommand> cmdForRemote =
2554             std::make_unique<RSAddModifier>(GetId(), modifier->CreateRenderModifier());
2555         AddCommand(cmdForRemote, true, GetFollowType(), GetId());
2556     }
2557     ROSEN_LOGD("RSNode::add modifier, node id: %{public}" PRIu64 ", type: %{public}s",
2558             GetId(), modifier->GetModifierTypeString().c_str());
2559 }
2560 
DoFlushModifier()2561 void RSNode::DoFlushModifier()
2562 {
2563     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
2564     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2565     if (modifiers_.empty()) {
2566         return;
2567     }
2568     auto transactionProxy = RSTransactionProxy::GetInstance();
2569     if (transactionProxy == nullptr) {
2570         return;
2571     }
2572     std::unique_ptr<RSCommand> removeAllModifiersCommand = std::make_unique<RSRemoveAllModifiers>(GetId());
2573     AddCommand(removeAllModifiersCommand, IsRenderServiceNode(), GetFollowType(), GetId());
2574     for (const auto& [_, modifier] : modifiers_) {
2575         std::unique_ptr<RSCommand> command = std::make_unique<RSAddModifier>(GetId(), modifier->CreateRenderModifier());
2576         AddCommand(command, IsRenderServiceNode(), GetFollowType(), GetId());
2577         ROSEN_LOGD("RSNode::flush modifier, node id: %{public}" PRIu64 ", type: %{public}s",
2578             GetId(), modifier->GetModifierTypeString().c_str());
2579     }
2580 }
2581 
RemoveModifier(const std::shared_ptr<RSModifier> modifier)2582 void RSNode::RemoveModifier(const std::shared_ptr<RSModifier> modifier)
2583 {
2584     {
2585         std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
2586         CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2587         if (!modifier) {
2588             return;
2589         }
2590         auto iter = modifiers_.find(modifier->GetPropertyId());
2591         if (iter == modifiers_.end()) {
2592             return;
2593         }
2594         auto deleteType = modifier->GetModifierType();
2595         bool isExist = false;
2596         modifiers_.erase(iter);
2597         for (auto [id, value] : modifiers_) {
2598             if (value && value->GetModifierType() == deleteType) {
2599                 modifiersTypeMap_.emplace((int16_t)deleteType, value);
2600                 isExist = true;
2601                 break;
2602             }
2603         }
2604         if (!isExist) {
2605             modifiersTypeMap_.erase((int16_t)deleteType);
2606         }
2607         modifier->DetachFromNode();
2608     }
2609     std::unique_ptr<RSCommand> command = std::make_unique<RSRemoveModifier>(GetId(), modifier->GetPropertyId());
2610     AddCommand(command, IsRenderServiceNode(), GetFollowType(), GetId());
2611     if (NeedForcedSendToRemote()) {
2612         std::unique_ptr<RSCommand> cmdForRemote =
2613             std::make_unique<RSRemoveModifier>(GetId(), modifier->GetPropertyId());
2614         AddCommand(cmdForRemote, true, GetFollowType(), GetId());
2615     }
2616     ROSEN_LOGD("RSNode::remove modifier, node id: %{public}" PRIu64 ", type: %{public}s", GetId(),
2617         modifier->GetModifierTypeString().c_str());
2618 }
2619 
GetModifier(const PropertyId & propertyId)2620 const std::shared_ptr<RSModifier> RSNode::GetModifier(const PropertyId& propertyId)
2621 {
2622     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
2623     CHECK_FALSE_RETURN_VALUE(CheckMultiThreadAccess(__func__), nullptr);
2624     auto iter = modifiers_.find(propertyId);
2625     if (iter != modifiers_.end()) {
2626         return iter->second;
2627     }
2628 
2629     return {};
2630 }
2631 
UpdateModifierMotionPathOption()2632 void RSNode::UpdateModifierMotionPathOption()
2633 {
2634     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
2635     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2636     for (auto& [type, modifier] : propertyModifiers_) {
2637         if (IsPathAnimatableModifier(type)) {
2638             modifier->SetMotionPathOption(motionPathOption_);
2639         }
2640     }
2641     for (auto& [id, modifier] : modifiers_) {
2642         if (IsPathAnimatableModifier(modifier->GetModifierType())) {
2643             modifier->SetMotionPathOption(motionPathOption_);
2644         }
2645     }
2646 }
2647 
CheckMultiThreadAccess(const std::string & func) const2648 bool RSNode::CheckMultiThreadAccess(const std::string& func) const
2649 {
2650     if (isSkipCheckInMultiInstance_) {
2651         return true;
2652     }
2653     auto rsContext = rsUIContext_.lock();
2654     // Node toDo
2655     if (rsContext == nullptr) {
2656         return true;
2657     }
2658 #ifdef ROSEN_OHOS
2659     thread_local auto tid = gettid();
2660     if ((tid != ExtractTid(rsContext->GetToken()))) {
2661         ROSEN_LOGE("RSNode::CheckMultiThreadAccess nodeId is %{public}" PRIu64 ", func:%{public}s is not "
2662                    "correspond tid is "
2663                    "%{public}d context "
2664                    "tid is %{public}d"
2665                    "nodeType is %{public}d",
2666             GetId(),
2667             func.c_str(),
2668             tid,
2669             ExtractTid(rsContext->GetToken()),
2670             GetType());
2671         return false;
2672     }
2673 #endif
2674     return true;
2675 }
2676 
SetSkipCheckInMultiInstance(bool isSkipCheckInMultiInstance)2677 void RSNode::SetSkipCheckInMultiInstance(bool isSkipCheckInMultiInstance)
2678 {
2679     isSkipCheckInMultiInstance_ = isSkipCheckInMultiInstance;
2680 }
2681 
GetModifierIds() const2682 std::vector<PropertyId> RSNode::GetModifierIds() const
2683 {
2684     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
2685     std::vector<PropertyId> ids;
2686     CHECK_FALSE_RETURN_VALUE(CheckMultiThreadAccess(__func__), ids);
2687     for (const auto& [id, _] : modifiers_) {
2688         ids.push_back(id);
2689     }
2690     return ids;
2691 }
2692 
MarkAllExtendModifierDirty()2693 void RSNode::MarkAllExtendModifierDirty()
2694 {
2695     std::unique_lock<std::recursive_mutex> lock(propertyMutex_);
2696     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2697     if (extendModifierIsDirty_) {
2698         return;
2699     }
2700 
2701     auto rsUIContext = rsUIContext_.lock();
2702     auto modifierManager = rsUIContext ? rsUIContext->GetRSModifierManager() :
2703         RSModifierManagerMap::Instance()->GetModifierManager(gettid());
2704     extendModifierIsDirty_ = true;
2705     for (auto& [id, modifier] : modifiers_) {
2706         if (modifier->GetModifierType() < RSModifierType::CUSTOM) {
2707             continue;
2708         }
2709         modifier->SetDirty(true, modifierManager);
2710     }
2711 }
2712 
ResetExtendModifierDirty()2713 void RSNode::ResetExtendModifierDirty()
2714 {
2715     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2716     extendModifierIsDirty_ = false;
2717 }
2718 
SetIsCustomTextType(bool isCustomTextType)2719 void RSNode::SetIsCustomTextType(bool isCustomTextType)
2720 {
2721     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2722     isCustomTextType_ = isCustomTextType;
2723 }
2724 
GetIsCustomTextType()2725 bool RSNode::GetIsCustomTextType()
2726 {
2727     return isCustomTextType_;
2728 }
2729 
SetIsCustomTypeface(bool isCustomTypeface)2730 void RSNode::SetIsCustomTypeface(bool isCustomTypeface)
2731 {
2732     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2733     isCustomTypeface_ = isCustomTypeface;
2734 }
2735 
GetIsCustomTypeface()2736 bool RSNode::GetIsCustomTypeface()
2737 {
2738     return isCustomTypeface_;
2739 }
2740 
SetDrawRegion(std::shared_ptr<RectF> rect)2741 void RSNode::SetDrawRegion(std::shared_ptr<RectF> rect)
2742 {
2743     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2744     if (drawRegion_ != rect) {
2745         drawRegion_ = rect;
2746         std::unique_ptr<RSCommand> command = std::make_unique<RSSetDrawRegion>(GetId(), rect);
2747         AddCommand(command, IsRenderServiceNode(), GetFollowType(), GetId());
2748     }
2749 }
2750 
RegisterTransitionPair(NodeId inNodeId,NodeId outNodeId,const bool isInSameWindow)2751 void RSNode::RegisterTransitionPair(NodeId inNodeId, NodeId outNodeId, const bool isInSameWindow)
2752 {
2753     std::unique_ptr<RSCommand> command =
2754         std::make_unique<RSRegisterGeometryTransitionNodePair>(inNodeId, outNodeId, isInSameWindow);
2755     auto transactionProxy = RSTransactionProxy::GetInstance();
2756     if (transactionProxy != nullptr) {
2757         transactionProxy->AddCommand(command, true);
2758     }
2759 }
2760 
UnregisterTransitionPair(NodeId inNodeId,NodeId outNodeId)2761 void RSNode::UnregisterTransitionPair(NodeId inNodeId, NodeId outNodeId)
2762 {
2763     std::unique_ptr<RSCommand> command =
2764         std::make_unique<RSUnregisterGeometryTransitionNodePair>(inNodeId, outNodeId);
2765     auto transactionProxy = RSTransactionProxy::GetInstance();
2766     if (transactionProxy != nullptr) {
2767         transactionProxy->AddCommand(command, true);
2768     }
2769 }
2770 
RegisterTransitionPair(const std::shared_ptr<RSUIContext> rsUIContext,NodeId inNodeId,NodeId outNodeId,const bool isInSameWindow)2771 void RSNode::RegisterTransitionPair(const std::shared_ptr<RSUIContext> rsUIContext, NodeId inNodeId, NodeId outNodeId,
2772     const bool isInSameWindow)
2773 {
2774     if (rsUIContext == nullptr) {
2775         ROSEN_LOGE("RSNode::RegisterTransitionPair, rsUIContext is nullptr");
2776         return;
2777     }
2778     std::unique_ptr<RSCommand> command = std::make_unique<RSRegisterGeometryTransitionNodePair>(inNodeId, outNodeId,
2779         isInSameWindow);
2780     auto transaction = rsUIContext->GetRSTransaction();
2781     if (transaction != nullptr) {
2782         transaction->AddCommand(command, true);
2783     }
2784 }
2785 
UnregisterTransitionPair(const std::shared_ptr<RSUIContext> rsUIContext,NodeId inNodeId,NodeId outNodeId)2786 void RSNode::UnregisterTransitionPair(const std::shared_ptr<RSUIContext> rsUIContext, NodeId inNodeId, NodeId outNodeId)
2787 {
2788     if (rsUIContext == nullptr) {
2789         ROSEN_LOGE("RSNode::UnregisterTransitionPair, rsUIContext is nullptr");
2790         return;
2791     }
2792     std::unique_ptr<RSCommand> command = std::make_unique<RSUnregisterGeometryTransitionNodePair>(inNodeId, outNodeId);
2793     auto transaction = rsUIContext->GetRSTransaction();
2794     if (transaction != nullptr) {
2795         transaction->AddCommand(command, true);
2796     }
2797 }
2798 
MarkNodeGroup(bool isNodeGroup,bool isForced,bool includeProperty)2799 void RSNode::MarkNodeGroup(bool isNodeGroup, bool isForced, bool includeProperty)
2800 {
2801     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2802     if (isNodeGroup_ == isNodeGroup) {
2803         return;
2804     }
2805     if (!isForced && !RSSystemProperties::GetNodeGroupGroupedByUIEnabled()) {
2806         return;
2807     }
2808     isNodeGroup_ = isNodeGroup;
2809     std::unique_ptr<RSCommand> command = std::make_unique<RSMarkNodeGroup>(GetId(), isNodeGroup, isForced,
2810         includeProperty);
2811     AddCommand(command, IsRenderServiceNode());
2812     if (isNodeGroup_) {
2813         SetDrawNode();
2814         if (GetParent()) {
2815             GetParent()->SetDrawNode();
2816         }
2817     }
2818 }
2819 
MarkNodeSingleFrameComposer(bool isNodeSingleFrameComposer)2820 void RSNode::MarkNodeSingleFrameComposer(bool isNodeSingleFrameComposer)
2821 {
2822     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2823     if (isNodeSingleFrameComposer_ != isNodeSingleFrameComposer) {
2824         isNodeSingleFrameComposer_ = isNodeSingleFrameComposer;
2825         std::unique_ptr<RSCommand> command =
2826             std::make_unique<RSMarkNodeSingleFrameComposer>(GetId(), isNodeSingleFrameComposer, GetRealPid());
2827         AddCommand(command, IsRenderServiceNode());
2828     }
2829 }
2830 
MarkSuggestOpincNode(bool isOpincNode,bool isNeedCalculate)2831 void RSNode::MarkSuggestOpincNode(bool isOpincNode, bool isNeedCalculate)
2832 {
2833     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2834     if (isSuggestOpincNode_ == isOpincNode) {
2835         return;
2836     }
2837     isSuggestOpincNode_ = isOpincNode;
2838     std::unique_ptr<RSCommand> command = std::make_unique<RSMarkSuggestOpincNode>(GetId(),
2839         isOpincNode, isNeedCalculate);
2840     AddCommand(command, IsRenderServiceNode());
2841     if (isSuggestOpincNode_) {
2842         SetDrawNode();
2843         if (GetParent()) {
2844             GetParent()->SetDrawNode();
2845         }
2846     }
2847 }
2848 
MarkUifirstNode(bool isUifirstNode)2849 void RSNode::MarkUifirstNode(bool isUifirstNode)
2850 {
2851     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2852     if (isUifirstNode_ == isUifirstNode) {
2853         return;
2854     }
2855     isUifirstNode_ = isUifirstNode;
2856     std::unique_ptr<RSCommand> command = std::make_unique<RSMarkUifirstNode>(GetId(), isUifirstNode);
2857     AddCommand(command, IsRenderServiceNode());
2858 }
2859 
MarkUifirstNode(bool isForceFlag,bool isUifirstEnable)2860 void RSNode::MarkUifirstNode(bool isForceFlag, bool isUifirstEnable)
2861 {
2862     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2863     if (isForceFlag == isForceFlag_ && isUifirstEnable_ == isUifirstEnable) {
2864         return;
2865     }
2866     isForceFlag_ = isForceFlag;
2867     isUifirstEnable_ = isUifirstEnable;
2868     std::unique_ptr<RSCommand> command = std::make_unique<RSForceUifirstNode>(GetId(), isForceFlag, isUifirstEnable);
2869     AddCommand(command, IsRenderServiceNode());
2870 }
2871 
SetDrawNode()2872 void RSNode::SetDrawNode()
2873 {
2874     if (isDrawNode_) {
2875         return;
2876     }
2877     isDrawNode_ = true;
2878     if (drawNodeChangeCallback_) {
2879         drawNodeChangeCallback_(shared_from_this(), false);
2880     }
2881 }
2882 
GetIsDrawn()2883 bool RSNode::GetIsDrawn()
2884 {
2885     return isDrawNode_;
2886 }
2887 
SetUIFirstSwitch(RSUIFirstSwitch uiFirstSwitch)2888 void RSNode::SetUIFirstSwitch(RSUIFirstSwitch uiFirstSwitch)
2889 {
2890     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2891     if (uiFirstSwitch_ == uiFirstSwitch) {
2892         return;
2893     }
2894     uiFirstSwitch_ = uiFirstSwitch;
2895     std::unique_ptr<RSCommand> command = std::make_unique<RSSetUIFirstSwitch>(GetId(), uiFirstSwitch);
2896     AddCommand(command, IsRenderServiceNode());
2897 }
2898 
SetGrayScale(float grayScale)2899 void RSNode::SetGrayScale(float grayScale)
2900 {
2901     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2902     SetProperty<RSGrayScaleModifier, RSAnimatableProperty<float>>(RSModifierType::GRAY_SCALE, grayScale);
2903 }
2904 
SetLightIntensity(float lightIntensity)2905 void RSNode::SetLightIntensity(float lightIntensity)
2906 {
2907     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2908     SetProperty<RSLightIntensityModifier, RSAnimatableProperty<float>>(RSModifierType::LIGHT_INTENSITY, lightIntensity);
2909 }
2910 
SetLightColor(uint32_t lightColorValue)2911 void RSNode::SetLightColor(uint32_t lightColorValue)
2912 {
2913     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2914     auto lightColor = Color::FromArgbInt(lightColorValue);
2915     SetProperty<RSLightColorModifier, RSAnimatableProperty<Color>>(RSModifierType::LIGHT_COLOR, lightColor);
2916 }
2917 
SetLightPosition(float positionX,float positionY,float positionZ)2918 void RSNode::SetLightPosition(float positionX, float positionY, float positionZ)
2919 {
2920     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2921     SetLightPosition(Vector4f(positionX, positionY, positionZ, 0.f));
2922 }
2923 
SetLightPosition(const Vector4f & lightPosition)2924 void RSNode::SetLightPosition(const Vector4f& lightPosition)
2925 {
2926     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2927     SetProperty<RSLightPositionModifier, RSAnimatableProperty<Vector4f>>(RSModifierType::LIGHT_POSITION, lightPosition);
2928 }
2929 
SetIlluminatedBorderWidth(float illuminatedBorderWidth)2930 void RSNode::SetIlluminatedBorderWidth(float illuminatedBorderWidth)
2931 {
2932     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2933     SetProperty<RSIlluminatedBorderWidthModifier, RSAnimatableProperty<float>>(
2934         RSModifierType::ILLUMINATED_BORDER_WIDTH, illuminatedBorderWidth);
2935 }
2936 
SetIlluminatedType(uint32_t illuminatedType)2937 void RSNode::SetIlluminatedType(uint32_t illuminatedType)
2938 {
2939     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2940     SetProperty<RSIlluminatedTypeModifier, RSProperty<int>>(
2941         RSModifierType::ILLUMINATED_TYPE, illuminatedType);
2942 }
2943 
SetBloom(float bloomIntensity)2944 void RSNode::SetBloom(float bloomIntensity)
2945 {
2946     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2947     SetProperty<RSBloomModifier, RSAnimatableProperty<float>>(RSModifierType::BLOOM, bloomIntensity);
2948 }
2949 
SetBrightness(float brightness)2950 void RSNode::SetBrightness(float brightness)
2951 {
2952     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2953     SetProperty<RSBrightnessModifier, RSAnimatableProperty<float>>(RSModifierType::BRIGHTNESS, brightness);
2954 }
2955 
SetContrast(float contrast)2956 void RSNode::SetContrast(float contrast)
2957 {
2958     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2959     SetProperty<RSContrastModifier, RSAnimatableProperty<float>>(RSModifierType::CONTRAST, contrast);
2960 }
2961 
SetSaturate(float saturate)2962 void RSNode::SetSaturate(float saturate)
2963 {
2964     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2965     SetProperty<RSSaturateModifier, RSAnimatableProperty<float>>(RSModifierType::SATURATE, saturate);
2966 }
2967 
SetSepia(float sepia)2968 void RSNode::SetSepia(float sepia)
2969 {
2970     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2971     SetProperty<RSSepiaModifier, RSAnimatableProperty<float>>(RSModifierType::SEPIA, sepia);
2972 }
2973 
SetInvert(float invert)2974 void RSNode::SetInvert(float invert)
2975 {
2976     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2977     SetProperty<RSInvertModifier, RSAnimatableProperty<float>>(RSModifierType::INVERT, invert);
2978 }
2979 
SetAiInvert(const Vector4f & aiInvert)2980 void RSNode::SetAiInvert(const Vector4f& aiInvert)
2981 {
2982     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2983     SetProperty<RSAiInvertModifier, RSAnimatableProperty<Vector4f>>(RSModifierType::AIINVERT, aiInvert);
2984 }
2985 
SetSystemBarEffect()2986 void RSNode::SetSystemBarEffect()
2987 {
2988     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2989     SetProperty<RSSystemBarEffectModifier, RSProperty<bool>>(RSModifierType::SYSTEMBAREFFECT, true);
2990 }
2991 
SetHueRotate(float hueRotate)2992 void RSNode::SetHueRotate(float hueRotate)
2993 {
2994     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
2995     SetProperty<RSHueRotateModifier, RSAnimatableProperty<float>>(RSModifierType::HUE_ROTATE, hueRotate);
2996 }
2997 
SetColorBlend(uint32_t colorValue)2998 void RSNode::SetColorBlend(uint32_t colorValue)
2999 {
3000     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3001     auto colorBlend = Color::FromArgbInt(colorValue);
3002     SetProperty<RSColorBlendModifier, RSAnimatableProperty<Color>>(RSModifierType::COLOR_BLEND, colorBlend);
3003 }
3004 
CalcExpectedFrameRate(const std::string & scene,float speed)3005 int32_t RSNode::CalcExpectedFrameRate(const std::string& scene, float speed)
3006 {
3007     auto preferredFps = RSFrameRatePolicy::GetInstance()->GetPreferredFps(scene, speed);
3008     return preferredFps;
3009 }
3010 
SetOutOfParent(OutOfParentType outOfParent)3011 void RSNode::SetOutOfParent(OutOfParentType outOfParent)
3012 {
3013     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3014     if (outOfParent != outOfParent_) {
3015         outOfParent_ = outOfParent;
3016 
3017         std::unique_ptr<RSCommand> command = std::make_unique<RSSetOutOfParent>(GetId(), outOfParent);
3018         AddCommand(command, IsRenderServiceNode());
3019     }
3020 }
3021 
GenerateId()3022 NodeId RSNode::GenerateId()
3023 {
3024     static pid_t pid_ = GetRealPid();
3025     static std::atomic<uint32_t> currentId_ = 1; // surfaceNode is seted correctly during boot when currentId is 1
3026 
3027     auto currentId = currentId_.fetch_add(1, std::memory_order_relaxed);
3028     if (currentId == UINT32_MAX) {
3029         // [PLANNING]:process the overflow situations
3030         ROSEN_LOGE("Node Id overflow");
3031     }
3032 
3033     // concat two 32-bit numbers to one 64-bit number
3034     return ((NodeId)pid_ << 32) | currentId;
3035 }
3036 
InitUniRenderEnabled()3037 void RSNode::InitUniRenderEnabled()
3038 {
3039     static bool inited = false;
3040     if (!inited) {
3041         inited = true;
3042         g_isUniRenderEnabled = RSSystemProperties::GetUniRenderEnabled();
3043         ROSEN_LOGD("RSNode::InitUniRenderEnabled:%{public}d", g_isUniRenderEnabled);
3044     }
3045 }
3046 
3047 
3048 // RSNode::~RSNode()
3049 // {
3050 
3051 // }
3052 
IsUniRenderEnabled() const3053 bool RSNode::IsUniRenderEnabled() const
3054 {
3055     return g_isUniRenderEnabled;
3056 }
3057 
IsRenderServiceNode() const3058 bool RSNode::IsRenderServiceNode() const
3059 {
3060     return (g_isUniRenderEnabled || isRenderServiceNode_) && (!isTextureExportNode_);
3061 }
3062 
AddChild(SharedPtr child,int index)3063 void RSNode::AddChild(SharedPtr child, int index)
3064 {
3065     if (child == nullptr) {
3066         ROSEN_LOGE("RSNode::AddChild, child is nullptr");
3067         return;
3068     }
3069     if (child->parent_ == id_) {
3070         ROSEN_LOGD("RSNode::AddChild, child already exist");
3071         return;
3072     }
3073     if (child->GetType() == RSUINodeType::DISPLAY_NODE) {
3074         // Disallow to add display node as child.
3075         return;
3076     }
3077     if (frameNodeId_ < 0) {
3078         child->SetDrawNode();
3079     }
3080     NodeId childId = child->GetId();
3081     if (child->parent_ != 0) {
3082         child->RemoveFromTree();
3083     }
3084 
3085     if (index < 0 || index >= static_cast<int>(children_.size())) {
3086         children_.push_back(childId);
3087     } else {
3088         children_.insert(children_.begin() + index, childId);
3089     }
3090     child->SetParent(id_);
3091     if (isTextureExportNode_ != child->isTextureExportNode_) {
3092         child->SyncTextureExport(isTextureExportNode_);
3093     }
3094     child->OnAddChildren();
3095     child->MarkDirty(NodeDirtyType::APPEARANCE, true);
3096     // construct command using child's GetHierarchyCommandNodeId(), not GetId()
3097     childId = child->GetHierarchyCommandNodeId();
3098     std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeAddChild>(id_, childId, index);
3099 
3100     AddCommand(command, IsRenderServiceNode(), GetFollowType(), id_);
3101     if (child->GetType() == RSUINodeType::SURFACE_NODE) {
3102         auto surfaceNode = RSBaseNode::ReinterpretCast<RSSurfaceNode>(child);
3103         ROSEN_LOGI("RSNode::AddChild, Id: %{public}" PRIu64 ", SurfaceNode:[Id: %{public}" PRIu64 ", name: %{public}s]",
3104             id_, childId, surfaceNode->GetName().c_str());
3105         RS_TRACE_NAME_FMT("RSNode::AddChild, Id: %" PRIu64 ", SurfaceNode:[Id: %" PRIu64 ", name: %s]",
3106             id_, childId, surfaceNode->GetName().c_str());
3107     }
3108 }
3109 
MoveChild(SharedPtr child,int index)3110 void RSNode::MoveChild(SharedPtr child, int index)
3111 {
3112     if (child == nullptr || child->parent_ != id_) {
3113         ROSEN_LOGD("RSNode::MoveChild, not valid child");
3114         return;
3115     }
3116     NodeId childId = child->GetId();
3117     auto itr = std::find(children_.begin(), children_.end(), childId);
3118     if (itr == children_.end()) {
3119         ROSEN_LOGD("RSNode::MoveChild, not child");
3120         return;
3121     }
3122     children_.erase(itr);
3123     if (index < 0 || index >= static_cast<int>(children_.size())) {
3124         children_.push_back(childId);
3125     } else {
3126         children_.insert(children_.begin() + index, childId);
3127     }
3128     // construct command using child's GetHierarchyCommandNodeId(), not GetId()
3129     childId = child->GetHierarchyCommandNodeId();
3130     std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeMoveChild>(id_, childId, index);
3131 
3132     AddCommand(command, IsRenderServiceNode(), GetFollowType(), id_);
3133 }
3134 
RemoveChild(SharedPtr child)3135 void RSNode::RemoveChild(SharedPtr child)
3136 {
3137     if (child == nullptr || child->parent_ != id_) {
3138         ROSEN_LOGI("RSNode::RemoveChild, child is nullptr");
3139         return;
3140     }
3141     NodeId childId = child->GetId();
3142     RemoveChildById(childId);
3143     child->OnRemoveChildren();
3144     child->SetParent(0);
3145     child->MarkDirty(NodeDirtyType::APPEARANCE, true);
3146     // construct command using child's GetHierarchyCommandNodeId(), not GetId()
3147     childId = child->GetHierarchyCommandNodeId();
3148     std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeRemoveChild>(id_, childId);
3149     AddCommand(command, IsRenderServiceNode(), GetFollowType(), id_);
3150 
3151     if (child->GetType() == RSUINodeType::SURFACE_NODE) {
3152         auto surfaceNode = RSBaseNode::ReinterpretCast<RSSurfaceNode>(child);
3153         ROSEN_LOGI("RSNode::RemoveChild, Id: %{public}" PRIu64 ", SurfaceNode:[Id: %{public}" PRIu64 ", "
3154             "name: %{public}s]", id_, childId, surfaceNode->GetName().c_str());
3155         RS_TRACE_NAME_FMT("RSNode::RemoveChild, Id: %" PRIu64 ", SurfaceNode:[Id: %" PRIu64 ", name: %s]",
3156             id_, childId, surfaceNode->GetName().c_str());
3157     }
3158 }
3159 
RemoveChildByNodeId(NodeId childId)3160 void RSNode::RemoveChildByNodeId(NodeId childId)
3161 {
3162     SharedPtr childPtr = rsUIContext_.lock() ? rsUIContext_.lock()->GetNodeMap().GetNode(childId)
3163                                              : RSNodeMap::Instance().GetNode(childId);
3164     if (childPtr) {
3165         RemoveChild(childPtr);
3166     } else {
3167         ROSEN_LOGE("RSNode::RemoveChildByNodeId, childId not found");
3168     }
3169 }
3170 
AddCrossParentChild(SharedPtr child,int index)3171 void RSNode::AddCrossParentChild(SharedPtr child, int index)
3172 {
3173     // AddCrossParentChild only used as: the child is under multiple parents(e.g. a window cross multi-screens),
3174     // so this child will not remove from the old parent.
3175     if (child == nullptr) {
3176         ROSEN_LOGE("RSNode::AddCrossScreenChild, child is nullptr");
3177         return;
3178     }
3179     if (!this->IsInstanceOf<RSDisplayNode>()) {
3180         ROSEN_LOGE("RSNode::AddCrossScreenChild, only displayNode support AddCrossScreenChild");
3181         return;
3182     }
3183     NodeId childId = child->GetId();
3184 
3185     if (index < 0 || index >= static_cast<int>(children_.size())) {
3186         children_.push_back(childId);
3187     } else {
3188         children_.insert(children_.begin() + index, childId);
3189     }
3190     child->SetParent(id_);
3191     child->OnAddChildren();
3192     child->MarkDirty(NodeDirtyType::APPEARANCE, true);
3193     // construct command using child's GetHierarchyCommandNodeId(), not GetId()
3194     childId = child->GetHierarchyCommandNodeId();
3195     std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeAddCrossParentChild>(id_, childId, index);
3196 
3197     AddCommand(command, IsRenderServiceNode(), GetFollowType(), id_);
3198 }
3199 
RemoveCrossParentChild(SharedPtr child,NodeId newParentId)3200 void RSNode::RemoveCrossParentChild(SharedPtr child, NodeId newParentId)
3201 {
3202     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3203     // RemoveCrossParentChild only used as: the child is under multiple parents(e.g. a window cross multi-screens),
3204     // set the newParentId to rebuild the parent-child relationship.
3205     if (child == nullptr) {
3206         ROSEN_LOGI("RSNode::RemoveCrossScreenChild, child is nullptr");
3207         return;
3208     }
3209     if (!this->IsInstanceOf<RSDisplayNode>()) {
3210         ROSEN_LOGE("RSNode::RemoveCrossScreenChild, only displayNode support RemoveCrossScreenChild");
3211         return;
3212     }
3213     NodeId childId = child->GetId();
3214     RemoveChildById(childId);
3215     child->OnRemoveChildren();
3216     child->SetParent(newParentId);
3217     child->MarkDirty(NodeDirtyType::APPEARANCE, true);
3218 
3219     // construct command using child's GetHierarchyCommandNodeId(), not GetId()
3220     childId = child->GetHierarchyCommandNodeId();
3221     std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeRemoveCrossParentChild>(id_, childId, newParentId);
3222     AddCommand(command, IsRenderServiceNode(), GetFollowType(), id_);
3223 }
3224 
SetIsCrossNode(bool isCrossNode)3225 void RSNode::SetIsCrossNode(bool isCrossNode)
3226 {
3227     auto transactionProxy = RSTransactionProxy::GetInstance();
3228     if (transactionProxy == nullptr) {
3229         ROSEN_LOGE("transactionProxy is null, SetIsCrossNode failed !");
3230         return;
3231     }
3232     std::unique_ptr<RSCommand> command =
3233         std::make_unique<RSBaseNodeSetIsCrossNode>(GetId(), isCrossNode);
3234     transactionProxy->AddCommand(command);
3235 }
3236 
AddCrossScreenChild(SharedPtr child,int index,bool autoClearCloneNode)3237 void RSNode::AddCrossScreenChild(SharedPtr child, int index, bool autoClearCloneNode)
3238 {
3239     if (child == nullptr) {
3240         ROSEN_LOGE("RSNode::AddCrossScreenChild, child is nullptr");
3241         return;
3242     }
3243     if (!this->IsInstanceOf<RSDisplayNode>()) {
3244         ROSEN_LOGE("RSNode::AddCrossScreenChild, only displayNode support AddCrossScreenChild");
3245         return;
3246     }
3247 
3248     if (!child->IsInstanceOf<RSSurfaceNode>()) {
3249         ROSEN_LOGE("RSNode::AddCrossScreenChild, child shoult be RSSurfaceNode");
3250         return;
3251     }
3252     // construct command using child's GetHierarchyCommandNodeId(), not GetId()
3253     NodeId childId = child->GetHierarchyCommandNodeId();
3254     // Generate an id on the client and create a clone node on the server based on the id.
3255     std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeAddCrossScreenChild>(id_, childId,
3256         GenerateId(), index, autoClearCloneNode);
3257     AddCommand(command, IsRenderServiceNode(), GetFollowType(), id_);
3258 }
3259 
RemoveCrossScreenChild(SharedPtr child)3260 void RSNode::RemoveCrossScreenChild(SharedPtr child)
3261 {
3262     if (child == nullptr) {
3263         ROSEN_LOGE("RSNode::RemoveCrossScreenChild, child is nullptr");
3264         return;
3265     }
3266     if (!this->IsInstanceOf<RSDisplayNode>()) {
3267         ROSEN_LOGE("RSNode::RemoveCrossScreenChild, only displayNode support RemoveCrossScreenChild");
3268         return;
3269     }
3270 
3271     if (!child->IsInstanceOf<RSSurfaceNode>()) {
3272         ROSEN_LOGE("RSNode::RemoveCrossScreenChild, child shoult be RSSurfaceNode");
3273         return;
3274     }
3275     // construct command using child's GetHierarchyCommandNodeId(), not GetId()
3276     NodeId childId = child->GetHierarchyCommandNodeId();
3277     std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeRemoveCrossScreenChild>(id_, childId);
3278     AddCommand(command, IsRenderServiceNode(), GetFollowType(), id_);
3279 }
3280 
RemoveChildById(NodeId childId)3281 void RSNode::RemoveChildById(NodeId childId)
3282 {
3283     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3284     auto itr = std::find(children_.begin(), children_.end(), childId);
3285     if (itr != children_.end()) {
3286         children_.erase(itr);
3287     }
3288 }
3289 
RemoveFromTree()3290 void RSNode::RemoveFromTree()
3291 {
3292     CHECK_FALSE_RETURN(CheckMultiThreadAccess(__func__));
3293     MarkDirty(NodeDirtyType::APPEARANCE, true);
3294     auto parentPtr = rsUIContext_.lock() ? rsUIContext_.lock()->GetNodeMap().GetNode(parent_)
3295                                          : RSNodeMap::Instance().GetNode(parent_);
3296     if (parentPtr) {
3297         parentPtr->RemoveChildById(GetId());
3298         OnRemoveChildren();
3299         SetParent(0);
3300     }
3301     // construct command using own GetHierarchyCommandNodeId(), not GetId()
3302     auto nodeId = GetHierarchyCommandNodeId();
3303     std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeRemoveFromTree>(nodeId);
3304     // always send Remove-From-Tree command
3305     AddCommand(command, IsRenderServiceNode(), GetFollowType(), nodeId);
3306 }
3307 
ClearChildren()3308 void RSNode::ClearChildren()
3309 {
3310     for (auto child : children_) {
3311         auto childPtr = rsUIContext_.lock() ? rsUIContext_.lock()->GetNodeMap().GetNode(child)
3312                                             : RSNodeMap::Instance().GetNode(child);
3313         if (childPtr) {
3314             childPtr->SetParent(0);
3315             childPtr->MarkDirty(NodeDirtyType::APPEARANCE, true);
3316         }
3317     }
3318     children_.clear();
3319     // construct command using own GetHierarchyCommandNodeId(), not GetId()
3320     auto nodeId = GetHierarchyCommandNodeId();
3321     std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeClearChild>(nodeId);
3322     AddCommand(command, IsRenderServiceNode(), GetFollowType(), nodeId);
3323 }
3324 
SetExportTypeChangedCallback(ExportTypeChangedCallback callback)3325 void RSNode::SetExportTypeChangedCallback(ExportTypeChangedCallback callback)
3326 {
3327     exportTypeChangedCallback_ = callback;
3328 }
3329 
SetTextureExport(bool isTextureExportNode)3330 void RSNode::SetTextureExport(bool isTextureExportNode)
3331 {
3332     if (isTextureExportNode == isTextureExportNode_) {
3333         return;
3334     }
3335     isTextureExportNode_ = isTextureExportNode;
3336     if (!IsUniRenderEnabled()) {
3337         return;
3338     }
3339     if (exportTypeChangedCallback_) {
3340         exportTypeChangedCallback_(isTextureExportNode);
3341     }
3342     if ((isTextureExportNode_ && !hasCreateRenderNodeInRT_) ||
3343         (!isTextureExportNode_ && !hasCreateRenderNodeInRS_)) {
3344         CreateRenderNodeForTextureExportSwitch();
3345     }
3346     DoFlushModifier();
3347 }
3348 
SyncTextureExport(bool isTextureExportNode)3349 void RSNode::SyncTextureExport(bool isTextureExportNode)
3350 {
3351     if (isTextureExportNode == isTextureExportNode_) {
3352         return;
3353     }
3354     SetTextureExport(isTextureExportNode);
3355     for (uint32_t index = 0; index < children_.size(); index++) {
3356         auto childPtr = rsUIContext_.lock() ? rsUIContext_.lock()->GetNodeMap().GetNode(children_[index])
3357                                             : RSNodeMap::Instance().GetNode(children_[index]);
3358         if (childPtr) {
3359             childPtr->SyncTextureExport(isTextureExportNode);
3360             std::unique_ptr<RSCommand> command =
3361                 std::make_unique<RSBaseNodeAddChild>(id_, childPtr->GetHierarchyCommandNodeId(), index);
3362             AddCommand(command, IsRenderServiceNode(), GetFollowType(), id_);
3363         }
3364     }
3365 }
3366 
GetChildIdByIndex(int index) const3367 const std::optional<NodeId> RSNode::GetChildIdByIndex(int index) const
3368 {
3369     int childrenTotal = static_cast<int>(children_.size());
3370     if (childrenTotal <= 0 || index < -1 || index >= childrenTotal) {
3371         return std::nullopt;
3372     }
3373     if (index == -1) {
3374         index = childrenTotal - 1;
3375     }
3376     return children_.at(index);
3377 }
3378 
SetParent(NodeId parentId)3379 void RSNode::SetParent(NodeId parentId)
3380 {
3381     parent_ = parentId;
3382 }
3383 
GetParent()3384 RSNode::SharedPtr RSNode::GetParent()
3385 {
3386     return rsUIContext_.lock() ? rsUIContext_.lock()->GetNodeMap().GetNode(parent_)
3387                                : RSNodeMap::Instance().GetNode(parent_);
3388 }
3389 
DumpTree(int depth,std::string & out) const3390 void RSNode::DumpTree(int depth, std::string& out) const
3391 {
3392     for (int i = 0; i < depth; i++) {
3393         out += "  ";
3394     }
3395     out += "| ";
3396     Dump(out);
3397     for (auto childId : children_) {
3398         auto child = rsUIContext_.lock() ? rsUIContext_.lock()->GetNodeMap().GetNode(childId)
3399                                          : RSNodeMap::Instance().GetNode(childId);
3400         if (child) {
3401             out += "\n";
3402             child->DumpTree(depth + 1, out);
3403         }
3404     }
3405 }
3406 
Dump(std::string & out) const3407 void RSNode::Dump(std::string& out) const
3408 {
3409     auto iter = RSUINodeTypeStrs.find(GetType());
3410     out += (iter != RSUINodeTypeStrs.end() ? iter->second : "RSNode");
3411     out += "[" + std::to_string(id_);
3412     out += "], parent[" + std::to_string(parent_);
3413     out += "], instanceId[" + std::to_string(instanceId_);
3414     if (auto node = ReinterpretCastTo<RSSurfaceNode>()) {
3415         out += "], name[" + node->GetName();
3416     } else if (!nodeName_.empty()) {
3417         out += "], nodeName[" + nodeName_;
3418     }
3419     out += "], frameNodeId[" + std::to_string(frameNodeId_);
3420     out += "], frameNodeTag[" + frameNodeTag_;
3421     out += "], extendModifierIsDirty[";
3422     out += extendModifierIsDirty_ ? "true" : "false";
3423     out += "], isNodeGroup[";
3424     out += isNodeGroup_ ? "true" : "false";
3425     out += "], isSingleFrameComposer[";
3426     out += isNodeSingleFrameComposer_ ? "true" : "false";
3427     out += "], isSuggestOpincNode[";
3428     out += isSuggestOpincNode_ ? "true" : "false";
3429     out += "], isUifirstNode[";
3430     out += isUifirstNode_ ? "true" : "false";
3431     out += "], drawRegion[";
3432     if (drawRegion_) {
3433         out += "x:" + std::to_string(drawRegion_->GetLeft());
3434         out += " y:" + std::to_string(drawRegion_->GetTop());
3435         out += " width:" + std::to_string(drawRegion_->GetWidth());
3436         out += " height:" + std::to_string(drawRegion_->GetHeight());
3437     } else {
3438         out += "null";
3439     }
3440     out += "], outOfParent[" + std::to_string(static_cast<int>(outOfParent_));
3441     out += "], animations[";
3442     for (const auto& [id, anim] : animations_) {
3443         out += "{id:" + std::to_string(id);
3444         out += " propId:" + std::to_string(anim->GetPropertyId());
3445         out += "} ";
3446     }
3447     if (!animations_.empty()) {
3448         out.pop_back();
3449     }
3450     out += "]";
3451 }
3452 
DumpNode(int depth) const3453 std::string RSNode::DumpNode(int depth) const
3454 {
3455     std::stringstream ss;
3456     auto it = RSUINodeTypeStrs.find(GetType());
3457     if (it == RSUINodeTypeStrs.end()) {
3458         return "";
3459     }
3460     ss << it->second << "[" << std::to_string(id_) << "] child[";
3461     for (auto child : children_) {
3462         ss << std::to_string(child) << " ";
3463     }
3464     ss << "]";
3465 
3466     if (!animations_.empty()) {
3467         ss << " animation:" << std::to_string(animations_.size());
3468     }
3469     for (const auto& [animationId, animation] : animations_) {
3470         if (animation) {
3471             ss << " animationInfo:" << animation->DumpAnimation();
3472         }
3473     }
3474     ss << " " << GetStagingProperties().Dump();
3475     return ss.str();
3476 }
3477 
IsInstanceOf(RSUINodeType type) const3478 bool RSNode::IsInstanceOf(RSUINodeType type) const
3479 {
3480     auto targetType = static_cast<uint32_t>(type);
3481     auto instanceType = static_cast<uint32_t>(GetType());
3482     // use bitmask to check whether the instance is a subclass of the target type
3483     return (instanceType & targetType) == targetType;
3484 }
3485 
3486 template<typename T>
IsInstanceOf() const3487 bool RSNode::IsInstanceOf() const
3488 {
3489     return IsInstanceOf(T::Type);
3490 }
3491 
3492 // explicit instantiation with all render node types
3493 template bool RSNode::IsInstanceOf<RSDisplayNode>() const;
3494 template bool RSNode::IsInstanceOf<RSSurfaceNode>() const;
3495 template bool RSNode::IsInstanceOf<RSProxyNode>() const;
3496 template bool RSNode::IsInstanceOf<RSCanvasNode>() const;
3497 template bool RSNode::IsInstanceOf<RSRootNode>() const;
3498 template bool RSNode::IsInstanceOf<RSCanvasDrawingNode>() const;
3499 
SetInstanceId(int32_t instanceId)3500 void RSNode::SetInstanceId(int32_t instanceId)
3501 {
3502     instanceId_ = instanceId;
3503     auto rsUIContext = rsUIContext_.lock();
3504     // use client multi don’t need
3505     if (rsUIContext == nullptr) {
3506         RSNodeMap::MutableInstance().RegisterNodeInstanceId(id_, instanceId_);
3507     }
3508 }
3509 
AddCommand(std::unique_ptr<RSCommand> & command,bool isRenderServiceCommand,FollowType followType,NodeId nodeId) const3510 bool RSNode::AddCommand(std::unique_ptr<RSCommand>& command, bool isRenderServiceCommand,
3511     FollowType followType, NodeId nodeId) const
3512 {
3513     auto transaction = GetRSTransaction();
3514     if (transaction != nullptr) {
3515         transaction->AddCommand(command, isRenderServiceCommand, followType, nodeId);
3516     } else {
3517         auto transactionProxy = RSTransactionProxy::GetInstance();
3518         if (!transactionProxy) {
3519             RS_LOGE("transactionProxy is nullptr");
3520             return false;
3521         }
3522         transactionProxy->AddCommand(command, isRenderServiceCommand, followType, nodeId);
3523     }
3524     return true;
3525 }
3526 
3527 DrawNodeChangeCallback RSNode::drawNodeChangeCallback_ = nullptr;
SetDrawNodeChangeCallback(DrawNodeChangeCallback callback)3528 void RSNode::SetDrawNodeChangeCallback(DrawNodeChangeCallback callback)
3529 {
3530     if (drawNodeChangeCallback_) {
3531         return;
3532     }
3533     drawNodeChangeCallback_ = callback;
3534 }
3535 
3536 } // namespace Rosen
3537 } // namespace OHOS
3538