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_RENDER_PATH_ANIMATION_H
17 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_RENDER_PATH_ANIMATION_H
18 
19 #include "animation/rs_interpolator.h"
20 #include "animation/rs_render_property_animation.h"
21 #include "common/rs_macros.h"
22 
23 namespace OHOS {
24 namespace Rosen {
25 class RSPath;
26 
27 class RSB_EXPORT RSRenderPathAnimation : public RSRenderPropertyAnimation {
28 static constexpr float UNDEFINED_FLOAT = 0.0f;
29 public:
30     RSRenderPathAnimation(AnimationId id, const PropertyId& propertyId,
31         const std::shared_ptr<RSRenderPropertyBase>& originPosition,
32         const std::shared_ptr<RSRenderPropertyBase>& startPosition,
33         const std::shared_ptr<RSRenderPropertyBase>& endPosition, float originRotation,
34         const std::shared_ptr<RSPath>& animationPath);
35 
36     ~RSRenderPathAnimation() = default;
37 
38     void DumpAnimationType(std::string& out) const override;
39 
40     void SetInterpolator(const std::shared_ptr<RSInterpolator>& interpolator);
41 
42     const std::shared_ptr<RSInterpolator>& GetInterpolator() const;
43 
44     void SetRotationMode(const RotationMode& rotationMode);
45 
46     RotationMode GetRotationMode() const;
47 
48     void SetBeginFraction(float fraction);
49 
50     float GetBeginFraction() const;
51 
52     void SetEndFraction(float fraction);
53 
54     float GetEndFraction() const;
55 
56     void SetIsNeedPath(const bool isNeedPath);
57 
58     void SetPathNeedAddOrigin(bool needAddOrigin);
59 
60     void SetRotationId(const PropertyId id);
61 
62     bool Marshalling(Parcel& parcel) const override;
63 
64     [[nodiscard]] static RSRenderPathAnimation* Unmarshalling(Parcel& parcel);
65 
66 protected:
67     RSRenderPathAnimation() = default;
68 
69     void OnAnimate(float fraction) override;
70 
71     void OnRemoveOnCompletion() override;
72 
73     void InitValueEstimator() override;
74 
75     void OnAttach() override;
76     void OnDetach() override;
77 
78 private:
79     bool ParseParam(Parcel& parcel) override;
80     void SetPathValue(const Vector2f& value, float tangent);
81     void SetPathValue(const Vector4f& value, float tangent);
82 
83     void SetRotationValue(const float tangent);
84 
85     void SetRotation(const float tangent);
86 
87     void GetPosTanValue(float fraction, Vector2f& position, float& tangent);
88 
89     void UpdateVector2fPathValue(Vector2f& value);
90     void UpdateVector4fPathValue(Vector4f& value, const Vector2f& position);
91 
92     float originRotation_ { UNDEFINED_FLOAT };
93     float beginFraction_ { FRACTION_MIN };
94     float endFraction_ { FRACTION_MAX };
95     bool isNeedPath_ { true };
96     bool needAddOrigin_ { false };
97     PropertyId rotationId_ {};
98     RotationMode rotationMode_ { RotationMode::ROTATE_NONE };
99     std::shared_ptr<RSRenderPropertyBase> startValue_ {};
100     std::shared_ptr<RSRenderPropertyBase> endValue_ {};
101     std::shared_ptr<RSInterpolator> interpolator_ { RSInterpolator::DEFAULT };
102     std::shared_ptr<RSPath> animationPath_;
103 };
104 } // namespace Rosen
105 } // namespace OHOS
106 
107 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_RENDER_PATH_ANIMATION_H
108