• 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_TRANSITION_RS_RENDER_TRANSITION_EFFECT_H
17 #define RENDER_SERVICE_CLIENT_CORE_TRANSITION_RS_RENDER_TRANSITION_EFFECT_H
18 
19 #include <cinttypes>
20 #include <memory>
21 #include <parcel.h>
22 #include <refbase.h>
23 
24 #include "animation/rs_animation_common.h"
25 #include "animation/rs_value_estimator.h"
26 #include "common/rs_macros.h"
27 #include "modifier/rs_render_property.h"
28 #include "modifier_ng/rs_render_modifier_ng.h"
29 
30 namespace OHOS {
31 namespace Rosen {
32 class RSB_EXPORT RSRenderTransitionEffect : public Parcelable {
33 public:
34     RSRenderTransitionEffect() = default;
35     virtual ~RSRenderTransitionEffect() = default;
36     const std::shared_ptr<ModifierNG::RSRenderModifier>& GetModifierNG();
37     virtual void UpdateFraction(float fraction) const = 0;
38 
Marshalling(Parcel & parcel)39     bool Marshalling(Parcel& parcel) const override
40     {
41         return false;
42     }
43     [[nodiscard]] static RSRenderTransitionEffect* Unmarshalling(Parcel& parcel);
44 private:
45     std::shared_ptr<ModifierNG::RSRenderModifier> modifierNG_;
46     virtual const std::shared_ptr<ModifierNG::RSRenderModifier> CreateModifierNG() = 0;
47 };
48 
49 class RSB_EXPORT RSTransitionFade : public RSRenderTransitionEffect {
50 public:
RSTransitionFade(float alpha)51     explicit RSTransitionFade(float alpha) : alpha_(alpha) {}
52     ~RSTransitionFade() override = default;
53     void UpdateFraction(float fraction) const override;
54 
55     bool Marshalling(Parcel& parcel) const override;
56     [[nodiscard]] static RSRenderTransitionEffect* Unmarshalling(Parcel& parcel);
57 private:
58     float alpha_ { 0.0 };
59     std::shared_ptr<RSRenderAnimatableProperty<float>> property_;
60     const std::shared_ptr<ModifierNG::RSRenderModifier> CreateModifierNG() override;
61 };
62 
63 class RSB_EXPORT RSTransitionScale : public RSRenderTransitionEffect {
64 public:
65     explicit RSTransitionScale(float scaleX = 0.0f, float scaleY = 0.0f, float scaleZ = 0.0f)
scaleX_(scaleX)66         : scaleX_(scaleX), scaleY_(scaleY), scaleZ_(scaleZ)
67     {}
68     ~RSTransitionScale() override = default;
69     void UpdateFraction(float fraction) const override;
70 
71     bool Marshalling(Parcel& parcel) const override;
72     [[nodiscard]] static RSRenderTransitionEffect* Unmarshalling(Parcel& parcel);
73 private:
74     float scaleX_ { 0.0 };
75     float scaleY_ { 0.0 };
76     float scaleZ_ { 0.0 };
77     std::shared_ptr<RSRenderAnimatableProperty<Vector2<float>>> property_;
78     const std::shared_ptr<ModifierNG::RSRenderModifier> CreateModifierNG() override;
79 };
80 
81 class RSB_EXPORT RSTransitionTranslate : public RSRenderTransitionEffect {
82 public:
RSTransitionTranslate(float translateX,float translateY,float translateZ)83     explicit RSTransitionTranslate(float translateX, float translateY, float translateZ)
84         : translateX_(translateX), translateY_(translateY), translateZ_(translateZ)
85     {}
86     ~RSTransitionTranslate() override = default;
87     void UpdateFraction(float fraction) const override;
88 
89     bool Marshalling(Parcel& parcel) const override;
90     [[nodiscard]] static RSRenderTransitionEffect* Unmarshalling(Parcel& parcel);
91 private:
92     float translateX_ { 0.0 };
93     float translateY_ { 0.0 };
94     float translateZ_ { 0.0 };
95     std::shared_ptr<RSRenderAnimatableProperty<Vector2<float>>> property_;
96     const std::shared_ptr<ModifierNG::RSRenderModifier> CreateModifierNG() override;
97 };
98 
99 class RSB_EXPORT RSTransitionRotate : public RSRenderTransitionEffect {
100 public:
RSTransitionRotate(float dx,float dy,float dz,float radian)101     explicit RSTransitionRotate(float dx, float dy, float dz, float radian) : dx_(dx), dy_(dy), dz_(dz), radian_(radian)
102     {}
103     ~RSTransitionRotate() override = default;
104     void UpdateFraction(float fraction) const override;
105 
106     bool Marshalling(Parcel& parcel) const override;
107     [[nodiscard]] static RSRenderTransitionEffect* Unmarshalling(Parcel& parcel);
108 private:
109     float dx_ { 0.0 };
110     float dy_ { 0.0 };
111     float dz_ { 0.0 };
112     float radian_ { 0.0 };
113     std::shared_ptr<RSRenderAnimatableProperty<Quaternion>> property_;
114     const std::shared_ptr<ModifierNG::RSRenderModifier> CreateModifierNG() override;
115 };
116 
117 class RSTransitionCustom : public RSRenderTransitionEffect {
118 public:
RSTransitionCustom(std::shared_ptr<RSRenderPropertyBase> property,std::shared_ptr<RSRenderPropertyBase> startValue,std::shared_ptr<RSRenderPropertyBase> endValue)119     RSTransitionCustom(std::shared_ptr<RSRenderPropertyBase> property, std::shared_ptr<RSRenderPropertyBase> startValue,
120         std::shared_ptr<RSRenderPropertyBase> endValue)
121         : property_(property), startValue_(startValue), endValue_(endValue)
122     {
123         InitValueEstimator();
124     }
125     ~RSTransitionCustom() override = default;
126 
UpdateFraction(float fraction)127     void UpdateFraction(float fraction) const override
128     {
129         if (!valueEstimator_) {
130             return;
131         }
132         valueEstimator_->UpdateAnimationValue(fraction, true);
133     }
134 
135 private:
CreateModifierNG()136     const std::shared_ptr<ModifierNG::RSRenderModifier> CreateModifierNG() override
137     {
138         return nullptr;
139     }
140 
InitValueEstimator()141     void InitValueEstimator()
142     {
143         if (valueEstimator_ == nullptr) {
144             valueEstimator_ = property_->CreateRSValueEstimator(RSValueEstimatorType::CURVE_VALUE_ESTIMATOR);
145         }
146         if (valueEstimator_ == nullptr) {
147             return;
148         }
149         valueEstimator_->InitCurveAnimationValue(property_, endValue_, startValue_, startValue_);
150     }
151 
152     std::shared_ptr<RSRenderPropertyBase> property_;
153     std::shared_ptr<RSRenderPropertyBase> startValue_;
154     std::shared_ptr<RSRenderPropertyBase> endValue_;
155     std::shared_ptr<RSValueEstimator> valueEstimator_;
156 };
157 } // namespace Rosen
158 } // namespace OHOS
159 
160 #endif
161