• 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> displayHasProtectedSurface;
53         std::map<ScreenId, bool> displaySpecailSurfaceChanged;
54         std::map<ScreenId, bool> hasCaptureWindow;
55     };
56 
57     enum CompositeType {
58         UNI_RENDER_COMPOSITE = 0,
59         UNI_RENDER_MIRROR_COMPOSITE,
60         UNI_RENDER_EXPAND_COMPOSITE,
61         HARDWARE_COMPOSITE,
62         SOFTWARE_COMPOSITE,
63         UNKNOWN
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) 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 
136     void CollectSurface(
137         const std::shared_ptr<RSBaseRenderNode>& node, std::vector<RSBaseRenderNode::SharedPtr>& vec,
138         bool isUniRender, bool onlyFirstLevel) override;
139     void QuickPrepare(const std::shared_ptr<RSNodeVisitor>& visitor) override;
140     void Prepare(const std::shared_ptr<RSNodeVisitor>& visitor) override;
141     void Process(const std::shared_ptr<RSNodeVisitor>& visitor) override;
142 
GetType()143     RSRenderNodeType GetType() const override
144     {
145         return RSRenderNodeType::DISPLAY_NODE;
146     }
147 
148     bool IsMirrorDisplay() const;
149 
150     void SetCompositeType(CompositeType type);
151     CompositeType GetCompositeType() const;
152     void SetForceSoftComposite(bool flag);
153     bool IsForceSoftComposite() const;
154     void SetMirrorSource(SharedPtr node);
155     void ResetMirrorSource();
156     void SetIsMirrorDisplay(bool isMirror);
157     void SetSecurityDisplay(bool isSecurityDisplay);
158     bool GetSecurityDisplay() const;
159     void SetDisplayGlobalZOrder(float zOrder);
160     bool SkipFrame(uint32_t refreshRate, uint32_t skipFrameInterval) override;
161     void SetBootAnimation(bool isBootAnimation) override;
162     bool GetBootAnimation() const override;
GetMirrorSource()163     WeakPtr GetMirrorSource() const
164     {
165         return mirrorSource_;
166     }
167 
HasDisappearingTransition(bool)168     bool HasDisappearingTransition(bool) const override
169     {
170         return false;
171     }
172     // Use in vulkan parallel rendering
SetIsParallelDisplayNode(bool isParallelDisplayNode)173     void SetIsParallelDisplayNode(bool isParallelDisplayNode)
174     {
175         isParallelDisplayNode_ = isParallelDisplayNode;
176     }
177 
IsParallelDisplayNode()178     bool IsParallelDisplayNode() const
179     {
180         return isParallelDisplayNode_;
181     }
182 
183     ScreenRotation GetRotation() const;
184 
GetDirtyManager()185     std::shared_ptr<RSDirtyRegionManager> GetDirtyManager() const
186     {
187         return dirtyManager_;
188     }
189     void UpdateDisplayDirtyManager(int32_t bufferage, bool useAlignedDirtyRegion = false);
190     void ClearCurrentSurfacePos();
UpdateSurfaceNodePos(NodeId id,RectI rect)191     void UpdateSurfaceNodePos(NodeId id, RectI rect)
192     {
193         currentFrameSurfacePos_[id] = rect;
194     }
195 
AddSurfaceNodePosByDescZOrder(NodeId id,RectI rect)196     void AddSurfaceNodePosByDescZOrder(NodeId id, RectI rect)
197     {
198         currentFrameSurfacesByDescZOrder_.emplace_back(id, rect);
199     }
200 
AddSecurityLayer(NodeId id)201     void AddSecurityLayer(NodeId id)
202     {
203         securityLayerList_.emplace_back(id);
204     }
205 
ClearSecurityLayerList()206     void ClearSecurityLayerList()
207     {
208         securityLayerList_.clear();
209     }
210 
GetSecurityLayerList()211     const std::vector<NodeId>& GetSecurityLayerList()
212     {
213         return securityLayerList_;
214     }
215 
SetSecurityExemption(bool isSecurityExemption)216     void SetSecurityExemption(bool isSecurityExemption)
217     {
218         isSecurityExemption_ = isSecurityExemption;
219     }
220 
GetSecurityExemption()221     bool GetSecurityExemption() const
222     {
223         return isSecurityExemption_;
224     }
225 
GetLastFrameSurfacePos(NodeId id)226     RectI GetLastFrameSurfacePos(NodeId id)
227     {
228         if (lastFrameSurfacePos_.count(id) == 0) {
229             return {};
230         }
231         return lastFrameSurfacePos_[id];
232     }
233 
GetCurrentFrameSurfacePos(NodeId id)234     RectI GetCurrentFrameSurfacePos(NodeId id)
235     {
236         if (currentFrameSurfacePos_.count(id) == 0) {
237             return {};
238         }
239         return currentFrameSurfacePos_[id];
240     }
241 
GetSurfaceChangedRects()242     const std::vector<RectI> GetSurfaceChangedRects() const
243     {
244         std::vector<RectI> rects;
245         for (const auto& lastFrameSurfacePo : lastFrameSurfacePos_) {
246             if (currentFrameSurfacePos_.find(lastFrameSurfacePo.first) == currentFrameSurfacePos_.end()) {
247                 rects.emplace_back(lastFrameSurfacePo.second);
248             }
249         }
250         for (const auto& currentFrameSurfacePo : currentFrameSurfacePos_) {
251             if (lastFrameSurfacePos_.find(currentFrameSurfacePo.first) == lastFrameSurfacePos_.end()) {
252                 rects.emplace_back(currentFrameSurfacePo.second);
253             }
254         }
255         return rects;
256     }
257 
GetCurAllSurfaces()258     std::vector<RSBaseRenderNode::SharedPtr>& GetCurAllSurfaces()
259     {
260         return curAllSurfaces_;
261     }
262 
263     void UpdateRenderParams() override;
264     void UpdatePartialRenderParams();
265     void UpdateScreenRenderParams(ScreenRenderParams& screenRenderParams);
266     void UpdateOffscreenRenderParams(bool needOffscreen);
267     void RecordMainAndLeashSurfaces(RSBaseRenderNode::SharedPtr surface);
GetAllMainAndLeashSurfaces()268     std::vector<RSBaseRenderNode::SharedPtr>& GetAllMainAndLeashSurfaces() { return curMainAndLeashSurfaceNodes_;}
GetCurAllSurfaces(bool onlyFirstLevel)269     std::vector<RSBaseRenderNode::SharedPtr>& GetCurAllSurfaces(bool onlyFirstLevel)
270     {
271         return onlyFirstLevel ? curAllFirstLevelSurfaces_ : curAllSurfaces_;
272     }
273 
274     void UpdateRotation();
275     bool IsRotationChanged() const;
IsLastRotationChanged()276     bool IsLastRotationChanged() const {
277         return lastRotationChanged;
278     }
GetPreRotationStatus()279     bool GetPreRotationStatus() const {
280         return preRotationStatus_;
281     }
GetCurRotationStatus()282     bool GetCurRotationStatus() const {
283         return curRotationStatus_;
284     }
IsFirstTimeToProcessor()285     bool IsFirstTimeToProcessor() const {
286         return isFirstTimeToProcessor_;
287     }
288 
SetOriginScreenRotation(const ScreenRotation & rotate)289     void SetOriginScreenRotation(const ScreenRotation& rotate) {
290         originScreenRotation_ = rotate;
291         isFirstTimeToProcessor_ = false;
292     }
GetOriginScreenRotation()293     ScreenRotation GetOriginScreenRotation() const {
294         return originScreenRotation_;
295     }
296 
SetInitMatrix(const Drawing::Matrix & matrix)297     void SetInitMatrix(const Drawing::Matrix& matrix) {
298         initMatrix_ = matrix;
299         isFirstTimeToProcessor_ = false;
300     }
301 
GetInitMatrix()302     const Drawing::Matrix& GetInitMatrix() const {
303         return initMatrix_;
304     }
305 
GetOffScreenCacheImgForCapture()306     std::shared_ptr<Drawing::Image> GetOffScreenCacheImgForCapture() {
307         return offScreenCacheImgForCapture_;
308     }
SetOffScreenCacheImgForCapture(std::shared_ptr<Drawing::Image> offScreenCacheImgForCapture)309     void SetOffScreenCacheImgForCapture(std::shared_ptr<Drawing::Image> offScreenCacheImgForCapture) {
310         offScreenCacheImgForCapture_ = offScreenCacheImgForCapture;
311     }
312 
313     void SetHDRPresent(bool hdrPresent);
314 
315     void SetBrightnessRatio(float brightnessRatio);
316 
GetDirtySurfaceNodeMap()317     std::map<NodeId, std::shared_ptr<RSSurfaceRenderNode>>& GetDirtySurfaceNodeMap()
318     {
319         return dirtySurfaceNodeMap_;
320     }
321 
ClearSurfaceSrcRect()322     void ClearSurfaceSrcRect()
323     {
324         surfaceSrcRects_.clear();
325     }
326 
ClearSurfaceDstRect()327     void ClearSurfaceDstRect()
328     {
329         surfaceDstRects_.clear();
330     }
331 
ClearSurfaceTotalMatrix()332     void ClearSurfaceTotalMatrix()
333     {
334         surfaceTotalMatrix_.clear();
335     }
336 
SetSurfaceSrcRect(NodeId id,RectI rect)337     void SetSurfaceSrcRect(NodeId id, RectI rect)
338     {
339         surfaceSrcRects_[id] = rect;
340     }
341 
SetSurfaceDstRect(NodeId id,RectI rect)342     void SetSurfaceDstRect(NodeId id, RectI rect)
343     {
344         surfaceDstRects_[id] = rect;
345     }
346 
SetSurfaceTotalMatrix(NodeId id,const Drawing::Matrix & totalMatrix)347     void SetSurfaceTotalMatrix(NodeId id, const Drawing::Matrix& totalMatrix)
348     {
349         surfaceTotalMatrix_[id] = totalMatrix;
350     }
351 
GetSurfaceSrcRect(NodeId id)352     RectI GetSurfaceSrcRect(NodeId id) const
353     {
354         auto iter = surfaceSrcRects_.find(id);
355         if (iter == surfaceSrcRects_.cend()) {
356             return RectI();
357         }
358 
359         return iter->second;
360     }
361 
GetSurfaceDstRect(NodeId id)362     RectI GetSurfaceDstRect(NodeId id) const
363     {
364         auto iter = surfaceDstRects_.find(id);
365         if (iter == surfaceDstRects_.cend()) {
366             return {};
367         }
368 
369         return iter->second;
370     }
371 
GetSurfaceTotalMatrix(NodeId id)372     Drawing::Matrix GetSurfaceTotalMatrix(NodeId id) const
373     {
374         auto iter = surfaceTotalMatrix_.find(id);
375         if (iter == surfaceTotalMatrix_.cend()) {
376             return {};
377         }
378 
379         return iter->second;
380     }
381 
382     void SetMainAndLeashSurfaceDirty(bool isDirty);
383 
384     // Use in MultiLayersPerf
GetSurfaceCountForMultiLayersPerf()385     size_t GetSurfaceCountForMultiLayersPerf() const
386     {
387         return surfaceCountForMultiLayersPerf_;
388     }
389 
GetLastSurfaceIds()390     const std::vector<NodeId>& GetLastSurfaceIds() const {
391         return lastSurfaceIds_;
392     }
393 
SetLastSurfaceIds(std::vector<NodeId> lastSurfaceIds)394     void SetLastSurfaceIds(std::vector<NodeId> lastSurfaceIds) {
395         lastSurfaceIds_ = std::move(lastSurfaceIds);
396     }
397 
SetScbNodePid(const std::vector<int32_t> & oldScbPids,int32_t currentScbPid)398     void SetScbNodePid(const std::vector<int32_t>& oldScbPids, int32_t currentScbPid)
399     {
400         oldScbPids_ = oldScbPids;
401         currentScbPid_ = currentScbPid;
402         isNeedWaitNewScbPid_ = true;
403         isFullChildrenListValid_ = false;
404     }
405 
GetOldScbPids()406     std::vector<int32_t> GetOldScbPids() const
407     {
408         return oldScbPids_;
409     }
410 
GetCurrentScbPid()411     int32_t GetCurrentScbPid() const
412     {
413         return currentScbPid_;
414     }
415 
416     ChildrenListSharedPtr GetSortedChildren() const override;
417 
418     Occlusion::Region GetDisappearedSurfaceRegionBelowCurrent(NodeId currentSurface) const;
419 
UpdateZoomState(bool state)420     void UpdateZoomState(bool state)
421     {
422         preZoomState_ = curZoomState_;
423         curZoomState_ = state;
424     }
425 
426     bool IsZoomStateChange() const;
427 protected:
428     void OnSync() override;
429 private:
430     explicit RSDisplayRenderNode(
431         NodeId id, const RSDisplayNodeConfig& config, const std::weak_ptr<RSContext>& context = {});
432     void InitRenderParams() override;
433     void HandleCurMainAndLeashSurfaceNodes();
434     // vector of sufacenodes will records dirtyregions by itself
435     std::vector<RSBaseRenderNode::SharedPtr> curMainAndLeashSurfaceNodes_;
436     CompositeType compositeType_ { HARDWARE_COMPOSITE };
437     ScreenRotation screenRotation_ = ScreenRotation::ROTATION_0;
438     ScreenRotation originScreenRotation_ = ScreenRotation::ROTATION_0;
439     uint64_t screenId_ = 0;
440     int32_t offsetX_ = 0;
441     int32_t offsetY_ = 0;
442     uint32_t rogWidth_ = 0;
443     uint32_t rogHeight_ = 0;
444     bool forceSoftComposite_ { false };
445     bool isMirroredDisplay_ = false;
446     bool isSecurityDisplay_ = false;
447     WeakPtr mirrorSource_;
448     float lastRotation_ = 0.f;
449     bool preRotationStatus_ = false;
450     bool curRotationStatus_ = false;
451     bool lastRotationChanged = false;
452     Drawing::Matrix initMatrix_;
453     bool isFirstTimeToProcessor_ = true;
454     bool hasFingerprint_ = false;
455 
456     std::map<NodeId, RectI> lastFrameSurfacePos_;
457     std::map<NodeId, RectI> currentFrameSurfacePos_;
458     std::vector<std::pair<NodeId, RectI>> lastFrameSurfacesByDescZOrder_;
459     std::vector<std::pair<NodeId, RectI>> currentFrameSurfacesByDescZOrder_;
460     std::shared_ptr<RSDirtyRegionManager> dirtyManager_ = nullptr;
461     std::vector<std::string> windowsName_;
462 
463     std::vector<NodeId> securityLayerList_;
464     bool isSecurityExemption_ = false;
465 
466     std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces_;
467     std::vector<RSBaseRenderNode::SharedPtr> curAllFirstLevelSurfaces_;
468     std::mutex mtx_;
469 
470     // Use in screen recording optimization
471     std::shared_ptr<Drawing::Image> offScreenCacheImgForCapture_ = nullptr;
472 
473     // Use in vulkan parallel rendering
474     bool isParallelDisplayNode_ = false;
475 
476     // Use in MultiLayersPerf
477     size_t surfaceCountForMultiLayersPerf_ = 0;
478 
479     std::map<NodeId, std::shared_ptr<RSSurfaceRenderNode>> dirtySurfaceNodeMap_;
480 
481 	// support multiscreen
482     std::map<NodeId, RectI> surfaceSrcRects_;
483     std::map<NodeId, RectI> surfaceDstRects_;
484     std::map<NodeId, Drawing::Matrix> surfaceTotalMatrix_;
485 
486     std::vector<NodeId> lastSurfaceIds_;
487 
488     std::vector<int32_t> oldScbPids_ {};
489     int32_t currentScbPid_ = -1;
490     mutable bool isNeedWaitNewScbPid_ = false;
491     mutable std::shared_ptr<std::vector<std::shared_ptr<RSRenderNode>>> currentChildrenList_ =
492         std::make_shared<std::vector<std::shared_ptr<RSRenderNode>>>();
493 
494     friend class DisplayNodeCommandHelper;
495     int64_t lastRefreshTime_ = 0;
496 
497     bool curZoomState_ = false;
498     bool preZoomState_ = false;
499 };
500 } // namespace Rosen
501 } // namespace OHOS
502 
503 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_DISPLAY_RENDER_NODE_H
504