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_SURFACE_RENDER_PARAMS_H 17 #define RENDER_SERVICE_BASE_PARAMS_RS_SURFACE_RENDER_PARAMS_H 18 19 #include <memory> 20 #include <string> 21 22 #include "common/rs_occlusion_region.h" 23 #include "drawable/rs_render_node_drawable_adapter.h" 24 #include "params/rs_render_params.h" 25 #include "pipeline/rs_base_render_node.h" 26 #ifndef ROSEN_CROSS_PLATFORM 27 #include "surface_buffer.h" 28 #include "sync_fence.h" 29 #endif 30 #include "surface_type.h" 31 32 namespace OHOS::Rosen { 33 class RSSurfaceRenderNode; 34 struct RSLayerInfo { 35 #ifndef ROSEN_CROSS_PLATFORM 36 GraphicIRect srcRect; 37 GraphicIRect dstRect; 38 GraphicIRect boundRect; 39 Drawing::Matrix matrix; 40 int32_t gravity = 0; 41 int32_t zOrder = 0; 42 float alpha = 1.f; 43 GraphicBlendType blendType; 44 GraphicTransformType transformType = GraphicTransformType::GRAPHIC_ROTATE_NONE; 45 int32_t layerSource; 46 bool arsrTag = true; 47 48 bool operator==(const RSLayerInfo& layerInfo) const 49 { 50 return (srcRect == layerInfo.srcRect) && (dstRect == layerInfo.dstRect) && 51 (boundRect == layerInfo.boundRect) && (matrix == layerInfo.matrix) && (gravity == layerInfo.gravity) && 52 (zOrder == layerInfo.zOrder) && (blendType == layerInfo.blendType) && 53 (transformType == layerInfo.transformType) && (ROSEN_EQ(alpha, layerInfo.alpha)) && 54 (layerSource == layerInfo.layerSource) && (arsrTag == layerInfo.arsrTag); 55 } 56 #endif 57 }; 58 struct RSWindowInfo { 59 bool isMainWindowType_ = false; 60 bool isLeashWindow_ = false; 61 bool isAppWindow_ = false; SetWindowInfoRSWindowInfo62 void SetWindowInfo(bool isMainWindowType, bool isLeashWindow, bool isAppWindow) 63 { 64 isMainWindowType_ = isMainWindowType; 65 isLeashWindow_ = isLeashWindow; 66 isAppWindow_ = isAppWindow; 67 } 68 }; 69 class RSB_EXPORT RSSurfaceRenderParams : public RSRenderParams { 70 public: 71 explicit RSSurfaceRenderParams(NodeId id); 72 ~RSSurfaceRenderParams() override = default; IsMainWindowType()73 inline bool IsMainWindowType() const 74 { 75 return windowInfo_.isMainWindowType_; 76 } IsLeashWindow()77 inline bool IsLeashWindow() const override 78 { 79 return windowInfo_.isLeashWindow_; 80 } IsAppWindow()81 bool IsAppWindow() const override 82 { 83 return windowInfo_.isAppWindow_; 84 } SetWindowInfo(bool isMainWindowType,bool isLeashWindow,bool isAppWindow)85 void SetWindowInfo(bool isMainWindowType, bool isLeashWindow, bool isAppWindow) 86 { 87 windowInfo_.SetWindowInfo(isMainWindowType, isLeashWindow, isAppWindow); 88 } GetSurfaceNodeType()89 RSSurfaceNodeType GetSurfaceNodeType() const 90 { 91 return rsSurfaceNodeType_; 92 } GetSelfDrawingNodeType()93 SelfDrawingNodeType GetSelfDrawingNodeType() const 94 { 95 return selfDrawingType_; 96 } SetAncestorDisplayNode(const RSRenderNode::WeakPtr & ancestorDisplayNode)97 void SetAncestorDisplayNode(const RSRenderNode::WeakPtr& ancestorDisplayNode) 98 { 99 ancestorDisplayNode_ = ancestorDisplayNode; 100 auto node = ancestorDisplayNode.lock(); 101 ancestorDisplayDrawable_ = node ? node->GetRenderDrawable() : nullptr; 102 } 103 GetAncestorDisplayNode()104 RSRenderNode::WeakPtr GetAncestorDisplayNode() const 105 { 106 return ancestorDisplayNode_; 107 } GetAncestorDisplayDrawable()108 DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr GetAncestorDisplayDrawable() const 109 { 110 return ancestorDisplayDrawable_; 111 } 112 GetAlpha()113 float GetAlpha() const 114 { 115 return alpha_; 116 } IsSpherizeValid()117 bool IsSpherizeValid() const 118 { 119 return isSpherizeValid_; 120 } NeedBilinearInterpolation()121 bool NeedBilinearInterpolation() const 122 { 123 return needBilinearInterpolation_; 124 } GetBackgroundColor()125 const Color& GetBackgroundColor() const 126 { 127 return backgroundColor_; 128 } GetAbsDrawRect()129 const RectI& GetAbsDrawRect() const override 130 { 131 return absDrawRect_; 132 } GetRRect()133 const RRect& GetRRect() const 134 { 135 return rrect_; 136 } 137 GetIsSecurityLayer()138 bool GetIsSecurityLayer() const 139 { 140 return isSecurityLayer_; 141 } GetIsSkipLayer()142 bool GetIsSkipLayer() const 143 { 144 return isSkipLayer_; 145 } GetIsProtectedLayer()146 bool GetIsProtectedLayer() const 147 { 148 return isProtectedLayer_; 149 } GetAnimateState()150 bool GetAnimateState() const 151 { 152 return animateState_; 153 } GetSecurityLayerIds()154 const std::set<NodeId>& GetSecurityLayerIds() const 155 { 156 return securityLayerIds_; 157 } GetSkipLayerIds()158 const std::set<NodeId>& GetSkipLayerIds() const 159 { 160 return skipLayerIds_; 161 } HasSecurityLayer()162 bool HasSecurityLayer() 163 { 164 return securityLayerIds_.size() != 0; 165 } HasSkipLayer()166 bool HasSkipLayer() 167 { 168 return skipLayerIds_.size() != 0; 169 } HasProtectedLayer()170 bool HasProtectedLayer() 171 { 172 return protectedLayerIds_.size() != 0; 173 } HasPrivacyContentLayer()174 bool HasPrivacyContentLayer() 175 { 176 return privacyContentLayerIds_.size() != 0; 177 } 178 GetLeashPersistentId()179 LeashPersistentId GetLeashPersistentId() const 180 { 181 return leashPersistentId_; 182 } 183 GetName()184 std::string GetName() const 185 { 186 return name_; 187 } 188 SetLeashWindowVisibleRegionEmptyParam(bool isLeashWindowVisibleRegionEmpty)189 void SetLeashWindowVisibleRegionEmptyParam(bool isLeashWindowVisibleRegionEmpty) 190 { 191 if (isLeashWindowVisibleRegionEmpty_ == isLeashWindowVisibleRegionEmpty) { 192 return; 193 } 194 isLeashWindowVisibleRegionEmpty_ = isLeashWindowVisibleRegionEmpty; 195 needSync_ = true; 196 } 197 GetLeashWindowVisibleRegionEmptyParam()198 bool GetLeashWindowVisibleRegionEmptyParam() const 199 { 200 return isLeashWindowVisibleRegionEmpty_; 201 } 202 SetUifirstNodeEnableParam(MultiThreadCacheType isUifirst)203 void SetUifirstNodeEnableParam(MultiThreadCacheType isUifirst) 204 { 205 if (uiFirstFlag_ == isUifirst) { 206 return; 207 } 208 uiFirstFlag_ = isUifirst; 209 needSync_ = true; 210 } 211 GetUifirstNodeEnableParam()212 MultiThreadCacheType GetUifirstNodeEnableParam() const 213 { 214 return uiFirstFlag_; 215 } 216 SetBufferClearCacheSet(const std::set<int32_t> bufferCacheSet)217 void SetBufferClearCacheSet(const std::set<int32_t> bufferCacheSet) 218 { 219 if (bufferCacheSet.size() > 0) { 220 bufferCacheSet_ = bufferCacheSet; 221 needSync_ = true; 222 } 223 } 224 GetBufferClearCacheSet()225 const std::set<int32_t> GetBufferClearCacheSet() 226 { 227 return bufferCacheSet_; 228 } 229 SetIsParentUifirstNodeEnableParam(bool isUifirstParent)230 void SetIsParentUifirstNodeEnableParam(bool isUifirstParent) 231 { 232 if (uiFirstParentFlag_ == isUifirstParent) { 233 return; 234 } 235 uiFirstParentFlag_ = isUifirstParent; 236 needSync_ = true; 237 } 238 SetUifirstUseStarting(NodeId id)239 void SetUifirstUseStarting(NodeId id) 240 { 241 if (uifirstUseStarting_ == id) { 242 return; 243 } 244 uifirstUseStarting_ = id; 245 needSync_ = true; 246 } 247 GetUifirstUseStarting()248 NodeId GetUifirstUseStarting() const 249 { 250 return uifirstUseStarting_; 251 } 252 SetUifirstChildrenDirtyRectParam(const RectI & rect)253 void SetUifirstChildrenDirtyRectParam(const RectI& rect) 254 { 255 childrenDirtyRect_ = rect; 256 needSync_ = true; 257 } 258 GetUifirstChildrenDirtyRectParam()259 RectI& GetUifirstChildrenDirtyRectParam() 260 { 261 return childrenDirtyRect_; 262 } GetDstRect()263 const RectI& GetDstRect() const 264 { 265 return dstRect_; 266 } 267 void SetSurfaceCacheContentStatic(bool contentStatic, bool lastFrameSynced); 268 bool GetSurfaceCacheContentStatic() const; 269 bool GetPreSurfaceCacheContentStatic() const; 270 271 float GetPositionZ() const; 272 273 void SetSurfaceSubTreeDirty(bool isSubTreeDirty); 274 bool GetSurfaceSubTreeDirty() const; 275 GetParentUifirstNodeEnableParam()276 bool GetParentUifirstNodeEnableParam() 277 { 278 return uiFirstParentFlag_; 279 } 280 SetUIFirstFrameGravity(Gravity gravity)281 void SetUIFirstFrameGravity(Gravity gravity) 282 { 283 if (uiFirstFrameGravity_ == gravity) { 284 return; 285 } 286 uiFirstFrameGravity_ = gravity; 287 needSync_ = true; 288 } 289 GetUIFirstFrameGravity()290 Gravity GetUIFirstFrameGravity() const 291 { 292 return uiFirstFrameGravity_; 293 } 294 295 void SetOcclusionVisible(bool visible); 296 bool GetOcclusionVisible() const override; 297 298 void SetIsParentScaling(bool isParentScaling); 299 bool IsParentScaling() const; 300 301 void SetTransparentRegion(const Occlusion::Region& transparentRegion); 302 const Occlusion::Region& GetTransparentRegion() const; 303 304 void SetOldDirtyInSurface(const RectI& oldDirtyInSurface) override; 305 RectI GetOldDirtyInSurface() const override; 306 307 void SetVisibleRegion(const Occlusion::Region& visibleRegion); 308 Occlusion::Region GetVisibleRegion() const override; 309 310 void SetVisibleRegionInVirtual(const Occlusion::Region& visibleRegion); 311 Occlusion::Region GetVisibleRegionInVirtual() const; 312 313 void SetOccludedByFilterCache(bool val); 314 bool GetOccludedByFilterCache() const; 315 316 void SetFilterCacheFullyCovered(bool val); 317 bool GetFilterCacheFullyCovered() const; 318 319 const std::vector<NodeId>& GetVisibleFilterChild() const; 320 bool IsTransparent() const; 321 void CheckValidFilterCacheFullyCoverTarget( 322 bool isFilterCacheValidForOcclusion, const RectI& filterCachedRect, const RectI& targetRect); 323 324 void SetLayerInfo(const RSLayerInfo& layerInfo); 325 const RSLayerInfo& GetLayerInfo() const override; 326 void SetHardwareEnabled(bool enabled); 327 bool GetHardwareEnabled() const override; 328 void SetLastFrameHardwareEnabled(bool enabled); 329 bool GetLastFrameHardwareEnabled() const override; 330 void SetFixRotationByUser(bool flag); 331 bool GetFixRotationByUser() const; 332 void SetInFixedRotation(bool flag); 333 bool IsInFixedRotation() const; 334 // source crop tuning 335 void SetLayerSourceTuning(int32_t needSourceTuning); 336 int32_t GetLayerSourceTuning() const; 337 338 void SetGpuOverDrawBufferOptimizeNode(bool overDrawNode); 339 bool IsGpuOverDrawBufferOptimizeNode() const; 340 void SetOverDrawBufferNodeCornerRadius(const Vector4f& radius); 341 const Vector4f& GetOverDrawBufferNodeCornerRadius() const; 342 343 void SetIsSubSurfaceNode(bool isSubSurfaceNode); 344 bool IsSubSurfaceNode() const; 345 346 void SetIsNodeToBeCaptured(bool isNodeToBeCaptured); 347 bool IsNodeToBeCaptured() const; 348 349 void SetSkipDraw(bool skip); 350 bool GetSkipDraw() const; 351 352 void SetHidePrivacyContent(bool needHidePrivacyContent); 353 bool GetHidePrivacyContent() const; 354 355 void SetLayerTop(bool isTop); 356 bool IsLayerTop() const; 357 SetScalingMode(ScalingMode scalingMode)358 void SetScalingMode(ScalingMode scalingMode) override 359 { 360 if (scalingMode_ == scalingMode) { 361 return; 362 } 363 scalingMode_ = scalingMode; 364 needSync_ = true; 365 } GetScalingMode()366 ScalingMode GetScalingMode() const override 367 { 368 return scalingMode_; 369 } 370 bool IsVisibleDirtyRegionEmpty(const Drawing::Region curSurfaceDrawRegion) const; 371 372 #ifndef ROSEN_CROSS_PLATFORM 373 void SetBuffer(const sptr<SurfaceBuffer>& buffer, const Rect& damageRect) override; 374 sptr<SurfaceBuffer> GetBuffer() const override; 375 void SetPreBuffer(const sptr<SurfaceBuffer>& preBuffer) override; 376 sptr<SurfaceBuffer> GetPreBuffer() override; 377 void SetAcquireFence(const sptr<SyncFence>& acquireFence) override; 378 sptr<SyncFence> GetAcquireFence() const override; 379 const Rect& GetBufferDamage() const override; SetBufferSynced(bool bufferSynced)380 inline void SetBufferSynced(bool bufferSynced) 381 { 382 bufferSynced_ = bufferSynced; 383 } IsBufferSynced()384 bool IsBufferSynced() const 385 { 386 return bufferSynced_; 387 } 388 #endif 389 390 virtual void OnSync(const std::unique_ptr<RSRenderParams>& target) override; 391 392 // DFX 393 std::string ToString() const override; 394 // Set/Get OpaqueRegion, currently only used for DFX 395 void SetOpaqueRegion(const Occlusion::Region& opaqueRegion); 396 const Occlusion::Region& GetOpaqueRegion() const; 397 SetNeedOffscreen(bool needOffscreen)398 void SetNeedOffscreen(bool needOffscreen) 399 { 400 if (needOffscreen_ == needOffscreen) { 401 return; 402 } 403 needOffscreen_ = needOffscreen; 404 needSync_ = true; 405 } 406 GetNeedOffscreen()407 bool GetNeedOffscreen() const 408 { 409 return RSSystemProperties::GetSurfaceOffscreenEnadbled() ? needOffscreen_ : false; 410 } 411 SetLayerCreated(bool layerCreated)412 void SetLayerCreated(bool layerCreated) override 413 { 414 layerCreated_ = layerCreated; 415 } 416 GetLayerCreated()417 bool GetLayerCreated() const override 418 { 419 return layerCreated_; 420 } SetTotalMatrix(const Drawing::Matrix & totalMatrix)421 void SetTotalMatrix(const Drawing::Matrix& totalMatrix) override 422 { 423 if (totalMatrix_ == totalMatrix) { 424 return; 425 } 426 totalMatrix_ = totalMatrix; 427 needSync_ = true; 428 } GetTotalMatrix()429 const Drawing::Matrix& GetTotalMatrix() override 430 { 431 return totalMatrix_; 432 } SetFingerprint(bool hasFingerprint)433 void SetFingerprint(bool hasFingerprint) override 434 { 435 if (hasFingerprint_ == hasFingerprint) { 436 return; 437 } 438 hasFingerprint_ = hasFingerprint; 439 needSync_ = true; 440 } GetFingerprint()441 bool GetFingerprint() override { 442 return false; 443 } 444 SetCornerRadiusInfoForDRM(const std::vector<float> & drmCornerRadiusInfo)445 void SetCornerRadiusInfoForDRM(const std::vector<float>& drmCornerRadiusInfo) 446 { 447 if (drmCornerRadiusInfo_ == drmCornerRadiusInfo) { 448 return; 449 } 450 drmCornerRadiusInfo_ = drmCornerRadiusInfo; 451 needSync_ = true; 452 } 453 GetCornerRadiusInfoForDRM()454 const std::vector<float>& GetCornerRadiusInfoForDRM() const 455 { 456 return drmCornerRadiusInfo_; 457 } 458 SetSdrNit(int32_t sdrNit)459 void SetSdrNit(int32_t sdrNit) 460 { 461 if (ROSEN_EQ(sdrNit_, sdrNit)) { 462 return; 463 } 464 sdrNit_ = sdrNit; 465 needSync_ = true; 466 } 467 GetSdrNit()468 int32_t GetSdrNit() const 469 { 470 return sdrNit_; 471 } 472 SetDisplayNit(int32_t displayNit)473 void SetDisplayNit(int32_t displayNit) 474 { 475 if (ROSEN_EQ(displayNit_, displayNit)) { 476 return; 477 } 478 displayNit_ = displayNit; 479 needSync_ = true; 480 } 481 GetDisplayNit()482 int32_t GetDisplayNit() const 483 { 484 return displayNit_; 485 } 486 SetBrightnessRatio(float brightnessRatio)487 void SetBrightnessRatio(float brightnessRatio) 488 { 489 if (ROSEN_EQ(brightnessRatio_, brightnessRatio)) { 490 return; 491 } 492 brightnessRatio_ = brightnessRatio; 493 needSync_ = true; 494 } 495 GetBrightnessRatio()496 float GetBrightnessRatio() const 497 { 498 return brightnessRatio_; 499 } 500 501 protected: 502 private: 503 RSSurfaceNodeType rsSurfaceNodeType_ = RSSurfaceNodeType::DEFAULT; 504 SelfDrawingNodeType selfDrawingType_ = SelfDrawingNodeType::DEFAULT; 505 RSRenderNode::WeakPtr ancestorDisplayNode_; 506 DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr ancestorDisplayDrawable_; 507 508 float alpha_ = 0; 509 bool isTransparent_ = false; 510 bool isSpherizeValid_ = false; 511 bool isParentScaling_ = false; 512 bool needBilinearInterpolation_ = false; 513 MultiThreadCacheType uiFirstFlag_ = MultiThreadCacheType::NONE; 514 bool uiFirstParentFlag_ = false; 515 NodeId uifirstUseStarting_ = INVALID_NODEID; 516 Color backgroundColor_ = RgbPalette::Transparent(); 517 518 RectI dstRect_; 519 RectI oldDirtyInSurface_; 520 RectI childrenDirtyRect_; 521 RectI absDrawRect_; 522 RRect rrect_; 523 Occlusion::Region transparentRegion_; 524 Occlusion::Region opaqueRegion_; 525 526 LeashPersistentId leashPersistentId_ = INVALID_LEASH_PERSISTENTID; 527 528 bool surfaceCacheContentStatic_ = false; 529 bool preSurfaceCacheContentStatic_ = false; 530 bool isSubTreeDirty_ = false; 531 float positionZ_ = 0.0f; 532 bool occlusionVisible_ = false; 533 bool isLeashWindowVisibleRegionEmpty_ = false; 534 Occlusion::Region visibleRegion_; 535 Occlusion::Region visibleRegionInVirtual_; 536 bool isOccludedByFilterCache_ = false; 537 // if current surfaceNode has filter cache to occlude the back surfaceNode 538 bool isFilterCacheFullyCovered_ = false; 539 std::vector<NodeId> visibleFilterChild_; 540 RSLayerInfo layerInfo_; 541 RSWindowInfo windowInfo_; 542 #ifndef ROSEN_CROSS_PLATFORM 543 sptr<SurfaceBuffer> buffer_ = nullptr; 544 sptr<SurfaceBuffer> preBuffer_ = nullptr; 545 sptr<SyncFence> acquireFence_ = SyncFence::InvalidFence(); 546 Rect damageRect_ = {0, 0, 0, 0}; 547 bool bufferSynced_ = true; 548 #endif 549 bool isHardwareEnabled_ = false; 550 bool isLastFrameHardwareEnabled_ = false; 551 bool isFixRotationByUser_ = false; 552 bool isInFixedRotation_ = false; 553 int32_t releaseInHardwareThreadTaskNum_ = 0; 554 bool isSecurityLayer_ = false; 555 bool isSkipLayer_ = false; 556 bool isProtectedLayer_ = false; 557 bool animateState_ = false; 558 bool isSubSurfaceNode_ = false; 559 Gravity uiFirstFrameGravity_ = Gravity::TOP_LEFT; 560 bool isNodeToBeCaptured_ = false; 561 std::set<NodeId> skipLayerIds_= {}; 562 std::set<NodeId> securityLayerIds_= {}; 563 std::set<NodeId> protectedLayerIds_= {}; 564 std::set<NodeId> privacyContentLayerIds_ = {}; 565 std::set<int32_t> bufferCacheSet_ = {}; 566 std::string name_= ""; 567 Vector4f overDrawBufferNodeCornerRadius_; 568 bool isGpuOverDrawBufferOptimizeNode_ = false; 569 bool isSkipDraw_ = false; 570 bool isLayerTop_ = false; 571 ScalingMode scalingMode_ = ScalingMode::SCALING_MODE_SCALE_TO_WINDOW; 572 bool needHidePrivacyContent_ = false; 573 bool needOffscreen_ = false; 574 bool layerCreated_ = false; 575 int32_t layerSource_ = 0; 576 std::vector<float> drmCornerRadiusInfo_; 577 578 Drawing::Matrix totalMatrix_; 579 float globalAlpha_ = 1.0f; 580 bool hasFingerprint_ = false; 581 // hdr 582 int32_t sdrNit_ = 500; // default sdrNit 583 int32_t displayNit_ = 500; // default displayNit_ 584 float brightnessRatio_ = 1.0; // 1.0f means no discount. 585 friend class RSSurfaceRenderNode; 586 friend class RSUniRenderProcessor; 587 friend class RSUniRenderThread; 588 }; 589 } // namespace OHOS::Rosen 590 #endif // RENDER_SERVICE_BASE_PARAMS_RS_SURFACE_RENDER_PARAMS_H 591