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 <parcel.h> 20 #include <refbase.h> 21 #include <memory> 22 23 #include "animation/rs_animation_common.h" 24 #include "common/rs_macros.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 class RSCanvasRenderNode; 29 class RSPaintFilterCanvas; 30 class RSProperties; 31 class RSRenderModifier; 32 template<typename T> 33 class RSRenderAnimatableProperty; 34 class Quaternion; 35 template<typename T> 36 class Vector2; 37 38 class RSB_EXPORT RSRenderTransitionEffect : public Parcelable { 39 public: 40 RSRenderTransitionEffect() = default; 41 virtual ~RSRenderTransitionEffect() = default; 42 const std::shared_ptr<RSRenderModifier>& GetModifier(); 43 virtual void UpdateFraction(float fraction) const = 0; 44 45 bool Marshalling(Parcel& parcel) const override = 0; 46 static RSRenderTransitionEffect* Unmarshalling(Parcel& parcel); 47 private: 48 std::shared_ptr<RSRenderModifier> modifier_; 49 virtual const std::shared_ptr<RSRenderModifier> CreateModifier() = 0; 50 }; 51 52 class RSB_EXPORT RSTransitionFade : public RSRenderTransitionEffect { 53 public: RSTransitionFade(float alpha)54 explicit RSTransitionFade(float alpha) : alpha_(alpha) {} 55 ~RSTransitionFade() override = default; 56 void UpdateFraction(float fraction) const override; 57 58 bool Marshalling(Parcel& parcel) const override; 59 static RSRenderTransitionEffect* Unmarshalling(Parcel& parcel); 60 private: 61 float alpha_; 62 std::shared_ptr<RSRenderAnimatableProperty<float>> property_; 63 const std::shared_ptr<RSRenderModifier> CreateModifier() override; 64 }; 65 66 class RSB_EXPORT RSTransitionScale : public RSRenderTransitionEffect { 67 public: 68 explicit RSTransitionScale(float scaleX = 0.0f, float scaleY = 0.0f, float scaleZ = 0.0f) scaleX_(scaleX)69 : scaleX_(scaleX), scaleY_(scaleY), scaleZ_(scaleZ) 70 {} 71 ~RSTransitionScale() override = default; 72 void UpdateFraction(float fraction) const override; 73 74 bool Marshalling(Parcel& parcel) const override; 75 static RSRenderTransitionEffect* Unmarshalling(Parcel& parcel); 76 private: 77 float scaleX_; 78 float scaleY_; 79 float scaleZ_; 80 std::shared_ptr<RSRenderAnimatableProperty<Vector2<float>>> property_; 81 const std::shared_ptr<RSRenderModifier> CreateModifier() override; 82 }; 83 84 class RSB_EXPORT RSTransitionTranslate : public RSRenderTransitionEffect { 85 public: RSTransitionTranslate(float translateX,float translateY,float translateZ)86 explicit RSTransitionTranslate(float translateX, float translateY, float translateZ) 87 : translateX_(translateX), translateY_(translateY), translateZ_(translateZ) 88 {} 89 ~RSTransitionTranslate() override = default; 90 void UpdateFraction(float fraction) const override; 91 92 bool Marshalling(Parcel& parcel) const override; 93 static RSRenderTransitionEffect* Unmarshalling(Parcel& parcel); 94 private: 95 float translateX_; 96 float translateY_; 97 float translateZ_; 98 std::shared_ptr<RSRenderAnimatableProperty<Vector2<float>>> property_; 99 const std::shared_ptr<RSRenderModifier> CreateModifier() override; 100 }; 101 102 class RSB_EXPORT RSTransitionRotate : public RSRenderTransitionEffect { 103 public: RSTransitionRotate(float dx,float dy,float dz,float radian)104 explicit RSTransitionRotate(float dx, float dy, float dz, float radian) : dx_(dx), dy_(dy), dz_(dz), radian_(radian) 105 {} 106 ~RSTransitionRotate() override = default; 107 void UpdateFraction(float fraction) const override; 108 109 bool Marshalling(Parcel& parcel) const override; 110 static RSRenderTransitionEffect* Unmarshalling(Parcel& parcel); 111 private: 112 float dx_; 113 float dy_; 114 float dz_; 115 float radian_; 116 std::shared_ptr<RSRenderAnimatableProperty<Quaternion>> property_; 117 const std::shared_ptr<RSRenderModifier> CreateModifier() override; 118 }; 119 } // namespace Rosen 120 } // namespace OHOS 121 122 #endif 123