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 #ifndef RENDER_SERVICE_CLIENT_CORE_UI_RS_NODE_H 16 #define RENDER_SERVICE_CLIENT_CORE_UI_RS_NODE_H 17 18 #include "animation/rs_animatable_property.h" 19 #include "animation/rs_animation_timing_curve.h" 20 #include "animation/rs_animation_timing_protocol.h" 21 #include "animation/rs_motion_path_option.h" 22 #include "animation/rs_property_accessors.h" 23 #include "animation/rs_transition_effect.h" 24 #include "common/rs_vector2.h" 25 #include "common/rs_vector4.h" 26 #include "pipeline/rs_recording_canvas.h" 27 #include "property/rs_properties.h" 28 #include "render/rs_path.h" 29 #include "render/rs_mask.h" 30 #include "ui/rs_base_node.h" 31 32 class SkCanvas; 33 34 namespace OHOS { 35 namespace Rosen { 36 using PropertyCallback = std::function<void()>; 37 class RSAnimation; 38 class RSCommand; 39 class RSImplicitAnimParam; 40 class RSBasePropertyAccessors; 41 42 class RS_EXPORT RSNode : public RSBaseNode { 43 public: 44 using WeakPtr = std::weak_ptr<RSNode>; 45 using SharedPtr = std::shared_ptr<RSNode>; 46 static inline constexpr RSUINodeType Type = RSUINodeType::RS_NODE; 47 48 virtual ~RSNode(); 49 std::string DumpNode(int depth) const override; 50 51 static std::vector<std::shared_ptr<RSAnimation>> Animate(const RSAnimationTimingProtocol& timingProtocol, 52 const RSAnimationTimingCurve& timingCurve, const PropertyCallback& callback, 53 const std::function<void()>& finshCallback = nullptr); 54 static void OpenImplicitAnimation(const RSAnimationTimingProtocol& timingProtocol, 55 const RSAnimationTimingCurve& timingCurve, const std::function<void()>& finishCallback = nullptr); 56 static std::vector<std::shared_ptr<RSAnimation>> CloseImplicitAnimation(); 57 static void AddKeyFrame( 58 float fraction, const RSAnimationTimingCurve& timingCurve, const PropertyCallback& callback); 59 static void AddKeyFrame(float fraction, const PropertyCallback& callback); 60 61 void NotifyTransition(const std::shared_ptr<const RSTransitionEffect>& effect, bool isTransitionIn); 62 63 void AddAnimation(const std::shared_ptr<RSAnimation>& animation); 64 void RemoveAllAnimations(); 65 void RemoveAnimation(const std::shared_ptr<RSAnimation>& animation); 66 void SetMotionPathOption(const std::shared_ptr<RSMotionPathOption>& motionPathOption); 67 const std::shared_ptr<RSMotionPathOption> GetMotionPathOption() const; 68 69 const RSProperties& GetStagingProperties() const; 70 71 virtual void SetBounds(const Vector4f& bounds); 72 virtual void SetBounds(float positionX, float positionY, float width, float height); 73 virtual void SetBoundsSize(const Vector2f& size); 74 virtual void SetBoundsSize(float width, float height); 75 virtual void SetBoundsWidth(float width); 76 virtual void SetBoundsHeight(float height); 77 void SetBoundsPosition(const Vector2f& boundsPosition); 78 void SetBoundsPosition(float positionX, float positionY); 79 void SetBoundsPositionX(float positionX); 80 void SetBoundsPositionY(float positionY); 81 82 void SetFrame(const Vector4f& frame); 83 void SetFrame(float positionX, float positionY, float width, float height); 84 void SetFrameSize(const Vector2f& size); 85 void SetFrameSize(float width, float height); 86 void SetFrameWidth(float width); 87 void SetFrameHeight(float height); 88 void SetFramePosition(const Vector2f& framePosition); 89 void SetFramePosition(float positionX, float positionY); 90 void SetFramePositionX(float positionX); 91 void SetFramePositionY(float positionY); 92 93 void SetPositionZ(float positionZ); 94 95 void SetPivot(const Vector2f& pivot); 96 void SetPivot(float pivotX, float pivotY); 97 void SetPivotX(float pivotX); 98 void SetPivotY(float pivotY); 99 100 void SetCornerRadius(float cornerRadius); 101 102 void SetRotation(const Quaternion& quaternion); 103 void SetRotation(float degreeX, float degreeY, float degreeZ); 104 void SetRotation(float degree); 105 void SetRotationX(float degree); 106 void SetRotationY(float degree); 107 108 void SetTranslate(const Vector2f& translate); 109 void SetTranslate(float translateX, float translateY, float translateZ); 110 void SetTranslateX(float translate); 111 void SetTranslateY(float translate); 112 void SetTranslateZ(float translate); 113 114 void SetScale(float scale); 115 void SetScale(float scaleX, float scaleY); 116 void SetScale(const Vector2f& scale); 117 void SetScaleX(float scale); 118 void SetScaleY(float scale); 119 120 void SetAlpha(float alpha); 121 122 void SetForegroundColor(uint32_t colorValue); 123 void SetBackgroundColor(uint32_t colorValue); 124 void SetBackgroundShader(std::shared_ptr<RSShader> shader); 125 126 void SetBgImage(std::shared_ptr<RSImage> image); 127 void SetBgImageSize(float width, float height); 128 void SetBgImageWidth(float width); 129 void SetBgImageHeight(float height); 130 void SetBgImagePosition(float positionX, float positionY); 131 void SetBgImagePositionX(float positionX); 132 void SetBgImagePositionY(float positionY); 133 134 void SetBorderColor(uint32_t colorValue); 135 void SetBorderWidth(float width); 136 void SetBorderStyle(uint32_t styleValue); 137 138 void SetSublayerTransform(Matrix3f sublayerTransform); 139 140 void SetBackgroundFilter(std::shared_ptr<RSFilter> backgroundFilter); 141 void SetFilter(std::shared_ptr<RSFilter> filter); 142 void SetCompositingFilter(std::shared_ptr<RSFilter> compositingFilter); 143 144 void SetShadowColor(uint32_t colorValue); 145 void SetShadowOffset(float offsetX, float offsetY); 146 void SetShadowOffsetX(float offsetX); 147 void SetShadowOffsetY(float offsetY); 148 void SetShadowAlpha(float alpha); 149 void SetShadowElevation(float elevation); 150 void SetShadowRadius(float radius); 151 void SetShadowPath(std::shared_ptr<RSPath> shadowpath); 152 153 void SetFrameGravity(Gravity gravity); 154 155 void SetClipBounds(std::shared_ptr<RSPath> clipToBounds); 156 void SetClipToBounds(bool clipToBounds); 157 void SetClipToFrame(bool clipToFrame); 158 159 void SetVisible(bool visible); 160 void SetPaintOrder(bool drawContentLast); 161 void SetMask(std::shared_ptr<RSMask> mask); 162 SetTransitionEffect(const std::shared_ptr<const RSTransitionEffect> & effect)163 void SetTransitionEffect(const std::shared_ptr<const RSTransitionEffect>& effect) 164 { 165 transitionEffect_ = effect; 166 } 167 GetType()168 RSUINodeType GetType() const override 169 { 170 return RSUINodeType::RS_NODE; 171 } 172 173 protected: 174 RSNode(bool isRenderServiceNode); 175 RSNode(const RSNode&) = delete; 176 RSNode(const RSNode&&) = delete; 177 RSNode& operator=(const RSNode&) = delete; 178 RSNode& operator=(const RSNode&&) = delete; 179 180 bool drawContentLast_ = false; 181 182 void OnAddChildren() override; 183 void OnRemoveChildren() override; 184 void AnimationFinish(long long animationId); 185 NeedForcedSendToRemote()186 virtual bool NeedForcedSendToRemote() const 187 { 188 return false; 189 } 190 191 private: 192 bool HasPropertyAnimation(const RSAnimatableProperty& property); 193 void FallbackAnimationsToRoot(); 194 void AddAnimationInner(const std::shared_ptr<RSAnimation>& animation); 195 void RemoveAnimationInner(const std::shared_ptr<RSAnimation>& animation); 196 void FinishAnimationByProperty(const RSAnimatableProperty& property); 197 198 std::unordered_map<AnimationId, std::shared_ptr<RSAnimation>> animations_; 199 std::unordered_map<RSAnimatableProperty, uint32_t> animatingPropertyNum_; 200 std::shared_ptr<RSMotionPathOption> motionPathOption_; 201 202 std::shared_ptr<const RSTransitionEffect> transitionEffect_ = nullptr; 203 204 RSProperties stagingProperties_; 205 206 friend class RSAnimation; 207 template<typename T> 208 friend class RSCurveAnimation; 209 template<typename T> 210 friend class RSKeyframeAnimation; 211 template<typename T> 212 friend class RSPropertyAnimation; 213 friend class RSPathAnimation; 214 friend class RSTransition; 215 friend class RSUIDirector; 216 friend class RSImplicitAnimator; 217 }; 218 } // namespace Rosen 219 } // namespace OHOS 220 221 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_NODE_H 222