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