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