• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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_MODIFIER_H
17 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_RENDER_MODIFIER_H
18 
19 #include <memory>
20 #include "parcel.h"
21 
22 #include "common/rs_color.h"
23 #include "common/rs_macros.h"
24 #include "common/rs_matrix3.h"
25 #include "common/rs_vector2.h"
26 #include "common/rs_vector4.h"
27 #include "modifier/rs_modifier_type.h"
28 #include "modifier/rs_render_property.h"
29 #include "pipeline/rs_draw_cmd_list.h"
30 #include "render/rs_border.h"
31 #include "render/rs_filter.h"
32 #include "render/rs_image.h"
33 #include "render/rs_mask.h"
34 #include "render/rs_path.h"
35 #include "render/rs_shader.h"
36 
37 
38 namespace OHOS {
39 namespace Rosen {
40 class RSProperties;
41 class RSPaintFilterCanvas;
42 
43 struct RSModifierContext {
44     RSProperties& property_;
45     RSPaintFilterCanvas* canvas_ = nullptr;
46 };
47 
48 class RSB_EXPORT RSRenderModifier {
49 public:
50     RSRenderModifier() = default;
51     virtual ~RSRenderModifier() = default;
52 
53     virtual void Apply(RSModifierContext& context) = 0;
54 
55     virtual PropertyId GetPropertyId() = 0;
56     virtual std::shared_ptr<RSRenderPropertyBase> GetProperty() = 0;
57     virtual RSModifierType GetType() = 0;
58     virtual void Update(const std::shared_ptr<RSRenderPropertyBase>& prop, bool isDelta) = 0;
59 
60     virtual bool Marshalling(Parcel& parcel) = 0;
61     static RSRenderModifier* Unmarshalling(Parcel& parcel);
62 };
63 
64 class RSB_EXPORT RSDrawCmdListRenderModifier : public RSRenderModifier {
65 public:
RSDrawCmdListRenderModifier(const std::shared_ptr<RSRenderProperty<DrawCmdListPtr>> & property)66     RSDrawCmdListRenderModifier(const std::shared_ptr<RSRenderProperty<DrawCmdListPtr>>& property)
67         : property_(property ? property : std::make_shared<RSRenderProperty<DrawCmdListPtr>>())
68     {}
69     virtual ~RSDrawCmdListRenderModifier() = default;
70     void Apply(RSModifierContext& context) override;
71     void Update(const std::shared_ptr<RSRenderPropertyBase>& prop, bool isDelta) override;
72     bool Marshalling(Parcel& parcel) override;
73 
GetPropertyId()74     virtual PropertyId GetPropertyId() override
75     {
76         return property_->GetId();
77     }
78 
GetProperty()79     std::shared_ptr<RSRenderPropertyBase> GetProperty() override
80     {
81         return property_;
82     }
83 
GetType()84     RSModifierType GetType() override
85     {
86         return drawStyle_;
87     }
SetType(RSModifierType type)88     void SetType(RSModifierType type)
89     {
90         drawStyle_ = type;
91     }
92 
SetOverlayBounds(std::shared_ptr<RectI> rect)93     void SetOverlayBounds(std::shared_ptr<RectI> rect)
94     {
95         overlayRect_ = rect;
96     }
97 
GetOverlayBounds()98     std::shared_ptr<RectI> GetOverlayBounds() const
99     {
100         return overlayRect_;
101     }
102 
103 protected:
104     std::shared_ptr<RectI> overlayRect_ = nullptr;
105     RSModifierType drawStyle_ = RSModifierType::EXTENDED;
106     std::shared_ptr<RSRenderProperty<DrawCmdListPtr>> property_;
107 };
108 
109 class RSAnimatableRenderModifier : public RSRenderModifier {
110 public:
RSAnimatableRenderModifier(const std::shared_ptr<RSRenderPropertyBase> & property)111     RSAnimatableRenderModifier(const std::shared_ptr<RSRenderPropertyBase>& property)
112         : property_(property ? property : std::make_shared<RSRenderPropertyBase>())
113     {}
114 
115     virtual ~RSAnimatableRenderModifier() = default;
116 
GetPropertyId()117     virtual PropertyId GetPropertyId() override
118     {
119         return property_->GetId();
120     }
121 
GetProperty()122     std::shared_ptr<RSRenderPropertyBase> GetProperty() override
123     {
124         return property_;
125     }
126 
127 protected:
128     std::shared_ptr<RSRenderPropertyBase> property_;
129 
130     friend class RSRenderPropertyAnimation;
131 };
132 
133 // declare RenderModifiers like RSBoundsRenderModifier
134 #define DECLARE_ANIMATABLE_MODIFIER(MODIFIER_NAME, TYPE, MODIFIER_TYPE, DELTA_OP)                        \
135     class RSB_EXPORT RS##MODIFIER_NAME##RenderModifier : public RSAnimatableRenderModifier {             \
136     public:                                                                                              \
137         RS##MODIFIER_NAME##RenderModifier(const std::shared_ptr<RSRenderPropertyBase>& property)         \
138             : RSAnimatableRenderModifier(property)                                                       \
139         {}                                                                                               \
140         virtual ~RS##MODIFIER_NAME##RenderModifier() = default;                                          \
141         void Apply(RSModifierContext& context) override;                                                 \
142         void Update(const std::shared_ptr<RSRenderPropertyBase>& prop, bool isDelta) override;           \
143         bool Marshalling(Parcel& parcel) override;                                                       \
144         RSModifierType GetType() override                                                                \
145         {                                                                                                \
146             return RSModifierType::MODIFIER_TYPE;                                                        \
147         }                                                                                                \
148     };
149 
150 #define DECLARE_NOANIMATABLE_MODIFIER(MODIFIER_NAME, TYPE, MODIFIER_TYPE) \
151     DECLARE_ANIMATABLE_MODIFIER(MODIFIER_NAME, TYPE, MODIFIER_TYPE, Add)
152 
153 #include "modifier/rs_modifiers_def.in"
154 
155 #undef DECLARE_ANIMATABLE_MODIFIER
156 #undef DECLARE_NOANIMATABLE_MODIFIER
157 } // namespace Rosen
158 } // namespace OHOS
159 
160 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_RENDER_MODIFIER_H
161