• 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_ANIMATION_TIMING_CURVE_H
17 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_ANIMATION_TIMING_CURVE_H
18 
19 #include <functional>
20 #include <map>
21 #include <memory>
22 
23 #include "common/rs_macros.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 class RSInterpolator;
28 enum class StepsCurvePosition;
29 class RSC_EXPORT RSAnimationTimingCurve final {
30 public:
31     static const RSAnimationTimingCurve DEFAULT;
32     static const RSAnimationTimingCurve LINEAR;
33     static const RSAnimationTimingCurve EASE;
34     static const RSAnimationTimingCurve EASE_IN;
35     static const RSAnimationTimingCurve EASE_OUT;
36     static const RSAnimationTimingCurve EASE_IN_OUT;
37     static const RSAnimationTimingCurve SPRING;
38     static const RSAnimationTimingCurve INTERACTIVE_SPRING;
39 
40     static RSAnimationTimingCurve CreateCustomCurve(const std::function<float(float)>& customCurveFunc);
41     static RSAnimationTimingCurve CreateCubicCurve(float ctrlX1, float ctrlY1, float ctrlX2, float ctrlY2);
42     static RSAnimationTimingCurve CreateStepsCurve(int32_t steps, StepsCurvePosition position);
43     // Create interpolating spring, which duration is determined by TimingProtocol. Multiple animations on the same
44     // property will run simultaneously and act additively.
45     static RSAnimationTimingCurve CreateSpringCurve(float velocity, float mass, float stiffness, float damping);
46     // Create interpolating spring, which duration is determined by the spring model. Multiple animations on the same
47     // property will run simultaneously and act additively.
48     static RSAnimationTimingCurve CreateInterpolatingSpring(float mass, float stiffness, float damping, float velocity);
49     // Create physical spring, which duration is determined by the spring model. When mixed with other physical spring
50     // animations on the same property, each animation will be replaced by their successor, preserving velocity from one
51     // animation to the next.
52     static RSAnimationTimingCurve CreateSpring(float response, float dampingRatio, float blendDuration = 0.0f);
53 
54     RSAnimationTimingCurve();
55     RSAnimationTimingCurve(const RSAnimationTimingCurve& timingCurve) = default;
56     RSAnimationTimingCurve& operator=(const RSAnimationTimingCurve& timingCurve) = default;
57     virtual ~RSAnimationTimingCurve() = default;
58 
59     enum class CurveType { INTERPOLATING, SPRING, INTERPOLATING_SPRING };
60     CurveType type_ { CurveType::INTERPOLATING };
61 
62 private:
63     RSAnimationTimingCurve(const std::shared_ptr<RSInterpolator>& interpolator);
64     RSAnimationTimingCurve(const std::function<float(float)>& customCurveFunc);
65     RSAnimationTimingCurve(float response, float dampingRatio, float blendDuration);
66     RSAnimationTimingCurve(float response, float dampingRatio, float initialVelocity, CurveType curveType);
67 
68     float response_ { 0.0f };
69     float dampingRatio_ { 0.0f };
70     float blendDuration_ { 0.0f };
71     float initialVelocity_ { 0.0f };
72 
73     std::shared_ptr<RSInterpolator> GetInterpolator(int duration) const;
74 
75     std::shared_ptr<RSInterpolator> interpolator_;
76     std::function<float(float)> customCurveFunc_;
77 
78     friend class RSCurveAnimation;
79     friend class RSInterpolatingSpringAnimation;
80     friend class RSKeyframeAnimation;
81     friend class RSSpringAnimation;
82     friend class RSPathAnimation;
83     friend class RSTransition;
84     friend class ParticleParams;
85     template<typename T>
86     friend class Change;
87 };
88 } // namespace Rosen
89 } // namespace OHOS
90 
91 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_ANIMATION_TIMING_CURVE_H
92