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 #ifndef RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_IMPLICIT_ANIMATION_PARAM_H 17 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_IMPLICIT_ANIMATION_PARAM_H 18 19 #include <functional> 20 #include <memory> 21 #include <vector> 22 23 #include "animation/rs_animation_timing_curve.h" 24 #include "animation/rs_animation_timing_protocol.h" 25 #include "modifier/rs_property.h" 26 27 namespace OHOS { 28 namespace Rosen { 29 enum class ImplicitAnimationParamType { 30 INVALID, 31 CURVE, 32 KEYFRAME, 33 PATH, 34 SPRING, 35 INTERPOLATING_SPRING, 36 TRANSITION, 37 CANCEL 38 }; 39 class RSAnimation; 40 class RSPropertyBase; 41 class RSMotionPathOption; 42 class RSTransition; 43 class RSTransitionEffect; 44 45 class RSImplicitAnimationParam { 46 public: 47 virtual ~RSImplicitAnimationParam() = default; 48 ImplicitAnimationParamType GetType() const; 49 50 protected: 51 explicit RSImplicitAnimationParam(const RSAnimationTimingProtocol& timingProtocol, ImplicitAnimationParamType type); 52 void ApplyTimingProtocol(const std::shared_ptr<RSAnimation>& animation) const; 53 ImplicitAnimationParamType animationType_ { ImplicitAnimationParamType::INVALID }; 54 55 private: 56 RSAnimationTimingProtocol timingProtocol_; 57 }; 58 59 class RSImplicitCancelAnimationParam : public RSImplicitAnimationParam { 60 public: 61 RSImplicitCancelAnimationParam(const RSAnimationTimingProtocol& timingProtocol); 62 63 ~RSImplicitCancelAnimationParam() override = default; 64 65 void AddPropertyToPendingSyncList(const std::shared_ptr<RSPropertyBase>& property); 66 bool SyncProperties(); 67 68 std::shared_ptr<RSAnimation> CreateEmptyAnimation(std::shared_ptr<RSPropertyBase> property, 69 const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const; 70 71 private: 72 bool ExecuteSyncPropertiesTask( 73 RSNodeGetShowingPropertiesAndCancelAnimation::PropertiesMap&& propertiesMap, bool isRenderService); 74 std::vector<std::shared_ptr<RSPropertyBase>> pendingSyncList_; 75 }; 76 77 class RSImplicitCurveAnimationParam : public RSImplicitAnimationParam { 78 public: 79 RSImplicitCurveAnimationParam( 80 const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve); 81 82 ~RSImplicitCurveAnimationParam() override = default; 83 84 std::shared_ptr<RSAnimation> CreateAnimation(std::shared_ptr<RSPropertyBase> property, 85 const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const; 86 87 private: 88 RSAnimationTimingCurve timingCurve_; 89 }; 90 91 class RSImplicitKeyframeAnimationParam : public RSImplicitAnimationParam { 92 public: 93 RSImplicitKeyframeAnimationParam( 94 const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve, 95 float fraction, int duration); 96 97 ~RSImplicitKeyframeAnimationParam() override = default; 98 99 std::shared_ptr<RSAnimation> CreateAnimation( 100 std::shared_ptr<RSPropertyBase> property, const bool& isCreateDurationKeyframe, const int& startDuration, 101 const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const; 102 103 void AddKeyframe(std::shared_ptr<RSAnimation>& animation, const std::shared_ptr<RSPropertyBase>& startValue, 104 const std::shared_ptr<RSPropertyBase>& endValue) const; 105 106 void AddKeyframe(std::shared_ptr<RSAnimation>& animation, const int startDuration, 107 const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const; 108 109 private: 110 RSAnimationTimingCurve timingCurve_; 111 float fraction_; 112 int duration_; 113 }; 114 115 class RSImplicitPathAnimationParam : public RSImplicitAnimationParam { 116 public: 117 RSImplicitPathAnimationParam(const RSAnimationTimingProtocol& timingProtocol, 118 const RSAnimationTimingCurve& timingCurve, const std::shared_ptr<RSMotionPathOption>& motionPathOption); 119 120 ~RSImplicitPathAnimationParam() override = default; 121 122 std::shared_ptr<RSAnimation> CreateAnimation(std::shared_ptr<RSPropertyBase> property, 123 const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const; 124 125 private: 126 RSAnimationTimingCurve timingCurve_; 127 std::shared_ptr<RSMotionPathOption> motionPathOption_; 128 }; 129 130 class RSImplicitSpringAnimationParam : public RSImplicitAnimationParam { 131 public: 132 RSImplicitSpringAnimationParam( 133 const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve); 134 ~RSImplicitSpringAnimationParam() override = default; 135 136 std::shared_ptr<RSAnimation> CreateAnimation(std::shared_ptr<RSPropertyBase> property, 137 const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const; 138 139 private: 140 RSAnimationTimingCurve timingCurve_; 141 }; 142 143 class RSImplicitInterpolatingSpringAnimationParam : public RSImplicitAnimationParam { 144 public: 145 RSImplicitInterpolatingSpringAnimationParam( 146 const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve); 147 ~RSImplicitInterpolatingSpringAnimationParam() override = default; 148 149 std::shared_ptr<RSAnimation> CreateAnimation(std::shared_ptr<RSPropertyBase> property, 150 const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const; 151 152 private: 153 RSAnimationTimingCurve timingCurve_; 154 }; 155 156 class RSImplicitTransitionParam : public RSImplicitAnimationParam { 157 public: 158 RSImplicitTransitionParam(const RSAnimationTimingProtocol& timingProtocol, 159 const RSAnimationTimingCurve& timingCurve, const std::shared_ptr<const RSTransitionEffect>& effect, 160 bool isTransitionIn); 161 ~RSImplicitTransitionParam() override = default; 162 163 std::shared_ptr<RSAnimation> CreateAnimation(); 164 165 std::shared_ptr<RSAnimation> CreateAnimation(const std::shared_ptr<RSPropertyBase>& property, 166 const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue); 167 168 private: 169 RSAnimationTimingCurve timingCurve_; 170 171 bool isTransitionIn_; 172 std::shared_ptr<RSTransition> transition_; 173 const std::shared_ptr<const RSTransitionEffect> effect_; 174 }; 175 } // namespace Rosen 176 } // namespace OHOS 177 178 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_IMPLICIT_ANIMATION_PARAM_H 179