• 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 <cstdint>
20 #include <functional>
21 #include <list>
22 #include <memory>
23 #include <mutex>
24 #include <unordered_map>
25 #include <unordered_set>
26 #include <variant>
27 #include <vector>
28 #include <bitset>
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 "memory/rs_dfx_string.h"
36 #include "modifier/rs_render_modifier.h"
37 #include "pipeline/rs_dirty_region_manager.h"
38 #include "pipeline/rs_render_display_sync.h"
39 #include "pipeline/rs_paint_filter_canvas.h"
40 #include "pipeline/rs_render_content.h"
41 #include "pipeline/rs_single_frame_composer.h"
42 #include "property/rs_properties.h"
43 #include "property/rs_property_drawable.h"
44 
45 #ifndef USE_ROSEN_DRAWING
46 #include "include/core/SkRefCnt.h"
47 #include "include/core/SkSurface.h"
48 #include "include/gpu/GrBackendSurface.h"
49 #else
50 #include "draw/surface.h"
51 #include "image/gpu_context.h"
52 #endif
53 
54 #ifndef USE_ROSEN_DRAWING
55 class SkCanvas;
56 #endif
57 namespace OHOS {
58 namespace Rosen {
59 class DrawCmdList;
60 class RSContext;
61 class RSNodeVisitor;
62 class RSCommand;
63 class RSPropertyDrawable;
64 namespace NativeBufferUtils {
65 class VulkanCleanupHelper;
66 }
67 class RSB_EXPORT RSRenderNode : public std::enable_shared_from_this<RSRenderNode>  {
68 public:
69 
70     using WeakPtr = std::weak_ptr<RSRenderNode>;
71     using SharedPtr = std::shared_ptr<RSRenderNode>;
72     static inline constexpr RSRenderNodeType Type = RSRenderNodeType::RS_NODE;
GetType()73     virtual RSRenderNodeType GetType() const
74     {
75         return Type;
76     }
77 
78     explicit RSRenderNode(NodeId id, const std::weak_ptr<RSContext>& context = {}, bool isTextureExportNode = false);
79     explicit RSRenderNode(NodeId id, bool isOnTheTree, const std::weak_ptr<RSContext>& context = {},
80         bool isTextureExportNode = false);
81     RSRenderNode(const RSRenderNode&) = delete;
82     RSRenderNode(const RSRenderNode&&) = delete;
83     RSRenderNode& operator=(const RSRenderNode&) = delete;
84     RSRenderNode& operator=(const RSRenderNode&&) = delete;
85     virtual ~RSRenderNode();
86 
87     void AddChild(SharedPtr child, int index = -1);
88     void SetContainBootAnimation(bool isContainBootAnimation);
89     bool GetContainBootAnimation() const;
90     virtual void SetBootAnimation(bool isBootAnimation);
91     virtual bool GetBootAnimation() const;
92 
93     void MoveChild(SharedPtr child, int index);
94     void RemoveChild(SharedPtr child, bool skipTransition = false);
95     void ClearChildren();
96     void RemoveFromTree(bool skipTransition = false);
97 
98     // Add/RemoveCrossParentChild only used as: the child is under multiple parents(e.g. a window cross multi-screens)
99     void AddCrossParentChild(const SharedPtr& child, int32_t index = -1);
100     void RemoveCrossParentChild(const SharedPtr& child, const WeakPtr& newParent);
101 
102     virtual void CollectSurface(const std::shared_ptr<RSRenderNode>& node,
103                                 std::vector<RSRenderNode::SharedPtr>& vec,
104                                 bool isUniRender,
105                                 bool onlyFirstLevel);
106     virtual void CollectSurfaceForUIFirstSwitch(uint32_t& leashWindowCount, uint32_t minNodeNum);
107     virtual void Prepare(const std::shared_ptr<RSNodeVisitor>& visitor);
108     virtual void Process(const std::shared_ptr<RSNodeVisitor>& visitor);
109     bool IsDirty() const;
110     // attention: current all base node's dirty ops causing content dirty
111     // if there is any new dirty op, check it
112     bool IsContentDirty() const;
113     void SetContentDirty();
114     void ResetIsOnlyBasicGeoTransform();
115     bool IsOnlyBasicGeoTransform() const;
116 
117     WeakPtr GetParent() const;
118 
GetId()119     inline NodeId GetId() const
120     {
121         return id_;
122     }
123 
GetSubSurfaceNodes()124     inline const std::map<NodeId, std::vector<WeakPtr>>& GetSubSurfaceNodes() const
125     {
126         return subSurfaceNodes_;
127     }
128 
129     bool IsFirstLevelSurfaceNode();
130     bool SubSurfaceNodeNeedDraw(PartialRenderType opDropType);
131     void AddSubSurfaceNode(SharedPtr child, SharedPtr parent);
132     void RemoveSubSurfaceNode(SharedPtr child, SharedPtr parent);
133     inline static const bool isSubSurfaceEnabled_ = RSSystemProperties::GetSubSurfaceEnabled();
134 
135     // flag: isOnTheTree; instanceRootNodeId: displaynode or leash/appnode attached to
136     // firstLevelNodeId: surfacenode for uiFirst to assign task; cacheNodeId: drawing cache rootnode attached to
137     virtual void SetIsOnTheTree(bool flag, NodeId instanceRootNodeId = INVALID_NODEID,
138         NodeId firstLevelNodeId = INVALID_NODEID, NodeId cacheNodeId = INVALID_NODEID);
139     bool IsOnTheTree() const;
140 
IsNewOnTree()141     bool IsNewOnTree() const
142     {
143         return isNewOnTree_;
144     }
145 
146     bool GetIsTextureExportNode() const;
147 
148     using ChildrenListSharedPtr = std::shared_ptr<const std::vector<std::shared_ptr<RSRenderNode>>>;
149     // return children and disappeared children, not guaranteed to be sorted by z-index
150     ChildrenListSharedPtr GetChildren() const;
151     // return children and disappeared children, sorted by z-index
152     ChildrenListSharedPtr GetSortedChildren() const;
153     uint32_t GetChildrenCount() const;
154     std::shared_ptr<RSRenderNode> GetFirstChild() const;
155 
156     void DumpTree(int32_t depth, std::string& ou) const;
157     void DumpNodeInfo(DfxString& log);
158 
159     virtual bool HasDisappearingTransition(bool recursive = true) const;
160 
161     void SetTunnelHandleChange(bool change);
162     bool GetTunnelHandleChange() const;
163 
164     // type-safe reinterpret_cast
165     template<typename T>
IsInstanceOf()166     bool IsInstanceOf() const
167     {
168         constexpr auto targetType = static_cast<uint32_t>(T::Type);
169         return (static_cast<uint32_t>(GetType()) & targetType) == targetType;
170     }
171     template<typename T>
ReinterpretCast(std::shared_ptr<RSRenderNode> node)172     static std::shared_ptr<T> ReinterpretCast(std::shared_ptr<RSRenderNode> node)
173     {
174         return node ? node->ReinterpretCastTo<T>() : nullptr;
175     }
176     template<typename T>
ReinterpretCastTo()177     std::shared_ptr<T> ReinterpretCastTo()
178     {
179         return (IsInstanceOf<T>()) ? std::static_pointer_cast<T>(shared_from_this()) : nullptr;
180     }
181 
182     bool HasChildrenOutOfRect() const;
183     void UpdateChildrenOutOfRectFlag(bool flag);
184 
185     void ResetHasRemovedChild();
186     bool HasRemovedChild() const;
187     void ResetChildrenRect();
188     RectI GetChildrenRect() const;
189 
190     bool ChildHasFilter() const;
191     void SetChildHasFilter(bool childHasFilter);
192 
193     NodeId GetInstanceRootNodeId() const;
194     const std::shared_ptr<RSRenderNode> GetInstanceRootNode() const;
195     NodeId GetFirstLevelNodeId() const;
196 
197     // accumulate all valid children's area
198     void UpdateChildrenRect(const RectI& subRect);
199     void SetDirty(bool forceAddToActiveList = false);
200 
AddDirtyType(RSModifierType type)201     virtual void AddDirtyType(RSModifierType type)
202     {
203 #ifndef USE_ROSEN_DRAWING
204         dirtyTypes_.emplace(type);
205 #else
206         dirtyTypes_.set(static_cast<int>(type), true);
207 #endif
208     }
209 
210     std::tuple<bool, bool, bool> Animate(int64_t timestamp, int64_t period = 0, bool isDisplaySyncEnabled = false);
211 
212     bool IsClipBound() const;
213     // clipRect has value in UniRender when calling PrepareCanvasRenderNode, else it is nullopt
214     bool Update(RSDirtyRegionManager& dirtyManager, const std::shared_ptr<RSRenderNode>& parent, bool parentDirty,
215         std::optional<RectI> clipRect = std::nullopt);
216 #ifndef USE_ROSEN_DRAWING
GetContextClipRegion()217     virtual std::optional<SkRect> GetContextClipRegion() const { return std::nullopt; }
218 #else
GetContextClipRegion()219     virtual std::optional<Drawing::Rect> GetContextClipRegion() const { return std::nullopt; }
220 #endif
221 
222     RSProperties& GetMutableRenderProperties();
223     const RSProperties& GetRenderProperties() const;
224     void UpdateRenderStatus(RectI& dirtyRegion, bool isPartialRenderEnabled);
225     bool IsRenderUpdateIgnored() const;
226 
227     // used for animation test
228     RSAnimationManager& GetAnimationManager();
229 
230     void ApplyBoundsGeometry(RSPaintFilterCanvas& canvas);
231     void ApplyAlpha(RSPaintFilterCanvas& canvas);
232     virtual void ProcessTransitionBeforeChildren(RSPaintFilterCanvas& canvas);
233     virtual void ProcessAnimatePropertyBeforeChildren(RSPaintFilterCanvas& canvas, bool includeProperty = true) {}
234     virtual void ProcessRenderBeforeChildren(RSPaintFilterCanvas& canvas);
235 
ProcessRenderContents(RSPaintFilterCanvas & canvas)236     virtual void ProcessRenderContents(RSPaintFilterCanvas& canvas) {}
237 
238     virtual void ProcessTransitionAfterChildren(RSPaintFilterCanvas& canvas);
ProcessAnimatePropertyAfterChildren(RSPaintFilterCanvas & canvas)239     virtual void ProcessAnimatePropertyAfterChildren(RSPaintFilterCanvas& canvas) {}
240     virtual void ProcessRenderAfterChildren(RSPaintFilterCanvas& canvas);
241 
242     void RenderTraceDebug() const;
243     bool ShouldPaint() const;
244 
245     RectI GetOldDirty() const;
246     RectI GetOldDirtyInSurface() const;
247     bool IsDirtyRegionUpdated() const;
248     void CleanDirtyRegionUpdated();
249 
250     void AddModifier(const std::shared_ptr<RSRenderModifier>& modifier, bool isSingleFrameComposer = false);
251     void RemoveModifier(const PropertyId& id);
252     std::shared_ptr<RSRenderModifier> GetModifier(const PropertyId& id);
253 
254     bool IsShadowValidLastFrame() const;
SetShadowValidLastFrame(bool isShadowValidLastFrame)255     void SetShadowValidLastFrame(bool isShadowValidLastFrame)
256     {
257         isShadowValidLastFrame_ = isShadowValidLastFrame;
258     }
259 
260     // update parent's children rect including childRect and itself
261     void UpdateParentChildrenRect(std::shared_ptr<RSRenderNode> parentNode) const;
262     virtual void UpdateFilterCacheManagerWithCacheRegion(
263         RSDirtyRegionManager& dirtyManager, const std::optional<RectI>& clipRect = std::nullopt);
264 
265     void SetStaticCached(bool isStaticCached);
266     bool IsStaticCached() const;
267     // store prev surface subtree's must-renewed info that need prepare
268     virtual void StoreMustRenewedInfo();
269     bool HasMustRenewedInfo() const;
270     // collect all subnodes using effect
271     void SetUseEffectNodes(bool val);
272     bool HasUseEffectNodes() const;
273     bool HasSubSurface() const;
274 
275     bool NeedInitCacheSurface() const;
276     bool NeedInitCacheCompletedSurface() const;
277     bool IsPureContainer() const;
278     bool IsContentNode() const;
279 
GetDrawCmdModifiers()280     inline const RSRenderContent::DrawCmdContainer& GetDrawCmdModifiers() const
281     {
282         return renderContent_->drawCmdModifiers_;
283     }
284 
285 #ifndef USE_ROSEN_DRAWING
286     using ClearCacheSurfaceFunc = std::function<void(sk_sp<SkSurface>&&, sk_sp<SkSurface>&&, uint32_t, uint32_t)>;
287 #ifdef NEW_SKIA
288     void InitCacheSurface(GrRecordingContext* grContext, ClearCacheSurfaceFunc func = nullptr,
289         uint32_t threadIndex = UNI_MAIN_THREAD_INDEX);
290 #else
291     void InitCacheSurface(GrContext* grContext, ClearCacheSurfaceFunc func = nullptr,
292         uint32_t threadIndex = UNI_MAIN_THREAD_INDEX);
293 #endif
294 #else
295     using ClearCacheSurfaceFunc =
296         std::function<void(std::shared_ptr<Drawing::Surface>&&,
297         std::shared_ptr<Drawing::Surface>&&, uint32_t, uint32_t)>;
298     void InitCacheSurface(Drawing::GPUContext* grContext, ClearCacheSurfaceFunc func = nullptr,
299         uint32_t threadIndex = UNI_MAIN_THREAD_INDEX);
300 #endif
301 
302     Vector2f GetOptionalBufferSize() const;
303 
304 #ifndef USE_ROSEN_DRAWING
GetCacheSurface()305     sk_sp<SkSurface> GetCacheSurface() const
306 #else
307     std::shared_ptr<Drawing::Surface> GetCacheSurface() const
308 #endif
309     {
310         std::scoped_lock<std::recursive_mutex> lock(surfaceMutex_);
311         return cacheSurface_;
312     }
313 
314 // use for uni render visitor
315 #ifndef USE_ROSEN_DRAWING
316     sk_sp<SkSurface> GetCacheSurface(uint32_t threadIndex, bool needCheckThread, bool releaseAfterGet = false);
317 #else
318     std::shared_ptr<Drawing::Surface> GetCacheSurface(uint32_t threadIndex, bool needCheckThread,
319         bool releaseAfterGet = false);
320 #endif
321 
322     void UpdateCompletedCacheSurface();
323     void SetTextureValidFlag(bool isValid);
324 #ifndef USE_ROSEN_DRAWING
325     sk_sp<SkSurface> GetCompletedCacheSurface(uint32_t threadIndex = UNI_MAIN_THREAD_INDEX,
326         bool needCheckThread = true, bool releaseAfterGet = false);
327 #else
328     std::shared_ptr<Drawing::Surface> GetCompletedCacheSurface(uint32_t threadIndex = UNI_MAIN_THREAD_INDEX,
329         bool needCheckThread = true, bool releaseAfterGet = false);
330 #endif
331     void ClearCacheSurfaceInThread();
332     void ClearCacheSurface(bool isClearCompletedCacheSurface = true);
333     bool IsCacheSurfaceValid() const;
334 
335 #if defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK)
336     void UpdateBackendTexture();
337 #endif
338 
339     void DrawCacheSurface(RSPaintFilterCanvas& canvas, uint32_t threadIndex = UNI_MAIN_THREAD_INDEX,
340         bool isUIFirst = false);
341 
342     void SetCacheType(CacheType cacheType);
343     CacheType GetCacheType() const;
344 
SetCacheSurfaceNeedUpdated(bool isCacheSurfaceNeedUpdate)345     void SetCacheSurfaceNeedUpdated(bool isCacheSurfaceNeedUpdate)
346     {
347         isCacheSurfaceNeedUpdate_ = isCacheSurfaceNeedUpdate;
348     }
349 
GetCacheSurfaceNeedUpdated()350     bool GetCacheSurfaceNeedUpdated() const
351     {
352         return isCacheSurfaceNeedUpdate_;
353     }
354 
355     int GetShadowRectOffsetX() const;
356     int GetShadowRectOffsetY() const;
357 
358     void SetDrawingCacheType(RSDrawingCacheType cacheType);
359     RSDrawingCacheType GetDrawingCacheType() const;
360     void ResetFilterRectsInCache(const std::unordered_set<NodeId>& curRects);
361     void GetFilterRectsInCache(std::unordered_map<NodeId, std::unordered_set<NodeId>>& allRects) const;
362     bool IsFilterRectsInCache() const;
363     void SetDrawingCacheChanged(bool cacheChanged);
364     bool GetDrawingCacheChanged() const;
365     void ResetDrawingCacheNeedUpdate();
366     void SetVisitedCacheRootIds(const std::unordered_set<NodeId>& visitedNodes);
367     const std::unordered_set<NodeId>& GetVisitedCacheRootIds() const;
368     // manage cache root nodeid
369     void SetDrawingCacheRootId(NodeId id);
370     NodeId GetDrawingCacheRootId() const;
371     // record cache geodirty for preparation optimization
372     void SetCacheGeoPreparationDelay(bool val);
373     void ResetCacheGeoPreparationDelay();
374     bool GetCacheGeoPreparationDelay() const;
375 
376     // driven render ///////////////////////////////////
377     void SetIsMarkDriven(bool isMarkDriven);
378     bool IsMarkDriven() const;
379     void SetIsMarkDrivenRender(bool isMarkDrivenRender);
380     bool IsMarkDrivenRender() const;
381 
382     void SetItemIndex(int index);
383     int GetItemIndex() const;
384 
385     void SetPaintState(bool paintState);
386     bool GetPaintState() const;
387 
388     void SetIsContentChanged(bool isChanged);
389     bool IsContentChanged() const;
390 
391     bool HasAnimation() const;
392 
393     bool HasFilter() const;
394     void SetHasFilter(bool hasFilter);
395 
396     std::recursive_mutex& GetSurfaceMutex() const;
397 
398     bool HasHardwareNode() const;
399     void SetHasHardwareNode(bool hasHardwareNode);
400 
401     bool HasAbilityComponent() const;
402     void SetHasAbilityComponent(bool hasAbilityComponent);
403 
404     uint32_t GetCacheSurfaceThreadIndex() const;
405 
406     uint32_t GetCompletedSurfaceThreadIndex() const;
407 
408     bool IsMainThreadNode() const;
409     void SetIsMainThreadNode(bool isMainThreadNode);
410 
411     bool IsScale() const;
412     void SetIsScale(bool isScale);
413 
414     void SetPriority(NodePriorityType priority);
415     NodePriorityType GetPriority();
416 
417     bool IsAncestorDirty() const;
418     void SetIsAncestorDirty(bool isAncestorDirty);
419 
420     bool IsParentLeashWindow() const;
421     void SetParentLeashWindow();
422 
423     bool IsParentScbScreen() const;
424     void SetParentScbScreen();
425 
426     bool HasCachedTexture() const;
427 
428     void SetDrawRegion(const std::shared_ptr<RectF>& rect);
429     const std::shared_ptr<RectF>& GetDrawRegion() const;
430     void SetOutOfParent(OutOfParentType outOfParent);
431     OutOfParentType GetOutOfParent() const;
432 
433 #ifndef USE_ROSEN_DRAWING
434     void UpdateEffectRegion(std::optional<SkIRect>& region, bool isForced = false);
435 #else
436     void UpdateEffectRegion(std::optional<Drawing::RectI>& region, bool isForced = false);
437 #endif
438     bool IsBackgroundFilterCacheValid() const;
439     virtual void UpdateFilterCacheWithDirty(RSDirtyRegionManager& dirtyManager, bool isForeground = true);
440 
441     void CheckGroupableAnimation(const PropertyId& id, bool isAnimAdd);
442     bool IsForcedDrawInGroup() const;
443     bool IsSuggestedDrawInGroup() const;
444     void CheckDrawingCacheType();
HasCacheableAnim()445     bool HasCacheableAnim() const { return hasCacheableAnim_; }
446     enum NodeGroupType {
447         NONE = 0,
448         GROUPED_BY_ANIM,
449         GROUPED_BY_UI,
450         GROUPED_BY_USER,
451     };
452     void MarkNodeGroup(NodeGroupType type, bool isNodeGroup, bool includeProperty);
453     NodeGroupType GetNodeGroupType();
454     bool IsNodeGroupIncludeProperty() const;
455 
456     void MarkNodeSingleFrameComposer(bool isNodeSingleFrameComposer, pid_t pid = 0);
457     virtual bool GetNodeIsSingleFrameComposer() const;
458 
459     /////////////////////////////////////////////
460 
461     // shared transition params, in format <InNodeId, target weakPtr>, nullopt means no transition
462     using SharedTransitionParam = std::pair<NodeId, std::weak_ptr<RSRenderNode>>;
463     void SetSharedTransitionParam(const std::optional<SharedTransitionParam>&& sharedTransitionParam);
464     const std::optional<SharedTransitionParam>& GetSharedTransitionParam() const;
465 
466     void SetGlobalAlpha(float alpha);
467     float GetGlobalAlpha() const;
OnAlphaChanged()468     virtual void OnAlphaChanged() {}
469 
GetGlobalCornerRadius()470     inline const Vector4f& GetGlobalCornerRadius() noexcept
471     {
472         return globalCornerRadius_;
473     }
474 
SetGlobalCornerRadius(const Vector4f & globalCornerRadius)475     inline void SetGlobalCornerRadius(const Vector4f& globalCornerRadius) noexcept
476     {
477         globalCornerRadius_ = globalCornerRadius;
478     }
479 
480     void ActivateDisplaySync();
481     void InActivateDisplaySync();
482     void UpdateDisplaySyncRange();
483 
484     void MarkNonGeometryChanged();
485     bool ApplyModifiers();
486 
487     virtual RectI GetFilterRect() const;
488     void SetIsUsedBySubThread(bool isUsedBySubThread);
489     bool GetIsUsedBySubThread() const;
490 
491     void SetLastIsNeedAssignToSubThread(bool lastIsNeedAssignToSubThread);
492     bool GetLastIsNeedAssignToSubThread() const;
493 
SetIsTextureExportNode(bool isTextureExportNode)494     void SetIsTextureExportNode(bool isTextureExportNode)
495     {
496         isTextureExportNode_ = isTextureExportNode;
497     }
498 
499     const std::shared_ptr<RSRenderContent> GetRenderContent() const;
500 protected:
OnApplyModifiers()501     virtual void OnApplyModifiers() {}
502 
503     enum class NodeDirty {
504         CLEAN = 0,
505         DIRTY,
506     };
507     void SetClean();
508 
509     void DumpNodeType(std::string& out) const;
510 
511     void DumpSubClassNode(std::string& out) const;
512     void DumpDrawCmdModifiers(std::string& out) const;
513     void DumpDrawCmdModifier(std::string& propertyDesc, RSModifierType type,
514         std::shared_ptr<RSRenderModifier>& modifier) const;
515 
516 
GetContext()517     const std::weak_ptr<RSContext> GetContext() const
518     {
519         return context_;
520     }
521     virtual void OnTreeStateChanged();
522     // recursive update subSurfaceCnt
523     void UpdateSubSurfaceCnt(SharedPtr curParent, SharedPtr preParent);
524 
525     static void SendCommandFromRT(std::unique_ptr<RSCommand>& command, NodeId nodeId);
526     void AddGeometryModifier(const std::shared_ptr<RSRenderModifier>& modifier);
527     RSPaintFilterCanvas::SaveStatus renderNodeSaveCount_;
528     std::shared_ptr<RSSingleFrameComposer> singleFrameComposer_ = nullptr;
529     bool isNodeSingleFrameComposer_ = false;
530     // if true, it means currently it's in partial render mode and this node is intersect with dirtyRegion
531     bool isRenderUpdateIgnored_ = false;
532     bool isShadowValidLastFrame_ = false;
533 
534     bool IsSelfDrawingNode() const;
535     bool isOnTheTree_ = false;
536     NodeId drawingCacheRootId_ = INVALID_NODEID;
537     bool mustRenewedInfo_ = false;
538 
539 #ifndef USE_ROSEN_DRAWING
540     std::unordered_set<RSModifierType> dirtyTypes_;
541 #else
542     std::bitset<static_cast<int>(RSModifierType::MAX_RS_MODIFIER_TYPE)> dirtyTypes_;
543 #endif
544     bool isBootAnimation_ = false;
DrawPropertyDrawable(RSPropertyDrawableSlot slot,RSPaintFilterCanvas & canvas)545     inline void DrawPropertyDrawable(RSPropertyDrawableSlot slot, RSPaintFilterCanvas& canvas)
546     {
547         renderContent_->DrawPropertyDrawable(slot, canvas);
548     }
DrawPropertyDrawableRange(RSPropertyDrawableSlot begin,RSPropertyDrawableSlot end,RSPaintFilterCanvas & canvas)549     inline void DrawPropertyDrawableRange(
550         RSPropertyDrawableSlot begin, RSPropertyDrawableSlot end, RSPaintFilterCanvas& canvas)
551     {
552         renderContent_->DrawPropertyDrawableRange(begin, end, canvas);
553     }
554 
555 private:
556     NodeId id_;
557     NodeId instanceRootNodeId_ = INVALID_NODEID;
558     NodeId firstLevelNodeId_ = INVALID_NODEID;
559 
560     WeakPtr parent_;
561     void SetParent(WeakPtr parent);
562     void ResetParent();
OnResetParent()563     virtual void OnResetParent() {}
564 
565     std::list<WeakPtr> children_;
566     std::list<std::pair<SharedPtr, uint32_t>> disappearingChildren_;
567 
568     // Note: Make sure that fullChildrenList_ is never nullptr. Otherwise, the caller using
569     // `for (auto child : *GetSortedChildren()) { ... }` will crash.
570     // When an empty list is needed, use EmptyChildrenList instead.
571     static const inline auto EmptyChildrenList = std::make_shared<const std::vector<std::shared_ptr<RSRenderNode>>>();
572     ChildrenListSharedPtr fullChildrenList_ = EmptyChildrenList ;
573     bool isFullChildrenListValid_ = true;
574     bool isChildrenSorted_ = true;
575 
576     void UpdateFullChildrenListIfNeeded();
577     void GenerateFullChildrenList();
578     void ResortChildren();
579 
580     std::weak_ptr<RSContext> context_ = {};
581     NodeDirty dirtyStatus_ = NodeDirty::CLEAN;
582     bool isContentDirty_ = false;
583     bool isNewOnTree_ = false;
584     bool isOnlyBasicGeoTransform_ = true;
585     friend class RSRenderPropertyBase;
586     friend class RSRenderTransition;
587     std::atomic<bool> isTunnelHandleChange_ = false;
588     // accumulate all children's region rect for dirty merging when any child has been removed
589     bool hasRemovedChild_ = false;
590     bool hasChildrenOutOfRect_ = false;
591     RectI childrenRect_;
592     bool childHasFilter_ = false;  // only collect children filter status
593 
594     void InternalRemoveSelfFromDisappearingChildren();
595     void FallbackAnimationsToRoot();
596     void FilterModifiersByPid(pid_t pid);
597 
598     void UpdateDirtyRegion(RSDirtyRegionManager& dirtyManager, bool geoDirty, std::optional<RectI> clipRect);
599     void UpdateFullScreenFilterCacheRect(RSDirtyRegionManager& dirtyManager, bool isForeground) const;
600 
601     void UpdateShouldPaint(); // update node should paint state in apply modifier stage
602     bool shouldPaint_ = true;
603 
604     bool isDirtyRegionUpdated_ = false;
605     bool isContainBootAnimation_ = false;
606     bool isLastVisible_ = false;
607     bool fallbackAnimationOnDestroy_ = true;
608     uint32_t disappearingTransitionCount_ = 0;
609     RectI oldDirty_;
610     RectI oldDirtyInSurface_;
611     RSAnimationManager animationManager_;
612     std::map<PropertyId, std::shared_ptr<RSRenderModifier>> modifiers_;
613     // bounds and frame modifiers must be unique
614     std::shared_ptr<RSRenderModifier> boundsModifier_;
615     std::shared_ptr<RSRenderModifier> frameModifier_;
616 
617 #ifndef USE_ROSEN_DRAWING
618     sk_sp<SkImage> GetCompletedImage(RSPaintFilterCanvas& canvas, uint32_t threadIndex, bool isUIFirst);
619     sk_sp<SkSurface> cacheSurface_ = nullptr;
620     sk_sp<SkSurface> cacheCompletedSurface_ = nullptr;
621 #else
622     std::shared_ptr<Drawing::Image> GetCompletedImage(
623         RSPaintFilterCanvas& canvas, uint32_t threadIndex, bool isUIFirst);
624     std::shared_ptr<Drawing::Surface> cacheSurface_ = nullptr;
625     std::shared_ptr<Drawing::Surface> cacheCompletedSurface_ = nullptr;
626 #endif
627 #if defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK)
628 #ifndef USE_ROSEN_DRAWING
629     GrBackendTexture cacheBackendTexture_;
630     GrBackendTexture cacheCompletedBackendTexture_;
631 #else
632     Drawing::BackendTexture cacheBackendTexture_;
633     Drawing::BackendTexture cacheCompletedBackendTexture_;
634 #endif
635 #ifdef RS_ENABLE_VK
636     NativeBufferUtils::VulkanCleanupHelper* cacheCleanupHelper_ = nullptr;
637     NativeBufferUtils::VulkanCleanupHelper* cacheCompletedCleanupHelper_ = nullptr;
638 #endif
639     bool isTextureValid_ = false;
640 #endif
641     std::atomic<bool> isCacheSurfaceNeedUpdate_ = false;
642     std::atomic<bool> isStaticCached_ = false;
643     CacheType cacheType_ = CacheType::NONE;
644     // drawing group cache
645     RSDrawingCacheType drawingCacheType_ = RSDrawingCacheType::DISABLED_CACHE;
646     bool isDrawingCacheChanged_ = false;
647     bool drawingCacheNeedUpdate_ = false;
648     // since cache preparation optimization would skip child's dirtyFlag(geoDirty) update
649     // it should be recorded and update if marked dirty again
650     bool cacheGeoPreparationDelay_ = false;
651     // specify if any subnode uses effect, not including itself
652     bool hasEffectNode_ = false;
653 
654     std::unordered_set<NodeId> curCacheFilterRects_ = {};
655     std::unordered_set<NodeId> visitedCacheRoots_ = {};
656     // collect subtree's surfaceNode including itself
657     uint32_t subSurfaceCnt_ = 0;
658 
659     mutable std::recursive_mutex surfaceMutex_;
660     ClearCacheSurfaceFunc clearCacheSurfaceFunc_ = nullptr;
661     uint32_t cacheSurfaceThreadIndex_ = UNI_MAIN_THREAD_INDEX;
662     uint32_t completedSurfaceThreadIndex_ = UNI_MAIN_THREAD_INDEX;
663     bool isMainThreadNode_ = true;
664     bool isScale_ = false;
665     bool hasFilter_ = false;
666     bool hasHardwareNode_ = false;
667     bool hasAbilityComponent_ = false;
668     bool isAncestorDirty_ = false;
669     bool isParentLeashWindow_ = false;
670     bool isParentScbScreen_ = false;
671     NodePriorityType priority_ = NodePriorityType::MAIN_PRIORITY;
672 
673     // driven render
674     int itemIndex_ = -1;
675     bool isMarkDriven_ = false;
676     bool isMarkDrivenRender_ = false;
677     bool paintState_ = false;
678     bool isContentChanged_ = false;
679     OutOfParentType outOfParent_ = OutOfParentType::UNKNOWN;
680     float globalAlpha_ = 1.0f;
681     Vector4f globalCornerRadius_{ 0.f, 0.f, 0.f, 0.f };
682     std::optional<SharedTransitionParam> sharedTransitionParam_;
683 
684     std::shared_ptr<RectF> drawRegion_ = nullptr;
685     NodeGroupType nodeGroupType_ = NodeGroupType::NONE;
686     bool nodeGroupIncludeProperty_ = false;
687 
688     // shadowRectOffset means offset between shadowRect and absRect of node
689     int shadowRectOffsetX_ = 0;
690     int shadowRectOffsetY_ = 0;
691     // Only use in RSRenderNode::DrawCacheSurface to calculate scale factor
692     float boundsWidth_ = 0.0f;
693     float boundsHeight_ = 0.0f;
694     bool hasCacheableAnim_ = false;
695     bool geometryChangeNotPerceived_ = false;
696 
697     bool isTextureExportNode_ = false;
698 
699     std::atomic_bool isUsedBySubThread_ = false;
700     bool lastIsNeedAssignToSubThread_ = false;
701 
702     std::shared_ptr<RSRenderDisplaySync> displaySync_ = nullptr;
703 
704     uint8_t drawableVecStatus_ = 0;
705     void UpdateDrawableVec();
706     void UpdateDrawableVecInternal(std::unordered_set<RSPropertyDrawableSlot> dirtySlots);
707     std::map<NodeId, std::vector<WeakPtr>> subSurfaceNodes_;
708     pid_t appPid_ = 0;
709 
710     const std::shared_ptr<RSRenderContent> renderContent_ = std::make_shared<RSRenderContent>();
711 
712     void OnRegister(const std::weak_ptr<RSContext>& context);
713 
714     friend class DrawFuncOpItem;
715     friend class RSAliasDrawable;
716     friend class RSContext;
717     friend class RSMainThread;
718     friend class RSModifierDrawable;
719     friend class RSProxyRenderNode;
720     friend class RSRenderNodeMap;
721     friend class RSRenderThread;
722     friend class RSRenderTransition;
723 };
724 // backward compatibility
725 using RSBaseRenderNode = RSRenderNode;
726 } // namespace Rosen
727 } // namespace OHOS
728 
729 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_RENDER_NODE_H
730