• 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 RENDER_SERVICE_BASE_RS_FILTER_DIRTY_COLLECTOR_H
16 #define RENDER_SERVICE_BASE_RS_FILTER_DIRTY_COLLECTOR_H
17 
18 #include <list>
19 
20 #include "common/rs_common_def.h"
21 #include "common/rs_rect.h"
22 #include "common/rs_occlusion_region.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 /*
27  * Whether an area of filter should be included into dirty region, and its cache validity depends on:
28  * - The filter is inside/outside of a surface.
29  * - Surface transparency.
30  * These enum values distinguish the different cases.
31  */
32 typedef enum : uint8_t {
33     OPAQUE_SURFACE_FILTER       = 0,
34     TRANSPARENT_SURFACE_FILTER  = 1,
35     CONTAINER_FILTER            = 2,
36     MAX_FILTER_DIRTY_TYPE
37 } FilterDirtyType;
38 
39 /**
40  * This structure shows the basic unit for processing filter dirty regions, including:
41  * - NodeId
42  * - Intersection test region (this may differ from the actual node bounds, e.g. effect node)
43  * - Region to be added to the dirty region
44  * - Aligned dirty region (when alignment is enabled, the filter region should also be aligned)
45  * - Pre-dirty region, when this filter collected by the main thread when this blur was created
46  */
47 struct FilterDirtyRegionInfo {
48     NodeId id_ = INVALID_NODEID;
49     Occlusion::Region intersectRegion_ = Occlusion::Region();
50     Occlusion::Region filterDirty_ = Occlusion::Region();
51     Occlusion::Region alignedFilterDirty_ = Occlusion::Region();
52     Occlusion::Region belowDirty_ = Occlusion::Region();
53     bool isBackgroundFilterClean_ = false;
54     bool addToDirty_ = false;
55 
56     FilterDirtyRegionInfo() = default;
57     FilterDirtyRegionInfo(const FilterDirtyRegionInfo& info) = default;
58     FilterDirtyRegionInfo& operator=(const FilterDirtyRegionInfo& info) = default;
59 };
60 
61 typedef std::list<FilterDirtyRegionInfo> FilterDirtyRegionInfoList;
62 
63 /**
64 * this class is closed-loop within the dirty region feature.
65 * For other features, DO NOT modify it.
66 * This class can only be obtained by reference and copy assignment is forbidden.
67  */
68 class RSB_EXPORT RSFilterDirtyCollector {
69 public:
70     RSFilterDirtyCollector& operator=(const RSFilterDirtyCollector& collector) = delete;
71     void CollectFilterDirtyRegionInfo(const FilterDirtyRegionInfo& filterInfo, bool syncToRT);
72     FilterDirtyRegionInfoList& GetFilterDirtyRegionInfoList(bool syncToRT);
73     void OnSync(RSFilterDirtyCollector& target) const;
74     void Clear();
AddPureCleanFilterDirtyRegion(const Occlusion::Region & region)75     void AddPureCleanFilterDirtyRegion(const Occlusion::Region& region)
76     {
77         pureCleanFilterDirtyRegion_.OrSelf(region);
78     }
GetPureCleanFilterDirtyRegion()79     const Occlusion::Region& GetPureCleanFilterDirtyRegion() const
80     {
81         return pureCleanFilterDirtyRegion_;
82     }
ClearPureCleanFilterDirtyRegion()83     void ClearPureCleanFilterDirtyRegion()
84     {
85         pureCleanFilterDirtyRegion_.Reset();
86     }
GetValidCachePartialRender()87     static bool GetValidCachePartialRender()
88     {
89         return enablePartialRender_;
90     }
SetValidCachePartialRender(bool enable)91     static void SetValidCachePartialRender(bool enable)
92     {
93         enablePartialRender_ = enable;
94     }
RecordFilterCacheValidForOcclusion(NodeId id,bool isValid)95     static void RecordFilterCacheValidForOcclusion(NodeId id, bool isValid)
96     {
97         if (!isValid) {
98             return;
99         }
100         validOcclusionFilterCache_.insert(id);
101     }
GetFilterCacheValidForOcclusion(NodeId id)102     static bool GetFilterCacheValidForOcclusion(NodeId id)
103     {
104         return validOcclusionFilterCache_.find(id) != validOcclusionFilterCache_.end();
105     }
ResetFilterCacheValidForOcclusion()106     static void ResetFilterCacheValidForOcclusion()
107     {
108         validOcclusionFilterCache_.clear();
109     }
110 private:
111     // Main thread filters affected by below dirty (may invalidate cache).
112     FilterDirtyRegionInfoList filtersWithBelowDirty_;
113     // RT thread filters requiring full merge on damage intersection.
114     FilterDirtyRegionInfoList pureCleanFilters_;
115 
116     //Blur that does not affect the display but intersects with dirty region
117     //Only used to increase the dirty region of the current frame
118     Occlusion::Region pureCleanFilterDirtyRegion_;
119 
120     // if filter cache valid for occlusion, dirty region collection can be skipped.
121     static std::unordered_set<NodeId> validOcclusionFilterCache_;
122     static bool enablePartialRender_;
123 };
124 } // namespace Rosen
125 } // namespace OHOS
126 #endif // RENDER_SERVICE_BASE_RS_FILTER_DIRTY_COLLECTOR_H
127