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_ANIMATOR_H 17 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_IMPLICIT_ANIMATOR_H 18 19 #include <stack> 20 #include <utility> 21 #include <vector> 22 23 #include "animation/rs_animation_timing_curve.h" 24 #include "animation/rs_animation_timing_protocol.h" 25 #include "common/rs_macros.h" 26 27 namespace OHOS { 28 namespace Rosen { 29 class AnimationFinishCallback; 30 class AnimationRepeatCallback; 31 class RSAnimation; 32 class RSPropertyBase; 33 class RSImplicitAnimationParam; 34 class RSTransitionEffect; 35 class RSMotionPathOption; 36 class RSNode; 37 38 class RSC_EXPORT RSImplicitAnimator { 39 public: 40 RSImplicitAnimator() = default; 41 virtual ~RSImplicitAnimator() = default; 42 43 // open implicit animation with given animation options, finish callback and repeatcallback 44 int OpenImplicitAnimation(const RSAnimationTimingProtocol& timingProtocol, 45 const RSAnimationTimingCurve& timingCurve, std::shared_ptr<AnimationFinishCallback>&& finishCallback, 46 std::shared_ptr<AnimationRepeatCallback>&& repeatCallback); 47 // open implicit animation with given animation options and finish callback 48 int OpenImplicitAnimation(const RSAnimationTimingProtocol& timingProtocol, 49 const RSAnimationTimingCurve& timingCurve, std::shared_ptr<AnimationFinishCallback>&& finishCallback); 50 // open implicit animation with current options and given finish callback 51 int OpenImplicitAnimation(std::shared_ptr<AnimationFinishCallback>&& finishCallback); 52 // open implicit animation with current callback and given timing protocol & curve 53 int OpenImplicitAnimation( 54 const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve); 55 56 // close implicit animation and return all animations 57 std::vector<std::shared_ptr<RSAnimation>> CloseImplicitAnimation(); 58 59 void BeginImplicitKeyFrameAnimation(float fraction, const RSAnimationTimingCurve& timingCurve); 60 void BeginImplicitKeyFrameAnimation(float fraction); 61 void EndImplicitKeyFrameAnimation(); 62 63 void BeginImplicitDurationKeyFrameAnimation(int duration, const RSAnimationTimingCurve& timingCurve); 64 void EndImplicitDurationKeyFrameAnimation(); 65 66 void BeginImplicitTransition(const std::shared_ptr<const RSTransitionEffect>& effect, bool isTransitionIn); 67 void EndImplicitTransition(); 68 69 void BeginImplicitPathAnimation(const std::shared_ptr<RSMotionPathOption>& motionPathOption); 70 void EndImplicitPathAnimation(); 71 72 bool NeedImplicitAnimation(); 73 74 void CreateImplicitAnimation(const std::shared_ptr<RSNode>& target, std::shared_ptr<RSPropertyBase> property, 75 const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue); 76 77 void CreateImplicitAnimationWithInitialVelocity(const std::shared_ptr<RSNode>& target, 78 const std::shared_ptr<RSPropertyBase>& property, const std::shared_ptr<RSPropertyBase>& startValue, 79 const std::shared_ptr<RSPropertyBase>& endValue, const std::shared_ptr<RSPropertyBase>& velocity); 80 81 void CreateImplicitTransition(RSNode& target); 82 void CancelImplicitAnimation( 83 const std::shared_ptr<RSNode>& target, const std::shared_ptr<RSPropertyBase>& property); 84 85 private: 86 void EndImplicitAnimation(); 87 void BeginImplicitCurveAnimation(); 88 void BeginImplicitSpringAnimation(); 89 void BeginImplicitInterpolatingSpringAnimation(); 90 void BeginImplicitCancelAnimation(); 91 92 void CloseImplicitAnimationInner(); 93 bool ProcessEmptyAnimations(const std::shared_ptr<AnimationFinishCallback>& finishCallback); 94 95 void PushImplicitParam(const std::shared_ptr<RSImplicitAnimationParam>& implicitParam); 96 void PopImplicitParam(); 97 void CreateEmptyAnimation(); 98 99 void SetPropertyValue(std::shared_ptr<RSPropertyBase> property, const std::shared_ptr<RSPropertyBase>& value); 100 101 void ExecuteWithoutAnimation(const std::function<void()>& callback); 102 103 std::stack<std::tuple<RSAnimationTimingProtocol, RSAnimationTimingCurve, 104 const std::shared_ptr<AnimationFinishCallback>, std::shared_ptr<AnimationRepeatCallback>>> 105 globalImplicitParams_; 106 std::stack<std::shared_ptr<RSImplicitAnimationParam>> implicitAnimationParams_; 107 std::stack<std::vector<std::pair<std::shared_ptr<RSAnimation>, NodeId>>> implicitAnimations_; 108 std::stack<std::map<std::pair<NodeId, PropertyId>, std::shared_ptr<RSAnimation>>> keyframeAnimations_; 109 std::stack<std::tuple<bool, int, int>> durationKeyframeParams_; 110 111 bool implicitAnimationDisabled_ { false }; 112 friend class RSNode; 113 }; 114 } // namespace Rosen 115 } // namespace OHOS 116 117 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_IMPLICIT_ANIMATOR_H 118