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