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_MISC_DRAWABLE_H 17 #define RENDER_SERVICE_BASE_DRAWABLE_RS_MISC_DRAWABLE_H 18 19 #include <bitset> 20 #include <cstdint> 21 #include <functional> 22 #include <memory> 23 #include <set> 24 #include <unordered_set> 25 26 #include "drawable/rs_drawable.h" 27 #include "modifier_ng/rs_modifier_ng_type.h" 28 #include "pipeline/rs_paint_filter_canvas.h" 29 #include "property/rs_properties_def.h" 30 31 namespace OHOS::Rosen { 32 namespace Drawing { 33 class DrawCmdList; 34 } 35 36 namespace DrawableV2 { 37 class RSRenderNodeDrawableAdapter; 38 // RSChildrenDrawable, for drawing children of RSRenderNode, updates on child add/remove 39 class RSChildrenDrawable : public RSDrawable { 40 public: 41 RSChildrenDrawable() = default; 42 ~RSChildrenDrawable() override = default; 43 44 static RSDrawable::Ptr OnGenerate(const RSRenderNode& node); 45 bool OnUpdate(const RSRenderNode& content) override; 46 void OnSync() override; 47 Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override; 48 49 private: 50 bool needSync_ = false; 51 std::vector<std::shared_ptr<RSRenderNodeDrawableAdapter>> childrenDrawableVec_; 52 std::vector<std::shared_ptr<RSRenderNodeDrawableAdapter>> stagingChildrenDrawableVec_; 53 54 // Shared Transition related 55 bool childrenHasSharedTransition_ = false; 56 bool OnSharedTransition(const std::shared_ptr<RSRenderNode>& node); 57 friend class RSRenderNode; 58 friend class RSRenderNodeDrawableAdapter; 59 }; 60 61 // RSCustomModifierDrawable, for drawing custom modifiers 62 class RSCustomModifierDrawable : public RSDrawable { 63 public: RSCustomModifierDrawable(ModifierNG::RSModifierType modifierType)64 RSCustomModifierDrawable(ModifierNG::RSModifierType modifierType) : modifierTypeNG_(modifierType) 65 { 66 } 67 static RSDrawable::Ptr OnGenerate(const RSRenderNode& content, ModifierNG::RSModifierType type); 68 bool OnUpdate(const RSRenderNode& node) override; 69 void OnSync() override; 70 void OnPurge() override; 71 Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override; 72 73 private: 74 ModifierNG::RSModifierType modifierTypeNG_ = ModifierNG::RSModifierType::INVALID; 75 bool needClearOp_ = false; 76 bool needSync_ = false; 77 Gravity gravity_ = Gravity::DEFAULT; 78 Gravity stagingGravity_ = Gravity::DEFAULT; 79 bool isCanvasNode_ = false; 80 bool stagingIsCanvasNode_ = false; 81 std::vector<std::shared_ptr<Drawing::DrawCmdList>> drawCmdListVec_; 82 std::vector<std::shared_ptr<Drawing::DrawCmdList>> stagingDrawCmdListVec_; 83 }; 84 85 // ============================================================================ 86 // Save and Restore 87 class RSSaveDrawable : public RSDrawable { 88 public: 89 explicit RSSaveDrawable(std::shared_ptr<uint32_t> content); 90 ~RSSaveDrawable() override = default; 91 92 // no need to sync, content_ only used in render thread OnSync()93 void OnSync() override {}; 94 Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override; 95 96 private: 97 std::shared_ptr<uint32_t> content_; 98 }; 99 100 class RSRestoreDrawable : public RSDrawable { 101 public: 102 explicit RSRestoreDrawable(std::shared_ptr<uint32_t> content); 103 ~RSRestoreDrawable() override = default; 104 105 // no need to sync, content_ only used in render thread OnSync()106 void OnSync() override {}; 107 Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override; 108 109 private: 110 std::shared_ptr<uint32_t> content_; 111 }; 112 113 class RSCustomSaveDrawable : public RSDrawable { 114 public: 115 explicit RSCustomSaveDrawable( 116 std::shared_ptr<RSPaintFilterCanvas::SaveStatus> content, RSPaintFilterCanvas::SaveType type); 117 ~RSCustomSaveDrawable() override = default; 118 119 // no need to sync, content_ only used in render thread OnSync()120 void OnSync() override {}; 121 Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override; 122 123 private: 124 std::shared_ptr<RSPaintFilterCanvas::SaveStatus> content_; 125 RSPaintFilterCanvas::SaveType type_; 126 }; 127 128 class RSCustomRestoreDrawable : public RSDrawable { 129 public: 130 explicit RSCustomRestoreDrawable(std::shared_ptr<RSPaintFilterCanvas::SaveStatus> content); 131 ~RSCustomRestoreDrawable() override = default; 132 133 // no need to sync, content_ only used in render thread OnSync()134 void OnSync() override {}; 135 Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override; 136 137 private: 138 std::shared_ptr<RSPaintFilterCanvas::SaveStatus> content_; 139 }; 140 141 // ============================================================================ 142 // EnvFGColor 143 class RSEnvFGColorDrawable : public RSDrawable { 144 public: 145 explicit RSEnvFGColorDrawable() = default; 146 ~RSEnvFGColorDrawable() override = default; 147 148 static RSDrawable::Ptr OnGenerate(const RSRenderNode& node); 149 bool OnUpdate(const RSRenderNode& node) override; 150 void OnSync() override; 151 152 Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override; 153 154 protected: 155 bool needSync_ = false; 156 Color envFGColor_; 157 Color stagingEnvFGColor_; 158 }; 159 160 // ============================================================================ 161 // EnvFGColorStrategy 162 class RSEnvFGColorStrategyDrawable : public RSDrawable { 163 public: 164 explicit RSEnvFGColorStrategyDrawable() = default; 165 ~RSEnvFGColorStrategyDrawable() override = default; 166 167 static RSDrawable::Ptr OnGenerate(const RSRenderNode& node); 168 bool OnUpdate(const RSRenderNode& node) override; 169 void OnSync() override; 170 171 Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override; 172 173 protected: 174 bool needSync_ = false; 175 ForegroundColorStrategyType envFGColorStrategy_; 176 bool needClipToBounds_; 177 Color backgroundColor_; 178 Vector4f boundsRect_; 179 180 ForegroundColorStrategyType stagingEnvFGColorStrategy_; 181 bool stagingNeedClipToBounds_; 182 Color stagingBackgroundColor_; 183 Vector4f stagingBoundsRect_; 184 }; 185 186 class RSCustomClipToFrameDrawable : public RSDrawable { 187 public: 188 explicit RSCustomClipToFrameDrawable() = default; 189 ~RSCustomClipToFrameDrawable() override = default; 190 191 static RSDrawable::Ptr OnGenerate(const RSRenderNode& node); 192 bool OnUpdate(const RSRenderNode& node) override; 193 void OnSync() override; 194 195 Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override; 196 197 protected: 198 bool needSync_ = false; 199 Drawing::Rect stagingCustomClipRect_; 200 Drawing::Rect customClipRect_; 201 }; 202 203 // ============================================================================ 204 // Blender & BlendMode 205 class RSBeginBlenderDrawable : public RSDrawable { 206 public: 207 RSBeginBlenderDrawable() = default; 208 ~RSBeginBlenderDrawable() override = default; 209 210 static RSDrawable::Ptr OnGenerate(const RSRenderNode& node); 211 void PostUpdate(const RSRenderNode& node); 212 bool OnUpdate(const RSRenderNode& node) override; 213 void OnSync() override; 214 Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override; 215 GetEnableEDR()216 bool GetEnableEDR() const override 217 { 218 return enableEDREffect_; 219 } 220 221 private: 222 NodeId screenNodeId_ = INVALID_NODEID; 223 224 bool needSync_ = false; 225 bool enableEDREffect_ = false; 226 std::shared_ptr<Drawing::Blender> blender_ = nullptr; 227 int blendApplyType_ = 0; 228 bool isDangerous_ = false; 229 std::string propertyDescription_; 230 231 std::shared_ptr<Drawing::Blender> stagingBlender_ = nullptr; 232 int stagingBlendApplyType_ = 0; 233 bool stagingIsDangerous_ = false; 234 std::string stagingPropertyDescription_; 235 }; 236 237 class RSEndBlenderDrawable : public RSDrawable { 238 public: 239 RSEndBlenderDrawable() = default; 240 ~RSEndBlenderDrawable() override = default; 241 242 static RSDrawable::Ptr OnGenerate(const RSRenderNode& node); 243 bool OnUpdate(const RSRenderNode& node) override; 244 void OnSync() override; 245 Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override; 246 247 private: 248 bool needSync_ = false; 249 int blendApplyType_ = 0; 250 int stagingBlendApplyType_ = 0; 251 }; 252 } // namespace DrawableV2 253 } // namespace OHOS::Rosen 254 #endif // RENDER_SERVICE_BASE_DRAWABLE_RS_MISC_DRAWABLE_H 255