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 "memory/rs_memory_track.h" 26 27 #include "common/rs_macros.h" 28 #include "common/rs_occlusion_region.h" 29 #include "common/rs_vector4.h" 30 #include "ipc_callbacks/buffer_available_callback.h" 31 #include "ipc_callbacks/buffer_clear_callback.h" 32 #include "pipeline/rs_paint_filter_canvas.h" 33 #include "pipeline/rs_render_node.h" 34 #include "pipeline/rs_surface_handler.h" 35 #include "pipeline/rs_uni_render_judgement.h" 36 #include "platform/common/rs_surface_ext.h" 37 #include "platform/common/rs_system_properties.h" 38 #include "property/rs_properties_painter.h" 39 #include "screen_manager/screen_types.h" 40 #include "transaction/rs_occlusion_data.h" 41 #include "surface_type.h" 42 #ifndef ROSEN_CROSS_PLATFORM 43 #include "surface_buffer.h" 44 #include "sync_fence.h" 45 #endif 46 #include "ipc_security/rs_ipc_interface_code_access_verifier_base.h" 47 48 namespace OHOS { 49 namespace Rosen { 50 class RSCommand; 51 class RSDirtyRegionManager; 52 class RSSurfaceHandler; 53 class RSB_EXPORT RSSurfaceRenderNode : public RSRenderNode { 54 public: 55 using WeakPtr = std::weak_ptr<RSSurfaceRenderNode>; 56 using SharedPtr = std::shared_ptr<RSSurfaceRenderNode>; 57 using TreeStateChangeCallback = std::function<void(RSSurfaceRenderNode&)>; 58 static inline constexpr RSRenderNodeType Type = RSRenderNodeType::SURFACE_NODE; GetType()59 RSRenderNodeType GetType() const override 60 { 61 return Type; 62 } 63 64 ~RSSurfaceRenderNode() override; 65 66 void PrepareRenderBeforeChildren(RSPaintFilterCanvas& canvas); 67 void PrepareRenderAfterChildren(RSPaintFilterCanvas& canvas); 68 69 void SetIsOnTheTree(bool onTree, NodeId instanceRootNodeId = INVALID_NODEID, 70 NodeId firstLevelNodeId = INVALID_NODEID, NodeId cacheNodeId = INVALID_NODEID, 71 NodeId uifirstRootNodeId = INVALID_NODEID) override; IsAppWindow()72 bool IsAppWindow() const 73 { 74 return nodeType_ == RSSurfaceNodeType::APP_WINDOW_NODE; 75 } 76 IsStartingWindow()77 bool IsStartingWindow() const 78 { 79 return nodeType_ == RSSurfaceNodeType::STARTING_WINDOW_NODE; 80 } 81 IsAbilityComponent()82 bool IsAbilityComponent() const 83 { 84 return nodeType_ == RSSurfaceNodeType::ABILITY_COMPONENT_NODE; 85 } 86 IsLeashWindow()87 bool IsLeashWindow() const 88 { 89 return nodeType_ == RSSurfaceNodeType::LEASH_WINDOW_NODE; 90 } 91 IsRosenWeb()92 bool IsRosenWeb() const 93 { 94 return GetName().find("RosenWeb") != std::string::npos; 95 } 96 IsScbScreen()97 bool IsScbScreen() const 98 { 99 return nodeType_ == RSSurfaceNodeType::SCB_SCREEN_NODE; 100 } 101 SetNodeDirty(bool isNodeDirty)102 void SetNodeDirty(bool isNodeDirty) 103 { 104 isNodeDirty_ = isNodeDirty || isNodeDirtyInLastFrame_; 105 isNodeDirtyInLastFrame_ = isNodeDirty; 106 } 107 IsNodeDirty()108 bool IsNodeDirty() const 109 { 110 return isNodeDirty_; 111 } 112 IsHardwareEnabledTopSurface()113 bool IsHardwareEnabledTopSurface() const 114 { 115 return nodeType_ == RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE && GetName() == "pointer window"; 116 } 117 118 void SetLayerTop(bool isTop); 119 IsLayerTop()120 bool IsLayerTop() const 121 { 122 return isLayerTop_; 123 } 124 125 // indicate if this node type can enable hardware composer IsHardwareEnabledType()126 bool IsHardwareEnabledType() const 127 { 128 if (IsRosenWeb() && !(RSSystemProperties::IsPhoneType() || RSSystemProperties::IsTabletType())) { 129 return false; 130 } 131 return (nodeType_ == RSSurfaceNodeType::SELF_DRAWING_NODE && isHardwareEnabledNode_) || 132 IsHardwareEnabledTopSurface() || IsLayerTop(); 133 } 134 IsDynamicHardwareEnable()135 bool IsDynamicHardwareEnable() const 136 { 137 return dynamicHardwareEnable_; 138 } 139 140 void SetHardwareEnabled(bool isEnabled, SelfDrawingNodeType selfDrawingType = SelfDrawingNodeType::DEFAULT, 141 bool dynamicHardwareEnable = true) 142 { 143 isHardwareEnabledNode_ = isEnabled; 144 selfDrawingType_ = selfDrawingType; 145 dynamicHardwareEnable_ = dynamicHardwareEnable; 146 } 147 148 void SetForceHardwareAndFixRotation(bool flag); 149 bool GetFixRotationByUser() const; 150 bool IsInFixedRotation() const; 151 void SetInFixedRotation(bool isRotating); 152 GetSelfDrawingNodeType()153 SelfDrawingNodeType GetSelfDrawingNodeType() const 154 { 155 return selfDrawingType_; 156 } 157 NeedBilinearInterpolation()158 bool NeedBilinearInterpolation() const 159 { 160 return nodeType_ == RSSurfaceNodeType::SELF_DRAWING_NODE && isHardwareEnabledNode_ && 161 (name_ == "SceneViewer Model0" || name_ == "RosenWeb" || 162 name_.find("HwStylusFeature") != std::string::npos); 163 } 164 SetSubNodeShouldPaint()165 void SetSubNodeShouldPaint() 166 { 167 hasSubNodeShouldPaint_ = true; 168 } 169 ResetSubNodeShouldPaint()170 void ResetSubNodeShouldPaint() 171 { 172 hasSubNodeShouldPaint_ = false; 173 } 174 HasSubNodeShouldPaint()175 bool HasSubNodeShouldPaint() const 176 { 177 return hasSubNodeShouldPaint_; 178 } 179 180 #ifndef ROSEN_CROSS_PLATFORM 181 void UpdateBufferInfo(const sptr<SurfaceBuffer>& buffer, const Rect& damageRect, 182 const sptr<SyncFence>& acquireFence, const sptr<SurfaceBuffer>& preBuffer); 183 #endif 184 IsLastFrameHardwareEnabled()185 bool IsLastFrameHardwareEnabled() const 186 { 187 return isLastFrameHardwareEnabled_; 188 } 189 IsCurrentFrameHardwareEnabled()190 bool IsCurrentFrameHardwareEnabled() const 191 { 192 return isCurrentFrameHardwareEnabled_; 193 } 194 SetCurrentFrameHardwareEnabled(bool enable)195 void SetCurrentFrameHardwareEnabled(bool enable) 196 { 197 isCurrentFrameHardwareEnabled_ = enable; 198 } 199 MarkCurrentFrameHardwareEnabled()200 void MarkCurrentFrameHardwareEnabled() 201 { 202 isCurrentFrameHardwareEnabled_ = true; 203 } 204 SetIsRotating(bool isRotating)205 void SetIsRotating(bool isRotating) 206 { 207 isRotating_ = isRotating; 208 } 209 IsRotating()210 bool IsRotating() const 211 { 212 return isRotating_; 213 } 214 ResetRotateState()215 void ResetRotateState() 216 { 217 isRotating_ = false; 218 } 219 ResetCurrentFrameHardwareEnabledState()220 void ResetCurrentFrameHardwareEnabledState() 221 { 222 isLastFrameHardwareEnabled_ = isCurrentFrameHardwareEnabled_; 223 isCurrentFrameHardwareEnabled_ = false; 224 } 225 ResetHardwareEnabledStates()226 void ResetHardwareEnabledStates() 227 { 228 isLastFrameHardwareEnabled_ = false; 229 isCurrentFrameHardwareEnabled_ = false; 230 } 231 SetHardwareForcedDisabledState(bool forcesDisabled)232 void SetHardwareForcedDisabledState(bool forcesDisabled) 233 { 234 isHardwareForcedDisabled_ = forcesDisabled; 235 } 236 SetNodeHasBackgroundColorAlpha(bool forcesDisabled)237 void SetNodeHasBackgroundColorAlpha(bool forcesDisabled) 238 { 239 isHardwareForcedByBackgroundAlpha_ = forcesDisabled; 240 } 241 IsNodeHasBackgroundColorAlpha()242 bool IsNodeHasBackgroundColorAlpha() const 243 { 244 return isHardwareForcedByBackgroundAlpha_; 245 } 246 SetHardwareDisabledByCache(bool disabledByCache)247 void SetHardwareDisabledByCache(bool disabledByCache) 248 { 249 isHardwareDisabledByCache_ = disabledByCache; 250 } 251 SetHardwareForcedDisabledStateByFilter(bool forcesDisabled)252 void SetHardwareForcedDisabledStateByFilter(bool forcesDisabled) 253 { 254 isHardwareForcedDisabledByFilter_ = forcesDisabled; 255 } 256 IsHardwareForcedDisabledByFilter()257 bool IsHardwareForcedDisabledByFilter() const 258 { 259 return isHardwareForcedDisabledByFilter_; 260 } 261 ResetHardwareForcedDisabledBySrcRect()262 void ResetHardwareForcedDisabledBySrcRect() 263 { 264 isHardwareForcedDisabledBySrcRect_ = false; 265 } 266 IsHardwareForcedDisabled()267 bool IsHardwareForcedDisabled() const 268 { 269 // a protected node not on the tree need to release buffer when producer produce buffers 270 // release buffer in ReleaseSelfDrawingNodeBuffer function 271 if (isProtectedLayer_ && IsOnTheTree()) { 272 return false; 273 } 274 return isHardwareForcedDisabled_ || 275 GetDstRect().GetWidth() <= 1 || GetDstRect().GetHeight() <= 1; // avoid fallback by composer 276 } 277 IsLeashOrMainWindow()278 bool IsLeashOrMainWindow() const 279 { 280 return nodeType_ <= RSSurfaceNodeType::LEASH_WINDOW_NODE; 281 } 282 IsMainWindowType()283 bool IsMainWindowType() const 284 { 285 // a mainWindowType surfacenode will not mounted under another mainWindowType surfacenode 286 // including app main window, starting window, and selfdrawing window 287 return nodeType_ <= RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE; 288 } 289 GetIsLastFrameHwcEnabled()290 bool GetIsLastFrameHwcEnabled() const 291 { 292 return isLastFrameHwcEnabled_; 293 } 294 SetIsLastFrameHwcEnabled(bool enable)295 void SetIsLastFrameHwcEnabled(bool enable) 296 { 297 isLastFrameHwcEnabled_ = enable; 298 } 299 GetNeedCollectHwcNode()300 bool GetNeedCollectHwcNode() const 301 { 302 return needCollectHwcNode_; 303 } 304 SetNeedCollectHwcNode(bool needCollect)305 void SetNeedCollectHwcNode(bool needCollect) 306 { 307 needCollectHwcNode_ = needCollect; 308 } 309 ResetNeedCollectHwcNode()310 void ResetNeedCollectHwcNode() 311 { 312 needCollectHwcNode_ = false; 313 } 314 GetCalcRectInPrepare()315 bool GetCalcRectInPrepare() const 316 { 317 return calcRectInPrepare_; 318 } 319 SetCalcRectInPrepare(bool calc)320 void SetCalcRectInPrepare(bool calc) 321 { 322 calcRectInPrepare_ = calc; 323 } 324 IsSelfDrawingType()325 bool IsSelfDrawingType() const 326 { 327 // self drawing surfacenode has its own buffer, and rendered in its own progress/thread 328 // such as surfaceview (web/videos) and self draw windows (such as mouse pointer and boot animation) 329 return nodeType_ == RSSurfaceNodeType::SELF_DRAWING_NODE || 330 nodeType_ == RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE; 331 } 332 333 bool IsUIFirstSelfDrawCheck(); 334 bool IsVisibleDirtyEmpty(DeviceType deviceType); 335 bool IsCurFrameStatic(DeviceType deviceType); 336 void UpdateCacheSurfaceDirtyManager(int bufferAge = 2); 337 GetNeedSubmitSubThread()338 bool GetNeedSubmitSubThread() const 339 { 340 return isNeedSubmitSubThread_; 341 } 342 SetNeedSubmitSubThread(bool needSubmitSubThread)343 void SetNeedSubmitSubThread(bool needSubmitSubThread) 344 { 345 isNeedSubmitSubThread_ = needSubmitSubThread; 346 } 347 GetSurfaceNodeType()348 RSSurfaceNodeType GetSurfaceNodeType() const 349 { 350 return nodeType_; 351 } 352 353 void SetSurfaceNodeType(RSSurfaceNodeType nodeType); 354 355 void MarkUIHidden(bool isHidden); 356 bool IsUIHidden() const; 357 358 bool IsLeashWindowSurfaceNodeVisible(); 359 GetName()360 const std::string& GetName() const 361 { 362 return name_; 363 } 364 GetBundleName()365 const std::string& GetBundleName() const 366 { 367 return bundleName_; 368 } 369 SetOffSetX(int32_t offset)370 void SetOffSetX(int32_t offset) 371 { 372 offsetX_ = offset; 373 } 374 GetSurfaceWindowType()375 enum SurfaceWindowType GetSurfaceWindowType() const 376 { 377 return surfaceWindowType_; 378 } 379 GetOffSetX()380 int32_t GetOffSetX() const 381 { 382 return offsetX_; 383 } 384 SetOffSetY(int32_t offset)385 void SetOffSetY(int32_t offset) 386 { 387 offsetY_ = offset; 388 } 389 GetOffSetY()390 int32_t GetOffSetY() const 391 { 392 return offsetY_; 393 } 394 SetOffset(int32_t offsetX,int32_t offsetY)395 void SetOffset(int32_t offsetX, int32_t offsetY) 396 { 397 offsetX_ = offsetX; 398 offsetY_ = offsetY; 399 } 400 GetArsrTag()401 bool GetArsrTag() const 402 { 403 return arsrTag_; 404 } 405 SetArsrTag(bool arsrTag)406 void SetArsrTag(bool arsrTag) 407 { 408 arsrTag_ = arsrTag; 409 } 410 411 void CollectSurface(const std::shared_ptr<RSBaseRenderNode>& node, std::vector<RSBaseRenderNode::SharedPtr>& vec, 412 bool isUniRender, bool onlyFirstLevel) override; 413 void CollectSurfaceForUIFirstSwitch(uint32_t& leashWindowCount, uint32_t minNodeNum) override; 414 void QuickPrepare(const std::shared_ptr<RSNodeVisitor>& visitor) override; 415 // keep specified nodetype preparation 416 virtual bool IsSubTreeNeedPrepare(bool filterInGloba, bool isOccluded = false) override; 417 void Prepare(const std::shared_ptr<RSNodeVisitor>& visitor) override; 418 void Process(const std::shared_ptr<RSNodeVisitor>& visitor) override; 419 ProcessTransitionBeforeChildren(RSPaintFilterCanvas & canvas)420 void ProcessTransitionBeforeChildren(RSPaintFilterCanvas& canvas) override {} 421 void ProcessAnimatePropertyBeforeChildren(RSPaintFilterCanvas& canvas, bool includeProperty) override; 422 void ProcessRenderBeforeChildren(RSPaintFilterCanvas& canvas) override; 423 ProcessTransitionAfterChildren(RSPaintFilterCanvas & canvas)424 void ProcessTransitionAfterChildren(RSPaintFilterCanvas& canvas) override {} 425 void ProcessAnimatePropertyAfterChildren(RSPaintFilterCanvas& canvas) override; 426 void ProcessRenderAfterChildren(RSPaintFilterCanvas& canvas) override; 427 bool IsSCBNode() const; 428 void UpdateHwcNodeLayerInfo(GraphicTransformType transform); 429 void UpdateHardwareDisabledState(bool disabled); 430 void SetHwcChildrenDisabledStateByUifirst(); 431 432 void SetContextBounds(const Vector4f bounds); 433 bool CheckParticipateInOcclusion(); 434 435 void OnApplyModifiers() override; 436 437 void SetTotalMatrix(const Drawing::Matrix& totalMatrix); GetTotalMatrix()438 const Drawing::Matrix& GetTotalMatrix() const 439 { 440 return totalMatrix_; 441 } 442 443 // Transfer the rendering context variables (matrix, alpha, and clipRegion) from the 444 // source node (in the render thread) to the 445 // target node (in the render service). Note that: 446 // - All three variables are relative to their parent node. 447 // - Alpha can be processed as an absolute value, as its parent (surface) node's alpha should always be 1.0f. 448 // - The matrix and clipRegion should be applied according to the parent node's matrix. 449 void SetContextMatrix(const std::optional<Drawing::Matrix>& transform, bool sendMsg = true); 450 void SetContextAlpha(float alpha, bool sendMsg = true); 451 void SetContextClipRegion(const std::optional<Drawing::Rect>& clipRegion, bool sendMsg = true); 452 std::optional<Drawing::Rect> GetContextClipRegion() const override; 453 454 void SetBootAnimation(bool isBootAnimation) override; 455 bool GetBootAnimation() const override; 456 457 void SetSecurityLayer(bool isSecurityLayer); 458 void SetLeashPersistentId(uint64_t leashPersistentId); 459 void SetSkipLayer(bool isSkipLayer); 460 void SetProtectedLayer(bool isProtectedLayer); 461 462 // get whether it is a security/skip layer itself 463 bool GetSecurityLayer() const; 464 bool GetSkipLayer() const; 465 bool GetProtectedLayer() const; 466 LeashPersistentId GetLeashPersistentId() const; 467 468 // set ability state that surfaceNode belongs to as foreground or background 469 void SetAbilityState(RSSurfaceNodeAbilityState abilityState); 470 RSSurfaceNodeAbilityState GetAbilityState() const override; 471 472 // get whether it and it's subtree contain security layer 473 bool GetHasSecurityLayer() const; 474 bool GetHasSkipLayer() const; 475 bool GetHasProtectedLayer() const; 476 bool GetHasPrivacyContentLayer() const; 477 ResetSpecialLayerChangedFlag()478 void ResetSpecialLayerChangedFlag() 479 { 480 specialLayerChanged_ = false; 481 } 482 IsSpecialLayerChanged()483 bool IsSpecialLayerChanged() const 484 { 485 return specialLayerChanged_; 486 } 487 488 void SyncSecurityInfoToFirstLevelNode(); 489 void SyncSkipInfoToFirstLevelNode(); 490 void SyncProtectedInfoToFirstLevelNode(); 491 void SyncPrivacyContentInfoToFirstLevelNode(); 492 493 void SetFingerprint(bool hasFingerprint); 494 bool GetFingerprint() const; 495 496 void SetForceUIFirst(bool forceUIFirst); 497 bool GetForceUIFirst() const; 498 SetUIFirstIsPurge(bool IsPurge)499 void SetUIFirstIsPurge(bool IsPurge) 500 { 501 UIFirstIsPurge_ = IsPurge; 502 } 503 GetUIFirstIsPurge()504 bool GetUIFirstIsPurge() const 505 { 506 return UIFirstIsPurge_; 507 } 508 void SetUifirstUseStarting(NodeId id); // only cache app window, first frame not wait 509 510 void SetForceUIFirstChanged(bool forceUIFirstChanged); 511 bool GetForceUIFirstChanged(); 512 513 static void SetAncoForceDoDirect(bool direct); 514 bool GetAncoForceDoDirect() const; 515 void SetAncoFlags(uint32_t flags); 516 uint32_t GetAncoFlags() const; 517 518 void SetHDRPresent(bool hasHdrPresent); 519 bool GetHDRPresent() const; 520 521 const std::shared_ptr<RSDirtyRegionManager>& GetDirtyManager() const; 522 std::shared_ptr<RSDirtyRegionManager> GetCacheSurfaceDirtyManager() const; 523 SetSrcRect(const RectI & rect)524 void SetSrcRect(const RectI& rect) 525 { 526 srcRect_ = rect; 527 } 528 529 void NeedClearBufferCache(); 530 GetSrcRect()531 const RectI& GetSrcRect() const 532 { 533 return srcRect_; 534 } 535 SetDstRect(const RectI & dstRect)536 void SetDstRect(const RectI& dstRect) 537 { 538 if (dstRect_ != dstRect) { 539 dstRectChanged_ = true; 540 } 541 dstRect_ = dstRect; 542 } 543 GetDstRect()544 const RectI& GetDstRect() const 545 { 546 return dstRect_; 547 } 548 GetOriginalDstRect()549 const RectI& GetOriginalDstRect() const 550 { 551 return originalDstRect_; 552 } 553 GetOriginalSrcRect()554 const RectI& GetOriginalSrcRect() const 555 { 556 return originalSrcRect_; 557 } 558 GetTransparentRegion()559 Occlusion::Region& GetTransparentRegion() 560 { 561 return transparentRegion_; 562 } 563 GetOpaqueRegion()564 const Occlusion::Region& GetOpaqueRegion() const 565 { 566 return opaqueRegion_; 567 } 568 GetOpaqueRegion()569 Occlusion::Region& GetOpaqueRegion() 570 { 571 return opaqueRegion_; 572 } 573 GetContainerRegion()574 Occlusion::Region& GetContainerRegion() 575 { 576 return containerRegion_; 577 } 578 OnAlphaChanged()579 void OnAlphaChanged() override { 580 alphaChanged_ = true; 581 } 582 583 void SetOcclusionVisible(bool visible); 584 GetOcclusionVisible()585 bool GetOcclusionVisible() const 586 { 587 return isOcclusionVisible_; 588 } 589 SetOcclusionVisibleWithoutFilter(bool visible)590 void SetOcclusionVisibleWithoutFilter(bool visible) 591 { 592 isOcclusionVisibleWithoutFilter_ = visible; 593 } 594 SetOcclusionInSpecificScenes(bool isOcclusionInSpecificScenes)595 void SetOcclusionInSpecificScenes(bool isOcclusionInSpecificScenes) 596 { 597 isOcclusionInSpecificScenes_ = isOcclusionInSpecificScenes; 598 } 599 GetVisibleRegion()600 const Occlusion::Region& GetVisibleRegion() const 601 { 602 return visibleRegion_; 603 } 604 GetVisibleRegionInVirtual()605 const Occlusion::Region& GetVisibleRegionInVirtual() const 606 { 607 return visibleRegionInVirtual_; 608 } 609 GetVisibleRegionForCallBack()610 const Occlusion::Region& GetVisibleRegionForCallBack() const 611 { 612 return visibleRegionForCallBack_; 613 } 614 SetAbilityBGAlpha(uint8_t alpha)615 void SetAbilityBGAlpha(uint8_t alpha) 616 { 617 alphaChanged_ = (alpha == 255 && abilityBgAlpha_ != 255) || 618 (alpha != 255 && abilityBgAlpha_ == 255); 619 abilityBgAlpha_ = alpha; 620 } 621 GetAbilityBgAlpha()622 uint8_t GetAbilityBgAlpha() const 623 { 624 return abilityBgAlpha_; 625 } 626 setQosCal(bool qosPidCal)627 void setQosCal(bool qosPidCal) 628 { 629 qosPidCal_ = qosPidCal; 630 } 631 632 bool IsSurfaceInStartingWindowStage() const; 633 634 WINDOW_LAYER_INFO_TYPE GetVisibleLevelForWMS(RSVisibleLevel visibleLevel); 635 636 void SetVisibleRegionRecursive( 637 const Occlusion::Region& region, 638 VisibleData& visibleVec, 639 std::map<NodeId, RSVisibleLevel>& pidVisMap, 640 bool needSetVisibleRegion = true, 641 RSVisibleLevel visibleLevel = RSVisibleLevel::RS_UNKNOW_VISIBLE_LEVEL, 642 bool isSystemAnimatedScenes = false); 643 SetLeashWindowVisibleRegionEmpty(bool isLeashWindowVisibleRegionEmpty)644 void SetLeashWindowVisibleRegionEmpty(bool isLeashWindowVisibleRegionEmpty) 645 { 646 if (!IsLeashWindow()) { 647 return; 648 } 649 isLeashWindowVisibleRegionEmpty_ = isLeashWindowVisibleRegionEmpty; 650 SetLeashWindowVisibleRegionEmptyParam(); 651 } 652 GetLeashWindowVisibleRegionEmpty()653 bool GetLeashWindowVisibleRegionEmpty() const 654 { 655 return isLeashWindowVisibleRegionEmpty_; 656 } 657 658 void SetLeashWindowVisibleRegionEmptyParam(); 659 SetExtraDirtyRegionAfterAlignment(const Occlusion::Region & region)660 void SetExtraDirtyRegionAfterAlignment(const Occlusion::Region& region) 661 { 662 extraDirtyRegionAfterAlignment_ = region; 663 extraDirtyRegionAfterAlignmentIsEmpty_ = extraDirtyRegionAfterAlignment_.IsEmpty(); 664 } 665 GetDstRectChanged()666 bool GetDstRectChanged() const 667 { 668 return dstRectChanged_; 669 } 670 CleanDstRectChanged()671 void CleanDstRectChanged() 672 { 673 dstRectChanged_ = false; 674 } 675 GetAlphaChanged()676 bool GetAlphaChanged() const 677 { 678 return alphaChanged_; 679 } 680 CleanAlphaChanged()681 void CleanAlphaChanged() 682 { 683 alphaChanged_ = false; 684 } 685 686 void SetLocalZOrder(float localZOrder); 687 float GetLocalZOrder() const; 688 689 void SetColorSpace(GraphicColorGamut colorSpace); 690 GraphicColorGamut GetColorSpace() const; 691 692 // Only call this if the node is self-drawing surface node. 693 void UpdateColorSpaceWithMetadata(); 694 695 #ifndef ROSEN_CROSS_PLATFORM 696 void SetConsumer(const sptr<IConsumerSurface>& consumer); 697 void SetBlendType(GraphicBlendType blendType); 698 GraphicBlendType GetBlendType(); 699 #endif 700 701 void UpdateSurfaceDefaultSize(float width, float height); 702 703 // Only SurfaceNode in RS calls "RegisterBufferAvailableListener" 704 // to save callback method sent by RT or UI which depends on the value of "isFromRenderThread". 705 void RegisterBufferAvailableListener(sptr<RSIBufferAvailableCallback> callback, bool isFromRenderThread); 706 707 void RegisterBufferClearListener(sptr<RSIBufferClearCallback> callback); 708 709 // Only SurfaceNode in RT calls "ConnectToNodeInRenderService" to send callback method to RS 710 void ConnectToNodeInRenderService(); 711 712 void NotifyRTBufferAvailable(bool isTextureExportNode = false); 713 bool IsNotifyRTBufferAvailable() const; 714 bool IsNotifyRTBufferAvailablePre() const; 715 716 void NotifyUIBufferAvailable(); 717 bool IsNotifyUIBufferAvailable() const; 718 void SetIsNotifyUIBufferAvailable(bool available); 719 720 // UI Thread would not be notified when SurfaceNode created by Video/Camera in RenderService has available buffer. 721 // And RenderThread does not call mainFunc_ if nothing in UI thread is changed 722 // which would cause callback for "clip" on parent SurfaceNode cannot be triggered 723 // for "clip" is executed in RenderThreadVisitor::ProcessSurfaceRenderNode. 724 // To fix this bug, we set callback which would call RSRenderThread::RequestNextVSync() to forcedly "refresh" 725 // RenderThread when SurfaceNode in RenderService has available buffer and execute RSIBufferAvailableCallback. 726 void SetCallbackForRenderThreadRefresh(bool isRefresh); 727 bool NeedSetCallbackForRenderThreadRefresh(); 728 ParallelVisitLock()729 void ParallelVisitLock() 730 { 731 parallelVisitMutex_.lock(); 732 } 733 ParallelVisitUnlock()734 void ParallelVisitUnlock() 735 { 736 parallelVisitMutex_.unlock(); 737 } 738 SubNodeVisible(const RectI & r)739 bool SubNodeVisible(const RectI& r) const 740 { 741 Occlusion::Rect nodeRect { r.left_, r.top_, r.GetRight(), r.GetBottom() }; 742 // if current node is in occluded region of the surface, it could be skipped in process step 743 return visibleRegion_.IsIntersectWith(nodeRect); 744 } 745 746 bool CheckIfOcclusionReusable(std::queue<NodeId>& surfaceNodesIds) const; 747 bool CheckIfOcclusionChanged() const; 748 SetVisibleRegion(const Occlusion::Region & region)749 void SetVisibleRegion(const Occlusion::Region& region) 750 { 751 visibleRegion_ = region; 752 } 753 SetVisibleRegionInVirtual(const Occlusion::Region & region)754 void SetVisibleRegionInVirtual(const Occlusion::Region& region) 755 { 756 visibleRegionInVirtual_ = region; 757 } 758 IsEmptyAppWindow()759 inline bool IsEmptyAppWindow() const 760 { 761 return IsAppWindow() && (GetChildrenCount() == 0 || HasOnlyOneRootNode()); 762 } 763 IsTransparent()764 inline bool IsTransparent() const 765 { 766 const uint8_t opacity = 255; 767 return !(GetAbilityBgAlpha() == opacity && ROSEN_EQ(GetGlobalAlpha(), 1.0f)) || 768 (IsEmptyAppWindow() && RSUniRenderJudgement::IsUniRender()); 769 } 770 IsCurrentNodeInTransparentRegion(const Occlusion::Rect & nodeRect)771 inline bool IsCurrentNodeInTransparentRegion(const Occlusion::Rect& nodeRect) const 772 { 773 return transparentRegion_.IsIntersectWith(nodeRect); 774 } 775 776 // Used when the node is opaque, but not calculate in occlusion SetTreatedAsTransparent(bool isOcclusion)777 void SetTreatedAsTransparent(bool isOcclusion) 778 { 779 isTreatedAsTransparent_ = isOcclusion; 780 } 781 IsTreatedAsTransparent()782 bool IsTreatedAsTransparent() const 783 { 784 return isTreatedAsTransparent_; 785 } 786 GetZorderChanged()787 bool GetZorderChanged() const 788 { 789 return zOrderChanged_; 790 } 791 IsZOrderPromoted()792 bool IsZOrderPromoted() const 793 { 794 return GetRenderProperties().GetPositionZ() > positionZ_; 795 } 796 UpdatePositionZ()797 void UpdatePositionZ() 798 { 799 const auto& zProperties = GetRenderProperties().GetPositionZ(); 800 zOrderChanged_ = !ROSEN_EQ(zProperties, positionZ_); 801 positionZ_ = zProperties; 802 } 803 HasContainerWindow()804 inline bool HasContainerWindow() const 805 { 806 return containerConfig_.hasContainerWindow_; 807 } 808 SetContainerWindow(bool hasContainerWindow,float density)809 void SetContainerWindow(bool hasContainerWindow, float density) 810 { 811 containerConfig_.Update(hasContainerWindow, density); 812 } 813 IsOpaqueRegionChanged()814 bool IsOpaqueRegionChanged() const 815 { 816 return opaqueRegionChanged_; 817 } 818 CleanOpaqueRegionChanged()819 void CleanOpaqueRegionChanged() 820 { 821 opaqueRegionChanged_ = false; 822 } 823 824 // [planning] Remove this after skia is upgraded, the clipRegion is supported 825 void ResetChildrenFilterRects(); 826 void UpdateChildrenFilterRects(std::shared_ptr<RSRenderNode> filternode, const RectI& rect, bool cacheValid); 827 const std::vector<RectI>& GetChildrenNeedFilterRects() const; 828 const std::vector<bool>& GetChildrenNeedFilterRectsCacheValid() const; 829 const std::vector<std::shared_ptr<RSRenderNode>>& GetChildrenFilterNodes() const; 830 std::vector<RectI> GetChildrenNeedFilterRectsWithoutCacheValid(); 831 832 // manage abilities' nodeid info 833 void UpdateAbilityNodeIds(NodeId id, bool isAdded); 834 const std::unordered_set<NodeId>& GetAbilityNodeIds() const; 835 void AddAbilityComponentNodeIds(const std::unordered_set<NodeId>& nodeIds); 836 void ResetAbilityNodeIds(); 837 838 // manage appWindowNode's child hardware enabled nodes info 839 void ResetChildHardwareEnabledNodes(); 840 void AddChildHardwareEnabledNode(WeakPtr childNode); 841 const std::vector<WeakPtr>& GetChildHardwareEnabledNodes() const; 842 IsFocusedNode(uint64_t focusedNodeId)843 bool IsFocusedNode(uint64_t focusedNodeId) 844 { 845 return GetId() == focusedNodeId; 846 } 847 848 void CheckAndUpdateOpaqueRegion(const RectI& screeninfo, const ScreenRotation screenRotation, 849 const bool isFocusWindow); 850 851 void ResetSurfaceOpaqueRegion(const RectI& screeninfo, const RectI& absRect, const ScreenRotation screenRotation, 852 const bool isFocusWindow, const Vector4<int>& cornerRadius); 853 Occlusion::Region ResetOpaqueRegion( 854 const RectI& absRect, const ScreenRotation screenRotation, const bool isFocusWindow) const; 855 Occlusion::Region SetUnfocusedWindowOpaqueRegion(const RectI& absRect, const ScreenRotation screenRotation) const; 856 Occlusion::Region SetFocusedWindowOpaqueRegion(const RectI& absRect, const ScreenRotation screenRotation) const; 857 Occlusion::Region SetCornerRadiusOpaqueRegion(const RectI& absRect, const Vector4<int>& cornerRadius) const; 858 void ResetSurfaceContainerRegion(const RectI& screeninfo, const RectI& absRect, 859 const ScreenRotation screenRotation); 860 bool CheckOpaqueRegionBaseInfo(const RectI& screeninfo, const RectI& absRect, const ScreenRotation screenRotation, 861 const bool isFocusWindow, const Vector4<int>& cornerRadius); 862 void SetOpaqueRegionBaseInfo(const RectI& screeninfo, const RectI& absRect, const ScreenRotation screenRotation, 863 const bool isFocusWindow, const Vector4<int>& cornerRadius); 864 bool IsStartAnimationFinished() const; 865 void SetStartAnimationFinished(); 866 // if surfacenode's buffer has been consumed, it should be set dirty 867 bool UpdateDirtyIfFrameBufferConsumed(); 868 869 void UpdateSrcRect(const Drawing::Canvas& canvas, const Drawing::RectI& dstRect, bool hasRotation = false); 870 void UpdateHwcDisabledBySrcRect(bool hasRotation); 871 872 // if a surfacenode's dstrect is empty, its subnodes' prepare stage can be skipped 873 bool ShouldPrepareSubnodes(); 874 void StoreMustRenewedInfo() override; 875 SetNodeCost(int32_t cost)876 void SetNodeCost(int32_t cost) 877 { 878 nodeCost_ = cost; 879 } 880 GetNodeCost()881 int32_t GetNodeCost() const 882 { 883 return nodeCost_; 884 } 885 886 std::string DirtyRegionDump() const; SetAnimateState()887 void SetAnimateState() { 888 animateState_ = true; 889 } ResetAnimateState()890 void ResetAnimateState() { 891 animateState_ = false; 892 } GetAnimateState()893 bool GetAnimateState() const 894 { 895 return animateState_; 896 } 897 bool IsParentLeashWindowInScale() const; 898 899 Occlusion::Rect GetSurfaceOcclusionRect(bool isUniRender); 900 901 void AccumulateOcclusionRegion(Occlusion::Region& accumulatedRegion, 902 Occlusion::Region& curRegion, 903 bool& hasFilterCacheOcclusion, 904 bool isUniRender, 905 bool filterCacheOcclusionEnabled); 906 907 bool LeashWindowRelatedAppWindowOccluded(std::vector<std::shared_ptr<RSSurfaceRenderNode>>& appNode); 908 909 void OnTreeStateChanged() override; 910 SetDrawingGPUContext(Drawing::GPUContext * grContext)911 void SetDrawingGPUContext(Drawing::GPUContext* grContext) 912 { 913 grContext_ = grContext; 914 } 915 // UIFirst 916 void UpdateUIFirstFrameGravity(); 917 SetSubmittedSubThreadIndex(uint32_t index)918 void SetSubmittedSubThreadIndex(uint32_t index) 919 { 920 submittedSubThreadIndex_ = index; 921 } 922 GetSubmittedSubThreadIndex()923 uint32_t GetSubmittedSubThreadIndex() const 924 { 925 return submittedSubThreadIndex_; 926 } 927 IsWaitUifirstFirstFrame()928 bool IsWaitUifirstFirstFrame() const 929 { 930 return isWaitUifirstFirstFrame_; 931 } 932 SetWaitUifirstFirstFrame(bool wait)933 void SetWaitUifirstFirstFrame(bool wait) 934 { 935 isWaitUifirstFirstFrame_ = wait; 936 } 937 938 void SetCacheSurfaceProcessedStatus(CacheProcessStatus cacheProcessStatus); 939 CacheProcessStatus GetCacheSurfaceProcessedStatus() const; 940 941 void RegisterTreeStateChangeCallback(TreeStateChangeCallback callback); 942 void NotifyTreeStateChange(); 943 944 /* For filter cache occlusion calculation */ GetFilterCacheFullyCovered()945 bool GetFilterCacheFullyCovered() const 946 { 947 return isFilterCacheFullyCovered_; 948 } 949 SetFilterCacheFullyCovered(bool val)950 void SetFilterCacheFullyCovered(bool val) 951 { 952 isFilterCacheFullyCovered_ = val; 953 } 954 GetFilterCacheValidForOcclusion()955 bool GetFilterCacheValidForOcclusion() const 956 { 957 return isFilterCacheValidForOcclusion_; 958 } 959 960 // mark if any valid filter cache within surface fully cover targer range 961 void CheckValidFilterCacheFullyCoverTarget(const RSRenderNode& filterNode, const RectI& targetRect); 962 void CalcFilterCacheValidForOcclusion(); 963 // mark occluded by upper filtercache 964 void UpdateOccludedByFilterCache(bool val); 965 bool IsOccludedByFilterCache() const; 966 IsFilterCacheStatusChanged()967 bool IsFilterCacheStatusChanged() const 968 { 969 return isFilterCacheStatusChanged_; 970 } 971 ResetFilterNodes()972 void ResetFilterNodes() 973 { 974 filterNodes_.clear(); 975 } 976 void UpdateFilterNodes(const std::shared_ptr<RSRenderNode>& nodePtr); 977 // update static node's back&front-ground filter cache status 978 void UpdateFilterCacheStatusWithVisible(bool visible); 979 void UpdateFilterCacheStatusIfNodeStatic(const RectI& clipRect, bool isRotationChanged); 980 void UpdateDrawingCacheNodes(const std::shared_ptr<RSRenderNode>& nodePtr); 981 // reset static node's drawing cache status as not changed and get filter rects 982 void ResetDrawingCacheStatusIfNodeStatic(std::unordered_map<NodeId, std::unordered_set<NodeId>>& allRects); 983 984 void SetNotifyRTBufferAvailable(bool isNotifyRTBufferAvailable); 985 986 // whether the subtree has only one root node 987 bool HasOnlyOneRootNode() const; 988 GetHwcDelayDirtyFlag()989 bool GetHwcDelayDirtyFlag() const noexcept 990 { 991 return hwcDelayDirtyFlag_; 992 } 993 SetHwcDelayDirtyFlag(bool hwcDelayDirtyFlag)994 void SetHwcDelayDirtyFlag(bool hwcDelayDirtyFlag) 995 { 996 hwcDelayDirtyFlag_ = hwcDelayDirtyFlag; 997 } 998 GetSurfaceCacheContentStatic()999 bool GetSurfaceCacheContentStatic() 1000 { 1001 return surfaceCacheContentStatic_; 1002 } 1003 1004 void UpdateSurfaceCacheContentStatic(); 1005 1006 void UpdateSurfaceCacheContentStatic( 1007 const std::unordered_map<NodeId, std::weak_ptr<RSRenderNode>>& activeNodeIds); 1008 // temperory limit situation: 1009 // subtree no drawingcache and geodirty 1010 // contentdirty 1 specifically for buffer update IsContentDirtyNodeLimited()1011 bool IsContentDirtyNodeLimited() const 1012 { 1013 return drawingCacheNodes_.empty() && dirtyGeoNodeNum_ == 0 && dirtyContentNodeNum_ <= 1; 1014 } 1015 GetLastFrameChildrenCnt()1016 size_t GetLastFrameChildrenCnt() 1017 { 1018 return lastFrameChildrenCnt_; 1019 } 1020 SetLastFrameChildrenCnt(size_t childrenCnt)1021 void SetLastFrameChildrenCnt(size_t childrenCnt) 1022 { 1023 lastFrameChildrenCnt_ = childrenCnt; 1024 } 1025 1026 bool IsUIFirstCacheReusable(DeviceType deviceType); 1027 GetUifirstSupportFlag()1028 bool GetUifirstSupportFlag() override 1029 { 1030 return RSRenderNode::GetUifirstSupportFlag(); 1031 } 1032 OpincGetNodeSupportFlag()1033 bool OpincGetNodeSupportFlag() override 1034 { 1035 return false; 1036 } 1037 1038 void UpdateSurfaceCacheContentStaticFlag(); 1039 1040 void UpdateSurfaceSubTreeDirtyFlag(); 1041 MergeOldDirtyRect()1042 void MergeOldDirtyRect() override 1043 { 1044 if (IsAppWindow()) { 1045 this->GetDirtyManager()->MergeDirtyRect(this->GetOldDirtyInSurface()); 1046 } 1047 } 1048 1049 #ifdef USE_SURFACE_TEXTURE GetSurfaceTexture()1050 std::shared_ptr<RSSurfaceTexture> GetSurfaceTexture() const { return surfaceTexture_; }; SetSurfaceTexture(const std::shared_ptr<RSSurfaceTexture> & texture)1051 void SetSurfaceTexture(const std::shared_ptr<RSSurfaceTexture> &texture) { surfaceTexture_ = texture; } 1052 #endif 1053 SetForeground(bool isForeground)1054 void SetForeground(bool isForeground) 1055 { 1056 isForeground_ = isForeground; 1057 } 1058 SetSurfaceId(SurfaceId surfaceId)1059 void SetSurfaceId(SurfaceId surfaceId) 1060 { 1061 surfaceId_ = surfaceId; 1062 } 1063 GetSurfaceId()1064 SurfaceId GetSurfaceId() const 1065 { 1066 return surfaceId_; 1067 } 1068 GetIsForeground()1069 bool GetIsForeground() const 1070 { 1071 return isForeground_; 1072 } 1073 bool GetNodeIsSingleFrameComposer() const override; 1074 SetAncestorDisplayNode(const RSBaseRenderNode::WeakPtr & ancestorDisplayNode)1075 void SetAncestorDisplayNode(const RSBaseRenderNode::WeakPtr& ancestorDisplayNode) 1076 { 1077 ancestorDisplayNode_ = ancestorDisplayNode; 1078 } 1079 1080 void SetUifirstNodeEnableParam(MultiThreadCacheType b); 1081 1082 void SetIsParentUifirstNodeEnableParam(bool b); 1083 1084 void SetUifirstChildrenDirtyRectParam(RectI rect); 1085 SetUifirstStartTime(int64_t startTime)1086 void SetUifirstStartTime(int64_t startTime) 1087 { 1088 uifirstStartTime_ = startTime; 1089 } 1090 GetUifirstStartTime()1091 int64_t GetUifirstStartTime() const 1092 { 1093 return uifirstStartTime_; 1094 } 1095 GetAncestorDisplayNode()1096 RSBaseRenderNode::WeakPtr GetAncestorDisplayNode() const 1097 { 1098 return ancestorDisplayNode_; 1099 } 1100 bool QuerySubAssignable(bool isRotation); 1101 bool QueryIfAllHwcChildrenForceDisabledByFilter(); 1102 bool GetHasSharedTransitionNode() const; 1103 void SetHasSharedTransitionNode(bool hasSharedTransitionNode); 1104 Vector2f GetGravityTranslate(float imgWidth, float imgHeight); 1105 bool GetHasTransparentSurface() const; 1106 void UpdatePartialRenderParams(); 1107 // This function is used for extending visibleRegion by dirty blurfilter node half-obscured 1108 void UpdateExtendVisibleRegion(Occlusion::Region& region); 1109 void UpdateAncestorDisplayNodeInRenderParams(); 1110 SetNeedDrawFocusChange(bool needDrawFocusChange)1111 void SetNeedDrawFocusChange(bool needDrawFocusChange) 1112 { 1113 needDrawFocusChange_ = needDrawFocusChange; 1114 } 1115 GetNeedDrawFocusChange()1116 bool GetNeedDrawFocusChange() const 1117 { 1118 return needDrawFocusChange_; 1119 } 1120 HasWindowCorner()1121 bool HasWindowCorner() 1122 { 1123 Vector4f cornerRadius; 1124 Vector4f::Max(GetWindowCornerRadius(), GetGlobalCornerRadius(), cornerRadius); 1125 return !cornerRadius.IsZero(); 1126 } SetBufferRelMatrix(const Drawing::Matrix & matrix)1127 void SetBufferRelMatrix(const Drawing::Matrix& matrix) 1128 { 1129 bufferRelMatrix_ = matrix; 1130 } 1131 GetBufferRelMatrix()1132 const Drawing::Matrix& GetBufferRelMatrix() const 1133 { 1134 return bufferRelMatrix_; 1135 } 1136 SetGpuOverDrawBufferOptimizeNode(bool overDrawNode)1137 void SetGpuOverDrawBufferOptimizeNode(bool overDrawNode) 1138 { 1139 isGpuOverDrawBufferOptimizeNode_ = overDrawNode; 1140 } IsGpuOverDrawBufferOptimizeNode()1141 bool IsGpuOverDrawBufferOptimizeNode() const 1142 { 1143 return isGpuOverDrawBufferOptimizeNode_; 1144 } 1145 SetOverDrawBufferNodeCornerRadius(const Vector4f & radius)1146 void SetOverDrawBufferNodeCornerRadius(const Vector4f& radius) 1147 { 1148 overDrawBufferNodeCornerRadius_ = radius; 1149 } GetOverDrawBufferNodeCornerRadius()1150 const Vector4f& GetOverDrawBufferNodeCornerRadius() const 1151 { 1152 return overDrawBufferNodeCornerRadius_; 1153 } 1154 1155 bool HasSubSurfaceNodes() const; 1156 void SetIsSubSurfaceNode(bool isSubSurfaceNode); 1157 bool IsSubSurfaceNode() const; 1158 const std::map<NodeId, RSSurfaceRenderNode::WeakPtr>& GetChildSubSurfaceNodes() const; 1159 void GetAllSubSurfaceNodes(std::vector<std::pair<NodeId, RSSurfaceRenderNode::WeakPtr>>& allSubSurfaceNodes); 1160 std::string SubSurfaceNodesDump() const; 1161 1162 void SetIsNodeToBeCaptured(bool isNodeToBeCaptured); 1163 bool IsNodeToBeCaptured() const; 1164 SetDoDirectComposition(bool flag)1165 void SetDoDirectComposition(bool flag) 1166 { 1167 doDirectComposition_ = flag; 1168 } 1169 GetDoDirectComposition()1170 bool GetDoDirectComposition() const 1171 { 1172 return doDirectComposition_; 1173 } 1174 SetHardWareDisabledByReverse(bool isHardWareDisabledByReverse)1175 void SetHardWareDisabledByReverse(bool isHardWareDisabledByReverse) 1176 { 1177 isHardWareDisabledByReverse_ = isHardWareDisabledByReverse; 1178 } 1179 GetHardWareDisabledByReverse()1180 bool GetHardWareDisabledByReverse() const 1181 { 1182 return isHardWareDisabledByReverse_; 1183 } 1184 1185 void SetSkipDraw(bool skip); 1186 bool GetSkipDraw() const; 1187 void SetHidePrivacyContent(bool needHidePrivacyContent); 1188 void SetNeedOffscreen(bool needOffscreen); 1189 void SetSdrNit(int32_t sdrNit); 1190 void SetDisplayNit(int32_t displayNit); 1191 void SetBrightnessRatio(float brightnessRatio); 1192 static const std::unordered_map<NodeId, NodeId>& GetSecUIExtensionNodes(); IsSecureUIExtension()1193 bool IsSecureUIExtension() const 1194 { 1195 return nodeType_ == RSSurfaceNodeType::UI_EXTENSION_SECURE_NODE; 1196 } 1197 IsUIExtension()1198 bool IsUIExtension() const 1199 { 1200 return nodeType_ == RSSurfaceNodeType::UI_EXTENSION_COMMON_NODE || 1201 nodeType_ == RSSurfaceNodeType::UI_EXTENSION_SECURE_NODE; 1202 } 1203 1204 void SetCornerRadiusInfoForDRM(const std::vector<float>& drmCornerRadius); GetCornerRadiusInfoForDRM()1205 const std::vector<float>& GetCornerRadiusInfoForDRM() const 1206 { 1207 return drmCornerRadiusInfo_; 1208 } 1209 GetRSSurfaceHandler()1210 const std::shared_ptr<RSSurfaceHandler> GetRSSurfaceHandler() const 1211 { 1212 return surfaceHandler_; 1213 } 1214 GetMutableRSSurfaceHandler()1215 std::shared_ptr<RSSurfaceHandler> GetMutableRSSurfaceHandler() 1216 { 1217 return surfaceHandler_; 1218 } 1219 CheckContainerDirtyStatusAndUpdateDirty(bool containerDirty)1220 void CheckContainerDirtyStatusAndUpdateDirty(bool containerDirty) 1221 { 1222 if (!IsLeashWindow()) { 1223 return; 1224 } 1225 dirtyStatus_ = containerDirty ? NodeDirty::DIRTY : dirtyStatus_; 1226 } 1227 1228 template<class... Args> SetIntersectedRoundCornerAABBs(Args &&...args)1229 void SetIntersectedRoundCornerAABBs(Args&& ...args) 1230 { 1231 std::vector<RectI>(std::forward<Args>(args)...).swap(intersectedRoundCornerAABBs_); 1232 } 1233 GetIntersectedRoundCornerAABBs()1234 const std::vector<RectI>& GetIntersectedRoundCornerAABBs() const 1235 { 1236 return intersectedRoundCornerAABBs_; 1237 } 1238 GetIntersectedRoundCornerAABBsSize()1239 size_t GetIntersectedRoundCornerAABBsSize() const 1240 { 1241 return intersectedRoundCornerAABBs_.size(); 1242 } 1243 1244 protected: 1245 void OnSync() override; 1246 1247 // rotate corner by rotation degreee. Every 90 degrees clockwise rotation, the vector 1248 // of corner radius loops one element to the right 1249 void RotateCorner(int rotationDegree, Vector4<int>& cornerRadius) const; 1250 1251 private: 1252 explicit RSSurfaceRenderNode(NodeId id, const std::weak_ptr<RSContext>& context = {}, 1253 bool isTextureExportNode = false); 1254 explicit RSSurfaceRenderNode(const RSSurfaceRenderNodeConfig& config, const std::weak_ptr<RSContext>& context = {}); 1255 void OnResetParent() override; 1256 void ClearChildrenCache(); 1257 Vector4f GetWindowCornerRadius(); 1258 std::vector<std::shared_ptr<RSSurfaceRenderNode>> GetLeashWindowNestedSurfaces(); 1259 bool IsHistoryOccludedDirtyRegionNeedSubmit(); 1260 void ClearHistoryUnSubmittedDirtyInfo(); 1261 void UpdateHistoryUnsubmittedDirtyInfo(); IsHardwareDisabledBySrcRect()1262 inline bool IsHardwareDisabledBySrcRect() const 1263 { 1264 return isHardwareForcedDisabledBySrcRect_; 1265 } 1266 void OnSubSurfaceChanged(); 1267 void UpdateChildSubSurfaceNodes(RSSurfaceRenderNode::SharedPtr node, bool isOnTheTree); 1268 bool IsYUVBufferFormat() const; 1269 void InitRenderParams() override; 1270 void UpdateRenderParams() override; 1271 void UpdateChildHardwareEnabledNode(NodeId id, bool isOnTree); 1272 std::mutex mutexRT_; 1273 std::mutex mutexUI_; 1274 std::mutex mutexClear_; 1275 std::mutex mutex_; 1276 Drawing::GPUContext* grContext_ = nullptr; 1277 std::mutex parallelVisitMutex_; 1278 1279 float contextAlpha_ = 1.0f; 1280 std::optional<Drawing::Matrix> contextMatrix_; 1281 std::optional<Drawing::Rect> contextClipRect_; 1282 1283 bool isSecurityLayer_ = false; 1284 bool isSkipLayer_ = false; 1285 bool isProtectedLayer_ = false; 1286 std::set<NodeId> skipLayerIds_= {}; 1287 std::set<NodeId> securityLayerIds_= {}; 1288 std::set<NodeId> protectedLayerIds_= {}; 1289 std::set<NodeId> privacyContentLayerIds_ = {}; 1290 bool specialLayerChanged_ = false; 1291 1292 bool hasFingerprint_ = false; 1293 bool hasHdrPresent_ = false; 1294 RectI srcRect_; 1295 Drawing::Matrix totalMatrix_; 1296 std::vector<RectI> intersectedRoundCornerAABBs_; 1297 int32_t offsetX_ = 0; 1298 int32_t offsetY_ = 0; 1299 float positionZ_ = 0.0f; 1300 bool zOrderChanged_ = false; 1301 bool qosPidCal_ = false; 1302 SurfaceId surfaceId_ = 0; 1303 RSSurfaceNodeAbilityState abilityState_ = RSSurfaceNodeAbilityState::FOREGROUND; 1304 std::vector<float> drmCornerRadiusInfo_; 1305 1306 std::string name_; 1307 std::string bundleName_; 1308 RSSurfaceNodeType nodeType_ = RSSurfaceNodeType::DEFAULT; 1309 bool isLayerTop_ = false; 1310 const enum SurfaceWindowType surfaceWindowType_ = SurfaceWindowType::DEFAULT_WINDOW; 1311 // This variable can be set in two cases: 1312 // 1. The upper-layer IPC interface directly sets window colorspace. 1313 // 2. If it is a self-drawing node, the colorspace will be refreshed after hardware-enable calculation. 1314 GraphicColorGamut colorSpace_ = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB; 1315 #ifndef ROSEN_CROSS_PLATFORM 1316 GraphicBlendType blendType_ = GraphicBlendType::GRAPHIC_BLEND_SRCOVER; 1317 #endif 1318 bool isNotifyRTBufferAvailablePre_ = false; 1319 std::atomic<bool> isNotifyRTBufferAvailable_ = false; 1320 std::atomic<bool> isNotifyUIBufferAvailable_ = true; 1321 std::atomic_bool isBufferAvailable_ = false; 1322 sptr<RSIBufferAvailableCallback> callbackFromRT_ = nullptr; 1323 sptr<RSIBufferAvailableCallback> callbackFromUI_ = nullptr; 1324 sptr<RSIBufferClearCallback> clearBufferCallback_ = nullptr; 1325 bool isRefresh_ = false; 1326 std::vector<NodeId> childSurfaceNodeIds_; 1327 friend class RSRenderThreadVisitor; 1328 RectI clipRegionFromParent_; 1329 uint64_t leashPersistentId_ = INVALID_LEASH_PERSISTENTID; 1330 /* 1331 visibleRegion: appwindow visible region after occlusion, used for rs opdrop and other optimization. 1332 visibleRegionForCallBack: appwindow visible region after occlusion (no filtercache occlusion), used in 1333 windowmanager, and web surfacenode visibility callback. 1334 These two values are the same in most cases. If there are filter cache occlusion, this two values will be 1335 different under filter cache surfacenode layer. 1336 */ 1337 Occlusion::Region visibleRegion_; 1338 Occlusion::Region extendVisibleRegion_; 1339 Occlusion::Region visibleRegionInVirtual_; 1340 Occlusion::Region visibleRegionForCallBack_; 1341 bool isLeashWindowVisibleRegionEmpty_ = false; 1342 bool isOcclusionVisible_ = true; 1343 bool isOcclusionVisibleWithoutFilter_ = true; 1344 bool isOcclusionInSpecificScenes_ = false; 1345 std::shared_ptr<RSDirtyRegionManager> dirtyManager_ = nullptr; 1346 std::shared_ptr<RSDirtyRegionManager> cacheSurfaceDirtyManager_ = nullptr; 1347 RectI dstRect_; 1348 bool dstRectChanged_ = false; 1349 uint8_t abilityBgAlpha_ = 0; 1350 bool alphaChanged_ = false; 1351 bool isUIHidden_ = false; 1352 1353 // dirtyRegion caused by surfaceNode visible region after alignment 1354 Occlusion::Region extraDirtyRegionAfterAlignment_; 1355 bool extraDirtyRegionAfterAlignmentIsEmpty_ = true; 1356 1357 // opaque region of the surface 1358 Occlusion::Region opaqueRegion_; 1359 bool opaqueRegionChanged_ = false; 1360 // [planning] Remove this after skia is upgraded, the clipRegion is supported 1361 std::vector<RectI> childrenFilterRects_; 1362 std::vector<bool> childrenFilterRectsCacheValid_; 1363 std::vector<std::shared_ptr<RSRenderNode>> childrenFilterNodes_; 1364 std::unordered_set<NodeId> abilityNodeIds_; 1365 size_t dirtyContentNodeNum_ = 0; 1366 size_t dirtyGeoNodeNum_ = 0; 1367 size_t dirtynodeNum_ = 0; 1368 // transparent region of the surface, floating window's container window is always treated as transparent 1369 Occlusion::Region transparentRegion_; 1370 1371 Occlusion::Region containerRegion_; 1372 bool isFilterCacheFullyCovered_ = false; 1373 bool isFilterCacheValidForOcclusion_ = false; 1374 bool isOccludedByFilterCache_ = false; 1375 bool isFilterCacheStatusChanged_ = false; 1376 bool isTreatedAsTransparent_ = false; 1377 // valid filter nodes within, including itself 1378 std::vector<std::shared_ptr<RSRenderNode>> filterNodes_; 1379 std::unordered_map<NodeId, std::weak_ptr<RSRenderNode>> drawingCacheNodes_; 1380 1381 // hdr 1382 int32_t displayNit_ = 500; // default sdr luminance 1383 float brightnessRatio_ = 1.0f; // no ratio by default 1384 1385 struct OpaqueRegionBaseInfo 1386 { 1387 RectI screenRect_; 1388 RectI absRect_; 1389 RectI oldDirty_; 1390 ScreenRotation screenRotation_ = ScreenRotation::INVALID_SCREEN_ROTATION; 1391 bool isFocusWindow_ = false; 1392 bool isTransparent_ = false; 1393 bool hasContainerWindow_ = false; 1394 Vector4<int> cornerRadius_; 1395 }; 1396 1397 //<screenRect, absRect, screenRotation, isFocusWindow, isTransparent, hasContainerWindow> 1398 OpaqueRegionBaseInfo opaqueRegionBaseInfo_; 1399 1400 /* 1401 ContainerWindow configs acquired from arkui, including container window state, screen density, container border 1402 width, padding width, inner/outer radius, etc. 1403 */ 1404 class ContainerConfig { 1405 public: 1406 void Update(bool hasContainer, float density); 1407 private: RoundFloor(float length)1408 inline int RoundFloor(float length) 1409 { 1410 // if a float value is very close to a integer (< 0.05f), return round value 1411 return std::abs(length - std::round(length)) < 0.05f ? std::round(length) : std::floor(length); 1412 } 1413 public: 1414 // temporary const value from ACE container_modal_constants.h, will be replaced by uniform interface 1415 const static int CONTAINER_TITLE_HEIGHT = 37; // container title height = 37 vp 1416 const static int CONTENT_PADDING = 4; // container <--> content distance 4 vp 1417 const static int CONTAINER_BORDER_WIDTH = 1; // container border width 2 vp 1418 const static int CONTAINER_OUTER_RADIUS = 16; // container outer radius 16 vp 1419 const static int CONTAINER_INNER_RADIUS = 14; // container inner radius 14 vp 1420 1421 bool hasContainerWindow_ = false; // set to false as default, set by arkui 1422 float density = 2.0f; // The density default value is 2 1423 int outR = 32; // outer radius (int value) 1424 int inR = 28; // inner radius (int value) 1425 int bp = 10; // border width + padding (int value) 1426 int bt = 76; // border width + title (int value) 1427 }; 1428 1429 ContainerConfig containerConfig_; 1430 1431 bool startAnimationFinished_ = false; 1432 1433 // only used in hardware enabled pointer window, when gpu -> hardware composer 1434 bool isNodeDirtyInLastFrame_ = true; 1435 bool isNodeDirty_ = true; 1436 // used for hardware enabled nodes 1437 bool isHardwareEnabledNode_ = false; 1438 bool dynamicHardwareEnable_ = true; 1439 bool isFixRotationByUser_ = false; 1440 bool isInFixedRotation_ = false; 1441 RectI originalDstRect_; 1442 RectI originalSrcRect_; 1443 SelfDrawingNodeType selfDrawingType_ = SelfDrawingNodeType::DEFAULT; 1444 bool isCurrentFrameHardwareEnabled_ = false; 1445 bool isLastFrameHardwareEnabled_ = false; 1446 bool isLastFrameHwcEnabled_ = false; 1447 bool needCollectHwcNode_ = false; 1448 bool intersectByFilterInApp_ = false; 1449 bool calcRectInPrepare_ = false; 1450 bool hasSubNodeShouldPaint_ = false; 1451 // mark if this self-drawing node is forced not to use hardware composer 1452 // in case where this node's parent window node is occluded or is appFreeze, this variable will be marked true 1453 bool isHardwareForcedDisabled_ = false; 1454 bool isHardwareForcedDisabledByFilter_ = false; 1455 // For certain buffer format(YUV), dss restriction on src : srcRect % 2 == 0 1456 // To avoid switch between gpu and dss during sliding, we disable dss when srcHeight != bufferHeight 1457 bool isHardwareForcedDisabledBySrcRect_ = false; 1458 bool isHardwareDisabledByCache_ = false; 1459 float localZOrder_ = 0.0f; 1460 std::vector<WeakPtr> childHardwareEnabledNodes_; 1461 int32_t nodeCost_ = 0; 1462 1463 bool animateState_ = false; 1464 bool isRotating_ = false; 1465 bool isParentScaling_ = false; 1466 1467 bool needDrawAnimateProperty_ = false; 1468 bool prevVisible_ = false; 1469 bool isHardWareDisabledByReverse_ = false; 1470 1471 uint32_t processZOrder_ = -1; 1472 1473 // mark if this self-drawing node do not consume buffer when gpu -> hwc 1474 bool hwcDelayDirtyFlag_ = false; 1475 1476 std::shared_ptr<RSSurfaceHandler> surfaceHandler_; 1477 1478 // UIFirst 1479 int64_t uifirstStartTime_ = -1; 1480 uint32_t submittedSubThreadIndex_ = INT_MAX; 1481 std::atomic<CacheProcessStatus> cacheProcessStatus_ = CacheProcessStatus::WAITING; 1482 std::atomic<bool> isNeedSubmitSubThread_ = true; 1483 #ifdef USE_SURFACE_TEXTURE 1484 std::shared_ptr<RSSurfaceTexture> surfaceTexture_ {}; 1485 #endif 1486 bool isForeground_ = false; 1487 bool UIFirstIsPurge_ = false; 1488 // whether to wait uifirst first frame finished when buffer available callback invoked. 1489 std::atomic<bool> isWaitUifirstFirstFrame_ = false; 1490 1491 TreeStateChangeCallback treeStateChangeCallback_; 1492 RSBaseRenderNode::WeakPtr ancestorDisplayNode_; 1493 bool hasSharedTransitionNode_ = false; 1494 size_t lastFrameChildrenCnt_ = 0; 1495 // node only have translate and scale changes 1496 bool surfaceCacheContentStatic_ = false; 1497 1498 bool needDrawFocusChange_ = false; 1499 1500 std::atomic<bool> hasUnSubmittedOccludedDirtyRegion_ = false; 1501 RectI historyUnSubmittedOccludedDirtyRegion_; 1502 bool hasTransparentSurface_ = false; 1503 bool forceUIFirst_ = false; 1504 bool forceUIFirstChanged_ = false; 1505 Drawing::Matrix bufferRelMatrix_ = Drawing::Matrix(); 1506 1507 std::atomic<int32_t> ancoFlags_ = 0; 1508 static inline std::atomic<bool> ancoForceDoDirect_ = false; 1509 1510 bool isGpuOverDrawBufferOptimizeNode_ = false; 1511 Vector4f overDrawBufferNodeCornerRadius_; 1512 1513 std::map<NodeId, RSSurfaceRenderNode::WeakPtr> childSubSurfaceNodes_; 1514 bool isSubSurfaceNode_ = false; 1515 bool isNodeToBeCaptured_ = false; 1516 1517 bool doDirectComposition_ = true; 1518 bool isSkipDraw_ = false; 1519 bool needHidePrivacyContent_ = false; 1520 1521 bool isHardwareForcedByBackgroundAlpha_ = false; 1522 1523 bool arsrTag_ = true; 1524 1525 // UIExtension record, <UIExtension, hostAPP> 1526 inline static std::unordered_map<NodeId, NodeId> secUIExtensionNodes_ = {}; 1527 friend class SurfaceNodeCommandHelper; 1528 friend class RSUifirstManager; 1529 friend class RSUniRenderVisitor; 1530 friend class RSRenderNode; 1531 friend class RSRenderService; 1532 #ifdef RS_PROFILER_ENABLED 1533 friend class RSProfiler; 1534 #endif 1535 }; 1536 } // namespace Rosen 1537 } // namespace OHOS 1538 1539 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_SURFACE_RENDER_NODE_H 1540