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_THREAD_PARAMS_H 17 #define RENDER_SERVICE_BASE_PARAMS_RS_RENDER_THREAD_PARAMS_H 18 19 #include <memory> 20 #include <vector> 21 #include "common/rs_occlusion_region.h" 22 #include "pipeline/rs_screen_render_node.h" 23 #include "pipeline/rs_surface_render_node.h" 24 #include "platform/ohos/rs_jank_stats.h" 25 #include "property/rs_properties.h" 26 #include "screen_manager/rs_screen_info.h" 27 28 namespace OHOS::Rosen { 29 class RSProcessor; 30 class RSSLRScaleFunction; 31 struct CaptureParam { 32 bool isSnapshot_ = false; 33 bool isSingleSurface_ = false; 34 bool isMirror_ = false; 35 uint64_t virtualScreenId_ = INVALID_SCREEN_ID; 36 NodeId rootIdInWhiteList_ = INVALID_NODEID; 37 bool isFirstNode_ = false; 38 bool isSystemCalling_ = false; 39 bool isSelfCapture_ = false; 40 bool isNeedBlur_ = false; 41 bool isSoloNodeUiCapture_ = false; 42 NodeId endNodeId_ = INVALID_NODEID; 43 bool captureFinished_ = false; CaptureParamCaptureParam44 CaptureParam() {} 45 CaptureParam(bool isSnapshot, bool isSingleSurface, bool isMirror, bool isFirstNode = false, 46 bool isSystemCalling = false, bool isSelfCapture = false, bool isNeedBlur = false, 47 bool isSoloNodeUiCapture = false, NodeId endNodeId = INVALID_NODEID, bool captureFinished = false) isSnapshot_CaptureParam48 : isSnapshot_(isSnapshot), 49 isSingleSurface_(isSingleSurface), 50 isMirror_(isMirror), 51 isFirstNode_(isFirstNode), 52 isSystemCalling_(isSystemCalling), 53 isSelfCapture_(isSelfCapture), 54 isNeedBlur_(isNeedBlur), 55 isSoloNodeUiCapture_(isSoloNodeUiCapture), 56 endNodeId_(endNodeId), 57 captureFinished_(captureFinished) {} 58 }; 59 struct HardCursorInfo { 60 NodeId id = INVALID_NODEID; 61 DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr drawablePtr = nullptr; 62 }; 63 64 enum ForceCommitReason { 65 NO_FORCE = 0, 66 FORCED_BY_UNI_RENDER_FLAG = 1, 67 FORCED_BY_HWC_UPDATE = 1 << 1, 68 FORCED_BY_POINTER_WINDOW = 1 << 2, 69 }; 70 71 class RSB_EXPORT RSRenderThreadParams { 72 public: 73 using DrawablesVec = std::vector<std::tuple<NodeId, NodeId, 74 DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr>>; 75 76 RSRenderThreadParams() = default; 77 virtual ~RSRenderThreadParams() = default; 78 IsPartialRenderEnabled()79 bool IsPartialRenderEnabled() const 80 { 81 return isPartialRenderEnabled_; 82 } 83 IsRegionDebugEnabled()84 bool IsRegionDebugEnabled() const 85 { 86 return isRegionDebugEnabled_; 87 } 88 IsAllSurfaceVisibleDebugEnabled()89 bool IsAllSurfaceVisibleDebugEnabled() const 90 { 91 return isAllSurfaceVisibleDebugEnabled_; 92 } 93 SetVirtualDirtyEnabled(bool isVirtualDirtyEnabled)94 void SetVirtualDirtyEnabled(bool isVirtualDirtyEnabled) 95 { 96 isVirtualDirtyEnabled_ = isVirtualDirtyEnabled; 97 } 98 IsVirtualDirtyEnabled()99 bool IsVirtualDirtyEnabled() const 100 { 101 return isVirtualDirtyEnabled_; 102 } 103 IsExpandScreenDirtyEnabled()104 bool IsExpandScreenDirtyEnabled() const 105 { 106 return isExpandScreenDirtyEnabled_; 107 } 108 IsVirtualDirtyDfxEnabled()109 bool IsVirtualDirtyDfxEnabled() const 110 { 111 return isVirtualDirtyDfxEnabled_; 112 } 113 IsOpDropped()114 bool IsOpDropped() const 115 { 116 return isOpDropped_; 117 } 118 SetOpDropped(bool opDropped)119 void SetOpDropped(bool opDropped) 120 { 121 isOpDropped_ = opDropped; 122 } 123 IsDirtyAlignEnabled()124 bool IsDirtyAlignEnabled() const 125 { 126 return isDirtyAlignEnabled_; 127 } 128 IsStencilPixelOcclusionCullingEnabled()129 bool IsStencilPixelOcclusionCullingEnabled() const 130 { 131 return isStencilPixelOcclusionCullingEnabled_; 132 } 133 HasDisplayHdrOn()134 bool HasDisplayHdrOn() const 135 { 136 return hasDisplayHdrOn_; 137 } 138 IsMirrorScreen()139 bool IsMirrorScreen() const 140 { 141 return isMirrorScreen_; 142 } 143 SetIsMirrorScreen(bool isMirrorScreen)144 void SetIsMirrorScreen(bool isMirrorScreen) 145 { 146 isMirrorScreen_ = isMirrorScreen; 147 } 148 IsFirstVisitCrossNodeDisplay()149 bool IsFirstVisitCrossNodeDisplay() const 150 { 151 return isFirstVisitCrossNodeDisplay_; 152 } 153 SetIsFirstVisitCrossNodeDisplay(bool isFirstVisitCrossNodeDisplay)154 void SetIsFirstVisitCrossNodeDisplay(bool isFirstVisitCrossNodeDisplay) 155 { 156 isFirstVisitCrossNodeDisplay_ = isFirstVisitCrossNodeDisplay; 157 } 158 GetCrossNodeOffScreenStatus()159 CrossNodeOffScreenRenderDebugType GetCrossNodeOffScreenStatus() const 160 { 161 return isCrossNodeOffscreenOn_; 162 } 163 GetUIFirstDebugEnabled()164 bool GetUIFirstDebugEnabled() const 165 { 166 return isUIFirstDebugEnable_; 167 } 168 SetUIFirstCurrentFrameCanSkipFirstWait(bool canSkip)169 void SetUIFirstCurrentFrameCanSkipFirstWait(bool canSkip) 170 { 171 isUIFirstCurrentFrameCanSkipFirstWait_ = canSkip; 172 } 173 GetUIFirstCurrentFrameCanSkipFirstWait()174 bool GetUIFirstCurrentFrameCanSkipFirstWait() const 175 { 176 return isUIFirstCurrentFrameCanSkipFirstWait_; 177 } 178 SetTimestamp(uint64_t timestamp)179 void SetTimestamp(uint64_t timestamp) 180 { 181 timestamp_ = timestamp; 182 } 183 GetCurrentTimestamp()184 uint64_t GetCurrentTimestamp() const 185 { 186 return timestamp_; 187 } 188 SetActualTimestamp(int64_t timestamp)189 void SetActualTimestamp(int64_t timestamp) 190 { 191 actualTimestamp_ = timestamp; 192 } 193 GetActualTimestamp()194 int64_t GetActualTimestamp() const 195 { 196 return actualTimestamp_; 197 } 198 SetVsyncId(uint64_t vsyncId)199 void SetVsyncId(uint64_t vsyncId) 200 { 201 vsyncId_ = vsyncId; 202 } 203 GetVsyncId()204 uint64_t GetVsyncId() const 205 { 206 return vsyncId_; 207 } 208 SetForceRefreshFlag(bool isForceRefresh)209 void SetForceRefreshFlag(bool isForceRefresh) 210 { 211 isForceRefresh_ = isForceRefresh; 212 } 213 GetForceRefreshFlag()214 bool GetForceRefreshFlag() const 215 { 216 return isForceRefresh_; 217 } 218 SetFastComposeTimeStampDiff(uint64_t fastComposeTimeStampDiff)219 void SetFastComposeTimeStampDiff(uint64_t fastComposeTimeStampDiff) 220 { 221 fastComposeTimeStampDiff_ = fastComposeTimeStampDiff; 222 } 223 GetFastComposeTimeStampDiff()224 uint64_t GetFastComposeTimeStampDiff() const 225 { 226 return fastComposeTimeStampDiff_; 227 } 228 GetSelfDrawables()229 const std::vector<DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr>& GetSelfDrawables() const 230 { 231 return selfDrawables_; 232 } 233 GetHardwareEnabledTypeDrawables()234 const DrawablesVec& GetHardwareEnabledTypeDrawables() const 235 { 236 return hardwareEnabledTypeDrawables_; 237 } 238 GetHardCursorDrawables()239 const auto& GetHardCursorDrawables() const 240 { 241 return hardCursorDrawableVec_; 242 } 243 SetPendingScreenRefreshRate(uint32_t rate)244 void SetPendingScreenRefreshRate(uint32_t rate) 245 { 246 pendingScreenRefreshRate_ = rate; 247 } 248 GetPendingScreenRefreshRate()249 uint32_t GetPendingScreenRefreshRate() const 250 { 251 return pendingScreenRefreshRate_; 252 } 253 SetPendingConstraintRelativeTime(uint64_t relativeTime)254 void SetPendingConstraintRelativeTime(uint64_t relativeTime) 255 { 256 pendingConstraintRelativeTime_ = relativeTime; 257 } 258 GetPendingConstraintRelativeTime()259 uint64_t GetPendingConstraintRelativeTime() const 260 { 261 return pendingConstraintRelativeTime_; 262 } 263 GetAccumulatedDirtyRegion()264 Occlusion::Region& GetAccumulatedDirtyRegion() 265 { 266 return accumulatedDirtyRegion_; 267 } 268 Reset()269 bool Reset() 270 { 271 accumulatedDirtyRegion_.Reset(); 272 return true; 273 } 274 GetWatermarkFlag()275 bool GetWatermarkFlag() const 276 { 277 return watermarkFlag_; 278 } 279 280 std::shared_ptr<Media::PixelMap> GetWatermark(pid_t pid, const std::string& name) const; 281 GetWatermarkImg()282 std::shared_ptr<Drawing::Image> GetWatermarkImg() const 283 { 284 return watermarkImg_; 285 } 286 SetWatermark(bool watermarkFlag,const std::shared_ptr<Drawing::Image> & watermarkImg)287 void SetWatermark(bool watermarkFlag, const std::shared_ptr<Drawing::Image>& watermarkImg) 288 { 289 watermarkFlag_ = watermarkFlag; 290 watermarkImg_ = watermarkImg; 291 } 292 293 void SetWatermarks(std::map<std::pair<pid_t, std::string>, std::shared_ptr<Media::PixelMap>>& watermarks); 294 SetOcclusionEnabled(bool isOcclusionEnabled)295 void SetOcclusionEnabled(bool isOcclusionEnabled) 296 { 297 isOcclusionEnabled_ = isOcclusionEnabled; 298 } 299 IsOcclusionEnabled()300 bool IsOcclusionEnabled() const 301 { 302 return isOcclusionEnabled_; 303 } 304 SetCurtainScreenUsingStatus(bool isCurtainScreenOn)305 void SetCurtainScreenUsingStatus(bool isCurtainScreenOn) 306 { 307 isCurtainScreenOn_ = isCurtainScreenOn; 308 } 309 IsCurtainScreenOn()310 bool IsCurtainScreenOn() const 311 { 312 return isCurtainScreenOn_; 313 } 314 SetForceCommitLayer(uint32_t forceCommitReason)315 void SetForceCommitLayer(uint32_t forceCommitReason) 316 { 317 forceCommitReason_ = forceCommitReason; 318 } 319 GetForceCommitReason()320 uint32_t GetForceCommitReason() const 321 { 322 return forceCommitReason_; 323 } 324 SetCacheEnabledForRotation(bool flag)325 void SetCacheEnabledForRotation(bool flag) 326 { 327 cacheEnabledForRotation_ = flag; 328 } 329 GetCacheEnabledForRotation()330 bool GetCacheEnabledForRotation() const 331 { 332 return cacheEnabledForRotation_; 333 } 334 SetOnVsyncStartTime(int64_t time)335 void SetOnVsyncStartTime(int64_t time) 336 { 337 onVsyncStartTime_ = time; 338 } 339 GetOnVsyncStartTime()340 int64_t GetOnVsyncStartTime() const 341 { 342 return onVsyncStartTime_; 343 } 344 SetOnVsyncStartTimeSteady(int64_t timeSteady)345 void SetOnVsyncStartTimeSteady(int64_t timeSteady) 346 { 347 onVsyncStartTimeSteady_ = timeSteady; 348 } 349 GetOnVsyncStartTimeSteady()350 int64_t GetOnVsyncStartTimeSteady() const 351 { 352 return onVsyncStartTimeSteady_; 353 } 354 SetOnVsyncStartTimeSteadyFloat(float timeSteadyFloat)355 void SetOnVsyncStartTimeSteadyFloat(float timeSteadyFloat) 356 { 357 onVsyncStartTimeSteadyFloat_ = timeSteadyFloat; 358 } 359 GetOnVsyncStartTimeSteadyFloat()360 float GetOnVsyncStartTimeSteadyFloat() const 361 { 362 return onVsyncStartTimeSteadyFloat_; 363 } 364 SetIsUniRenderAndOnVsync(bool isUniRenderAndOnVsync)365 void SetIsUniRenderAndOnVsync(bool isUniRenderAndOnVsync) 366 { 367 isUniRenderAndOnVsync_ = isUniRenderAndOnVsync; 368 } 369 IsUniRenderAndOnVsync()370 bool IsUniRenderAndOnVsync() const 371 { 372 return isUniRenderAndOnVsync_; 373 } 374 SetContext(std::shared_ptr<RSContext> context)375 void SetContext(std::shared_ptr<RSContext> context) 376 { 377 context_ = context; 378 } 379 GetContext()380 const std::shared_ptr<RSContext> GetContext() const 381 { 382 return context_.lock(); 383 } 384 SetClipRegion(const Drawing::Region & clipRegion)385 void SetClipRegion(const Drawing::Region& clipRegion) 386 { 387 clipRegion_.Clone(clipRegion); 388 } 389 GetClipRegion()390 const Drawing::Region& GetClipRegion() const 391 { 392 return clipRegion_; 393 } 394 SetForceMirrorScreenDirty(bool flag)395 void SetForceMirrorScreenDirty(bool flag) 396 { 397 isMirrorScreenDirty_ = flag; 398 } 399 GetForceMirrorScreenDirty()400 bool GetForceMirrorScreenDirty() const 401 { 402 return isMirrorScreenDirty_; 403 } 404 SetImplicitAnimationEnd(bool isImplicitAnimationEnd)405 void SetImplicitAnimationEnd(bool isImplicitAnimationEnd) 406 { 407 isImplicitAnimationEnd_ = isImplicitAnimationEnd; 408 } 409 GetImplicitAnimationEnd()410 bool GetImplicitAnimationEnd() const 411 { 412 return isImplicitAnimationEnd_; 413 } 414 SetDiscardJankFrames(bool discardJankFrames)415 void SetDiscardJankFrames(bool discardJankFrames) 416 { 417 discardJankFrames_ = discardJankFrames; 418 } 419 GetDiscardJankFrames()420 bool GetDiscardJankFrames() const 421 { 422 return discardJankFrames_; 423 } 424 HasMirrorDisplay()425 bool HasMirrorDisplay() const 426 { 427 return hasMirrorDisplay_; 428 } 429 SetSecExemption(bool isSecurityExemption)430 void SetSecExemption(bool isSecurityExemption) 431 { 432 isSecurityExemption_ = isSecurityExemption; 433 } 434 GetSecExemption()435 bool GetSecExemption() const 436 { 437 return isSecurityExemption_; 438 } 439 IsOverDrawEnabled()440 bool IsOverDrawEnabled() const 441 { 442 return isOverDrawEnabled_; 443 } 444 IsDrawingCacheDfxEnabled()445 bool IsDrawingCacheDfxEnabled() const 446 { 447 return isDrawingCacheDfxEnabled_; 448 } 449 GetScreenInfo()450 const ScreenInfo& GetScreenInfo() const 451 { 452 return screenInfo_; 453 } 454 SetScreenInfo(const ScreenInfo & info)455 void SetScreenInfo(const ScreenInfo& info) 456 { 457 screenInfo_ = info; 458 } 459 GetCompositeType()460 CompositeType GetCompositeType() const 461 { 462 return compositeType_; 463 } 464 SetCompositeType(CompositeType type)465 void SetCompositeType(CompositeType type) 466 { 467 compositeType_ = type; 468 } GetCurrentVisitDisplayDrawableId()469 NodeId GetCurrentVisitDisplayDrawableId() const 470 { 471 return currentVisitDisplayDrawableId_; 472 } SetCurrentVisitDisplayDrawableId(NodeId displayId)473 void SetCurrentVisitDisplayDrawableId(NodeId displayId) 474 { 475 currentVisitDisplayDrawableId_ = displayId; 476 } 477 HasPhysicMirror()478 bool HasPhysicMirror() const 479 { 480 return isMirrorScreen_ && compositeType_ == CompositeType::UNI_RENDER_COMPOSITE; 481 } 482 GetAdvancedDirtyType()483 AdvancedDirtyRegionType GetAdvancedDirtyType() const 484 { 485 return advancedDirtyType_; 486 } 487 SetRSProcessor(const std::shared_ptr<RSProcessor> & processor)488 void SetRSProcessor(const std::shared_ptr<RSProcessor>& processor) 489 { 490 processor_ = processor; 491 } 492 GetRSProcessor()493 std::shared_ptr<RSProcessor> GetRSProcessor() const 494 { 495 return processor_; 496 } 497 SetVirtualDirtyRefresh(bool virtualdirtyRefresh)498 void SetVirtualDirtyRefresh(bool virtualdirtyRefresh) 499 { 500 virtualDirtyRefresh_ = virtualdirtyRefresh; 501 } 502 GetVirtualDirtyRefresh()503 bool GetVirtualDirtyRefresh() const 504 { 505 return virtualDirtyRefresh_; 506 } 507 SetSLRScaleManager(std::shared_ptr<RSSLRScaleFunction> slrManager)508 void SetSLRScaleManager(std::shared_ptr<RSSLRScaleFunction> slrManager) 509 { 510 slrManager_ = slrManager; 511 } 512 GetSLRScaleManager()513 std::shared_ptr<RSSLRScaleFunction> GetSLRScaleManager() const 514 { 515 return slrManager_; 516 } 517 518 private: 519 bool virtualDirtyRefresh_ = false; 520 // Used by hardware thred 521 uint64_t timestamp_ = 0; 522 int64_t actualTimestamp_ = 0; 523 uint64_t vsyncId_ = 0; 524 bool isForceRefresh_ = false; 525 uint32_t pendingScreenRefreshRate_ = 0; 526 uint64_t pendingConstraintRelativeTime_ = 0; 527 uint64_t fastComposeTimeStampDiff_ = 0; 528 // RSDirtyRectsDfx dfx 529 std::vector<std::string> dfxTargetSurfaceNames_; 530 bool hasDisplayHdrOn_ = false; 531 bool isMirrorScreen_ = false; 532 bool isFirstVisitCrossNodeDisplay_ = false; 533 bool isRegionDebugEnabled_ = false; 534 bool isPartialRenderEnabled_ = false; 535 bool isDirtyRegionDfxEnabled_ = false; 536 bool isTargetDirtyRegionDfxEnabled_ = false; 537 bool isDisplayDirtyDfxEnabled_ = false; 538 bool isOpaqueRegionDfxEnabled_ = false; 539 bool isVisibleRegionDfxEnabled_ = false; 540 bool isMergedDirtyRegionDfxEnabled_ = false; 541 bool isAllSurfaceVisibleDebugEnabled_ = false; 542 bool isOpDropped_ = false; 543 bool isDirtyAlignEnabled_ = false; 544 bool isStencilPixelOcclusionCullingEnabled_ = false; 545 bool isOcclusionEnabled_ = false; 546 CrossNodeOffScreenRenderDebugType isCrossNodeOffscreenOn_ = CrossNodeOffScreenRenderDebugType::ENABLE; 547 bool isUIFirstDebugEnable_ = false; 548 bool isUIFirstCurrentFrameCanSkipFirstWait_ = false; 549 bool isVirtualDirtyDfxEnabled_ = false; 550 bool isVirtualDirtyEnabled_ = false; 551 bool isExpandScreenDirtyEnabled_ = false; 552 bool isMirrorScreenDirty_ = false; 553 bool cacheEnabledForRotation_ = false; 554 NodeId currentVisitDisplayDrawableId_ = INVALID_NODEID; 555 AdvancedDirtyRegionType advancedDirtyType_ = AdvancedDirtyRegionType::DISABLED; 556 DirtyRegionDebugType dirtyRegionDebugType_ = DirtyRegionDebugType::DISABLED; 557 std::vector<DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr> selfDrawables_; 558 DrawablesVec hardwareEnabledTypeDrawables_; 559 std::vector<std::tuple<NodeId, NodeId, DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr>> hardCursorDrawableVec_; 560 uint32_t forceCommitReason_ = 0; 561 bool hasMirrorDisplay_ = false; 562 // accumulatedDirtyRegion to decide whether to skip tranasparent nodes. 563 Occlusion::Region accumulatedDirtyRegion_; 564 bool watermarkFlag_ = false; 565 std::shared_ptr<Drawing::Image> watermarkImg_ = nullptr; 566 std::map<std::pair<pid_t, std::string>, std::shared_ptr<Media::PixelMap>> surfaceNodeWatermarks_; 567 std::shared_ptr<RSSLRScaleFunction> slrManager_ = nullptr; 568 569 bool isOverDrawEnabled_ = false; 570 bool isDrawingCacheDfxEnabled_ = false; 571 572 int64_t onVsyncStartTime_ = TIMESTAMP_INITIAL; 573 int64_t onVsyncStartTimeSteady_ = TIMESTAMP_INITIAL; 574 float onVsyncStartTimeSteadyFloat_ = TIMESTAMP_INITIAL_FLOAT; 575 bool isUniRenderAndOnVsync_ = false; 576 std::weak_ptr<RSContext> context_; 577 bool isCurtainScreenOn_ = false; 578 CompositeType compositeType_ = CompositeType::HARDWARE_COMPOSITE; 579 580 Drawing::Region clipRegion_; 581 bool isImplicitAnimationEnd_ = false; 582 bool discardJankFrames_ = false; 583 584 bool isSecurityExemption_ = false; 585 ScreenInfo screenInfo_ = {}; 586 std::shared_ptr<RSProcessor> processor_ = nullptr; 587 588 friend class RSMainThread; 589 friend class RSUniRenderVisitor; 590 friend class RSDirtyRectsDfx; 591 }; 592 593 class RSRenderThreadParamsManager { 594 public: 595 RSRenderThreadParamsManager() = default; 596 ~RSRenderThreadParamsManager() = default; 597 Instance()598 static RSRenderThreadParamsManager& Instance() 599 { 600 static RSRenderThreadParamsManager instance; 601 return instance; 602 } 603 SetRSRenderThreadParams(std::unique_ptr<RSRenderThreadParams> && renderThreadParams)604 inline void SetRSRenderThreadParams(std::unique_ptr<RSRenderThreadParams>&& renderThreadParams) 605 { 606 renderThreadParams_ = std::move(renderThreadParams); 607 } GetRSRenderThreadParams()608 inline const std::unique_ptr<RSRenderThreadParams>& GetRSRenderThreadParams() const 609 { 610 return renderThreadParams_; 611 } 612 613 private: 614 static inline thread_local std::unique_ptr<RSRenderThreadParams> renderThreadParams_ = nullptr; 615 }; 616 } // namespace OHOS::Rosen 617 #endif // RENDER_SERVICE_BASE_PARAMS_RS_RENDER_THREAD_PARAMS_H 618