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