• 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_BACKGROUND_H
17 #define RENDER_SERVICE_BASE_DRAWABLE_RS_PROPERTY_DRAWABLE_BACKGROUND_H
18 
19 #include <utility>
20 
21 #include "common/rs_color.h"
22 #include "drawable/rs_property_drawable.h"
23 #include "drawable/rs_render_node_drawable_adapter.h"
24 #include "property/rs_properties_def.h"
25 
26 #if defined(ROSEN_OHOS) && (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
27 #include "external_window.h"
28 #include "surface_buffer.h"
29 #endif
30 
31 namespace OHOS::Rosen {
32 class RSProperties;
33 class RSFilter;
34 class RSNGRenderShaderBase;
35 namespace Drawing {
36 class GEShader;
37 class RuntimeEffect;
38 class GEVisualEffectContainer;
39 }
40 #ifdef RS_ENABLE_VK
41 namespace NativeBufferUtils {
42 class VulkanCleanupHelper;
43 }
44 #endif
45 
46 namespace DrawableV2 {
47 class RSShadowDrawable : public RSDrawable {
48 public:
49     RSShadowDrawable() = default;
50     ~RSShadowDrawable() = default;
51     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
52     bool OnUpdate(const RSRenderNode& node) override;
53     void OnSync() override;
54     Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override;
55 
56 private:
57     bool needSync_ = false;
58     bool isFilled_ = false;
59     bool stagingIsFilled_ = false;
60     float offsetX_ = 0.0f;
61     float stagingOffsetX_ = 0.0f;
62     float offsetY_ = 0.0f;
63     float stagingOffsetY_ = 0.0f;
64     float elevation_ = 0.0f;
65     float stagingElevation_ = 0.0f;
66     float radius_ = 0.0f;
67     float stagingRadius_ = 0.0f;
68     int colorStrategy_ = 0;
69     int stagingColorStrategy_ = 0;
70     Drawing::Path path_;
71     Drawing::Path stagingPath_;
72     Color color_;
73     Color stagingColor_;
74 };
75 
76 class RSMaskDrawable : public RSPropertyDrawable {
77 public:
RSMaskDrawable(std::shared_ptr<Drawing::DrawCmdList> && drawCmdList)78     RSMaskDrawable(std::shared_ptr<Drawing::DrawCmdList>&& drawCmdList) : RSPropertyDrawable(std::move(drawCmdList)) {}
79     RSMaskDrawable() = default;
80     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
81     bool OnUpdate(const RSRenderNode& node) override;
82 
83 private:
84 };
85 
86 // ============================================================================
87 // Background
88 class RSBackgroundColorDrawable : public RSPropertyDrawable {
89 public:
RSBackgroundColorDrawable(std::shared_ptr<Drawing::DrawCmdList> && drawCmdList)90     RSBackgroundColorDrawable(std::shared_ptr<Drawing::DrawCmdList>&& drawCmdList)
91         : RSPropertyDrawable(std::move(drawCmdList))
92     {}
93     RSBackgroundColorDrawable() = default;
94     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
95     bool OnUpdate(const RSRenderNode& node) override;
96 };
97 
98 class RSBackgroundShaderDrawable : public RSPropertyDrawable {
99 public:
RSBackgroundShaderDrawable(std::shared_ptr<Drawing::DrawCmdList> && drawCmdList)100     RSBackgroundShaderDrawable(std::shared_ptr<Drawing::DrawCmdList>&& drawCmdList)
101         : RSPropertyDrawable(std::move(drawCmdList))
102     {}
103     RSBackgroundShaderDrawable() = default;
104     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
105     bool OnUpdate(const RSRenderNode& node) override;
106 
107 private:
108 };
109 
110 class RSBackgroundNGShaderDrawable : public RSDrawable {
111 public:
112     RSBackgroundNGShaderDrawable() = default;
113     ~RSBackgroundNGShaderDrawable() override = default;
114 
115     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
116     bool OnUpdate(const RSRenderNode& node) override;
117     void OnSync() override;
118     Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override;
119 private:
120     bool needSync_ = false;
121     std::shared_ptr<Drawing::GEVisualEffectContainer> visualEffectContainer_;
122     std::shared_ptr<RSNGRenderShaderBase> stagingShader_;
123 };
124 
125 class RSBackgroundImageDrawable : public RSPropertyDrawable {
126 public:
RSBackgroundImageDrawable(std::shared_ptr<Drawing::DrawCmdList> && drawCmdList)127     RSBackgroundImageDrawable(std::shared_ptr<Drawing::DrawCmdList>&& drawCmdList)
128         : RSPropertyDrawable(std::move(drawCmdList))
129     {}
130     ~RSBackgroundImageDrawable() override;
131     RSBackgroundImageDrawable() = default;
132     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
133     bool OnUpdate(const RSRenderNode& node) override;
134     void OnSync() override;
135     Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override;
136 private:
137 #if defined(ROSEN_OHOS) && defined(RS_ENABLE_VK)
138     static Drawing::ColorType GetColorTypeFromVKFormat(VkFormat vkFormat);
139     std::shared_ptr<Drawing::Image> MakeFromTextureForVK(Drawing::Canvas& canvas, SurfaceBuffer* surfaceBuffer);
140     void ReleaseNativeWindowBuffer();
141     void SetCompressedDataForASTC();
142     OHNativeWindowBuffer* nativeWindowBuffer_ = nullptr;
143     pid_t tid_ = 0;
144     uint32_t pixelMapId_ = 0;
145     Drawing::BackendTexture backendTexture_ = {};
146     NativeBufferUtils::VulkanCleanupHelper* cleanUpHelper_ = nullptr;
147 #endif
148     std::shared_ptr<RSImage> stagingBgImage_ = nullptr;
149     Drawing::Rect stagingBoundsRect_;
150     std::shared_ptr<RSImage> bgImage_ = nullptr;
151     Drawing::Rect boundsRect_;
152 };
153 
154 class RSBackgroundFilterDrawable : public RSFilterDrawable {
155 public:
156     RSBackgroundFilterDrawable() = default;
157     ~RSBackgroundFilterDrawable() override = default;
158 
159     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
160     bool OnUpdate(const RSRenderNode& node) override;
161     void OnSync() override;
162     void RemovePixelStretch();
163     bool FuzePixelStretch(const RSRenderNode& node);
164 
165 private:
166     static std::shared_ptr<RSFilter> GetBehindWindowFilter(const RSRenderNode& node);
167     template<typename T>
168     static bool GetBehindWindowFilterProperty(const RSRenderNode& node, ModifierNG::RSPropertyType type, T& property);
169 };
170 
171 class RSBackgroundEffectDrawable : public RSFilterDrawable {
172 public:
173     RSBackgroundEffectDrawable() = default;
174     ~RSBackgroundEffectDrawable() override = default;
175 
176     bool OnUpdate(const RSRenderNode& node) override;
177     void OnSync() override;
178     Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override;
179 };
180 
181 class RSUseEffectDrawable : public RSDrawable {
182 public:
183     RSUseEffectDrawable() = default;
RSUseEffectDrawable(UseEffectType useEffectType)184     RSUseEffectDrawable(UseEffectType useEffectType) : useEffectType_(useEffectType) {}
RSUseEffectDrawable(DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr drawable)185     RSUseEffectDrawable(DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr drawable)
186         : effectRenderNodeDrawableWeakRef_(drawable)
187     {}
188     ~RSUseEffectDrawable() override = default;
189 
190     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
191     bool OnUpdate(const RSRenderNode& node) override;
192     void OnSync() override;
193     Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override;
194 
195 private:
196     bool needSync_ = false;
197     UseEffectType stagingUseEffectType_ = UseEffectType::DEFAULT;
198     UseEffectType useEffectType_ = UseEffectType::DEFAULT;
199     DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr effectRenderNodeDrawableWeakRef_;
200 };
201 
202 class RSDynamicLightUpDrawable : public RSDrawable {
203 public:
RSDynamicLightUpDrawable(float dynamicLightUpRate,float dynamicLightUpDeg)204     explicit RSDynamicLightUpDrawable(float dynamicLightUpRate, float dynamicLightUpDeg)
205         : dynamicLightUpRate_(dynamicLightUpRate), dynamicLightUpDeg_(dynamicLightUpDeg)
206     {}
207     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
208     bool OnUpdate(const RSRenderNode& node) override;
209     void OnSync() override;
210     Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override;
211 
212 private:
213     static std::shared_ptr<Drawing::Blender> MakeDynamicLightUpBlender(float rate, float degree, float alpha);
214 
215     bool needSync_ = false;
216     float dynamicLightUpRate_ = 0.0f;
217     float dynamicLightUpDeg_ = 0.0f;
218     float stagingDynamicLightUpRate_ = 0.0f;
219     float stagingDynamicLightUpDeg_ = 0.0f;
220 };
221 } // namespace DrawableV2
222 } // namespace OHOS::Rosen
223 #endif // RENDER_SERVICE_BASE_DRAWABLE_RS_PROPERTY_DRAWABLE_BACKGROUND_H
224