1 /* 2 * Copyright (c) 2021-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_CLIENT_CORE_PIPELINE_RS_SURFACE_RENDER_NODE_H 16 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_SURFACE_RENDER_NODE_H 17 18 #include <climits> 19 #include <functional> 20 #include <limits> 21 #include <memory> 22 #include <tuple> 23 #include <queue> 24 25 #include "surface_type.h" 26 27 #include "common/rs_macros.h" 28 #include "common/rs_occlusion_region.h" 29 #include "common/rs_special_layer_manager.h" 30 #include "common/rs_vector4.h" 31 #include "display_engine/rs_luminance_control.h" 32 #include "ipc_callbacks/buffer_available_callback.h" 33 #include "ipc_callbacks/buffer_clear_callback.h" 34 #include "memory/rs_memory_track.h" 35 #include "pipeline/rs_paint_filter_canvas.h" 36 #include "pipeline/rs_render_node.h" 37 #include "pipeline/rs_surface_handler.h" 38 #include "pipeline/rs_uni_render_judgement.h" 39 #include "platform/common/rs_surface_ext.h" 40 #include "platform/common/rs_system_properties.h" 41 #include "property/rs_properties_painter.h" 42 #include "screen_manager/screen_types.h" 43 #include "transaction/rs_occlusion_data.h" 44 45 #ifndef ROSEN_CROSS_PLATFORM 46 #include "surface_buffer.h" 47 #include "sync_fence.h" 48 #endif 49 #include "ipc_security/rs_ipc_interface_code_access_verifier_base.h" 50 #ifdef ENABLE_FULL_SCREEN_RECONGNIZE 51 #include "monitor/aps_monitor_impl.h" 52 #endif 53 54 namespace OHOS { 55 namespace Rosen { 56 class OcclusionNode; 57 class RSCommand; 58 class RSDirtyRegionManager; 59 class RSOcclusionHandler; 60 class RSSurfaceHandler; 61 62 // Used for control-level occlusion culling scene info and culled nodes transmission. 63 // Maintained by the Dirty Regions feature team. 64 class RSB_EXPORT OcclusionParams { 65 public: 66 // Enables/Disables control-level occlusion culling for the node's subtree 67 void UpdateOcclusionCullingStatus(bool enable, NodeId keyOcclusionNodeId); 68 IsOcclusionCullingOn()69 bool IsOcclusionCullingOn() 70 { 71 return !keyOcclusionNodeIds_.empty(); 72 } 73 SetOcclusionHandler(std::shared_ptr<RSOcclusionHandler> occlusionHandler)74 void SetOcclusionHandler(std::shared_ptr<RSOcclusionHandler> occlusionHandler) 75 { 76 occlusionHandler_ = occlusionHandler; 77 } 78 GetOcclusionHandler()79 std::shared_ptr<RSOcclusionHandler> GetOcclusionHandler() const 80 { 81 return occlusionHandler_; 82 } 83 TakeCulledNodes()84 std::unordered_set<NodeId> TakeCulledNodes() 85 { 86 return std::move(culledNodes_); 87 } 88 SetCulledNodes(std::unordered_set<NodeId> && culledNodes)89 void SetCulledNodes(std::unordered_set<NodeId>&& culledNodes) 90 { 91 culledNodes_ = std::move(culledNodes); 92 } 93 TakeCulledEntireSubtree()94 std::unordered_set<NodeId> TakeCulledEntireSubtree() 95 { 96 return std::move(culledEntireSubtree_); 97 } 98 SetCulledEntireSubtree(std::unordered_set<NodeId> && culledEntireSubtree)99 void SetCulledEntireSubtree(std::unordered_set<NodeId>&& culledEntireSubtree) 100 { 101 culledEntireSubtree_ = std::move(culledEntireSubtree); 102 } 103 104 void CheckKeyOcclusionNodeValidity( 105 const std::unordered_map<NodeId, std::shared_ptr<OcclusionNode>>& occlusionNodes); 106 private: 107 std::unordered_multiset<NodeId> keyOcclusionNodeIds_; 108 std::shared_ptr<RSOcclusionHandler> occlusionHandler_; 109 std::unordered_set<NodeId> culledNodes_; 110 std::unordered_set<NodeId> culledEntireSubtree_; 111 }; 112 113 class RSB_EXPORT RSSurfaceRenderNode : public RSRenderNode { 114 public: 115 using WeakPtr = std::weak_ptr<RSSurfaceRenderNode>; 116 using SharedPtr = std::shared_ptr<RSSurfaceRenderNode>; 117 using TreeStateChangeCallback = std::function<void(RSSurfaceRenderNode&)>; 118 static inline constexpr RSRenderNodeType Type = RSRenderNodeType::SURFACE_NODE; GetType()119 RSRenderNodeType GetType() const override 120 { 121 return Type; 122 } 123 124 ~RSSurfaceRenderNode() override; 125 126 void PrepareRenderBeforeChildren(RSPaintFilterCanvas& canvas); 127 void PrepareRenderAfterChildren(RSPaintFilterCanvas& canvas); 128 129 void SetIsOnTheTree(bool onTree, NodeId instanceRootNodeId = INVALID_NODEID, 130 NodeId firstLevelNodeId = INVALID_NODEID, NodeId cacheNodeId = INVALID_NODEID, 131 NodeId uifirstRootNodeId = INVALID_NODEID, NodeId screenNodeId = INVALID_NODEID, 132 NodeId logicalDisplayNodeId = INVALID_NODEID) override; IsAppWindow()133 bool IsAppWindow() const 134 { 135 return nodeType_ == RSSurfaceNodeType::APP_WINDOW_NODE; 136 } 137 IsStartingWindow()138 bool IsStartingWindow() const 139 { 140 return nodeType_ == RSSurfaceNodeType::STARTING_WINDOW_NODE; 141 } 142 143 void ResetRenderParams(); 144 GetScreenId()145 ScreenId GetScreenId() const 146 { 147 return screenId_; 148 } 149 IsAbilityComponent()150 bool IsAbilityComponent() const 151 { 152 return nodeType_ == RSSurfaceNodeType::ABILITY_COMPONENT_NODE; 153 } 154 IsLeashWindow()155 bool IsLeashWindow() const 156 { 157 return nodeType_ == RSSurfaceNodeType::LEASH_WINDOW_NODE; 158 } 159 IsRosenWeb()160 bool IsRosenWeb() const 161 { 162 return GetName().find("RosenWeb") != std::string::npos; 163 } 164 IsSubHighPriorityType()165 bool IsSubHighPriorityType() const 166 { 167 return GetName().find("hipreview") != std::string::npos; 168 } 169 IsScbScreen()170 bool IsScbScreen() const 171 { 172 return nodeType_ == RSSurfaceNodeType::SCB_SCREEN_NODE; 173 } 174 SetNodeDirty(bool isNodeDirty)175 void SetNodeDirty(bool isNodeDirty) 176 { 177 isNodeDirty_ = isNodeDirty || isNodeDirtyInLastFrame_; 178 isNodeDirtyInLastFrame_ = isNodeDirty; 179 } 180 IsNodeDirty()181 bool IsNodeDirty() const 182 { 183 return isNodeDirty_; 184 } 185 186 bool IsHardwareEnabledTopSurface() const; 187 void SetHardCursorStatus(bool status); GetHardCursorStatus()188 bool GetHardCursorStatus() const 189 { 190 return isHardCursor_; 191 } 192 GetHardCursorLastStatus()193 bool GetHardCursorLastStatus() const 194 { 195 return isLastHardCursor_; 196 } 197 198 void SetLayerTop(bool isTop, bool isTopLayerForceRefresh = true); 199 IsLayerTop()200 bool IsLayerTop() const 201 { 202 return isLayerTop_; 203 } 204 IsTopLayerForceRefresh()205 bool IsTopLayerForceRefresh() const 206 { 207 return isTopLayerForceRefresh_; 208 } 209 210 void SetForceRefresh(bool isForceRefresh); 211 IsForceRefresh()212 bool IsForceRefresh() const 213 { 214 return isForceRefresh_; 215 } 216 SetHardwareEnableHint(bool enable)217 void SetHardwareEnableHint(bool enable) 218 { 219 if (isHardwareEnableHint_ == enable) { 220 return; 221 } 222 isHardwareEnableHint_ = enable; 223 SetContentDirty(); 224 } 225 IsHardwareEnableHint()226 bool IsHardwareEnableHint() const 227 { 228 return isHardwareEnableHint_; 229 } 230 SetSourceDisplayRenderNodeId(NodeId nodeId)231 void SetSourceDisplayRenderNodeId(NodeId nodeId) 232 { 233 sourceDisplayRenderNodeId_ = nodeId; 234 } 235 GetSourceDisplayRenderNodeId()236 NodeId GetSourceDisplayRenderNodeId() const 237 { 238 return sourceDisplayRenderNodeId_; 239 } 240 241 void SetSourceDisplayRenderNodeDrawable(DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr drawable); 242 SetExistTransparentHardwareEnabledNode(bool exist)243 void SetExistTransparentHardwareEnabledNode(bool exist) 244 { 245 existTransparentHardwareEnabledNode_ = exist; 246 } 247 ExistTransparentHardwareEnabledNode()248 bool ExistTransparentHardwareEnabledNode() const 249 { 250 return existTransparentHardwareEnabledNode_; 251 } 252 253 // indicate if this node type can enable hardware composer IsHardwareEnabledType()254 bool IsHardwareEnabledType() const 255 { 256 return (nodeType_ == RSSurfaceNodeType::SELF_DRAWING_NODE && isHardwareEnabledNode_) || 257 IsLayerTop(); 258 } 259 260 void SetPreSubHighPriorityType(bool priorityType); 261 IsDynamicHardwareEnable()262 bool IsDynamicHardwareEnable() const 263 { 264 return dynamicHardwareEnable_; 265 } 266 void SetHardwareEnabled(bool isEnabled, SelfDrawingNodeType selfDrawingType = SelfDrawingNodeType::DEFAULT, 267 bool dynamicHardwareEnable = true) 268 { 269 isHardwareEnabledNode_ = isEnabled; 270 selfDrawingType_ = selfDrawingType; 271 dynamicHardwareEnable_ = dynamicHardwareEnable; 272 } 273 274 void SetForceHardwareAndFixRotation(bool flag); GetFixRotationByUser()275 bool GetFixRotationByUser() const 276 { 277 return isFixRotationByUser_; 278 } 279 bool IsInFixedRotation() const; 280 void SetInFixedRotation(bool isRotating); 281 GetSelfDrawingNodeType()282 SelfDrawingNodeType GetSelfDrawingNodeType() const 283 { 284 return selfDrawingType_; 285 } 286 NeedBilinearInterpolation()287 bool NeedBilinearInterpolation() const 288 { 289 return nodeType_ == RSSurfaceNodeType::SELF_DRAWING_NODE && isHardwareEnabledNode_; 290 } 291 SetSubNodeShouldPaint()292 void SetSubNodeShouldPaint() 293 { 294 hasSubNodeShouldPaint_ = true; 295 } 296 ResetSubNodeShouldPaint()297 void ResetSubNodeShouldPaint() 298 { 299 hasSubNodeShouldPaint_ = false; 300 } 301 HasSubNodeShouldPaint()302 bool HasSubNodeShouldPaint() const 303 { 304 return hasSubNodeShouldPaint_; 305 } 306 307 #ifndef ROSEN_CROSS_PLATFORM 308 void UpdateBufferInfo(const sptr<SurfaceBuffer>& buffer, const Rect& damageRect, 309 const sptr<SyncFence>& acquireFence, const sptr<SurfaceBuffer>& preBuffer); 310 #endif 311 IsLastFrameHardwareEnabled()312 bool IsLastFrameHardwareEnabled() const 313 { 314 return isLastFrameHardwareEnabled_; 315 } 316 IsCurrentFrameHardwareEnabled()317 bool IsCurrentFrameHardwareEnabled() const 318 { 319 return isCurrentFrameHardwareEnabled_; 320 } 321 SetCurrentFrameHardwareEnabled(bool enable)322 void SetCurrentFrameHardwareEnabled(bool enable) 323 { 324 isCurrentFrameHardwareEnabled_ = enable; 325 } 326 MarkCurrentFrameHardwareEnabled()327 void MarkCurrentFrameHardwareEnabled() 328 { 329 isCurrentFrameHardwareEnabled_ = true; 330 } 331 SetIsRotating(bool isRotating)332 void SetIsRotating(bool isRotating) 333 { 334 isRotating_ = isRotating; 335 } 336 IsRotating()337 bool IsRotating() const 338 { 339 return isRotating_; 340 } 341 ResetRotateState()342 void ResetRotateState() 343 { 344 isRotating_ = false; 345 } 346 ResetCurrentFrameHardwareEnabledState()347 void ResetCurrentFrameHardwareEnabledState() 348 { 349 isLastFrameHardwareEnabled_ = isCurrentFrameHardwareEnabled_; 350 isCurrentFrameHardwareEnabled_ = false; 351 } 352 ResetHardwareEnabledStates()353 void ResetHardwareEnabledStates() 354 { 355 isLastFrameHardwareEnabled_ = false; 356 isCurrentFrameHardwareEnabled_ = false; 357 } 358 SetHardwareForcedDisabledState(bool forcesDisabled)359 void SetHardwareForcedDisabledState(bool forcesDisabled) 360 { 361 isHardwareForcedDisabled_ = forcesDisabled; 362 } 363 SetNodeHasBackgroundColorAlpha(bool forcesDisabled)364 void SetNodeHasBackgroundColorAlpha(bool forcesDisabled) 365 { 366 isHardwareForcedByBackgroundAlpha_ = forcesDisabled; 367 } 368 IsNodeHasBackgroundColorAlpha()369 bool IsNodeHasBackgroundColorAlpha() const 370 { 371 return isHardwareForcedByBackgroundAlpha_; 372 } 373 SetHardwareForcedDisabledStateByFilter(bool forcesDisabled)374 void SetHardwareForcedDisabledStateByFilter(bool forcesDisabled) 375 { 376 isHardwareForcedDisabledByFilter_ = forcesDisabled; 377 } 378 ResetMakeImageState()379 void ResetMakeImageState() 380 { 381 intersectWithAIBar_ = false; 382 hardwareNeedMakeImage_ = false; 383 } 384 SetHardwareNeedMakeImage(bool needMakeImage)385 void SetHardwareNeedMakeImage(bool needMakeImage) 386 { 387 hardwareNeedMakeImage_ = needMakeImage; 388 } 389 IsHardwareNeedMakeImage()390 bool IsHardwareNeedMakeImage() const 391 { 392 if (specialLayerManager_.Find(SpecialLayerType::PROTECTED)) { 393 return false; 394 } 395 return hardwareNeedMakeImage_; 396 } 397 SetIntersectWithAIBar(bool flag)398 void SetIntersectWithAIBar(bool flag) 399 { 400 intersectWithAIBar_ = flag; 401 } 402 GetIntersectWithAIBar()403 bool GetIntersectWithAIBar() const 404 { 405 return intersectWithAIBar_; 406 } 407 IsHardwareForcedDisabledByFilter()408 bool IsHardwareForcedDisabledByFilter() const 409 { 410 return isHardwareForcedDisabledByFilter_; 411 } 412 ResetHardwareForcedDisabledBySrcRect()413 void ResetHardwareForcedDisabledBySrcRect() 414 { 415 isHardwareForcedDisabledBySrcRect_ = false; 416 } 417 IsHardwareForcedDisabled()418 bool IsHardwareForcedDisabled() const 419 { 420 // a protected node not on the tree need to release buffer when producer produce buffers 421 // release buffer in ReleaseSelfDrawingNodeBuffer function 422 // isForcedClipHole: for tv product, force clip hole in tvplayer 423 if ((specialLayerManager_.Find(SpecialLayerType::PROTECTED) || isForcedClipHole()) && IsOnTheTree()) { 424 constexpr float DRM_MIN_ALPHA = 0.1f; 425 return GetGlobalAlpha() < DRM_MIN_ALPHA; // if alpha less than 0.1, drm layer display black background. 426 } 427 return isHardwareForcedDisabled_; 428 } 429 IsLeashOrMainWindow()430 bool IsLeashOrMainWindow() const 431 { 432 return nodeType_ <= RSSurfaceNodeType::LEASH_WINDOW_NODE || nodeType_ == RSSurfaceNodeType::CURSOR_NODE || 433 nodeType_ == RSSurfaceNodeType::ABILITY_MAGNIFICATION_NODE; 434 } 435 IsMainWindowType()436 bool IsMainWindowType() const 437 { 438 // a mainWindowType surfacenode will not mounted under another mainWindowType surfacenode 439 // including app main window, starting window, and selfdrawing window 440 return nodeType_ <= RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE || 441 nodeType_ == RSSurfaceNodeType::CURSOR_NODE || 442 nodeType_ == RSSurfaceNodeType::ABILITY_MAGNIFICATION_NODE; 443 } 444 GetIsLastFrameHwcEnabled()445 bool GetIsLastFrameHwcEnabled() const 446 { 447 return isLastFrameHwcEnabled_; 448 } 449 SetIsLastFrameHwcEnabled(bool enable)450 void SetIsLastFrameHwcEnabled(bool enable) 451 { 452 isLastFrameHwcEnabled_ = enable; 453 } 454 GetNeedCollectHwcNode()455 bool GetNeedCollectHwcNode() const 456 { 457 return needCollectHwcNode_; 458 } 459 SetNeedCollectHwcNode(bool needCollect)460 void SetNeedCollectHwcNode(bool needCollect) 461 { 462 needCollectHwcNode_ = needCollect; 463 } 464 ResetNeedCollectHwcNode()465 void ResetNeedCollectHwcNode() 466 { 467 needCollectHwcNode_ = false; 468 } 469 GetCalcRectInPrepare()470 bool GetCalcRectInPrepare() const 471 { 472 return calcRectInPrepare_; 473 } 474 SetCalcRectInPrepare(bool calc)475 void SetCalcRectInPrepare(bool calc) 476 { 477 calcRectInPrepare_ = calc; 478 } 479 IsSelfDrawingType()480 bool IsSelfDrawingType() const 481 { 482 // self drawing surfacenode has its own buffer, and rendered in its own progress/thread 483 // such as surfaceview (web/videos) and self draw windows (such as mouse pointer and boot animation) 484 return nodeType_ == RSSurfaceNodeType::SELF_DRAWING_NODE || 485 nodeType_ == RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE || 486 nodeType_ == RSSurfaceNodeType::CURSOR_NODE; 487 } 488 489 bool IsUIFirstSelfDrawCheck(); 490 void UpdateCacheSurfaceDirtyManager(int bufferAge = 2); 491 GetNeedSubmitSubThread()492 bool GetNeedSubmitSubThread() const 493 { 494 return isNeedSubmitSubThread_; 495 } 496 SetNeedSubmitSubThread(bool needSubmitSubThread)497 void SetNeedSubmitSubThread(bool needSubmitSubThread) 498 { 499 isNeedSubmitSubThread_ = needSubmitSubThread; 500 } 501 GetSurfaceNodeType()502 RSSurfaceNodeType GetSurfaceNodeType() const 503 { 504 return nodeType_; 505 } 506 507 void SetSurfaceNodeType(RSSurfaceNodeType nodeType); 508 509 void MarkUIHidden(bool isHidden); 510 bool IsUIHidden() const; 511 512 bool IsLeashWindowSurfaceNodeVisible(); 513 GetName()514 const std::string& GetName() const 515 { 516 return name_; 517 } 518 GetBundleName()519 const std::string& GetBundleName() const 520 { 521 return bundleName_; 522 } 523 SetOffSetX(int32_t offset)524 void SetOffSetX(int32_t offset) 525 { 526 offsetX_ = offset; 527 } 528 GetSurfaceWindowType()529 enum SurfaceWindowType GetSurfaceWindowType() const 530 { 531 return surfaceWindowType_; 532 } 533 GetOffSetX()534 int32_t GetOffSetX() const 535 { 536 return offsetX_; 537 } 538 SetOffSetY(int32_t offset)539 void SetOffSetY(int32_t offset) 540 { 541 offsetY_ = offset; 542 } 543 GetOffSetY()544 int32_t GetOffSetY() const 545 { 546 return offsetY_; 547 } 548 SetOffset(int32_t offsetX,int32_t offsetY)549 void SetOffset(int32_t offsetX, int32_t offsetY) 550 { 551 offsetX_ = offsetX; 552 offsetY_ = offsetY; 553 } 554 GetArsrTag()555 bool GetArsrTag() const 556 { 557 return arsrTag_; 558 } 559 SetArsrTag(bool arsrTag)560 void SetArsrTag(bool arsrTag) 561 { 562 arsrTag_ = arsrTag; 563 } 564 565 // hpae offline GetDeviceOfflineEnable()566 bool GetDeviceOfflineEnable() const { return deviceOfflineEnable_; } SetDeviceOfflineEnable(bool enabled)567 void SetDeviceOfflineEnable(bool enabled) { deviceOfflineEnable_ = enabled; } 568 GetCopybitTag()569 bool GetCopybitTag() const 570 { 571 return copybitTag_; 572 } 573 SetCopybitTag(bool copybitTag)574 void SetCopybitTag(bool copybitTag) 575 { 576 copybitTag_ = copybitTag; 577 } 578 579 void CollectSurface(const std::shared_ptr<RSBaseRenderNode>& node, std::vector<RSBaseRenderNode::SharedPtr>& vec, 580 bool isUniRender, bool onlyFirstLevel) override; 581 void CollectSelfDrawingChild(const std::shared_ptr<RSBaseRenderNode>& node, std::vector<NodeId>& vec) override; 582 void QuickPrepare(const std::shared_ptr<RSNodeVisitor>& visitor) override; 583 // keep specified nodetype preparation 584 virtual bool IsSubTreeNeedPrepare(bool filterInGloba, bool isOccluded = false) override; 585 void Prepare(const std::shared_ptr<RSNodeVisitor>& visitor) override; 586 void Process(const std::shared_ptr<RSNodeVisitor>& visitor) override; 587 ProcessTransitionBeforeChildren(RSPaintFilterCanvas & canvas)588 void ProcessTransitionBeforeChildren(RSPaintFilterCanvas& canvas) override {} 589 void ProcessAnimatePropertyBeforeChildren(RSPaintFilterCanvas& canvas, bool includeProperty) override; 590 void ProcessRenderBeforeChildren(RSPaintFilterCanvas& canvas) override; 591 ProcessTransitionAfterChildren(RSPaintFilterCanvas & canvas)592 void ProcessTransitionAfterChildren(RSPaintFilterCanvas& canvas) override {} 593 void ProcessAnimatePropertyAfterChildren(RSPaintFilterCanvas& canvas) override; 594 void ProcessRenderAfterChildren(RSPaintFilterCanvas& canvas) override; 595 bool IsSCBNode() const; 596 void UpdateHwcNodeLayerInfo(GraphicTransformType transform, bool isHardCursorEnable = false); 597 void UpdateHardwareDisabledState(bool disabled); 598 void SetHwcChildrenDisabledState(); 599 600 void SetContextBounds(const Vector4f bounds); 601 virtual bool CheckParticipateInOcclusion(); 602 603 void OnApplyModifiers() override; 604 605 void SetTotalMatrix(const Drawing::Matrix& totalMatrix); GetTotalMatrix()606 const Drawing::Matrix& GetTotalMatrix() const 607 { 608 return totalMatrix_; 609 } 610 611 // Transfer the rendering context variables (matrix, alpha, and clipRegion) from the 612 // source node (in the render thread) to the 613 // target node (in the render service). Note that: 614 // - All three variables are relative to their parent node. 615 // - Alpha can be processed as an absolute value, as its parent (surface) node's alpha should always be 1.0f. 616 // - The matrix and clipRegion should be applied according to the parent node's matrix. 617 void SetContextMatrix(const std::optional<Drawing::Matrix>& transform, bool sendMsg = true); 618 void SetContextAlpha(float alpha, bool sendMsg = true); 619 void SetContextClipRegion(const std::optional<Drawing::Rect>& clipRegion, bool sendMsg = true); 620 std::optional<Drawing::Rect> GetContextClipRegion() const override; 621 622 void SetBootAnimation(bool isBootAnimation) override; 623 bool GetBootAnimation() const override; 624 625 void SetGlobalPositionEnabled(bool isEnabled); GetGlobalPositionEnabled()626 bool GetGlobalPositionEnabled() const override 627 { 628 return isGlobalPositionEnabled_; 629 } 630 631 void SetHwcGlobalPositionEnabled(bool isEnabled); GetHwcGlobalPositionEnabled()632 bool GetHwcGlobalPositionEnabled() const 633 { 634 return isHwcGlobalPositionEnabled_; 635 } 636 637 void SetHwcCrossNode(bool isCrossNode); 638 bool IsHwcCrossNode() const; 639 640 void SetSecurityLayer(bool isSecurityLayer); 641 void SetLeashPersistentId(uint64_t leashPersistentId); 642 void SetSkipLayer(bool isSkipLayer); 643 void SetSnapshotSkipLayer(bool isSnapshotSkipLayer); 644 void SetProtectedLayer(bool isProtectedLayer); 645 void SetIsOutOfScreen(bool isOutOfScreen); 646 void UpdateBlackListStatus(ScreenId virtualScreenId, bool isBlackList); 647 void UpdateVirtualScreenWhiteListInfo( 648 const std::unordered_map<ScreenId, std::unordered_set<uint64_t>>& allWhiteListInfo); 649 650 // get whether it is a security/skip layer itself GetLeashPersistentId()651 LeashPersistentId GetLeashPersistentId() const 652 { 653 return leashPersistentId_; 654 } 655 656 // set ability state that surfaceNode belongs to as foreground or background 657 void SetAbilityState(RSSurfaceNodeAbilityState abilityState); 658 RSSurfaceNodeAbilityState GetAbilityState() const override; 659 660 // get whether it and it's subtree contain security layer 661 bool GetHasPrivacyContentLayer() const; 662 ResetSpecialLayerChangedFlag()663 void ResetSpecialLayerChangedFlag() 664 { 665 specialLayerChanged_ = false; 666 } 667 IsSpecialLayerChanged()668 bool IsSpecialLayerChanged() const 669 { 670 return specialLayerChanged_; 671 } 672 673 void UpdateSpecialLayerInfoByTypeChange(uint32_t type, bool isSpecialLayer); 674 void UpdateSpecialLayerInfoByOnTreeStateChange(); 675 void SyncBlackListInfoToFirstLevelNode(); 676 void SyncPrivacyContentInfoToFirstLevelNode(); 677 void SyncColorGamutInfoToFirstLevelNode(); 678 679 void SetFingerprint(bool hasFingerprint); GetFingerprint()680 bool GetFingerprint() const 681 { 682 return hasFingerprint_; 683 } 684 685 // [Attention] The function only used for unlocking screen for PC currently 686 void SetClonedNodeRenderDrawable(DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr clonedNodeRenderDrawable); IsCloneNode()687 bool IsCloneNode() const 688 { 689 return isCloneNode_; 690 } 691 void SetClonedNodeInfo(NodeId id, bool needOffscreen); 692 void SetIsCloned(bool isCloned); SetIsClonedNodeOnTheTree(bool isOnTheTree)693 void SetIsClonedNodeOnTheTree(bool isOnTheTree) 694 { 695 isClonedNodeOnTheTree_ = isOnTheTree; 696 } 697 698 void SetForceUIFirst(bool forceUIFirst); GetForceUIFirst()699 bool GetForceUIFirst() const 700 { 701 return forceUIFirst_; 702 } 703 704 bool GetForceDrawWithSkipped() const; SetForceDrawWithSkipped(bool GetForceDrawWithSkipped)705 void SetForceDrawWithSkipped(bool GetForceDrawWithSkipped) 706 { 707 uifirstForceDrawWithSkipped_ = GetForceDrawWithSkipped; 708 } 709 SetUIFirstIsPurge(bool IsPurge)710 void SetUIFirstIsPurge(bool IsPurge) 711 { 712 UIFirstIsPurge_ = IsPurge; 713 } 714 GetUIFirstIsPurge()715 bool GetUIFirstIsPurge() const 716 { 717 return UIFirstIsPurge_; 718 } 719 void SetUifirstUseStarting(NodeId id); // only cache app window, first frame not wait 720 721 void SetForceUIFirstChanged(bool forceUIFirstChanged); 722 bool GetForceUIFirstChanged(); 723 724 // Unified DSS synthesis switch for Anco nodes 725 static void SetAncoForceDoDirect(bool direct); 726 // Obtain whether the Anco node is using the DSS synthesis flag 727 static bool GetOriAncoForceDoDirect(); 728 // Whether to use DSS synthesis to obtain anco nodes. only anco node can be true. 729 bool GetAncoForceDoDirect() const; 730 // Used to distinguish whether this node is an Anco node 731 void SetAncoFlags(uint32_t flags); 732 // Determine whether it is an Anco node GetAncoFlags()733 uint32_t GetAncoFlags() const 734 { 735 return ancoFlags_.load(); 736 } 737 // Set the buffer srcRect of the anco node. Only used on anco nodes. 738 void SetAncoSrcCrop(const Rect& srcCrop); 739 740 void SetHDRPresent(bool hasHdrPresent); GetHDRPresent()741 bool GetHDRPresent() const 742 { 743 return hdrPhotoNum_ > 0 || hdrUIComponentNum_ > 0; 744 } 745 746 void IncreaseHDRNum(HDRComponentType hdrType); 747 void ReduceHDRNum(HDRComponentType hdrType); 748 749 void IncreaseCanvasGamutNum(GraphicColorGamut gamut); 750 void ReduceCanvasGamutNum(GraphicColorGamut gamut); 751 752 bool IsHdrEffectColorGamut() const; 753 GetDirtyManager()754 const std::shared_ptr<RSDirtyRegionManager>& GetDirtyManager() const 755 { 756 return dirtyManager_; 757 } 758 std::shared_ptr<RSDirtyRegionManager> GetCacheSurfaceDirtyManager() const; 759 SetSrcRect(const RectI & rect)760 void SetSrcRect(const RectI& rect) 761 { 762 srcRect_ = rect; 763 } 764 765 void NeedClearBufferCache(std::set<uint32_t>& bufferCacheSet); 766 767 void NeedClearPreBuffer(std::set<uint32_t>& bufferCacheSet); 768 GetSrcRect()769 const RectI& GetSrcRect() const 770 { 771 return srcRect_; 772 } 773 SetDstRect(const RectI & dstRect)774 void SetDstRect(const RectI& dstRect) 775 { 776 if (dstRect_ != dstRect) { 777 dstRectChanged_ = true; 778 } 779 dstRect_ = dstRect; 780 } 781 GetDstRect()782 const RectI& GetDstRect() const 783 { 784 return dstRect_; 785 } 786 SetDstRectWithoutRenderFit(const RectI & rect)787 void SetDstRectWithoutRenderFit(const RectI& rect) 788 { 789 dstRectWithoutRenderFit_ = Drawing::Rect(rect.left_, rect.top_, rect.GetRight(), rect.GetBottom()); 790 } 791 SetRegionToBeMagnified(const Vector4<int> & regionToBeMagnified)792 void SetRegionToBeMagnified(const Vector4<int>& regionToBeMagnified) 793 { 794 regionToBeMagnified_ = regionToBeMagnified; 795 } 796 GetDstRectWithoutRenderFit()797 Drawing::Rect GetDstRectWithoutRenderFit() const 798 { 799 return dstRectWithoutRenderFit_; 800 } 801 GetOriginalDstRect()802 const RectI& GetOriginalDstRect() const 803 { 804 return originalDstRect_; 805 } 806 GetOriginalSrcRect()807 const RectI& GetOriginalSrcRect() const 808 { 809 return originalSrcRect_; 810 } 811 GetTransparentRegion()812 Occlusion::Region& GetTransparentRegion() 813 { 814 return transparentRegion_; 815 } 816 GetRoundedCornerRegion()817 const Occlusion::Region& GetRoundedCornerRegion() const 818 { 819 return roundedCornerRegion_; 820 } 821 GetOpaqueRegion()822 const Occlusion::Region& GetOpaqueRegion() const 823 { 824 return opaqueRegion_; 825 } 826 GetOpaqueRegion()827 Occlusion::Region& GetOpaqueRegion() 828 { 829 return opaqueRegion_; 830 } 831 GetContainerRegion()832 Occlusion::Region& GetContainerRegion() 833 { 834 return containerRegion_; 835 } 836 OnAlphaChanged()837 void OnAlphaChanged() override { 838 alphaChanged_ = true; 839 } 840 SetStencilVal(int64_t stencilVal)841 void SetStencilVal(int64_t stencilVal) 842 { 843 stencilVal_ = stencilVal; 844 } 845 846 void SetOcclusionVisible(bool visible); 847 GetOcclusionVisible()848 bool GetOcclusionVisible() const 849 { 850 return isOcclusionVisible_; 851 } 852 SetOcclusionVisibleWithoutFilter(bool visible)853 void SetOcclusionVisibleWithoutFilter(bool visible) 854 { 855 isOcclusionVisibleWithoutFilter_ = visible; 856 } 857 SetOcclusionInSpecificScenes(bool isOcclusionInSpecificScenes)858 void SetOcclusionInSpecificScenes(bool isOcclusionInSpecificScenes) 859 { 860 isOcclusionInSpecificScenes_ = isOcclusionInSpecificScenes; 861 } 862 GetOcclusionInSpecificScenes()863 bool GetOcclusionInSpecificScenes() const 864 { 865 return isOcclusionInSpecificScenes_; 866 } 867 GetVisibleRegion()868 const Occlusion::Region& GetVisibleRegion() const 869 { 870 return visibleRegion_; 871 } 872 GetVisibleRegionBehindWindow()873 const Occlusion::Region& GetVisibleRegionBehindWindow() const 874 { 875 return visibleRegionBehindWindow_; 876 } 877 GetVisibleRegionInVirtual()878 const Occlusion::Region& GetVisibleRegionInVirtual() const 879 { 880 return visibleRegionInVirtual_; 881 } 882 GetVisibleRegionForCallBack()883 const Occlusion::Region& GetVisibleRegionForCallBack() const 884 { 885 return visibleRegionForCallBack_; 886 } 887 SetAbilityBGAlpha(uint8_t alpha)888 void SetAbilityBGAlpha(uint8_t alpha) 889 { 890 alphaChanged_ = (alpha == 255 && abilityBgAlpha_ != 255) || 891 (alpha != 255 && abilityBgAlpha_ == 255); 892 abilityBgAlpha_ = alpha; 893 } 894 GetAbilityBgAlpha()895 uint8_t GetAbilityBgAlpha() const 896 { 897 return abilityBgAlpha_; 898 } 899 setQosCal(bool qosPidCal)900 void setQosCal(bool qosPidCal) 901 { 902 qosPidCal_ = qosPidCal; 903 } 904 905 bool IsSurfaceInStartingWindowStage() const; 906 907 WINDOW_LAYER_INFO_TYPE GetVisibleLevelForWMS(RSVisibleLevel visibleLevel); 908 909 void SetVisibleRegionRecursive( 910 const Occlusion::Region& region, 911 VisibleData& visibleVec, 912 std::map<NodeId, RSVisibleLevel>& pidVisMap, 913 bool needSetVisibleRegion = true, 914 RSVisibleLevel visibleLevel = RSVisibleLevel::RS_UNKNOW_VISIBLE_LEVEL, 915 bool isSystemAnimatedScenes = false); 916 SetExtraDirtyRegionAfterAlignment(const Occlusion::Region & region)917 void SetExtraDirtyRegionAfterAlignment(const Occlusion::Region& region) 918 { 919 extraDirtyRegionAfterAlignment_ = region; 920 extraDirtyRegionAfterAlignmentIsEmpty_ = extraDirtyRegionAfterAlignment_.IsEmpty(); 921 } 922 GetDstRectChanged()923 bool GetDstRectChanged() const 924 { 925 return dstRectChanged_; 926 } 927 CleanDstRectChanged()928 void CleanDstRectChanged() 929 { 930 dstRectChanged_ = false; 931 } 932 GetAlphaChanged()933 bool GetAlphaChanged() const 934 { 935 return alphaChanged_; 936 } 937 CleanAlphaChanged()938 void CleanAlphaChanged() 939 { 940 alphaChanged_ = false; 941 } 942 943 void SetLocalZOrder(float localZOrder); 944 float GetLocalZOrder() const; 945 946 void SetColorSpace(GraphicColorGamut colorSpace); 947 GraphicColorGamut GetColorSpace() const; 948 // Only call this if the node is first level node. 949 GraphicColorGamut GetFirstLevelNodeColorGamut() const; 950 void SetFirstLevelNodeColorGamutByResource(bool isOnTree, GraphicColorGamut gamut); 951 void SetFirstLevelNodeColorGamutByWindow(bool isOnTree, GraphicColorGamut gamut); 952 953 // Only call this if the node is self-drawing surface node. 954 void UpdateColorSpaceWithMetadata(); 955 956 #ifndef ROSEN_CROSS_PLATFORM 957 void SetConsumer(const sptr<IConsumerSurface>& consumer); SetBlendType(GraphicBlendType blendType)958 void SetBlendType(GraphicBlendType blendType) 959 { 960 blendType_ = blendType; 961 } GetBlendType()962 GraphicBlendType GetBlendType() 963 { 964 return blendType_; 965 } 966 #endif 967 968 void UpdateSurfaceDefaultSize(float width, float height); 969 970 void UpdateInfoForClonedNode(NodeId nodeId); 971 972 // Only SurfaceNode in RS calls "RegisterBufferAvailableListener" 973 // to save callback method sent by RT or UI which depends on the value of "isFromRenderThread". 974 void RegisterBufferAvailableListener(sptr<RSIBufferAvailableCallback> callback, bool isFromRenderThread); 975 976 void RegisterBufferClearListener(sptr<RSIBufferClearCallback> callback); 977 978 // Only SurfaceNode in RT calls "ConnectToNodeInRenderService" to send callback method to RS 979 void ConnectToNodeInRenderService(); 980 981 void NotifyRTBufferAvailable(bool isTextureExportNode = false); 982 bool IsNotifyRTBufferAvailable() const; 983 bool IsNotifyRTBufferAvailablePre() const; 984 985 void NotifyUIBufferAvailable(); 986 bool IsNotifyUIBufferAvailable() const; 987 void SetIsNotifyUIBufferAvailable(bool available); 988 989 // UI Thread would not be notified when SurfaceNode created by Video/Camera in RenderService has available buffer. 990 // And RenderThread does not call mainFunc_ if nothing in UI thread is changed 991 // which would cause callback for "clip" on parent SurfaceNode cannot be triggered 992 // for "clip" is executed in RenderThreadVisitor::ProcessSurfaceRenderNode. 993 // To fix this bug, we set callback which would call RSRenderThread::RequestNextVSync() to forcedly "refresh" 994 // RenderThread when SurfaceNode in RenderService has available buffer and execute RSIBufferAvailableCallback. 995 void SetCallbackForRenderThreadRefresh(bool isRefresh); 996 bool NeedSetCallbackForRenderThreadRefresh(); 997 ParallelVisitLock()998 void ParallelVisitLock() 999 { 1000 parallelVisitMutex_.lock(); 1001 } 1002 ParallelVisitUnlock()1003 void ParallelVisitUnlock() 1004 { 1005 parallelVisitMutex_.unlock(); 1006 } 1007 SubNodeVisible(const RectI & r)1008 bool SubNodeVisible(const RectI& r) const 1009 { 1010 Occlusion::Rect nodeRect { r.left_, r.top_, r.GetRight(), r.GetBottom() }; 1011 // if current node is in occluded region of the surface, it could be skipped in process step 1012 return visibleRegion_.IsIntersectWith(nodeRect); 1013 } 1014 1015 bool CheckIfOcclusionReusable(std::queue<NodeId>& surfaceNodesIds) const; 1016 bool CheckIfOcclusionChanged() const; 1017 SetVisibleRegion(const Occlusion::Region & region)1018 void SetVisibleRegion(const Occlusion::Region& region) 1019 { 1020 visibleRegion_ = region; 1021 } 1022 SetVisibleRegionBehindWindow(const Occlusion::Region & region)1023 void SetVisibleRegionBehindWindow(const Occlusion::Region& region) 1024 { 1025 visibleRegionBehindWindow_ = region; 1026 } 1027 SetVisibleRegionInVirtual(const Occlusion::Region & region)1028 void SetVisibleRegionInVirtual(const Occlusion::Region& region) 1029 { 1030 visibleRegionInVirtual_ = region; 1031 } 1032 IsEmptyAppWindow()1033 inline bool IsEmptyAppWindow() const 1034 { 1035 return IsAppWindow() && (GetChildrenCount() == 0 || HasOnlyOneRootNode()); 1036 } 1037 1038 // Due to the BehindWindowFilter enabling ui-first, the condition is excluded. 1039 // This condition is now only used by ui-first IsAlphaTransparent()1040 inline bool IsAlphaTransparent() const 1041 { 1042 const uint8_t opacity = 255; 1043 return !(GetAbilityBgAlpha() == opacity && ROSEN_EQ(GetGlobalAlpha(), 1.0f)) || 1044 (IsEmptyAppWindow() && RSUniRenderJudgement::IsUniRender()); 1045 } 1046 IsTransparent()1047 inline bool IsTransparent() const 1048 { 1049 return IsAlphaTransparent() || NeedDrawBehindWindow(); 1050 } 1051 IsCurrentNodeInTransparentRegion(const Occlusion::Rect & nodeRect)1052 inline bool IsCurrentNodeInTransparentRegion(const Occlusion::Rect& nodeRect) const 1053 { 1054 return transparentRegion_.IsIntersectWith(nodeRect); 1055 } 1056 1057 // Used when the node is opaque, but not calculate in occlusion SetTreatedAsTransparent(bool isOcclusion)1058 void SetTreatedAsTransparent(bool isOcclusion) 1059 { 1060 isTreatedAsTransparent_ = isOcclusion; 1061 } 1062 IsTreatedAsTransparent()1063 bool IsTreatedAsTransparent() const 1064 { 1065 return isTreatedAsTransparent_; 1066 } 1067 GetZorderChanged()1068 bool GetZorderChanged() const 1069 { 1070 return zOrderChanged_; 1071 } 1072 IsZOrderPromoted()1073 bool IsZOrderPromoted() const 1074 { 1075 return GetRenderProperties().GetPositionZ() > positionZ_; 1076 } 1077 UpdatePositionZ()1078 void UpdatePositionZ() 1079 { 1080 const auto& zProperties = GetRenderProperties().GetPositionZ(); 1081 zOrderChanged_ = !ROSEN_EQ(zProperties, positionZ_); 1082 positionZ_ = zProperties; 1083 } 1084 HasContainerWindow()1085 inline bool HasContainerWindow() const 1086 { 1087 return containerConfig_.hasContainerWindow_; 1088 } 1089 1090 void SetContainerWindow(bool hasContainerWindow, RRect rrect); 1091 GetContainerConfigDump()1092 std::string GetContainerConfigDump() const 1093 { 1094 return "[outR: " + std::to_string(containerConfig_.outR_) + 1095 " inR: " + std::to_string(containerConfig_.inR_) + 1096 " x: " + std::to_string(containerConfig_.innerRect_.left_) + 1097 " y: " + std::to_string(containerConfig_.innerRect_.top_) + 1098 " w: " + std::to_string(containerConfig_.innerRect_.width_) + 1099 " h: " + std::to_string(containerConfig_.innerRect_.height_) + "]"; 1100 } 1101 IsOpaqueRegionChanged()1102 bool IsOpaqueRegionChanged() const 1103 { 1104 return opaqueRegionChanged_; 1105 } 1106 CleanOpaqueRegionChanged()1107 void CleanOpaqueRegionChanged() 1108 { 1109 opaqueRegionChanged_ = false; 1110 } 1111 IsBehindWindowOcclusionChanged()1112 bool IsBehindWindowOcclusionChanged() const 1113 { 1114 return behindWindowOcclusionChanged_; 1115 } 1116 1117 // [planning] Remove this after skia is upgraded, the clipRegion is supported 1118 void ResetChildrenFilterRects(); 1119 void UpdateChildrenFilterRects(std::shared_ptr<RSRenderNode> filternode, const RectI& rect, bool cacheValid); 1120 const std::vector<RectI>& GetChildrenNeedFilterRects() const; 1121 const std::vector<bool>& GetChildrenNeedFilterRectsCacheValid() const; 1122 const std::vector<std::shared_ptr<RSRenderNode>>& GetChildrenFilterNodes() const; 1123 std::vector<RectI> GetChildrenNeedFilterRectsWithoutCacheValid(); 1124 1125 // manage abilities' nodeid info 1126 void UpdateAbilityNodeIds(NodeId id, bool isAdded); GetAbilityNodeIds()1127 const std::unordered_set<NodeId>& GetAbilityNodeIds() const 1128 { 1129 return abilityNodeIds_; 1130 } 1131 1132 void AddAbilityComponentNodeIds(std::unordered_set<NodeId>& nodeIds); 1133 void ResetAbilityNodeIds(); 1134 1135 // manage appWindowNode's child hardware enabled nodes info ResetChildHardwareEnabledNodes()1136 void ResetChildHardwareEnabledNodes() 1137 { 1138 childHardwareEnabledNodes_.clear(); 1139 } 1140 1141 void AddChildHardwareEnabledNode(WeakPtr childNode); GetChildHardwareEnabledNodes()1142 const std::vector<WeakPtr>& GetChildHardwareEnabledNodes() const 1143 { 1144 return childHardwareEnabledNodes_; 1145 } 1146 IsFocusedNode(uint64_t focusedNodeId)1147 bool IsFocusedNode(uint64_t focusedNodeId) const 1148 { 1149 return GetId() == focusedNodeId; 1150 } 1151 1152 void CheckAndUpdateOpaqueRegion(const RectI& screeninfo, const ScreenRotation screenRotation, 1153 const bool isFocusWindow); 1154 1155 void ResetSurfaceOpaqueRegion(const RectI& screeninfo, const RectI& absRect, const ScreenRotation screenRotation, 1156 const bool isFocusWindow, const Vector4<int>& cornerRadius); 1157 Occlusion::Region ResetOpaqueRegion( 1158 const RectI& absRect, const ScreenRotation screenRotation, const bool isFocusWindow) const; 1159 Occlusion::Region SetUnfocusedWindowOpaqueRegion(const RectI& absRect, const ScreenRotation screenRotation) const; 1160 Occlusion::Region SetFocusedWindowOpaqueRegion(const RectI& absRect, const ScreenRotation screenRotation) const; 1161 void SetCornerRadiusOpaqueRegion(const RectI& absRect, const Vector4<int>& cornerRadius); 1162 void ResetSurfaceContainerRegion(const RectI& screeninfo, const RectI& absRect, 1163 const ScreenRotation screenRotation); 1164 bool CheckOpaqueRegionBaseInfo(const RectI& screeninfo, const RectI& absRect, const ScreenRotation screenRotation, 1165 const bool isFocusWindow, const Vector4<int>& cornerRadius) const; 1166 void SetOpaqueRegionBaseInfo(const RectI& screeninfo, const RectI& absRect, const ScreenRotation screenRotation, 1167 const bool isFocusWindow, const Vector4<int>& cornerRadius); 1168 void DealWithDrawBehindWindowTransparentRegion(); 1169 1170 bool IsStartAnimationFinished() const; 1171 void SetStartAnimationFinished(); 1172 // if surfacenode's buffer has been consumed, it should be set dirty 1173 bool UpdateDirtyIfFrameBufferConsumed(); 1174 1175 void UpdateSrcRect(const Drawing::Canvas& canvas, const Drawing::RectI& dstRect, bool hasRotation = false); 1176 1177 // if a surfacenode's dstrect is empty, its subnodes' prepare stage can be skipped 1178 bool ShouldPrepareSubnodes(); 1179 SetNodeCost(int32_t cost)1180 void SetNodeCost(int32_t cost) 1181 { 1182 nodeCost_ = cost; 1183 } 1184 GetNodeCost()1185 int32_t GetNodeCost() const 1186 { 1187 return nodeCost_; 1188 } 1189 1190 std::string DirtyRegionDump() const; SetAnimateState()1191 void SetAnimateState() { 1192 animateState_ = true; 1193 } ResetAnimateState()1194 void ResetAnimateState() { 1195 animateState_ = false; 1196 } GetAnimateState()1197 bool GetAnimateState() const 1198 { 1199 return animateState_; 1200 } 1201 bool IsParentLeashWindowInScale() const; 1202 1203 Occlusion::Rect GetSurfaceOcclusionRect(bool isUniRender); 1204 1205 void AccumulateOcclusionRegion(Occlusion::Region& accumulatedRegion, 1206 Occlusion::Region& curRegion, 1207 bool& hasFilterCacheOcclusion, 1208 bool isUniRender, 1209 bool filterCacheOcclusionEnabled); 1210 1211 bool LeashWindowRelatedAppWindowOccluded(std::vector<std::shared_ptr<RSSurfaceRenderNode>>& appNode); 1212 1213 void FindScreenId(); 1214 1215 void OnTreeStateChanged() override; 1216 SetDrawingGPUContext(Drawing::GPUContext * grContext)1217 void SetDrawingGPUContext(Drawing::GPUContext* grContext) 1218 { 1219 grContext_ = grContext; 1220 } 1221 // UIFirst 1222 void UpdateUIFirstFrameGravity(); 1223 SetSubmittedSubThreadIndex(uint32_t index)1224 void SetSubmittedSubThreadIndex(uint32_t index) 1225 { 1226 submittedSubThreadIndex_ = index; 1227 } 1228 GetSubmittedSubThreadIndex()1229 uint32_t GetSubmittedSubThreadIndex() const 1230 { 1231 return submittedSubThreadIndex_; 1232 } 1233 1234 bool IsWaitUifirstFirstFrame() const; 1235 void SetWaitUifirstFirstFrame(bool wait); 1236 1237 void SetCacheSurfaceProcessedStatus(CacheProcessStatus cacheProcessStatus); GetCacheSurfaceProcessedStatus()1238 CacheProcessStatus GetCacheSurfaceProcessedStatus() const 1239 { 1240 return cacheProcessStatus_.load(); 1241 } 1242 RegisterTreeStateChangeCallback(TreeStateChangeCallback callback)1243 void RegisterTreeStateChangeCallback(TreeStateChangeCallback callback) 1244 { 1245 treeStateChangeCallback_ = callback; 1246 } 1247 void NotifyTreeStateChange(); 1248 1249 /* For filter cache occlusion calculation */ GetFilterCacheFullyCovered()1250 bool GetFilterCacheFullyCovered() const 1251 { 1252 return isFilterCacheFullyCovered_; 1253 } 1254 SetFilterCacheFullyCovered(bool val)1255 void SetFilterCacheFullyCovered(bool val) 1256 { 1257 isFilterCacheFullyCovered_ = val; 1258 } 1259 IsAttractionAnimation()1260 bool IsAttractionAnimation() const 1261 { 1262 return isAttractionAnimation_; 1263 } 1264 SetAttractionAnimation(bool isAttractionAnimation)1265 void SetAttractionAnimation(bool isAttractionAnimation) 1266 { 1267 isAttractionAnimation_ = isAttractionAnimation; 1268 } 1269 GetFilterCacheValidForOcclusion()1270 bool GetFilterCacheValidForOcclusion() const 1271 { 1272 return isFilterCacheValidForOcclusion_; 1273 } 1274 1275 // mark if any valid filter cache within surface fully cover targer range 1276 void CheckValidFilterCacheFullyCoverTarget(const RSRenderNode& filterNode, const RectI& targetRect); 1277 void CalcFilterCacheValidForOcclusion(); 1278 // mark occluded by upper filtercache 1279 void UpdateOccludedByFilterCache(bool val); IsOccludedByFilterCache()1280 bool IsOccludedByFilterCache() const 1281 { 1282 return isOccludedByFilterCache_; 1283 } 1284 IsFilterCacheStatusChanged()1285 bool IsFilterCacheStatusChanged() const 1286 { 1287 return isFilterCacheStatusChanged_; 1288 } 1289 ResetFilterNodes()1290 void ResetFilterNodes() 1291 { 1292 filterNodes_.clear(); 1293 } 1294 void UpdateFilterNodes(const std::shared_ptr<RSRenderNode>& nodePtr); 1295 // update static node's back&front-ground filter cache status 1296 void UpdateFilterCacheStatusWithVisible(bool visible); 1297 void UpdateFilterCacheStatusIfNodeStatic(const RectI& clipRect, bool isRotationChanged); 1298 void UpdateDrawingCacheNodes(const std::shared_ptr<RSRenderNode>& nodePtr); 1299 // reset static node's drawing cache status as not changed and get filter rects 1300 void ResetDrawingCacheStatusIfNodeStatic(std::unordered_map<NodeId, std::unordered_set<NodeId>>& allRects); 1301 1302 void SetNotifyRTBufferAvailable(bool isNotifyRTBufferAvailable); 1303 1304 // whether the subtree has only one root node 1305 bool HasOnlyOneRootNode() const; 1306 GetHwcDelayDirtyFlag()1307 bool GetHwcDelayDirtyFlag() const noexcept 1308 { 1309 return hwcDelayDirtyFlag_; 1310 } 1311 SetHwcDelayDirtyFlag(bool hwcDelayDirtyFlag)1312 void SetHwcDelayDirtyFlag(bool hwcDelayDirtyFlag) 1313 { 1314 hwcDelayDirtyFlag_ = hwcDelayDirtyFlag; 1315 } 1316 GetSurfaceCacheContentStatic()1317 bool GetSurfaceCacheContentStatic() 1318 { 1319 return surfaceCacheContentStatic_; 1320 } 1321 GetUifirstContentDirty()1322 bool GetUifirstContentDirty() 1323 { 1324 bool uifirstContentDirty = uifirstContentDirty_; 1325 uifirstContentDirty_ = false; 1326 return uifirstContentDirty; 1327 } 1328 1329 void UpdateSurfaceCacheContentStatic(); 1330 1331 void UpdateSurfaceCacheContentStatic( 1332 const std::unordered_map<NodeId, std::weak_ptr<RSRenderNode>>& activeNodeIds); 1333 // temperory limit situation: 1334 // subtree no drawingcache and geodirty 1335 // contentdirty 1 specifically for buffer update IsContentDirtyNodeLimited()1336 bool IsContentDirtyNodeLimited() const 1337 { 1338 return drawingCacheNodes_.empty() && dirtyGeoNodeNum_ == 0 && dirtyContentNodeNum_ <= 1; 1339 } 1340 GetLastFrameChildrenCnt()1341 size_t GetLastFrameChildrenCnt() 1342 { 1343 return lastFrameChildrenCnt_; 1344 } 1345 SetLastFrameChildrenCnt(size_t childrenCnt)1346 void SetLastFrameChildrenCnt(size_t childrenCnt) 1347 { 1348 lastFrameChildrenCnt_ = childrenCnt; 1349 } 1350 GetUifirstSupportFlag()1351 bool GetUifirstSupportFlag() override 1352 { 1353 return RSRenderNode::GetUifirstSupportFlag(); 1354 } 1355 1356 void UpdateSurfaceCacheContentStaticFlag(bool isAccessibilityChanged); 1357 1358 void UpdateSurfaceSubTreeDirtyFlag(); 1359 MergeOldDirtyRect()1360 void MergeOldDirtyRect() override 1361 { 1362 if (IsAppWindow()) { 1363 this->GetDirtyManager()->MergeDirtyRect(this->GetOldDirtyInSurface()); 1364 } 1365 } 1366 1367 #ifdef USE_SURFACE_TEXTURE GetSurfaceTexture()1368 std::shared_ptr<RSSurfaceTexture> GetSurfaceTexture() const { return surfaceTexture_; }; SetSurfaceTexture(const std::shared_ptr<RSSurfaceTexture> & texture)1369 void SetSurfaceTexture(const std::shared_ptr<RSSurfaceTexture> &texture) { surfaceTexture_ = texture; } 1370 #endif 1371 SetForeground(bool isForeground)1372 void SetForeground(bool isForeground) 1373 { 1374 isForeground_ = isForeground; 1375 } 1376 SetSurfaceId(SurfaceId surfaceId)1377 void SetSurfaceId(SurfaceId surfaceId) 1378 { 1379 surfaceId_ = surfaceId; 1380 } 1381 GetSurfaceId()1382 SurfaceId GetSurfaceId() const 1383 { 1384 return surfaceId_; 1385 } 1386 SetTunnelLayerId(SurfaceId tunnelLayerId)1387 void SetTunnelLayerId(SurfaceId tunnelLayerId) 1388 { 1389 tunnelLayerId_ = tunnelLayerId; 1390 } 1391 GetTunnelLayerId()1392 SurfaceId GetTunnelLayerId() const 1393 { 1394 return tunnelLayerId_; 1395 } 1396 GetIsForeground()1397 bool GetIsForeground() const 1398 { 1399 return isForeground_; 1400 } 1401 bool GetNodeIsSingleFrameComposer() const override; 1402 SetAncestorScreenNode(const RSBaseRenderNode::WeakPtr & ancestorScreenNode)1403 void SetAncestorScreenNode(const RSBaseRenderNode::WeakPtr& ancestorScreenNode) 1404 { 1405 ancestorScreenNode_ = ancestorScreenNode; 1406 } 1407 1408 bool SetUifirstNodeEnableParam(MultiThreadCacheType b); 1409 1410 void SetIsParentUifirstNodeEnableParam(bool b); 1411 1412 void SetUifirstChildrenDirtyRectParam(RectI rect); 1413 SetUifirstStartTime(int64_t startTime)1414 void SetUifirstStartTime(int64_t startTime) 1415 { 1416 uifirstStartTime_ = startTime; 1417 } 1418 GetUifirstStartTime()1419 int64_t GetUifirstStartTime() const 1420 { 1421 return uifirstStartTime_; 1422 } 1423 GetAncestorScreenNode()1424 RSBaseRenderNode::WeakPtr GetAncestorScreenNode() const 1425 { 1426 return ancestorScreenNode_; 1427 } 1428 bool QuerySubAssignable(bool isRotation); 1429 bool QueryIfAllHwcChildrenForceDisabledByFilter(); GetHasSharedTransitionNode()1430 bool GetHasSharedTransitionNode() const 1431 { 1432 return hasSharedTransitionNode_; 1433 } 1434 void SetHasSharedTransitionNode(bool hasSharedTransitionNode); 1435 Vector2f GetGravityTranslate(float imgWidth, float imgHeight); 1436 void UpdateTransparentSurface(); 1437 bool GetHasTransparentSurface() const; 1438 void UpdatePartialRenderParams(); 1439 // This function is used for extending visibleRegion by dirty blurfilter node half-obscured 1440 void UpdateExtendVisibleRegion(Occlusion::Region& region); 1441 void UpdateAncestorScreenNodeInRenderParams(); 1442 SetNeedDrawFocusChange(bool needDrawFocusChange)1443 void SetNeedDrawFocusChange(bool needDrawFocusChange) 1444 { 1445 needDrawFocusChange_ = needDrawFocusChange; 1446 } 1447 GetNeedDrawFocusChange()1448 bool GetNeedDrawFocusChange() const 1449 { 1450 return needDrawFocusChange_; 1451 } 1452 HasWindowCorner()1453 bool HasWindowCorner() 1454 { 1455 Vector4f cornerRadius; 1456 Vector4f::Max(GetWindowCornerRadius(), GetGlobalCornerRadius(), cornerRadius); 1457 return !cornerRadius.IsZero(); 1458 } SetBufferRelMatrix(const Drawing::Matrix & matrix)1459 void SetBufferRelMatrix(const Drawing::Matrix& matrix) 1460 { 1461 bufferRelMatrix_ = matrix; 1462 } 1463 GetBufferRelMatrix()1464 const Drawing::Matrix& GetBufferRelMatrix() const 1465 { 1466 return bufferRelMatrix_; 1467 } 1468 SetGpuOverDrawBufferOptimizeNode(bool overDrawNode)1469 void SetGpuOverDrawBufferOptimizeNode(bool overDrawNode) 1470 { 1471 isGpuOverDrawBufferOptimizeNode_ = overDrawNode; 1472 } IsGpuOverDrawBufferOptimizeNode()1473 bool IsGpuOverDrawBufferOptimizeNode() const 1474 { 1475 return isGpuOverDrawBufferOptimizeNode_; 1476 } 1477 SetOverDrawBufferNodeCornerRadius(const Vector4f & radius)1478 void SetOverDrawBufferNodeCornerRadius(const Vector4f& radius) 1479 { 1480 overDrawBufferNodeCornerRadius_ = radius; 1481 } GetOverDrawBufferNodeCornerRadius()1482 const Vector4f& GetOverDrawBufferNodeCornerRadius() const 1483 { 1484 return overDrawBufferNodeCornerRadius_; 1485 } 1486 HasSubSurfaceNodes()1487 bool HasSubSurfaceNodes() const 1488 { 1489 return childSubSurfaceNodes_.size() != 0; 1490 } 1491 void SetIsSubSurfaceNode(bool isSubSurfaceNode); 1492 bool IsSubSurfaceNode() const; 1493 const std::map<NodeId, RSSurfaceRenderNode::WeakPtr>& GetChildSubSurfaceNodes() const; 1494 void GetAllSubSurfaceNodes(std::vector<std::pair<NodeId, RSSurfaceRenderNode::WeakPtr>>& allSubSurfaceNodes) const; 1495 std::string SubSurfaceNodesDump() const; 1496 1497 void SetIsNodeToBeCaptured(bool isNodeToBeCaptured); IsNodeToBeCaptured()1498 bool IsNodeToBeCaptured() const 1499 { 1500 return isNodeToBeCaptured_; 1501 } 1502 SetDoDirectComposition(bool flag)1503 void SetDoDirectComposition(bool flag) 1504 { 1505 doDirectComposition_ = flag; 1506 } 1507 GetDoDirectComposition()1508 bool GetDoDirectComposition() const 1509 { 1510 return doDirectComposition_; 1511 } 1512 1513 void SetSkipDraw(bool skip); 1514 bool GetSkipDraw() const; 1515 void SetHidePrivacyContent(bool needHidePrivacyContent); 1516 void SetNeedOffscreen(bool needOffscreen); 1517 void SetSdrNit(float sdrNit); 1518 void SetDisplayNit(float displayNit); 1519 void SetColorFollow(bool colorFollow); 1520 void SetBrightnessRatio(float brightnessRatio); 1521 void SetLayerLinearMatrix(const std::vector<float>& layerLinearMatrix); 1522 void SetSdrHasMetadata(bool hasMetadata); 1523 bool GetSdrHasMetadata() const; 1524 static const std::unordered_map<NodeId, NodeId>& GetSecUIExtensionNodes(); IsSecureUIExtension()1525 bool IsSecureUIExtension() const 1526 { 1527 return nodeType_ == RSSurfaceNodeType::UI_EXTENSION_SECURE_NODE; 1528 } 1529 IsUnobscuredUIExtensionNode()1530 bool IsUnobscuredUIExtensionNode() const 1531 { 1532 return nodeType_ == RSSurfaceNodeType::UI_EXTENSION_COMMON_NODE && GetUIExtensionUnobscured(); 1533 } 1534 IsUIExtension()1535 bool IsUIExtension() const 1536 { 1537 return nodeType_ == RSSurfaceNodeType::UI_EXTENSION_COMMON_NODE || 1538 nodeType_ == RSSurfaceNodeType::UI_EXTENSION_SECURE_NODE; 1539 } 1540 1541 void SetCornerRadiusInfoForDRM(const std::vector<float>& drmCornerRadius); 1542 void SetForceDisableClipHoleForDRM(bool isForceDisable); GetCornerRadiusInfoForDRM()1543 const std::vector<float>& GetCornerRadiusInfoForDRM() const 1544 { 1545 return drmCornerRadiusInfo_; 1546 } 1547 1548 // [Attention] The function only used for unlocking screen for PC currently GetClonedNodeId()1549 NodeId GetClonedNodeId() const 1550 { 1551 return clonedSourceNodeId_; 1552 } 1553 GetRSSurfaceHandler()1554 const std::shared_ptr<RSSurfaceHandler> GetRSSurfaceHandler() const 1555 { 1556 return surfaceHandler_; 1557 } 1558 GetMutableRSSurfaceHandler()1559 std::shared_ptr<RSSurfaceHandler> GetMutableRSSurfaceHandler() 1560 { 1561 return surfaceHandler_; 1562 } 1563 CheckContainerDirtyStatusAndUpdateDirty(bool & containerDirty)1564 void CheckContainerDirtyStatusAndUpdateDirty(bool& containerDirty) 1565 { 1566 if (!containerDirty || !IsLeashOrMainWindow()) { 1567 return; 1568 } 1569 dirtyStatus_ = NodeDirty::DIRTY; 1570 containerDirty = false; 1571 } 1572 1573 void SetWatermarkEnabled(const std::string& name, bool isEnabled); 1574 const std::unordered_map<std::string, bool>& GetWatermark() const; 1575 bool IsWatermarkEmpty() const; 1576 1577 template<class... Args> SetIntersectedRoundCornerAABBs(Args &&...args)1578 void SetIntersectedRoundCornerAABBs(Args&& ...args) 1579 { 1580 std::vector<RectI>(std::forward<Args>(args)...).swap(intersectedRoundCornerAABBs_); 1581 } 1582 GetIntersectedRoundCornerAABBs()1583 const std::vector<RectI>& GetIntersectedRoundCornerAABBs() const 1584 { 1585 return intersectedRoundCornerAABBs_; 1586 } 1587 GetIntersectedRoundCornerAABBsSize()1588 size_t GetIntersectedRoundCornerAABBsSize() const 1589 { 1590 return intersectedRoundCornerAABBs_.size(); 1591 } 1592 1593 void SetNeedCacheSurface(bool needCacheSurface); GetSubThreadAssignable()1594 bool GetSubThreadAssignable() const 1595 { 1596 return subThreadAssignable_; 1597 } SetSubThreadAssignable(bool subThreadAssignable)1598 void SetSubThreadAssignable(bool subThreadAssignable) 1599 { 1600 subThreadAssignable_ = subThreadAssignable; 1601 } GetMultableSpecialLayerMgr()1602 RSSpecialLayerManager& GetMultableSpecialLayerMgr() 1603 { 1604 return specialLayerManager_; 1605 } 1606 GetSpecialLayerMgr()1607 const RSSpecialLayerManager& GetSpecialLayerMgr() const 1608 { 1609 return specialLayerManager_; 1610 } 1611 1612 bool NeedUpdateDrawableBehindWindow() const override; 1613 void SetOldNeedDrawBehindWindow(bool val); 1614 bool NeedDrawBehindWindow() const override; 1615 void AddChildBlurBehindWindow(NodeId id) override; 1616 void RemoveChildBlurBehindWindow(NodeId id) override; 1617 const std::unordered_set<NodeId>& GetChildBlurBehindWindow(); 1618 void CalDrawBehindWindowRegion() override; 1619 RectI GetFilterRect() const override; 1620 RectI GetBehindWindowRegion() const override; UpdateCrossNodeSkipDisplayConversionMatrices(NodeId displayId,const Drawing::Matrix & matrix)1621 void UpdateCrossNodeSkipDisplayConversionMatrices(NodeId displayId, const Drawing::Matrix& matrix) 1622 { 1623 crossNodeSkipDisplayConversionMatrices_[displayId] = matrix; 1624 } GetCrossNodeSkipDisplayConversionMatrix(NodeId displayId)1625 const Drawing::Matrix& GetCrossNodeSkipDisplayConversionMatrix(NodeId displayId) 1626 { 1627 return crossNodeSkipDisplayConversionMatrices_[displayId]; 1628 } ClearCrossNodeSkipDisplayConversionMatrices()1629 void ClearCrossNodeSkipDisplayConversionMatrices() 1630 { 1631 crossNodeSkipDisplayConversionMatrices_.clear(); 1632 } GetVideoHdrStatus()1633 HdrStatus GetVideoHdrStatus() const 1634 { 1635 return hdrVideoSurface_; 1636 } 1637 SetVideoHdrStatus(HdrStatus hasHdrVideoSurface)1638 void SetVideoHdrStatus(HdrStatus hasHdrVideoSurface) 1639 { 1640 hdrVideoSurface_ = hasHdrVideoSurface; 1641 } 1642 GetHDRBrightnessFactor()1643 float GetHDRBrightnessFactor() const 1644 { 1645 return hdrBrightnessFactor_; 1646 } 1647 SetHDRBrightnessFactor(float hdrBrightnessFactor)1648 void SetHDRBrightnessFactor(float hdrBrightnessFactor) 1649 { 1650 hdrBrightnessFactor_ = hdrBrightnessFactor; 1651 } 1652 1653 void SetApiCompatibleVersion(uint32_t apiCompatibleVersion); GetApiCompatibleVersion()1654 uint32_t GetApiCompatibleVersion() 1655 { 1656 return apiCompatibleVersion_; 1657 } 1658 1659 void ResetIsBufferFlushed(); 1660 1661 void ResetSurfaceNodeStates(); 1662 1663 bool IsUIBufferAvailable(); 1664 GetUIExtensionUnobscured()1665 bool GetUIExtensionUnobscured() const 1666 { 1667 return UIExtensionUnobscured_; 1668 } 1669 GetDirtyManagerForUifirst()1670 std::shared_ptr<RSDirtyRegionManager>& GetDirtyManagerForUifirst() 1671 { 1672 return dirtyManager_; 1673 } 1674 1675 // [Attention] Used in uifirst for checking whether node and parent should paint or not SetSelfAndParentShouldPaint(bool selfAndParentShouldPaint)1676 void SetSelfAndParentShouldPaint(bool selfAndParentShouldPaint) 1677 { 1678 selfAndParentShouldPaint_ = selfAndParentShouldPaint; 1679 } 1680 GetSelfAndParentShouldPaint()1681 bool GetSelfAndParentShouldPaint() const 1682 { 1683 return selfAndParentShouldPaint_; 1684 } 1685 IsHardwareDisabledBySrcRect()1686 inline bool IsHardwareDisabledBySrcRect() const 1687 { 1688 return isHardwareForcedDisabledBySrcRect_; 1689 } 1690 SetAppWindowZOrder(int32_t appWindowZOrder)1691 void SetAppWindowZOrder(int32_t appWindowZOrder) 1692 { 1693 appWindowZOrder_ = appWindowZOrder; 1694 } 1695 GetAppWindowZOrder()1696 int32_t GetAppWindowZOrder() const 1697 { 1698 return appWindowZOrder_; 1699 } 1700 1701 void SetTopLayerZOrder(uint32_t zOrder); 1702 GetTopLayerZOrder()1703 uint32_t GetTopLayerZOrder() const 1704 { 1705 return topLayerZOrder_; 1706 } 1707 1708 // Enable HWCompose HwcSurfaceRecorder()1709 RSHwcSurfaceRecorder& HwcSurfaceRecorder() { return hwcSurfaceRecorder_; } 1710 1711 void SetFrameGravityNewVersionEnabled(bool isEnabled); GetFrameGravityNewVersionEnabled()1712 bool GetFrameGravityNewVersionEnabled() const 1713 { 1714 return isFrameGravityNewVersionEnabled_; 1715 } 1716 1717 // Used for control-level occlusion culling scene info and culled nodes transmission. GetOcclusionParams()1718 std::shared_ptr<OcclusionParams> GetOcclusionParams() 1719 { 1720 if (occlusionParams_ == nullptr) { 1721 occlusionParams_ = std::make_shared<OcclusionParams>(); 1722 } 1723 return occlusionParams_; 1724 } 1725 1726 protected: 1727 void OnSync() override; 1728 void OnSkipSync() override; 1729 // rotate corner by rotation degreee. Every 90 degrees clockwise rotation, the vector 1730 // of corner radius loops one element to the right 1731 void RotateCorner(int rotationDegree, Vector4<int>& cornerRadius) const; 1732 1733 private: 1734 explicit RSSurfaceRenderNode(NodeId id, const std::weak_ptr<RSContext>& context = {}, 1735 bool isTextureExportNode = false); 1736 explicit RSSurfaceRenderNode(const RSSurfaceRenderNodeConfig& config, const std::weak_ptr<RSContext>& context = {}); 1737 void OnResetParent() override; 1738 void ClearChildrenCache(); 1739 Vector4f GetWindowCornerRadius(); 1740 std::vector<std::shared_ptr<RSSurfaceRenderNode>> GetLeashWindowNestedSurfaces(); 1741 bool IsHistoryOccludedDirtyRegionNeedSubmit(); 1742 void ClearHistoryUnSubmittedDirtyInfo(); 1743 void UpdateHistoryUnsubmittedDirtyInfo(); 1744 void SetUIExtensionUnobscured(bool obscured); 1745 void OnSubSurfaceChanged(); 1746 void UpdateChildSubSurfaceNodes(RSSurfaceRenderNode::SharedPtr node, bool isOnTheTree); 1747 bool IsYUVBufferFormat() const; 1748 void InitRenderParams() override; 1749 void UpdateRenderParams() override; 1750 void UpdateChildHardwareEnabledNode(NodeId id, bool isOnTree); 1751 std::unordered_set<NodeId> GetAllSubSurfaceNodeIds() const; 1752 bool IsCurFrameSwitchToPaint(); 1753 1754 bool isForcedClipHole() const; 1755 1756 #ifdef ENABLE_FULL_SCREEN_RECONGNIZE 1757 void UpdateSurfaceNodeTreeStatusForAps(bool onTree); 1758 void SendSurfaceNodeBoundChange(); 1759 #endif 1760 #ifndef ROSEN_CROSS_PLATFORM 1761 void UpdatePropertyFromConsumer(); 1762 #endif 1763 1764 RSSpecialLayerManager specialLayerManager_; 1765 bool specialLayerChanged_ = false; 1766 std::unordered_map<ScreenId, std::unordered_set<NodeId>> blackListIds_ = {}; 1767 bool isGlobalPositionEnabled_ = false; 1768 bool isHwcGlobalPositionEnabled_ = false; 1769 bool isHwcCrossNode_ = false; 1770 bool hasFingerprint_ = false; 1771 // hdr video 1772 HdrStatus hdrVideoSurface_ = HdrStatus::NO_HDR; 1773 bool zOrderChanged_ = false; 1774 bool qosPidCal_ = false; 1775 RSSurfaceNodeAbilityState abilityState_ = RSSurfaceNodeAbilityState::FOREGROUND; 1776 RSSurfaceNodeType nodeType_ = RSSurfaceNodeType::DEFAULT; 1777 uint32_t topLayerZOrder_ = 0; 1778 bool isLayerTop_ = false; 1779 bool isTopLayerForceRefresh_ = false; 1780 bool isForceRefresh_ = false; // the self-drawing node need force refresh 1781 // Specifying hardware enable is only a 'hint' to RS that 1782 // the self-drawing node use hardware composer in some condition, 1783 // such as transparent background. 1784 bool isHardwareEnableHint_ = false; 1785 NodeId sourceDisplayRenderNodeId_ = INVALID_NODEID; 1786 const enum SurfaceWindowType surfaceWindowType_ = SurfaceWindowType::DEFAULT_WINDOW; 1787 bool isNotifyRTBufferAvailablePre_ = false; 1788 bool isRefresh_ = false; 1789 bool isOcclusionVisible_ = true; 1790 bool isOcclusionVisibleWithoutFilter_ = true; 1791 bool isOcclusionInSpecificScenes_ = false; 1792 bool dstRectChanged_ = false; 1793 uint8_t abilityBgAlpha_ = 0; 1794 bool alphaChanged_ = false; 1795 bool isUIHidden_ = false; 1796 bool extraDirtyRegionAfterAlignmentIsEmpty_ = true; 1797 bool opaqueRegionChanged_ = false; 1798 bool behindWindowOcclusionChanged_ = false; 1799 bool isFilterCacheFullyCovered_ = false; 1800 bool isAttractionAnimation_ = false; 1801 bool isFilterCacheValidForOcclusion_ = false; 1802 bool isOccludedByFilterCache_ = false; 1803 bool isFilterCacheStatusChanged_ = false; 1804 bool isTreatedAsTransparent_ = false; 1805 bool startAnimationFinished_ = false; 1806 // only used in hardware enabled pointer window, when gpu -> hardware composer 1807 bool isNodeDirtyInLastFrame_ = true; 1808 bool isNodeDirty_ = true; 1809 // used for hardware enabled nodes 1810 bool isHardwareEnabledNode_ = false; 1811 bool dynamicHardwareEnable_ = true; 1812 bool isFixRotationByUser_ = false; 1813 bool isInFixedRotation_ = false; 1814 SelfDrawingNodeType selfDrawingType_ = SelfDrawingNodeType::DEFAULT; 1815 bool isCurrentFrameHardwareEnabled_ = false; 1816 bool isLastFrameHardwareEnabled_ = false; 1817 bool isLastFrameHwcEnabled_ = false; 1818 bool needCollectHwcNode_ = false; 1819 bool intersectByFilterInApp_ = false; 1820 bool calcRectInPrepare_ = false; 1821 bool hasSubNodeShouldPaint_ = false; 1822 // mark if this self-drawing node is forced not to use hardware composer 1823 // in case where this node's parent window node is occluded or is appFreeze, this variable will be marked true 1824 bool isHardwareForcedDisabled_ = false; 1825 bool hardwareNeedMakeImage_ = false; 1826 bool intersectWithAIBar_ = false; 1827 bool isHardwareForcedDisabledByFilter_ = false; 1828 // For certain buffer format(YUV), dss restriction on src : srcRect % 2 == 0 1829 // To avoid switch between gpu and dss during sliding, we disable dss when srcHeight != bufferHeight 1830 bool isHardwareForcedDisabledBySrcRect_ = false; 1831 // Mark if the leash or main window node has transparent self-drawing node 1832 bool existTransparentHardwareEnabledNode_ = false; 1833 bool animateState_ = false; 1834 bool isRotating_ = false; 1835 bool isParentScaling_ = false; 1836 bool needDrawAnimateProperty_ = false; 1837 bool prevVisible_ = false; 1838 1839 // mark if this self-drawing node do not consume buffer when gpu -> hwc 1840 bool hwcDelayDirtyFlag_ = false; 1841 bool isForeground_ = false; 1842 bool UIFirstIsPurge_ = false; 1843 bool isTargetUIFirstDfxEnabled_ = false; 1844 bool hasSharedTransitionNode_ = false; 1845 bool lastFrameShouldPaint_ = true; 1846 // node only have translate and scale changes 1847 bool surfaceCacheContentStatic_ = false; 1848 bool uifirstContentDirty_ = false; 1849 // point window 1850 bool isHardCursor_ = false; 1851 bool isLastHardCursor_ = false; 1852 bool needDrawFocusChange_ = false; 1853 bool forceUIFirstChanged_ = false; 1854 bool forceUIFirst_ = false; 1855 bool uifirstForceDrawWithSkipped_ = false; 1856 bool hasTransparentSurface_ = false; 1857 bool isGpuOverDrawBufferOptimizeNode_ = false; 1858 bool isSubSurfaceNode_ = false; 1859 bool isNodeToBeCaptured_ = false; 1860 bool doDirectComposition_ = true; 1861 bool isSkipDraw_ = false; 1862 bool needHidePrivacyContent_ = false; 1863 bool isHardwareForcedByBackgroundAlpha_ = false; 1864 bool arsrTag_ = true; 1865 bool copybitTag_ = false; 1866 1867 // hpae offline 1868 bool deviceOfflineEnable_ = false; 1869 1870 bool subThreadAssignable_ = false; 1871 bool oldNeedDrawBehindWindow_ = false; 1872 RectI skipFrameDirtyRect_; 1873 bool UIExtensionUnobscured_ = false; 1874 std::atomic<bool> isNotifyRTBufferAvailable_ = false; 1875 std::atomic<bool> isNotifyUIBufferAvailable_ = true; 1876 std::atomic_bool isBufferAvailable_ = false; 1877 std::atomic<CacheProcessStatus> cacheProcessStatus_ = CacheProcessStatus::WAITING; 1878 std::atomic<bool> isNeedSubmitSubThread_ = true; 1879 // whether to wait uifirst first frame finished when buffer available callback invoked. 1880 std::atomic<bool> isWaitUifirstFirstFrame_ = false; 1881 std::atomic<bool> hasUnSubmittedOccludedDirtyRegion_ = false; 1882 static inline std::atomic<bool> ancoForceDoDirect_ = false; 1883 float contextAlpha_ = 1.0f; 1884 // Count the number of hdr pictures. If hdrPhotoNum_ > 0, it means there are hdr pictures 1885 int hdrPhotoNum_ = 0; 1886 // Count the number of hdr UI components. If hdrUIComponentNum_ > 0, it means there are hdr UI components 1887 int hdrUIComponentNum_ = 0; 1888 int hdrEffectNum_ = 0; 1889 int bt2020Num_ = 0; 1890 int p3Num_ = 0; 1891 int firstLevelNodeBt2020WindowNum_ = 0; 1892 int firstLevelNodeP3WindowNum_ = 0; 1893 int firstLevelNodeBt2020ResourceNum_ = 0; 1894 int firstLevelNodeP3ResourceNum_ = 0; 1895 int wideColorGamutNum_ = 0; 1896 int32_t offsetX_ = 0; 1897 int32_t offsetY_ = 0; 1898 int64_t stencilVal_ = -1; 1899 float positionZ_ = 0.0f; 1900 // This variable can be set in two cases: 1901 // 1. The upper-layer IPC interface directly sets window colorspace. 1902 // 2. If it is a self-drawing node, the colorspace will be refreshed after hardware-enable calculation. 1903 GraphicColorGamut colorSpace_ = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB; 1904 #ifndef ROSEN_CROSS_PLATFORM 1905 GraphicBlendType blendType_ = GraphicBlendType::GRAPHIC_BLEND_SRCOVER; 1906 #endif 1907 // hdr 1908 int32_t displayNit_ = 500; // default sdr luminance 1909 float brightnessRatio_ = 1.0f; // no ratio by default 1910 float hdrBrightnessFactor_ = 1.0f; // no discount by default 1911 float localZOrder_ = 0.0f; 1912 uint32_t processZOrder_ = -1; 1913 int32_t nodeCost_ = 0; 1914 uint32_t submittedSubThreadIndex_ = INT_MAX; 1915 uint32_t wideColorGamutWindowCount_ = 0; 1916 uint32_t wideColorGamutResourceWindowCount_ = 0; 1917 uint32_t apiCompatibleVersion_ = 0; 1918 std::atomic<uint32_t> ancoFlags_ = 0; 1919 Drawing::GPUContext* grContext_ = nullptr; 1920 ScreenId screenId_ = INVALID_SCREEN_ID; 1921 SurfaceId surfaceId_ = 0; 1922 SurfaceId tunnelLayerId_ = 0; 1923 uint64_t leashPersistentId_ = INVALID_LEASH_PERSISTENTID; 1924 size_t dirtyContentNodeNum_ = 0; 1925 size_t dirtyGeoNodeNum_ = 0; 1926 size_t dirtynodeNum_ = 0; 1927 // UIFirst 1928 int64_t uifirstStartTime_ = -1; 1929 size_t lastFrameChildrenCnt_ = 0; 1930 sptr<RSIBufferAvailableCallback> callbackFromRT_ = nullptr; 1931 sptr<RSIBufferAvailableCallback> callbackFromUI_ = nullptr; 1932 sptr<RSIBufferClearCallback> clearBufferCallback_ = nullptr; 1933 std::shared_ptr<RSDirtyRegionManager> dirtyManager_ = nullptr; 1934 std::shared_ptr<RSDirtyRegionManager> cacheSurfaceDirtyManager_ = nullptr; 1935 std::shared_ptr<RSSurfaceHandler> surfaceHandler_; 1936 #ifdef USE_SURFACE_TEXTURE 1937 std::shared_ptr<RSSurfaceTexture> surfaceTexture_ {}; 1938 #endif 1939 RSBaseRenderNode::WeakPtr ancestorScreenNode_; 1940 RectI clipRegionFromParent_; 1941 RectI dstRect_; 1942 RectI srcRect_; 1943 RectI originalDstRect_; 1944 RectI originalSrcRect_; 1945 Vector4<int> regionToBeMagnified_; 1946 Drawing::Rect dstRectWithoutRenderFit_; 1947 RectI historyUnSubmittedOccludedDirtyRegion_; 1948 Vector4f overDrawBufferNodeCornerRadius_; 1949 RectI drawBehindWindowRegion_; 1950 1951 std::mutex mutexRT_; 1952 std::mutex mutexUI_; 1953 std::mutex mutexClear_; 1954 std::mutex mutex_; 1955 std::mutex mutexHDR_; 1956 std::mutex parallelVisitMutex_; 1957 std::optional<Drawing::Matrix> contextMatrix_; 1958 std::optional<Drawing::Rect> contextClipRect_; 1959 1960 std::set<NodeId> privacyContentLayerIds_ = {}; 1961 Drawing::Matrix totalMatrix_; 1962 std::vector<RectI> intersectedRoundCornerAABBs_; 1963 std::vector<float> drmCornerRadiusInfo_; 1964 1965 std::string name_; 1966 std::string bundleName_; 1967 std::vector<NodeId> childSurfaceNodeIds_; 1968 friend class RSRenderThreadVisitor; 1969 /* 1970 visibleRegion: appwindow visible region after occlusion, used for rs opdrop and other optimization. 1971 visibleRegionForCallBack: appwindow visible region after occlusion (no filtercache occlusion), used in 1972 windowmanager, and web surfacenode visibility callback. 1973 These two values are the same in most cases. If there are filter cache occlusion, this two values will be 1974 different under filter cache surfacenode layer. 1975 */ 1976 Occlusion::Region visibleRegion_; 1977 Occlusion::Region visibleRegionBehindWindow_; 1978 Occlusion::Region extendVisibleRegion_; 1979 Occlusion::Region visibleRegionInVirtual_; 1980 Occlusion::Region visibleRegionForCallBack_; 1981 1982 // dirtyRegion caused by surfaceNode visible region after alignment 1983 Occlusion::Region extraDirtyRegionAfterAlignment_; 1984 1985 // region of rounded corner 1986 Occlusion::Region roundedCornerRegion_; 1987 // opaque region of the surface 1988 Occlusion::Region opaqueRegion_; 1989 // [planning] Remove this after skia is upgraded, the clipRegion is supported 1990 std::vector<RectI> childrenFilterRects_; 1991 std::vector<bool> childrenFilterRectsCacheValid_; 1992 std::vector<std::shared_ptr<RSRenderNode>> childrenFilterNodes_; 1993 // transparent region of the surface, floating window's container window is always treated as transparent 1994 Occlusion::Region transparentRegion_; 1995 Occlusion::Region occlusionRegionBehindWindow_; 1996 1997 Occlusion::Region containerRegion_; 1998 std::unordered_set<NodeId> abilityNodeIds_; 1999 // valid filter nodes within, including itself 2000 std::vector<std::shared_ptr<RSRenderNode>> filterNodes_; 2001 std::unordered_map<NodeId, std::weak_ptr<RSRenderNode>> drawingCacheNodes_; 2002 int32_t appWindowZOrder_ = 0; 2003 2004 // Enable HWCompose 2005 RSHwcSurfaceRecorder hwcSurfaceRecorder_; 2006 2007 // previous self-Drawing Node Bound 2008 #ifdef ENABLE_FULL_SCREEN_RECONGNIZE 2009 float prevSelfDrawHeight_ = 0.0f; 2010 float prevSelfDrawWidth_ = 0.0f; 2011 #endif 2012 2013 /* 2014 ContainerWindow configs acquired from arkui, including container window state, screen density, container border 2015 width, padding width, inner/outer radius, etc. 2016 */ 2017 class ContainerConfig { 2018 public: 2019 // rrect means content region, including padding to left and top, inner radius; 2020 void Update(bool hasContainer, RRect rrect); 2021 2022 bool operator==(const ContainerConfig& config) const 2023 { 2024 return hasContainerWindow_ == config.hasContainerWindow_ && 2025 outR_ == config.outR_ && 2026 inR_ == config.inR_ && 2027 innerRect_ == config.innerRect_; 2028 } 2029 private: RoundFloor(float length)2030 inline int RoundFloor(float length) 2031 { 2032 // if a float value is very close to a integer (< 0.05f), return round value 2033 return std::abs(length - std::round(length)) < 0.05f ? std::round(length) : std::floor(length); 2034 } 2035 public: 2036 bool hasContainerWindow_ = false; // set to false as default, set by arkui 2037 int outR_ = 0; // outer radius (int value) 2038 int inR_ = 0; // inner radius (int value) 2039 RectI innerRect_ = {}; // inner rect, value relative to outerRect 2040 }; 2041 2042 ContainerConfig containerConfig_; 2043 ContainerConfig GetAbsContainerConfig() const; 2044 2045 struct OpaqueRegionBaseInfo 2046 { 2047 RectI screenRect_; 2048 RectI absRect_; 2049 RectI oldDirty_; 2050 ScreenRotation screenRotation_ = ScreenRotation::INVALID_SCREEN_ROTATION; 2051 bool isFocusWindow_ = false; 2052 bool isTransparent_ = false; 2053 bool hasContainerWindow_ = false; 2054 Vector4<int> cornerRadius_; 2055 ContainerConfig containerConfig_; 2056 bool needDrawBehindWindow_ = false; 2057 RectI absDrawBehindWindowRegion_ = RectI(); 2058 }; 2059 2060 //<screenRect, absRect, screenRotation, isFocusWindow, isTransparent, hasContainerWindow> 2061 OpaqueRegionBaseInfo opaqueRegionBaseInfo_; 2062 2063 std::vector<WeakPtr> childHardwareEnabledNodes_; 2064 2065 TreeStateChangeCallback treeStateChangeCallback_; 2066 Drawing::Matrix bufferRelMatrix_ = Drawing::Matrix(); 2067 2068 // [Attention] The variable only used for unlocking screen for PC currently 2069 bool isCloneNode_ = false; 2070 NodeId clonedSourceNodeId_ = INVALID_NODEID; 2071 bool isClonedNodeOnTheTree_ = false; 2072 bool clonedSourceNodeNeedOffscreen_ = true; 2073 2074 std::map<NodeId, RSSurfaceRenderNode::WeakPtr> childSubSurfaceNodes_; 2075 std::unordered_map<std::string, bool> watermarkHandles_ = {}; 2076 std::unordered_set<NodeId> childrenBlurBehindWindow_ = {}; 2077 std::unordered_map<NodeId, Drawing::Matrix> crossNodeSkipDisplayConversionMatrices_ = {}; 2078 2079 // used in uifirst for checking whether node and parents should paint or not 2080 bool selfAndParentShouldPaint_ = true; 2081 2082 bool isFrameGravityNewVersionEnabled_ = false; 2083 2084 // Used for control-level occlusion culling scene info and culled nodes transmission. 2085 std::shared_ptr<OcclusionParams> occlusionParams_ = nullptr; 2086 2087 // UIExtension record, <UIExtension, hostAPP> 2088 inline static std::unordered_map<NodeId, NodeId> secUIExtensionNodes_ = {}; 2089 friend class SurfaceNodeCommandHelper; 2090 friend class RSUifirstManager; 2091 friend class RSUniRenderVisitor; 2092 friend class RSRenderNode; 2093 friend class RSRenderService; 2094 friend class RSHdrUtil; 2095 #ifdef RS_PROFILER_ENABLED 2096 friend class RSProfiler; 2097 #endif 2098 }; 2099 } // namespace Rosen 2100 } // namespace OHOS 2101 2102 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_SURFACE_RENDER_NODE_H 2103