1 /* 2 * Copyright (c) 2022-2023 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 #ifndef RENDER_SERVICE_CORE_PIPELINE_RS_UNI_RENDER_VISITOR_H 16 #define RENDER_SERVICE_CORE_PIPELINE_RS_UNI_RENDER_VISITOR_H 17 18 #include <cstdint> 19 #include <list> 20 #include <memory> 21 #include <mutex> 22 #include <optional> 23 #include <parameters.h> 24 #include <set> 25 26 #include "rs_base_render_engine.h" 27 #include "system/rs_system_parameters.h" 28 29 #include "params/rs_render_thread_params.h" 30 #include "pipeline/round_corner_display/rs_rcd_render_manager.h" 31 #include "pipeline/rs_dirty_region_manager.h" 32 #include "pipeline/rs_main_thread.h" 33 #include "pipeline/rs_processor.h" 34 #include "pipeline/rs_recording_canvas.h" 35 #include "pipeline/rs_uni_hwc_prevalidate_util.h" 36 #include "platform/ohos/overdraw/rs_cpu_overdraw_canvas_listener.h" 37 #include "platform/ohos/overdraw/rs_gpu_overdraw_canvas_listener.h" 38 #include "platform/ohos/overdraw/rs_overdraw_controller.h" 39 #include "screen_manager/rs_screen_manager.h" 40 #include "visitor/rs_node_visitor.h" 41 42 class SkPicture; 43 namespace OHOS { 44 namespace Rosen { 45 class RSPaintFilterCanvas; 46 class RSUniRenderVisitor : public RSNodeVisitor { 47 public: 48 using SurfaceDirtyMgrPair = std::pair<std::shared_ptr<RSSurfaceRenderNode>, std::shared_ptr<RSSurfaceRenderNode>>; 49 RSUniRenderVisitor(); 50 RSUniRenderVisitor(std::shared_ptr<RSPaintFilterCanvas> canvas, uint32_t surfaceIndex); 51 explicit RSUniRenderVisitor(const RSUniRenderVisitor& visitor); 52 ~RSUniRenderVisitor() override; 53 54 // To prepare nodes between displayRenderNode and app nodes. 55 void QuickPrepareEffectRenderNode(RSEffectRenderNode& node) override; 56 void QuickPrepareCanvasRenderNode(RSCanvasRenderNode& node) override; 57 void QuickPrepareDisplayRenderNode(RSDisplayRenderNode& node) override; 58 void QuickPrepareSurfaceRenderNode(RSSurfaceRenderNode& node) override; 59 void QuickPrepareChildren(RSRenderNode& node) override; 60 61 void PrepareChildren(RSRenderNode& node) override; 62 void PrepareCanvasRenderNode(RSCanvasRenderNode& node) override; 63 void PrepareDisplayRenderNode(RSDisplayRenderNode& node) override; 64 void PrepareProxyRenderNode(RSProxyRenderNode& node) override; 65 // prepareroot also used for quickprepare 66 void PrepareRootRenderNode(RSRootRenderNode& node) override; 67 void PrepareSurfaceRenderNode(RSSurfaceRenderNode& node) override; 68 void PrepareEffectRenderNode(RSEffectRenderNode& node) override; 69 70 void ProcessChildren(RSRenderNode& node) override; 71 void ProcessChildInner(RSRenderNode& node, const RSRenderNode::SharedPtr child); 72 void ProcessCanvasRenderNode(RSCanvasRenderNode& node) override; 73 void ProcessDisplayRenderNode(RSDisplayRenderNode& node) override; 74 void ProcessProxyRenderNode(RSProxyRenderNode& node) override; 75 void ProcessRootRenderNode(RSRootRenderNode& node) override; 76 void ProcessSurfaceRenderNode(RSSurfaceRenderNode& node) override; 77 void ProcessEffectRenderNode(RSEffectRenderNode& node) override; 78 79 bool DoDirectComposition(std::shared_ptr<RSBaseRenderNode> rootNode); 80 void ChangeCacheRenderNodeMap(RSRenderNode& node, const uint32_t count = 0); 81 void UpdateCacheRenderNodeMap(RSRenderNode& node); 82 bool GenerateNodeContentCache(RSRenderNode& node); 83 bool InitNodeCache(RSRenderNode& node); 84 void CopyVisitorInfos(std::shared_ptr<RSUniRenderVisitor> visitor); 85 void CheckSkipRepeatShadow(RSRenderNode& node, const bool resetStatus); 86 void SetNodeSkipShadow(std::shared_ptr<RSRenderNode> node, const bool resetStatus); SetProcessorRenderEngine(std::shared_ptr<RSBaseRenderEngine> renderEngine)87 void SetProcessorRenderEngine(std::shared_ptr<RSBaseRenderEngine> renderEngine) 88 { 89 renderEngine_ = renderEngine; 90 } 91 SetAnimateState(bool doAnimate)92 void SetAnimateState(bool doAnimate) 93 { 94 doAnimate_ = doAnimate; 95 } 96 SetDirtyFlag(bool isDirty)97 void SetDirtyFlag(bool isDirty) 98 { 99 isDirty_ = isDirty; 100 } 101 SetFocusedNodeId(uint64_t nodeId,uint64_t leashId)102 void SetFocusedNodeId(uint64_t nodeId, uint64_t leashId) 103 { 104 currentFocusedNodeId_ = nodeId; 105 focusedLeashWindowId_ = leashId; 106 } 107 SetSubThreadConfig(uint32_t threadIndex)108 void SetSubThreadConfig(uint32_t threadIndex) 109 { 110 isSubThread_ = true; 111 isHardwareForcedDisabled_ = true; 112 threadIndex_ = threadIndex; 113 } 114 GetAnimateState()115 bool GetAnimateState() const 116 { 117 return doAnimate_; 118 } 119 MarkHardwareForcedDisabled()120 void MarkHardwareForcedDisabled() 121 { 122 isHardwareForcedDisabled_ = true; 123 } 124 125 void SetUniRenderThreadParam(std::unique_ptr<RSRenderThreadParams>& renderThreadParams); 126 void SetHardwareEnabledNodes(const std::vector<std::shared_ptr<RSSurfaceRenderNode>>& hardwareEnabledNodes); 127 void AssignGlobalZOrderAndCreateLayer(std::vector<std::shared_ptr<RSSurfaceRenderNode>>& nodesInZOrder); 128 void RotateMirrorCanvasIfNeed(RSDisplayRenderNode& node, bool canvasRotation = false); 129 void ScaleMirrorIfNeed(RSDisplayRenderNode& node, bool canvasRotation = false); 130 void RotateMirrorCanvasIfNeedForWiredScreen(RSDisplayRenderNode& node); 131 void ScaleMirrorIfNeedForWiredScreen(RSDisplayRenderNode& node, bool canvasRotation = false); 132 GetIsPartialRenderEnabled()133 bool GetIsPartialRenderEnabled() const 134 { 135 return isPartialRenderEnabled_; 136 } GetIsOpDropped()137 bool GetIsOpDropped() const 138 { 139 return isOpDropped_; 140 } GetIsRegionDebugEnabled()141 bool GetIsRegionDebugEnabled() const 142 { 143 return isRegionDebugEnabled_; 144 } 145 // Use in vulkan parallel rendering GetColorGamut()146 GraphicColorGamut GetColorGamut() const 147 { 148 return newColorSpace_; 149 } 150 GetProcessor()151 std::shared_ptr<RSProcessor> GetProcessor() const 152 { 153 return processor_; 154 } 155 SetRenderFrame(std::unique_ptr<RSRenderFrame> renderFrame)156 void SetRenderFrame(std::unique_ptr<RSRenderFrame> renderFrame) 157 { 158 renderFrame_ = std::move(renderFrame); 159 } 160 void SetAppWindowNum(uint32_t num); 161 SetForceUpdateFlag(bool flag)162 void SetForceUpdateFlag(bool flag) 163 { 164 forceUpdateFlag_ = flag; 165 } 166 SetScreenInfo(ScreenInfo screenInfo)167 void SetScreenInfo(ScreenInfo screenInfo) 168 { 169 screenInfo_ = screenInfo; 170 } 171 172 // Use in updating hwcnode hardware state with background alpha 173 void UpdateHardwareStateByHwcNodeBackgroundAlpha(const std::vector<std::weak_ptr<RSSurfaceRenderNode>>& hwcNodes); 174 175 bool IsNodeAboveInsideOfNodeBelow(const RectI& rectAbove, std::list<RectI>& hwcNodeRectList); 176 // Use end 177 178 void SurfaceOcclusionCallbackToWMS(); 179 180 std::unordered_set<NodeId> GetCurrentBlackList() const; 181 182 static void ClearRenderGroupCache(); 183 184 using RenderParam = std::tuple<std::shared_ptr<RSRenderNode>, RSPaintFilterCanvas::CanvasStatus>; 185 private: 186 /* Prepare relevant calculation */ 187 // considering occlusion info for app surface as well as widget 188 bool IsSubTreeOccluded(RSRenderNode& node) const; 189 // restore node's flag and filter dirty collection 190 void PostPrepare(RSRenderNode& node, bool subTreeSkipped = false); 191 void UpdateNodeVisibleRegion(RSSurfaceRenderNode& node); 192 void CalculateOcclusion(RSSurfaceRenderNode& node); 193 194 void CheckFilterCacheNeedForceClearOrSave(RSRenderNode& node); 195 void UpdateOccludedStatusWithFilterNode(std::shared_ptr<RSSurfaceRenderNode>& surfaceNode) const; 196 void PartialRenderOptionInit(); 197 RSVisibleLevel GetRegionVisibleLevel(const Occlusion::Region& visibleRegion, 198 const Occlusion::Region& selfDrawRegion); 199 void UpdateSurfaceOcclusionInfo(); 200 void CalcChildFilterNodeDirtyRegion(std::shared_ptr<RSSurfaceRenderNode>& currentSurfaceNode, 201 std::shared_ptr<RSDisplayRenderNode>& displayNode); 202 void CalcSurfaceFilterNodeDirtyRegion(std::shared_ptr<RSSurfaceRenderNode>& currentSurfaceNode, 203 std::shared_ptr<RSDisplayRenderNode>& displayNode); 204 void DrawWatermarkIfNeed(RSDisplayRenderNode& node, bool isMirror = false); 205 enum class RSPaintStyle { 206 FILL, 207 STROKE 208 }; 209 void DrawDirtyRectForDFX(const RectI& dirtyRect, const Drawing::Color color, 210 const RSPaintStyle fillType, float alpha, int edgeWidth, std::string extra = ""); 211 void DrawDirtyRegionForDFX(std::vector<RectI> dirtyRects); 212 void DrawCacheRegionForDFX(std::map<NodeId, RectI>& cacheRects); 213 void DrawHwcRegionForDFX(std::vector<std::shared_ptr<RSSurfaceRenderNode>>& hwcNodes); 214 void DrawAllSurfaceDirtyRegionForDFX(RSDisplayRenderNode& node, const Occlusion::Region& region); 215 void DrawAllSurfaceOpaqueRegionForDFX(RSDisplayRenderNode& node); 216 void DrawSurfaceOpaqueRegionForDFX(RSSurfaceRenderNode& node); 217 void DrawTargetSurfaceVisibleRegionForDFX(RSDisplayRenderNode& node); 218 void DrawCurrentRefreshRate(uint32_t currentRefreshRate, uint32_t realtimeRefreshRate, RSDisplayRenderNode& node); 219 // check if surface name is in dfx target list CheckIfSurfaceTargetedForDFX(std::string nodeName)220 inline bool CheckIfSurfaceTargetedForDFX(std::string nodeName) 221 { 222 return (std::find(dfxTargetSurfaceNames_.begin(), dfxTargetSurfaceNames_.end(), 223 nodeName) != dfxTargetSurfaceNames_.end()); 224 } 225 226 bool DrawDetailedTypesOfDirtyRegionForDFX(RSSurfaceRenderNode& node); 227 void DrawAndTraceSingleDirtyRegionTypeForDFX(RSSurfaceRenderNode& node, 228 DirtyRegionType dirtyType, bool isDrawn = true); 229 230 bool InitDisplayInfo(RSDisplayRenderNode& node); 231 232 bool BeforeUpdateSurfaceDirtyCalc(RSSurfaceRenderNode& node); 233 bool NeedPrepareChindrenInReverseOrder(RSRenderNode& node) const; 234 bool IsLeashAndHasMainSubNode(RSRenderNode& node) const; 235 bool AfterUpdateSurfaceDirtyCalc(RSSurfaceRenderNode& node); 236 void UpdateLeashWindowVisibleRegionEmpty(RSSurfaceRenderNode& node); 237 void UpdateSurfaceRenderNodeRotate(RSSurfaceRenderNode& node); 238 void UpdateSurfaceDirtyAndGlobalDirty(); 239 // should ensure that the surface size of dirty region manager has been set 240 void ResetDisplayDirtyRegion(); 241 bool CheckScreenPowerChange() const; 242 bool CheckColorFilterChange() const; 243 bool CheckCurtainScreenUsingStatusChange() const; 244 bool CheckLuminanceStatusChange(); 245 bool IsFirstFrameOfPartialRender() const; 246 bool IsFirstFrameOfOverdrawSwitch() const; 247 bool IsWatermarkFlagChanged() const; 248 void UpdateDisplayZoomState(); 249 void CollectFilterInfoAndUpdateDirty(RSRenderNode& node, 250 RSDirtyRegionManager& dirtyManager, const RectI& globalFilterRect); 251 RectI GetVisibleEffectDirty(RSRenderNode& node) const; 252 253 void UpdateHwcNodeEnableByGlobalFilter(std::shared_ptr<RSSurfaceRenderNode>& node); 254 void UpdateHwcNodeEnableByGlobalCleanFilter(const std::vector<std::pair<NodeId, RectI>>& cleanFilter, 255 RSSurfaceRenderNode& hwcNodePtr); 256 void UpdateHwcNodeEnableByFilterRect( 257 std::shared_ptr<RSSurfaceRenderNode>& node, const RectI& filterRect, bool isReverseOrder = false); 258 void CalcHwcNodeEnableByFilterRect( 259 std::shared_ptr<RSSurfaceRenderNode>& node, const RectI& filterRect, bool isReverseOrder = false); 260 // This function is used for solving display problems caused by dirty blurfilter node half-obscured. 261 void UpdateDisplayDirtyAndExtendVisibleRegion(); 262 // This function is used to update global dirty and visibleRegion 263 // by processing dirty blurfilter node obscured. 264 void ProcessFilterNodeObscured(std::shared_ptr<RSSurfaceRenderNode>& surfaceNode, 265 Occlusion::Region& extendRegion, const RSRenderNodeMap& nodeMap); 266 void UpdateHwcNodeEnableByBackgroundAlpha(RSSurfaceRenderNode& node); 267 void UpdateHwcNodeEnableBySrcRect(RSSurfaceRenderNode& node); 268 void UpdateHwcNodeEnableByBufferSize(RSSurfaceRenderNode& node); 269 void UpdateHwcNodeInfoForAppNode(RSSurfaceRenderNode& node); 270 void UpdateSrcRect(RSSurfaceRenderNode& node, 271 const Drawing::Matrix& absMatrix, const RectI& clipRect); 272 void UpdateDstRect(RSSurfaceRenderNode& node, const RectI& absRect, const RectI& clipRect); 273 void UpdateHwcNodeProperty(std::shared_ptr<RSSurfaceRenderNode> hwcNode); 274 void UpdateHwcNodeByTransform(RSSurfaceRenderNode& node); 275 void UpdateHwcNodeEnableByRotateAndAlpha(std::shared_ptr<RSSurfaceRenderNode>& node); 276 void ProcessAncoNode(std::shared_ptr<RSSurfaceRenderNode>& hwcNodePtr); 277 void InitAncoStatus(); 278 void UpdateAncoNodeHWCDisabledState(); 279 void UpdateHwcNodeEnableByHwcNodeBelowSelfInApp(std::vector<RectI>& hwcRects, 280 std::shared_ptr<RSSurfaceRenderNode>& hwcNode); 281 void UpdateChildHwcNodeEnableByHwcNodeBelow(std::vector<RectI>& hwcRects, 282 std::shared_ptr<RSSurfaceRenderNode>& appNode); 283 void UpdateHwcNodeEnableByHwcNodeBelowSelf(std::vector<RectI>& hwcRects, 284 std::shared_ptr<RSSurfaceRenderNode>& hwcNode, bool isIntersectWithRoundCorner); 285 void UpdateHwcNodeDirtyRegionAndCreateLayer(std::shared_ptr<RSSurfaceRenderNode>& node); 286 void AllSurfacesDrawnInUniRender(const std::vector<std::weak_ptr<RSSurfaceRenderNode>>& hwcNodes); 287 void UpdatePointWindowDirtyStatus(std::shared_ptr<RSSurfaceRenderNode>& pointWindow); 288 void UpdateTopLayersDirtyStatus(const std::vector<std::shared_ptr<RSSurfaceRenderNode>>& topLayers); 289 void UpdateCornerRadiusInfoForDRM(std::shared_ptr<RSSurfaceRenderNode> hwcNode, std::vector<RectI>& hwcRects); 290 bool CheckIfRoundCornerIntersectDRM(const float& ratio, std::vector<float>& ratioVector, 291 const Vector4f& instanceCornerRadius, const RectI& instanceAbsRect, const RectI& hwcAbsRect); 292 void UpdateHwcNodeEnable(); 293 void UpdateHwcNodeEnableByNodeBelow(); 294 void PrevalidateHwcNode(); 295 296 // use in QuickPrepareSurfaceRenderNode, update SurfaceRenderNode's uiFirst status 297 void PrepareForUIFirstNode(RSSurfaceRenderNode& node); 298 299 void UpdateHwcNodeDirtyRegionForApp(std::shared_ptr<RSSurfaceRenderNode>& appNode, 300 std::shared_ptr<RSSurfaceRenderNode>& hwcNode); 301 302 void UpdatePrepareClip(RSRenderNode& node); 303 304 void CheckMergeDisplayDirtyByTransparent(RSSurfaceRenderNode& surfaceNode) const; 305 void CheckMergeDisplayDirtyByZorderChanged(RSSurfaceRenderNode& surfaceNode) const; 306 void CheckMergeDisplayDirtyByPosChanged(RSSurfaceRenderNode& surfaceNode) const; 307 void CheckMergeDisplayDirtyByShadowChanged(RSSurfaceRenderNode& surfaceNode) const; 308 void CheckMergeDisplayDirtyBySurfaceChanged() const; 309 void CheckMergeSurfaceDirtysForDisplay(std::shared_ptr<RSSurfaceRenderNode>& surfaceNode) const; 310 void CheckMergeDisplayDirtyByTransparentRegions(RSSurfaceRenderNode& surfaceNode) const; 311 void CheckMergeFilterDirtyByIntersectWithDirty(OcclusionRectISet& filterSet, bool isGlobalDirty); 312 313 bool IfSkipInCalcGlobalDirty(RSSurfaceRenderNode& surfaceNode) const; 314 void CheckMergeDisplayDirtyByTransparentFilter(std::shared_ptr<RSSurfaceRenderNode>& surfaceNode, 315 Occlusion::Region& accumulatedDirtyRegion); 316 void CheckMergeGlobalFilterForDisplay(Occlusion::Region& accumulatedDirtyRegion); 317 void CheckMergeDebugRectforRefreshRate(std::vector<RSBaseRenderNode::SharedPtr>& surfaces); 318 319 bool IsNotDirtyHardwareEnabledTopSurface(std::shared_ptr<RSSurfaceRenderNode>& node) const; 320 void ClipRegion(std::shared_ptr<Drawing::Canvas> canvas, const Drawing::Region& region) const; 321 /* calculate display/global (between windows) level dirty region, current include: 322 * 1. window move/add/remove 2. transparent dirty region 323 * when process canvas culling, canvas intersect with surface's visibledirty region or 324 * global dirty region will be skipped 325 */ 326 void CalcDirtyDisplayRegion(std::shared_ptr<RSDisplayRenderNode>& node); 327 void CalcDirtyRegionForFilterNode(const RectI& filterRect, 328 std::shared_ptr<RSSurfaceRenderNode>& currentSurfaceNode, 329 std::shared_ptr<RSDisplayRenderNode>& displayNode); 330 331 // remove functions below when dirty region is enabled for foldable device 332 void UpdateHardwareNodeStatusBasedOnFilterRegion(RSDisplayRenderNode& displayNode); 333 void UpdateHardwareNodeStatusBasedOnFilter(std::shared_ptr<RSSurfaceRenderNode>& node, 334 std::vector<std::shared_ptr<RSSurfaceRenderNode>>& prevHwcEnabledNodes); 335 void UpdateHardwareChildNodeStatus(std::shared_ptr<RSSurfaceRenderNode>& node, 336 std::vector<SurfaceDirtyMgrPair>& curHwcEnabledNodes); 337 338 void UpdateHardwareEnableList(std::vector<RectI>& filterRects, 339 std::vector<std::shared_ptr<RSSurfaceRenderNode>>& validHwcNodes); 340 // remove functions above when dirty region is enabled for foldable device 341 342 void CalcDirtyFilterRegion(std::shared_ptr<RSDisplayRenderNode>& node); 343 /* Disable visible hwc surface if it intersects with filter region 344 * Save rest validNodes in prevHwcEnabledNodes 345 * [planning] Update hwc surface dirty status at the same time 346 */ 347 void UpdateHardwareNodeStatusBasedOnFilter(std::shared_ptr<RSSurfaceRenderNode>& node, 348 std::vector<SurfaceDirtyMgrPair>& prevHwcEnabledNodes, 349 std::shared_ptr<RSDirtyRegionManager>& displayDirtyManager); 350 /* Disable hwc surface intersect with filter rects and merge dirty filter region 351 * [planning] If invisible filterRects could be removed 352 */ 353 RectI UpdateHardwareEnableList(std::vector<RectI>& filterRects, 354 std::vector<SurfaceDirtyMgrPair>& validHwcNodes); 355 void MergeDirtyRectIfNeed(std::shared_ptr<RSSurfaceRenderNode> appNode, 356 std::shared_ptr<RSSurfaceRenderNode> hwcNode); 357 void AddContainerDirtyToGlobalDirty(std::shared_ptr<RSDisplayRenderNode>& node) const; 358 // merge last childRect as dirty if any child has been removed 359 void MergeRemovedChildDirtyRegion(RSRenderNode& node, bool needMap = false); 360 // Reset curSurface info as upper surfaceParent in case surfaceParent has multi children 361 void ResetCurSurfaceInfoAsUpperSurfaceParent(RSSurfaceRenderNode& node); 362 void CheckAndSetNodeCacheType(RSRenderNode& node); 363 bool UpdateCacheSurface(RSRenderNode& node); 364 void DrawSpherize(RSRenderNode& node); 365 void DrawChildRenderNode(RSRenderNode& node); 366 void DrawChildCanvasRenderNode(RSRenderNode& node); 367 368 void CheckColorSpace(RSSurfaceRenderNode& node); 369 void CheckColorSpaceWithSelfDrawingNode(RSSurfaceRenderNode& node); 370 void UpdateColorSpaceAfterHwcCalc(RSDisplayRenderNode& node); 371 void HandleColorGamuts(RSDisplayRenderNode& node, const sptr<RSScreenManager>& screenManager); 372 void CheckPixelFormat(RSSurfaceRenderNode& node); 373 void HandlePixelFormat(RSDisplayRenderNode& node, const sptr<RSScreenManager>& screenManager); 374 void AddOverDrawListener(std::unique_ptr<RSRenderFrame>& renderFrame, 375 std::shared_ptr<RSCanvasListener>& overdrawListener); 376 /* Judge if surface render node could skip preparation: 377 * 1. not leash window 378 * 2. parent not dirty 379 * 3. no processWithCommands_ of node's corresponding pid 380 * If so, reset status flag and stop traversal 381 */ 382 bool CheckIfSurfaceRenderNodeStatic(RSSurfaceRenderNode& node); 383 /* Judge if uifirst surface render node could skip subtree preparation: 384 * mainwindow check if it has leashwindow parent 385 * If so, check parent or check itself 386 */ 387 bool CheckIfUIFirstSurfaceContentReusable(std::shared_ptr<RSSurfaceRenderNode>& node, bool& isAssigned); 388 // currently classify surface assigned subthread specific dirty case for preparation 389 void ClassifyUIFirstSurfaceDirtyStatus(RSSurfaceRenderNode& node); 390 391 void PrepareTypesOfSurfaceRenderNodeBeforeUpdate(RSSurfaceRenderNode& node); 392 void PrepareTypesOfSurfaceRenderNodeAfterUpdate(RSSurfaceRenderNode& node); 393 // judge if node's cache changes 394 // return false if cache static and simplify its subtree traversal 395 bool UpdateCacheChangeStatus(RSRenderNode& node); 396 bool IsDrawingCacheStatic(RSRenderNode& node); 397 // if cache root reuses, update its subtree 398 // [attention] check curSurfaceDirtyManager_ before function calls 399 void UpdateSubTreeInCache(const std::shared_ptr<RSRenderNode>& cacheRootNode, 400 const std::vector<RSRenderNode::SharedPtr>& children); 401 // set node cacheable animation after checking whold child tree 402 void SetNodeCacheChangeStatus(RSRenderNode& node); 403 void DisableNodeCacheInSetting(RSRenderNode& node); 404 // update rendernode's cache status and collect valid cache rect 405 void UpdateForegroundFilterCacheWithDirty(RSRenderNode& node, 406 RSDirtyRegionManager& dirtyManager, bool isForeground = true); 407 408 bool IsHardwareComposerEnabled(); 409 410 // choose to keep filter cache if node is filter occluded 411 bool CheckIfSurfaceRenderNodeNeedProcess(RSSurfaceRenderNode& node, bool& keepFilterCache); 412 413 void ClearTransparentBeforeSaveLayer(); 414 // mark surfaceNode's child surfaceView nodes hardware forced disabled 415 void MarkSubHardwareEnableNodeState(RSSurfaceRenderNode& surfaceNode); 416 void CollectAppNodeForHwc(std::shared_ptr<RSSurfaceRenderNode> surfaceNode); 417 void UpdateSecuritySkipAndProtectedLayersRecord(RSSurfaceRenderNode& node); 418 void PrepareEffectNodeIfCacheReuse(const std::shared_ptr<RSRenderNode>& cacheRootNode, 419 std::shared_ptr<RSEffectRenderNode> effectNode); 420 421 // close partialrender when perform window animation 422 void ClosePartialRenderWhenAnimatingWindows(std::shared_ptr<RSDisplayRenderNode>& node); 423 bool DrawBlurInCache(RSRenderNode& node); 424 void UpdateCacheRenderNodeMapWithBlur(RSRenderNode& node); 425 bool IsFirstVisitedCacheForced() const; 426 bool ForceHardwareComposer(RSSurfaceRenderNode& node) const; 427 // return if srcRect is allowed by dss restriction 428 bool UpdateSrcRectForHwcNode(RSSurfaceRenderNode& node, bool isProtected = false); 429 430 void SwitchColorFilterDrawing(int currentSaveCount); 431 void ProcessShadowFirst(RSRenderNode& node, bool inSubThread); 432 void SaveCurSurface(); 433 void RestoreCurSurface(); 434 void PrepareSubSurfaceNodes(RSSurfaceRenderNode& node); 435 void ProcessSubSurfaceNodes(RSSurfaceRenderNode& node); 436 437 void SendRcdMessage(RSDisplayRenderNode& node); 438 ForcePrepareSubTree()439 bool ForcePrepareSubTree() 440 { 441 return curSurfaceNode_ && curSurfaceNode_->GetNeedCollectHwcNode(); 442 } IsValidInVirtualScreen(RSSurfaceRenderNode & node)443 bool IsValidInVirtualScreen(RSSurfaceRenderNode& node) const 444 { 445 return !node.GetSkipLayer() && !node.GetSecurityLayer() && (screenInfo_.whiteList.empty() || 446 screenInfo_.whiteList.find(node.GetId()) != screenInfo_.whiteList.end()); 447 } 448 void UpdateRotationStatusForEffectNode(RSEffectRenderNode& node); 449 void CheckFilterNodeInSkippedSubTreeNeedClearCache(const RSRenderNode& node, RSDirtyRegionManager& dirtyManager); 450 void UpdateHwcNodeRectInSkippedSubTree(const RSRenderNode& node); 451 void UpdateSubSurfaceNodeRectInSkippedSubTree(const RSRenderNode& rootNode); 452 void CollectOcclusionInfoForWMS(RSSurfaceRenderNode& node); 453 void CollectEffectInfo(RSRenderNode& node); 454 455 void UpdateVirtualScreenSecurityExemption(RSDisplayRenderNode& node); 456 457 /* Check whether gpu overdraw buffer feature can be enabled on the RenderNode 458 * 1. is leash window 459 * 2. window has scale, radius, no transparency and no animation 460 * 3. find the child background node, which is no transparency and completely filling the window 461 */ 462 void CheckIsGpuOverDrawBufferOptimizeNode(RSSurfaceRenderNode& node); 463 464 void MarkBlurIntersectWithDRM(std::shared_ptr<RSRenderNode> node) const; 465 466 // record DRM nodes 467 std::vector<std::weak_ptr<RSSurfaceRenderNode>> drmNodes_; 468 std::shared_ptr<Drawing::Surface> offscreenSurface_; // temporary holds offscreen surface 469 std::shared_ptr<RSPaintFilterCanvas> canvasBackup_; // backup current canvas before offscreen render 470 471 // Use in vulkan parallel rendering 472 bool IsOutOfScreenRegion(RectI rect); 473 474 // used to catch overdraw 475 std::shared_ptr<Drawing::Surface> overdrawSurface_ = nullptr; 476 std::shared_ptr<Drawing::OverDrawCanvas> overdrawCanvas_ = nullptr; 477 478 sptr<RSScreenManager> screenManager_; 479 ScreenInfo screenInfo_; 480 RectI screenRect_; 481 std::shared_ptr<RSDirtyRegionManager> curSurfaceDirtyManager_; 482 std::shared_ptr<RSSurfaceRenderNode> curSurfaceNode_; 483 std::stack<std::shared_ptr<RSDirtyRegionManager>> surfaceDirtyManager_; 484 std::stack<std::shared_ptr<RSSurfaceRenderNode>> surfaceNode_; 485 float curAlpha_ = 1.f; 486 Vector4f curCornerRadius_{ 0.f, 0.f, 0.f, 0.f }; 487 bool dirtyFlag_ { false }; 488 std::unique_ptr<RSRenderFrame> renderFrame_; 489 std::shared_ptr<RSPaintFilterCanvas> canvas_; 490 Drawing::Region clipRegion_; 491 std::map<NodeId, std::shared_ptr<RSSurfaceRenderNode>> dirtySurfaceNodeMap_; 492 std::map<NodeId, RectI> cacheRenderNodeMapRects_; 493 std::map<NodeId, bool> cacheRenderNodeIsUpdateMap_; 494 Drawing::Rect boundsRect_ {}; 495 Gravity frameGravity_ = Gravity::DEFAULT; 496 497 int32_t offsetX_ { 0 }; 498 int32_t offsetY_ { 0 }; 499 std::shared_ptr<RSProcessor> processor_; 500 Drawing::Matrix parentSurfaceNodeMatrix_; 501 502 ScreenId currentVisitDisplay_ = INVALID_SCREEN_ID; 503 std::map<ScreenId, bool> displayHasSecSurface_; 504 std::map<ScreenId, bool> displayHasSkipSurface_; 505 std::map<ScreenId, bool> displayHasProtectedSurface_; 506 std::map<ScreenId, bool> displaySpecailSurfaceChanged_; 507 std::map<ScreenId, bool> hasCaptureWindow_; 508 std::set<ScreenId> mirroredDisplays_; 509 bool isSecurityDisplay_ = false; 510 511 bool hasFingerprint_ = false; 512 bool hasUniRenderHdrSurface_ = false; 513 bool mirrorAutoRotate_ = false; 514 515 std::shared_ptr<RSBaseRenderEngine> renderEngine_; 516 517 std::shared_ptr<RSDirtyRegionManager> curDisplayDirtyManager_; 518 std::shared_ptr<RSDisplayRenderNode> curDisplayNode_; 519 bool doAnimate_ = false; 520 bool isSurfaceRotationChanged_ = false; 521 bool isPartialRenderEnabled_ = false; 522 bool isCompleteRenderEnabled_ = false; 523 bool isOpDropped_ = false; 524 bool isDirtyRegionDfxEnabled_ = false; // dirtyRegion DFX visualization 525 bool isTargetDirtyRegionDfxEnabled_ = false; 526 bool isOpaqueRegionDfxEnabled_ = false; 527 bool isVisibleRegionDfxEnabled_ = false; 528 bool isAllSurfaceVisibleDebugEnabled_ = false; 529 bool isDisplayDirtyDfxEnabled_ = false; 530 bool isCanvasNodeSkipDfxEnabled_ = false; 531 bool isVirtualDirtyEnabled_ = false; 532 bool isVirtualDirtyDfxEnabled_ = false; 533 bool isExpandScreenDirtyEnabled_ = false; 534 bool hasMirrorDisplay_ = false; 535 // if display node has skip layer except capsule window 536 bool hasSkipLayer_ = false; 537 bool isQuickSkipPreparationEnabled_ = false; 538 bool isOcclusionEnabled_ = false; 539 bool isSkipCanvasNodeOutOfScreen_ = false; 540 bool isScreenRotationAnimating_ = false; 541 bool displayNodeRotationChanged_ = false; 542 std::vector<std::string> dfxTargetSurfaceNames_; 543 PartialRenderType partialRenderType_; 544 QuickSkipPrepareType quickSkipPrepareType_; 545 DirtyRegionDebugType dirtyRegionDebugType_; 546 SurfaceRegionDebugType surfaceRegionDebugType_; 547 bool isRegionDebugEnabled_ = false; 548 bool isDirty_ = false; 549 // added for judge if drawing cache changes 550 bool isDrawingCacheEnabled_ = false; 551 std::stack<bool> isDrawingCacheChanged_ = {}; 552 std::vector<RectI> accumulatedDirtyRegions_ = {}; 553 bool isSubSurfaceEnabled_ = false; 554 555 // opinc feature 556 bool autoCacheEnable_ = false; 557 bool unchangeMarkEnable_ = false; 558 bool unchangeMarkInApp_ = false; 559 560 bool needFilter_ = false; 561 GraphicColorGamut newColorSpace_ = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB; 562 GraphicPixelFormat newPixelFormat_ = GraphicPixelFormat::GRAPHIC_PIXEL_FMT_RGBA_8888; 563 std::vector<ScreenColorGamut> colorGamutModes_; 564 uint64_t currentFocusedNodeId_ = 0; 565 uint64_t focusedLeashWindowId_ = 0; 566 567 bool isSubThread_ = false; 568 bool isUIFirst_ = false; 569 bool isUIFirstDebugEnable_ = false; 570 bool hasSelfDraw_ = false; 571 bool ancestorNodeHasAnimation_ = false; 572 bool hasAccumulatedClip_ = false; 573 uint32_t threadIndex_ = UNI_MAIN_THREAD_INDEX; 574 // check each surface could be reused per frame 575 // currently available to uiFirst 576 bool isCachedSurfaceReuse_ = false; 577 bool isSurfaceDirtyNodeLimited_ = false; 578 579 bool isDirtyRegionAlignedEnable_ = false; 580 bool isPrevalidateHwcNodeEnable_ = false; 581 582 RectI prepareClipRect_{0, 0, 0, 0}; // renderNode clip rect used in Prepare 583 584 // count prepared and processed canvasnode numbers per app 585 // unirender visitor resets every frame, no overflow risk here 586 unsigned int preparedCanvasNodeInCurrentSurface_ = 0; 587 unsigned int processedCanvasNodeInCurrentSurface_ = 0; 588 unsigned int processedPureContainerNode_ = 0; 589 590 float globalZOrder_ = 0.0f; 591 bool isUpdateCachedSurface_ = false; 592 bool isHardwareForcedDisabled_ = false; // indicates if hardware composer is totally disabled 593 std::vector<std::shared_ptr<RSSurfaceRenderNode>> hardwareEnabledNodes_; 594 // vector of all app window nodes with surfaceView, sorted by zOrder 595 std::vector<std::shared_ptr<RSSurfaceRenderNode>> appWindowNodesInZOrder_; 596 // vector of hardwareEnabled nodes above displayNodeSurface like pointer window 597 std::vector<std::shared_ptr<RSSurfaceRenderNode>> hardwareEnabledTopNodes_; 598 // vector of Appwindow nodes ids not contain subAppWindow nodes ids in current frame 599 std::queue<NodeId> curMainAndLeashWindowNodesIds_; 600 // vector of Appwindow nodes ids not contain subAppWindow nodes ids in last frame 601 static inline std::queue<NodeId> preMainAndLeashWindowNodesIds_; 602 // vector of current displaynode mainwindow surface visible info 603 VisibleData dstCurVisVec_; 604 // vector of current frame mainwindow surface visible info 605 VisibleData allDstCurVisVec_; 606 // vector of last frame mainwindow surface visible info 607 static inline VisibleData allLastVisVec_; 608 std::mutex occlusionMutex_; 609 float localZOrder_ = 0.0f; // local zOrder for surfaceView under same app window node 610 611 std::unique_ptr<RcdInfo> rcdInfo_ = nullptr; 612 static void ProcessUnpairedSharedTransitionNode(); 613 std::stack<RenderParam> curGroupedNodes_; 614 615 // adapt to sceneboard, mark if the canvasNode within the scope of surfaceNode 616 bool isSubNodeOfSurfaceInPrepare_ = false; 617 bool isSubNodeOfSurfaceInProcess_ = false; 618 619 uint32_t appWindowNum_ = 0; 620 621 // displayNodeMatrix only used in offScreen render case to ensure correct composer layer info when with rotation, 622 // displayNodeMatrix indicates display node's matrix info 623 std::optional<Drawing::Matrix> displayNodeMatrix_; 624 mutable std::mutex copyVisitorInfosMutex_; 625 bool resetRotate_ = false; 626 std::optional<Drawing::RectI> effectRegion_ = std::nullopt; 627 // variable for occlusion 628 bool needRecalculateOcclusion_ = false; 629 Occlusion::Region accumulatedOcclusionRegion_; 630 Occlusion::Region occlusionRegionWithoutSkipLayer_; 631 632 bool curDirty_ = false; 633 bool curContentDirty_ = false; 634 // to record and pass container node dirty to leash node. 635 bool curContainerDirty_ = false; 636 bool isPhone_ = false; 637 bool isPc_ = false; 638 bool isOverdrawDfxOn_ = false; 639 bool isCacheBlurPartialRenderEnabled_ = false; 640 bool drawCacheWithBlur_ = false; 641 bool notRunCheckAndSetNodeCacheType_ = false; 642 bool noNeedTodrawShadowAgain_ = false; 643 int updateCacheProcessCnt_ = 0; 644 std::vector<std::string> windowsName_; 645 646 NodeId firstVisitedCache_ = INVALID_NODEID; 647 std::unordered_set<NodeId> visitedCacheNodeIds_ = {}; 648 std::unordered_map<NodeId, std::unordered_set<NodeId>> allCacheFilterRects_ = {}; 649 std::stack<std::unordered_set<NodeId>> curCacheFilterRects_ = {}; 650 651 // record nodes in surface which has filter may influence globalDirty 652 OcclusionRectISet globalFilter_; 653 // record filter in current surface when there is no below dirty 654 OcclusionRectISet curSurfaceNoBelowDirtyFilter_; 655 // record container nodes which need filter 656 FilterRectISet containerFilter_; 657 // record nodes which has transparent clean filter 658 std::unordered_map<NodeId, std::vector<std::pair<NodeId, RectI>>> transparentCleanFilter_; 659 // record nodes which has transparent dirty filter 660 std::unordered_map<NodeId, std::vector<std::pair<NodeId, RectI>>> transparentDirtyFilter_; 661 662 std::vector<RectI> globalFilterRects_; 663 std::vector<RectI> globalSurfaceBounds_; 664 // visible filter in transparent surface or display must prepare 665 bool filterInGlobal_ = true; 666 bool needRequestNextVsync_ = true; 667 668 bool forceUpdateFlag_ = false; 669 #ifdef ENABLE_RECORDING_DCL 670 void tryCapture(float width, float height); 671 void endCapture() const; 672 std::shared_ptr<ExtendRecordingCanvas> recordingCanvas_; 673 #endif 674 bool isNodeSingleFrameComposer_ = false; 675 // use for screen recording optimization 676 std::shared_ptr<Drawing::Image> cacheImgForCapture_ = nullptr; 677 std::shared_ptr<Drawing::Image> offScreenCacheImgForCapture_ = nullptr; 678 679 void SetHasSharedTransitionNode(RSSurfaceRenderNode& surfaceNode, bool hasSharedTransitionNode); 680 681 // attention: please synchronize the change of RSUniRenderVisitor::ProcessChildren to this func 682 void ProcessChildrenForScreenRecordingOptimization(RSDisplayRenderNode& node, NodeId rootIdOfCaptureWindow); 683 NodeId FindInstanceChildOfDisplay(std::shared_ptr<RSRenderNode> node); 684 bool CheckIfNeedResetRotate(); 685 686 // use for virtual screen app/window filtering ability 687 NodeId virtualScreenWhiteListRootId_ = INVALID_NODEID; 688 void UpdateVirtualScreenWhiteListRootId(const RSRenderNode::SharedPtr& node); 689 690 void UpdateSurfaceRenderNodeScale(RSSurfaceRenderNode& node); 691 692 // dfx for effect render node 693 void DrawEffectRenderNodeForDFX(); 694 std::vector<RectI> nodesUseEffectFallbackForDfx_; 695 std::vector<RectI> nodesUseEffectForDfx_; 696 // pair<ApplyBackgroundEffectNodeList, ApplyBackgroundEffectFallbackNodeList> 697 std::unordered_map<NodeId, std::pair<std::vector<RectI>, std::vector<RectI>>> effectNodeMapForDfx_; 698 699 // use for curtain screen 700 void DrawCurtainScreen(); 701 bool isCurtainScreenOn_ = false; 702 703 // use for hardware compose disabled reason collection 704 HwcDisabledReasonCollection& hwcDisabledReasonCollection_ = HwcDisabledReasonCollection::GetInstance(); 705 706 bool zoomStateChange_ = false; 707 708 // anco RSSurfaceNode process 709 bool ancoHasGpu_ = false; 710 std::unordered_set<std::shared_ptr<RSSurfaceRenderNode>> ancoNodes_; 711 }; 712 } // namespace Rosen 713 } // namespace OHOS 714 715 #endif // RENDER_SERVICE_CORE_PIPELINE_RS_UNI_RENDER_VISITOR_H 716