• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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_CLIENT_CORE_PIPELINE_RS_DISPLAY_RENDER_NODE_H
16 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_DISPLAY_RENDER_NODE_H
17 
18 #include <memory>
19 #include <mutex>
20 #include "common/rs_common_def.h"
21 
22 #ifndef ROSEN_CROSS_PLATFORM
23 #include <ibuffer_consumer_listener.h>
24 #include <iconsumer_surface.h>
25 #include <surface.h>
26 #include "sync_fence.h"
27 #endif
28 
29 #include "common/rs_macros.h"
30 #include "common/rs_occlusion_region.h"
31 #include "memory/rs_memory_track.h"
32 #include "pipeline/rs_render_node.h"
33 #include "pipeline/rs_surface_handler.h"
34 #include <screen_manager/screen_types.h>
35 #include "screen_manager/rs_screen_info.h"
36 #ifdef NEW_RENDER_CONTEXT
37 #include "rs_render_surface.h"
38 #else
39 #include "platform/drawing/rs_surface.h"
40 #endif
41 
42 namespace OHOS {
43 namespace Rosen {
44 class RSSurfaceRenderNode;
45 class RSB_EXPORT RSDisplayRenderNode : public RSRenderNode {
46 public:
47     struct ScreenRenderParams
48     {
49         ScreenInfo screenInfo;
50         std::map<ScreenId, bool> displayHasSecSurface;
51         std::map<ScreenId, bool> displayHasSkipSurface;
52         std::map<ScreenId, bool> displayHasSnapshotSkipSurface;
53         std::map<ScreenId, bool> displayHasProtectedSurface;
54         std::map<ScreenId, bool> displaySpecailSurfaceChanged;
55         std::map<ScreenId, bool> hasCaptureWindow;
56     };
57 
58     enum CompositeType {
59         UNI_RENDER_COMPOSITE = 0,
60         UNI_RENDER_MIRROR_COMPOSITE,
61         UNI_RENDER_EXPAND_COMPOSITE,
62         HARDWARE_COMPOSITE,
63         SOFTWARE_COMPOSITE
64     };
65     using WeakPtr = std::weak_ptr<RSDisplayRenderNode>;
66     using SharedPtr = std::shared_ptr<RSDisplayRenderNode>;
67     static inline constexpr RSRenderNodeType Type = RSRenderNodeType::DISPLAY_NODE;
68 
69     ~RSDisplayRenderNode() override;
70     void SetIsOnTheTree(bool flag, NodeId instanceRootNodeId = INVALID_NODEID,
71         NodeId firstLevelNodeId = INVALID_NODEID, NodeId cacheNodeId = INVALID_NODEID,
72         NodeId uifirstRootNodeId = INVALID_NODEID, NodeId displayNodeId = INVALID_NODEID) override;
73 
SetScreenId(uint64_t screenId)74     void SetScreenId(uint64_t screenId)
75     {
76         screenId_ = screenId;
77     }
78 
GetScreenId()79     uint64_t GetScreenId() const
80     {
81         return screenId_;
82     }
83 
SetRogSize(uint32_t rogWidth,uint32_t rogHeight)84     void SetRogSize(uint32_t rogWidth, uint32_t rogHeight)
85     {
86         rogWidth_ = rogWidth;
87         rogHeight_ = rogHeight;
88     }
89 
GetRogWidth()90     uint32_t GetRogWidth() const
91     {
92         return rogWidth_;
93     }
94 
GetRogHeight()95     uint32_t GetRogHeight() const
96     {
97         return rogHeight_;
98     }
99 
SetDisplayOffset(int32_t offsetX,int32_t offsetY)100     void SetDisplayOffset(int32_t offsetX, int32_t offsetY)
101     {
102         offsetX_ = offsetX;
103         offsetY_ = offsetY;
104     }
105 
GetDisplayOffsetX()106     int32_t GetDisplayOffsetX() const
107     {
108         return offsetX_;
109     }
110 
GetDisplayOffsetY()111     int32_t GetDisplayOffsetY() const
112     {
113         return offsetY_;
114     }
115 
GetFingerprint()116     bool GetFingerprint() const
117     {
118         return hasFingerprint_;
119     }
120 
SetFingerprint(bool hasFingerprint)121     void SetFingerprint(bool hasFingerprint)
122     {
123         hasFingerprint_ = hasFingerprint;
124     }
125 
SetScreenRotation(const ScreenRotation & screenRotation)126     void SetScreenRotation(const ScreenRotation& screenRotation)
127     {
128         screenRotation_ = screenRotation;
129     }
130 
GetScreenRotation()131     ScreenRotation GetScreenRotation()
132     {
133         return screenRotation_;
134     }
135 
IsMirrorScreen()136     bool IsMirrorScreen() const
137     {
138         return isMirrorScreen_;
139     }
140 
SetIsMirrorScreen(bool isMirrorScreen)141     void SetIsMirrorScreen(bool isMirrorScreen)
142     {
143         isMirrorScreen_ = isMirrorScreen;
144     }
145 
146     void CollectSurface(
147         const std::shared_ptr<RSBaseRenderNode>& node, std::vector<RSBaseRenderNode::SharedPtr>& vec,
148         bool isUniRender, bool onlyFirstLevel) override;
149     void QuickPrepare(const std::shared_ptr<RSNodeVisitor>& visitor) override;
150     void Prepare(const std::shared_ptr<RSNodeVisitor>& visitor) override;
151     void Process(const std::shared_ptr<RSNodeVisitor>& visitor) override;
152 
GetType()153     RSRenderNodeType GetType() const override
154     {
155         return RSRenderNodeType::DISPLAY_NODE;
156     }
157 
158     bool IsMirrorDisplay() const;
159 
HasMirroredDisplayChanged()160     inline bool HasMirroredDisplayChanged() const noexcept
161     {
162         return hasMirroredDisplayChanged_;
163     }
164 
ResetMirroredDisplayChangedFlag()165     inline void ResetMirroredDisplayChangedFlag() noexcept
166     {
167         hasMirroredDisplayChanged_ = false;
168     }
169 
170     void SetCompositeType(CompositeType type);
171     CompositeType GetCompositeType() const;
172     void SetForceSoftComposite(bool flag);
173     bool IsForceSoftComposite() const;
174     void SetMirrorSource(SharedPtr node);
175     void ResetMirrorSource();
176     void SetIsMirrorDisplay(bool isMirror);
177     void SetSecurityDisplay(bool isSecurityDisplay);
178     bool GetSecurityDisplay() const;
179     void SetDisplayGlobalZOrder(float zOrder);
180     bool SkipFrame(uint32_t refreshRate, uint32_t skipFrameInterval) override;
181     void SetBootAnimation(bool isBootAnimation) override;
182     bool GetBootAnimation() const override;
GetMirrorSource()183     WeakPtr GetMirrorSource() const
184     {
185         return mirrorSource_;
186     }
187 
HasDisappearingTransition(bool)188     bool HasDisappearingTransition(bool) const override
189     {
190         return false;
191     }
192     // Use in vulkan parallel rendering
SetIsParallelDisplayNode(bool isParallelDisplayNode)193     void SetIsParallelDisplayNode(bool isParallelDisplayNode)
194     {
195         isParallelDisplayNode_ = isParallelDisplayNode;
196     }
197 
IsParallelDisplayNode()198     bool IsParallelDisplayNode() const
199     {
200         return isParallelDisplayNode_;
201     }
202 
203     ScreenRotation GetRotation() const;
204 
GetDirtyManager()205     std::shared_ptr<RSDirtyRegionManager> GetDirtyManager() const
206     {
207         return dirtyManager_;
208     }
209     void UpdateDisplayDirtyManager(int32_t bufferage, bool useAlignedDirtyRegion = false);
210     void ClearCurrentSurfacePos();
UpdateSurfaceNodePos(NodeId id,RectI rect)211     void UpdateSurfaceNodePos(NodeId id, RectI rect)
212     {
213         currentFrameSurfacePos_[id] = rect;
214     }
215 
AddSurfaceNodePosByDescZOrder(NodeId id,RectI rect)216     void AddSurfaceNodePosByDescZOrder(NodeId id, RectI rect)
217     {
218         currentFrameSurfacesByDescZOrder_.emplace_back(id, rect);
219     }
220 
AddSecurityLayer(NodeId id)221     void AddSecurityLayer(NodeId id)
222     {
223         securityLayerList_.emplace_back(id);
224     }
225 
ClearSecurityLayerList()226     void ClearSecurityLayerList()
227     {
228         securityLayerList_.clear();
229     }
230 
GetSecurityLayerList()231     const std::vector<NodeId>& GetSecurityLayerList()
232     {
233         return securityLayerList_;
234     }
235 
SetSecurityExemption(bool isSecurityExemption)236     void SetSecurityExemption(bool isSecurityExemption)
237     {
238         isSecurityExemption_ = isSecurityExemption;
239     }
240 
GetSecurityExemption()241     bool GetSecurityExemption() const
242     {
243         return isSecurityExemption_;
244     }
245 
GetLastFrameSurfacePos(NodeId id)246     RectI GetLastFrameSurfacePos(NodeId id)
247     {
248         if (lastFrameSurfacePos_.count(id) == 0) {
249             return {};
250         }
251         return lastFrameSurfacePos_[id];
252     }
253 
GetCurrentFrameSurfacePos(NodeId id)254     RectI GetCurrentFrameSurfacePos(NodeId id)
255     {
256         if (currentFrameSurfacePos_.count(id) == 0) {
257             return {};
258         }
259         return currentFrameSurfacePos_[id];
260     }
261 
GetSurfaceChangedRects()262     const std::vector<RectI> GetSurfaceChangedRects() const
263     {
264         std::vector<RectI> rects;
265         for (const auto& lastFrameSurfacePo : lastFrameSurfacePos_) {
266             if (currentFrameSurfacePos_.find(lastFrameSurfacePo.first) == currentFrameSurfacePos_.end()) {
267                 rects.emplace_back(lastFrameSurfacePo.second);
268             }
269         }
270         for (const auto& currentFrameSurfacePo : currentFrameSurfacePos_) {
271             if (lastFrameSurfacePos_.find(currentFrameSurfacePo.first) == lastFrameSurfacePos_.end()) {
272                 rects.emplace_back(currentFrameSurfacePo.second);
273             }
274         }
275         return rects;
276     }
277 
GetCurAllSurfaces()278     std::vector<RSBaseRenderNode::SharedPtr>& GetCurAllSurfaces()
279     {
280         return curAllSurfaces_;
281     }
282 
283     void UpdateRenderParams() override;
284     void UpdatePartialRenderParams();
285     void UpdateScreenRenderParams(ScreenRenderParams& screenRenderParams);
286     void UpdateOffscreenRenderParams(bool needOffscreen);
287     void RecordMainAndLeashSurfaces(RSBaseRenderNode::SharedPtr surface);
GetAllMainAndLeashSurfaces()288     std::vector<RSBaseRenderNode::SharedPtr>& GetAllMainAndLeashSurfaces() { return curMainAndLeashSurfaceNodes_;}
GetCurAllSurfaces(bool onlyFirstLevel)289     std::vector<RSBaseRenderNode::SharedPtr>& GetCurAllSurfaces(bool onlyFirstLevel)
290     {
291         return onlyFirstLevel ? curAllFirstLevelSurfaces_ : curAllSurfaces_;
292     }
293 
294     void UpdateRotation();
295     bool IsRotationChanged() const;
IsLastRotationChanged()296     bool IsLastRotationChanged() const {
297         return lastRotationChanged;
298     }
GetPreRotationStatus()299     bool GetPreRotationStatus() const {
300         return preRotationStatus_;
301     }
GetCurRotationStatus()302     bool GetCurRotationStatus() const {
303         return curRotationStatus_;
304     }
IsFirstTimeToProcessor()305     bool IsFirstTimeToProcessor() const {
306         return isFirstTimeToProcessor_;
307     }
308 
SetOriginScreenRotation(const ScreenRotation & rotate)309     void SetOriginScreenRotation(const ScreenRotation& rotate) {
310         originScreenRotation_ = rotate;
311         isFirstTimeToProcessor_ = false;
312     }
GetOriginScreenRotation()313     ScreenRotation GetOriginScreenRotation() const {
314         return originScreenRotation_;
315     }
316 
SetInitMatrix(const Drawing::Matrix & matrix)317     void SetInitMatrix(const Drawing::Matrix& matrix) {
318         initMatrix_ = matrix;
319         isFirstTimeToProcessor_ = false;
320     }
321 
GetInitMatrix()322     const Drawing::Matrix& GetInitMatrix() const {
323         return initMatrix_;
324     }
325 
GetOffScreenCacheImgForCapture()326     std::shared_ptr<Drawing::Image> GetOffScreenCacheImgForCapture() {
327         return offScreenCacheImgForCapture_;
328     }
SetOffScreenCacheImgForCapture(std::shared_ptr<Drawing::Image> offScreenCacheImgForCapture)329     void SetOffScreenCacheImgForCapture(std::shared_ptr<Drawing::Image> offScreenCacheImgForCapture) {
330         offScreenCacheImgForCapture_ = offScreenCacheImgForCapture;
331     }
332 
333     void SetHDRPresent(bool hdrPresent);
334 
335     void SetBrightnessRatio(float brightnessRatio);
336 
337     void SetColorSpace(const GraphicColorGamut& newColorSpace);
338     GraphicColorGamut GetColorSpace() const;
339 
GetDirtySurfaceNodeMap()340     std::map<NodeId, std::shared_ptr<RSSurfaceRenderNode>>& GetDirtySurfaceNodeMap()
341     {
342         return dirtySurfaceNodeMap_;
343     }
344 
345     void SetMainAndLeashSurfaceDirty(bool isDirty);
346 
347     // Use in MultiLayersPerf
GetSurfaceCountForMultiLayersPerf()348     size_t GetSurfaceCountForMultiLayersPerf() const
349     {
350         return surfaceCountForMultiLayersPerf_;
351     }
352 
SetScbNodePid(const std::vector<int32_t> & oldScbPids,int32_t currentScbPid)353     void SetScbNodePid(const std::vector<int32_t>& oldScbPids, int32_t currentScbPid)
354     {
355         oldScbPids_ = oldScbPids;
356         currentScbPid_ = currentScbPid;
357         isNeedWaitNewScbPid_ = true;
358         isFullChildrenListValid_ = false;
359     }
360 
GetOldScbPids()361     std::vector<int32_t> GetOldScbPids() const
362     {
363         return oldScbPids_;
364     }
365 
GetCurrentScbPid()366     int32_t GetCurrentScbPid() const
367     {
368         return currentScbPid_;
369     }
370 
371     ChildrenListSharedPtr GetSortedChildren() const override;
372 
373     Occlusion::Region GetDisappearedSurfaceRegionBelowCurrent(NodeId currentSurface) const;
374 
UpdateZoomState(bool state)375     void UpdateZoomState(bool state)
376     {
377         preZoomState_ = curZoomState_;
378         curZoomState_ = state;
379     }
380 
381     bool IsZoomStateChange() const;
382 
383     using ScreenStatusNotifyTask = std::function<void(bool)>;
384 
385     static void SetScreenStatusNotifyTask(ScreenStatusNotifyTask task);
386 
387     void NotifyScreenNotSwitching();
388 
389     // Window Container
390     void SetWindowContainer(std::shared_ptr<RSBaseRenderNode> container);
391     std::shared_ptr<RSBaseRenderNode> GetWindowContainer() const;
392 
393 protected:
394     void OnSync() override;
395 private:
396     explicit RSDisplayRenderNode(
397         NodeId id, const RSDisplayNodeConfig& config, const std::weak_ptr<RSContext>& context = {});
398     void InitRenderParams() override;
399     void HandleCurMainAndLeashSurfaceNodes();
400     // vector of sufacenodes will records dirtyregions by itself
401     std::vector<RSBaseRenderNode::SharedPtr> curMainAndLeashSurfaceNodes_;
402     CompositeType compositeType_ { HARDWARE_COMPOSITE };
403     bool isMirrorScreen_ = false;
404     ScreenRotation screenRotation_ = ScreenRotation::ROTATION_0;
405     ScreenRotation originScreenRotation_ = ScreenRotation::ROTATION_0;
406     uint64_t screenId_ = 0;
407     int32_t offsetX_ = 0;
408     int32_t offsetY_ = 0;
409     uint32_t rogWidth_ = 0;
410     uint32_t rogHeight_ = 0;
411     bool forceSoftComposite_ { false };
412     bool isMirroredDisplay_ = false;
413     bool hasMirroredDisplayChanged_ = false;
414     bool isSecurityDisplay_ = false;
415     WeakPtr mirrorSource_;
416     float lastRotation_ = 0.f;
417     bool preRotationStatus_ = false;
418     bool curRotationStatus_ = false;
419     bool lastRotationChanged = false;
420     Drawing::Matrix initMatrix_;
421     bool isFirstTimeToProcessor_ = true;
422     bool hasFingerprint_ = false;
423     GraphicColorGamut colorSpace_ = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB;
424 
425     std::map<NodeId, RectI> lastFrameSurfacePos_;
426     std::map<NodeId, RectI> currentFrameSurfacePos_;
427     std::vector<std::pair<NodeId, RectI>> lastFrameSurfacesByDescZOrder_;
428     std::vector<std::pair<NodeId, RectI>> currentFrameSurfacesByDescZOrder_;
429     std::shared_ptr<RSDirtyRegionManager> dirtyManager_ = nullptr;
430     std::vector<std::string> windowsName_;
431 
432     std::vector<NodeId> securityLayerList_;
433     bool isSecurityExemption_ = false;
434 
435     std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces_;
436     std::vector<RSBaseRenderNode::SharedPtr> curAllFirstLevelSurfaces_;
437     std::mutex mtx_;
438 
439     // Use in screen recording optimization
440     std::shared_ptr<Drawing::Image> offScreenCacheImgForCapture_ = nullptr;
441 
442     // Use in vulkan parallel rendering
443     bool isParallelDisplayNode_ = false;
444 
445     // Use in MultiLayersPerf
446     size_t surfaceCountForMultiLayersPerf_ = 0;
447 
448     std::map<NodeId, std::shared_ptr<RSSurfaceRenderNode>> dirtySurfaceNodeMap_;
449 
450     std::vector<int32_t> oldScbPids_ {};
451     int32_t currentScbPid_ = -1;
452     mutable bool isNeedWaitNewScbPid_ = false;
453     mutable std::shared_ptr<std::vector<std::shared_ptr<RSRenderNode>>> currentChildrenList_ =
454         std::make_shared<std::vector<std::shared_ptr<RSRenderNode>>>();
455 
456     // Window Container
457     std::shared_ptr<RSBaseRenderNode> windowContainer_;
458 
459     friend class DisplayNodeCommandHelper;
460     static inline ScreenStatusNotifyTask screenStatusNotifyTask_ = nullptr;
461     int64_t lastRefreshTime_ = 0;
462 
463     bool curZoomState_ = false;
464     bool preZoomState_ = false;
465 };
466 } // namespace Rosen
467 } // namespace OHOS
468 
469 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_DISPLAY_RENDER_NODE_H
470