1 /* 2 * Copyright (c) 2021-2023 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 #ifndef RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_SURFACE_RENDER_NODE_H 16 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_SURFACE_RENDER_NODE_H 17 18 #include <climits> 19 #include <functional> 20 #include <limits> 21 #include <memory> 22 #include <tuple> 23 24 #include "memory/rs_memory_track.h" 25 26 #include "common/rs_macros.h" 27 #include "common/rs_occlusion_region.h" 28 #include "common/rs_vector4.h" 29 #include "ipc_callbacks/buffer_available_callback.h" 30 #include "ipc_callbacks/buffer_clear_callback.h" 31 #include "pipeline/rs_paint_filter_canvas.h" 32 #include "pipeline/rs_render_node.h" 33 #include "pipeline/rs_surface_handler.h" 34 #include "property/rs_properties_painter.h" 35 #include "screen_manager/screen_types.h" 36 #include "transaction/rs_occlusion_data.h" 37 38 #ifndef USE_ROSEN_DRAWING 39 #include "include/core/SkRect.h" 40 #include "include/core/SkRefCnt.h" 41 #ifdef NEW_SKIA 42 #include "include/gpu/GrDirectContext.h" 43 #else 44 #include "include/gpu/GrContext.h" 45 #include "refbase.h" 46 #endif 47 #endif 48 49 namespace OHOS { 50 namespace Rosen { 51 class RSCommand; 52 class RSDirtyRegionManager; 53 class RSB_EXPORT RSSurfaceRenderNode : public RSRenderNode, public RSSurfaceHandler { 54 public: 55 using WeakPtr = std::weak_ptr<RSSurfaceRenderNode>; 56 using SharedPtr = std::shared_ptr<RSSurfaceRenderNode>; 57 static inline constexpr RSRenderNodeType Type = RSRenderNodeType::SURFACE_NODE; GetType()58 RSRenderNodeType GetType() const override 59 { 60 return Type; 61 } 62 63 explicit RSSurfaceRenderNode(NodeId id, std::weak_ptr<RSContext> context = {}); 64 explicit RSSurfaceRenderNode(const RSSurfaceRenderNodeConfig& config, std::weak_ptr<RSContext> context = {}); 65 ~RSSurfaceRenderNode() override; 66 67 void PrepareRenderBeforeChildren(RSPaintFilterCanvas& canvas); 68 void PrepareRenderAfterChildren(RSPaintFilterCanvas& canvas); 69 70 #ifdef OHOS_PLATFORM 71 void SetIsOnTheTree(bool flag, NodeId instanceRootNodeId = INVALID_NODEID) override; 72 #endif IsAppWindow()73 bool IsAppWindow() const 74 { 75 return nodeType_ == RSSurfaceNodeType::APP_WINDOW_NODE; 76 } 77 IsStartingWindow()78 bool IsStartingWindow() const 79 { 80 return nodeType_ == RSSurfaceNodeType::STARTING_WINDOW_NODE; 81 } 82 IsAbilityComponent()83 bool IsAbilityComponent() const 84 { 85 return nodeType_ == RSSurfaceNodeType::ABILITY_COMPONENT_NODE; 86 } 87 IsLeashWindow()88 bool IsLeashWindow() const 89 { 90 return nodeType_ == RSSurfaceNodeType::LEASH_WINDOW_NODE; 91 } 92 93 // indicate if this node type can enable hardware composer IsHardwareEnabledType()94 bool IsHardwareEnabledType() const 95 { 96 return nodeType_ == RSSurfaceNodeType::SELF_DRAWING_NODE && isHardwareEnabledNode_; 97 } 98 SetHardwareEnabled(bool isEnabled)99 void SetHardwareEnabled(bool isEnabled) 100 { 101 isHardwareEnabledNode_ = isEnabled; 102 } 103 IsLastFrameHardwareEnabled()104 bool IsLastFrameHardwareEnabled() const 105 { 106 return isLastFrameHardwareEnabled_; 107 } 108 IsCurrentFrameHardwareEnabled()109 bool IsCurrentFrameHardwareEnabled() const 110 { 111 return isCurrentFrameHardwareEnabled_; 112 } 113 MarkCurrentFrameHardwareEnabled()114 void MarkCurrentFrameHardwareEnabled() 115 { 116 isCurrentFrameHardwareEnabled_ = true; 117 } 118 ResetCurrentFrameHardwareEnabledState()119 void ResetCurrentFrameHardwareEnabledState() 120 { 121 isLastFrameHardwareEnabled_ = isCurrentFrameHardwareEnabled_; 122 isCurrentFrameHardwareEnabled_ = false; 123 } 124 ResetHardwareEnabledStates()125 void ResetHardwareEnabledStates() 126 { 127 isLastFrameHardwareEnabled_ = false; 128 isCurrentFrameHardwareEnabled_ = false; 129 } 130 SetHardwareForcedDisabledState(bool forcesDisabled)131 void SetHardwareForcedDisabledState(bool forcesDisabled) 132 { 133 isHardwareForcedDisabled_ = forcesDisabled; 134 } 135 SetHardwareDisabledByCache(bool disabledByCache)136 void SetHardwareDisabledByCache(bool disabledByCache) 137 { 138 isHardwareDisabledByCache_ = disabledByCache; 139 } 140 SetHardwareForcedDisabledStateByFilter(bool forcesDisabled)141 void SetHardwareForcedDisabledStateByFilter(bool forcesDisabled) 142 { 143 isHardwareForcedDisabledByFilter_ = forcesDisabled; 144 } 145 IsHardwareForcedDisabledByFilter()146 bool IsHardwareForcedDisabledByFilter() const 147 { 148 return isHardwareForcedDisabledByFilter_; 149 } 150 IsHardwareForcedDisabled()151 bool IsHardwareForcedDisabled() const 152 { 153 return isHardwareForcedDisabled_ || isHardwareDisabledByCache_ || 154 GetDstRect().GetWidth() <= 1 || GetDstRect().GetHeight() <= 1; // avoid fallback by composer 155 } 156 IsMainWindowType()157 bool IsMainWindowType() const 158 { 159 // a mainWindowType surfacenode will not mounted under another mainWindowType surfacenode 160 // including app main window, starting window, and selfdrawing window 161 return nodeType_ == RSSurfaceNodeType::APP_WINDOW_NODE || 162 nodeType_ == RSSurfaceNodeType::STARTING_WINDOW_NODE || 163 nodeType_ == RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE; 164 } 165 IsSelfDrawingType()166 bool IsSelfDrawingType() const 167 { 168 // self drawing surfacenode has its own buffer, and rendered in its own progress/thread 169 // such as surfaceview (web/videos) and self draw windows (such as mouse pointer and boot animation) 170 return nodeType_ == RSSurfaceNodeType::SELF_DRAWING_NODE || 171 nodeType_ == RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE; 172 } 173 174 // used to determine whether the layer-1 surfacenodes can be skipped in the subthread of focus-first framework 175 bool IsCurrentFrameStatic(); 176 void UpdateCacheSurfaceDirtyManager(int bufferAge = 2); 177 GetSurfaceNodeType()178 RSSurfaceNodeType GetSurfaceNodeType() const 179 { 180 return nodeType_; 181 } 182 SetSurfaceNodeType(RSSurfaceNodeType nodeType)183 void SetSurfaceNodeType(RSSurfaceNodeType nodeType) 184 { 185 if (nodeType_ != RSSurfaceNodeType::ABILITY_COMPONENT_NODE) { 186 nodeType_ = nodeType; 187 } 188 } 189 190 void MarkUIHidden(bool isHidden); 191 bool IsUIHidden() const; 192 GetName()193 std::string GetName() const 194 { 195 return name_; 196 } 197 GetBundleName()198 std::string GetBundleName() const 199 { 200 return bundleName_; 201 } 202 SetOffSetX(int32_t offset)203 void SetOffSetX(int32_t offset) 204 { 205 offsetX_ = offset; 206 } 207 GetOffSetX()208 int32_t GetOffSetX() 209 { 210 return offsetX_; 211 } 212 SetOffSetY(int32_t offset)213 void SetOffSetY(int32_t offset) 214 { 215 offsetY_ = offset; 216 } 217 GetOffSetY()218 int32_t GetOffSetY() 219 { 220 return offsetY_; 221 } 222 SetOffset(int32_t offsetX,int32_t offsetY)223 void SetOffset(int32_t offsetX, int32_t offsetY) 224 { 225 offsetX_ = offsetX; 226 offsetY_ = offsetY; 227 } 228 229 void CollectSurface(const std::shared_ptr<RSBaseRenderNode>& node, std::vector<RSBaseRenderNode::SharedPtr>& vec, 230 bool isUniRender, bool onlyFirstLevel) override; 231 void Prepare(const std::shared_ptr<RSNodeVisitor>& visitor) override; 232 void Process(const std::shared_ptr<RSNodeVisitor>& visitor) override; 233 ProcessTransitionBeforeChildren(RSPaintFilterCanvas & canvas)234 void ProcessTransitionBeforeChildren(RSPaintFilterCanvas& canvas) override {} 235 void ProcessAnimatePropertyBeforeChildren(RSPaintFilterCanvas& canvas) override; 236 void ProcessRenderBeforeChildren(RSPaintFilterCanvas& canvas) override; 237 ProcessTransitionAfterChildren(RSPaintFilterCanvas & canvas)238 void ProcessTransitionAfterChildren(RSPaintFilterCanvas& canvas) override {} 239 void ProcessAnimatePropertyAfterChildren(RSPaintFilterCanvas& canvas) override; 240 void ProcessRenderAfterChildren(RSPaintFilterCanvas& canvas) override; 241 242 void SetContextBounds(const Vector4f bounds); 243 244 void OnApplyModifiers() override; 245 246 #ifndef USE_ROSEN_DRAWING SetTotalMatrix(const SkMatrix & totalMatrix)247 void SetTotalMatrix(const SkMatrix& totalMatrix) 248 #else 249 void SetTotalMatrix(const Drawing::Matrix& totalMatrix) 250 #endif 251 { 252 totalMatrix_ = totalMatrix; 253 } 254 #ifndef USE_ROSEN_DRAWING GetTotalMatrix()255 const SkMatrix& GetTotalMatrix() const 256 #else 257 const Drawing::Matrix& GetTotalMatrix() const 258 #endif 259 { 260 return totalMatrix_; 261 } 262 263 // Transfer the rendering context variables (matrix, alpha, and clipRegion) from the 264 // source node (in the render thread) to the 265 // target node (in the render service). Note that: 266 // - All three variables are relative to their parent node. 267 // - Alpha can be processed as an absolute value, as its parent (surface) node's alpha should always be 1.0f. 268 // - The matrix and clipRegion should be applied according to the parent node's matrix. 269 #ifndef USE_ROSEN_DRAWING 270 void SetContextMatrix(const std::optional<SkMatrix>& transform, bool sendMsg = true); 271 void SetContextAlpha(float alpha, bool sendMsg = true); 272 void SetContextClipRegion(const std::optional<SkRect>& clipRegion, bool sendMsg = true); 273 std::optional<SkRect> GetContextClipRegion() const override; 274 #else 275 void SetContextMatrix(const std::optional<Drawing::Matrix>& transform, bool sendMsg = true); 276 void SetContextAlpha(float alpha, bool sendMsg = true); 277 void SetContextClipRegion(const std::optional<Drawing::Rect>& clipRegion, bool sendMsg = true); 278 std::optional<Drawing::Rect> GetContextClipRegion() const override; 279 #endif 280 281 void SetSecurityLayer(bool isSecurityLayer); 282 bool GetSecurityLayer() const; 283 284 void SetFingerprint(bool hasFingerprint); 285 bool GetFingerprint() const; 286 287 std::shared_ptr<RSDirtyRegionManager> GetDirtyManager() const; 288 std::shared_ptr<RSDirtyRegionManager> GetCacheSurfaceDirtyManager() const; 289 SetSrcRect(const RectI & rect)290 void SetSrcRect(const RectI& rect) 291 { 292 srcRect_ = rect; 293 } 294 GetSrcRect()295 const RectI& GetSrcRect() const 296 { 297 return srcRect_; 298 } 299 SetDstRect(const RectI & dstRect)300 void SetDstRect(const RectI& dstRect) 301 { 302 if (dstRect_ != dstRect) { 303 dstRectChanged_ = true; 304 } 305 dstRect_ = dstRect; 306 } 307 GetDstRect()308 const RectI& GetDstRect() const 309 { 310 return dstRect_; 311 } 312 GetTransparentRegion()313 Occlusion::Region& GetTransparentRegion() 314 { 315 return transparentRegion_; 316 } 317 GetOpaqueRegion()318 Occlusion::Region& GetOpaqueRegion() 319 { 320 return opaqueRegion_; 321 } 322 GetContainerRegion()323 Occlusion::Region& GetContainerRegion() 324 { 325 return containerRegion_; 326 } 327 OnAlphaChanged()328 void OnAlphaChanged() override { 329 alphaChanged_ = true; 330 } 331 SetOcclusionVisible(bool visible)332 void SetOcclusionVisible(bool visible) 333 { 334 isOcclusionVisible_ = visible; 335 } 336 GetOcclusionVisible()337 bool GetOcclusionVisible() const 338 { 339 return isOcclusionVisible_; 340 } 341 GetVisibleRegion()342 const Occlusion::Region& GetVisibleRegion() const 343 { 344 return visibleRegion_; 345 } 346 SetAbilityBGAlpha(uint8_t alpha)347 void SetAbilityBGAlpha(uint8_t alpha) 348 { 349 alphaChanged_ = (alpha == 255 && abilityBgAlpha_ != 255) || 350 (alpha != 255 && abilityBgAlpha_ == 255); 351 abilityBgAlpha_ = alpha; 352 } 353 GetAbilityBgAlpha()354 uint8_t GetAbilityBgAlpha() const 355 { 356 return abilityBgAlpha_; 357 } 358 setQosCal(bool qosPidCal)359 void setQosCal(bool qosPidCal) 360 { 361 qosPidCal_ = qosPidCal; 362 } 363 364 void SetVisibleRegionRecursive( 365 const Occlusion::Region& region, VisibleData& visibleVec, std::map<uint32_t, bool>& pidVisMap); 366 GetVisibleDirtyRegion()367 const Occlusion::Region& GetVisibleDirtyRegion() const 368 { 369 return visibleDirtyRegion_; 370 } 371 SetVisibleDirtyRegion(const Occlusion::Region & region)372 void SetVisibleDirtyRegion(const Occlusion::Region& region) 373 { 374 visibleDirtyRegion_ = region; 375 } 376 SetAlignedVisibleDirtyRegion(const Occlusion::Region & alignedRegion)377 void SetAlignedVisibleDirtyRegion(const Occlusion::Region& alignedRegion) 378 { 379 alignedVisibleDirtyRegion_ = alignedRegion; 380 } 381 GetAlignedVisibleDirtyRegion()382 const Occlusion::Region& GetAlignedVisibleDirtyRegion() 383 { 384 return alignedVisibleDirtyRegion_; 385 } 386 SetExtraDirtyRegionAfterAlignment(const Occlusion::Region & region)387 void SetExtraDirtyRegionAfterAlignment(const Occlusion::Region& region) 388 { 389 extraDirtyRegionAfterAlignment_ = region; 390 extraDirtyRegionAfterAlignmentIsEmpty_ = extraDirtyRegionAfterAlignment_.IsEmpty(); 391 } 392 SetDirtyRegionAlignedEnable(bool enable)393 void SetDirtyRegionAlignedEnable(bool enable) 394 { 395 isDirtyRegionAlignedEnable_ = enable; 396 } 397 GetDirtyRegionBelowCurrentLayer()398 const Occlusion::Region& GetDirtyRegionBelowCurrentLayer() const 399 { 400 return dirtyRegionBelowCurrentLayer_; 401 } 402 SetDirtyRegionBelowCurrentLayer(Occlusion::Region & region)403 void SetDirtyRegionBelowCurrentLayer(Occlusion::Region& region) 404 { 405 #ifndef ROSEN_CROSS_PLATFORM 406 Occlusion::Rect dirtyRect { GetOldDirtyInSurface() }; 407 Occlusion::Region dirtyRegion { dirtyRect }; 408 dirtyRegionBelowCurrentLayer_ = dirtyRegion.And(region); 409 dirtyRegionBelowCurrentLayerIsEmpty_ = dirtyRegionBelowCurrentLayer_.IsEmpty(); 410 #endif 411 } 412 GetDstRectChanged()413 bool GetDstRectChanged() const 414 { 415 return dstRectChanged_; 416 } 417 CleanDstRectChanged()418 void CleanDstRectChanged() 419 { 420 dstRectChanged_ = false; 421 } 422 GetAlphaChanged()423 bool GetAlphaChanged() const 424 { 425 return alphaChanged_; 426 } 427 CleanAlphaChanged()428 void CleanAlphaChanged() 429 { 430 alphaChanged_ = false; 431 } 432 SetGlobalDirtyRegion(const RectI & rect)433 void SetGlobalDirtyRegion(const RectI& rect) 434 { 435 Occlusion::Rect tmpRect { rect.left_, rect.top_, rect.GetRight(), rect.GetBottom() }; 436 Occlusion::Region region { tmpRect }; 437 globalDirtyRegion_ = visibleRegion_.And(region); 438 globalDirtyRegionIsEmpty_ = globalDirtyRegion_.IsEmpty(); 439 } 440 GetGlobalDirtyRegion()441 const Occlusion::Region& GetGlobalDirtyRegion() const 442 { 443 return globalDirtyRegion_; 444 } 445 446 void SetLocalZOrder(float localZOrder); 447 float GetLocalZOrder() const; 448 449 #ifndef ROSEN_CROSS_PLATFORM 450 void SetColorSpace(GraphicColorGamut colorSpace); 451 GraphicColorGamut GetColorSpace() const; 452 void SetConsumer(const sptr<IConsumerSurface>& consumer); 453 void SetBlendType(GraphicBlendType blendType); 454 GraphicBlendType GetBlendType(); 455 #endif 456 457 void UpdateSurfaceDefaultSize(float width, float height); 458 459 // Only SurfaceNode in RS calls "RegisterBufferAvailableListener" 460 // to save callback method sent by RT or UI which depends on the value of "isFromRenderThread". 461 void RegisterBufferAvailableListener(sptr<RSIBufferAvailableCallback> callback, bool isFromRenderThread); 462 463 void RegisterBufferClearListener(sptr<RSIBufferClearCallback> callback); 464 465 // Only SurfaceNode in RT calls "ConnectToNodeInRenderService" to send callback method to RS 466 void ConnectToNodeInRenderService(); 467 468 void NotifyRTBufferAvailable(); 469 bool IsNotifyRTBufferAvailable() const; 470 bool IsNotifyRTBufferAvailablePre() const; 471 472 void NotifyUIBufferAvailable(); 473 bool IsNotifyUIBufferAvailable() const; 474 void SetIsNotifyUIBufferAvailable(bool available); 475 476 // UI Thread would not be notified when SurfaceNode created by Video/Camera in RenderService has available buffer. 477 // And RenderThread does not call mainFunc_ if nothing in UI thread is changed 478 // which would cause callback for "clip" on parent SurfaceNode cannot be triggered 479 // for "clip" is executed in RenderThreadVisitor::ProcessSurfaceRenderNode. 480 // To fix this bug, we set callback which would call RSRenderThread::RequestNextVSync() to forcedly "refresh" 481 // RenderThread when SurfaceNode in RenderService has available buffer and execute RSIBufferAvailableCallback. 482 void SetCallbackForRenderThreadRefresh(bool isRefresh); 483 bool NeedSetCallbackForRenderThreadRefresh(); 484 ParallelVisitLock()485 void ParallelVisitLock() 486 { 487 parallelVisitMutex_.lock(); 488 } 489 ParallelVisitUnlock()490 void ParallelVisitUnlock() 491 { 492 parallelVisitMutex_.unlock(); 493 } 494 SubNodeVisible(const RectI & r)495 bool SubNodeVisible(const RectI& r) const 496 { 497 Occlusion::Rect nodeRect { r.left_, r.top_, r.GetRight(), r.GetBottom() }; 498 // if current node is in occluded region of the surface, it could be skipped in process step 499 return visibleRegion_.IsIntersectWith(nodeRect); 500 } 501 IsTransparent()502 inline bool IsTransparent() const 503 { 504 const uint8_t opacity = 255; 505 return !(GetAbilityBgAlpha() == opacity && ROSEN_EQ(GetGlobalAlpha(), 1.0f)) || 506 (IsAppWindow() && GetChildrenCount() == 0); 507 } 508 IsCurrentNodeInTransparentRegion(const Occlusion::Rect & nodeRect)509 inline bool IsCurrentNodeInTransparentRegion(const Occlusion::Rect& nodeRect) const 510 { 511 return transparentRegion_.IsIntersectWith(nodeRect); 512 } 513 514 bool SubNodeIntersectWithDirty(const RectI& r) const; 515 516 // judge if a rect r is intersect with existing dirtyregion, include current surfacenode's dirtyregion, display 517 // dirtyregion, and dirtyregion from other surfacenode because of 32/64 bits alignment. 518 bool SubNodeNeedDraw(const RectI& r, PartialRenderType opDropType) const; 519 GetZorderChanged()520 bool GetZorderChanged() const 521 { 522 return zOrderChanged_; 523 } 524 IsZOrderPromoted()525 bool IsZOrderPromoted() const 526 { 527 return GetRenderProperties().GetPositionZ() > positionZ_; 528 } 529 UpdatePositionZ()530 void UpdatePositionZ() 531 { 532 zOrderChanged_ = !ROSEN_EQ(GetRenderProperties().GetPositionZ(), positionZ_); 533 positionZ_ = GetRenderProperties().GetPositionZ(); 534 } 535 HasContainerWindow()536 inline bool HasContainerWindow() const 537 { 538 return containerConfig_.hasContainerWindow_; 539 } 540 SetContainerWindow(bool hasContainerWindow,float density)541 void SetContainerWindow(bool hasContainerWindow, float density) 542 { 543 containerConfig_.Update(hasContainerWindow, density); 544 } 545 IsOpaqueRegionChanged()546 bool IsOpaqueRegionChanged() const 547 { 548 return opaqueRegionChanged_; 549 } 550 551 // [planning] Remove this after skia is upgraded, the clipRegion is supported 552 void ResetChildrenFilterRects(); 553 void UpdateChildrenFilterRects(const RectI& rect); 554 const std::vector<RectI>& GetChildrenNeedFilterRects() const; 555 556 // manage abilities' nodeid info 557 void ResetAbilityNodeIds(); 558 void UpdateAbilityNodeIds(NodeId id); 559 const std::vector<NodeId>& GetAbilityNodeIds() const; 560 561 // manage appWindowNode's child hardware enabled nodes info 562 void ResetChildHardwareEnabledNodes(); 563 void AddChildHardwareEnabledNode(WeakPtr childNode); 564 const std::vector<WeakPtr>& GetChildHardwareEnabledNodes() const; 565 IsFocusedNode(uint64_t focusedNodeId)566 bool IsFocusedNode(uint64_t focusedNodeId) 567 { 568 return GetNodeId() == focusedNodeId; 569 } 570 571 void ResetSurfaceOpaqueRegion( 572 const RectI& screeninfo, const RectI& absRect, const ScreenRotation screenRotation, const bool isFocusWindow); 573 Occlusion::Region ResetOpaqueRegion( 574 const RectI& absRect, const ScreenRotation screenRotation, const bool isFocusWindow) const; 575 Occlusion::Region SetUnfocusedWindowOpaqueRegion(const RectI& absRect, const ScreenRotation screenRotation) const; 576 Occlusion::Region SetFocusedWindowOpaqueRegion(const RectI& absRect, const ScreenRotation screenRotation) const; 577 Occlusion::Region SetCornerRadiusOpaqueRegion(const RectI& absRect, float radius) const; 578 void ResetSurfaceContainerRegion(const RectI& screeninfo, const RectI& absRect, 579 const ScreenRotation screenRotation); 580 bool CheckOpaqueRegionBaseInfo( 581 const RectI& screeninfo, const RectI& absRect, const ScreenRotation screenRotation, const bool isFocusWindow); 582 void SetOpaqueRegionBaseInfo( 583 const RectI& screeninfo, const RectI& absRect, const ScreenRotation screenRotation, const bool isFocusWindow); 584 585 bool IsStartAnimationFinished() const; 586 void SetStartAnimationFinished(); 587 #ifndef USE_ROSEN_DRAWING SetCachedImage(sk_sp<SkImage> image)588 void SetCachedImage(sk_sp<SkImage> image) 589 #else 590 void SetCachedImage(std::shared_ptr<Drawing::Image> image) 591 #endif 592 { 593 SetContentDirty(); 594 std::lock_guard<std::mutex> lock(cachedImageMutex_); 595 cachedImage_ = image; 596 } 597 598 #ifndef USE_ROSEN_DRAWING GetCachedImage()599 sk_sp<SkImage> GetCachedImage() const 600 #else 601 std::shared_ptr<Drawing::Image> GetCachedImage() const 602 #endif 603 { 604 std::lock_guard<std::mutex> lock(cachedImageMutex_); 605 return cachedImage_; 606 } 607 ClearCachedImage()608 void ClearCachedImage() 609 { 610 std::lock_guard<std::mutex> lock(cachedImageMutex_); 611 cachedImage_ = nullptr; 612 } 613 614 // if surfacenode's buffer has been consumed, it should be set dirty 615 bool UpdateDirtyIfFrameBufferConsumed(); 616 617 #ifndef USE_ROSEN_DRAWING 618 void UpdateSrcRect(const RSPaintFilterCanvas& canvas, const SkIRect& dstRect); 619 #else 620 void UpdateSrcRect(const RSPaintFilterCanvas& canvas, const Drawing::RectI& dstRect); 621 #endif 622 623 // if a surfacenode's dstrect is empty, its subnodes' prepare stage can be skipped 624 bool ShouldPrepareSubnodes(); 625 SetNodeCost(int32_t cost)626 void SetNodeCost(int32_t cost) 627 { 628 nodeCost_ = cost; 629 } 630 GetNodeCost()631 int32_t GetNodeCost() const 632 { 633 return nodeCost_; 634 } 635 636 std::string DirtyRegionDump() const; SetAnimateState()637 void SetAnimateState() { 638 animateState_ = true; 639 } ResetAnimateState()640 void ResetAnimateState() { 641 animateState_ = false; 642 } GetAnimateState()643 bool GetAnimateState() const{ 644 return animateState_; 645 } 646 bool LeashWindowRelatedAppWindowOccluded(std::shared_ptr<RSSurfaceRenderNode>& appNode); 647 648 void OnTreeStateChanged() override; 649 650 #ifndef USE_ROSEN_DRAWING 651 #ifdef NEW_SKIA SetGrContext(GrDirectContext * grContext)652 void SetGrContext(GrDirectContext* grContext) 653 #else 654 void SetGrContext(GrContext* grContext) 655 #endif 656 #else 657 void SetDrawingGPUContext(Drawing::GPUContext* grContext) 658 #endif 659 { 660 grContext_ = grContext; 661 } 662 // UIFirst SetSubmittedSubThreadIndex(uint32_t index)663 void SetSubmittedSubThreadIndex(uint32_t index) 664 { 665 submittedSubThreadIndex_ = index; 666 } 667 GetSubmittedSubThreadIndex()668 uint32_t GetSubmittedSubThreadIndex() const 669 { 670 return submittedSubThreadIndex_; 671 } 672 673 void SetCacheSurfaceProcessedStatus(CacheProcessStatus cacheProcessStatus); 674 CacheProcessStatus GetCacheSurfaceProcessedStatus() const; 675 bool NodeIsUsedBySubThread() const override; 676 GetFilterCacheFullyCovered()677 bool GetFilterCacheFullyCovered() const 678 { 679 return isFilterCacheFullyCovered_; 680 } 681 SetFilterCacheFullyCovered(bool val)682 void SetFilterCacheFullyCovered(bool val) 683 { 684 isFilterCacheFullyCovered_ = val; 685 } 686 ResetFilterNodes()687 void ResetFilterNodes() 688 { 689 filterNodes_.clear(); 690 } 691 void UpdateFilterNodes(const std::shared_ptr<RSRenderNode>& nodePtr); 692 // update static node's back&front-ground filter cache status 693 void UpdateFilterCacheStatusIfNodeStatic(const RectI& clipRect); 694 695 void SetNotifyRTBufferAvailable(bool isNotifyRTBufferAvailable); 696 697 private: IsSelfDrawingNode()698 bool IsSelfDrawingNode() const override 699 { 700 return IsSelfDrawingType(); 701 } 702 703 void OnResetParent() override; 704 void ClearChildrenCache(const std::shared_ptr<RSBaseRenderNode>& node); 705 bool SubNodeIntersectWithExtraDirtyRegion(const RectI& r) const; 706 Vector4f GetWindowCornerRadius(); 707 std::vector<std::shared_ptr<RSSurfaceRenderNode>> GetLeashWindowNestedSurfaces(); 708 709 std::mutex mutexRT_; 710 std::mutex mutexUI_; 711 std::mutex mutexClear_; 712 std::mutex mutex_; 713 #ifndef USE_ROSEN_DRAWING 714 #ifdef NEW_SKIA 715 GrDirectContext* grContext_ = nullptr; 716 #else 717 GrContext* grContext_ = nullptr; 718 #endif 719 #else 720 Drawing::GPUContext* grContext_ = nullptr; 721 #endif 722 std::mutex parallelVisitMutex_; 723 724 float contextAlpha_ = 1.0f; 725 #ifndef USE_ROSEN_DRAWING 726 std::optional<SkMatrix> contextMatrix_; 727 std::optional<SkRect> contextClipRect_; 728 #else 729 std::optional<Drawing::Matrix> contextMatrix_; 730 std::optional<Drawing::Rect> contextClipRect_; 731 #endif 732 733 bool isSecurityLayer_ = false; 734 bool hasFingerprint_ = false; 735 bool isReportFirstFrame_ = false; 736 RectI srcRect_; 737 #ifndef USE_ROSEN_DRAWING 738 SkMatrix totalMatrix_; 739 #else 740 Drawing::Matrix totalMatrix_; 741 #endif 742 int32_t offsetX_ = 0; 743 int32_t offsetY_ = 0; 744 float positionZ_ = 0.0f; 745 bool zOrderChanged_ = false; 746 bool qosPidCal_ = false; 747 748 std::string name_; 749 std::string bundleName_; 750 RSSurfaceNodeType nodeType_ = RSSurfaceNodeType::DEFAULT; 751 #ifndef ROSEN_CROSS_PLATFORM 752 GraphicColorGamut colorSpace_ = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB; 753 GraphicBlendType blendType_ = GraphicBlendType::GRAPHIC_BLEND_SRCOVER; 754 #endif 755 bool isNotifyRTBufferAvailablePre_ = false; 756 std::atomic<bool> isNotifyRTBufferAvailable_ = false; 757 std::atomic<bool> isNotifyUIBufferAvailable_ = true; 758 std::atomic_bool isBufferAvailable_ = false; 759 sptr<RSIBufferAvailableCallback> callbackFromRT_; 760 sptr<RSIBufferAvailableCallback> callbackFromUI_; 761 sptr<RSIBufferClearCallback> clearBufferCallback_; 762 bool isRefresh_ = false; 763 std::vector<NodeId> childSurfaceNodeIds_; 764 friend class RSRenderThreadVisitor; 765 RectI clipRegionFromParent_; 766 Occlusion::Region visibleRegion_; 767 Occlusion::Region visibleDirtyRegion_; 768 bool isDirtyRegionAlignedEnable_ = false; 769 Occlusion::Region alignedVisibleDirtyRegion_; 770 bool isOcclusionVisible_ = true; 771 std::shared_ptr<RSDirtyRegionManager> dirtyManager_ = nullptr; 772 std::shared_ptr<RSDirtyRegionManager> cacheSurfaceDirtyManager_ = nullptr; 773 RectI dstRect_; 774 bool dstRectChanged_ = false; 775 uint8_t abilityBgAlpha_ = 0; 776 bool alphaChanged_ = false; 777 bool isUIHidden_ = false; 778 Occlusion::Region globalDirtyRegion_; 779 // dirtyRegion caused by surfaceNode visible region after alignment 780 Occlusion::Region extraDirtyRegionAfterAlignment_; 781 bool extraDirtyRegionAfterAlignmentIsEmpty_ = true; 782 783 bool globalDirtyRegionIsEmpty_ = false; 784 // if a there a dirty layer under transparent clean layer, transparent layer should refreshed 785 Occlusion::Region dirtyRegionBelowCurrentLayer_; 786 bool dirtyRegionBelowCurrentLayerIsEmpty_ = false; 787 788 // opaque region of the surface 789 Occlusion::Region opaqueRegion_; 790 bool opaqueRegionChanged_ = false; 791 // [planning] Remove this after skia is upgraded, the clipRegion is supported 792 std::vector<RectI> childrenFilterRects_; 793 std::vector<NodeId> abilityNodeIds_; 794 // transparent region of the surface, floating window's container window is always treated as transparent 795 Occlusion::Region transparentRegion_; 796 797 Occlusion::Region containerRegion_; 798 bool isFilterCacheFullyCovered_ = false; 799 std::unordered_map<NodeId, std::shared_ptr<RSRenderNode>> 800 filterNodes_; // valid filter nodes within, including itself 801 802 struct OpaqueRegionBaseInfo 803 { 804 RectI screenRect_; 805 RectI absRect_; 806 ScreenRotation screenRotation_; 807 bool isFocusWindow_; 808 bool isTransparent_; 809 bool hasContainerWindow_; 810 }; 811 812 //<screenRect, absRect, screenRotation, isFocusWindow, isTransparent, hasContainerWindow> 813 OpaqueRegionBaseInfo opaqueRegionBaseInfo_; 814 815 /* 816 ContainerWindow configs acquired from arkui, including container window state, screen density, container border 817 width, padding width, inner/outer radius, etc. 818 */ 819 class ContainerConfig { 820 public: 821 void Update(bool hasContainer, float density); 822 private: RoundFloor(float length)823 inline int RoundFloor(float length) 824 { 825 // if a float value is very close to a integer (< 0.05f), return round value 826 return std::abs(length - std::round(length)) < 0.05f ? std::round(length) : std::floor(length); 827 } 828 public: 829 // temporary const value from ACE container_modal_constants.h, will be replaced by uniform interface 830 const static int CONTAINER_TITLE_HEIGHT = 37; // container title height = 37 vp 831 const static int CONTENT_PADDING = 4; // container <--> content distance 4 vp 832 const static int CONTAINER_BORDER_WIDTH = 1; // container border width 2 vp 833 const static int CONTAINER_OUTER_RADIUS = 16; // container outer radius 16 vp 834 const static int CONTAINER_INNER_RADIUS = 14; // container inner radius 14 vp 835 836 bool hasContainerWindow_ = false; // set to false as default, set by arkui 837 float density = 2.0f; // The density default value is 2 838 int outR = 32; // outer radius (int value) 839 int inR = 28; // inner radius (int value) 840 int bp = 10; // border width + padding (int value) 841 int bt = 76; // border width + title (int value) 842 }; 843 844 ContainerConfig containerConfig_; 845 846 bool startAnimationFinished_ = false; 847 mutable std::mutex cachedImageMutex_; 848 #ifndef USE_ROSEN_DRAWING 849 sk_sp<SkImage> cachedImage_; 850 #else 851 std::shared_ptr<Drawing::Image> cachedImage_; 852 #endif 853 854 // used for hardware enabled nodes 855 bool isHardwareEnabledNode_ = false; 856 bool isCurrentFrameHardwareEnabled_ = false; 857 bool isLastFrameHardwareEnabled_ = false; 858 // mark if this self-drawing node is forced not to use hardware composer 859 // in case where this node's parent window node is occluded or is appFreeze, this variable will be marked true 860 bool isHardwareForcedDisabled_ = false; 861 bool isHardwareForcedDisabledByFilter_ = false; 862 bool isHardwareDisabledByCache_ = false; 863 float localZOrder_ = 0.0f; 864 std::vector<WeakPtr> childHardwareEnabledNodes_; 865 int32_t nodeCost_ = 0; 866 867 bool animateState_ = false; 868 869 bool needDrawAnimateProperty_ = false; 870 871 // UIFirst 872 uint32_t submittedSubThreadIndex_ = INT_MAX; 873 std::atomic<CacheProcessStatus> cacheProcessStatus_ = CacheProcessStatus::WAITING; 874 875 friend class RSUniRenderVisitor; 876 friend class RSRenderNode; 877 friend class RSRenderService; 878 }; 879 } // namespace Rosen 880 } // namespace OHOS 881 882 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_SURFACE_RENDER_NODE_H 883