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 #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 21 #include "animation/rs_animation.h" 22 #include "animation/rs_animation_timing_curve.h" 23 #include "animation/rs_implicit_animation_param.h" 24 #include "platform/common/rs_log.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 class RSImplicitAnimator { 29 public: 30 virtual ~RSImplicitAnimator() = default; 31 static RSImplicitAnimator& Instance(); 32 33 void OpenImplicitAnimation(const RSAnimationTimingProtocol& timingProtocol, 34 const RSAnimationTimingCurve& timingCurve, const std::function<void()>& finishCallback); 35 std::vector<std::shared_ptr<RSAnimation>> CloseImplicitAnimation(); 36 void BeginImplicitKeyFrameAnimation(float fraction, const RSAnimationTimingCurve& timingCurve); 37 void BeginImplicitKeyFrameAnimation(float fraction); 38 void BeginImplicitTransition(const std::shared_ptr<const RSTransitionEffect>& effect); 39 void EndImplicitTransition(); 40 void EndImplicitKeyFrameAnimation(); 41 bool NeedImplicitAnimaton(); 42 43 template<typename T> 44 std::shared_ptr<RSAnimation> CreateImplicitAnimation( 45 RSNode& target, const RSAnimatableProperty& property, const T& startValue, const T& endValue); 46 47 std::shared_ptr<RSAnimation> CreateImplicitTransition(RSNode& target, bool isTransitionIn); 48 49 private: 50 RSImplicitAnimator() = default; 51 52 void BeginImplicitCurveAnimation(); 53 void EndImplicitCurveAnimation(); 54 void BeginImplicitPathAnimation(const std::shared_ptr<RSMotionPathOption>& motionPathOption); 55 void EndImplicitPathAnimation(); 56 void PushImplicitParam(const std::shared_ptr<RSImplicitAnimationParam>& implicitParam); 57 void PopImplicitParam(); 58 void ProcessPreCreateAnimation(const RSNode& target, const RSAnimatableProperty& property); 59 void ProcessPostCreateAnimation(const RSNode& target, const RSAnimatableProperty& property); 60 void CreateEmptyAnimation(); 61 62 template<typename T> SetPropertyValue(RSNode & target,const RSAnimatableProperty & property,const T & value)63 void SetPropertyValue(RSNode& target, const RSAnimatableProperty& property, const T& value) 64 { 65 std::shared_ptr<RSBasePropertyAccessors> propertyAccess = RSBasePropertyAccessors::GetAccessor(property); 66 auto accessors = std::static_pointer_cast<RSPropertyAccessors<T>>(propertyAccess); 67 if (accessors->setter_ == nullptr) { 68 return; 69 } 70 (target.stagingProperties_.*accessors->setter_)(value); 71 } 72 73 std::stack<std::tuple<RSAnimationTimingProtocol, RSAnimationTimingCurve, std::function<void()>>> 74 globalImplicitParams_; 75 std::stack<std::shared_ptr<RSImplicitAnimationParam>> implicitAnimationParams_; 76 std::stack<std::vector<std::pair<std::shared_ptr<RSAnimation>, NodeId>>> implicitAnimations_; 77 std::stack<std::map<std::pair<NodeId, RSAnimatableProperty>, std::shared_ptr<RSAnimation>>> keyframeAnimations_; 78 }; 79 } // namespace Rosen 80 } // namespace OHOS 81 82 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_IMPLICIT_ANIMATOR_H 83