• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_BASE_DRAWABLE_RS_PROPERTY_DRAWABLE_FOREGROUND_H
17 #define RENDER_SERVICE_BASE_DRAWABLE_RS_PROPERTY_DRAWABLE_FOREGROUND_H
18 
19 #include "common/rs_rect.h"
20 #include "common/rs_vector4.h"
21 #include "drawable/rs_property_drawable.h"
22 #include "property/rs_properties.h"
23 #include "property/rs_properties_def.h"
24 
25 namespace OHOS::Rosen {
26 class RSFilter;
27 class RSBorder;
28 class RSNGRenderShaderBase;
29 class RSProperties;
30 namespace Drawing {
31 class GEShader;
32 class RuntimeEffect;
33 class RuntimeShaderBuilder;
34 class GEVisualEffectContainer;
35 } // namespace Drawing
36 
37 namespace DrawableV2 {
38 namespace {
39 constexpr int MAX_LIGHT_SOURCES = 12;
40 }
41 class RSBinarizationDrawable : public RSDrawable {
42 public:
43     RSBinarizationDrawable() = default;
44     ~RSBinarizationDrawable() override = default;
45 
46     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
47     bool OnUpdate(const RSRenderNode& node) override;
48     void OnSync() override;
49     Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override;
50 
51 private:
52     bool needSync_ = false;
53     std::optional<Vector4f> aiInvert_;
54     std::optional<Vector4f> stagingAiInvert_;
55 };
56 
57 class RSColorFilterDrawable : public RSDrawable {
58 public:
59     RSColorFilterDrawable() = default;
60     ~RSColorFilterDrawable() override = default;
61 
62     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
63     bool OnUpdate(const RSRenderNode& node) override;
64     void OnSync() override;
65     Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override;
66 
67 private:
68     bool needSync_ = false;
69     std::shared_ptr<Drawing::ColorFilter> filter_;
70     std::shared_ptr<Drawing::ColorFilter> stagingFilter_;
71 };
72 
73 class RSLightUpEffectDrawable : public RSDrawable {
74 public:
75     RSLightUpEffectDrawable() = default;
76     ~RSLightUpEffectDrawable() override = default;
77 
78     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
79     bool OnUpdate(const RSRenderNode& node) override;
80     void OnSync() override;
81     Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override;
82 
83 private:
84     bool needSync_ = false;
85     float lightUpEffectDegree_ = 1.0f;
86     float stagingLightUpEffectDegree_ = 1.0f;
87 };
88 
89 class RSDynamicDimDrawable : public RSDrawable {
90 public:
91     RSDynamicDimDrawable() = default;
92     ~RSDynamicDimDrawable() override = default;
93 
94     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
95     bool OnUpdate(const RSRenderNode& node) override;
96     void OnSync() override;
97     Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override;
98 
99 private:
100     bool needSync_ = false;
101     float dynamicDimDegree_ = 1.0f;
102     float stagingDynamicDimDegree_ = 1.0f;
103 };
104 
105 class RSCompositingFilterDrawable : public RSFilterDrawable {
106 public:
107     RSCompositingFilterDrawable() = default;
108     ~RSCompositingFilterDrawable() override = default;
109 
110     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
111     bool OnUpdate(const RSRenderNode& node) override;
IsForeground()112     bool IsForeground() const override
113     {
114         return true;
115     }
116 };
117 
118 // foregroundFilter
119 class RSForegroundFilterDrawable : public RSDrawable {
120 public:
121     RSForegroundFilterDrawable() = default;
122     ~RSForegroundFilterDrawable() override = default;
123 
124     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
125     bool OnUpdate(const RSRenderNode& node) override;
126     void OnSync() override;
127     Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override;
128 
129 private:
130     bool needSync_ = false;
131     RectF boundsRect_;
132     RectF stagingBoundsRect_;
133 };
134 
135 class RSForegroundFilterRestoreDrawable : public RSDrawable {
136 public:
137     RSForegroundFilterRestoreDrawable() = default;
138     ~RSForegroundFilterRestoreDrawable() override = default;
139 
140     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
141     bool OnUpdate(const RSRenderNode& node) override;
142     void OnSync() override;
143     Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override;
144 
145 private:
146     bool needSync_ = false;
147     std::shared_ptr<RSFilter> foregroundFilter_;
148     std::shared_ptr<RSFilter> stagingForegroundFilter_;
149 };
150 
151 class RSForegroundColorDrawable : public RSPropertyDrawable {
152 public:
RSForegroundColorDrawable(std::shared_ptr<Drawing::DrawCmdList> && drawCmdList)153     RSForegroundColorDrawable(std::shared_ptr<Drawing::DrawCmdList>&& drawCmdList)
154         : RSPropertyDrawable(std::move(drawCmdList))
155     {}
156     RSForegroundColorDrawable() = default;
157     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
158     bool OnUpdate(const RSRenderNode& node) override;
159 
160 private:
161 };
162 
163 class RSForegroundShaderDrawable : public RSDrawable {
164 public:
165     RSForegroundShaderDrawable() = default;
166     ~RSForegroundShaderDrawable() override = default;
167 
168     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
169     void PostUpdate(const RSRenderNode& node);
170     bool OnUpdate(const RSRenderNode& node) override;
171     void OnSync() override;
172     Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override;
173 
GetEnableEDR()174     bool GetEnableEDR() const override
175     {
176         return enableEDREffect_;
177     }
178 
179 private:
180     NodeId screenNodeId_ = INVALID_NODEID;
181 
182     bool needSync_ = false;
183     bool enableEDREffect_ = false;
184     std::shared_ptr<RSNGRenderShaderBase> stagingShader_;
185     std::shared_ptr<Drawing::GEVisualEffectContainer> visualEffectContainer_;
186 };
187 
188 class RSPointLightDrawable : public RSDrawable {
189 public:
RSPointLightDrawable(const RSProperties & properties)190     RSPointLightDrawable(const RSProperties &properties) : properties_(properties) {}
191     ~RSPointLightDrawable() override = default;
192     void OnSync() override;
193     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
194     bool OnUpdate(const RSRenderNode& node) override;
195     Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override;
196 
197 private:
198     const RSProperties &properties_;
199     std::vector<std::pair<std::shared_ptr<RSLightSource>, Vector4f>> lightSourcesAndPosVec_;
200     RectI rect_  = {};
201     IlluminatedType illuminatedType_ = IlluminatedType::INVALID;
202     Drawing::RoundRect borderRRect_ = {};
203     Drawing::RoundRect contentRRect_ = {};
204     float borderWidth_ = 0.0f;
205     void DrawLight(Drawing::Canvas* canvas) const;
206     static const std::shared_ptr<Drawing::RuntimeShaderBuilder>& GetPhongShaderBuilder();
207     static const std::shared_ptr<Drawing::RuntimeShaderBuilder>& GetFeatheringBoardLightShaderBuilder();
208     void DrawContentLight(Drawing::Canvas& canvas, std::shared_ptr<Drawing::RuntimeShaderBuilder>& lightBuilder,
209         Drawing::Brush& brush, const std::array<float, MAX_LIGHT_SOURCES>& lightIntensityArray) const;
210     void DrawBorderLight(Drawing::Canvas& canvas, std::shared_ptr<Drawing::RuntimeShaderBuilder>& lightBuilder,
211         Drawing::Pen& pen, const std::array<float, MAX_LIGHT_SOURCES>& lightIntensityArray) const;
212 };
213 
214 // ============================================================================
215 // Border & Outline
216 class RSBorderDrawable : public RSPropertyDrawable {
217     friend class RSOutlineDrawable;
218 
219 public:
RSBorderDrawable(std::shared_ptr<Drawing::DrawCmdList> && drawCmdList)220     RSBorderDrawable(std::shared_ptr<Drawing::DrawCmdList>&& drawCmdList) : RSPropertyDrawable(std::move(drawCmdList))
221     {}
222     RSBorderDrawable() = default;
223     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
224     bool OnUpdate(const RSRenderNode& node) override;
225 
226 private:
227     static void DrawBorder(const RSProperties& properties, Drawing::Canvas& canvas,
228         const std::shared_ptr<RSBorder>& border, const bool& isOutline);
229 };
230 
231 class RSOutlineDrawable : public RSPropertyDrawable {
232 public:
RSOutlineDrawable(std::shared_ptr<Drawing::DrawCmdList> && drawCmdList)233     RSOutlineDrawable(std::shared_ptr<Drawing::DrawCmdList>&& drawCmdList) : RSPropertyDrawable(std::move(drawCmdList))
234     {}
235     RSOutlineDrawable() = default;
236     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
237     bool OnUpdate(const RSRenderNode& node) override;
238 
239 private:
240 };
241 
242 class RSParticleDrawable : public RSPropertyDrawable {
243 public:
RSParticleDrawable(std::shared_ptr<Drawing::DrawCmdList> && drawCmdList)244     RSParticleDrawable(std::shared_ptr<Drawing::DrawCmdList>&& drawCmdList) : RSPropertyDrawable(std::move(drawCmdList))
245     {}
246     RSParticleDrawable() = default;
247     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
248     bool OnUpdate(const RSRenderNode& node) override;
249 
250 private:
251 };
252 
253 class RSPixelStretchDrawable : public RSDrawable {
254 public:
255     RSPixelStretchDrawable() = default;
256     ~RSPixelStretchDrawable() override = default;
257 
258     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
259     bool OnUpdate(const RSRenderNode& node) override;
260     void OnSync() override;
261     Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override;
262     void SetPixelStretch(const std::optional<Vector4f>& pixelStretch);
263 
264 private:
265     bool needSync_ = false;
266     NodeId stagingNodeId_ = INVALID_NODEID;
267     NodeId renderNodeId_ = INVALID_NODEID;
268     std::optional<Vector4f> pixelStretch_;
269     std::optional<Vector4f> stagingPixelStretch_;
270     int pixelStretchTileMode_ = 0;
271     int stagePixelStretchTileMode_ = 0;
272     bool boundsGeoValid_ = false;
273     bool stagingBoundsGeoValid_ = false;
274     RectF boundsRect_;
275     RectF stagingBoundsRect_;
276 };
277 } // namespace DrawableV2
278 } // namespace OHOS::Rosen
279 #endif // RENDER_SERVICE_BASE_DRAWABLE_RS_PROPERTY_DRAWABLE_FOREGROUND_H
280