• 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 #ifndef ROSEN_CROSS_PLATFORM
21 #include <ibuffer_consumer_listener.h>
22 #include <iconsumer_surface.h>
23 #include <surface.h>
24 #include "sync_fence.h"
25 #endif
26 
27 #include "common/rs_macros.h"
28 #include "memory/rs_memory_track.h"
29 #include "pipeline/rs_render_node.h"
30 #include "pipeline/rs_surface_handler.h"
31 #include <screen_manager/screen_types.h>
32 #ifdef NEW_RENDER_CONTEXT
33 #include "rs_render_surface.h"
34 #else
35 #include "platform/drawing/rs_surface.h"
36 #endif
37 
38 namespace OHOS {
39 namespace Rosen {
40 class RSB_EXPORT RSDisplayRenderNode : public RSRenderNode, public RSSurfaceHandler {
41 public:
42     enum CompositeType {
43         UNI_RENDER_COMPOSITE = 0,
44         UNI_RENDER_MIRROR_COMPOSITE,
45         UNI_RENDER_EXPAND_COMPOSITE,
46         HARDWARE_COMPOSITE,
47         SOFTWARE_COMPOSITE
48     };
49     using WeakPtr = std::weak_ptr<RSDisplayRenderNode>;
50     using SharedPtr = std::shared_ptr<RSDisplayRenderNode>;
51     static inline constexpr RSRenderNodeType Type = RSRenderNodeType::DISPLAY_NODE;
52 
53     explicit RSDisplayRenderNode(
54         NodeId id, const RSDisplayNodeConfig& config, const std::weak_ptr<RSContext>& context = {});
55     ~RSDisplayRenderNode() override;
56     void SetIsOnTheTree(bool flag, NodeId instanceRootNodeId = INVALID_NODEID,
57         NodeId firstLevelNodeId = INVALID_NODEID, NodeId cacheNodeId = INVALID_NODEID) override;
58 
SetScreenId(uint64_t screenId)59     void SetScreenId(uint64_t screenId)
60     {
61         screenId_ = screenId;
62     }
63 
GetScreenId()64     uint64_t GetScreenId() const
65     {
66         return screenId_;
67     }
68 
SetRogSize(uint32_t rogWidth,uint32_t rogHeight)69     void SetRogSize(uint32_t rogWidth, uint32_t rogHeight)
70     {
71         rogWidth_ = rogWidth;
72         rogHeight_ = rogHeight;
73     }
74 
GetRogWidth()75     uint32_t GetRogWidth() const
76     {
77         return rogWidth_;
78     }
79 
GetRogHeight()80     uint32_t GetRogHeight() const
81     {
82         return rogHeight_;
83     }
84 
SetDisplayOffset(int32_t offsetX,int32_t offsetY)85     void SetDisplayOffset(int32_t offsetX, int32_t offsetY)
86     {
87         offsetX_ = offsetX;
88         offsetY_ = offsetY;
89     }
90 
GetDisplayOffsetX()91     int32_t GetDisplayOffsetX() const
92     {
93         return offsetX_;
94     }
95 
GetDisplayOffsetY()96     int32_t GetDisplayOffsetY() const
97     {
98         return offsetY_;
99     }
100 
GetFingerprint()101     bool GetFingerprint() const
102     {
103         return hasFingerprint_;
104     }
105 
SetFingerprint(bool hasFingerprint)106     void SetFingerprint(bool hasFingerprint)
107     {
108         hasFingerprint_ = hasFingerprint;
109     }
110 
SetScreenRotation(const ScreenRotation & screenRotation)111     void SetScreenRotation(const ScreenRotation& screenRotation)
112     {
113         screenRotation_ = screenRotation;
114     }
115 
GetScreenRotation()116     ScreenRotation GetScreenRotation()
117     {
118         return screenRotation_;
119     }
120 
121     void CollectSurface(
122         const std::shared_ptr<RSBaseRenderNode>& node, std::vector<RSBaseRenderNode::SharedPtr>& vec,
123         bool isUniRender, bool onlyFirstLevel) override;
124     void Prepare(const std::shared_ptr<RSNodeVisitor>& visitor) override;
125     void Process(const std::shared_ptr<RSNodeVisitor>& visitor) override;
126 
GetType()127     RSRenderNodeType GetType() const override
128     {
129         return RSRenderNodeType::DISPLAY_NODE;
130     }
131 
132     bool IsMirrorDisplay() const;
133 
134     void SetCompositeType(CompositeType type);
135     CompositeType GetCompositeType() const;
136     void SetForceSoftComposite(bool flag);
137     bool IsForceSoftComposite() const;
138     void SetMirrorSource(SharedPtr node);
139     void ResetMirrorSource();
140     void SetIsMirrorDisplay(bool isMirror);
141     void SetSecurityDisplay(bool isSecurityDisplay);
142     bool GetSecurityDisplay() const;
143     bool SkipFrame(uint32_t skipFrameInterval);
144     void SetBootAnimation(bool isBootAnimation) override;
145     bool GetBootAnimation() const override;
GetMirrorSource()146     WeakPtr GetMirrorSource() const
147     {
148         return mirrorSource_;
149     }
150 
HasDisappearingTransition(bool)151     bool HasDisappearingTransition(bool) const override
152     {
153         return false;
154     }
155 #ifdef NEW_RENDER_CONTEXT
GetRSSurface()156     std::shared_ptr<RSRenderSurface> GetRSSurface() const
157     {
158         return surface_;
159     }
160 #else
GetRSSurface()161     std::shared_ptr<RSSurface> GetRSSurface() const
162     {
163         return surface_;
164     }
165 #endif
166     // Use in vulkan parallel rendering
SetIsParallelDisplayNode(bool isParallelDisplayNode)167     void SetIsParallelDisplayNode(bool isParallelDisplayNode)
168     {
169         isParallelDisplayNode_ = isParallelDisplayNode;
170     }
171 
IsParallelDisplayNode()172     bool IsParallelDisplayNode() const
173     {
174         return isParallelDisplayNode_;
175     }
176 
177 #ifndef ROSEN_CROSS_PLATFORM
178     bool CreateSurface(sptr<IBufferConsumerListener> listener);
GetConsumerListener()179     sptr<IBufferConsumerListener> GetConsumerListener() const
180     {
181         return consumerListener_;
182     }
183 #endif
184 
IsSurfaceCreated()185     bool IsSurfaceCreated() const
186     {
187         return surfaceCreated_;
188     }
189 
190     ScreenRotation GetRotation() const;
191 
GetDirtyManager()192     std::shared_ptr<RSDirtyRegionManager> GetDirtyManager()
193     {
194         return dirtyManager_;
195     }
196     void UpdateDisplayDirtyManager(int32_t bufferage, bool useAlignedDirtyRegion = false);
197     void ClearCurrentSurfacePos();
UpdateSurfaceNodePos(NodeId id,RectI rect)198     void UpdateSurfaceNodePos(NodeId id, RectI rect)
199     {
200 #if defined(RS_ENABLE_PARALLEL_RENDER) && (defined (RS_ENABLE_GL) || defined (RS_ENABLE_VK))
201         std::unique_lock<std::mutex> lock(mtx_);
202         currentFrameSurfacePos_[id] = rect;
203 #else
204         currentFrameSurfacePos_[id] = rect;
205 #endif
206     }
207 
GetLastFrameSurfacePos(NodeId id)208     RectI GetLastFrameSurfacePos(NodeId id)
209     {
210         if (lastFrameSurfacePos_.count(id) == 0) {
211             return RectI();
212         }
213         return lastFrameSurfacePos_[id];
214     }
215 
GetCurrentFrameSurfacePos(NodeId id)216     RectI GetCurrentFrameSurfacePos(NodeId id)
217     {
218         if (currentFrameSurfacePos_.count(id) == 0) {
219             return RectI();
220         }
221         return currentFrameSurfacePos_[id];
222     }
223 
GetSurfaceChangedRects()224     const std::vector<RectI> GetSurfaceChangedRects() const
225     {
226         std::vector<RectI> rects;
227         for (auto iter = lastFrameSurfacePos_.begin(); iter != lastFrameSurfacePos_.end(); iter++) {
228             if (currentFrameSurfacePos_.find(iter->first) == currentFrameSurfacePos_.end()) {
229                 rects.emplace_back(iter->second);
230             }
231         }
232         for (auto iter = currentFrameSurfacePos_.begin(); iter != currentFrameSurfacePos_.end(); iter++) {
233             if (lastFrameSurfacePos_.find(iter->first) == lastFrameSurfacePos_.end()) {
234                 rects.emplace_back(iter->second);
235             }
236         }
237         return rects;
238     }
239 
GetCurAllSurfaces()240     std::vector<RSBaseRenderNode::SharedPtr>& GetCurAllSurfaces()
241     {
242         return curAllSurfaces_;
243     }
244 
245     void UpdateRotation();
246     bool IsRotationChanged() const;
IsFirstTimeToProcessor()247     bool IsFirstTimeToProcessor() const {
248         return isFirstTimeToProcessor_;
249     }
250 
SetOriginScreenRotation(const ScreenRotation & rotate)251     void SetOriginScreenRotation(const ScreenRotation& rotate) {
252         originScreenRotation_ = rotate;
253         isFirstTimeToProcessor_ = false;
254     }
GetOriginScreenRotation()255     ScreenRotation GetOriginScreenRotation() const {
256         return originScreenRotation_;
257     }
258 
259 #ifndef USE_ROSEN_DRAWING
SetInitMatrix(const SkMatrix & skMatrix)260     void SetInitMatrix(const SkMatrix& skMatrix) {
261         initMatrix_ = skMatrix;
262 #else
263     void SetInitMatrix(const Drawing::Matrix& matrix) {
264         initMatrix_ = matrix;
265 #endif
266         isFirstTimeToProcessor_ = false;
267     }
268 
269 #ifndef USE_ROSEN_DRAWING
270     const SkMatrix& GetInitMatrix() const {
271 #else
272     const Drawing::Matrix& GetInitMatrix() const {
273 #endif
274         return initMatrix_;
275     }
276 
277 #ifndef USE_ROSEN_DRAWING
278     sk_sp<SkImage> GetCacheImgForCapture() {
279         std::unique_lock<std::mutex> lock(mtx_);
280         return cacheImgForCapture_;
281     }
282     void SetCacheImgForCapture(sk_sp<SkImage> cacheImgForCapture) {
283         std::unique_lock<std::mutex> lock(mtx_);
284         cacheImgForCapture_ = cacheImgForCapture;
285     }
286 #else
287     std::shared_ptr<Drawing::Image> GetCacheImgForCapture() {
288         std::unique_lock<std::mutex> lock(mtx_);
289         return cacheImgForCapture_;
290     }
291     void SetCacheImgForCapture(std::shared_ptr<Drawing::Image> cacheImgForCapture) {
292         std::unique_lock<std::mutex> lock(mtx_);
293         cacheImgForCapture_ = cacheImgForCapture;
294     }
295 #endif
296     NodeId GetRootIdOfCaptureWindow() {
297         return rootIdOfCaptureWindow_;
298     }
299     void SetRootIdOfCaptureWindow(NodeId rootIdOfCaptureWindow) {
300         rootIdOfCaptureWindow_ = rootIdOfCaptureWindow;
301     }
302 
303 private:
304     CompositeType compositeType_ { HARDWARE_COMPOSITE };
305     ScreenRotation screenRotation_ = ScreenRotation::ROTATION_0;
306     ScreenRotation originScreenRotation_ = ScreenRotation::ROTATION_0;
307     uint64_t screenId_;
308     int32_t offsetX_;
309     int32_t offsetY_;
310     uint32_t rogWidth_;
311     uint32_t rogHeight_;
312     bool forceSoftComposite_ { false };
313     bool isMirroredDisplay_ = false;
314     bool isSecurityDisplay_ = false;
315     WeakPtr mirrorSource_;
316     float lastRotation_ = 0.f;
317 #ifndef USE_ROSEN_DRAWING
318     SkMatrix initMatrix_;
319 #else
320     Drawing::Matrix initMatrix_;
321 #endif
322     bool isFirstTimeToProcessor_ = true;
323 #ifdef NEW_RENDER_CONTEXT
324     std::shared_ptr<RSRenderSurface> surface_;
325 #else
326     std::shared_ptr<RSSurface> surface_;
327 #endif
328     bool surfaceCreated_ { false };
329     bool hasFingerprint_ = false;
330 #ifndef ROSEN_CROSS_PLATFORM
331     sptr<IBufferConsumerListener> consumerListener_;
332 #endif
333     uint64_t frameCount_ = 0;
334 
335     std::map<NodeId, RectI> lastFrameSurfacePos_;
336     std::map<NodeId, RectI> currentFrameSurfacePos_;
337     std::shared_ptr<RSDirtyRegionManager> dirtyManager_ = nullptr;
338 
339     std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces_;
340     std::mutex mtx_;
341 
342     // Use in screen recording optimization
343 #ifndef USE_ROSEN_DRAWING
344     sk_sp<SkImage> cacheImgForCapture_ = nullptr;
345 #else
346     std::shared_ptr<Drawing::Image> cacheImgForCapture_ = nullptr;
347 #endif
348     NodeId rootIdOfCaptureWindow_ = INVALID_NODEID;
349 
350     // Use in vulkan parallel rendering
351     bool isParallelDisplayNode_ = false;
352 };
353 } // namespace Rosen
354 } // namespace OHOS
355 
356 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_DISPLAY_RENDER_NODE_H
357