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