• 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 
21 #include "parcel.h"
22 #include "rs_modifier_type.h"
23 
24 #include "common/rs_color.h"
25 #include "common/rs_macros.h"
26 #include "common/rs_matrix3.h"
27 #include "common/rs_vector2.h"
28 #include "common/rs_vector4.h"
29 #include "modifier/rs_modifier_type.h"
30 #include "modifier/rs_render_property.h"
31 #include "render/rs_border.h"
32 #include "render/rs_filter.h"
33 #include "render/rs_image.h"
34 #include "render/rs_mask.h"
35 #include "render/rs_path.h"
36 #include "render/rs_shader.h"
37 #include "animation/rs_render_particle.h"
38 #ifndef USE_ROSEN_DRAWING
39 #include "include/core/SkMatrix.h"
40 #include "pipeline/rs_draw_cmd_list.h"
41 #else
42 #include "recording/draw_cmd_list.h"
43 #include "utils/matrix.h"
44 #endif
45 
46 namespace OHOS {
47 namespace Rosen {
48 class RSProperties;
49 class RSPaintFilterCanvas;
50 class RSRenderNode;
51 
52 struct RSModifierContext {
53     RSProperties& property_;
54     RSPaintFilterCanvas* canvas_ = nullptr;
55 };
56 
57 class RSB_EXPORT RSRenderModifier {
58 public:
59     RSRenderModifier() = default;
60     RSRenderModifier(const RSRenderModifier&) = delete;
61     RSRenderModifier(const RSRenderModifier&&) = delete;
62     RSRenderModifier& operator=(const RSRenderModifier&) = delete;
63     RSRenderModifier& operator=(const RSRenderModifier&&) = delete;
64     virtual ~RSRenderModifier() = default;
65 
66     virtual void Apply(RSModifierContext& context) const = 0;
67 
68     virtual PropertyId GetPropertyId() = 0;
69     virtual std::shared_ptr<RSRenderPropertyBase> GetProperty() = 0;
70     virtual RSModifierType GetType() = 0;
71     virtual void Update(const std::shared_ptr<RSRenderPropertyBase>& prop, bool isDelta) = 0;
72 
73     virtual bool Marshalling(Parcel& parcel) = 0;
74     [[nodiscard]] static RSRenderModifier* Unmarshalling(Parcel& parcel);
75 };
76 
77 class RSB_EXPORT RSGeometryTransRenderModifier : public RSRenderModifier {
78 public:
79 #ifndef USE_ROSEN_DRAWING
RSGeometryTransRenderModifier(const std::shared_ptr<RSRenderProperty<SkMatrix>> & property)80     RSGeometryTransRenderModifier(const std::shared_ptr<RSRenderProperty<SkMatrix>>& property)
81         : property_(property ? property : std::make_shared<RSRenderProperty<SkMatrix>>()) {}
82 #else
83     RSGeometryTransRenderModifier(const std::shared_ptr<RSRenderProperty<Drawing::Matrix>>& property)
84         : property_(property ? property : std::make_shared<RSRenderProperty<Drawing::Matrix>>()) {}
85 #endif
86     virtual ~RSGeometryTransRenderModifier() = default;
87     void Apply(RSModifierContext& context) const override;
88     void Update(const std::shared_ptr<RSRenderPropertyBase>& prop, bool isDelta) override;
89     bool Marshalling(Parcel& parcel) override;
GetPropertyId()90     virtual PropertyId GetPropertyId() override
91     {
92         return property_->GetId();
93     }
94 
GetProperty()95     std::shared_ptr<RSRenderPropertyBase> GetProperty() override
96     {
97         return property_;
98     }
99 
SetType(RSModifierType type)100     void SetType(RSModifierType type)
101     {
102         drawStyle_ = type;
103     }
104 
GetType()105     RSModifierType GetType() override
106     {
107         return drawStyle_;
108     }
109 
110 protected:
111     RSModifierType drawStyle_ = RSModifierType::GEOMETRYTRANS;
112 #ifndef USE_ROSEN_DRAWING
113     std::shared_ptr<RSRenderProperty<SkMatrix>> property_;
114 #else
115     std::shared_ptr<RSRenderProperty<Drawing::Matrix>> property_;
116 #endif
117 };
118 
119 class RSB_EXPORT RSDrawCmdListRenderModifier : public RSRenderModifier {
120 public:
121 #ifndef USE_ROSEN_DRAWING
RSDrawCmdListRenderModifier(const std::shared_ptr<RSRenderProperty<DrawCmdListPtr>> & property)122     RSDrawCmdListRenderModifier(const std::shared_ptr<RSRenderProperty<DrawCmdListPtr>>& property)
123         : property_(property ? property : std::make_shared<RSRenderProperty<DrawCmdListPtr>>())
124     {}
125 #else
126     RSDrawCmdListRenderModifier(const std::shared_ptr<RSRenderProperty<Drawing::DrawCmdListPtr>>& property)
127         : property_(property ? property : std::make_shared<RSRenderProperty<Drawing::DrawCmdListPtr>>())
128     {}
129 #endif
130     virtual ~RSDrawCmdListRenderModifier() = default;
131     void Apply(RSModifierContext& context) const override;
132     void Update(const std::shared_ptr<RSRenderPropertyBase>& prop, bool isDelta) override;
133     bool Marshalling(Parcel& parcel) override;
134 
GetPropertyId()135     virtual PropertyId GetPropertyId() override
136     {
137         return property_->GetId();
138     }
139 
GetProperty()140     std::shared_ptr<RSRenderPropertyBase> GetProperty() override
141     {
142         return property_;
143     }
144 
GetType()145     RSModifierType GetType() override
146     {
147         return drawStyle_;
148     }
SetType(RSModifierType type)149     void SetType(RSModifierType type)
150     {
151         drawStyle_ = type;
152     }
153 
154     // functions that are dedicated to driven render [start]
155     RectF GetCmdsClipRect() const;
156     void ApplyForDrivenContent(RSModifierContext& context) const;
157     // functions that are dedicated to driven render [end]
158 protected:
159     RSModifierType drawStyle_ = RSModifierType::EXTENDED;
160 #ifndef USE_ROSEN_DRAWING
161     std::shared_ptr<RSRenderProperty<DrawCmdListPtr>> property_;
162 #else
163     std::shared_ptr<RSRenderProperty<Drawing::DrawCmdListPtr>> property_;
164 #endif
165 };
166 
167 class RSB_EXPORT RSParticleRenderModifier : public RSRenderModifier {
168 public:
RSParticleRenderModifier(const std::shared_ptr<RSRenderProperty<RSRenderParticleVector>> & property)169     RSParticleRenderModifier(
170         const std::shared_ptr<RSRenderProperty<RSRenderParticleVector>>& property)
171         : property_(property ? property
172                              : std::make_shared<RSRenderProperty<RSRenderParticleVector>>())
173     {
174         property_->SetModifierType(RSModifierType::PARTICLE);
175     }
176     virtual ~RSParticleRenderModifier() = default;
177     void Apply(RSModifierContext& context) const override;
178 
GetPropertyId()179     virtual PropertyId GetPropertyId() override
180     {
181         return property_->GetId();
182     }
183 
GetProperty()184     std::shared_ptr<RSRenderPropertyBase> GetProperty() override
185     {
186         return property_;
187     }
188 
189     void Update(const std::shared_ptr<RSRenderPropertyBase>& prop, bool isDelta) override;
190     bool Marshalling(Parcel& parcel) override;
191 
GetType()192     RSModifierType GetType() override
193     {
194         return RSModifierType::PARTICLE;
195     }
196     std::shared_ptr<RSRenderProperty<RSRenderParticleVector>> property_;
197 };
198 
199 class RSAnimatableRenderModifier : public RSRenderModifier {
200 public:
RSAnimatableRenderModifier(const std::shared_ptr<RSRenderPropertyBase> & property)201     RSAnimatableRenderModifier(const std::shared_ptr<RSRenderPropertyBase>& property)
202         : property_(property ? property : std::make_shared<RSRenderPropertyBase>())
203     {}
204 
205     virtual ~RSAnimatableRenderModifier() = default;
206 
GetPropertyId()207     virtual PropertyId GetPropertyId() override
208     {
209         return property_->GetId();
210     }
211 
GetProperty()212     std::shared_ptr<RSRenderPropertyBase> GetProperty() override
213     {
214         return property_;
215     }
216 
217 protected:
218     std::shared_ptr<RSRenderPropertyBase> property_;
219 
220     friend class RSRenderPropertyAnimation;
221 };
222 
223 class RSGeometryRenderModifier : public RSAnimatableRenderModifier {
224 public:
RSGeometryRenderModifier(const std::shared_ptr<RSRenderPropertyBase> & property)225     RSGeometryRenderModifier(const std::shared_ptr<RSRenderPropertyBase>& property)
226         : RSAnimatableRenderModifier(property)
227     {}
228 
229     virtual ~RSGeometryRenderModifier() = default;
230 };
231 
232 class RSBackgroundRenderModifier : public RSAnimatableRenderModifier {
233 public:
RSBackgroundRenderModifier(const std::shared_ptr<RSRenderPropertyBase> & property)234     RSBackgroundRenderModifier(const std::shared_ptr<RSRenderPropertyBase>& property)
235         : RSAnimatableRenderModifier(property)
236     {}
237 
238     virtual ~RSBackgroundRenderModifier() = default;
239 };
240 
241 class RSContentRenderModifier : public RSAnimatableRenderModifier {
242 public:
RSContentRenderModifier(const std::shared_ptr<RSRenderPropertyBase> & property)243     RSContentRenderModifier(const std::shared_ptr<RSRenderPropertyBase>& property)
244         : RSAnimatableRenderModifier(property)
245     {}
246 
247     virtual ~RSContentRenderModifier() = default;
248 };
249 
250 class RSForegroundRenderModifier : public RSAnimatableRenderModifier {
251 public:
RSForegroundRenderModifier(const std::shared_ptr<RSRenderPropertyBase> & property)252     RSForegroundRenderModifier(const std::shared_ptr<RSRenderPropertyBase>& property)
253         : RSAnimatableRenderModifier(property)
254     {}
255 
256     virtual ~RSForegroundRenderModifier() = default;
257 };
258 
259 class RSOverlayRenderModifier : public RSAnimatableRenderModifier {
260 public:
RSOverlayRenderModifier(const std::shared_ptr<RSRenderPropertyBase> & property)261     RSOverlayRenderModifier(const std::shared_ptr<RSRenderPropertyBase>& property)
262         : RSAnimatableRenderModifier(property)
263     {}
264 
265     virtual ~RSOverlayRenderModifier() = default;
266 };
267 
268 class RSAppearanceRenderModifier : public RSAnimatableRenderModifier {
269 public:
RSAppearanceRenderModifier(const std::shared_ptr<RSRenderPropertyBase> & property)270     RSAppearanceRenderModifier(const std::shared_ptr<RSRenderPropertyBase>& property)
271         : RSAnimatableRenderModifier(property)
272     {}
273 
274     virtual ~RSAppearanceRenderModifier() = default;
275 };
276 
277 
278 class RSB_EXPORT RSEnvForegroundColorRenderModifier : public RSForegroundRenderModifier {
279 public:
RSEnvForegroundColorRenderModifier(const std::shared_ptr<RSRenderPropertyBase> & property)280     RSEnvForegroundColorRenderModifier(const std::shared_ptr<RSRenderPropertyBase>& property)
281         : RSForegroundRenderModifier(property)
282     {}
283     virtual ~RSEnvForegroundColorRenderModifier() = default;
284     void Apply(RSModifierContext& context) const override;
285     void Update(const std::shared_ptr<RSRenderPropertyBase>& prop, bool isDelta) override;
286     bool Marshalling(Parcel& parcel) override;
GetType()287     RSModifierType GetType() override
288     {
289         return RSModifierType::ENV_FOREGROUND_COLOR;
290     }
291 };
292 
293 class RSB_EXPORT RSEnvForegroundColorStrategyRenderModifier : public RSForegroundRenderModifier {
294 public:
RSEnvForegroundColorStrategyRenderModifier(const std::shared_ptr<RSRenderPropertyBase> & property)295     RSEnvForegroundColorStrategyRenderModifier(const std::shared_ptr<RSRenderPropertyBase>& property)
296         : RSForegroundRenderModifier(property)
297     {}
298     virtual ~RSEnvForegroundColorStrategyRenderModifier() = default;
299     void Apply(RSModifierContext& context) const override;
300     void Update(const std::shared_ptr<RSRenderPropertyBase>& prop, bool isDelta) override;
301     bool Marshalling(Parcel& parcel) override;
GetType()302     RSModifierType GetType() override
303     {
304         return RSModifierType::ENV_FOREGROUND_COLOR_STRATEGY;
305     }
306     Color GetInvertBackgroundColor(RSModifierContext& context) const;
307     Color CalculateInvertColor(Color backgroundColor) const;
308 };
309 
310 // declare RenderModifiers like RSBoundsRenderModifier
311 #define DECLARE_ANIMATABLE_MODIFIER(MODIFIER_NAME, TYPE, MODIFIER_TYPE, DELTA_OP, MODIFIER_TIER)    \
312     class RSB_EXPORT RS##MODIFIER_NAME##RenderModifier : public RS##MODIFIER_TIER##RenderModifier { \
313     public:                                                                                         \
314         RS##MODIFIER_NAME##RenderModifier(const std::shared_ptr<RSRenderPropertyBase>& property)    \
315             : RS##MODIFIER_TIER##RenderModifier(property)                                           \
316         {                                                                                           \
317             property->SetModifierType(RSModifierType::MODIFIER_TYPE);                               \
318         }                                                                                           \
319         virtual ~RS##MODIFIER_NAME##RenderModifier() = default;                                     \
320         void Apply(RSModifierContext& context) const override;                                      \
321         void Update(const std::shared_ptr<RSRenderPropertyBase>& prop, bool isDelta) override;      \
322         bool Marshalling(Parcel& parcel) override;                                                  \
323         RSModifierType GetType() override { return (RSModifierType::MODIFIER_TYPE); }               \
324     };
325 
326 #define DECLARE_NOANIMATABLE_MODIFIER(MODIFIER_NAME, TYPE, MODIFIER_TYPE, MODIFIER_TIER) \
327     DECLARE_ANIMATABLE_MODIFIER(MODIFIER_NAME, TYPE, MODIFIER_TYPE, Add, MODIFIER_TIER)
328 
329 #include "modifier/rs_modifiers_def.in"
330 
331 #undef DECLARE_ANIMATABLE_MODIFIER
332 #undef DECLARE_NOANIMATABLE_MODIFIER
333 } // namespace Rosen
334 } // namespace OHOS
335 
336 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_RENDER_MODIFIER_H
337