• 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_PARAMS_RS_RENDER_THREAD_PARAMS_H
17 #define RENDER_SERVICE_BASE_PARAMS_RS_RENDER_THREAD_PARAMS_H
18 
19 #include <memory>
20 #include <vector>
21 #include "common/rs_occlusion_region.h"
22 #include "pipeline/rs_display_render_node.h"
23 #include "pipeline/rs_surface_render_node.h"
24 #include "platform/ohos/rs_jank_stats.h"
25 #include "property/rs_properties.h"
26 #include "screen_manager/rs_screen_info.h"
27 
28 namespace OHOS::Rosen {
29 struct CaptureParam {
30     bool isSnapshot_ = false;
31     bool isSingleSurface_ = false;
32     bool isMirror_ = false;
33     NodeId rootIdInWhiteList_ = INVALID_NODEID;
34     float scaleX_ = 0.0f;
35     float scaleY_ = 0.0f;
36     bool isFirstNode_ = false;
37     bool isSystemCalling_ = false;
CaptureParamCaptureParam38     CaptureParam() {}
39     CaptureParam(bool isSnapshot, bool isSingleSurface, bool isMirror,
40         float scaleX, float scaleY, bool isFirstNode = false, bool isSystemCalling = false)
isSnapshot_CaptureParam41         : isSnapshot_(isSnapshot),
42         isSingleSurface_(isSingleSurface),
43         isMirror_(isMirror),
44         scaleX_(scaleX),
45         scaleY_(scaleY),
46         isFirstNode_(isFirstNode),
47         isSystemCalling_(isSystemCalling) {}
48 };
49 class RSB_EXPORT RSRenderThreadParams {
50 public:
51     using DrawablesVec = std::vector<std::pair<NodeId,
52         DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr>>;
53 
54     RSRenderThreadParams() = default;
55     virtual ~RSRenderThreadParams() = default;
56 
IsPartialRenderEnabled()57     bool IsPartialRenderEnabled() const
58     {
59         return isPartialRenderEnabled_;
60     }
61 
IsRegionDebugEnabled()62     bool IsRegionDebugEnabled() const
63     {
64         return isRegionDebugEnabled_;
65     }
66 
IsAllSurfaceVisibleDebugEnabled()67     bool IsAllSurfaceVisibleDebugEnabled() const
68     {
69         return isAllSurfaceVisibleDebugEnabled_;
70     }
71 
IsVirtualDirtyEnabled()72     bool IsVirtualDirtyEnabled() const
73     {
74         return isVirtualDirtyEnabled_;
75     }
76 
IsExpandScreenDirtyEnabled()77     bool IsExpandScreenDirtyEnabled() const
78     {
79         return isExpandScreenDirtyEnabled_;
80     }
81 
IsVirtualDirtyDfxEnabled()82     bool IsVirtualDirtyDfxEnabled() const
83     {
84         return isVirtualDirtyDfxEnabled_;
85     }
86 
IsOpDropped()87     bool IsOpDropped() const
88     {
89         return isOpDropped_;
90     }
91 
SetOpDropped(bool opDropped)92     void SetOpDropped(bool opDropped)
93     {
94         isOpDropped_ = opDropped;
95     }
96 
GetUIFirstDebugEnabled()97     bool GetUIFirstDebugEnabled() const
98     {
99         return isUIFirstDebugEnable_;
100     }
101 
SetUIFirstCurrentFrameCanSkipFirstWait(bool canSkip)102     void SetUIFirstCurrentFrameCanSkipFirstWait(bool canSkip)
103     {
104         isUIFirstCurrentFrameCanSkipFirstWait_ = canSkip;
105     }
106 
GetUIFirstCurrentFrameCanSkipFirstWait()107     bool GetUIFirstCurrentFrameCanSkipFirstWait() const
108     {
109         return isUIFirstCurrentFrameCanSkipFirstWait_;
110     }
111 
SetTimestamp(uint64_t timestamp)112     void SetTimestamp(uint64_t timestamp)
113     {
114         timestamp_ = timestamp;
115     }
116 
GetCurrentTimestamp()117     uint64_t GetCurrentTimestamp() const
118     {
119         return timestamp_;
120     }
121 
SetActualTimestamp(int64_t timestamp)122     void SetActualTimestamp(int64_t timestamp)
123     {
124         actualTimestamp_ = timestamp;
125     }
126 
GetActualTimestamp()127     int64_t GetActualTimestamp() const
128     {
129         return actualTimestamp_;
130     }
131 
SetVsyncId(uint64_t vsyncId)132     void SetVsyncId(uint64_t vsyncId)
133     {
134         vsyncId_ = vsyncId;
135     }
136 
GetVsyncId()137     uint64_t GetVsyncId() const
138     {
139         return vsyncId_;
140     }
141 
SetForceRefreshFlag(bool isForceRefresh)142     void SetForceRefreshFlag(bool isForceRefresh)
143     {
144         isForceRefresh_ = isForceRefresh;
145     }
146 
GetForceRefreshFlag()147     bool GetForceRefreshFlag() const
148     {
149         return isForceRefresh_;
150     }
151 
GetSelfDrawables()152     const std::vector<DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr>& GetSelfDrawables() const
153     {
154         return selfDrawables_;
155     }
156 
GetHardwareEnabledTypeDrawables()157     const DrawablesVec& GetHardwareEnabledTypeDrawables() const
158     {
159         return hardwareEnabledTypeDrawables_;
160     }
161 
162 
SetPendingScreenRefreshRate(uint32_t rate)163     void SetPendingScreenRefreshRate(uint32_t rate)
164     {
165         pendingScreenRefreshRate_ = rate;
166     }
167 
GetPendingScreenRefreshRate()168     uint32_t GetPendingScreenRefreshRate() const
169     {
170         return pendingScreenRefreshRate_;
171     }
172 
SetPendingConstraintRelativeTime(uint64_t relativeTime)173     void SetPendingConstraintRelativeTime(uint64_t relativeTime)
174     {
175         pendingConstraintRelativeTime_ = relativeTime;
176     }
177 
GetPendingConstraintRelativeTime()178     uint64_t GetPendingConstraintRelativeTime() const
179     {
180         return pendingConstraintRelativeTime_;
181     }
182 
GetAccumulatedDirtyRegion()183     Occlusion::Region& GetAccumulatedDirtyRegion()
184     {
185         return accumulatedDirtyRegion_;
186     }
187 
Reset()188     bool Reset()
189     {
190         accumulatedDirtyRegion_.Reset();
191         return true;
192     }
193 
GetWatermarkFlag()194     bool GetWatermarkFlag() const
195     {
196         return watermarkFlag_;
197     }
198 
GetWatermarkImg()199     std::shared_ptr<Drawing::Image> GetWatermarkImg() const
200     {
201         return watermarkImg_;
202     }
203 
SetWatermark(bool watermarkFlag,const std::shared_ptr<Drawing::Image> & watermarkImg)204     void SetWatermark(bool watermarkFlag, const std::shared_ptr<Drawing::Image>& watermarkImg)
205     {
206         watermarkFlag_ = watermarkFlag;
207         watermarkImg_ = std::move(watermarkImg);
208     }
209 
SetOcclusionEnabled(bool isOcclusionEnabled)210     void SetOcclusionEnabled(bool isOcclusionEnabled)
211     {
212         isOcclusionEnabled_ = isOcclusionEnabled;
213     }
214 
IsOcclusionEnabled()215     bool IsOcclusionEnabled() const
216     {
217         return isOcclusionEnabled_;
218     }
219 
SetCurtainScreenUsingStatus(bool isCurtainScreenOn)220     void SetCurtainScreenUsingStatus(bool isCurtainScreenOn)
221     {
222         isCurtainScreenOn_ = isCurtainScreenOn;
223     }
224 
IsCurtainScreenOn()225     bool IsCurtainScreenOn() const
226     {
227         return isCurtainScreenOn_;
228     }
229 
SetForceCommitLayer(bool forceCommit)230     void SetForceCommitLayer(bool forceCommit)
231     {
232         isForceCommitLayer_ = forceCommit;
233     }
234 
GetForceCommitLayer()235     bool GetForceCommitLayer() const
236     {
237         return isForceCommitLayer_;
238     }
239 
SetCacheEnabledForRotation(bool flag)240     void SetCacheEnabledForRotation(bool flag)
241     {
242         cacheEnabledForRotation_ = flag;
243     }
244 
GetCacheEnabledForRotation()245     bool GetCacheEnabledForRotation() const
246     {
247         return cacheEnabledForRotation_;
248     }
249 
SetRequestNextVsyncFlag(bool flag)250     void SetRequestNextVsyncFlag(bool flag)
251     {
252         needRequestNextVsyncAnimate_ = flag;
253     }
254 
GetRequestNextVsyncFlag()255     bool GetRequestNextVsyncFlag() const
256     {
257         return needRequestNextVsyncAnimate_;
258     }
259 
SetOnVsyncStartTime(int64_t time)260     void SetOnVsyncStartTime(int64_t time)
261     {
262         onVsyncStartTime_ = time;
263     }
264 
GetOnVsyncStartTime()265     int64_t GetOnVsyncStartTime() const
266     {
267         return onVsyncStartTime_;
268     }
269 
SetOnVsyncStartTimeSteady(int64_t timeSteady)270     void SetOnVsyncStartTimeSteady(int64_t timeSteady)
271     {
272         onVsyncStartTimeSteady_ = timeSteady;
273     }
274 
GetOnVsyncStartTimeSteady()275     int64_t GetOnVsyncStartTimeSteady() const
276     {
277         return onVsyncStartTimeSteady_;
278     }
279 
SetOnVsyncStartTimeSteadyFloat(float timeSteadyFloat)280     void SetOnVsyncStartTimeSteadyFloat(float timeSteadyFloat)
281     {
282         onVsyncStartTimeSteadyFloat_ = timeSteadyFloat;
283     }
284 
GetOnVsyncStartTimeSteadyFloat()285     float GetOnVsyncStartTimeSteadyFloat() const
286     {
287         return onVsyncStartTimeSteadyFloat_;
288     }
289 
SetIsUniRenderAndOnVsync(bool isUniRenderAndOnVsync)290     void SetIsUniRenderAndOnVsync(bool isUniRenderAndOnVsync)
291     {
292         isUniRenderAndOnVsync_ = isUniRenderAndOnVsync;
293     }
294 
IsUniRenderAndOnVsync()295     bool IsUniRenderAndOnVsync() const
296     {
297         return isUniRenderAndOnVsync_;
298     }
299 
SetContext(std::shared_ptr<RSContext> context)300     void SetContext(std::shared_ptr<RSContext> context)
301     {
302         context_ = context;
303     }
304 
GetContext()305     const std::shared_ptr<RSContext> GetContext() const
306     {
307         return context_.lock();
308     }
309 
SetClipRegion(const Drawing::Region & clipRegion)310     void SetClipRegion(const Drawing::Region& clipRegion)
311     {
312         clipRegion_.Clone(clipRegion);
313     }
314 
GetClipRegion()315     const Drawing::Region& GetClipRegion() const
316     {
317         return clipRegion_;
318     }
319 
SetForceMirrorScreenDirty(bool flag)320     void SetForceMirrorScreenDirty(bool flag)
321     {
322         isMirrorScreenDirty_ = flag;
323     }
324 
GetForceMirrorScreenDirty()325     bool GetForceMirrorScreenDirty() const
326     {
327         return isMirrorScreenDirty_;
328     }
329 
SetImplicitAnimationEnd(bool isImplicitAnimationEnd)330     void SetImplicitAnimationEnd(bool isImplicitAnimationEnd)
331     {
332         isImplicitAnimationEnd_ = isImplicitAnimationEnd;
333     }
334 
GetImplicitAnimationEnd()335     bool GetImplicitAnimationEnd() const
336     {
337         return isImplicitAnimationEnd_;
338     }
339 
SetDiscardJankFrames(bool discardJankFrames)340     void SetDiscardJankFrames(bool discardJankFrames)
341     {
342         discardJankFrames_ = discardJankFrames;
343     }
344 
GetDiscardJankFrames()345     bool GetDiscardJankFrames() const
346     {
347         return discardJankFrames_;
348     }
349 
HasMirrorDisplay()350     bool HasMirrorDisplay() const
351     {
352         return hasMirrorDisplay_;
353     }
354 
SetSecExemption(bool isSecurityExemption)355     void SetSecExemption(bool isSecurityExemption)
356     {
357         isSecurityExemption_ = isSecurityExemption;
358     }
359 
GetSecExemption()360     bool GetSecExemption() const
361     {
362         return isSecurityExemption_;
363     }
364 
IsOverDrawEnabled()365     bool IsOverDrawEnabled() const
366     {
367         return isOverDrawEnabled_;
368     }
369 
IsDrawingCacheDfxEnabled()370     bool IsDrawingCacheDfxEnabled() const
371     {
372         return isDrawingCacheDfxEnabled_;
373     }
374 
IsAceDebugBoundaryEnabled()375     bool IsAceDebugBoundaryEnabled() const
376     {
377         return isAceDebugBoundaryEnabled_;
378     }
GetScreenInfo()379     const ScreenInfo& GetScreenInfo() const
380     {
381         return screenInfo_;
382     }
383 
SetScreenInfo(const ScreenInfo & info)384     void SetScreenInfo(const ScreenInfo& info)
385     {
386         screenInfo_ = info;
387     }
388 
IsMirrorScreen()389     bool IsMirrorScreen() const
390     {
391         return isMirrorScreen_;
392     }
393 
SetIsMirrorScreen(bool isMirrorScreen)394     void SetIsMirrorScreen(bool isMirrorScreen)
395     {
396         isMirrorScreen_ = isMirrorScreen;
397     }
398 
GetCompositeType()399     RSDisplayRenderNode::CompositeType GetCompositeType() const
400     {
401         return compositeType_;
402     }
403 
SetCompositeType(RSDisplayRenderNode::CompositeType type)404     void SetCompositeType(RSDisplayRenderNode::CompositeType type)
405     {
406         compositeType_ = type;
407     }
408 
409 private:
410     // Used by hardware thred
411     uint64_t timestamp_ = 0;
412     int64_t actualTimestamp_ = 0;
413     uint64_t vsyncId_ = 0;
414     bool isForceRefresh_ = false;
415     uint32_t pendingScreenRefreshRate_ = 0;
416     uint64_t pendingConstraintRelativeTime_ = 0;
417     // RSDirtyRectsDfx dfx
418     std::vector<std::string> dfxTargetSurfaceNames_;
419     bool isRegionDebugEnabled_ = false;
420     bool isPartialRenderEnabled_ = false;
421     bool isDirtyRegionDfxEnabled_ = false;
422     bool isTargetDirtyRegionDfxEnabled_ = false;
423     bool isDisplayDirtyDfxEnabled_ = false;
424     bool isOpaqueRegionDfxEnabled_ = false;
425     bool isVisibleRegionDfxEnabled_ = false;
426     bool isAllSurfaceVisibleDebugEnabled_ = false;
427     bool isOpDropped_ = false;
428     bool isOcclusionEnabled_ = false;
429     bool isUIFirstDebugEnable_ = false;
430     bool isUIFirstCurrentFrameCanSkipFirstWait_ = false;
431     bool isVirtualDirtyDfxEnabled_ = false;
432     bool isVirtualDirtyEnabled_ = false;
433     bool isExpandScreenDirtyEnabled_ = false;
434     bool isMirrorScreenDirty_ = false;
435     bool cacheEnabledForRotation_ = false;
436     DirtyRegionDebugType dirtyRegionDebugType_ = DirtyRegionDebugType::DISABLED;
437     std::vector<DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr> selfDrawables_;
438     DrawablesVec hardwareEnabledTypeDrawables_;
439     bool isForceCommitLayer_ = false;
440     bool hasMirrorDisplay_ = false;
441     // accumulatedDirtyRegion to decide whether to skip tranasparent nodes.
442     Occlusion::Region accumulatedDirtyRegion_;
443     bool watermarkFlag_ = false;
444     std::shared_ptr<Drawing::Image> watermarkImg_ = nullptr;
445 
446     bool needRequestNextVsyncAnimate_ = false;
447     bool isOverDrawEnabled_ = false;
448     bool isDrawingCacheDfxEnabled_ = false;
449 
450     int64_t onVsyncStartTime_ = TIMESTAMP_INITIAL;
451     int64_t onVsyncStartTimeSteady_ = TIMESTAMP_INITIAL;
452     float onVsyncStartTimeSteadyFloat_ = TIMESTAMP_INITIAL_FLOAT;
453     bool isUniRenderAndOnVsync_ = false;
454     std::weak_ptr<RSContext> context_;
455     bool isCurtainScreenOn_ = false;
456     bool isAceDebugBoundaryEnabled_ = false;
457     RSDisplayRenderNode::CompositeType compositeType_ = RSDisplayRenderNode::CompositeType::HARDWARE_COMPOSITE;
458     bool isMirrorScreen_ = false;
459 
460     Drawing::Region clipRegion_;
461     bool isImplicitAnimationEnd_ = false;
462     bool discardJankFrames_ = false;
463 
464     bool isSecurityExemption_ = false;
465     ScreenInfo screenInfo_ = {};
466 
467     friend class RSMainThread;
468     friend class RSUniRenderVisitor;
469     friend class RSDirtyRectsDfx;
470 };
471 
472 class RSRenderThreadParamsManager {
473 public:
474     RSRenderThreadParamsManager() = default;
475     ~RSRenderThreadParamsManager() = default;
476 
Instance()477     static RSRenderThreadParamsManager& Instance()
478     {
479         static RSRenderThreadParamsManager instance;
480         return instance;
481     }
482 
SetRSRenderThreadParams(std::unique_ptr<RSRenderThreadParams> && renderThreadParams)483     inline void SetRSRenderThreadParams(std::unique_ptr<RSRenderThreadParams>&& renderThreadParams)
484     {
485         renderThreadParams_ = std::move(renderThreadParams);
486     }
GetRSRenderThreadParams()487     inline const std::unique_ptr<RSRenderThreadParams>& GetRSRenderThreadParams() const
488     {
489         return renderThreadParams_;
490     }
491 
492 private:
493     static inline thread_local std::unique_ptr<RSRenderThreadParams> renderThreadParams_ = nullptr;
494 };
495 } // namespace OHOS::Rosen
496 #endif // RENDER_SERVICE_BASE_PARAMS_RS_RENDER_THREAD_PARAMS_H
497