• 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_DRAWABLE_RS_SURFACE_RENDER_NODE_DRAWABLE_H
17 #define RENDER_SERVICE_DRAWABLE_RS_SURFACE_RENDER_NODE_DRAWABLE_H
18 
19 #ifndef ROSEN_CROSS_PLATFORM
20 #include <ibuffer_consumer_listener.h>
21 #include <iconsumer_surface.h>
22 #include <surface.h>
23 #endif
24 #include <mutex>
25 #include "platform/drawing/rs_surface.h"
26 
27 #include "common/rs_common_def.h"
28 #include "drawable/rs_render_node_drawable.h"
29 #include "params/rs_surface_render_params.h"
30 #include "params/rs_screen_render_params.h"
31 #include "pipeline/render_thread/rs_base_render_engine.h"
32 #include "pipeline/rs_surface_render_node.h"
33 #include "feature/hdr/rs_hdr_util.h"
34 #include "feature/hetero_hdr/rs_hdr_buffer_layer.h"
35 #include "feature/hetero_hdr/rs_hetero_hdr_util.h"
36 #include "feature/uifirst/rs_draw_window_cache.h"
37 #include "feature/uifirst/rs_sub_thread_cache.h"
38 
39 namespace OHOS::Rosen {
40 class RSRenderThreadParams;
41 class RSSurfaceRenderNode;
42 class RSSurfaceRenderParams;
43 namespace DrawableV2 {
44 class RSScreenRenderNodeDrawable;
45 class RSLogicalDisplayRenderNodeDrawable;
46 class RSRcdSurfaceRenderNodeDrawable;
47 
48 // remove this when rcd node is replaced by common hardware composer node in OH 6.0 rcd refactoring
49 class RSSurfaceRenderNodeDrawable : public RSRenderNodeDrawable {
50 public:
51     ~RSSurfaceRenderNodeDrawable() = default;
52 
53     static RSRenderNodeDrawable::Ptr OnGenerate(std::shared_ptr<const RSRenderNode> node);
54     void OnDraw(Drawing::Canvas& canvas) override;
55     void OnCapture(Drawing::Canvas& canvas) override;
56     bool CheckIfSurfaceSkipInMirrorOrScreenshot(const RSSurfaceRenderParams& surfaceParams);
57     void SetVirtualScreenWhiteListRootId(const std::unordered_set<NodeId>& whiteList, NodeId id);
58     void ResetVirtualScreenWhiteListRootId(NodeId id);
59 
GetName()60     const std::string& GetName() const
61     {
62         return name_;
63     }
64 
GetDebugInfo()65     std::string GetDebugInfo()
66     {
67         std::string res = "pid_";
68         res.append("_name_");
69         res.append(name_);
70         return res;
71     }
72 
73     // uifirst
GetRsSubThreadCache()74     RsSubThreadCache& GetRsSubThreadCache()
75     {
76         return subThreadCache_;
77     }
78     // HDR
79     bool DrawHDRCacheWithDmaFFRT(RSPaintFilterCanvas& canvas, RSSurfaceRenderParams& surfaceParams);
80     bool GetCurHeterogComputingHdr() const;
81     void SetNodeDrawableNodeDstRect(bool isFixedDstBuffer, RectI boundSize);
82     void SetVideoHdrStatus(HdrStatus hasHdrVideoSurface);
83     void SetHpaeDstRect(RectI boundSize);
84     std::shared_ptr<RSHDRBUfferLayer> GetRsHdrBUfferLayer();
85 
86     Drawing::Matrix GetGravityMatrix(float imgWidth, float imgHeight);
87 
88     const Occlusion::Region& GetVisibleDirtyRegion() const;
89     void SetVisibleDirtyRegion(const Occlusion::Region& region);
90     void SetAlignedVisibleDirtyRegion(const Occlusion::Region& region);
91     void SetGlobalDirtyRegion(Occlusion::Region region);
92     const Occlusion::Region& GetGlobalDirtyRegion() const;
93     void SetDirtyRegionAlignedEnable(bool enable);
94     void SetDirtyRegionBelowCurrentLayer(Occlusion::Region& region);
95     std::shared_ptr<RSDirtyRegionManager> GetSyncDirtyManager() const override;
96 
97     GraphicColorGamut GetAncestorDisplayColorGamut(const RSSurfaceRenderParams& surfaceParams);
98     void DealWithSelfDrawingNodeBuffer(RSPaintFilterCanvas& canvas, RSSurfaceRenderParams& surfaceParams);
99 
SetUIExtensionNeedToDraw(bool needToDraw)100     void SetUIExtensionNeedToDraw(bool needToDraw) override
101     {
102         uiExtensionNeedToDraw_ = needToDraw;
103     }
104 
UIExtensionNeedToDraw()105     bool UIExtensionNeedToDraw() const override
106     {
107         return uiExtensionNeedToDraw_;
108     }
109 
110     bool PrepareOffscreenRender();
111     void FinishOffscreenRender(const Drawing::SamplingOptions& sampling);
112     bool IsHardwareEnabled();
113 
114 #ifndef ROSEN_CROSS_PLATFORM
GetConsumerOnDraw()115     sptr<IConsumerSurface> GetConsumerOnDraw() const
116     {
117         return consumerOnDraw_;
118     }
119     void RegisterDeleteBufferListenerOnSync(sptr<IConsumerSurface> consumer) override;
120 #endif
121 
122     bool IsHardwareEnabledTopSurface() const;
123     void UpdateSurfaceDirtyRegion(std::shared_ptr<RSPaintFilterCanvas>& canvas);
124 
GetDrawableType()125     RSRenderNodeDrawableType GetDrawableType() const override
126     {
127         return RSRenderNodeDrawableType::SURFACE_NODE_DRAWABLE;
128     }
129 
130 private:
131     explicit RSSurfaceRenderNodeDrawable(std::shared_ptr<const RSRenderNode>&& node);
132     void OnGeneralProcess(RSPaintFilterCanvas& canvas, RSSurfaceRenderParams& surfaceParams,
133         RSRenderThreadParams& uniParams, bool isSelfDrawingSurface);
134     bool IsVisibleRegionEqualOnPhysicalAndVirtual(RSSurfaceRenderParams& surfaceParams);
135     void CaptureSurface(RSPaintFilterCanvas& canvas, RSSurfaceRenderParams& surfaceParams);
136 
137     Drawing::Region CalculateVisibleDirtyRegion(RSSurfaceRenderParams& surfaceParams,
138         RSSurfaceRenderNodeDrawable& surfaceDrawable, bool isOffscreen) const;
139     Drawing::Region GetSurfaceDrawRegion() const;
140     void SetSurfaceDrawRegion(const Drawing::Region& region);
141     void CrossDisplaySurfaceDirtyRegionConversion(
142         const RSRenderThreadParams& uniParam, const RSSurfaceRenderParams& surfaceParam, RectI& surfaceDirtyRect) const;
143     bool HasCornerRadius(const RSSurfaceRenderParams& surfaceParams) const;
144     using Registrar = RenderNodeDrawableRegistrar<RSRenderNodeType::SURFACE_NODE, OnGenerate>;
145     static Registrar instance_;
146 
147     bool CheckDrawAndCacheWindowContent(RSSurfaceRenderParams& surfaceParams,
148         RSRenderThreadParams& uniParams) const;
149     void PreprocessUnobscuredUEC(RSPaintFilterCanvas& canvas);
150 
151     void EnableGpuOverDrawDrawBufferOptimization(Drawing::Canvas& canvas, RSSurfaceRenderParams* surfaceParams);
152 
153     // dirty manager
154     void UpdateDisplayDirtyManager(int32_t bufferage, bool useAlignedDirtyRegion = false);
155 
156     void DrawSelfDrawingNodeBuffer(RSPaintFilterCanvas& canvas,
157         const RSSurfaceRenderParams& surfaceParams, BufferDrawParam& params);
158 
159     // Draw cloneNode
160     bool DrawCloneNode(RSPaintFilterCanvas& canvas, RSRenderThreadParams& uniParam,
161         RSSurfaceRenderParams& surfaceParams, bool isCapture = false);
162     void ApplyCrossScreenOffset(RSPaintFilterCanvas& canvas, const RSSurfaceRenderParams& surfaceParams);
163 
164     // Watermark
165     void DrawWatermark(RSPaintFilterCanvas& canvas, const RSSurfaceRenderParams& surfaceParams);
166 
167     /* draw local magnification region */
168     void DrawMagnificationRegion(RSPaintFilterCanvas& canvas, const RSSurfaceRenderParams& surfaceParams);
169 
170     bool RecordTimestamp(NodeId id, uint32_t seqNum);
171 
172     bool DrawCacheImageForMultiScreenView(RSPaintFilterCanvas& canvas, const RSSurfaceRenderParams& surfaceParams);
173 
174     void ClipHoleForSelfDrawingNode(RSPaintFilterCanvas& canvas, RSSurfaceRenderParams& surfaceParams);
175     void DrawBufferForRotationFixed(RSPaintFilterCanvas& canvas, RSSurfaceRenderParams& surfaceParams);
176 
177     void SetCurHeterogComputingHdr(bool curCondition);
178     void DrawHDRBufferWithGPU(RSPaintFilterCanvas &canvas);
179     BufferDrawParam InitBufferDrawParam(RSSurfaceRenderParams* surfaceParams);
180 
181     HdrStatus GetVideoHdrStatus();
182 
183     int GetMaxRenderSizeForRotationOffscreen(int& offscreenWidth, int& offscreenHeight);
184     void ApplyCanvasScalingIfDownscaleEnabled();
185     void SetCulledNodesToCanvas(RSPaintFilterCanvas* canvas, const RSSurfaceRenderParams* surfaceParams);
186 
187 #ifdef SUBTREE_PARALLEL_ENABLE
188     bool QuickGetDrawState(RSPaintFilterCanvas* rscanvas, Drawing::Region& curSurfaceDrawRegion,
189         RSSurfaceRenderParams* surfaceParams);
190 #endif
191     std::string name_;
192     RSSurfaceNodeType surfaceNodeType_ = RSSurfaceNodeType::DEFAULT;
193 #ifndef ROSEN_CROSS_PLATFORM
194     sptr<IBufferConsumerListener> consumerListener_ = nullptr;
195 #endif
196     std::shared_ptr<RSSurface> surface_ = nullptr;
197     bool surfaceCreated_ = false;
198     bool uiExtensionNeedToDraw_ = false;
199 
200     RSPaintFilterCanvas* curCanvas_ = nullptr;
201     std::shared_ptr<Drawing::Surface> offscreenSurface_ = nullptr; // temporary holds offscreen surface
202     int releaseCount_ = 0;
203     static constexpr int MAX_RELEASE_FRAME = 10;
204     RSPaintFilterCanvas* canvasBackup_ = nullptr; // backup current canvas before offscreen rende
205     std::shared_ptr<RSPaintFilterCanvas> offscreenCanvas_ = nullptr;
206     int maxRenderSize_ = 0;
207     std::unique_ptr<RSAutoCanvasRestore> arc_ = nullptr;
208 
209 #ifndef ROSEN_CROSS_PLATFORM
210     sptr<IConsumerSurface> consumerOnDraw_ = nullptr;
211 #endif
212 
213     // dirty manager
214     std::shared_ptr<RSDirtyRegionManager> syncDirtyManager_ = nullptr;
215     Occlusion::Region visibleDirtyRegion_;
216     Occlusion::Region alignedVisibleDirtyRegion_;
217     bool isDirtyRegionAlignedEnable_ = false;
218     Occlusion::Region globalDirtyRegion_;
219 
220     // if a there a dirty layer under transparent clean layer, transparent layer should refreshed
221     Occlusion::Region dirtyRegionBelowCurrentLayer_;
222     bool dirtyRegionBelowCurrentLayerIsEmpty_ = false;
223 
224     friend class OHOS::Rosen::RSDrawWindowCache;
225     bool vmaCacheOff_ = false;
226 
227     static inline bool isInRotationFixed_ = false;
228     bool lastGlobalPositionEnabled_ = false;
229     RsSubThreadCache subThreadCache_;
230     friend class RsSubThreadCache;
231 
232     Drawing::Region curSurfaceDrawRegion_ {};
233     mutable std::mutex drawRegionMutex_;
234 
235     // HDR
236     struct HDRHeterRenderContext {
237         std::shared_ptr<RSHDRBUfferLayer> rsHdrBufferLayer_ {nullptr};
238         HdrStatus hdrSatus_ {HdrStatus::NO_HDR};
239         bool curHeterogComputingHdr_ {false};
240         bool isFixedDstBuffer_ {false};
241 
242         MdcRectT aaeDstRect_;
243         RectI boundSize_;
244 
245         Drawing::Region curSurfaceDrawRegion_ {};
246         mutable std::mutex drawRegionMutex_;
247     };
248     HDRHeterRenderContext g_HDRHeterRenderContext;
249 };
250 } // namespace DrawableV2
251 } // namespace OHOS::Rosen
252 #endif // RENDER_SERVICE_DRAWABLE_RS_SURFACE_RENDER_NODE_DRAWABLE_H
253