• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 RENDER_SERVICE_BASE_DRAWABLE_RS_PROPERTY_DRAWABLE_H
17 #define RENDER_SERVICE_BASE_DRAWABLE_RS_PROPERTY_DRAWABLE_H
18 
19 #include <memory>
20 
21 #include "common/rs_common_def.h"
22 #include "common/rs_rect.h"
23 #include "render/rs_filter.h"
24 #include "recording/draw_cmd_list.h"
25 
26 #include "drawable/rs_drawable.h"
27 
28 namespace OHOS::Rosen {
29 class RSRenderNode;
30 class RSFilter;
31 class RSFilterCacheManager;
32 class ExtendRecordingCanvas;
33 
34 namespace DrawableV2 {
35 class RSPropertyDrawable : public RSDrawable {
36 public:
RSPropertyDrawable(std::shared_ptr<Drawing::DrawCmdList> && drawCmdList)37     RSPropertyDrawable(std::shared_ptr<Drawing::DrawCmdList>&& drawCmdList) : drawCmdList_(std::move(drawCmdList)) {}
38     RSPropertyDrawable() = default;
39     ~RSPropertyDrawable() override = default;
40 
41     void OnSync() override;
42     void OnPurge() override;
43     Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override;
44 
45 protected:
46     bool needSync_ = false;
47     std::shared_ptr<Drawing::DrawCmdList> drawCmdList_;
48     std::shared_ptr<Drawing::DrawCmdList> stagingDrawCmdList_;
49     std::string propertyDescription_;
50     std::string stagingPropertyDescription_;
51 
52     friend class RSPropertyDrawCmdListUpdater;
53 };
54 
55 class RSPropertyDrawCmdListUpdater {
56 public:
57     // not copyable and moveable
58     RSPropertyDrawCmdListUpdater(const RSPropertyDrawCmdListUpdater&) = delete;
59     RSPropertyDrawCmdListUpdater(const RSPropertyDrawCmdListUpdater&&) = delete;
60     RSPropertyDrawCmdListUpdater& operator=(const RSPropertyDrawCmdListUpdater&) = delete;
61     RSPropertyDrawCmdListUpdater& operator=(const RSPropertyDrawCmdListUpdater&&) = delete;
62 
63     explicit RSPropertyDrawCmdListUpdater(int width, int height, RSPropertyDrawable* target);
64     virtual ~RSPropertyDrawCmdListUpdater();
65     const std::unique_ptr<ExtendRecordingCanvas>& GetRecordingCanvas() const;
66 
67 protected:
68     std::unique_ptr<ExtendRecordingCanvas> recordingCanvas_;
69     RSPropertyDrawable* target_;
70 };
71 
72 // ============================================================================
73 // Frame offset
74 class RSFrameOffsetDrawable : public RSPropertyDrawable {
75 public:
RSFrameOffsetDrawable(std::shared_ptr<Drawing::DrawCmdList> && drawCmdList)76     RSFrameOffsetDrawable(std::shared_ptr<Drawing::DrawCmdList>&& drawCmdList)
77         : RSPropertyDrawable(std::move(drawCmdList))
78     {}
79     RSFrameOffsetDrawable() = default;
80     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
81     bool OnUpdate(const RSRenderNode& node) override;
82 
83 private:
84 };
85 
86 // ============================================================================
87 // Clip To Bounds and Clip To Frame
88 class RSClipToBoundsDrawable : public RSPropertyDrawable {
89 public:
RSClipToBoundsDrawable(std::shared_ptr<Drawing::DrawCmdList> && drawCmdList)90     RSClipToBoundsDrawable(std::shared_ptr<Drawing::DrawCmdList>&& drawCmdList)
91         : RSPropertyDrawable(std::move(drawCmdList))
92     {}
93     RSClipToBoundsDrawable() = default;
94     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
95     bool OnUpdate(const RSRenderNode& node) override;
96 
97 private:
98 };
99 
100 class RSClipToFrameDrawable : public RSPropertyDrawable {
101 public:
RSClipToFrameDrawable(std::shared_ptr<Drawing::DrawCmdList> && drawCmdList)102     RSClipToFrameDrawable(std::shared_ptr<Drawing::DrawCmdList>&& drawCmdList)
103         : RSPropertyDrawable(std::move(drawCmdList))
104     {}
105     RSClipToFrameDrawable() = default;
106     static RSDrawable::Ptr OnGenerate(const RSRenderNode& node);
107     bool OnUpdate(const RSRenderNode& node) override;
108 
109 private:
110 };
111 
112 class RSFilterDrawable : public RSDrawable {
113 public:
114     RSFilterDrawable();
115     ~RSFilterDrawable() override = default;
116 
IsForeground()117     virtual bool IsForeground() const
118     {
119         return false;
120     }
121 
122     // set flags for clearing filter cache
123     // All MarkXXX function should be called from render_service thread
124     void MarkFilterRegionChanged();
125     void MarkFilterRegionInteractWithDirty();
126     void MarkFilterRegionIsLargeArea();
127     void MarkFilterForceUseCache(bool forceUseCache = true);
128     void MarkFilterForceClearCache();
129     void MarkEffectNode();
130     void MarkForceClearCacheWithLastFrame();
131     void MarkRotationChanged();
132     void MarkNodeIsOccluded(bool isOccluded);
133     void MarkNeedClearFilterCache();
134     void MarkBlurIntersectWithDRM(bool IsIntersectWithDRM, bool isDark);
135     void MarkInForegroundFilterAndCheckNeedForceClearCache(NodeId offscreenCanvasNodeId);
136 
137     bool IsFilterCacheValid() const;
138     bool IsForceClearFilterCache() const;
139     bool IsForceUseFilterCache() const;
140     bool NeedPendingPurge() const;
141     bool IsSkippingFrame() const;
142     bool IsAIBarFilter() const;
143     bool CheckAndUpdateAIBarCacheStatus(bool intersectHwcDamage);
144     bool WouldDrawLargeAreaBlur();
145     bool WouldDrawLargeAreaBlurPrecisely();
146 
147     void PostUpdate(const RSRenderNode& node);
148     void OnSync() override;
149     Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override;
150     const RectI GetFilterCachedRegion() const;
151 
GetEnableEDR()152     bool GetEnableEDR() const override
153     {
154         return enableEDREffect_;
155     }
156 
157     bool IsFilterCacheValidForOcclusion();
158 
159     void SetDrawBehindWindowRegion(RectI region);
160 
161 protected:
162     void RecordFilterInfos(const std::shared_ptr<RSFilter>& rsFilter);
163 
164     bool needSync_ = false;
165     bool needDrawBehindWindow_ = false;
166     bool stagingNeedDrawBehindWindow_ = false;
167 
168     bool stagingIntersectWithDRM_ = false;
169     bool stagingIsDarkColorMode_ = false;
170 
171     bool renderIntersectWithDRM_  = false;
172     bool renderIsDarkColorMode_  = false;
173     bool enableEDREffect_ = false;
174 
175     NodeId stagingNodeId_ = INVALID_NODEID;
176     NodeId renderNodeId_ = INVALID_NODEID;
177     NodeId screenNodeId_ = INVALID_NODEID;
178 
179     std::string stagingNodeName_ = "invalid0";
180     std::string renderNodeName_ = "invalid0";
181 
182     std::shared_ptr<RSFilter> filter_;
183     std::shared_ptr<RSFilter> stagingFilter_;
184     std::unique_ptr<RSFilterCacheManager> stagingCacheManager_;
185     std::unique_ptr<RSFilterCacheManager> cacheManager_;
186     RectI drawBehindWindowRegion_;
187     RectI stagingDrawBehindWindowRegion_;
188 };
189 } // namespace DrawableV2
190 } // namespace OHOS::Rosen
191 #endif // RENDER_SERVICE_BASE_DRAWABLE_RS_PROPERTY_DRAWABLE_H
192