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