• 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 "utils/matrix.h"
26 #include "utils/region.h"
27 
28 #ifndef ROSEN_CROSS_PLATFORM
29 #include <iconsumer_surface.h>
30 #include <surface.h>
31 #include "sync_fence.h"
32 #endif
33 
34 namespace OHOS::Rosen {
35 #define RENDER_BASIC_PARAM_TO_STRING(basicType) (std::string(#basicType "[") + std::to_string(basicType) + "] ")
36 #define RENDER_RECT_PARAM_TO_STRING(rect) (std::string(#rect "[") + (rect).ToString() + "] ")
37 #define RENDER_PARAM_TO_STRING(param) (std::string(#param "[") + (param).ToString() + "] ")
38 
39 struct DirtyRegionInfoForDFX {
40     RectI oldDirty;
41     RectI oldDirtyInSurface;
42     bool operator==(const DirtyRegionInfoForDFX& rhs) const
43     {
44         return oldDirty == rhs.oldDirty && oldDirtyInSurface == rhs.oldDirtyInSurface;
45     }
46 };
47 struct RSLayerInfo;
48 struct ScreenInfo;
49 class RSB_EXPORT RSRenderParams {
50 public:
RSRenderParams(NodeId id)51     RSRenderParams(NodeId id) : id_(id) {}
52     virtual ~RSRenderParams() = default;
53 
54     struct SurfaceParam {
55         int width = 0;
56         int height = 0;
57     };
58 
59     void SetDirtyType(RSRenderParamsDirtyType dirtyType);
60 
61     void SetAlpha(float alpha);
62     float GetAlpha() const;
63 
64     void SetAlphaOffScreen(bool alphaOffScreen);
65     bool GetAlphaOffScreen() const;
66 
67     void SetMatrix(const Drawing::Matrix& matrix);
68     const Drawing::Matrix& GetMatrix() const;
69 
70     void ApplyAlphaAndMatrixToCanvas(RSPaintFilterCanvas& canvas, bool applyMatrix = true) const;
71 
72     void SetBoundsRect(const Drawing::RectF& boundsRect);
73     const Drawing::Rect& GetBounds() const;
74 
75     void SetFrameRect(const Drawing::RectF& frameRect);
76     const Drawing::Rect& GetFrameRect() const;
77 
78     // return to add some dirtynode does not mark pending
79     bool SetLocalDrawRect(const RectF& localDrawRect);
80     const RectF& GetLocalDrawRect() const;
81 
82     void SetHasSandBox(bool hasSandBox);
83     bool HasSandBox() const;
84 
85     bool GetShouldPaint() const;
86     void SetShouldPaint(bool shouldPaint);
87     void SetContentEmpty(bool empty);
88 
89     bool NeedSync() const;
90     void SetNeedSync(bool needSync);
91 
92     const std::shared_ptr<RSFilter>& GetForegroundFilterCache() const;
93     void SetForegroundFilterCache(const std::shared_ptr<RSFilter>& foregroundFilterCache);
94 
GetId()95     inline NodeId GetId() const
96     {
97         return id_;
98     }
99 
GetFrameGravity()100     Gravity GetFrameGravity() const
101     {
102         return frameGravity_;
103     }
104 
105     void SetFrameGravity(Gravity gravity);
106 
107     void SetNeedFilter(bool needFilter);
108 
NeedFilter()109     inline bool NeedFilter() const
110     {
111         return needFilter_;
112     }
113 
114     void SetNodeType(RSRenderNodeType type);
GetType()115     inline RSRenderNodeType GetType() const
116     {
117         return renderNodeType_;
118     }
119 
120     void SetEffectNodeShouldPaint(bool effectNodeShouldPaint);
GetEffectNodeShouldPaint()121     inline bool GetEffectNodeShouldPaint() const
122     {
123         return effectNodeShouldPaint_;
124     }
125 
126     void SetHasGlobalCorner(bool hasGlobalCorner);
HasGlobalCorner()127     inline bool HasGlobalCorner() const
128     {
129         return hasGlobalCorner_;
130     }
131 
132     void SetHasBlurFilter(bool hasBlurFilter);
HasBlurFilter()133     inline bool HasBlurFilter() const
134     {
135         return hasBlurFilter_;
136     }
137 
138     void SetGlobalAlpha(float alpha);
GetGlobalAlpha()139     inline float GetGlobalAlpha() const
140     {
141         return globalAlpha_;
142     }
143 
IsSecurityLayer()144     inline bool IsSecurityLayer() const
145     {
146         return isSecurityLayer_;
147     }
148 
IsSkipLayer()149     inline bool IsSkipLayer() const
150     {
151         return isSkipLayer_;
152     }
153 
IsLayerDirty()154     inline bool IsLayerDirty() const
155     {
156         return dirtyType_.test(RSRenderParamsDirtyType::LAYER_INFO_DIRTY);
157     }
158 
IsBufferDirty()159     inline bool IsBufferDirty() const
160     {
161         return dirtyType_.test(RSRenderParamsDirtyType::BUFFER_INFO_DIRTY);
162     }
163 
164     void SetChildHasVisibleFilter(bool val);
165     bool ChildHasVisibleFilter() const;
166     void SetChildHasVisibleEffect(bool val);
167     bool ChildHasVisibleEffect() const;
168 
169     void SetCacheSize(Vector2f size);
GetCacheSize()170     inline Vector2f GetCacheSize() const
171     {
172         return cacheSize_;
173     }
174 
175     void SetDrawingCacheChanged(bool isChanged, bool lastFrameSynced);
176     bool GetDrawingCacheChanged() const;
177 
178     void SetDrawingCacheType(RSDrawingCacheType cacheType);
179     RSDrawingCacheType GetDrawingCacheType() const;
180 
181     void OpincUpdateRootFlag(bool suggestFlag);
182     bool OpincGetRootFlag() const;
183     void OpincSetCacheChangeFlag(bool state, bool lastFrameSynced);
184     bool OpincGetCacheChangeState();
185 
186     void SetDrawingCacheIncludeProperty(bool includeProperty);
187     bool GetDrawingCacheIncludeProperty() const;
188 
189     void SetRSFreezeFlag(bool freezeFlag);
190     bool GetRSFreezeFlag() const;
191     void SetShadowRect(Drawing::Rect rect);
192     Drawing::Rect GetShadowRect() const;
193 
194     void SetDirtyRegionInfoForDFX(DirtyRegionInfoForDFX dirtyRegionInfo);
195     DirtyRegionInfoForDFX GetDirtyRegionInfoForDFX() const;
196 
197     // One-time trigger, needs to be manually reset false in main/RT thread after each sync operation
198     void OnCanvasDrawingSurfaceChange(const std::unique_ptr<RSRenderParams>& target);
199     bool GetCanvasDrawingSurfaceChanged() const;
200     void SetCanvasDrawingSurfaceChanged(bool changeFlag);
201     SurfaceParam GetCanvasDrawingSurfaceParams();
202     void SetCanvasDrawingSurfaceParams(int width, int height);
203 
SetStartingWindowFlag(bool b)204     void SetStartingWindowFlag(bool b)
205     {
206         if (startingWindowFlag_ == b) {
207             return;
208         }
209         startingWindowFlag_ = b;
210         needSync_ = true;
211     }
212 
GetStartingWindowFlag()213     bool GetStartingWindowFlag() const
214     {
215         return startingWindowFlag_;
216     }
217 
218     bool SetFirstLevelNode(NodeId firstLevelNodeId);
219     NodeId GetFirstLevelNodeId() const;
220     bool SetUiFirstRootNode(NodeId uifirstRootNodeId);
221     NodeId GetUifirstRootNodeId() const;
222 
223     // disable copy and move
224     RSRenderParams(const RSRenderParams&) = delete;
225     RSRenderParams(RSRenderParams&&) = delete;
226     RSRenderParams& operator=(const RSRenderParams&) = delete;
227     RSRenderParams& operator=(RSRenderParams&&) = delete;
228 
229     virtual void OnSync(const std::unique_ptr<RSRenderParams>& target);
230 
231     // dfx
232     virtual std::string ToString() const;
233 
234     static void SetParentSurfaceMatrix(const Drawing::Matrix& parentSurfaceMatrix);
235     static const Drawing::Matrix& GetParentSurfaceMatrix();
236 
237     // overrided surface params
238 #ifndef ROSEN_CROSS_PLATFORM
SetBuffer(const sptr<SurfaceBuffer> & buffer,const Rect & damageRect)239     virtual void SetBuffer(const sptr<SurfaceBuffer>& buffer, const Rect& damageRect) {}
GetBuffer()240     virtual sptr<SurfaceBuffer> GetBuffer() const { return nullptr; }
SetPreBuffer(const sptr<SurfaceBuffer> & preBuffer)241     virtual void SetPreBuffer(const sptr<SurfaceBuffer>& preBuffer) {}
GetPreBuffer()242     virtual sptr<SurfaceBuffer> GetPreBuffer() { return nullptr; }
SetAcquireFence(const sptr<SyncFence> & acquireFence)243     virtual void SetAcquireFence(const sptr<SyncFence>& acquireFence) {}
GetAcquireFence()244     virtual sptr<SyncFence> GetAcquireFence() const { return nullptr; }
GetBufferDamage()245     virtual const Rect& GetBufferDamage() const
246     {
247         static const Rect defaultRect = {};
248         return defaultRect;
249     }
250 #endif
251     virtual const RSLayerInfo& GetLayerInfo() const;
GetAbsDrawRect()252     virtual const RectI& GetAbsDrawRect() const
253     {
254         return absDrawRect_;
255     }
256 
SetAbsDrawRect(RectI & absRect)257     void SetAbsDrawRect(RectI& absRect)
258     {
259         absDrawRect_ = absRect;
260     }
261 
262     // surface params
GetOcclusionVisible()263     virtual bool GetOcclusionVisible() const { return true; }
IsLeashWindow()264     virtual bool IsLeashWindow() const { return true; }
IsAppWindow()265     virtual bool IsAppWindow() const { return false; }
GetHardwareEnabled()266     virtual bool GetHardwareEnabled() const { return false; }
GetLayerCreated()267     virtual bool GetLayerCreated() const { return false; }
GetLastFrameHardwareEnabled()268     virtual bool GetLastFrameHardwareEnabled() const { return false; }
SetLayerCreated(bool layerCreated)269     virtual void SetLayerCreated(bool layerCreated) {}
SetOldDirtyInSurface(const RectI & oldDirtyInSurface)270     virtual void SetOldDirtyInSurface(const RectI& oldDirtyInSurface) {}
GetOldDirtyInSurface()271     virtual RectI GetOldDirtyInSurface() const { return {}; }
272 
273     // overrided by displayNode
GetAllMainAndLeashSurfaceDrawables()274     virtual std::vector<DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr>& GetAllMainAndLeashSurfaceDrawables()
275     {
276         static std::vector<DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr> defaultSurfaceVector;
277         return defaultSurfaceVector;
278     }
279 
GetVisibleRegion()280     virtual Occlusion::Region GetVisibleRegion() const
281     {
282         return {};
283     }
284 
SetRotationChanged(bool changed)285     virtual void SetRotationChanged(bool changed) {}
IsRotationChanged()286     virtual bool IsRotationChanged() const
287     {
288         return false;
289     }
290 
291     virtual const ScreenInfo& GetScreenInfo() const;
GetScreenId()292     virtual uint64_t GetScreenId() const
293     {
294         return 0;
295     }
GetScreenRotation()296     virtual ScreenRotation GetScreenRotation() const
297     {
298         return ScreenRotation::ROTATION_0;
299     }
SetTotalMatrix(const Drawing::Matrix & totalMatrix)300     virtual void SetTotalMatrix(const Drawing::Matrix& totalMatrix) {}
301     virtual const Drawing::Matrix& GetTotalMatrix();
SetScalingMode(ScalingMode scalingMode)302     virtual void SetScalingMode(ScalingMode scalingMode) {}
GetScalingMode()303     virtual ScalingMode GetScalingMode() const
304     {
305         return ScalingMode::SCALING_MODE_FREEZE;
306     }
SetNeedClient(bool needClient)307     virtual void SetNeedClient(bool needClient) {}
GetNeedClient()308     virtual bool GetNeedClient() const { return false; }
GetFingerprint()309     virtual bool GetFingerprint() { return false; }
SetFingerprint(bool hasFingerprint)310     virtual void SetFingerprint(bool hasFingerprint) {}
311     // virtual display params
312     virtual DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr GetMirrorSourceDrawable();
GetSecurityDisplay()313     virtual bool GetSecurityDisplay() const { return true; }
314     // canvas drawing node
IsNeedProcess()315     virtual bool IsNeedProcess() const { return false; }
SetNeedProcess(bool isNeedProcess)316     virtual void SetNeedProcess(bool isNeedProcess) {}
317 protected:
318     bool needSync_ = false;
319     std::bitset<RSRenderParamsDirtyType::MAX_DIRTY_TYPE> dirtyType_;
320 
321 private:
322     NodeId id_;
323     RSRenderNodeType renderNodeType_ = RSRenderNodeType::RS_NODE;
324     Drawing::Matrix matrix_;
325     Drawing::RectF boundsRect_;
326     Drawing::RectF frameRect_;
327     float alpha_ = 1.0f;
328     float globalAlpha_ = 1.0f;
329     // this rect should map display coordination
330     RectF localDrawRect_;
331     RectI absDrawRect_;
332     Vector2f cacheSize_;
333     Gravity frameGravity_ = Gravity::CENTER;
334     bool freezeFlag_ = false;
335     bool childHasVisibleEffect_ = false;
336     bool childHasVisibleFilter_ = false;
337     bool hasSandBox_ = false;
338     bool isDrawingCacheChanged_ = false;
339     bool drawingCacheIncludeProperty_ = false;
340     bool isSecurityLayer_ = false;
341     bool isSkipLayer_ = false;
342     bool shouldPaint_ = false;
343     bool contentEmpty_  = false;
344     std::atomic_bool canvasDrawingNodeSurfaceChanged_ = false;
345     bool alphaOffScreen_ = false;
346     Drawing::Rect shadowRect_;
347     RSDrawingCacheType drawingCacheType_ = RSDrawingCacheType::DISABLED_CACHE;
348     DirtyRegionInfoForDFX dirtyRegionInfoForDFX_;
349     std::shared_ptr<RSFilter> foregroundFilterCache_ = nullptr;
350     bool isOpincRootFlag_ = false;
351     bool isOpincStateChanged_ = false;
352     bool startingWindowFlag_ = false;
353     bool needFilter_ = false;
354     bool effectNodeShouldPaint_ = false;
355     bool hasGlobalCorner_ = false;
356     bool hasBlurFilter_ = false;
357     SurfaceParam surfaceParams_;
358     NodeId firstLevelNodeId_ = INVALID_NODEID;
359     NodeId uifirstRootNodeId_ = INVALID_NODEID;
360 };
361 } // namespace OHOS::Rosen
362 #endif // RENDER_SERVICE_BASE_PARAMS_RS_RENDER_PARAMS_H
363