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