• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 RS_UNI_HWC_VISITOR_H
16 #define RS_UNI_HWC_VISITOR_H
17 
18 #include "pipeline/main_thread/rs_uni_render_visitor.h"
19 
20 namespace OHOS {
21 namespace Rosen {
22 class RSCanvasRenderNode;
23 class RSUniHwcVisitor {
24 public:
25     explicit RSUniHwcVisitor(RSUniRenderVisitor& visitor);
26     ~RSUniHwcVisitor();
27 
28     // Compute
29     void UpdateSrcRect(RSSurfaceRenderNode& node, const Drawing::Matrix& totalMatrix);
30     void UpdateDstRect(RSSurfaceRenderNode& node, const RectI& absRect, const RectI& clipRect);
31     void UpdateHwcNodeByTransform(RSSurfaceRenderNode& node, const Drawing::Matrix& totalMatrix);
32     void UpdateDstRectByGlobalPosition(RSSurfaceRenderNode& node);
33 
34     RectI GetHwcVisibleEffectDirty(RSRenderNode& node, const RectI& globalFilterRect) const;
35 
36     bool UpdateIsOffscreen(RSCanvasRenderNode& node);
RestoreIsOffscreen(bool isOffscreen)37     void RestoreIsOffscreen(bool isOffscreen) { isOffscreen_ = isOffscreen; }
38 
39     void UpdateForegroundColorValid(RSCanvasRenderNode& node);
40 
41     Color FindAppBackgroundColor(RSSurfaceRenderNode& node);
42     bool CheckNodeOcclusion(const std::shared_ptr<RSRenderNode>& node,
43         const RectI& nodeAbsRect, Color& nodeBgColor);
44     bool CheckSubTreeOcclusion(const std::shared_ptr<RSRenderNode>& branchNode,
45         const RectI& nodeAbsRect, std::stack<Color>& nodeBgColor);
46     void ProcessSolidLayerDisabled(RSSurfaceRenderNode& node);
47     void ProcessSolidLayerEnabled(RSSurfaceRenderNode& node);
48 
49     void UpdateHwcNodeEnableByBackgroundAlpha(RSSurfaceRenderNode& node);
50     void UpdateHwcNodeEnableByBufferSize(RSSurfaceRenderNode& node);
51     void UpdateHwcNodeEnableByAlpha(const std::shared_ptr<RSSurfaceRenderNode>& node);
52     void UpdateHwcNodeEnableByRotate(const std::shared_ptr<RSSurfaceRenderNode>& node);
53     void UpdateHwcNodeEnable();
54     void UpdateHwcNodeEnableByNodeBelow();
55     void UpdateHwcNodeEnableByHwcNodeBelowSelf(std::vector<RectI>& hwcRects,
56         std::shared_ptr<RSSurfaceRenderNode>& hwcNode, bool isIntersectWithRoundCorner);
57     void UpdateHwcNodeEnableByHwcNodeBelowSelfInApp(const std::shared_ptr<RSSurfaceRenderNode>& hwcNode,
58         std::vector<RectI>& hwcRects);
59     void UpdateHardwareStateByBoundNEDstRectInApps(const std::vector<std::weak_ptr<RSSurfaceRenderNode>>& hwcNodes,
60         std::vector<RectI>& abovedBounds);
61     // Use in updating hwcnode hardware state with background alpha
62     void UpdateHardwareStateByHwcNodeBackgroundAlpha(const std::vector<std::weak_ptr<RSSurfaceRenderNode>>& hwcNodes,
63         RectI& backgroundAlphaRect, bool& isHardwareEnableByBackgroundAlpha);
64     void UpdateChildHwcNodeEnableByHwcNodeBelow(std::vector<RectI>& hwcRects,
65         std::shared_ptr<RSSurfaceRenderNode>& appNode);
66     void UpdateTransparentHwcNodeEnable(const std::vector<std::weak_ptr<RSSurfaceRenderNode>>& hwcNodes);
67     bool IsBackgroundFilterUnderSurface(const std::shared_ptr<RSSurfaceRenderNode>& hwcNode,
68         const std::shared_ptr<RSRenderNode>& filterNode);
69     void CalcHwcNodeEnableByFilterRect(std::shared_ptr<RSSurfaceRenderNode>& node,
70         RSRenderNode& filterNode, uint32_t filterZOrder = 0);
71     void UpdateHwcNodeEnableByFilterRect(std::shared_ptr<RSSurfaceRenderNode>& node,
72         RSRenderNode& filterNode, uint32_t filterZOrder = 0);
73     void UpdateHwcNodeEnableByGlobalFilter(std::shared_ptr<RSSurfaceRenderNode>& node);
74     void UpdateHwcNodeEnableByGlobalCleanFilter(const std::vector<std::pair<NodeId, RectI>>& cleanFilter,
75         RSSurfaceRenderNode& hwcNode);
76     void UpdateHwcNodeEnableByGlobalDirtyFilter(const std::vector<std::pair<NodeId, RectI>>& dirtyFilter,
77         RSSurfaceRenderNode& hwcNode);
78     void UpdateHwcNodeRectInSkippedSubTree(const RSRenderNode& rootNode);
79     void UpdatePrepareClip(RSRenderNode& node);
80     void UpdateTopSurfaceSrcRect(RSSurfaceRenderNode& node,
81         const Drawing::Matrix& absMatrix, const RectI& absRect);
82 
83     bool IsDisableHwcOnExpandScreen() const;
84 
85     void UpdateHwcNodeInfo(RSSurfaceRenderNode& node, const Drawing::Matrix& absMatrix, const RectI& absRect,
86         bool subTreeSkipped = false);
87     void QuickPrepareChildrenOnlyOrder(RSRenderNode& node);
88     void PrintHiperfCounterLog(const char* const counterContext, uint64_t counter);
89     void PrintHiperfLog(RSSurfaceRenderNode* node, const char* const disabledContext);
90     void PrintHiperfLog(const std::shared_ptr<RSSurfaceRenderNode>& node, const char* const disabledContext);
91 
92     // DRM
93     void UpdateCrossInfoForProtectedHwcNode(RSSurfaceRenderNode& hwcNode);
94 
95     // DFX
Statistics()96     HwcDisabledReasonCollection& Statistics() { return hwcDisabledReasonCollection_; }
97 
IncreaseSolidLayerHwcEnableCount()98     void IncreaseSolidLayerHwcEnableCount() { solidLayerHwcEnableCount_++; }
GetSolidLayerHwcEnableCount()99     size_t GetSolidLayerHwcEnableCount() const { return solidLayerHwcEnableCount_; }
100 
101 private:
102     friend class RSUniRenderVisitor;
103     RSUniRenderVisitor& uniRenderVisitor_;
104 
105     // Functions
106     bool IsFindRootSuccess(std::shared_ptr<RSRenderNode>& parent, const RSRenderNode& rootNode);
107     void UpdateHwcNodeClipRect(const std::shared_ptr<RSRenderNode>& hwcNodeParent,
108         Drawing::Rect& childRectMapped);
109     void UpdateHwcNodeMatrix(const std::shared_ptr<RSRenderNode>& hwcNodeParent,
110         Drawing::Matrix& accumulatedMatrix);
111     void UpdateHwcNodeClipRectAndMatrix(const std::shared_ptr<RSSurfaceRenderNode>& hwcNodePtr,
112         const RSRenderNode& rootNode, RectI& clipRect, Drawing::Matrix& matrix);
113     void UpdateRenderResolutionDstRectForDrm(RSSurfaceRenderNode& node, RectI& dstRect);
114     bool IntersectHwcDamage(RSSurfaceRenderNode& hwcNode, const RectI& filterRect);
115 
116     // indicates if hardware composer is totally disabled
117     bool isHardwareForcedDisabled_ = false;
118 
119     // record nodes which has transparent clean filter
120     std::unordered_map<NodeId, std::vector<std::pair<NodeId, RectI>>> transparentHwcCleanFilter_;
121     // record nodes which has transparent dirty filter
122     std::unordered_map<NodeId, std::vector<std::pair<NodeId, RectI>>> transparentHwcDirtyFilter_;
123 
124     uint32_t curZOrderForHwcEnableByFilter_ = 0;
125 
126     size_t solidLayerHwcEnableCount_ = 0;
127 
128     bool isOffscreen_ = false;
129 
130     // use for hardware compose disabled reason collection
131     HwcDisabledReasonCollection& hwcDisabledReasonCollection_ = HwcDisabledReasonCollection::GetInstance();
132 };
133 } // namespace Rosen
134 } // namespace OHOS
135 #endif // RS_UNI_HWC_VISITOR_H