• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
21 #include "animation/rs_animation_timing_curve.h"
22 #include "animation/rs_animation_timing_protocol.h"
23 
24 #include "common/rs_macros.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 class RSAnimation;
29 class RSPropertyBase;
30 class RSImplicitAnimationParam;
31 class RSTransitionEffect;
32 class RSMotionPathOption;
33 class RSNode;
34 
35 class RSC_EXPORT RSImplicitAnimator {
36 public:
37     RSImplicitAnimator() = default;
38     virtual ~RSImplicitAnimator() = default;
39 
40     void OpenImplicitAnimation(const RSAnimationTimingProtocol& timingProtocol,
41         const RSAnimationTimingCurve& timingCurve, const std::function<void()>& finishCallback);
42     std::vector<std::shared_ptr<RSAnimation>> CloseImplicitAnimation();
43 
44     void BeginImplicitKeyFrameAnimation(float fraction, const RSAnimationTimingCurve& timingCurve);
45     void BeginImplicitKeyFrameAnimation(float fraction);
46     void EndImplicitKeyFrameAnimation();
47 
48     void BeginImplicitTransition(const std::shared_ptr<const RSTransitionEffect>& effect);
49     void EndImplicitTransition();
50 
51     void BeginImplicitPathAnimation(const std::shared_ptr<RSMotionPathOption>& motionPathOption);
52     void EndImplicitPathAnimation();
53 
54     bool NeedImplicitAnimation();
55 
56     std::shared_ptr<RSAnimation> CreateImplicitAnimation(const std::shared_ptr<RSNode>& target,
57         std::shared_ptr<RSPropertyBase> property, const std::shared_ptr<RSPropertyBase>& startValue,
58         const std::shared_ptr<RSPropertyBase>& endValue);
59 
60     std::shared_ptr<RSAnimation> CreateImplicitTransition(RSNode& target, bool isTransitionIn);
61 
62 private:
63     void EndImplicitAnimation();
64     void BeginImplicitCurveAnimation();
65     void BeginImplicitSpringAnimation();
66 
67     void PushImplicitParam(const std::shared_ptr<RSImplicitAnimationParam>& implicitParam);
68     void PopImplicitParam();
69     void CreateEmptyAnimation();
70 
71     void SetPropertyValue(std::shared_ptr<RSPropertyBase> property, const std::shared_ptr<RSPropertyBase>& value);
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, PropertyId>, 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