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