• 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 
16 #ifndef ROSEN_RENDER_SERVICE_PIPELINE_RS_OCCLUSION_NODE_H
17 #define ROSEN_RENDER_SERVICE_PIPELINE_RS_OCCLUSION_NODE_H
18 #include <cstdint>
19 #include <string>
20 #include <unordered_map>
21 #include <vector>
22 
23 #include "property/rs_properties.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 typedef RectT<int16_t> RectI16;
28 
29 struct OcclusionCoverageInfo {
30     uint64_t id_ = 0;
31     RectI16 rect_ = RectI16();
32     int area_ = 0;
33 };
34 
35 class RSB_EXPORT OcclusionNode : public std::enable_shared_from_this<OcclusionNode> {
36 public:
OcclusionNode(NodeId id,RSRenderNodeType type)37     OcclusionNode(NodeId id, RSRenderNodeType type) : id_(id), type_(type){};
38     OcclusionNode() = delete;
GetId()39     NodeId GetId() const {
40         return id_;
41     }
GetParentOcNode()42     std::weak_ptr<OcclusionNode> GetParentOcNode() const {
43         return parentOcNode_;
44     }
UpdateChildrenOutOfRectInfo(bool hasChildrenOutOfRect)45     void UpdateChildrenOutOfRectInfo(bool hasChildrenOutOfRect) {
46         hasChildrenOutOfRect_ = hasChildrenOutOfRect;
47     }
MarkAsRootOcclusionNode()48     void MarkAsRootOcclusionNode() {
49         isValidInCurrentFrame_ = true;
50         rootOcclusionNode_ = weak_from_this();
51     }
IsSubTreeIgnored()52     bool IsSubTreeIgnored() const {
53         return isSubTreeIgnored_;
54     }
IsValid(const float value)55     bool IsValid(const float value)
56     {
57         return !std::isinf(value) && !std::isnan(value);
58     }
59     void ForwardOrderInsert(std::shared_ptr<OcclusionNode> newNode);
60     bool RemoveChild(const std::shared_ptr<OcclusionNode>& child);
61     void RemoveSubTree(std::unordered_map<NodeId, std::shared_ptr<OcclusionNode>>& occlusionNodes);
62     void CollectNodeProperties(const RSRenderNode& node);
63     void CalculateNodeAllBounds();
64     void UpdateClipRect(const RSRenderNode& node);
65     void UpdateSubTreeProp();
66     void DetectOcclusion(std::unordered_set<NodeId>& culledNodes, std::unordered_set<NodeId>& culledEntireSubtree,
67         std::unordered_set<NodeId>& offTreeNodes);
68     void PreorderTraversal(std::vector<std::shared_ptr<OcclusionNode>>& result);
69     std::string GetOcclusionNodeInfoString();
70 private:
71     void CalculateDrawRect(const RSRenderNode& node, const RSProperties& renderProperties);
72     bool IsOutOfRootRect(const RectI16 &rect);
73     bool IsSubTreeShouldIgnored(const RSRenderNode& node, const RSProperties& renderProperties);
IsOpaque()74     bool IsOpaque() const {
75         return isBgOpaque_ && !isAlphaNeed_;
76     }
77     OcclusionCoverageInfo DetectOcclusionInner(OcclusionCoverageInfo& globalCoverInfo,
78         std::unordered_set<NodeId>& culledNodes, std::unordered_set<NodeId>& culledEntireSubtree,
79         std::unordered_set<NodeId>& offTreeNodes);
80     void CheckNodeOcclusion(OcclusionCoverageInfo& coverageInfo, std::unordered_set<NodeId>& culledNodes);
81     void CheckNodeOcclusion(OcclusionCoverageInfo& coverageInfo, std::unordered_set<NodeId>& culledNodes,
82         std::unordered_set<NodeId>& culledEntireSubtree);
83     void UpdateCoverageInfo(OcclusionCoverageInfo& globalCoverage, OcclusionCoverageInfo& selfCoverage);
84 
85     uint64_t id_ = INVALID_NODEID;
86     uint64_t occludedById_ = INVALID_NODEID;
87     RSRenderNodeType type_ = RSRenderNodeType::UNKNOW;
88     bool isSubTreeIgnored_ = false;
89     bool hasChildrenOutOfRect_ = false;
90     bool isNeedClip_ = false;
91     bool isOutOfRootRect_ = false;
92     bool isAlphaNeed_ = false;
93     bool isBgOpaque_ = false;
94     // Indicates whether the node was inserted or updated in the current frame.
95     // Nodes not inserted or updated in the current frame will be removed from the occlusion tree.
96     bool isValidInCurrentFrame_ = false;
97 
98     // Spatial information
99     Vector2f localPosition_;
100     Vector2f absPositions_;
101     Vector2f localScale_ = {1.0f, 1.0f};
102     Vector2f accumulatedScale_ = {1.0f, 1.0f};
103     float localAlpha_ = 1.0f;
104     float accumulatedAlpha_ = 1.0f;
105     Vector4f cornerRadius_;
106     RectF drawRect_;
107     RectI16 clipOuterRect_;
108     RectI16 clipInnerRect_;
109     RectI16 outerRect_;
110     RectI16 innerRect_;
111 
112     // Node relationship
113     std::weak_ptr<OcclusionNode> rootOcclusionNode_;
114     std::weak_ptr<OcclusionNode> parentOcNode_;
115     std::shared_ptr<OcclusionNode> firstChild_ = nullptr;
116     std::shared_ptr<OcclusionNode> lastChild_ = nullptr;
117     // Same-level node relationships
118     std::weak_ptr<OcclusionNode> leftSibling_;
119     std::weak_ptr<OcclusionNode> rightSibling_;
120 };
121 
122 } // namespace Rosen
123 } // namespace OHOS
124 #endif // ROSEN_RENDER_SERVICE_PIPELINE_RS_OCCLUSION_NODE_H
125