1 /* 2 * Copyright (c) 2025 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_DRAWABLE_RS_SCREEN_RENDER_NODE_DRAWABLE_H 17 #define RENDER_SERVICE_DRAWABLE_RS_SCREEN_RENDER_NODE_DRAWABLE_H 18 19 #include <memory> 20 21 #include "common/rs_common_def.h" 22 #include "common/rs_occlusion_region.h" 23 #include "drawable/rs_render_node_drawable.h" 24 #include "params/rs_render_thread_params.h" 25 #include "pipeline/render_thread/rs_base_render_engine.h" 26 #include "pipeline/render_thread/rs_uni_render_virtual_processor.h" 27 #include "pipeline/rs_processor_factory.h" 28 #include "pipeline/rs_render_node.h" 29 #include "pipeline/rs_surface_handler.h" 30 #include "screen_manager/rs_screen_manager.h" 31 32 namespace OHOS::Rosen { 33 namespace DrawableV2 { 34 class RSScreenRenderNodeDrawable : public RSRenderNodeDrawable { 35 public: 36 ~RSScreenRenderNodeDrawable() override = default; 37 38 static RSRenderNodeDrawable::Ptr OnGenerate(std::shared_ptr<const RSRenderNode> node); 39 void OnDraw(Drawing::Canvas& canvas) override; OnCapture(Drawing::Canvas & canvas)40 void OnCapture(Drawing::Canvas& canvas) override {} 41 GetCacheImgForCapture()42 std::shared_ptr<Drawing::Image> GetCacheImgForCapture() const 43 { 44 return cacheImgForMultiScreenView_; 45 } 46 SetCacheImgForCapture(std::shared_ptr<Drawing::Image> cacheImgForCapture)47 void SetCacheImgForCapture(std::shared_ptr<Drawing::Image> cacheImgForCapture) 48 { 49 if (cacheImgForMultiScreenView_ == cacheImgForCapture) { 50 return; 51 } 52 cacheImgForMultiScreenView_ = cacheImgForCapture; 53 } 54 GetRSSurfaceHandlerOnDraw()55 const std::shared_ptr<RSSurfaceHandler> GetRSSurfaceHandlerOnDraw() const 56 { 57 return surfaceHandler_; 58 } 59 GetMutableRSSurfaceHandlerOnDraw()60 std::shared_ptr<RSSurfaceHandler> GetMutableRSSurfaceHandlerOnDraw() 61 { 62 return surfaceHandler_; 63 } 64 GetDirtyRects()65 const std::vector<RectI>& GetDirtyRects() const 66 { 67 return dirtyRects_; 68 } 69 SetDirtyRects(const std::vector<RectI> & rects)70 void SetDirtyRects(const std::vector<RectI>& rects) 71 { 72 dirtyRects_ = rects; 73 } 74 GetSyncDirtyManager()75 std::shared_ptr<RSDirtyRegionManager> GetSyncDirtyManager() const override 76 { 77 return syncDirtyManager_; 78 } 79 80 int32_t GetBufferAge(); 81 void SetDamageRegion(const std::vector<RectI>& rects); 82 #ifndef ROSEN_CROSS_PLATFORM 83 bool CreateSurface(sptr<IBufferConsumerListener> listener); GetConsumerListener()84 sptr<IBufferConsumerListener> GetConsumerListener() const 85 { 86 return consumerListener_; 87 } 88 #endif IsSurfaceCreated()89 bool IsSurfaceCreated() const 90 { 91 return surfaceCreated_; 92 } GetRSSurface()93 std::shared_ptr<RSSurface> GetRSSurface() const 94 { 95 return surface_; 96 } SetVirtualSurface(std::shared_ptr<RSSurface> & virtualSurface,uint64_t pSurfaceUniqueId)97 void SetVirtualSurface(std::shared_ptr<RSSurface>& virtualSurface, uint64_t pSurfaceUniqueId) 98 { 99 virtualSurface_ = virtualSurface; 100 virtualSurfaceUniqueId_ = pSurfaceUniqueId; 101 } GetVirtualSurface(uint64_t pSurfaceUniqueId)102 std::shared_ptr<RSSurface> GetVirtualSurface(uint64_t pSurfaceUniqueId) 103 { 104 return virtualSurfaceUniqueId_ != pSurfaceUniqueId ? nullptr : virtualSurface_; 105 } 106 bool SkipFrame(uint32_t refreshRate, ScreenInfo screenInfo); IsRenderSkipIfScreenOff()107 bool IsRenderSkipIfScreenOff() const 108 { 109 return isRenderSkipIfScreenOff_; 110 } 111 SetLastPixelFormat(const GraphicPixelFormat & lastPixelFormat)112 void SetLastPixelFormat(const GraphicPixelFormat& lastPixelFormat) 113 { 114 lastPixelFormat_ = lastPixelFormat; 115 } 116 GetLastPixelFormat()117 GraphicPixelFormat GetLastPixelFormat() const 118 { 119 return lastPixelFormat_; 120 } 121 IsPixelFormatChanged(RSScreenRenderParams & params)122 bool IsPixelFormatChanged(RSScreenRenderParams& params) const 123 { 124 return lastPixelFormat_ != params.GetNewPixelFormat(); 125 } 126 GetDrawableType()127 RSRenderNodeDrawableType GetDrawableType() const override 128 { 129 return RSRenderNodeDrawableType::SCREEN_NODE_DRAWABLE; 130 } 131 GetFirstBufferRotation()132 ScreenRotation GetFirstBufferRotation() const 133 { 134 return firstBufferRotation_; 135 } 136 SetFirstBufferRotation(const ScreenRotation bufferRotation)137 void SetFirstBufferRotation(const ScreenRotation bufferRotation) 138 { 139 firstBufferRotation_ = bufferRotation; 140 } 141 void CheckAndUpdateFilterCacheOcclusionFast(); 142 143 private: 144 explicit RSScreenRenderNodeDrawable(std::shared_ptr<const RSRenderNode>&& node); 145 bool CheckScreenNodeSkip(RSScreenRenderParams& params, std::shared_ptr<RSProcessor> processor); 146 std::unique_ptr<RSRenderFrame> RequestFrame(RSScreenRenderParams& params, std::shared_ptr<RSProcessor> processor); 147 void DrawCurtainScreen() const; 148 void RemoveClearMemoryTask() const; 149 void PostClearMemoryTask() const; 150 void SetScreenNodeSkipFlag(RSRenderThreadParams& uniParam, bool flag); 151 static void CheckFilterCacheFullyCovered(RSSurfaceRenderParams& surfaceParams, RectI screenRect); 152 static void CheckAndUpdateFilterCacheOcclusion(RSScreenRenderParams& params, const ScreenInfo& screenInfo); 153 bool HardCursorCreateLayer(std::shared_ptr<RSProcessor> processor); 154 155 void RenderOverDraw(); 156 bool SkipFrameByInterval(uint32_t refreshRate, uint32_t skipFrameInterval); 157 bool SkipFrameByRefreshRate(uint32_t refreshRate, uint32_t expectedRefreshRate); 158 void UpdateSurfaceDrawRegion(std::shared_ptr<RSPaintFilterCanvas>& mainCanvas, 159 RSScreenRenderParams* params); 160 161 static void UpdateSlrScale(ScreenInfo& screenInfo); 162 163 void CheckHpaeBlurRun(bool isHdrOn); 164 165 bool CheckScreenFreezeSkip(RSScreenRenderParams& params); 166 167 // hpae offline 168 void CheckAndPostAsyncProcessOfflineTask(); 169 bool ProcessOfflineSurfaceDrawable(const std::shared_ptr<RSProcessor>& processor, 170 std::shared_ptr<RSSurfaceRenderNodeDrawable>& surfaceDrawable, bool async); 171 172 using Registrar = RenderNodeDrawableRegistrar<RSRenderNodeType::SCREEN_NODE, OnGenerate>; 173 static Registrar instance_; 174 std::shared_ptr<RSSurfaceHandler> surfaceHandler_ = nullptr; 175 mutable std::shared_ptr<RSPaintFilterCanvas> curCanvas_ = nullptr; 176 std::unique_ptr<RSRenderFrame> expandRenderFrame_ = nullptr; 177 std::shared_ptr<Drawing::Surface> offscreenSurface_ = nullptr; // temporarily holds offscreen surface 178 std::shared_ptr<RSPaintFilterCanvas> canvasBackup_ = nullptr; // backup current canvas before offscreen render 179 std::shared_ptr<Drawing::Image> cacheImgForMultiScreenView_ = nullptr; 180 GraphicPixelFormat lastPixelFormat_ = GraphicPixelFormat::GRAPHIC_PIXEL_FMT_RGBA_8888; 181 bool isScreenNodeSkip_ = false; 182 bool isScreenNodeSkipStatusChanged_ = false; 183 bool useFixedOffscreenSurfaceSize_ = false; 184 uint64_t virtualSurfaceUniqueId_ = 0; 185 // dirty manager 186 std::shared_ptr<RSDirtyRegionManager> syncDirtyManager_ = nullptr; 187 std::vector<RectI> dirtyRects_; 188 189 // surface create in render thread 190 static constexpr uint32_t BUFFER_SIZE = 4; 191 bool surfaceCreated_ = false; 192 std::shared_ptr<RSSurface> surface_ = nullptr; 193 std::shared_ptr<RSSurface> virtualSurface_ = nullptr; 194 ScreenRotation firstBufferRotation_ = ScreenRotation::INVALID_SCREEN_ROTATION; 195 196 bool isMirrorSLRCopy_ = false; 197 #ifndef ROSEN_CROSS_PLATFORM 198 sptr<IBufferConsumerListener> consumerListener_ = nullptr; 199 #endif 200 int64_t lastRefreshTime_ = 0; 201 bool virtualDirtyRefresh_ = false; 202 bool enableVisibleRect_ = false; 203 Drawing::RectI curVisibleRect_; 204 Drawing::RectI lastVisibleRect_; 205 206 bool isRenderSkipIfScreenOff_ = false; 207 208 bool filterCacheOcclusionUpdated_ = false; 209 210 bool hardCursorLastCommitSuccess_ = false; 211 }; 212 } // namespace DrawableV2 213 } // namespace OHOS::Rosen 214 #endif // RENDER_SERVICE_DRAWABLE_RS_SCREEN_RENDER_NODE_DRAWABLE_H