• 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 struct ScreenInfo;
50 
51 typedef enum {
52     RS_PARAM_DEFAULT,
53     RS_PARAM_OWNED_BY_NODE,
54     RS_PARAM_OWNED_BY_DRAWABLE,
55     RS_PARAM_OWNED_BY_DRAWABLE_UIFIRST,
56     RS_PARAM_INVALID,
57 } RSRenderParamsType;
58 
59 class RSB_EXPORT RSRenderParams {
60 public:
RSRenderParams(NodeId id)61     RSRenderParams(NodeId id) : id_(id) {}
62     virtual ~RSRenderParams() = default;
63 
64     struct SurfaceParam {
65         int width = 0;
66         int height = 0;
67     };
68 
69     void SetDirtyType(RSRenderParamsDirtyType dirtyType);
70 
71     void SetAlpha(float alpha);
72     float GetAlpha() const;
73 
74     void SetAlphaOffScreen(bool alphaOffScreen);
75     bool GetAlphaOffScreen() const;
76 
77     void SetMatrix(const Drawing::Matrix& matrix);
78     const Drawing::Matrix& GetMatrix() const;
79 
80     void ApplyAlphaAndMatrixToCanvas(RSPaintFilterCanvas& canvas, bool applyMatrix = true) const;
81 
82     void SetBoundsRect(const Drawing::RectF& boundsRect);
83     const Drawing::Rect& GetBounds() const;
84 
85     void SetFrameRect(const Drawing::RectF& frameRect);
86     const Drawing::Rect& GetFrameRect() const;
87 
88     // return to add some dirtynode does not mark pending
89     bool SetLocalDrawRect(const RectF& localDrawRect);
90     const RectF& GetLocalDrawRect() const;
91 
92     void SetHasSandBox(bool hasSandBox);
93     bool HasSandBox() const;
94 
95     bool GetShouldPaint() const;
96     void SetShouldPaint(bool shouldPaint);
97     void SetContentEmpty(bool empty);
98 
99     bool NeedSync() const;
100     void SetNeedSync(bool needSync);
101 
102     const std::shared_ptr<RSFilter>& GetForegroundFilterCache() const;
103     void SetForegroundFilterCache(const std::shared_ptr<RSFilter>& foregroundFilterCache);
104 
GetId()105     inline NodeId GetId() const
106     {
107         return id_;
108     }
109 
SetParamsType(RSRenderParamsType paramsType)110     void SetParamsType(RSRenderParamsType paramsType)
111     {
112         paramsType_ = paramsType;
113     }
114 
GetParamsType()115     inline RSRenderParamsType GetParamsType() const
116     {
117         return paramsType_;
118     }
119 
GetFrameGravity()120     Gravity GetFrameGravity() const
121     {
122         return frameGravity_;
123     }
124 
125     void SetFrameGravity(Gravity gravity);
126 
127     void SetNeedFilter(bool needFilter);
128 
NeedFilter()129     inline bool NeedFilter() const
130     {
131         return needFilter_;
132     }
133 
134     void SetNodeType(RSRenderNodeType type);
GetType()135     inline RSRenderNodeType GetType() const
136     {
137         return renderNodeType_;
138     }
139 
140     void SetEffectNodeShouldPaint(bool effectNodeShouldPaint);
GetEffectNodeShouldPaint()141     inline bool GetEffectNodeShouldPaint() const
142     {
143         return effectNodeShouldPaint_;
144     }
145 
146     void SetHasGlobalCorner(bool hasGlobalCorner);
HasGlobalCorner()147     inline bool HasGlobalCorner() const
148     {
149         return hasGlobalCorner_;
150     }
151 
152     void SetHasBlurFilter(bool hasBlurFilter);
HasBlurFilter()153     inline bool HasBlurFilter() const
154     {
155         return hasBlurFilter_;
156     }
157 
158     void SetGlobalAlpha(float alpha);
GetGlobalAlpha()159     inline float GetGlobalAlpha() const
160     {
161         return globalAlpha_;
162     }
163 
IsSecurityLayer()164     inline bool IsSecurityLayer() const
165     {
166         return isSecurityLayer_;
167     }
168 
IsSkipLayer()169     inline bool IsSkipLayer() const
170     {
171         return isSkipLayer_;
172     }
173 
IsSnapshotSkipLayer()174     inline bool IsSnapshotSkipLayer() const
175     {
176         return isSnapshotSkipLayer_;
177     }
178 
IsLayerDirty()179     inline bool IsLayerDirty() const
180     {
181         return dirtyType_.test(RSRenderParamsDirtyType::LAYER_INFO_DIRTY);
182     }
183 
IsBufferDirty()184     inline bool IsBufferDirty() const
185     {
186         return dirtyType_.test(RSRenderParamsDirtyType::BUFFER_INFO_DIRTY);
187     }
188 
189     void SetChildHasVisibleFilter(bool val);
190     bool ChildHasVisibleFilter() const;
191     void SetChildHasVisibleEffect(bool val);
192     bool ChildHasVisibleEffect() const;
193 
194     void SetCacheSize(Vector2f size);
GetCacheSize()195     inline Vector2f GetCacheSize() const
196     {
197         return cacheSize_;
198     }
199 
200     void SetDrawingCacheChanged(bool isChanged, bool lastFrameSynced);
201     bool GetDrawingCacheChanged() const;
202 
203     void SetNeedUpdateCache(bool needUpdateCache);
204     bool GetNeedUpdateCache() const;
205 
206     void SetDrawingCacheType(RSDrawingCacheType cacheType);
207     RSDrawingCacheType GetDrawingCacheType() const;
208 
209     void OpincUpdateRootFlag(bool suggestFlag);
210     bool OpincGetRootFlag() const;
211     void OpincSetCacheChangeFlag(bool state, bool lastFrameSynced);
212     bool OpincGetCacheChangeState();
213 
214     void SetDrawingCacheIncludeProperty(bool includeProperty);
215     bool GetDrawingCacheIncludeProperty() const;
216 
217     void SetRSFreezeFlag(bool freezeFlag);
218     bool GetRSFreezeFlag() const;
219     void SetShadowRect(Drawing::Rect rect);
220     Drawing::Rect GetShadowRect() const;
221 
222     // One-time trigger, needs to be manually reset false in main/RT thread after each sync operation
223     void OnCanvasDrawingSurfaceChange(const std::unique_ptr<RSRenderParams>& target);
224     bool GetCanvasDrawingSurfaceChanged() const;
225     void SetCanvasDrawingSurfaceChanged(bool changeFlag);
226     SurfaceParam GetCanvasDrawingSurfaceParams();
227     void SetCanvasDrawingSurfaceParams(int width, int height);
228 
SetStartingWindowFlag(bool b)229     void SetStartingWindowFlag(bool b)
230     {
231         if (startingWindowFlag_ == b) {
232             return;
233         }
234         startingWindowFlag_ = b;
235         needSync_ = true;
236     }
237 
GetStartingWindowFlag()238     bool GetStartingWindowFlag() const
239     {
240         return startingWindowFlag_;
241     }
242 
243     bool SetFirstLevelNode(NodeId firstLevelNodeId);
244     NodeId GetFirstLevelNodeId() const;
245     bool SetUiFirstRootNode(NodeId uifirstRootNodeId);
246     NodeId GetUifirstRootNodeId() const;
247 
248     // disable copy and move
249     RSRenderParams(const RSRenderParams&) = delete;
250     RSRenderParams(RSRenderParams&&) = delete;
251     RSRenderParams& operator=(const RSRenderParams&) = delete;
252     RSRenderParams& operator=(RSRenderParams&&) = delete;
253 
254     virtual void OnSync(const std::unique_ptr<RSRenderParams>& target);
255 
256     // dfx
257     virtual std::string ToString() const;
258 
259     static void SetParentSurfaceMatrix(const Drawing::Matrix& parentSurfaceMatrix);
260     static const Drawing::Matrix& GetParentSurfaceMatrix();
261 
262     // overrided surface params
263 #ifndef ROSEN_CROSS_PLATFORM
SetBuffer(const sptr<SurfaceBuffer> & buffer,const Rect & damageRect)264     virtual void SetBuffer(const sptr<SurfaceBuffer>& buffer, const Rect& damageRect) {}
GetBuffer()265     virtual sptr<SurfaceBuffer> GetBuffer() const { return nullptr; }
SetPreBuffer(const sptr<SurfaceBuffer> & preBuffer)266     virtual void SetPreBuffer(const sptr<SurfaceBuffer>& preBuffer) {}
GetPreBuffer()267     virtual sptr<SurfaceBuffer> GetPreBuffer() { return nullptr; }
SetAcquireFence(const sptr<SyncFence> & acquireFence)268     virtual void SetAcquireFence(const sptr<SyncFence>& acquireFence) {}
GetAcquireFence()269     virtual sptr<SyncFence> GetAcquireFence() const { return nullptr; }
GetBufferDamage()270     virtual const Rect& GetBufferDamage() const
271     {
272         static const Rect defaultRect = {};
273         return defaultRect;
274     }
275 #endif
276     virtual const RSLayerInfo& GetLayerInfo() const;
GetAbsDrawRect()277     virtual const RectI& GetAbsDrawRect() const
278     {
279         return absDrawRect_;
280     }
281 
SetAbsDrawRect(RectI & absRect)282     void SetAbsDrawRect(RectI& absRect)
283     {
284         absDrawRect_ = absRect;
285     }
286 
287     // surface params
GetOcclusionVisible()288     virtual bool GetOcclusionVisible() const { return true; }
IsLeashWindow()289     virtual bool IsLeashWindow() const { return true; }
IsAppWindow()290     virtual bool IsAppWindow() const { return false; }
GetHardwareEnabled()291     virtual bool GetHardwareEnabled() const { return false; }
GetNeedMakeImage()292     virtual bool GetNeedMakeImage() const { return false; }
GetHardCursorStatus()293     virtual bool GetHardCursorStatus() const { return false; }
GetLayerCreated()294     virtual bool GetLayerCreated() const { return false; }
GetLastFrameHardwareEnabled()295     virtual bool GetLastFrameHardwareEnabled() const { return false; }
SetLayerCreated(bool layerCreated)296     virtual void SetLayerCreated(bool layerCreated) {}
SetOldDirtyInSurface(const RectI & oldDirtyInSurface)297     virtual void SetOldDirtyInSurface(const RectI& oldDirtyInSurface) {}
GetOldDirtyInSurface()298     virtual RectI GetOldDirtyInSurface() const { return {}; }
299 
300     // overrided by displayNode
GetAllMainAndLeashSurfaceDrawables()301     virtual std::vector<DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr>& GetAllMainAndLeashSurfaceDrawables()
302     {
303         static std::vector<DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr> defaultSurfaceVector;
304         return defaultSurfaceVector;
305     }
306 
GetVisibleRegion()307     virtual Occlusion::Region GetVisibleRegion() const
308     {
309         return {};
310     }
311 
SetRotationChanged(bool changed)312     virtual void SetRotationChanged(bool changed) {}
IsRotationChanged()313     virtual bool IsRotationChanged() const
314     {
315         return false;
316     }
317 
318     virtual const ScreenInfo& GetScreenInfo() const;
GetScreenId()319     virtual uint64_t GetScreenId() const
320     {
321         return 0;
322     }
GetScreenRotation()323     virtual ScreenRotation GetScreenRotation() const
324     {
325         return ScreenRotation::ROTATION_0;
326     }
SetTotalMatrix(const Drawing::Matrix & totalMatrix)327     virtual void SetTotalMatrix(const Drawing::Matrix& totalMatrix) {}
328     virtual const Drawing::Matrix& GetTotalMatrix();
SetNeedClient(bool needClient)329     virtual void SetNeedClient(bool needClient) {}
GetNeedClient()330     virtual bool GetNeedClient() const { return false; }
GetFingerprint()331     virtual bool GetFingerprint() { return false; }
SetFingerprint(bool hasFingerprint)332     virtual void SetFingerprint(bool hasFingerprint) {}
333     // virtual display params
334     virtual DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr GetMirrorSourceDrawable();
335     DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr GetCloneSourceDrawable() const;
336     void SetCloneSourceDrawable(DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr drawable);
GetSecurityDisplay()337     virtual bool GetSecurityDisplay() const { return true; }
338     // canvas drawing node
IsNeedProcess()339     virtual bool IsNeedProcess() const { return true; }
SetNeedProcess(bool isNeedProcess)340     virtual void SetNeedProcess(bool isNeedProcess) {}
IsFirstLevelCrossNode()341     virtual bool IsFirstLevelCrossNode() const { return isFirstLevelCrossNode_; }
SetFirstLevelCrossNode(bool firstLevelCrossNode)342     virtual void SetFirstLevelCrossNode(bool firstLevelCrossNode) { isFirstLevelCrossNode_ = firstLevelCrossNode; }
GetCrossNodeOffScreenStatus()343     CrossNodeOffScreenRenderDebugType GetCrossNodeOffScreenStatus() const
344     {
345         return isCrossNodeOffscreenOn_;
346     }
SetCrossNodeOffScreenStatus(CrossNodeOffScreenRenderDebugType isCrossNodeOffScreenOn)347     void SetCrossNodeOffScreenStatus(CrossNodeOffScreenRenderDebugType isCrossNodeOffScreenOn)
348     {
349         isCrossNodeOffscreenOn_ = isCrossNodeOffScreenOn;
350     }
351 
SetAbsRotation(float degree)352     void SetAbsRotation(float degree)
353     {
354         absRotation_ = degree;
355     }
356 
GetAbsRotation()357     float GetAbsRotation() const
358     {
359         return absRotation_;
360     }
361 
362     bool HasUnobscuredUEC() const;
363     void SetHasUnobscuredUEC(bool flag);
364 
365     // [Attention] Only used in PC window resize scene now
366     void EnableWindowKeyFrame(bool enable);
367     bool IsWindowKeyFrameEnabled() const;
368     void SetLinkedRootNodeDrawable(DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr drawable);
369     DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr GetLinkedRootNodeDrawable();
370     void SetNeedSwapBuffer(bool needSwapBuffer);
371     bool GetNeedSwapBuffer() const;
372     void SetCacheNodeFrameRect(const Drawing::RectF& cacheNodeFrameRect);
373     const Drawing::RectF& GetCacheNodeFrameRect() const;
374 
375 protected:
376     bool needSync_ = false;
377     std::bitset<RSRenderParamsDirtyType::MAX_DIRTY_TYPE> dirtyType_;
378 
379 private:
380     NodeId id_;
381     RSRenderParamsType paramsType_ = RSRenderParamsType::RS_PARAM_DEFAULT;
382     RSRenderNodeType renderNodeType_ = RSRenderNodeType::RS_NODE;
383     Drawing::Matrix matrix_;
384     Drawing::RectF boundsRect_;
385     Drawing::RectF frameRect_;
386     float alpha_ = 1.0f;
387     float globalAlpha_ = 1.0f;
388     // this rect should map display coordination
389     RectF localDrawRect_;
390     RectI absDrawRect_;
391     Vector2f cacheSize_;
392     Gravity frameGravity_ = Gravity::CENTER;
393     bool freezeFlag_ = false;
394     bool childHasVisibleEffect_ = false;
395     bool childHasVisibleFilter_ = false;
396     bool hasSandBox_ = false;
397     bool isDrawingCacheChanged_ = false;
398     std::atomic_bool isNeedUpdateCache_ = false;
399     bool drawingCacheIncludeProperty_ = false;
400     bool isSecurityLayer_ = false;
401     bool isSkipLayer_ = false;
402     bool isSnapshotSkipLayer_ = false;
403     bool shouldPaint_ = false;
404     bool contentEmpty_  = false;
405     std::atomic_bool canvasDrawingNodeSurfaceChanged_ = false;
406     bool alphaOffScreen_ = false;
407     Drawing::Rect shadowRect_;
408     RSDrawingCacheType drawingCacheType_ = RSDrawingCacheType::DISABLED_CACHE;
409     DirtyRegionInfoForDFX dirtyRegionInfoForDFX_;
410     std::shared_ptr<RSFilter> foregroundFilterCache_ = nullptr;
411     bool isOpincRootFlag_ = false;
412     bool isOpincStateChanged_ = false;
413     bool startingWindowFlag_ = false;
414     bool needFilter_ = false;
415     bool effectNodeShouldPaint_ = false;
416     bool hasGlobalCorner_ = false;
417     bool hasBlurFilter_ = false;
418     SurfaceParam surfaceParams_;
419     NodeId firstLevelNodeId_ = INVALID_NODEID;
420     NodeId uifirstRootNodeId_ = INVALID_NODEID;
421     bool isFirstLevelCrossNode_ = false;
422     DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr cloneSourceDrawable_;
423     CrossNodeOffScreenRenderDebugType isCrossNodeOffscreenOn_ = CrossNodeOffScreenRenderDebugType::ENABLE;
424     // The angle at which the node rotates about the Z-axis
425     float absRotation_ = 0.f;
426     bool hasUnobscuredUEC_ = false;
427 
428     // [Attention] Only used in PC window resize scene now
429     DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr linkedRootNodeDrawable_;
430     bool windowKeyframeEnabled_ = false;
431     bool needSwapBuffer_ = false;
432     Drawing::RectF cacheNodeFrameRect_;
433 };
434 } // namespace OHOS::Rosen
435 #endif // RENDER_SERVICE_BASE_PARAMS_RS_RENDER_PARAMS_H
436