• 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_PARAMS_H
17 #define RENDER_SERVICE_BASE_PARAMS_RS_RENDER_PARAMS_H
18 
19 #include "common/rs_common_def.h"
20 #include "common/rs_occlusion_region.h"
21 #include "common/rs_rect.h"
22 #include "drawable/rs_render_node_drawable_adapter.h"
23 #include "pipeline/rs_render_node.h"
24 #include "property/rs_properties.h"
25 #include "screen_manager/screen_types.h"
26 #include "utils/matrix.h"
27 #include "utils/region.h"
28 
29 #ifndef ROSEN_CROSS_PLATFORM
30 #include <iconsumer_surface.h>
31 #include <surface.h>
32 #include "sync_fence.h"
33 #endif
34 
35 namespace OHOS::Rosen {
36 #define RENDER_BASIC_PARAM_TO_STRING(basicType) (std::string(#basicType "[") + std::to_string(basicType) + "] ")
37 #define RENDER_RECT_PARAM_TO_STRING(rect) (std::string(#rect "[") + (rect).ToString() + "] ")
38 #define RENDER_PARAM_TO_STRING(param) (std::string(#param "[") + (param).ToString() + "] ")
39 
40 struct DirtyRegionInfoForDFX {
41     RectI oldDirty;
42     RectI oldDirtyInSurface;
43     bool operator==(const DirtyRegionInfoForDFX& rhs) const
44     {
45         return oldDirty == rhs.oldDirty && oldDirtyInSurface == rhs.oldDirtyInSurface;
46     }
47 };
48 struct RSLayerInfo;
49 
50 typedef enum {
51     RS_PARAM_DEFAULT,
52     RS_PARAM_OWNED_BY_NODE,
53     RS_PARAM_OWNED_BY_DRAWABLE,
54     RS_PARAM_OWNED_BY_DRAWABLE_UIFIRST,
55     RS_PARAM_INVALID,
56 } RSRenderParamsType;
57 
58 class RSB_EXPORT RSRenderParams {
59 public:
RSRenderParams(NodeId id)60     RSRenderParams(NodeId id) : id_(id) {}
61     virtual ~RSRenderParams() = default;
62 
63     struct SurfaceParam {
64         int width = 0;
65         int height = 0;
66         GraphicColorGamut colorSpace = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB;
67     };
68 
69     void SetDirtyType(RSRenderParamsDirtyType dirtyType);
70 
71     void SetAlpha(float alpha);
GetAlpha()72     float GetAlpha() const
73     {
74         return alpha_;
75     }
76 
77     void SetAlphaOffScreen(bool alphaOffScreen);
78     bool GetAlphaOffScreen() const;
79 
80     void SetMatrix(const Drawing::Matrix& matrix);
GetMatrix()81     const Drawing::Matrix& GetMatrix() const
82     {
83         return matrix_;
84     }
85 
86     void ApplyAlphaAndMatrixToCanvas(RSPaintFilterCanvas& canvas, bool applyMatrix = true) const;
87 
88     void SetBoundsRect(const Drawing::RectF& boundsRect);
GetBounds()89     const Drawing::Rect& GetBounds() const
90     {
91         return boundsRect_;
92     }
93 
94     void SetFrameRect(const Drawing::RectF& frameRect);
GetFrameRect()95     const Drawing::Rect& GetFrameRect() const
96     {
97         return frameRect_;
98     }
99 
100     // return to add some dirtynode does not mark pending
101     bool SetLocalDrawRect(const RectF& localDrawRect);
GetLocalDrawRect()102     const RectF& GetLocalDrawRect() const
103     {
104         return localDrawRect_;
105     }
106 
107     void SetHasSandBox(bool hasSandBox);
HasSandBox()108     bool HasSandBox() const
109     {
110         return hasSandBox_;
111     }
112 
GetShouldPaint()113     bool GetShouldPaint() const
114     {
115         return shouldPaint_ && !contentEmpty_;
116     }
117     void SetShouldPaint(bool shouldPaint);
118     void SetContentEmpty(bool empty);
119 
NeedSync()120     bool NeedSync() const
121     {
122         return needSync_;
123     }
124     void SetNeedSync(bool needSync);
125 
GetForegroundFilterCache()126     const std::shared_ptr<RSFilter>& GetForegroundFilterCache() const
127     {
128         return foregroundFilterCache_;
129     }
130     void SetForegroundFilterCache(const std::shared_ptr<RSFilter>& foregroundFilterCache);
131 
GetId()132     inline NodeId GetId() const
133     {
134         return id_;
135     }
136 
SetParamsType(RSRenderParamsType paramsType)137     void SetParamsType(RSRenderParamsType paramsType)
138     {
139         paramsType_ = paramsType;
140     }
141 
GetParamsType()142     inline RSRenderParamsType GetParamsType() const
143     {
144         return paramsType_;
145     }
146 
GetFrameGravity()147     Gravity GetFrameGravity() const
148     {
149         return frameGravity_;
150     }
151 
152     void SetFrameGravity(Gravity gravity);
153 
154     void SetHDRBrightness(float hdrBrightness);
155 
GetHDRBrightness()156     inline float GetHDRBrightness() const
157     {
158         return hdrBrightness_;
159     }
160 
161     void SetNeedFilter(bool needFilter);
162 
NeedFilter()163     inline bool NeedFilter() const
164     {
165         return needFilter_;
166     }
167 
168     void SetNodeType(RSRenderNodeType type);
GetType()169     inline RSRenderNodeType GetType() const
170     {
171         return renderNodeType_;
172     }
173 
174     void SetEffectNodeShouldPaint(bool effectNodeShouldPaint);
GetEffectNodeShouldPaint()175     inline bool GetEffectNodeShouldPaint() const
176     {
177         return effectNodeShouldPaint_;
178     }
179 
180     void SetHasGlobalCorner(bool hasGlobalCorner);
HasGlobalCorner()181     inline bool HasGlobalCorner() const
182     {
183         return hasGlobalCorner_;
184     }
185 
186     void SetHasBlurFilter(bool hasBlurFilter);
HasBlurFilter()187     inline bool HasBlurFilter() const
188     {
189         return hasBlurFilter_;
190     }
191 
192     void SetGlobalAlpha(float alpha);
GetGlobalAlpha()193     inline float GetGlobalAlpha() const
194     {
195         return globalAlpha_;
196     }
197 
NodeGroupHasChildInBlacklist()198     inline bool NodeGroupHasChildInBlacklist() const
199     {
200         return isNodeGroupHasChildInBlacklist_;
201     }
202 
SetNodeGroupHasChildInBlacklist(bool isInBlackList)203     inline void SetNodeGroupHasChildInBlacklist(bool isInBlackList)
204     {
205         isNodeGroupHasChildInBlacklist_ = isInBlackList;
206     }
207 
IsSnapshotSkipLayer()208     inline bool IsSnapshotSkipLayer() const
209     {
210         return isSnapshotSkipLayer_;
211     }
212 
IsLayerDirty()213     inline bool IsLayerDirty() const
214     {
215         return dirtyType_.test(RSRenderParamsDirtyType::LAYER_INFO_DIRTY);
216     }
217 
IsBufferDirty()218     inline bool IsBufferDirty() const
219     {
220         return dirtyType_.test(RSRenderParamsDirtyType::BUFFER_INFO_DIRTY);
221     }
222 
223     void SetChildHasVisibleFilter(bool val);
ChildHasVisibleFilter()224     bool ChildHasVisibleFilter() const
225     {
226         return childHasVisibleFilter_;
227     }
228     void SetChildHasVisibleEffect(bool val);
ChildHasVisibleEffect()229     bool ChildHasVisibleEffect() const
230     {
231         return childHasVisibleEffect_;
232     }
233 
234     void SetCacheSize(Vector2f size);
GetCacheSize()235     inline Vector2f GetCacheSize() const
236     {
237         return cacheSize_;
238     }
239 
240     void SetDrawingCacheChanged(bool isChanged, bool lastFrameSynced);
GetDrawingCacheChanged()241     bool GetDrawingCacheChanged() const
242     {
243         return isDrawingCacheChanged_;
244     }
SetNeedUpdateCache(bool needUpdateCache)245     void SetNeedUpdateCache(bool needUpdateCache)
246     {
247         isNeedUpdateCache_ = needUpdateCache;
248     }
GetNeedUpdateCache()249     bool GetNeedUpdateCache() const
250     {
251         return isNeedUpdateCache_;
252     }
253 
254     void SetDrawingCacheType(RSDrawingCacheType cacheType);
GetDrawingCacheType()255     RSDrawingCacheType GetDrawingCacheType() const
256     {
257         return drawingCacheType_;
258     }
259 
260     void OpincSetIsSuggest(bool isSuggest);
OpincIsSuggest()261     bool OpincIsSuggest() const
262     {
263         return isOpincSuggestFlag_;
264     }
265     void OpincUpdateSupportFlag(bool supportFlag);
OpincGetSupportFlag()266     bool OpincGetSupportFlag() const
267     {
268         return isOpincSupportFlag_;
269     }
270     void OpincUpdateRootFlag(bool suggestFlag);
OpincGetRootFlag()271     bool OpincGetRootFlag() const
272     {
273         return isOpincRootFlag_;
274     }
275     void OpincSetCacheChangeFlag(bool state, bool lastFrameSynced);
OpincGetCacheChangeState()276     bool OpincGetCacheChangeState()
277     {
278         bool state = isOpincStateChanged_;
279         isOpincStateChanged_ = false;
280         return state;
281     }
282 
283     void SetDrawingCacheIncludeProperty(bool includeProperty);
GetDrawingCacheIncludeProperty()284     bool GetDrawingCacheIncludeProperty() const
285     {
286         return drawingCacheIncludeProperty_;
287     }
288 
289     void SetRSFreezeFlag(bool freezeFlag);
GetRSFreezeFlag()290     bool GetRSFreezeFlag() const
291     {
292         return freezeFlag_;
293     }
294     void SetShadowRect(Drawing::Rect rect);
GetShadowRect()295     Drawing::Rect GetShadowRect() const
296     {
297         return shadowRect_;
298     }
299 
300     // One-time trigger, needs to be manually reset false in main/RT thread after each sync operation
301     void OnCanvasDrawingSurfaceChange(const std::unique_ptr<RSRenderParams>& target);
GetCanvasDrawingSurfaceChanged()302     bool GetCanvasDrawingSurfaceChanged() const
303     {
304         return canvasDrawingNodeSurfaceChanged_;
305     }
306     void SetCanvasDrawingSurfaceChanged(bool changeFlag);
GetCanvasDrawingSurfaceParams()307     SurfaceParam GetCanvasDrawingSurfaceParams()
308     {
309         return surfaceParams_;
310     }
311     void SetCanvasDrawingSurfaceParams(int width, int height,
312         GraphicColorGamut colorSpace = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB);
313 
SetStartingWindowFlag(bool b)314     void SetStartingWindowFlag(bool b)
315     {
316         if (startingWindowFlag_ == b) {
317             return;
318         }
319         startingWindowFlag_ = b;
320         needSync_ = true;
321     }
322 
GetStartingWindowFlag()323     bool GetStartingWindowFlag() const
324     {
325         return startingWindowFlag_;
326     }
327 
328     bool IsRepaintBoundary() const;
329     void MarkRepaintBoundary(bool isRepaintBoundary);
330 
331     bool SetFirstLevelNode(NodeId firstLevelNodeId);
GetFirstLevelNodeId()332     NodeId GetFirstLevelNodeId() const
333     {
334         return firstLevelNodeId_;
335     }
336     bool SetUiFirstRootNode(NodeId uifirstRootNodeId);
GetUifirstRootNodeId()337     NodeId GetUifirstRootNodeId() const
338     {
339         return uifirstRootNodeId_;
340     }
341 
342     // disable copy and move
343     RSRenderParams(const RSRenderParams&) = delete;
344     RSRenderParams(RSRenderParams&&) = delete;
345     RSRenderParams& operator=(const RSRenderParams&) = delete;
346     RSRenderParams& operator=(RSRenderParams&&) = delete;
347 
348     virtual void OnSync(const std::unique_ptr<RSRenderParams>& target);
349 
350     // dfx
351     virtual std::string ToString() const;
352 
353     static void SetParentSurfaceMatrix(const Drawing::Matrix& parentSurfaceMatrix);
354     static const Drawing::Matrix& GetParentSurfaceMatrix();
355 
356     // overrided surface params
357 #ifndef ROSEN_CROSS_PLATFORM
SetBuffer(const sptr<SurfaceBuffer> & buffer,const Rect & damageRect)358     virtual void SetBuffer(const sptr<SurfaceBuffer>& buffer, const Rect& damageRect) {}
GetBuffer()359     virtual sptr<SurfaceBuffer> GetBuffer() const { return nullptr; }
SetPreBuffer(const sptr<SurfaceBuffer> & preBuffer)360     virtual void SetPreBuffer(const sptr<SurfaceBuffer>& preBuffer) {}
GetPreBuffer()361     virtual sptr<SurfaceBuffer> GetPreBuffer() { return nullptr; }
SetAcquireFence(const sptr<SyncFence> & acquireFence)362     virtual void SetAcquireFence(const sptr<SyncFence>& acquireFence) {}
GetAcquireFence()363     virtual sptr<SyncFence> GetAcquireFence() const { return nullptr; }
GetBufferDamage()364     virtual const Rect& GetBufferDamage() const
365     {
366         static const Rect defaultRect = {};
367         return defaultRect;
368     }
369 #endif
370     virtual const RSLayerInfo& GetLayerInfo() const;
GetAbsDrawRect()371     virtual const RectI& GetAbsDrawRect() const
372     {
373         return absDrawRect_;
374     }
375 
SetAbsDrawRect(const RectI & absRect)376     void SetAbsDrawRect(const RectI& absRect)
377     {
378         absDrawRect_ = absRect;
379     }
380 
381     // surface params
GetOcclusionVisible()382     virtual bool GetOcclusionVisible() const { return true; }
IsLeashWindow()383     virtual bool IsLeashWindow() const { return true; }
IsAppWindow()384     virtual bool IsAppWindow() const { return false; }
GetHardwareEnabled()385     virtual bool GetHardwareEnabled() const { return false; }
GetNeedMakeImage()386     virtual bool GetNeedMakeImage() const { return false; }
GetHardCursorStatus()387     virtual bool GetHardCursorStatus() const { return false; }
GetLayerCreated()388     virtual bool GetLayerCreated() const { return false; }
GetLastFrameHardwareEnabled()389     virtual bool GetLastFrameHardwareEnabled() const { return false; }
SetLayerCreated(bool layerCreated)390     virtual void SetLayerCreated(bool layerCreated) {}
SetOldDirtyInSurface(const RectI & oldDirtyInSurface)391     virtual void SetOldDirtyInSurface(const RectI& oldDirtyInSurface) {}
GetOldDirtyInSurface()392     virtual RectI GetOldDirtyInSurface() const { return {}; }
393 
394     // overrided by displayNode
GetAllMainAndLeashSurfaceDrawables()395     virtual std::vector<DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr>& GetAllMainAndLeashSurfaceDrawables()
396     {
397         static std::vector<DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr> defaultSurfaceVector;
398         return defaultSurfaceVector;
399     }
400 
GetVisibleRegion()401     virtual Occlusion::Region GetVisibleRegion() const
402     {
403         return {};
404     }
405 
SetRotationChanged(bool changed)406     virtual void SetRotationChanged(bool changed) {}
IsRotationChanged()407     virtual bool IsRotationChanged() const
408     {
409         return false;
410     }
411 
GetScreenRotation()412     virtual ScreenRotation GetScreenRotation() const
413     {
414         return ScreenRotation::ROTATION_0;
415     }
SetTotalMatrix(const Drawing::Matrix & totalMatrix)416     virtual void SetTotalMatrix(const Drawing::Matrix& totalMatrix) {}
417     virtual const Drawing::Matrix& GetTotalMatrix();
SetNeedClient(bool needClient)418     virtual void SetNeedClient(bool needClient) {}
GetNeedClient()419     virtual bool GetNeedClient() const { return false; }
GetFingerprint()420     virtual bool GetFingerprint() { return false; }
SetFingerprint(bool hasFingerprint)421     virtual void SetFingerprint(bool hasFingerprint) {}
422     // virtual display params
423     virtual DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr GetMirrorSourceDrawable();
GetCloneSourceDrawable()424     DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr GetCloneSourceDrawable() const
425     {
426         return cloneSourceDrawable_;
427     }
428     void SetCloneSourceDrawable(DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr drawable);
429     // canvas drawing node
IsNeedProcess()430     virtual bool IsNeedProcess() const { return true; }
SetNeedProcess(bool isNeedProcess)431     virtual void SetNeedProcess(bool isNeedProcess) {}
IsFirstLevelCrossNode()432     virtual bool IsFirstLevelCrossNode() const { return isFirstLevelCrossNode_; }
SetFirstLevelCrossNode(bool firstLevelCrossNode)433     virtual void SetFirstLevelCrossNode(bool firstLevelCrossNode) { isFirstLevelCrossNode_ = firstLevelCrossNode; }
GetCrossNodeOffScreenStatus()434     CrossNodeOffScreenRenderDebugType GetCrossNodeOffScreenStatus() const
435     {
436         return isCrossNodeOffscreenOn_;
437     }
SetCrossNodeOffScreenStatus(CrossNodeOffScreenRenderDebugType isCrossNodeOffScreenOn)438     void SetCrossNodeOffScreenStatus(CrossNodeOffScreenRenderDebugType isCrossNodeOffScreenOn)
439     {
440         isCrossNodeOffscreenOn_ = isCrossNodeOffScreenOn;
441     }
442 
SetAbsRotation(float degree)443     void SetAbsRotation(float degree)
444     {
445         absRotation_ = degree;
446     }
447 
GetAbsRotation()448     float GetAbsRotation() const
449     {
450         return absRotation_;
451     }
452 
HasUnobscuredUEC()453     bool HasUnobscuredUEC() const
454     {
455         return hasUnobscuredUEC_;
456     }
SetHasUnobscuredUEC(bool flag)457     void SetHasUnobscuredUEC(bool flag)
458     {
459         hasUnobscuredUEC_ = flag;
460     }
461 
462     void SetVirtualScreenWhiteListInfo(const std::unordered_map<ScreenId, bool>& info);
GetVirtualScreenWhiteListInfo()463     const std::unordered_map<ScreenId, bool>& GetVirtualScreenWhiteListInfo() const
464     {
465         return hasVirtualScreenWhiteList_;
466     }
467 
468     // [Attention] Only used in PC window resize scene now
469     void EnableWindowKeyFrame(bool enable);
470     // [Attention] Only used in PC window resize scene now
IsWindowKeyFrameEnabled()471     bool IsWindowKeyFrameEnabled() const
472     {
473         return windowKeyframeEnabled_;
474     }
475     void SetLinkedRootNodeDrawable(DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr drawable);
476     // [Attention] Only used in PC window resize scene now
GetLinkedRootNodeDrawable()477     DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr GetLinkedRootNodeDrawable()
478     {
479         return linkedRootNodeDrawable_;
480     }
481     void SetNeedSwapBuffer(bool needSwapBuffer);
482     // [Attention] Only used in PC window resize scene now
GetNeedSwapBuffer()483     bool GetNeedSwapBuffer() const
484     {
485         return needSwapBuffer_;
486     }
487     void SetCacheNodeFrameRect(const Drawing::RectF& cacheNodeFrameRect);
488     // [Attention] Only used in PC window resize scene now
GetCacheNodeFrameRect()489     const Drawing::RectF& GetCacheNodeFrameRect() const
490     {
491         return cacheNodeFrameRect_;
492     }
493 
494     void SetIsOnTheTree(bool isOnTheTree);
495     bool GetIsOnTheTree() const;
496 
497 protected:
498     bool needSync_ = false;
499     std::bitset<RSRenderParamsDirtyType::MAX_DIRTY_TYPE> dirtyType_;
500 
501 private:
502     NodeId id_;
503     RSRenderParamsType paramsType_ = RSRenderParamsType::RS_PARAM_DEFAULT;
504     RSRenderNodeType renderNodeType_ = RSRenderNodeType::RS_NODE;
505     Drawing::Matrix matrix_;
506     Drawing::RectF boundsRect_;
507     Drawing::RectF frameRect_;
508     float alpha_ = 1.0f;
509     float globalAlpha_ = 1.0f;
510     // this rect should map display coordination
511     RectF localDrawRect_;
512     RectI absDrawRect_;
513     Vector2f cacheSize_;
514     Gravity frameGravity_ = Gravity::CENTER;
515     // default 1.0f means max available headroom
516     float hdrBrightness_ = 1.0f;
517     bool freezeFlag_ = false;
518     bool childHasVisibleEffect_ = false;
519     bool childHasVisibleFilter_ = false;
520     bool hasSandBox_ = false;
521     bool isDrawingCacheChanged_ = false;
522     std::atomic_bool isNeedUpdateCache_ = false;
523     bool drawingCacheIncludeProperty_ = false;
524     bool isNodeGroupHasChildInBlacklist_ = false;
525     bool isSnapshotSkipLayer_ = false;
526     bool shouldPaint_ = false;
527     bool contentEmpty_  = false;
528     std::atomic_bool canvasDrawingNodeSurfaceChanged_ = false;
529     bool alphaOffScreen_ = false;
530     Drawing::Rect shadowRect_;
531     RSDrawingCacheType drawingCacheType_ = RSDrawingCacheType::DISABLED_CACHE;
532     DirtyRegionInfoForDFX dirtyRegionInfoForDFX_;
533     std::shared_ptr<RSFilter> foregroundFilterCache_ = nullptr;
534     bool isOpincSuggestFlag_ = false;
535     bool isOpincSupportFlag_ = false;
536     bool isOpincRootFlag_ = false;
537     bool isOpincStateChanged_ = false;
538     bool startingWindowFlag_ = false;
539     bool needFilter_ = false;
540     bool effectNodeShouldPaint_ = false;
541     bool hasGlobalCorner_ = false;
542     bool hasBlurFilter_ = false;
543     SurfaceParam surfaceParams_;
544     NodeId firstLevelNodeId_ = INVALID_NODEID;
545     NodeId uifirstRootNodeId_ = INVALID_NODEID;
546     bool isFirstLevelCrossNode_ = false;
547     DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr cloneSourceDrawable_;
548     CrossNodeOffScreenRenderDebugType isCrossNodeOffscreenOn_ = CrossNodeOffScreenRenderDebugType::ENABLE;
549     // The angle at which the node rotates about the Z-axis
550     float absRotation_ = 0.f;
551     bool hasUnobscuredUEC_ = false;
552 
553     // [Attention] Only used in PC window resize scene now
554     DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr linkedRootNodeDrawable_;
555     bool windowKeyframeEnabled_ = false;
556     bool needSwapBuffer_ = false;
557     Drawing::RectF cacheNodeFrameRect_;
558     bool isRepaintBoundary_ = false;
559 
560     // used for DFX
561     bool isOnTheTree_ = false;
562 
563     std::unordered_map<ScreenId, bool> hasVirtualScreenWhiteList_;
564 };
565 } // namespace OHOS::Rosen
566 #endif // RENDER_SERVICE_BASE_PARAMS_RS_RENDER_PARAMS_H
567