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_H 17 #define RENDER_SERVICE_BASE_DRAWABLE_RS_PROPERTY_DRAWABLE_H 18 19 #include <memory> 20 21 #include "common/rs_common_def.h" 22 #include "common/rs_rect.h" 23 #include "render/rs_filter.h" 24 #include "recording/draw_cmd_list.h" 25 26 #include "drawable/rs_drawable.h" 27 28 namespace OHOS::Rosen { 29 class RSRenderNode; 30 class RSFilter; 31 class RSFilterCacheManager; 32 class ExtendRecordingCanvas; 33 34 namespace DrawableV2 { 35 class RSPropertyDrawable : public RSDrawable { 36 public: RSPropertyDrawable(std::shared_ptr<Drawing::DrawCmdList> && drawCmdList)37 RSPropertyDrawable(std::shared_ptr<Drawing::DrawCmdList>&& drawCmdList) : drawCmdList_(std::move(drawCmdList)) {} 38 RSPropertyDrawable() = default; 39 ~RSPropertyDrawable() override = default; 40 41 void OnSync() override; 42 void OnPurge() override; 43 Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override; 44 45 protected: 46 bool needSync_ = false; 47 std::shared_ptr<Drawing::DrawCmdList> drawCmdList_; 48 std::shared_ptr<Drawing::DrawCmdList> stagingDrawCmdList_; 49 std::string propertyDescription_; 50 std::string stagingPropertyDescription_; 51 52 friend class RSPropertyDrawCmdListUpdater; 53 }; 54 55 class RSPropertyDrawCmdListUpdater { 56 public: 57 // not copyable and moveable 58 RSPropertyDrawCmdListUpdater(const RSPropertyDrawCmdListUpdater&) = delete; 59 RSPropertyDrawCmdListUpdater(const RSPropertyDrawCmdListUpdater&&) = delete; 60 RSPropertyDrawCmdListUpdater& operator=(const RSPropertyDrawCmdListUpdater&) = delete; 61 RSPropertyDrawCmdListUpdater& operator=(const RSPropertyDrawCmdListUpdater&&) = delete; 62 63 explicit RSPropertyDrawCmdListUpdater(int width, int height, RSPropertyDrawable* target); 64 virtual ~RSPropertyDrawCmdListUpdater(); 65 const std::unique_ptr<ExtendRecordingCanvas>& GetRecordingCanvas() const; 66 67 protected: 68 std::unique_ptr<ExtendRecordingCanvas> recordingCanvas_; 69 RSPropertyDrawable* target_; 70 }; 71 72 // ============================================================================ 73 // Frame offset 74 class RSFrameOffsetDrawable : public RSPropertyDrawable { 75 public: RSFrameOffsetDrawable(std::shared_ptr<Drawing::DrawCmdList> && drawCmdList)76 RSFrameOffsetDrawable(std::shared_ptr<Drawing::DrawCmdList>&& drawCmdList) 77 : RSPropertyDrawable(std::move(drawCmdList)) 78 {} 79 RSFrameOffsetDrawable() = default; 80 static RSDrawable::Ptr OnGenerate(const RSRenderNode& node); 81 bool OnUpdate(const RSRenderNode& node) override; 82 83 private: 84 }; 85 86 // ============================================================================ 87 // Clip To Bounds and Clip To Frame 88 class RSClipToBoundsDrawable : public RSPropertyDrawable { 89 public: RSClipToBoundsDrawable(std::shared_ptr<Drawing::DrawCmdList> && drawCmdList)90 RSClipToBoundsDrawable(std::shared_ptr<Drawing::DrawCmdList>&& drawCmdList) 91 : RSPropertyDrawable(std::move(drawCmdList)) 92 {} 93 RSClipToBoundsDrawable() = default; 94 static RSDrawable::Ptr OnGenerate(const RSRenderNode& node); 95 bool OnUpdate(const RSRenderNode& node) override; 96 97 private: 98 }; 99 100 class RSClipToFrameDrawable : public RSPropertyDrawable { 101 public: RSClipToFrameDrawable(std::shared_ptr<Drawing::DrawCmdList> && drawCmdList)102 RSClipToFrameDrawable(std::shared_ptr<Drawing::DrawCmdList>&& drawCmdList) 103 : RSPropertyDrawable(std::move(drawCmdList)) 104 {} 105 RSClipToFrameDrawable() = default; 106 static RSDrawable::Ptr OnGenerate(const RSRenderNode& node); 107 bool OnUpdate(const RSRenderNode& node) override; 108 109 private: 110 }; 111 112 class RSFilterDrawable : public RSDrawable { 113 public: 114 RSFilterDrawable(); 115 ~RSFilterDrawable() override = default; 116 IsForeground()117 virtual bool IsForeground() const 118 { 119 return false; 120 } 121 122 // set flags for clearing filter cache 123 // All MarkXXX function should be called from render_service thread 124 void MarkFilterRegionChanged(); 125 void MarkFilterRegionInteractWithDirty(); 126 void MarkFilterRegionIsLargeArea(); 127 void MarkFilterForceUseCache(bool forceUseCache = true); 128 void MarkFilterForceClearCache(); 129 void MarkEffectNode(); 130 void MarkForceClearCacheWithLastFrame(); 131 void MarkRotationChanged(); 132 void MarkNodeIsOccluded(bool isOccluded); 133 void MarkNeedClearFilterCache(); 134 void MarkBlurIntersectWithDRM(bool IsIntersectWithDRM, bool isDark); 135 136 bool IsFilterCacheValid() const; 137 bool IsForceClearFilterCache() const; 138 bool IsForceUseFilterCache() const; 139 bool NeedPendingPurge() const; 140 bool IsSkippingFrame() const; 141 bool IsAIBarFilter() const; 142 bool IsAIBarCacheValid(); 143 bool WouldDrawLargeAreaBlur(); 144 bool WouldDrawLargeAreaBlurPrecisely(); 145 146 void OnSync() override; 147 Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override; 148 const RectI GetFilterCachedRegion() const; 149 150 bool IsFilterCacheValidForOcclusion(); 151 152 void SetDrawBehindWindowRegion(RectI region); 153 154 protected: 155 void RecordFilterInfos(const std::shared_ptr<RSFilter>& rsFilter); 156 157 bool needSync_ = false; 158 bool needDrawBehindWindow_ = false; 159 bool stagingNeedDrawBehindWindow_ = false; 160 161 bool stagingIntersectWithDRM_ = false; 162 bool stagingIsDarkColorMode_ = false; 163 164 bool renderIntersectWithDRM_ = false; 165 bool renderIsDarkColorMode_ = false; 166 167 NodeId stagingNodeId_ = INVALID_NODEID; 168 NodeId renderNodeId_ = INVALID_NODEID; 169 std::string stagingNodeName_ = "invalid0"; 170 std::string renderNodeName_ = "invalid0"; 171 172 std::shared_ptr<RSFilter> filter_; 173 std::shared_ptr<RSFilter> stagingFilter_; 174 std::unique_ptr<RSFilterCacheManager> stagingCacheManager_; 175 std::unique_ptr<RSFilterCacheManager> cacheManager_; 176 RectI drawBehindWindowRegion_; 177 RectI stagingDrawBehindWindowRegion_; 178 }; 179 } // namespace DrawableV2 180 } // namespace OHOS::Rosen 181 #endif // RENDER_SERVICE_BASE_DRAWABLE_RS_PROPERTY_DRAWABLE_H 182