1 /*
2 * Copyright (c) 2021-2022 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 <sstream>
20 #include <string>
21
22 #include "animation/rs_animation.h"
23 #include "animation/rs_implicit_animator.h"
24 #include "command/rs_node_command.h"
25 #include "common/rs_color.h"
26 #include "common/rs_obj_geometry.h"
27 #include "pipeline/rs_node_map.h"
28 #include "platform/common/rs_log.h"
29 #include "render/rs_path.h"
30 #include "transaction/rs_transaction_proxy.h"
31
32 namespace OHOS {
33 namespace Rosen {
34
RSNode(bool isRenderServiceNode)35 RSNode::RSNode(bool isRenderServiceNode) : RSBaseNode(isRenderServiceNode), stagingProperties_(false) {}
36
~RSNode()37 RSNode::~RSNode()
38 {
39 FallbackAnimationsToRoot();
40 }
41
OpenImplicitAnimation(const RSAnimationTimingProtocol & timingProtocol,const RSAnimationTimingCurve & timingCurve,const std::function<void ()> & finishCallback)42 void RSNode::OpenImplicitAnimation(const RSAnimationTimingProtocol& timingProtocol,
43 const RSAnimationTimingCurve& timingCurve, const std::function<void()>& finishCallback)
44 {
45 RSImplicitAnimator::Instance().OpenImplicitAnimation(timingProtocol, timingCurve, finishCallback);
46 }
47
CloseImplicitAnimation()48 std::vector<std::shared_ptr<RSAnimation>> RSNode::CloseImplicitAnimation()
49 {
50 return RSImplicitAnimator::Instance().CloseImplicitAnimation();
51 }
52
AddKeyFrame(float fraction,const RSAnimationTimingCurve & timingCurve,const PropertyCallback & propertyCallback)53 void RSNode::AddKeyFrame(
54 float fraction, const RSAnimationTimingCurve& timingCurve, const PropertyCallback& propertyCallback)
55 {
56 if (propertyCallback == nullptr) {
57 ROSEN_LOGE("Failed to add keyframe animation, property callback is null!");
58 return;
59 }
60
61 RSImplicitAnimator::Instance().BeginImplicitKeyFrameAnimation(fraction, timingCurve);
62 propertyCallback();
63 RSImplicitAnimator::Instance().EndImplicitKeyFrameAnimation();
64 }
65
AddKeyFrame(float fraction,const PropertyCallback & propertyCallback)66 void RSNode::AddKeyFrame(float fraction, const PropertyCallback& propertyCallback)
67 {
68 if (propertyCallback == nullptr) {
69 ROSEN_LOGE("Failed to add keyframe animation, property callback is null!");
70 return;
71 }
72
73 RSImplicitAnimator::Instance().BeginImplicitKeyFrameAnimation(fraction);
74 propertyCallback();
75 RSImplicitAnimator::Instance().EndImplicitKeyFrameAnimation();
76 }
77
Animate(const RSAnimationTimingProtocol & timingProtocol,const RSAnimationTimingCurve & timingCurve,const PropertyCallback & propertyCallback,const std::function<void ()> & finshCallback)78 std::vector<std::shared_ptr<RSAnimation>> RSNode::Animate(const RSAnimationTimingProtocol& timingProtocol,
79 const RSAnimationTimingCurve& timingCurve, const PropertyCallback& propertyCallback,
80 const std::function<void()>& finshCallback)
81 {
82 if (propertyCallback == nullptr) {
83 ROSEN_LOGE("Failed to add curve animation, property callback is null!");
84 return {};
85 }
86 OpenImplicitAnimation(timingProtocol, timingCurve, finshCallback);
87 propertyCallback();
88 return CloseImplicitAnimation();
89 }
90
FallbackAnimationsToRoot()91 void RSNode::FallbackAnimationsToRoot()
92 {
93 auto target = RSNodeMap::Instance().GetAnimationFallbackNode();
94
95 if (target == nullptr) {
96 ROSEN_LOGE("Failed to move animation to root, root node is null!");
97 return;
98 }
99 for (const auto& [animationId, animation] : animations_) {
100 target->AddAnimationInner(animation);
101 }
102 }
103
AddAnimationInner(const std::shared_ptr<RSAnimation> & animation)104 void RSNode::AddAnimationInner(const std::shared_ptr<RSAnimation>& animation)
105 {
106 animations_[animation->GetId()] = animation;
107 animatingPropertyNum_[animation->GetProperty()]++;
108 }
109
RemoveAnimationInner(const std::shared_ptr<RSAnimation> & animation)110 void RSNode::RemoveAnimationInner(const std::shared_ptr<RSAnimation>& animation)
111 {
112 auto animationItr = animations_.find(animation->GetId());
113 animations_.erase(animationItr);
114 animatingPropertyNum_[animation->GetProperty()]--;
115 }
116
FinishAnimationByProperty(const RSAnimatableProperty & property)117 void RSNode::FinishAnimationByProperty(const RSAnimatableProperty& property)
118 {
119 for (const auto& [animationId, animation] : animations_) {
120 if (animation->GetProperty() == property) {
121 animation->Finish();
122 }
123 }
124 }
125
GetStagingProperties() const126 const RSProperties& RSNode::GetStagingProperties() const
127 {
128 return stagingProperties_;
129 }
130
AddAnimation(const std::shared_ptr<RSAnimation> & animation)131 void RSNode::AddAnimation(const std::shared_ptr<RSAnimation>& animation)
132 {
133 if (animation == nullptr) {
134 ROSEN_LOGE("Failed to add animation, animation is null!");
135 return;
136 }
137
138 auto animationId = animation->GetId();
139 if (animations_.find(animationId) != animations_.end()) {
140 ROSEN_LOGE("Failed to add animation, animation already exists!");
141 return;
142 }
143
144 if (animation->GetDuration() <= 0) {
145 FinishAnimationByProperty(animation->GetProperty());
146 }
147
148 AddAnimationInner(animation);
149 animation->StartInner(std::static_pointer_cast<RSNode>(shared_from_this()));
150 }
151
RemoveAllAnimations()152 void RSNode::RemoveAllAnimations()
153 {
154 for (const auto& [id, animation] : animations_) {
155 RemoveAnimation(animation);
156 }
157 }
158
RemoveAnimation(const std::shared_ptr<RSAnimation> & animation)159 void RSNode::RemoveAnimation(const std::shared_ptr<RSAnimation>& animation)
160 {
161 if (animation == nullptr) {
162 ROSEN_LOGE("Failed to remove animation, animation is null!");
163 return;
164 }
165
166 if (animations_.find(animation->GetId()) == animations_.end()) {
167 ROSEN_LOGE("Failed to remove animation, animation not exists!");
168 return;
169 }
170
171 animation->Finish();
172 }
173
SetMotionPathOption(const std::shared_ptr<RSMotionPathOption> & motionPathOption)174 void RSNode::SetMotionPathOption(const std::shared_ptr<RSMotionPathOption>& motionPathOption)
175 {
176 motionPathOption_ = motionPathOption;
177 }
178
GetMotionPathOption() const179 const std::shared_ptr<RSMotionPathOption> RSNode::GetMotionPathOption() const
180 {
181 return motionPathOption_;
182 }
183
HasPropertyAnimation(const RSAnimatableProperty & property)184 bool RSNode::HasPropertyAnimation(const RSAnimatableProperty& property)
185 {
186 // check if any animation matches the property bitmask
187 auto pred = [property](const auto& it) -> bool {
188 return it.second > 0 && (static_cast<unsigned long long>(it.first) & static_cast<unsigned long long>(property));
189 };
190 return std::any_of(animatingPropertyNum_.begin(), animatingPropertyNum_.end(), pred);
191 }
192
193 namespace {
194 template<typename T>
IsValid(const T & value)195 bool IsValid(const T& value)
196 {
197 return true;
198 }
199 template<>
IsValid(const float & value)200 bool IsValid(const float& value)
201 {
202 return !isinf(value);
203 }
204 template<>
IsValid(const Vector2f & value)205 bool IsValid(const Vector2f& value)
206 {
207 return !value.IsInfinite();
208 }
209 template<>
IsValid(const Vector4f & value)210 bool IsValid(const Vector4f& value)
211 {
212 return !value.IsInfinite();
213 }
214 } // namespace
215
216 #define SET_ANIMATABLE_PROPERTY(propertyName, value, property) \
217 do { \
218 auto currentValue = stagingProperties_.Get##propertyName(); \
219 if (ROSEN_EQ(value, currentValue)) { \
220 return; \
221 } \
222 if (RSImplicitAnimator::Instance().NeedImplicitAnimaton() && IsValid(currentValue)) { \
223 RSImplicitAnimator::Instance().CreateImplicitAnimation(*this, property, currentValue, value); \
224 } else if (HasPropertyAnimation(property)) { \
225 std::unique_ptr<RSCommand> command = \
226 std::make_unique<RSNodeSet##propertyName##Delta>(GetId(), (value)-currentValue); \
227 auto transactionProxy = RSTransactionProxy::GetInstance(); \
228 if (transactionProxy != nullptr) { \
229 transactionProxy->AddCommand(command, IsRenderServiceNode()); \
230 if (NeedForcedSendToRemote()) { \
231 std::unique_ptr<RSCommand> commandForRemote = \
232 std::make_unique<RSNodeSet##propertyName##Delta>(GetId(), (value)-currentValue); \
233 transactionProxy->AddCommand(commandForRemote, true); \
234 } \
235 } \
236 stagingProperties_.Set##propertyName(value); \
237 } else { \
238 std::unique_ptr<RSCommand> command = std::make_unique<RSNodeSet##propertyName>(GetId(), value); \
239 auto transactionProxy = RSTransactionProxy::GetInstance(); \
240 if (transactionProxy != nullptr) { \
241 transactionProxy->AddCommand(command, IsRenderServiceNode()); \
242 if (NeedForcedSendToRemote()) { \
243 std::unique_ptr<RSCommand> commandForRemote = \
244 std::make_unique<RSNodeSet##propertyName>(GetId(), value); \
245 transactionProxy->AddCommand(commandForRemote, true); \
246 } \
247 } \
248 stagingProperties_.Set##propertyName(value); \
249 } \
250 } while (0)
251
252 #define SET_NONANIMATABLE_PROPERTY(propertyName, value) \
253 do { \
254 auto currentValue = stagingProperties_.Get##propertyName(); \
255 if (ROSEN_EQ(value, currentValue)) { \
256 return; \
257 } \
258 std::unique_ptr<RSCommand> command = std::make_unique<RSNodeSet##propertyName>(GetId(), value); \
259 auto transactionProxy = RSTransactionProxy::GetInstance(); \
260 if (transactionProxy != nullptr) { \
261 transactionProxy->AddCommand(command, IsRenderServiceNode()); \
262 if (NeedForcedSendToRemote()) { \
263 std::unique_ptr<RSCommand> commandForRemote = \
264 std::make_unique<RSNodeSet##propertyName>(GetId(), value); \
265 transactionProxy->AddCommand(commandForRemote, true); \
266 } \
267 } \
268 stagingProperties_.Set##propertyName(value); \
269 } while (0)
270
271 // alpha
SetAlpha(float alpha)272 void RSNode::SetAlpha(float alpha)
273 {
274 SET_ANIMATABLE_PROPERTY(Alpha, alpha, RSAnimatableProperty::ALPHA);
275 }
276
277 // Bounds
SetBounds(const Vector4f & bounds)278 void RSNode::SetBounds(const Vector4f& bounds)
279 {
280 SET_ANIMATABLE_PROPERTY(Bounds, bounds, RSAnimatableProperty::BOUNDS);
281 }
282
SetBounds(float positionX,float positionY,float width,float height)283 void RSNode::SetBounds(float positionX, float positionY, float width, float height)
284 {
285 SetBounds({ positionX, positionY, width, height });
286 }
287
SetBoundsSize(const Vector2f & size)288 void RSNode::SetBoundsSize(const Vector2f& size)
289 {
290 SET_ANIMATABLE_PROPERTY(BoundsSize, size, RSAnimatableProperty::BOUNDS_SIZE);
291 }
292
SetBoundsSize(float width,float height)293 void RSNode::SetBoundsSize(float width, float height)
294 {
295 SetBoundsSize({ width, height });
296 }
297
SetBoundsWidth(float width)298 void RSNode::SetBoundsWidth(float width)
299 {
300 SET_ANIMATABLE_PROPERTY(BoundsWidth, width, RSAnimatableProperty::BOUNDS_WIDTH);
301 }
302
SetBoundsHeight(float height)303 void RSNode::SetBoundsHeight(float height)
304 {
305 SET_ANIMATABLE_PROPERTY(BoundsHeight, height, RSAnimatableProperty::BOUNDS_HEIGHT);
306 }
307
SetBoundsPosition(const Vector2f & boundsPosition)308 void RSNode::SetBoundsPosition(const Vector2f& boundsPosition)
309 {
310 SET_ANIMATABLE_PROPERTY(BoundsPosition, boundsPosition, RSAnimatableProperty::BOUNDS_POSITION);
311 }
312
SetBoundsPosition(float positionX,float positionY)313 void RSNode::SetBoundsPosition(float positionX, float positionY)
314 {
315 SetBoundsPosition({ positionX, positionY });
316 }
317
SetBoundsPositionX(float positionX)318 void RSNode::SetBoundsPositionX(float positionX)
319 {
320 SET_ANIMATABLE_PROPERTY(BoundsPositionX, positionX, RSAnimatableProperty::BOUNDS_POSITION_X);
321 }
322
SetBoundsPositionY(float positionY)323 void RSNode::SetBoundsPositionY(float positionY)
324 {
325 SET_ANIMATABLE_PROPERTY(BoundsPositionY, positionY, RSAnimatableProperty::BOUNDS_POSITION_Y);
326 }
327
328 // Frame
SetFrame(const Vector4f & bounds)329 void RSNode::SetFrame(const Vector4f& bounds)
330 {
331 SET_ANIMATABLE_PROPERTY(Frame, bounds, RSAnimatableProperty::FRAME);
332 }
333
SetFrame(float positionX,float positionY,float width,float height)334 void RSNode::SetFrame(float positionX, float positionY, float width, float height)
335 {
336 SetFrame({ positionX, positionY, width, height });
337 }
338
SetFrameSize(const Vector2f & size)339 void RSNode::SetFrameSize(const Vector2f& size)
340 {
341 SET_ANIMATABLE_PROPERTY(FrameSize, size, RSAnimatableProperty::FRAME_SIZE);
342 }
343
SetFrameSize(float width,float height)344 void RSNode::SetFrameSize(float width, float height)
345 {
346 SetFrameSize({ width, height });
347 }
348
SetFrameWidth(float width)349 void RSNode::SetFrameWidth(float width)
350 {
351 SET_ANIMATABLE_PROPERTY(FrameWidth, width, RSAnimatableProperty::FRAME_WIDTH);
352 }
353
SetFrameHeight(float height)354 void RSNode::SetFrameHeight(float height)
355 {
356 SET_ANIMATABLE_PROPERTY(FrameHeight, height, RSAnimatableProperty::FRAME_HEIGHT);
357 }
358
SetFramePosition(const Vector2f & position)359 void RSNode::SetFramePosition(const Vector2f& position)
360 {
361 SET_ANIMATABLE_PROPERTY(FramePosition, position, RSAnimatableProperty::FRAME_POSITION);
362 }
363
SetFramePosition(float positionX,float positionY)364 void RSNode::SetFramePosition(float positionX, float positionY)
365 {
366 SetFramePosition({ positionX, positionY });
367 }
368
SetFramePositionX(float positionX)369 void RSNode::SetFramePositionX(float positionX)
370 {
371 SET_ANIMATABLE_PROPERTY(FramePositionX, positionX, RSAnimatableProperty::FRAME_POSITION_X);
372 }
373
SetFramePositionY(float positionY)374 void RSNode::SetFramePositionY(float positionY)
375 {
376 SET_ANIMATABLE_PROPERTY(FramePositionY, positionY, RSAnimatableProperty::FRAME_POSITION_Y);
377 }
378
SetPositionZ(float positionZ)379 void RSNode::SetPositionZ(float positionZ)
380 {
381 SET_ANIMATABLE_PROPERTY(PositionZ, positionZ, RSAnimatableProperty::POSITION_Z);
382 }
383
384 // pivot
SetPivot(const Vector2f & pivot)385 void RSNode::SetPivot(const Vector2f& pivot)
386 {
387 SET_ANIMATABLE_PROPERTY(Pivot, pivot, RSAnimatableProperty::PIVOT);
388 }
389
SetPivot(float pivotX,float pivotY)390 void RSNode::SetPivot(float pivotX, float pivotY)
391 {
392 SetPivot({ pivotX, pivotY });
393 }
394
SetPivotX(float pivotX)395 void RSNode::SetPivotX(float pivotX)
396 {
397 SET_ANIMATABLE_PROPERTY(PivotX, pivotX, RSAnimatableProperty::PIVOT_X);
398 }
399
SetPivotY(float pivotY)400 void RSNode::SetPivotY(float pivotY)
401 {
402 SET_ANIMATABLE_PROPERTY(PivotY, pivotY, RSAnimatableProperty::PIVOT_Y);
403 }
404
SetCornerRadius(float cornerRadius)405 void RSNode::SetCornerRadius(float cornerRadius)
406 {
407 SET_ANIMATABLE_PROPERTY(CornerRadius, cornerRadius, RSAnimatableProperty::CORNER_RADIUS);
408 }
409
410 // transform
SetRotation(const Quaternion & quaternion)411 void RSNode::SetRotation(const Quaternion& quaternion)
412 {
413 SET_ANIMATABLE_PROPERTY(Quaternion, quaternion, RSAnimatableProperty::ROTATION_3D);
414 }
415
SetRotation(float degree)416 void RSNode::SetRotation(float degree)
417 {
418 SET_ANIMATABLE_PROPERTY(Rotation, degree, RSAnimatableProperty::ROTATION);
419 }
420
SetRotation(float degreeX,float degreeY,float degreeZ)421 void RSNode::SetRotation(float degreeX, float degreeY, float degreeZ)
422 {
423 SetRotationX(degreeX);
424 SetRotationY(degreeY);
425 SetRotation(degreeZ);
426 }
427
SetRotationX(float degree)428 void RSNode::SetRotationX(float degree)
429 {
430 SET_ANIMATABLE_PROPERTY(RotationX, degree, RSAnimatableProperty::ROTATION_X);
431 }
432
SetRotationY(float degree)433 void RSNode::SetRotationY(float degree)
434 {
435 SET_ANIMATABLE_PROPERTY(RotationY, degree, RSAnimatableProperty::ROTATION_Y);
436 }
437
SetTranslate(const Vector2f & translate)438 void RSNode::SetTranslate(const Vector2f& translate)
439 {
440 SET_ANIMATABLE_PROPERTY(Translate, translate, RSAnimatableProperty::TRANSLATE);
441 }
442
SetTranslate(float translateX,float translateY,float translateZ)443 void RSNode::SetTranslate(float translateX, float translateY, float translateZ)
444 {
445 SetTranslate({ translateX, translateY });
446 SetTranslateZ(translateZ);
447 }
448
SetTranslateX(float translate)449 void RSNode::SetTranslateX(float translate)
450 {
451 SET_ANIMATABLE_PROPERTY(TranslateX, translate, RSAnimatableProperty::TRANSLATE_X);
452 }
453
SetTranslateY(float translate)454 void RSNode::SetTranslateY(float translate)
455 {
456 SET_ANIMATABLE_PROPERTY(TranslateY, translate, RSAnimatableProperty::TRANSLATE_Y);
457 }
458
SetTranslateZ(float translate)459 void RSNode::SetTranslateZ(float translate)
460 {
461 SET_ANIMATABLE_PROPERTY(TranslateZ, translate, RSAnimatableProperty::TRANSLATE_Z);
462 }
463
SetScale(float scale)464 void RSNode::SetScale(float scale)
465 {
466 SetScale({ scale, scale });
467 }
468
SetScale(float scaleX,float scaleY)469 void RSNode::SetScale(float scaleX, float scaleY)
470 {
471 SetScale({ scaleX, scaleY });
472 }
473
SetScale(const Vector2f & scale)474 void RSNode::SetScale(const Vector2f& scale)
475 {
476 SET_ANIMATABLE_PROPERTY(Scale, scale, RSAnimatableProperty::SCALE);
477 }
478
SetScaleX(float scale)479 void RSNode::SetScaleX(float scale)
480 {
481 SET_ANIMATABLE_PROPERTY(ScaleX, scale, RSAnimatableProperty::SCALE_X);
482 }
483
SetScaleY(float scale)484 void RSNode::SetScaleY(float scale)
485 {
486 SET_ANIMATABLE_PROPERTY(ScaleY, scale, RSAnimatableProperty::SCALE_Y);
487 }
488
489 // foreground
SetForegroundColor(uint32_t colorValue)490 void RSNode::SetForegroundColor(uint32_t colorValue)
491 {
492 auto color = Color::FromArgbInt(colorValue);
493 SET_ANIMATABLE_PROPERTY(ForegroundColor, color, RSAnimatableProperty::FOREGROUND_COLOR);
494 }
495
SetBackgroundColor(uint32_t colorValue)496 void RSNode::SetBackgroundColor(uint32_t colorValue)
497 {
498 auto color = Color::FromArgbInt(colorValue);
499 SET_ANIMATABLE_PROPERTY(BackgroundColor, color, RSAnimatableProperty::BACKGROUND_COLOR);
500 }
501
SetBackgroundShader(std::shared_ptr<RSShader> shader)502 void RSNode::SetBackgroundShader(std::shared_ptr<RSShader> shader)
503 {
504 SET_NONANIMATABLE_PROPERTY(BackgroundShader, shader);
505 }
506
507 // background
SetBgImage(std::shared_ptr<RSImage> image)508 void RSNode::SetBgImage(std::shared_ptr<RSImage> image)
509 {
510 SET_NONANIMATABLE_PROPERTY(BgImage, image);
511 }
512
SetBgImageSize(float width,float height)513 void RSNode::SetBgImageSize(float width, float height)
514 {
515 SetBgImageWidth(width);
516 SetBgImageHeight(height);
517 }
518
SetBgImageWidth(float width)519 void RSNode::SetBgImageWidth(float width)
520 {
521 SET_ANIMATABLE_PROPERTY(BgImageWidth, width, RSAnimatableProperty::BGIMAGE_WIDTH);
522 }
523
SetBgImageHeight(float height)524 void RSNode::SetBgImageHeight(float height)
525 {
526 SET_ANIMATABLE_PROPERTY(BgImageHeight, height, RSAnimatableProperty::BGIMAGE_HEIGHT);
527 }
528
SetBgImagePosition(float positionX,float positionY)529 void RSNode::SetBgImagePosition(float positionX, float positionY)
530 {
531 SetBgImagePositionX(positionX);
532 SetBgImagePositionY(positionY);
533 }
534
SetBgImagePositionX(float positionX)535 void RSNode::SetBgImagePositionX(float positionX)
536 {
537 SET_ANIMATABLE_PROPERTY(BgImagePositionX, positionX, RSAnimatableProperty::BGIMAGE_POSITION_X);
538 }
539
SetBgImagePositionY(float positionY)540 void RSNode::SetBgImagePositionY(float positionY)
541 {
542 SET_ANIMATABLE_PROPERTY(BgImagePositionY, positionY, RSAnimatableProperty::BGIMAGE_POSITION_Y);
543 }
544
545 // border
SetBorderColor(uint32_t colorValue)546 void RSNode::SetBorderColor(uint32_t colorValue)
547 {
548 auto color = Color::FromArgbInt(colorValue);
549 SET_ANIMATABLE_PROPERTY(BorderColor, color, RSAnimatableProperty::BORDER_COLOR);
550 }
551
SetBorderWidth(float width)552 void RSNode::SetBorderWidth(float width)
553 {
554 SET_ANIMATABLE_PROPERTY(BorderWidth, width, RSAnimatableProperty::BORDER_WIDTH);
555 }
556
SetBorderStyle(uint32_t styleValue)557 void RSNode::SetBorderStyle(uint32_t styleValue)
558 {
559 BorderStyle style = static_cast<BorderStyle>(styleValue);
560 SET_NONANIMATABLE_PROPERTY(BorderStyle, style);
561 }
562
563 // others
SetSublayerTransform(Matrix3f sublayerTransform)564 void RSNode::SetSublayerTransform(Matrix3f sublayerTransform)
565 {
566 SET_ANIMATABLE_PROPERTY(SublayerTransform, sublayerTransform, RSAnimatableProperty::SUB_LAYER_TRANSFORM);
567 }
568
SetBackgroundFilter(std::shared_ptr<RSFilter> backgroundFilter)569 void RSNode::SetBackgroundFilter(std::shared_ptr<RSFilter> backgroundFilter)
570 {
571 SET_ANIMATABLE_PROPERTY(BackgroundFilter, backgroundFilter, RSAnimatableProperty::BACKGROUND_FILTER);
572 }
573
SetFilter(std::shared_ptr<RSFilter> filter)574 void RSNode::SetFilter(std::shared_ptr<RSFilter> filter)
575 {
576 SET_ANIMATABLE_PROPERTY(Filter, filter, RSAnimatableProperty::FILTER);
577 }
578
SetCompositingFilter(std::shared_ptr<RSFilter> compositingFilter)579 void RSNode::SetCompositingFilter(std::shared_ptr<RSFilter> compositingFilter) {}
580
SetShadowColor(uint32_t colorValue)581 void RSNode::SetShadowColor(uint32_t colorValue)
582 {
583 auto color = Color::FromArgbInt(colorValue);
584 SET_ANIMATABLE_PROPERTY(ShadowColor, color, RSAnimatableProperty::SHADOW_COLOR);
585 }
586
SetShadowOffset(float offsetX,float offsetY)587 void RSNode::SetShadowOffset(float offsetX, float offsetY)
588 {
589 SetShadowOffsetX(offsetX);
590 SetShadowOffsetY(offsetY);
591 }
592
SetShadowOffsetX(float offsetX)593 void RSNode::SetShadowOffsetX(float offsetX)
594 {
595 SET_ANIMATABLE_PROPERTY(ShadowOffsetX, offsetX, RSAnimatableProperty::SHADOW_OFFSET_X);
596 }
597
SetShadowOffsetY(float offsetY)598 void RSNode::SetShadowOffsetY(float offsetY)
599 {
600 SET_ANIMATABLE_PROPERTY(ShadowOffsetY, offsetY, RSAnimatableProperty::SHADOW_OFFSET_Y);
601 }
602
SetShadowAlpha(float alpha)603 void RSNode::SetShadowAlpha(float alpha)
604 {
605 SET_ANIMATABLE_PROPERTY(ShadowAlpha, alpha, RSAnimatableProperty::SHADOW_ALPHA);
606 }
607
SetShadowElevation(float elevation)608 void RSNode::SetShadowElevation(float elevation)
609 {
610 SET_ANIMATABLE_PROPERTY(ShadowElevation, elevation, RSAnimatableProperty::SHADOW_ELEVATION);
611 }
612
SetShadowRadius(float radius)613 void RSNode::SetShadowRadius(float radius)
614 {
615 SET_ANIMATABLE_PROPERTY(ShadowRadius, radius, RSAnimatableProperty::SHADOW_RADIUS);
616 }
617
SetShadowPath(std::shared_ptr<RSPath> shadowpath)618 void RSNode::SetShadowPath(std::shared_ptr<RSPath> shadowpath)
619 {
620 SET_NONANIMATABLE_PROPERTY(ShadowPath, shadowpath);
621 }
622
SetFrameGravity(Gravity gravity)623 void RSNode::SetFrameGravity(Gravity gravity)
624 {
625 SET_NONANIMATABLE_PROPERTY(FrameGravity, gravity);
626 }
627
SetClipBounds(std::shared_ptr<RSPath> path)628 void RSNode::SetClipBounds(std::shared_ptr<RSPath> path)
629 {
630 SET_NONANIMATABLE_PROPERTY(ClipBounds, path);
631 }
632
SetClipToBounds(bool clipToBounds)633 void RSNode::SetClipToBounds(bool clipToBounds)
634 {
635 SET_NONANIMATABLE_PROPERTY(ClipToBounds, clipToBounds);
636 }
637
SetClipToFrame(bool clipToFrame)638 void RSNode::SetClipToFrame(bool clipToFrame)
639 {
640 SET_NONANIMATABLE_PROPERTY(ClipToFrame, clipToFrame);
641 }
642
SetVisible(bool visible)643 void RSNode::SetVisible(bool visible)
644 {
645 SET_NONANIMATABLE_PROPERTY(Visible, visible);
646 if (transitionEffect_ != nullptr) {
647 NotifyTransition(transitionEffect_, visible);
648 }
649 }
650
NotifyTransition(const std::shared_ptr<const RSTransitionEffect> & effect,bool isTransitionIn)651 void RSNode::NotifyTransition(const std::shared_ptr<const RSTransitionEffect>& effect, bool isTransitionIn)
652 {
653 if (!RSImplicitAnimator::Instance().NeedImplicitAnimaton()) {
654 return;
655 }
656 RSImplicitAnimator::Instance().BeginImplicitTransition(effect);
657 RSImplicitAnimator::Instance().CreateImplicitTransition(*this, isTransitionIn);
658 RSImplicitAnimator::Instance().EndImplicitTransition();
659 }
660
OnAddChildren()661 void RSNode::OnAddChildren()
662 {
663 if (transitionEffect_ != nullptr) {
664 NotifyTransition(transitionEffect_, true);
665 }
666 }
667
OnRemoveChildren()668 void RSNode::OnRemoveChildren()
669 {
670 if (transitionEffect_ != nullptr) {
671 NotifyTransition(transitionEffect_, false);
672 }
673 }
674
AnimationFinish(long long animationId)675 void RSNode::AnimationFinish(long long animationId)
676 {
677 auto animationItr = animations_.find(animationId);
678 if (animationItr == animations_.end()) {
679 ROSEN_LOGE("Failed to find animation[%llu]!", animationId);
680 return;
681 }
682
683 auto animation = animationItr->second;
684 if (animation == nullptr) {
685 ROSEN_LOGE("Failed to finish animation[%llu], animation is null!", animationId);
686 return;
687 }
688
689 animation->CallFinishCallback();
690 RemoveAnimationInner(animation);
691 }
692
SetPaintOrder(bool drawContentLast)693 void RSNode::SetPaintOrder(bool drawContentLast)
694 {
695 drawContentLast_ = drawContentLast;
696 }
697
DumpNode(int depth) const698 std::string RSNode::DumpNode(int depth) const
699 {
700 std::stringstream ss;
701 ss << RSBaseNode::DumpNode(depth);
702 if (!animations_.empty()) {
703 ss << " animation:" << std::to_string(animations_.size());
704 }
705 ss << " " << stagingProperties_.Dump();
706 return ss.str();
707 }
708
SetMask(std::shared_ptr<RSMask> mask)709 void RSNode::SetMask(std::shared_ptr<RSMask> mask)
710 {
711 SET_NONANIMATABLE_PROPERTY(Mask, mask);
712 }
713 } // namespace Rosen
714 } // namespace OHOS
715