• 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 physical spring, which duration is determined by the spring model. When mixed with other physical spring
47     // animations on the same property, each animation will be replaced by their successor, preserving velocity from one
48     // animation to the next.
49     static RSAnimationTimingCurve CreateSpring(float response, float dampingRatio, float blendDuration = 0.0f);
50 
51     RSAnimationTimingCurve();
52     RSAnimationTimingCurve(const RSAnimationTimingCurve& timingCurve) = default;
53     RSAnimationTimingCurve& operator=(const RSAnimationTimingCurve& timingCurve) = default;
54     virtual ~RSAnimationTimingCurve() = default;
55 
56     enum class CurveType { INTERPOLATING, SPRING };
57     CurveType type_ { CurveType::INTERPOLATING };
58 private:
59     RSAnimationTimingCurve(const std::shared_ptr<RSInterpolator>& interpolator);
60     RSAnimationTimingCurve(const std::function<float(float)>& customCurveFunc);
61     RSAnimationTimingCurve(float response, float dampingRatio, float blendDuration);
62 
63     float response_ { 0.0f };
64     float dampingRatio_ { 0.0f };
65     float blendDuration_ { 0.0f };
66 
67     std::shared_ptr<RSInterpolator> GetInterpolator(int duration) const;
68 
69     std::shared_ptr<RSInterpolator> interpolator_;
70     std::function<float(float)> customCurveFunc_;
71 
72     friend class RSCurveAnimation;
73     friend class RSKeyframeAnimation;
74     friend class RSSpringAnimation;
75     friend class RSPathAnimation;
76     friend class RSTransition;
77 };
78 } // namespace Rosen
79 } // namespace OHOS
80 
81 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_ANIMATION_TIMING_CURVE_H
82