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