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_RENDER_NODE_H 16 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_RENDER_NODE_H 17 18 #include <atomic> 19 #include <bitset> 20 #include <cstdint> 21 #include <functional> 22 #include <list> 23 #include <memory> 24 #include <mutex> 25 #include <unordered_map> 26 #include <unordered_set> 27 #include <variant> 28 #include <vector> 29 30 #include "animation/rs_animation_manager.h" 31 #include "animation/rs_frame_rate_range.h" 32 #include "common/rs_common_def.h" 33 #include "common/rs_macros.h" 34 #include "common/rs_rect.h" 35 #include "draw/surface.h" 36 #include "drawable/rs_drawable.h" 37 #include "drawable/rs_property_drawable.h" 38 #include "image/gpu_context.h" 39 #include "memory/rs_dfx_string.h" 40 #include "memory/rs_memory_snapshot.h" 41 #include "modifier/rs_render_modifier.h" 42 #include "pipeline/rs_dirty_region_manager.h" 43 #include "pipeline/rs_render_display_sync.h" 44 #include "pipeline/rs_paint_filter_canvas.h" 45 #include "pipeline/rs_render_content.h" 46 #include "pipeline/rs_single_frame_composer.h" 47 #include "property/rs_properties.h" 48 #include "drawable/rs_render_node_drawable_adapter.h" 49 50 namespace OHOS { 51 namespace Rosen { 52 namespace DrawableV2 { 53 class RSChildrenDrawable; 54 class RSRenderNodeDrawableAdapter; 55 class RSRenderNodeShadowDrawable; 56 } 57 class RSRenderParams; 58 class RSContext; 59 class RSNodeVisitor; 60 class RSCommand; 61 namespace NativeBufferUtils { 62 class VulkanCleanupHelper; 63 } 64 struct SharedTransitionParam; 65 66 struct CurFrameInfoDetail { 67 uint32_t curFramePrepareSeqNum = 0; 68 uint32_t curFramePostPrepareSeqNum = 0; 69 uint64_t curFrameVsyncId = 0; 70 bool curFrameSubTreeSkipped = false; 71 bool curFrameReverseChildren = false; 72 }; 73 74 class RSB_EXPORT RSRenderNode : public std::enable_shared_from_this<RSRenderNode> { 75 public: 76 // Used to check if hwc should enable for this selfdraw-surface 77 int32_t zOrderForCalcHwcNodeEnableByFilter_ = 0; 78 using WeakPtr = std::weak_ptr<RSRenderNode>; 79 using SharedPtr = std::shared_ptr<RSRenderNode>; 80 static inline constexpr RSRenderNodeType Type = RSRenderNodeType::RS_NODE; 81 std::atomic<int32_t> cacheCnt_ = -1; GetType()82 virtual RSRenderNodeType GetType() const 83 { 84 return Type; 85 } 86 87 explicit RSRenderNode(NodeId id, const std::weak_ptr<RSContext>& context = {}, bool isTextureExportNode = false); 88 explicit RSRenderNode(NodeId id, bool isOnTheTree, const std::weak_ptr<RSContext>& context = {}, 89 bool isTextureExportNode = false); 90 RSRenderNode(const RSRenderNode&) = delete; 91 RSRenderNode(const RSRenderNode&&) = delete; 92 RSRenderNode& operator=(const RSRenderNode&) = delete; 93 RSRenderNode& operator=(const RSRenderNode&&) = delete; 94 virtual ~RSRenderNode(); 95 96 void AddChild(SharedPtr child, int index = -1); 97 void SetContainBootAnimation(bool isContainBootAnimation); 98 99 virtual void SetBootAnimation(bool isBootAnimation); 100 virtual bool GetBootAnimation() const; 101 102 virtual bool GetGlobalPositionEnabled() const; 103 104 void MoveChild(SharedPtr child, int index); 105 void RemoveChild(SharedPtr child, bool skipTransition = false); 106 void ClearChildren(); 107 void RemoveFromTree(bool skipTransition = false); 108 109 // Add/RemoveCrossParentChild only used as: the child is under multiple parents(e.g. a window cross multi-screens) 110 void AddCrossParentChild(const SharedPtr& child, int32_t index = -1); 111 void RemoveCrossParentChild(const SharedPtr& child, const WeakPtr& newParent); 112 void SetIsCrossNode(bool isCrossNode); 113 114 // Only used in PC extend screen 115 void AddCrossScreenChild(const SharedPtr& child, NodeId cloneNodeId, int32_t index = -1, 116 bool autoClearCloneNode = false); 117 void RemoveCrossScreenChild(const SharedPtr& child); 118 void ClearCloneCrossNode(); 119 GetSourceCrossNode()120 WeakPtr GetSourceCrossNode() const 121 { 122 return sourceCrossNode_; 123 } 124 IsCloneCrossNode()125 bool IsCloneCrossNode() const 126 { 127 return isCloneCrossNode_; 128 } 129 SetCurCloneNodeParent(SharedPtr node)130 void SetCurCloneNodeParent(SharedPtr node) 131 { 132 curCloneNodeParent_ = node; 133 } GetCurCloneNodeParent()134 WeakPtr GetCurCloneNodeParent() const 135 { 136 return curCloneNodeParent_; 137 } 138 139 virtual void CollectSurface(const std::shared_ptr<RSRenderNode>& node, 140 std::vector<RSRenderNode::SharedPtr>& vec, 141 bool isUniRender, 142 bool onlyFirstLevel); 143 virtual void CollectSelfDrawingChild(const std::shared_ptr<RSRenderNode>& node, std::vector<NodeId>& vec); 144 virtual void QuickPrepare(const std::shared_ptr<RSNodeVisitor>& visitor); 145 void PrepareSelfNodeForApplyModifiers(); 146 void PrepareChildrenForApplyModifiers(); 147 // if subtree dirty or child filter need prepare 148 virtual bool IsSubTreeNeedPrepare(bool filterInGlobal, bool isOccluded = false); 149 virtual void Prepare(const std::shared_ptr<RSNodeVisitor>& visitor); 150 virtual void Process(const std::shared_ptr<RSNodeVisitor>& visitor); 151 bool SetAccumulatedClipFlag(bool clipChange); GetAccumulatedClipFlagChange()152 bool GetAccumulatedClipFlagChange() const 153 { 154 return isAccumulatedClipFlagChanged_; 155 } 156 bool IsDirty() const; 157 bool IsSubTreeDirty() const; 158 void SetSubTreeDirty(bool val); 159 void SetParentSubTreeDirty(); 160 // attention: current all base node's dirty ops causing content dirty 161 // if there is any new dirty op, check it 162 bool IsContentDirty() const; 163 void SetContentDirty(); 164 void ResetIsOnlyBasicGeoTransform(); 165 bool IsOnlyBasicGeoTransform() const; 166 void ForceMergeSubTreeDirtyRegion(RSDirtyRegionManager& dirtyManager, const RectI& clipRect); 167 void SubTreeSkipPrepare(RSDirtyRegionManager& dirtymanager, bool isDirty, bool accumGeoDirty, 168 const RectI& clipRect); LastFrameSubTreeSkipped()169 inline bool LastFrameSubTreeSkipped() const 170 { 171 return lastFrameSubTreeSkipped_; 172 } 173 GetParent()174 inline WeakPtr GetParent() const 175 { 176 return parent_; 177 } 178 GetId()179 inline NodeId GetId() const 180 { 181 return id_; 182 } 183 184 bool IsFirstLevelNode(); 185 void UpdateChildSubSurfaceNode(); 186 bool GetAbsMatrixReverse(const RSRenderNode& rootNode, Drawing::Matrix& absMatrix); 187 188 // flag: isOnTheTree; instanceRootNodeId: displaynode or leash/appnode attached to 189 // firstLevelNodeId: surfacenode for uiFirst to assign task; cacheNodeId: drawing cache rootnode attached to 190 virtual void SetIsOnTheTree(bool flag, NodeId instanceRootNodeId = INVALID_NODEID, 191 NodeId firstLevelNodeId = INVALID_NODEID, NodeId cacheNodeId = INVALID_NODEID, 192 NodeId uifirstRootNodeId = INVALID_NODEID, NodeId displayNodeId = INVALID_NODEID); SetIsOntheTreeOnlyFlag(bool flag)193 void SetIsOntheTreeOnlyFlag(bool flag) 194 { 195 SetIsOnTheTree(flag, instanceRootNodeId_, firstLevelNodeId_, drawingCacheRootId_, 196 uifirstRootNodeId_, displayNodeId_); 197 } IsOnTheTree()198 inline bool IsOnTheTree() const 199 { 200 return isOnTheTree_; 201 } 202 IsNewOnTree()203 inline bool IsNewOnTree() const 204 { 205 return isNewOnTree_; 206 } 207 GetIsTextureExportNode()208 inline bool GetIsTextureExportNode() const 209 { 210 return isTextureExportNode_; 211 } 212 GetFilterRegion()213 inline RectI GetFilterRegion() const 214 { 215 return filterRegion_; 216 } 217 IsWaitSync()218 inline bool IsWaitSync() const 219 { 220 return waitSync_; 221 } 222 223 using ChildrenListSharedPtr = std::shared_ptr<const std::vector<std::shared_ptr<RSRenderNode>>>; 224 // return children and disappeared children, not guaranteed to be sorted by z-index 225 ChildrenListSharedPtr GetChildren() const; 226 // return children and disappeared children, sorted by z-index 227 virtual ChildrenListSharedPtr GetSortedChildren() const; 228 uint32_t GetChildrenCount() const; 229 std::shared_ptr<RSRenderNode> GetFirstChild() const; 230 231 void DumpTree(int32_t depth, std::string& ou) const; 232 void DumpNodeInfo(DfxString& log); 233 234 virtual bool HasDisappearingTransition(bool recursive = true) const; 235 236 void SetTunnelHandleChange(bool change); 237 bool GetTunnelHandleChange() const; 238 239 void SetChildHasSharedTransition(bool val); 240 bool ChildHasSharedTransition() const; 241 242 // type-safe reinterpret_cast 243 template<typename T> IsInstanceOf()244 bool IsInstanceOf() const 245 { 246 constexpr auto targetType = static_cast<uint32_t>(T::Type); 247 return (static_cast<uint32_t>(GetType()) & targetType) == targetType; 248 } 249 template<typename T> ReinterpretCast(std::shared_ptr<RSRenderNode> node)250 static std::shared_ptr<T> ReinterpretCast(std::shared_ptr<RSRenderNode> node) 251 { 252 return node ? node->ReinterpretCastTo<T>() : nullptr; 253 } 254 template<typename T> ReinterpretCastTo()255 std::shared_ptr<T> ReinterpretCastTo() 256 { 257 return (IsInstanceOf<T>()) ? std::static_pointer_cast<T>(shared_from_this()) : nullptr; 258 } 259 template<typename T> ReinterpretCastTo()260 std::shared_ptr<const T> ReinterpretCastTo() const 261 { 262 return (IsInstanceOf<T>()) ? std::static_pointer_cast<const T>(shared_from_this()) : nullptr; 263 } 264 265 bool HasChildrenOutOfRect() const; 266 void UpdateChildrenOutOfRectFlag(bool flag); 267 268 void ResetHasRemovedChild(); 269 bool HasRemovedChild() const; ResetChildrenRect()270 inline void ResetChildrenRect() 271 { 272 childrenRect_.Clear(); 273 } 274 RectI GetChildrenRect() const; 275 RectI GetRemovedChildrenRect() const; 276 277 bool ChildHasVisibleFilter() const; 278 void SetChildHasVisibleFilter(bool val); 279 bool ChildHasVisibleEffect() const; 280 void SetChildHasVisibleEffect(bool val); 281 const std::vector<NodeId>& GetVisibleFilterChild() const; 282 void UpdateVisibleFilterChild(RSRenderNode& childNode); 283 const std::unordered_set<NodeId>& GetVisibleEffectChild() const; 284 void UpdateVisibleEffectChild(RSRenderNode& childNode); 285 GetInstanceRootNodeId()286 inline NodeId GetInstanceRootNodeId() const 287 { 288 return instanceRootNodeId_; 289 } 290 291 const std::shared_ptr<RSRenderNode> GetInstanceRootNode() const; GetFirstLevelNodeId()292 inline NodeId GetFirstLevelNodeId() const 293 { 294 return firstLevelNodeId_; 295 } 296 const std::shared_ptr<RSRenderNode> GetFirstLevelNode() const; 297 GetPreFirstLevelNodeIdSet()298 inline const std::set<NodeId>& GetPreFirstLevelNodeIdSet() 299 { 300 return preFirstLevelNodeIdSet_; 301 } 302 GetMutablePreFirstLevelNodeIdSet()303 inline std::set<NodeId>& GetMutablePreFirstLevelNodeIdSet() 304 { 305 return preFirstLevelNodeIdSet_; 306 } 307 AddPreFirstLevelNodeIdSet(const std::set<NodeId> & preSet)308 inline void AddPreFirstLevelNodeIdSet(const std::set<NodeId>& preSet) 309 { 310 preFirstLevelNodeIdSet_.insert(preSet.begin(), preSet.end()); 311 } 312 313 // only use for ARKTS_CARD GetUifirstRootNodeId()314 inline NodeId GetUifirstRootNodeId() const 315 { 316 return uifirstRootNodeId_; 317 } 318 const std::shared_ptr<RSRenderNode> GetUifirstRootNode() const; 319 void UpdateTreeUifirstRootNodeId(NodeId id); 320 321 // reset accumulated vals before traverses children 322 void ResetChildRelevantFlags(); 323 // accumulate all valid children's area 324 void UpdateChildrenRect(const RectI& subRect); 325 void UpdateCurCornerRadius(Vector4f& curCornerRadius); 326 void SetDirty(bool forceAddToActiveList = false); 327 void SetBlendWithBackground(bool isBlendWithBackgroun); 328 bool IsBlendWithBackground() const; 329 AddDirtyType(RSModifierType type)330 virtual void AddDirtyType(RSModifierType type) 331 { 332 dirtyTypes_.set(static_cast<int>(type), true); 333 } 334 335 std::tuple<bool, bool, bool> Animate(int64_t timestamp, int64_t period = 0, bool isDisplaySyncEnabled = false); 336 337 bool IsClipBound() const; 338 // clipRect has value in UniRender when calling PrepareCanvasRenderNode, else it is nullopt 339 const RectF& GetSelfDrawRect() const; 340 const RectI& GetAbsDrawRect() const; 341 void UpdateAbsDrawRect(); 342 343 void ResetChangeState(); 344 void NodeDrawLargeAreaBlur(std::pair<bool, bool>& nodeDrawLargeAreaBlur); 345 bool UpdateDrawRectAndDirtyRegion(RSDirtyRegionManager& dirtyManager, bool accumGeoDirty, const RectI& clipRect, 346 const Drawing::Matrix& parentSurfaceMatrix); 347 void UpdateDirtyRegionInfoForDFX(RSDirtyRegionManager& dirtyManager); 348 void UpdateSubTreeSkipDirtyForDFX(RSDirtyRegionManager& dirtyManager, const RectI& rect); 349 // update node's local draw region (based on node itself, including childrenRect) 350 bool UpdateLocalDrawRect(); 351 352 bool Update(RSDirtyRegionManager& dirtyManager, const std::shared_ptr<RSRenderNode>& parent, bool parentDirty, 353 std::optional<RectI> clipRect = std::nullopt); GetContextClipRegion()354 virtual std::optional<Drawing::Rect> GetContextClipRegion() const { return std::nullopt; } 355 356 RSProperties& GetMutableRenderProperties(); GetRenderProperties()357 inline const RSProperties& GetRenderProperties() const 358 { 359 return renderContent_->GetRenderProperties(); 360 } 361 void UpdateRenderStatus(RectI& dirtyRegion, bool isPartialRenderEnabled); 362 bool IsRenderUpdateIgnored() const; 363 364 // used for animation test 365 RSAnimationManager& GetAnimationManager(); 366 367 void ApplyBoundsGeometry(RSPaintFilterCanvas& canvas); 368 void ApplyAlpha(RSPaintFilterCanvas& canvas); 369 virtual void ProcessTransitionBeforeChildren(RSPaintFilterCanvas& canvas); 370 virtual void ProcessAnimatePropertyBeforeChildren(RSPaintFilterCanvas& canvas, bool includeProperty = true) {} 371 virtual void ProcessRenderBeforeChildren(RSPaintFilterCanvas& canvas); 372 ProcessRenderContents(RSPaintFilterCanvas & canvas)373 virtual void ProcessRenderContents(RSPaintFilterCanvas& canvas) {} 374 375 virtual void ProcessTransitionAfterChildren(RSPaintFilterCanvas& canvas); ProcessAnimatePropertyAfterChildren(RSPaintFilterCanvas & canvas)376 virtual void ProcessAnimatePropertyAfterChildren(RSPaintFilterCanvas& canvas) {} 377 virtual void ProcessRenderAfterChildren(RSPaintFilterCanvas& canvas); 378 379 void RenderTraceDebug() const; ShouldPaint()380 inline bool ShouldPaint() const 381 { 382 return shouldPaint_; 383 } 384 GetInnerAbsDrawRect()385 inline RectI GetInnerAbsDrawRect() const noexcept 386 { 387 return innerAbsDrawRect_; 388 } 389 390 // dirty rect of current frame after update dirty, last frame before update 391 RectI GetOldDirty() const; 392 // dirty rect in display of current frame after update dirty, last frame before update 393 RectI GetOldDirtyInSurface() const; 394 // clip rect of last frame before post prepare, current frame after post prepare 395 RectI GetOldClipRect() const; 396 397 bool IsDirtyRegionUpdated() const; 398 void CleanDirtyRegionUpdated(); 399 400 void AddModifier(const std::shared_ptr<RSRenderModifier>& modifier, bool isSingleFrameComposer = false); 401 void RemoveModifier(const PropertyId& id); 402 void RemoveAllModifiers(); 403 std::shared_ptr<RSRenderModifier> GetModifier(const PropertyId& id); 404 405 size_t GetAllModifierSize(); 406 407 bool IsShadowValidLastFrame() const; SetShadowValidLastFrame(bool isShadowValidLastFrame)408 void SetShadowValidLastFrame(bool isShadowValidLastFrame) 409 { 410 isShadowValidLastFrame_ = isShadowValidLastFrame; 411 } 412 413 // update parent's children rect including childRect and itself 414 void MapAndUpdateChildrenRect(); 415 void UpdateSubTreeInfo(const RectI& clipRect); 416 void UpdateParentChildrenRect(std::shared_ptr<RSRenderNode> parentNode) const; 417 418 void SetStaticCached(bool isStaticCached); 419 virtual bool IsStaticCached() const; 420 void SetNodeName(const std::string& nodeName); 421 const std::string& GetNodeName() const; 422 // store prev surface subtree's must-renewed info that need prepare 423 virtual void StoreMustRenewedInfo(); 424 bool HasMustRenewedInfo() const; 425 bool HasSubSurface() const; 426 427 bool NeedInitCacheSurface(); 428 bool NeedInitCacheCompletedSurface(); 429 bool IsPureContainer() const; 430 bool IsContentNode() const; 431 GetDrawCmdModifiers()432 inline const RSRenderContent::DrawCmdContainer& GetDrawCmdModifiers() const 433 { 434 return renderContent_->drawCmdModifiers_; 435 } 436 437 using ClearCacheSurfaceFunc = 438 std::function<void(std::shared_ptr<Drawing::Surface>&&, 439 std::shared_ptr<Drawing::Surface>&&, uint32_t, uint32_t)>; 440 void InitCacheSurface(Drawing::GPUContext* grContext, ClearCacheSurfaceFunc func = nullptr, 441 uint32_t threadIndex = UNI_MAIN_THREAD_INDEX); 442 443 Vector2f GetOptionalBufferSize() const; 444 GetCacheSurface()445 std::shared_ptr<Drawing::Surface> GetCacheSurface() const 446 { 447 std::scoped_lock<std::recursive_mutex> lock(surfaceMutex_); 448 return cacheSurface_; 449 } 450 451 // use for uni render visitor 452 std::shared_ptr<Drawing::Surface> GetCacheSurface(uint32_t threadIndex, bool needCheckThread, 453 bool releaseAfterGet = false); 454 455 void UpdateCompletedCacheSurface(); 456 void SetTextureValidFlag(bool isValid); 457 std::shared_ptr<Drawing::Surface> GetCompletedCacheSurface(uint32_t threadIndex = UNI_MAIN_THREAD_INDEX, 458 bool needCheckThread = true, bool releaseAfterGet = false); 459 void ClearCacheSurfaceInThread(); 460 void ClearCacheSurface(bool isClearCompletedCacheSurface = true); 461 bool IsCacheCompletedSurfaceValid() const; 462 bool IsCacheSurfaceValid() const; 463 464 #if defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK) 465 void UpdateBackendTexture(); 466 #endif 467 468 void DrawCacheSurface(RSPaintFilterCanvas& canvas, uint32_t threadIndex = UNI_MAIN_THREAD_INDEX, 469 bool isUIFirst = false); 470 471 void SetCacheType(CacheType cacheType); 472 CacheType GetCacheType() const; 473 SetCacheSurfaceNeedUpdated(bool isCacheSurfaceNeedUpdate)474 void SetCacheSurfaceNeedUpdated(bool isCacheSurfaceNeedUpdate) 475 { 476 isCacheSurfaceNeedUpdate_ = isCacheSurfaceNeedUpdate; 477 } 478 GetCacheSurfaceNeedUpdated()479 bool GetCacheSurfaceNeedUpdated() const 480 { 481 return isCacheSurfaceNeedUpdate_; 482 } 483 484 int GetShadowRectOffsetX() const; 485 int GetShadowRectOffsetY() const; 486 487 void SetDrawingCacheType(RSDrawingCacheType cacheType); 488 RSDrawingCacheType GetDrawingCacheType() const; 489 void ResetFilterRectsInCache(const std::unordered_set<NodeId>& curRects); 490 void GetFilterRectsInCache(std::unordered_map<NodeId, std::unordered_set<NodeId>>& allRects) const; 491 bool IsFilterRectsInCache() const; 492 void SetDrawingCacheChanged(bool cacheChanged); 493 bool GetDrawingCacheChanged() const; 494 void ResetDrawingCacheNeedUpdate(); 495 void SetVisitedCacheRootIds(const std::unordered_set<NodeId>& visitedNodes); 496 const std::unordered_set<NodeId>& GetVisitedCacheRootIds() const; 497 // manage cache root nodeid 498 void SetDrawingCacheRootId(NodeId id); 499 NodeId GetDrawingCacheRootId() const; 500 // record cache geodirty for preparation optimization 501 void SetGeoUpdateDelay(bool val); 502 void ResetGeoUpdateDelay(); 503 bool GetGeoUpdateDelay() const; 504 bool HasAnimation() const; GetCurFrameHasAnimation()505 bool GetCurFrameHasAnimation() const 506 { 507 return curFrameHasAnimation_; 508 } SetCurFrameHasAnimation(bool b)509 void SetCurFrameHasAnimation(bool b) 510 { 511 curFrameHasAnimation_ = b; 512 } 513 514 float GetHDRBrightness() const; 515 bool HasFilter() const; 516 void SetHasFilter(bool hasFilter); GetCommandExecuted()517 bool GetCommandExecuted() const 518 { 519 return commandExecuted_; 520 } 521 SetCommandExecuted(bool commandExecuted)522 void SetCommandExecuted(bool commandExecuted) 523 { 524 commandExecuted_ = commandExecuted; 525 } 526 527 std::recursive_mutex& GetSurfaceMutex() const; 528 529 bool HasHardwareNode() const; 530 void SetHasHardwareNode(bool hasHardwareNode); 531 532 bool HasAbilityComponent() const; 533 void SetHasAbilityComponent(bool hasAbilityComponent); 534 535 uint32_t GetCacheSurfaceThreadIndex() const; 536 537 uint32_t GetCompletedSurfaceThreadIndex() const; 538 539 bool IsMainThreadNode() const; 540 void SetIsMainThreadNode(bool isMainThreadNode); 541 542 bool IsScale() const; 543 void SetIsScale(bool isScale); 544 545 bool IsScaleInPreFrame() const; 546 void SetIsScaleInPreFrame(bool isScale); 547 548 void SetPriority(NodePriorityType priority); 549 NodePriorityType GetPriority(); 550 551 bool IsAncestorDirty() const; 552 void SetIsAncestorDirty(bool isAncestorDirty); 553 554 bool IsParentLeashWindow() const; 555 void SetParentLeashWindow(); 556 557 bool IsParentScbScreen() const; 558 void SetParentScbScreen(); 559 560 bool HasCachedTexture() const; 561 562 void SetDrawRegion(const std::shared_ptr<RectF>& rect); 563 const std::shared_ptr<RectF>& GetDrawRegion() const; 564 void SetOutOfParent(OutOfParentType outOfParent); 565 OutOfParentType GetOutOfParent() const; 566 567 void UpdateEffectRegion(std::optional<Drawing::RectI>& region, bool isForced = false); MarkFilterHasEffectChildren()568 virtual void MarkFilterHasEffectChildren() {}; OnFilterCacheStateChanged()569 virtual void OnFilterCacheStateChanged() {}; 570 571 // for blur filter cache 572 virtual void CheckBlurFilterCacheNeedForceClearOrSave(bool rotationChanged = false, 573 bool rotationStatusChanged = false); 574 void UpdateLastFilterCacheRegion(); 575 void UpdateFilterRegionInSkippedSubTree(RSDirtyRegionManager& dirtyManager, 576 const RSRenderNode& subTreeRoot, RectI& filterRect, const RectI& clipRect); 577 void MarkFilterStatusChanged(bool isForeground, bool isFilterRegionChanged); 578 void UpdateFilterCacheWithBackgroundDirty(); 579 virtual void UpdateFilterCacheWithBelowDirty(RSDirtyRegionManager& dirtyManager, bool isForeground = false); 580 virtual void UpdateFilterCacheWithSelfDirty(); 581 bool IsBackgroundInAppOrNodeSelfDirty() const; 582 void PostPrepareForBlurFilterNode(RSDirtyRegionManager& dirtyManager, bool needRequestNextVsync); 583 #ifdef RS_ENABLE_GPU 584 void CheckFilterCacheAndUpdateDirtySlots( 585 std::shared_ptr<DrawableV2::RSFilterDrawable>& filterDrawable, RSDrawableSlot slot); 586 #endif 587 bool IsFilterCacheValid() const; 588 bool IsAIBarFilter() const; 589 bool IsAIBarFilterCacheValid() const; 590 void MarkForceClearFilterCacheWithInvisible(); 591 592 void CheckGroupableAnimation(const PropertyId& id, bool isAnimAdd); 593 bool IsForcedDrawInGroup() const; 594 bool IsSuggestedDrawInGroup() const; 595 void CheckDrawingCacheType(); HasCacheableAnim()596 bool HasCacheableAnim() const { return hasCacheableAnim_; } 597 enum NodeGroupType : uint8_t { 598 NONE = 0, 599 GROUPED_BY_ANIM = 1, 600 GROUPED_BY_UI = GROUPED_BY_ANIM << 1, 601 GROUPED_BY_USER = GROUPED_BY_UI << 1, 602 GROUPED_BY_FOREGROUND_FILTER = GROUPED_BY_USER << 1, 603 GROUP_TYPE_BUTT = GROUPED_BY_FOREGROUND_FILTER, 604 }; 605 void MarkNodeGroup(NodeGroupType type, bool isNodeGroup, bool includeProperty); 606 void MarkForegroundFilterCache(); 607 NodeGroupType GetNodeGroupType(); 608 bool IsNodeGroupIncludeProperty() const; 609 610 void MarkNodeSingleFrameComposer(bool isNodeSingleFrameComposer, pid_t pid = 0); 611 virtual bool GetNodeIsSingleFrameComposer() const; 612 613 // mark cross node in physical extended screen model 614 bool IsCrossNode() const; 615 616 // mark stable node 617 void OpincSetInAppStateStart(bool& unchangeMarkInApp); 618 void OpincSetInAppStateEnd(bool& unchangeMarkInApp); 619 void OpincQuickMarkStableNode(bool& unchangeMarkInApp, bool& unchangeMarkEnable, bool isAccessibilityChanged); 620 bool IsOpincUnchangeState(); 621 std::string QuickGetNodeDebugInfo(); 622 623 // mark support node 624 void OpincUpdateNodeSupportFlag(bool supportFlag); OpincGetNodeSupportFlag()625 virtual bool OpincGetNodeSupportFlag() 626 { 627 return isOpincNodeSupportFlag_; 628 } 629 bool IsMarkedRenderGroup(); 630 bool OpincForcePrepareSubTree(bool autoCacheEnable); 631 632 // sync to drawable 633 void OpincUpdateRootFlag(bool& unchangeMarkEnable); 634 bool OpincGetRootFlag() const; 635 636 // arkui mark 637 void MarkSuggestOpincNode(bool isOpincNode, bool isNeedCalculate); 638 bool GetSuggestOpincNode() const; 639 640 ///////////////////////////////////////////// 641 642 void SetSharedTransitionParam(const std::shared_ptr<SharedTransitionParam>& sharedTransitionParam); 643 const std::shared_ptr<SharedTransitionParam>& GetSharedTransitionParam() const; 644 645 void SetGlobalAlpha(float alpha); 646 float GetGlobalAlpha() const; OnAlphaChanged()647 virtual void OnAlphaChanged() {} 648 GetGlobalCornerRadius()649 inline const Vector4f& GetGlobalCornerRadius() noexcept 650 { 651 return globalCornerRadius_; 652 } 653 SetGlobalCornerRadius(const Vector4f & globalCornerRadius)654 inline void SetGlobalCornerRadius(const Vector4f& globalCornerRadius) noexcept 655 { 656 globalCornerRadius_ = globalCornerRadius; 657 } 658 659 void ActivateDisplaySync(); InActivateDisplaySync()660 inline void InActivateDisplaySync() 661 { 662 displaySync_ = nullptr; 663 } 664 void UpdateDisplaySyncRange(); 665 666 void MarkNonGeometryChanged(); 667 668 void ApplyModifier(RSModifierContext& context, std::shared_ptr<RSRenderModifier> modifier); 669 void ApplyModifiers(); 670 void ApplyPositionZModifier(); 671 virtual void UpdateRenderParams(); 672 void SetCrossNodeOffScreenStatus(CrossNodeOffScreenRenderDebugType isCrossNodeOffscreenOn_); 673 void UpdateDrawingCacheInfoBeforeChildren(bool isScreenRotation); 674 void UpdateDrawingCacheInfoAfterChildren(); 675 676 virtual RectI GetFilterRect() const; 677 void CalVisibleFilterRect(const std::optional<RectI>& clipRect); 678 void SetIsUsedBySubThread(bool isUsedBySubThread); 679 bool GetIsUsedBySubThread() const; 680 681 void SetLastIsNeedAssignToSubThread(bool lastIsNeedAssignToSubThread); 682 bool GetLastIsNeedAssignToSubThread() const; 683 SetIsTextureExportNode(bool isTextureExportNode)684 void SetIsTextureExportNode(bool isTextureExportNode) 685 { 686 isTextureExportNode_ = isTextureExportNode; 687 } 688 689 #ifdef RS_ENABLE_STACK_CULLING 690 void SetFullSurfaceOpaqueMarks(const std::shared_ptr<RSRenderNode> curSurfaceNodeParam); 691 void SetSubNodesCovered(); 692 void ResetSubNodesCovered(); 693 bool isFullSurfaceOpaquCanvasNode_ = false; 694 bool hasChildFullSurfaceOpaquCanvasNode_ = false; 695 bool isCoveredByOtherNode_ = false; 696 #define MAX_COLD_DOWN_NUM 20 697 int32_t coldDownCounter_ = 0; 698 #endif 699 700 const std::shared_ptr<RSRenderContent> GetRenderContent() const; 701 702 void MarkParentNeedRegenerateChildren() const; 703 ResetChildUifirstSupportFlag()704 void ResetChildUifirstSupportFlag() 705 { 706 isChildSupportUifirst_ = true; 707 } 708 UpdateChildUifirstSupportFlag(bool b)709 void UpdateChildUifirstSupportFlag(bool b) 710 { 711 isChildSupportUifirst_ = isChildSupportUifirst_ && b; 712 } 713 714 virtual bool GetUifirstSupportFlag(); 715 MergeOldDirtyRect()716 virtual void MergeOldDirtyRect() 717 { 718 return; 719 } 720 #ifdef RS_ENABLE_GPU 721 std::unique_ptr<RSRenderParams>& GetStagingRenderParams(); 722 723 // Deprecated! Do not use this interface. 724 // This interface has crash risks and will be deleted in later versions. 725 const std::unique_ptr<RSRenderParams>& GetRenderParams() const; 726 #endif 727 void UpdatePointLightDirtySlot(); 728 void AccmulateDirtyInOcclusion(bool isOccluded); 729 void RecordCurDirtyStatus(); 730 void AccmulateDirtyStatus(); 731 void ResetAccmulateDirtyStatus(); 732 void RecordCurDirtyTypes(); 733 void AccmulateDirtyTypes(); 734 void ResetAccmulateDirtyTypes(); 735 void SetUifirstSyncFlag(bool needSync); SetUifirstSkipPartialSync(bool skip)736 void SetUifirstSkipPartialSync(bool skip) 737 { 738 uifirstSkipPartialSync_ = skip; 739 } 740 SetForceUpdateByUifirst(bool b)741 void SetForceUpdateByUifirst(bool b) 742 { 743 forceUpdateByUifirst_ = b; 744 } 745 GetForceUpdateByUifirst()746 bool GetForceUpdateByUifirst() const 747 { 748 return forceUpdateByUifirst_; 749 } 750 GetLastFrameUifirstFlag()751 MultiThreadCacheType GetLastFrameUifirstFlag() 752 { 753 return lastFrameUifirstFlag_; 754 } 755 SetLastFrameUifirstFlag(MultiThreadCacheType b)756 void SetLastFrameUifirstFlag(MultiThreadCacheType b) 757 { 758 lastFrameUifirstFlag_ = b; 759 } 760 SkipSync()761 void SkipSync() 762 { 763 OnSkipSync(); 764 } Sync()765 void Sync() 766 { 767 OnSync(); 768 } 769 void AddToPendingSyncList(); GetContext()770 const std::weak_ptr<RSContext> GetContext() const 771 { 772 return context_; 773 } 774 775 // will be abandoned 776 void MarkUifirstNode(bool isUifirstNode); 777 // Mark uifirst leash node 778 void MarkUifirstNode(bool isForceFlag, bool isUifirstEnable); 779 bool GetUifirstNodeForceFlag() const; 780 781 void SetUIFirstSwitch(RSUIFirstSwitch uiFirstSwitch); 782 RSUIFirstSwitch GetUIFirstSwitch() const; 783 784 void SetOccludedStatus(bool occluded); 785 const RectI GetFilterCachedRegion() const; EffectNodeShouldPaint()786 virtual bool EffectNodeShouldPaint() const { return true; }; FirstFrameHasEffectChildren()787 virtual bool FirstFrameHasEffectChildren() const { return false; } MarkClearFilterCacheIfEffectChildrenChanged()788 virtual void MarkClearFilterCacheIfEffectChildrenChanged() {} 789 bool HasBlurFilter() const; 790 void SetChildrenHasSharedTransition(bool hasSharedTransition); SkipFrame(uint32_t refreshRate,uint32_t skipFrameInterval)791 virtual bool SkipFrame(uint32_t refreshRate, uint32_t skipFrameInterval) { return false; } 792 void RemoveChildFromFulllist(NodeId nodeId); 793 void SetStartingWindowFlag(bool startingFlag); GetStartingWindowFlag()794 bool GetStartingWindowFlag() const 795 { 796 return startingWindowFlag_; 797 } 798 void SetChildrenHasUIExtension(bool SetChildrenHasUIExtension); ChildrenHasUIExtension()799 bool ChildrenHasUIExtension() const 800 { 801 return childrenHasUIExtension_; 802 } 803 804 // temporary used for dfx/surfaceHandler/canvas drawing render node GetRenderDrawable()805 DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr GetRenderDrawable() const 806 { 807 return renderDrawable_; 808 } 809 void MarkBlurIntersectWithDRM(bool intersectWithDRM, bool isDark); GetIsFullChildrenListValid()810 bool GetIsFullChildrenListValid() const 811 { 812 return isFullChildrenListValid_; 813 } 814 GetAbilityState()815 virtual RSSurfaceNodeAbilityState GetAbilityState() const { return RSSurfaceNodeAbilityState::FOREGROUND; } 816 GetPreparedDisplayOffsetX()817 int32_t GetPreparedDisplayOffsetX() const 818 { 819 return preparedDisplayOffsetX_; 820 } SetPreparedDisplayOffsetX(int32_t offsetX)821 void SetPreparedDisplayOffsetX(int32_t offsetX) 822 { 823 preparedDisplayOffsetX_ = offsetX; 824 } GetPreparedDisplayOffsetY()825 int32_t GetPreparedDisplayOffsetY() const 826 { 827 return preparedDisplayOffsetY_; 828 } SetPreparedDisplayOffsetY(int32_t offsetY)829 void SetPreparedDisplayOffsetY(int32_t offsetY) 830 { 831 preparedDisplayOffsetY_ = offsetY; 832 } IsFirstLevelCrossNode()833 bool IsFirstLevelCrossNode() const 834 { 835 return isFirstLevelCrossNode_; 836 } SetFirstLevelCrossNode(bool isFirstLevelCrossNode)837 void SetFirstLevelCrossNode(bool isFirstLevelCrossNode) 838 { 839 isFirstLevelCrossNode_ = isFirstLevelCrossNode; 840 } 841 void SetHdrNum(bool flag, NodeId instanceRootNodeId); 842 SetIsAccessibilityConfigChanged(bool isAccessibilityConfigChanged)843 void SetIsAccessibilityConfigChanged(bool isAccessibilityConfigChanged) 844 { 845 isAccessibilityConfigChanged_ = isAccessibilityConfigChanged; 846 } 847 IsAccessibilityConfigChanged()848 bool IsAccessibilityConfigChanged() const 849 { 850 return isAccessibilityConfigChanged_; 851 } 852 GetDisplayNodeId()853 NodeId GetDisplayNodeId() const 854 { 855 return displayNodeId_; 856 } 857 858 // recursive update subSurfaceCnt 859 void UpdateSubSurfaceCnt(int updateCnt); 860 861 void ProcessBehindWindowOnTreeStateChanged(); 862 void ProcessBehindWindowAfterApplyModifiers(); 863 void UpdateDrawableBehindWindow(); NeedUpdateDrawableBehindWindow()864 virtual bool NeedUpdateDrawableBehindWindow() const { return false; } NeedDrawBehindWindow()865 virtual bool NeedDrawBehindWindow() const { return false; } AddChildBlurBehindWindow(NodeId id)866 virtual void AddChildBlurBehindWindow(NodeId id) {} RemoveChildBlurBehindWindow(NodeId id)867 virtual void RemoveChildBlurBehindWindow(NodeId id) {} CalDrawBehindWindowRegion()868 virtual void CalDrawBehindWindowRegion() {} GetBehindWindowRegion()869 virtual RectI GetBehindWindowRegion() const { return {}; }; 870 SetAbsRotation(float degree)871 void SetAbsRotation(float degree) 872 { 873 absRotation_ = degree; 874 } 875 GetAbsRotation()876 float GetAbsRotation() const 877 { 878 return absRotation_; 879 } 880 GetCurFrameInfoDetail()881 CurFrameInfoDetail& GetCurFrameInfoDetail() { return curFrameInfoDetail_; } 882 883 bool HasUnobscuredUEC() const; 884 void SetHasUnobscuredUEC(); 885 886 protected: 887 // only be called in node's constructor if it's generated by render service 888 static NodeId GenerateId(); 889 OnApplyModifiers()890 virtual void OnApplyModifiers() {} 891 void SetOldDirtyInSurface(RectI oldDirtyInSurface); 892 893 enum class NodeDirty { 894 CLEAN = 0, 895 DIRTY, 896 }; SetClean()897 inline void SetClean() 898 { 899 isNewOnTree_ = false; 900 isContentDirty_ = false; 901 dirtyStatus_ = NodeDirty::CLEAN; 902 } 903 904 static void DumpNodeType(RSRenderNodeType nodeType, std::string& out); 905 906 void DumpSubClassNode(std::string& out) const; 907 void DumpDrawCmdModifiers(std::string& out) const; 908 void DumpModifiers(std::string& out) const; 909 910 virtual void OnTreeStateChanged(); 911 void AddSubSurfaceUpdateInfo(SharedPtr curParent, SharedPtr preParent); 912 913 static void SendCommandFromRT(std::unique_ptr<RSCommand>& command, NodeId nodeId); 914 void AddGeometryModifier(const std::shared_ptr<RSRenderModifier>& modifier); 915 916 virtual void InitRenderParams(); 917 virtual void OnSync(); 918 virtual void OnSkipSync(); ClearResource()919 virtual void ClearResource() {}; ClearNeverOnTree()920 virtual void ClearNeverOnTree() {}; 921 922 void AddUIExtensionChild(SharedPtr child); 923 void MoveUIExtensionChild(SharedPtr child); 924 void RemoveUIExtensionChild(SharedPtr child); 925 bool NeedRoutedBasedOnUIExtension(SharedPtr child); 926 927 void UpdateDrawableVecV2(); 928 void ClearDrawableVec2(); 929 DrawPropertyDrawable(RSPropertyDrawableSlot slot,RSPaintFilterCanvas & canvas)930 inline void DrawPropertyDrawable(RSPropertyDrawableSlot slot, RSPaintFilterCanvas& canvas) 931 { 932 renderContent_->DrawPropertyDrawable(slot, canvas); 933 } DrawPropertyDrawableRange(RSPropertyDrawableSlot begin,RSPropertyDrawableSlot end,RSPaintFilterCanvas & canvas)934 inline void DrawPropertyDrawableRange( 935 RSPropertyDrawableSlot begin, RSPropertyDrawableSlot end, RSPaintFilterCanvas& canvas) 936 { 937 renderContent_->DrawPropertyDrawableRange(begin, end, canvas); 938 } 939 #ifdef RS_ENABLE_GPU 940 std::shared_ptr<DrawableV2::RSFilterDrawable> GetFilterDrawable(bool isForeground) const; 941 virtual void MarkFilterCacheFlags(std::shared_ptr<DrawableV2::RSFilterDrawable>& filterDrawable, 942 RSDirtyRegionManager& dirtyManager, bool needRequestNextVsync); 943 bool IsForceClearOrUseFilterCache(std::shared_ptr<DrawableV2::RSFilterDrawable>& filterDrawable); 944 #endif 945 void UpdateDirtySlotsAndPendingNodes(RSDrawableSlot slot); 946 // if true, it means currently it's in partial render mode and this node is intersect with dirtyRegion 947 bool isRenderUpdateIgnored_ = false; 948 bool isShadowValidLastFrame_ = false; 949 bool IsSelfDrawingNode() const; 950 bool lastFrameHasAnimation_ = false; 951 bool mustRenewedInfo_ = false; 952 bool needClearSurface_ = false; 953 bool isBootAnimation_ = false; 954 bool lastFrameHasVisibleEffect_ = false; 955 bool waitSync_ = false; 956 mutable bool isFullChildrenListValid_ = true; 957 bool isOnTheTree_ = false; 958 bool isChildSupportUifirst_ = true; 959 bool isUifirstNode_ = true; 960 bool isForceFlag_ = false; 961 bool isUifirstEnable_ = false; 962 bool lastFrameSynced_ = true; 963 bool srcOrClipedAbsDrawRectChangeFlag_ = false; 964 bool startingWindowFlag_ = false; 965 bool isNodeSingleFrameComposer_ = false; 966 bool childHasSharedTransition_ = false; 967 bool flagIntersectWithDRM_ = false; 968 std::atomic<bool> isStaticCached_ = false; 969 RSUIFirstSwitch uiFirstSwitch_ = RSUIFirstSwitch::NONE; 970 NodeDirty dirtyStatus_ = NodeDirty::CLEAN; 971 NodeDirty curDirtyStatus_ = NodeDirty::CLEAN; 972 int isUifirstDelay_ = 0; 973 NodeId drawingCacheRootId_ = INVALID_NODEID; 974 mutable std::shared_ptr<DrawableV2::RSRenderNodeDrawableAdapter> renderDrawable_; 975 std::shared_ptr<RSSingleFrameComposer> singleFrameComposer_ = nullptr; 976 std::unique_ptr<RSRenderParams> stagingRenderParams_; 977 RSPaintFilterCanvas::SaveStatus renderNodeSaveCount_; 978 RectI filterRegion_; 979 ModifierDirtyTypes dirtyTypes_; 980 ModifierDirtyTypes curDirtyTypes_; 981 982 CurFrameInfoDetail curFrameInfoDetail_; 983 984 private: 985 // mark cross node in physical extended screen model 986 bool isCrossNode_ = false; 987 bool isCloneCrossNode_ = false; 988 bool isFirstLevelCrossNode_ = false; 989 bool autoClearCloneNode_ = false; 990 bool isChildrenSorted_ = true; 991 bool childrenHasSharedTransition_ = false; 992 uint8_t nodeGroupType_ = NodeGroupType::NONE; 993 bool shouldPaint_ = true; 994 // drawing group cache 995 RSDrawingCacheType drawingCacheType_ = RSDrawingCacheType::DISABLED_CACHE; 996 bool isTextureExportNode_ = false; 997 uint8_t drawableVecStatus_ = 0; 998 bool isOnlyBasicGeoTransform_ = true; 999 // Test pipeline 1000 bool addedToPendingSyncList_ = false; 1001 bool drawCmdListNeedSync_ = false; 1002 bool drawableVecNeedClear_ = false; 1003 bool unobscuredUECChildrenNeedSync_ = false; 1004 // accumulate all children's region rect for dirty merging when any child has been removed 1005 bool hasRemovedChild_ = false; 1006 bool lastFrameSubTreeSkipped_ = false; 1007 bool curFrameHasAnimation_ = false; 1008 bool childHasVisibleFilter_ = false; // only collect visible children filter status 1009 bool childHasVisibleEffect_ = false; // only collect visible children has useeffect 1010 bool hasChildrenOutOfRect_ = false; 1011 // opinc state 1012 NodeCacheState nodeCacheState_ = NodeCacheState::STATE_INIT; 1013 bool isSubTreeDirty_ = false; 1014 bool isContentDirty_ = false; 1015 bool nodeGroupIncludeProperty_ = false; 1016 bool isNewOnTree_ = false; 1017 bool geometryChangeNotPerceived_ = false; 1018 // node region, only used in selfdrawing node dirty 1019 bool isSelfDrawingNode_ = false; 1020 bool isDirtyRegionUpdated_ = false; 1021 bool isLastVisible_ = false; 1022 bool isAccumulatedClipFlagChanged_ = false; 1023 bool hasAccumulatedClipFlag_ = false; 1024 bool isOpincNodeSupportFlag_ = true; 1025 bool isSuggestOpincNode_ = false; 1026 // since preparation optimization would skip child's dirtyFlag(geoDirty) update 1027 // it should be recorded and update if marked dirty again 1028 bool geoUpdateDelay_ = false; 1029 bool isOpincRootFlag_ = false; 1030 bool lastFrameHasChildrenOutOfRect_ = false; 1031 MultiThreadCacheType lastFrameUifirstFlag_ = MultiThreadCacheType::NONE; 1032 bool isContainBootAnimation_ = false; 1033 bool isUnchangeMarkEnable_ = false; 1034 bool isNeedCalculate_ = false; 1035 bool isUnchangeMarkInApp_ = false; 1036 CacheType cacheType_ = CacheType::NONE; 1037 bool isDrawingCacheChanged_ = false; 1038 bool drawingCacheNeedUpdate_ = false; 1039 bool selfAddForSubSurfaceCnt_ = false; 1040 bool visitedForSubSurfaceCnt_ = false; 1041 bool isMainThreadNode_ = true; 1042 bool isScale_ = false; 1043 bool isScaleInPreFrame_ = false; 1044 bool hasFilter_ = false; 1045 bool hasHardwareNode_ = false; 1046 bool hasAbilityComponent_ = false; 1047 bool isAncestorDirty_ = false; 1048 bool isParentLeashWindow_ = false; 1049 bool isParentScbScreen_ = false; 1050 bool hasCacheableAnim_ = false; 1051 NodePriorityType priority_ = NodePriorityType::MAIN_PRIORITY; 1052 bool lastIsNeedAssignToSubThread_ = false; 1053 uint8_t drawableVecStatusV1_ = 0; 1054 bool uifirstNeedSync_ = false; // both cmdlist¶m 1055 bool uifirstSkipPartialSync_ = false; 1056 bool forceUpdateByUifirst_ = false; 1057 bool backgroundFilterRegionChanged_ = false; 1058 bool backgroundFilterInteractWithDirty_ = false; 1059 bool foregroundFilterRegionChanged_ = false; 1060 bool foregroundFilterInteractWithDirty_ = false; 1061 bool isOccluded_ = false; 1062 bool isBlendWithBackground_ = false; 1063 // for UIExtension info collection 1064 bool childrenHasUIExtension_ = false; 1065 bool isAccessibilityConfigChanged_ = false; 1066 const bool isPurgeable_; 1067 std::atomic<bool> isTunnelHandleChange_ = false; 1068 std::atomic<bool> isCacheSurfaceNeedUpdate_ = false; 1069 std::atomic<bool> commandExecuted_ = false; 1070 std::atomic_bool isUsedBySubThread_ = false; 1071 int32_t crossScreenNum_ = 0; 1072 // shadowRectOffset means offset between shadowRect and absRect of node 1073 int shadowRectOffsetX_ = 0; 1074 int shadowRectOffsetY_ = 0; 1075 int32_t preparedDisplayOffsetX_ = 0; 1076 int32_t preparedDisplayOffsetY_ = 0; 1077 uint32_t disappearingTransitionCount_ = 0; 1078 float globalAlpha_ = 1.0f; 1079 int tryCacheTimes_ = 0; 1080 int unchangeCount_ = 0; 1081 int unchangeCountUpper_ = 3; // 3 time is the default to cache 1082 // collect subtree's surfaceNode including itself 1083 int subSurfaceCnt_ = 0; 1084 uint32_t cacheSurfaceThreadIndex_ = UNI_MAIN_THREAD_INDEX; 1085 uint32_t completedSurfaceThreadIndex_ = UNI_MAIN_THREAD_INDEX; 1086 OutOfParentType outOfParent_ = OutOfParentType::UNKNOWN; 1087 // Only use in RSRenderNode::DrawCacheSurface to calculate scale factor 1088 float boundsWidth_ = 0.0f; 1089 float boundsHeight_ = 0.0f; 1090 pid_t appPid_ = 0; 1091 NodeId id_; 1092 NodeId instanceRootNodeId_ = INVALID_NODEID; 1093 NodeId firstLevelNodeId_ = INVALID_NODEID; 1094 NodeId uifirstRootNodeId_ = INVALID_NODEID; 1095 NodeId displayNodeId_ = INVALID_NODEID; 1096 const std::shared_ptr<RSRenderContent> renderContent_ = std::make_shared<RSRenderContent>(); 1097 std::shared_ptr<SharedTransitionParam> sharedTransitionParam_; 1098 // bounds and frame modifiers must be unique 1099 std::shared_ptr<RSRenderModifier> boundsModifier_; 1100 std::shared_ptr<RSRenderModifier> frameModifier_; 1101 // Note: Make sure that fullChildrenList_ is never nullptr. Otherwise, the caller using 1102 // `for (auto child : *GetSortedChildren()) { ... }` will crash. 1103 // When an empty list is needed, use EmptyChildrenList instead. 1104 static const inline auto EmptyChildrenList = std::make_shared<const std::vector<std::shared_ptr<RSRenderNode>>>(); 1105 ChildrenListSharedPtr fullChildrenList_ = EmptyChildrenList ; 1106 std::shared_ptr<RSRenderDisplaySync> displaySync_ = nullptr; 1107 std::shared_ptr<Drawing::Surface> cacheSurface_ = nullptr; 1108 std::shared_ptr<Drawing::Surface> cacheCompletedSurface_ = nullptr; 1109 std::shared_ptr<RectF> drawRegion_ = nullptr; 1110 std::shared_ptr<std::unordered_set<std::shared_ptr<RSRenderNode>>> stagingUECChildren_ = 1111 std::make_shared<std::unordered_set<std::shared_ptr<RSRenderNode>>>(); 1112 WeakPtr sourceCrossNode_; 1113 WeakPtr curCloneNodeParent_; 1114 std::weak_ptr<RSContext> context_ = {}; 1115 WeakPtr parent_; 1116 // including enlarged draw region 1117 RectF selfDrawRect_; 1118 RectI localShadowRect_; 1119 RectI localOutlineRect_; 1120 RectI localPixelStretchRect_; 1121 RectI localForegroundEffectRect_; 1122 RectI localDistortionEffectRect_; 1123 // map parentMatrix 1124 RectI absDrawRect_; 1125 RectF absDrawRectF_; 1126 RectI oldAbsDrawRect_; 1127 // round in by absDrawRectF_ or selfDrawingNodeAbsDirtyRectF_, and apply the clip of parent component 1128 RectI innerAbsDrawRect_; 1129 RectI oldDirty_; 1130 RectI oldDirtyInSurface_; 1131 RectI childrenRect_; 1132 RectI oldChildrenRect_; 1133 RectI removedChildrenRect_; 1134 RectI oldClipRect_; 1135 // aim to record children rect in abs coords, without considering clip 1136 RectI absChildrenRect_; 1137 // aim to record current frame clipped children dirty region, in abs coords 1138 RectI subTreeDirtyRegion_; 1139 Vector4f globalCornerRadius_{ 0.f, 0.f, 0.f, 0.f }; 1140 RectF selfDrawingNodeDirtyRect_; 1141 RectI selfDrawingNodeAbsDirtyRect_; 1142 RectF selfDrawingNodeAbsDirtyRectF_; 1143 // used in old pipline 1144 RectI oldRectFromRenderProperties_; 1145 // for blur cache 1146 RectI lastFilterRegion_; 1147 std::vector<SharedPtr> cloneCrossNodeVec_; 1148 std::map<PropertyId, std::shared_ptr<RSRenderModifier>> modifiers_; 1149 std::unordered_set<RSDrawableSlot> dirtySlots_; 1150 DrawCmdIndex stagingDrawCmdIndex_; 1151 std::vector<Drawing::RecordingCanvas::DrawFunc> stagingDrawCmdList_; 1152 std::vector<NodeId> visibleFilterChild_; 1153 std::unordered_set<NodeId> visibleEffectChild_; 1154 Drawing::Matrix oldAbsMatrix_; 1155 RSDrawable::Vec drawableVec_; 1156 RSAnimationManager animationManager_; 1157 1158 std::list<WeakPtr> children_; 1159 std::set<NodeId> preFirstLevelNodeIdSet_ = {}; 1160 std::list<std::pair<SharedPtr, uint32_t>> disappearingChildren_; 1161 friend class RSRenderPropertyBase; 1162 friend class RSRenderTransition; 1163 #if defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK) 1164 Drawing::BackendTexture cacheBackendTexture_; 1165 Drawing::BackendTexture cacheCompletedBackendTexture_; 1166 #ifdef RS_ENABLE_VK 1167 NativeBufferUtils::VulkanCleanupHelper* cacheCleanupHelper_ = nullptr; 1168 NativeBufferUtils::VulkanCleanupHelper* cacheCompletedCleanupHelper_ = nullptr; 1169 #endif 1170 bool isTextureValid_ = false; 1171 #endif 1172 std::string nodeName_ = ""; 1173 std::unordered_set<NodeId> curCacheFilterRects_ = {}; 1174 std::unordered_set<NodeId> visitedCacheRoots_ = {}; 1175 mutable std::recursive_mutex surfaceMutex_; 1176 ClearCacheSurfaceFunc clearCacheSurfaceFunc_ = nullptr; 1177 1178 // for blur effct count 1179 static std::unordered_map<pid_t, size_t> blurEffectCounter_; 1180 // The angle at which the node rotates about the Z-axis 1181 float absRotation_ = 0.f; 1182 void UpdateBlurEffectCounter(int deltaCount); 1183 int GetBlurEffectDrawbleCount(); 1184 1185 void SetParent(WeakPtr parent); 1186 void ResetParent(); 1187 void UpdateSrcOrClipedAbsDrawRectChangeState(const RectI& clipRect); 1188 bool IsUifirstArkTsCardNode(); OnResetParent()1189 virtual void OnResetParent() {} 1190 1191 void GenerateFullChildrenList(); 1192 void ResortChildren(); 1193 bool ShouldClearSurface(); 1194 1195 void InternalRemoveSelfFromDisappearingChildren(); 1196 void FallbackAnimationsToRoot(); 1197 void FilterModifiersByPid(pid_t pid); 1198 1199 bool UpdateBufferDirtyRegion(RectI& dirtyRect, const RectI& drawRegion); 1200 void CollectAndUpdateLocalShadowRect(); 1201 void CollectAndUpdateLocalOutlineRect(); 1202 void CollectAndUpdateLocalPixelStretchRect(); 1203 void CollectAndUpdateLocalForegroundEffectRect(); 1204 void CollectAndUpdateLocalDistortionEffectRect(); 1205 // update drawrect based on self's info 1206 void UpdateBufferDirtyRegion(); 1207 bool UpdateSelfDrawRect(); 1208 bool CheckAndUpdateGeoTrans(std::shared_ptr<RSObjAbsGeometry>& geoPtr); 1209 void UpdateAbsDirtyRegion(RSDirtyRegionManager& dirtyManager, const RectI& clipRect); 1210 void UpdateDirtyRegion(RSDirtyRegionManager& dirtyManager, bool geoDirty, const std::optional<RectI>& clipRect); 1211 void UpdateDrawRect(bool& accumGeoDirty, const RectI& clipRect, const Drawing::Matrix& parentSurfaceMatrix); 1212 void UpdateFullScreenFilterCacheRect(RSDirtyRegionManager& dirtyManager, bool isForeground) const; 1213 void ValidateLightResources(); 1214 void UpdateShouldPaint(); // update node should paint state in apply modifier stage 1215 1216 // opinc state func 1217 void NodeCacheStateChange(NodeChangeType type); 1218 void SetCacheStateByRetrytime(); 1219 void NodeCacheStateReset(NodeCacheState nodeCacheState); 1220 1221 std::shared_ptr<Drawing::Image> GetCompletedImage( 1222 RSPaintFilterCanvas& canvas, uint32_t threadIndex, bool isUIFirst); 1223 1224 void UpdateDrawableVec(); 1225 void UpdateDrawableVecInternal(std::unordered_set<RSPropertyDrawableSlot> dirtySlots); 1226 void UpdateDisplayList(); 1227 void UpdateShadowRect(); 1228 1229 void RecordCloneCrossNode(SharedPtr node); 1230 1231 void OnRegister(const std::weak_ptr<RSContext>& context); 1232 1233 friend class DrawFuncOpItem; 1234 friend class RSAliasDrawable; 1235 friend class RSContext; 1236 friend class RSMainThread; 1237 friend class RSPointerWindowManager; 1238 friend class RSModifierDrawable; 1239 friend class RSProxyRenderNode; 1240 friend class RSRenderNodeMap; 1241 friend class RSRenderThread; 1242 friend class RSRenderTransition; 1243 friend class DrawableV2::RSRenderNodeDrawableAdapter; 1244 friend class DrawableV2::RSChildrenDrawable; 1245 friend class DrawableV2::RSRenderNodeShadowDrawable; 1246 #ifdef RS_PROFILER_ENABLED 1247 friend class RSProfiler; 1248 #endif 1249 }; 1250 // backward compatibility 1251 using RSBaseRenderNode = RSRenderNode; 1252 1253 struct SharedTransitionParam { 1254 SharedTransitionParam(RSRenderNode::SharedPtr inNode, RSRenderNode::SharedPtr outNode, bool isInSameWindow); 1255 1256 RSRenderNode::SharedPtr GetPairedNode(const NodeId nodeId) const; 1257 bool IsLower(const NodeId nodeId) const; 1258 void UpdateHierarchy(const NodeId nodeId); IsInAppTranSitionSharedTransitionParam1259 bool IsInAppTranSition() const 1260 { 1261 return !crossApplication_; 1262 } 1263 void InternalUnregisterSelf(); 1264 bool HasRelation(); 1265 void SetNeedGenerateDrawable(const bool needGenerateDrawable); 1266 static void UpdateUnpairedSharedTransitionMap(const std::shared_ptr<SharedTransitionParam>& param); 1267 RSB_EXPORT std::string Dump() const; 1268 RSB_EXPORT void ResetRelation(); 1269 RSB_EXPORT void GenerateDrawable(const RSRenderNode& node); 1270 1271 std::weak_ptr<RSRenderNode> inNode_; 1272 std::weak_ptr<RSRenderNode> outNode_; 1273 NodeId inNodeId_; 1274 NodeId outNodeId_; 1275 bool needGenerateDrawable_ = false; 1276 1277 RSB_EXPORT static std::map<NodeId, std::weak_ptr<SharedTransitionParam>> unpairedShareTransitions_; 1278 bool paired_ = true; // treated as paired by default, until we fail to pair them 1279 1280 private: 1281 enum class NodeHierarchyRelation : uint8_t { 1282 UNKNOWN = -1, 1283 IN_NODE_BELOW_OUT_NODE = 0, 1284 IN_NODE_ABOVE_OUT_NODE = 1, 1285 }; 1286 NodeHierarchyRelation relation_ = NodeHierarchyRelation::UNKNOWN; 1287 bool crossApplication_ = false; 1288 }; 1289 } // namespace Rosen 1290 } // namespace OHOS 1291 1292 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_RENDER_NODE_H 1293