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
16 #include "pipeline/rs_surface_render_node.h"
17
18 #include "command/rs_command_verify_helper.h"
19 #include "command/rs_surface_node_command.h"
20 #include "common/rs_common_def.h"
21 #include "common/rs_common_hook.h"
22 #include "display_engine/rs_color_temperature.h"
23 #include "rs_trace.h"
24 #include "common/rs_optional_trace.h"
25 #include "common/rs_obj_abs_geometry.h"
26 #include "common/rs_rect.h"
27 #include "common/rs_vector2.h"
28 #include "common/rs_vector4.h"
29 #ifdef RS_MEMORY_INFO_MANAGER
30 #include "feature/memory_info_manager/rs_memory_info_manager.h"
31 #endif
32 #include "ipc_callbacks/rs_rt_refresh_callback.h"
33 #include "monitor/self_drawing_node_monitor.h"
34 #include "params/rs_surface_render_params.h"
35 #include "pipeline/rs_render_node.h"
36
37 #include "pipeline/rs_effect_render_node.h"
38 #include "pipeline/rs_root_render_node.h"
39 #include "pipeline/rs_screen_render_node.h"
40 #include "pipeline/rs_surface_handler.h"
41 #include "platform/common/rs_log.h"
42 #include "platform/ohos/rs_jank_stats.h"
43 #include "property/rs_properties_painter.h"
44 #include "render/rs_drawing_filter.h"
45 #include "render/rs_skia_filter.h"
46 #include "transaction/rs_render_service_client.h"
47 #include "visitor/rs_node_visitor.h"
48 #ifndef ROSEN_CROSS_PLATFORM
49 #include "metadata_helper.h"
50 #include <v1_0/cm_color_space.h>
51 #endif
52 namespace OHOS {
53 namespace Rosen {
54
55 // set the offset value to prevent the situation where the float number
56 // with the suffix 0.000x is still rounded up.
57 constexpr float RECT_CEIL_DEVIATION = 0.001;
58
59 namespace {
CheckRootNodeReadyToDraw(const std::shared_ptr<RSBaseRenderNode> & child)60 bool CheckRootNodeReadyToDraw(const std::shared_ptr<RSBaseRenderNode>& child)
61 {
62 if (child->IsInstanceOf<RSRootRenderNode>()) {
63 auto rootNode = child->ReinterpretCastTo<RSRootRenderNode>();
64 // when rootnode is occluded, its applymodifiers will be skipped
65 // need to applymodifiers to update its properties here
66 rootNode->ApplyModifiers();
67 const auto& property = rootNode->GetRenderProperties();
68 if (property.GetFrameWidth() > 0 && property.GetFrameHeight() > 0 && rootNode->GetEnableRender()) {
69 return true;
70 }
71 }
72 return false;
73 }
74
CheckScbReadyToDraw(const std::shared_ptr<RSBaseRenderNode> & child)75 bool CheckScbReadyToDraw(const std::shared_ptr<RSBaseRenderNode>& child)
76 {
77 if (child->IsInstanceOf<RSCanvasRenderNode>()) {
78 auto canvasRenderNode = child->ReinterpretCastTo<RSCanvasRenderNode>();
79 const auto& property = canvasRenderNode->GetRenderProperties();
80 if (property.GetFrameWidth() > 0 && property.GetFrameHeight() > 0) {
81 return true;
82 }
83 }
84 return false;
85 }
86
IsFirstFrameReadyToDraw(RSSurfaceRenderNode & node)87 bool IsFirstFrameReadyToDraw(RSSurfaceRenderNode& node)
88 {
89 auto sortedChildren = node.GetSortedChildren();
90 if (node.IsScbScreen() || node.IsSCBNode()) {
91 for (const auto& child : *sortedChildren) {
92 if (CheckScbReadyToDraw(child)) {
93 return true;
94 }
95 }
96 }
97 for (auto& child : *sortedChildren) {
98 if (CheckRootNodeReadyToDraw(child)) {
99 return true;
100 }
101 // when appWindow has abilityComponent node
102 if (child->IsInstanceOf<RSSurfaceRenderNode>()) {
103 for (const auto& surfaceNodeChild : *child->GetSortedChildren()) {
104 if (CheckRootNodeReadyToDraw(surfaceNodeChild)) {
105 return true;
106 }
107 }
108 }
109 }
110 return false;
111 }
112
GamutChange(GraphicColorGamut gamut)113 GraphicColorGamut GamutChange(GraphicColorGamut gamut)
114 {
115 switch (gamut) {
116 case GRAPHIC_COLOR_GAMUT_ADOBE_RGB:
117 case GRAPHIC_COLOR_GAMUT_DCI_P3:
118 case GRAPHIC_COLOR_GAMUT_DISPLAY_P3:
119 return GRAPHIC_COLOR_GAMUT_DISPLAY_P3;
120 case GRAPHIC_COLOR_GAMUT_BT2020:
121 case GRAPHIC_COLOR_GAMUT_BT2100_PQ:
122 case GRAPHIC_COLOR_GAMUT_BT2100_HLG:
123 case GRAPHIC_COLOR_GAMUT_DISPLAY_BT2020:
124 return GRAPHIC_COLOR_GAMUT_DISPLAY_BT2020;
125 default:
126 return GRAPHIC_COLOR_GAMUT_SRGB;
127 }
128 }
129
130 #ifndef ROSEN_CROSS_PLATFORM
CMPrimariesToGamut(HDI::Display::Graphic::Common::V1_0::CM_ColorPrimaries primary)131 GraphicColorGamut CMPrimariesToGamut(HDI::Display::Graphic::Common::V1_0::CM_ColorPrimaries primary)
132 {
133 using namespace HDI::Display::Graphic::Common::V1_0;
134 switch (primary) {
135 case COLORPRIMARIES_ADOBERGB:
136 case COLORPRIMARIES_P3_DCI:
137 case COLORPRIMARIES_P3_D65:
138 return GRAPHIC_COLOR_GAMUT_DISPLAY_P3;
139 case COLORPRIMARIES_BT2020: // COLORPRIMARIES_BT2100 = COLORPRIMARIES_BT2020
140 return GRAPHIC_COLOR_GAMUT_DISPLAY_BT2020;
141 default:
142 return GRAPHIC_COLOR_GAMUT_SRGB;
143 }
144 }
145 #endif
146
JudgeGamut(int bt2020Num,int p3Num)147 GraphicColorGamut JudgeGamut(int bt2020Num, int p3Num)
148 {
149 if (bt2020Num > 0) {
150 return GRAPHIC_COLOR_GAMUT_DISPLAY_BT2020;
151 } else if (p3Num > 0) {
152 return GRAPHIC_COLOR_GAMUT_DISPLAY_P3;
153 } else {
154 return GRAPHIC_COLOR_GAMUT_SRGB;
155 }
156 }
157 }
158
UpdateOcclusionCullingStatus(bool enable,NodeId keyOcclusionNodeId)159 void OcclusionParams::UpdateOcclusionCullingStatus(bool enable, NodeId keyOcclusionNodeId)
160 {
161 if (enable) {
162 constexpr uint16_t maxSize = std::numeric_limits<uint16_t>::max();
163 if (keyOcclusionNodeIds_.size() >= maxSize) {
164 RS_LOGE("%s: Size limit reached. Failed to add key occlusion node id.", __func__);
165 } else {
166 keyOcclusionNodeIds_.emplace(keyOcclusionNodeId);
167 }
168 return;
169 }
170 auto it = keyOcclusionNodeIds_.find(keyOcclusionNodeId);
171 if (it != keyOcclusionNodeIds_.end()) {
172 keyOcclusionNodeIds_.erase(it);
173 if (keyOcclusionNodeIds_.empty()) {
174 occlusionHandler_ = nullptr;
175 }
176 }
177 }
178
CheckKeyOcclusionNodeValidity(const std::unordered_map<NodeId,std::shared_ptr<OcclusionNode>> & occlusionNodes)179 void OcclusionParams::CheckKeyOcclusionNodeValidity(
180 const std::unordered_map<NodeId, std::shared_ptr<OcclusionNode>>& occlusionNodes)
181 {
182 for (auto it = keyOcclusionNodeIds_.begin(); it != keyOcclusionNodeIds_.end();) {
183 if (occlusionNodes.count(*it) == 0) {
184 it = keyOcclusionNodeIds_.erase(it);
185 } else {
186 ++it;
187 }
188 }
189 if (keyOcclusionNodeIds_.empty()) {
190 occlusionHandler_ = nullptr;
191 }
192 }
193
RSSurfaceRenderNode(const RSSurfaceRenderNodeConfig & config,const std::weak_ptr<RSContext> & context)194 RSSurfaceRenderNode::RSSurfaceRenderNode(
195 const RSSurfaceRenderNodeConfig& config, const std::weak_ptr<RSContext>& context)
196 : RSRenderNode(config.id, context, config.isTextureExportNode),
197 nodeType_(config.nodeType), surfaceWindowType_(config.surfaceWindowType),
198 dirtyManager_(std::make_shared<RSDirtyRegionManager>()),
199 cacheSurfaceDirtyManager_(std::make_shared<RSDirtyRegionManager>()),
200 surfaceHandler_(std::make_shared<RSSurfaceHandler>(config.id)), name_(config.name),
201 bundleName_(config.bundleName)
202 {
203 #ifndef ROSEN_ARKUI_X
204 MemoryInfo info = {sizeof(*this), ExtractPid(config.id), config.id, MEMORY_TYPE::MEM_RENDER_NODE};
205 MemoryTrack::Instance().AddNodeRecord(config.id, info);
206 #endif
207 MemorySnapshot::Instance().AddCpuMemory(ExtractPid(config.id), sizeof(*this));
208 RsCommandVerifyHelper::GetInstance().AddSurfaceNodeCreateCnt(ExtractPid(config.id));
209 GetMutableRenderProperties().SetLocalMagnificationCap(nodeType_ == RSSurfaceNodeType::ABILITY_MAGNIFICATION_NODE);
210 }
211
RSSurfaceRenderNode(NodeId id,const std::weak_ptr<RSContext> & context,bool isTextureExportNode)212 RSSurfaceRenderNode::RSSurfaceRenderNode(NodeId id, const std::weak_ptr<RSContext>& context, bool isTextureExportNode)
213 : RSSurfaceRenderNode(RSSurfaceRenderNodeConfig { .id = id, .name = "SurfaceNode",
214 .isTextureExportNode = isTextureExportNode}, context)
215 {}
216
~RSSurfaceRenderNode()217 RSSurfaceRenderNode::~RSSurfaceRenderNode()
218 {
219 #ifdef USE_SURFACE_TEXTURE
220 SetSurfaceTexture(nullptr);
221 #endif
222 #ifndef ROSEN_ARKUI_X
223 MemoryTrack::Instance().RemoveNodeRecord(GetId());
224 #endif
225 MemorySnapshot::Instance().RemoveCpuMemory(ExtractPid(GetId()), sizeof(*this));
226 RsCommandVerifyHelper::GetInstance().SubSurfaceNodeCreateCnt(ExtractPid(GetId()));
227 }
228
229 #ifndef ROSEN_CROSS_PLATFORM
SetConsumer(const sptr<IConsumerSurface> & consumer)230 void RSSurfaceRenderNode::SetConsumer(const sptr<IConsumerSurface>& consumer)
231 {
232 GetMutableRSSurfaceHandler()->SetConsumer(consumer);
233 }
234 #endif
235
UpdateSrcRect(const Drawing::Canvas & canvas,const Drawing::RectI & dstRect,bool hasRotation)236 void RSSurfaceRenderNode::UpdateSrcRect(const Drawing::Canvas& canvas, const Drawing::RectI& dstRect,
237 bool hasRotation)
238 {
239 // if surfaceNode bound change, send message to aps
240 #ifdef ENABLE_FULL_SCREEN_RECONGNIZE
241 SendSurfaceNodeBoundChange();
242 #endif
243 auto localClipRect = RSPaintFilterCanvas::GetLocalClipBounds(canvas, &dstRect).value_or(Drawing::Rect());
244 const RSProperties& properties = GetRenderProperties();
245 int left = std::clamp<int>(localClipRect.GetLeft(), 0, properties.GetBoundsWidth());
246 int top = std::clamp<int>(localClipRect.GetTop(), 0, properties.GetBoundsHeight());
247 int width = std::clamp<int>(std::ceil(localClipRect.GetWidth() - RECT_CEIL_DEVIATION), 0,
248 std::ceil(properties.GetBoundsWidth() - left));
249 int height = std::clamp<int>(std::ceil(localClipRect.GetHeight() - RECT_CEIL_DEVIATION), 0,
250 std::ceil(properties.GetBoundsHeight() - top));
251 RectI srcRect = {left, top, width, height};
252 SetSrcRect(srcRect);
253 // We allow 1px error value to avoid disable dss by mistake [this flag only used for YUV buffer format]
254 if (IsYUVBufferFormat()) {
255 isHardwareForcedDisabledBySrcRect_ = !GetAncoForceDoDirect() &&
256 (hasRotation ? (width + 1 < static_cast<int>(properties.GetBoundsWidth())) :
257 (height + 1 < static_cast<int>(properties.GetBoundsHeight())));
258 #ifndef ROSEN_CROSS_PLATFORM
259 RS_OPTIONAL_TRACE_NAME_FMT("UpdateSrcRect hwcDisableBySrc:%d localClip:[%.2f, %.2f, %.2f, %.2f]" \
260 " bounds:[%.2f, %.2f] hasRotation:%d name:%s id:%llu",
261 isHardwareForcedDisabledBySrcRect_,
262 localClipRect.GetLeft(), localClipRect.GetTop(), localClipRect.GetWidth(), localClipRect.GetHeight(),
263 properties.GetBoundsWidth(), properties.GetBoundsHeight(), hasRotation,
264 GetName().c_str(), GetId());
265 #endif
266 }
267 }
268
IsYUVBufferFormat() const269 bool RSSurfaceRenderNode::IsYUVBufferFormat() const
270 {
271 #ifndef ROSEN_CROSS_PLATFORM
272 auto curBuffer = surfaceHandler_->GetBuffer();
273 if (!curBuffer) {
274 return false;
275 }
276 auto format = curBuffer->GetFormat();
277 if (format < GRAPHIC_PIXEL_FMT_YUV_422_I || format == GRAPHIC_PIXEL_FMT_RGBA_1010102 ||
278 format > GRAPHIC_PIXEL_FMT_YCRCB_P010) {
279 return false;
280 }
281 return true;
282 #else
283 return false;
284 #endif
285 }
286
UpdateInfoForClonedNode(NodeId nodeId)287 void RSSurfaceRenderNode::UpdateInfoForClonedNode(NodeId nodeId)
288 {
289 bool isClonedNode = GetId() == nodeId;
290 if (isClonedNode && IsMainWindowType() && clonedSourceNodeNeedOffscreen_) {
291 SetNeedCacheSurface(true);
292 SetHwcChildrenDisabledState();
293 RS_OPTIONAL_TRACE_FMT("hwc debug: name:%s id:%" PRIu64 " children disabled by isCloneNode",
294 GetName().c_str(), GetId());
295 }
296 SetIsCloned(isClonedNode);
297 }
298
ShouldPrepareSubnodes()299 bool RSSurfaceRenderNode::ShouldPrepareSubnodes()
300 {
301 // if a appwindow or abilitycomponent has a empty dstrect, its subnodes' prepare stage can be skipped
302 // most common scenario: HiBoard (SwipeLeft screen on home screen)
303 if (GetDstRect().IsEmpty() && (IsAppWindow() || IsAbilityComponent())) {
304 return false;
305 }
306 return true;
307 }
308
DirtyRegionDump() const309 std::string RSSurfaceRenderNode::DirtyRegionDump() const
310 {
311 std::string dump = GetName() +
312 " SurfaceNodeType [" + std::to_string(static_cast<unsigned int>(GetSurfaceNodeType())) + "]" +
313 " Transparent [" + std::to_string(IsTransparent()) +"]" +
314 " DstRect: " + GetDstRect().ToString() +
315 " VisibleRegion: " + GetVisibleRegion().GetRegionInfo();
316 if (GetDirtyManager()) {
317 dump += " DirtyRegion: " + GetDirtyManager()->GetDirtyRegion().ToString();
318 }
319 return dump;
320 }
321
ResetRenderParams()322 void RSSurfaceRenderNode::ResetRenderParams()
323 {
324 stagingRenderParams_.reset();
325 renderDrawable_->renderParams_.reset();
326 }
327
PrepareRenderBeforeChildren(RSPaintFilterCanvas & canvas)328 void RSSurfaceRenderNode::PrepareRenderBeforeChildren(RSPaintFilterCanvas& canvas)
329 {
330 // Save the current state of the canvas before modifying it.
331 renderNodeSaveCount_ = canvas.SaveAllStatus();
332
333 // Apply alpha to canvas
334 const RSProperties& properties = GetRenderProperties();
335 canvas.MultiplyAlpha(properties.GetAlpha());
336
337 // Apply matrix to canvas
338 auto& currentGeoPtr = (properties.GetBoundsGeometry());
339 if (currentGeoPtr != nullptr) {
340 currentGeoPtr->UpdateByMatrixFromSelf();
341 auto matrix = currentGeoPtr->GetMatrix();
342 matrix.Set(Drawing::Matrix::TRANS_X, std::ceil(matrix.Get(Drawing::Matrix::TRANS_X)));
343 matrix.Set(Drawing::Matrix::TRANS_Y, std::ceil(matrix.Get(Drawing::Matrix::TRANS_Y)));
344 canvas.ConcatMatrix(matrix);
345 }
346
347 // Clip by bounds
348 canvas.ClipRect(Drawing::Rect(0, 0, std::floor(properties.GetBoundsWidth()),
349 std::floor(properties.GetBoundsHeight())), Drawing::ClipOp::INTERSECT, false);
350
351 // Extract srcDest and dstRect from Drawing::Canvas, localCLipBounds as SrcRect, deviceClipBounds as DstRect
352 auto deviceClipRect = canvas.GetDeviceClipBounds();
353 UpdateSrcRect(canvas, deviceClipRect);
354 RectI dstRect = { deviceClipRect.GetLeft() + offsetX_, deviceClipRect.GetTop() + offsetY_,
355 deviceClipRect.GetWidth(), deviceClipRect.GetHeight() };
356 SetDstRect(dstRect);
357
358 // Save TotalMatrix and GlobalAlpha for compositor
359 SetTotalMatrix(canvas.GetTotalMatrix());
360 SetGlobalAlpha(canvas.GetAlpha());
361 }
362
PrepareRenderAfterChildren(RSPaintFilterCanvas & canvas)363 void RSSurfaceRenderNode::PrepareRenderAfterChildren(RSPaintFilterCanvas& canvas)
364 {
365 canvas.RestoreStatus(renderNodeSaveCount_);
366 }
367
CollectSurface(const std::shared_ptr<RSBaseRenderNode> & node,std::vector<RSBaseRenderNode::SharedPtr> & vec,bool isUniRender,bool onlyFirstLevel)368 void RSSurfaceRenderNode::CollectSurface(const std::shared_ptr<RSBaseRenderNode>& node,
369 std::vector<RSBaseRenderNode::SharedPtr>& vec, bool isUniRender, bool onlyFirstLevel)
370 {
371 if (IsScbScreen()) {
372 for (auto& child : *node->GetSortedChildren()) {
373 child->CollectSurface(child, vec, isUniRender, onlyFirstLevel);
374 }
375 return;
376 }
377 if (IsStartingWindow()) {
378 if (isUniRender) {
379 vec.emplace_back(shared_from_this());
380 }
381 return;
382 }
383 if (IsLeashWindow()) {
384 if (isUniRender) {
385 vec.emplace_back(shared_from_this());
386 }
387 if (onlyFirstLevel) {
388 return;
389 }
390 for (auto& child : *node->GetSortedChildren()) {
391 child->CollectSurface(child, vec, isUniRender, onlyFirstLevel);
392 }
393 return;
394 }
395
396 #ifndef ROSEN_CROSS_PLATFORM
397 auto consumer = surfaceHandler_->GetConsumer();
398 if (consumer != nullptr && consumer->GetTunnelHandle() != nullptr) {
399 return;
400 }
401 #endif
402 auto num = find(vec.begin(), vec.end(), shared_from_this());
403 if (num != vec.end()) {
404 return;
405 }
406 if (isUniRender && ShouldPaint()) {
407 vec.emplace_back(shared_from_this());
408 } else {
409 #ifndef ROSEN_CROSS_PLATFORM
410 if (surfaceHandler_->GetBuffer() != nullptr && ShouldPaint()) {
411 vec.emplace_back(shared_from_this());
412 }
413 #endif
414 }
415 }
416
CollectSelfDrawingChild(const std::shared_ptr<RSBaseRenderNode> & node,std::vector<NodeId> & vec)417 void RSSurfaceRenderNode::CollectSelfDrawingChild(
418 const std::shared_ptr<RSBaseRenderNode>& node, std::vector<NodeId>& vec)
419 {
420 if (IsSelfDrawingType()) {
421 vec.push_back(node->GetId());
422 }
423 for (auto& child : *node->GetSortedChildren()) {
424 child->CollectSelfDrawingChild(child, vec);
425 }
426 }
427
ClearChildrenCache()428 void RSSurfaceRenderNode::ClearChildrenCache()
429 {
430 for (auto& child : *GetChildren()) {
431 auto surfaceNode = child->ReinterpretCastTo<RSSurfaceRenderNode>();
432 if (surfaceNode == nullptr) {
433 continue;
434 }
435 #ifndef ROSEN_CROSS_PLATFORM
436 auto consumer = surfaceNode->GetRSSurfaceHandler()->GetConsumer();
437 if (consumer != nullptr) {
438 consumer->GoBackground();
439 }
440 #endif
441 }
442 // Temporary solution, GetChildren will generate fullChildrenList_, which will cause memory leak
443 OnTreeStateChanged();
444 }
445
FindScreenId()446 void RSSurfaceRenderNode::FindScreenId()
447 {
448 // The results found across screen windows are inaccurate
449 auto nodeTemp = GetParent().lock();
450 screenId_ = -1;
451 while (nodeTemp != nullptr) {
452 if (nodeTemp->GetId() == 0) {
453 break;
454 }
455 if (nodeTemp->GetType() == RSRenderNodeType::SCREEN_NODE) {
456 auto displayNode = RSBaseRenderNode::ReinterpretCast<RSScreenRenderNode>(nodeTemp);
457 screenId_ = displayNode->GetScreenId();
458 break;
459 }
460 nodeTemp = nodeTemp->GetParent().lock();
461 }
462 }
463
OnTreeStateChanged()464 void RSSurfaceRenderNode::OnTreeStateChanged()
465 {
466 NotifyTreeStateChange();
467 RSRenderNode::OnTreeStateChanged();
468 #if defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK)
469 if (!IsOnTheTree()) {
470 if (auto context = GetContext().lock()) {
471 RS_TRACE_NAME_FMT("need purgeUnlockedResources this SurfaceNode isn't on the tree Id:%" PRIu64 " Name:%s",
472 GetId(), GetName().c_str());
473 RS_LOGD("need purgeUnlockedResources this SurfaceNode isn't on the tree Id:%" PRIu64 " Name:%s",
474 GetId(), GetName().c_str());
475 if (IsLeashWindow()) {
476 context->MarkNeedPurge(ClearMemoryMoment::COMMON_SURFACE_NODE_HIDE, RSContext::PurgeType::GENTLY);
477 }
478 if (IS_SCB_WINDOW_TYPE(surfaceWindowType_)) {
479 context->MarkNeedPurge(ClearMemoryMoment::SCENEBOARD_SURFACE_NODE_HIDE, RSContext::PurgeType::STRONGLY);
480 }
481 }
482 } else if (GetSurfaceNodeType() == RSSurfaceNodeType::CURSOR_NODE) {
483 FindScreenId();
484 }
485 #endif
486 if (IsAbilityComponent()) {
487 if (auto instanceRootNode = GetInstanceRootNode()) {
488 if (auto surfaceNode = instanceRootNode->ReinterpretCastTo<RSSurfaceRenderNode>()) {
489 surfaceNode->UpdateAbilityNodeIds(GetId(), IsOnTheTree());
490 }
491 }
492 } else if (IsHardwareEnabledType() && RSUniRenderJudgement::IsUniRender()) {
493 if (auto instanceRootNode = GetInstanceRootNode()) {
494 if (auto surfaceNode = instanceRootNode->ReinterpretCastTo<RSSurfaceRenderNode>()) {
495 surfaceNode->UpdateChildHardwareEnabledNode(GetId(), IsOnTheTree());
496 }
497 }
498 }
499 OnSubSurfaceChanged();
500
501 // sync skip & security info
502 SyncBlackListInfoToFirstLevelNode();
503 UpdateSpecialLayerInfoByOnTreeStateChange();
504 SyncPrivacyContentInfoToFirstLevelNode();
505 SyncColorGamutInfoToFirstLevelNode();
506 }
507
SetIsSubSurfaceNode(bool isSubSurfaceNode)508 void RSSurfaceRenderNode::SetIsSubSurfaceNode(bool isSubSurfaceNode)
509 {
510 #ifdef RS_ENABLE_GPU
511 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
512 if (surfaceParams) {
513 surfaceParams->SetIsSubSurfaceNode(isSubSurfaceNode);
514 isSubSurfaceNode_ = isSubSurfaceNode;
515 AddToPendingSyncList();
516 }
517 #endif
518 }
519
IsSubSurfaceNode() const520 bool RSSurfaceRenderNode::IsSubSurfaceNode() const
521 {
522 return isSubSurfaceNode_;
523 }
524
GetChildSubSurfaceNodes() const525 const std::map<NodeId, RSSurfaceRenderNode::WeakPtr>& RSSurfaceRenderNode::GetChildSubSurfaceNodes() const
526 {
527 return childSubSurfaceNodes_;
528 }
529
OnSubSurfaceChanged()530 void RSSurfaceRenderNode::OnSubSurfaceChanged()
531 {
532 if (!IsMainWindowType() || !RSUniRenderJudgement::IsUniRender()) {
533 return;
534 }
535 auto parentNode = GetParent().lock();
536 if (!parentNode) {
537 return;
538 }
539 std::shared_ptr<RSSurfaceRenderNode> parentSurfaceNode = parentNode->ReinterpretCastTo<RSSurfaceRenderNode>();
540 if (!parentSurfaceNode || !parentSurfaceNode->IsMainWindowType()) {
541 if (auto instanceRootNode = parentNode->GetInstanceRootNode()) {
542 parentSurfaceNode = instanceRootNode->ReinterpretCastTo<RSSurfaceRenderNode>();
543 }
544 }
545 if (parentSurfaceNode && parentSurfaceNode->IsLeashOrMainWindow()) {
546 parentSurfaceNode->UpdateChildSubSurfaceNodes(ReinterpretCastTo<RSSurfaceRenderNode>(), IsOnTheTree());
547 }
548 }
549
UpdateChildSubSurfaceNodes(RSSurfaceRenderNode::SharedPtr node,bool isOnTheTree)550 void RSSurfaceRenderNode::UpdateChildSubSurfaceNodes(RSSurfaceRenderNode::SharedPtr node, bool isOnTheTree)
551 {
552 if (isOnTheTree) {
553 childSubSurfaceNodes_[node->GetId()] = node;
554 } else {
555 childSubSurfaceNodes_.erase(node->GetId());
556 }
557 if (!IsLeashWindow()) {
558 node->SetIsSubSurfaceNode(isOnTheTree);
559 }
560 }
561
GetAllSubSurfaceNodeIds() const562 std::unordered_set<NodeId> RSSurfaceRenderNode::GetAllSubSurfaceNodeIds() const
563 {
564 std::unordered_set<NodeId> allSubSurfaceNodeIds;
565 std::vector<std::pair<NodeId, RSSurfaceRenderNode::WeakPtr>> allSubSurfaceNodes;
566 GetAllSubSurfaceNodes(allSubSurfaceNodes);
567 for (auto& [id, _] : allSubSurfaceNodes) {
568 allSubSurfaceNodeIds.insert(id);
569 }
570 return allSubSurfaceNodeIds;
571 }
572
GetAllSubSurfaceNodes(std::vector<std::pair<NodeId,RSSurfaceRenderNode::WeakPtr>> & allSubSurfaceNodes) const573 void RSSurfaceRenderNode::GetAllSubSurfaceNodes(
574 std::vector<std::pair<NodeId, RSSurfaceRenderNode::WeakPtr>>& allSubSurfaceNodes) const
575 {
576 for (auto& [id, node] : childSubSurfaceNodes_) {
577 auto subSubSurfaceNodePtr = node.lock();
578 if (!subSubSurfaceNodePtr) {
579 continue;
580 }
581 if (subSubSurfaceNodePtr->HasSubSurfaceNodes()) {
582 subSubSurfaceNodePtr->GetAllSubSurfaceNodes(allSubSurfaceNodes);
583 }
584 allSubSurfaceNodes.push_back({id, node});
585 }
586 }
587
SubSurfaceNodesDump() const588 std::string RSSurfaceRenderNode::SubSurfaceNodesDump() const
589 {
590 std::string out;
591 out += ", subSurface";
592 for (auto [id, _] : childSubSurfaceNodes_) {
593 out += "[" + std::to_string(id) + "]";
594 }
595 return out;
596 }
597
SetIsNodeToBeCaptured(bool isNodeToBeCaptured)598 void RSSurfaceRenderNode::SetIsNodeToBeCaptured(bool isNodeToBeCaptured)
599 {
600 #ifdef RS_ENABLE_GPU
601 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
602 if (surfaceParams) {
603 surfaceParams->SetIsNodeToBeCaptured(isNodeToBeCaptured);
604 isNodeToBeCaptured_ = isNodeToBeCaptured;
605 AddToPendingSyncList();
606 }
607 #endif
608 }
609
OnResetParent()610 void RSSurfaceRenderNode::OnResetParent()
611 {
612 if (nodeType_ == RSSurfaceNodeType::LEASH_WINDOW_NODE) {
613 ClearChildrenCache();
614 } else {
615 #ifndef ROSEN_CROSS_PLATFORM
616 auto consumer = GetRSSurfaceHandler()->GetConsumer();
617 if (consumer != nullptr && !IsSelfDrawingType() && !IsAbilityComponent()) {
618 consumer->GoBackground();
619 }
620 #endif
621 }
622 }
623
SetIsNotifyUIBufferAvailable(bool available)624 void RSSurfaceRenderNode::SetIsNotifyUIBufferAvailable(bool available)
625 {
626 #ifdef USE_SURFACE_TEXTURE
627 auto texture = GetSurfaceTexture();
628 if (texture) {
629 texture->MarkUiFrameAvailable(available);
630 }
631 #endif
632 isNotifyUIBufferAvailable_.store(available);
633 }
634
QuickPrepare(const std::shared_ptr<RSNodeVisitor> & visitor)635 void RSSurfaceRenderNode::QuickPrepare(const std::shared_ptr<RSNodeVisitor>& visitor)
636 {
637 if (!visitor) {
638 return;
639 }
640 ApplyModifiers();
641 visitor->QuickPrepareSurfaceRenderNode(*this);
642 }
643
IsUIBufferAvailable()644 bool RSSurfaceRenderNode::IsUIBufferAvailable()
645 {
646 return ((IsAppWindow() || IsScbScreen() || IsUIExtension())
647 && !IsNotifyUIBufferAvailable() && IsFirstFrameReadyToDraw(*this));
648 }
649
IsSubTreeNeedPrepare(bool filterInGlobal,bool isOccluded)650 bool RSSurfaceRenderNode::IsSubTreeNeedPrepare(bool filterInGlobal, bool isOccluded)
651 {
652 // force preparation case for occlusion
653 if (IsLeashWindow()) {
654 SetSubTreeDirty(false);
655 UpdateChildrenOutOfRectFlag(false); // collect again
656 return true;
657 }
658
659 // force preparation case for update gravity when appWindow geoDirty
660 auto parentPtr = this->GetParent().lock();
661 auto surfaceParentPtr = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(parentPtr);
662 if (surfaceParentPtr != nullptr &&
663 surfaceParentPtr->GetSurfaceNodeType() == RSSurfaceNodeType::LEASH_WINDOW_NODE) {
664 if (this->GetRenderProperties().IsCurGeoDirty()) {
665 SetSubTreeDirty(false);
666 UpdateChildrenOutOfRectFlag(false);
667 return true;
668 }
669 }
670
671 return RSRenderNode::IsSubTreeNeedPrepare(filterInGlobal, isOccluded);
672 }
673
Prepare(const std::shared_ptr<RSNodeVisitor> & visitor)674 void RSSurfaceRenderNode::Prepare(const std::shared_ptr<RSNodeVisitor>& visitor)
675 {
676 if (!visitor) {
677 return;
678 }
679 ApplyModifiers();
680 visitor->PrepareSurfaceRenderNode(*this);
681 }
682
Process(const std::shared_ptr<RSNodeVisitor> & visitor)683 void RSSurfaceRenderNode::Process(const std::shared_ptr<RSNodeVisitor>& visitor)
684 {
685 if (!visitor) {
686 return;
687 }
688 RSRenderNode::RenderTraceDebug();
689 visitor->ProcessSurfaceRenderNode(*this);
690 }
691
ProcessRenderBeforeChildren(RSPaintFilterCanvas & canvas)692 void RSSurfaceRenderNode::ProcessRenderBeforeChildren(RSPaintFilterCanvas& canvas)
693 {
694 needDrawAnimateProperty_ = true;
695 ProcessAnimatePropertyBeforeChildren(canvas, true);
696 needDrawAnimateProperty_ = false;
697 }
698
ProcessAnimatePropertyBeforeChildren(RSPaintFilterCanvas & canvas,bool includeProperty)699 void RSSurfaceRenderNode::ProcessAnimatePropertyBeforeChildren(RSPaintFilterCanvas& canvas, bool includeProperty)
700 {
701 if (GetCacheType() != CacheType::ANIMATE_PROPERTY && !needDrawAnimateProperty_) {
702 return;
703 }
704
705 const auto& property = GetRenderProperties();
706 const RectF absBounds = {0, 0, property.GetBoundsWidth(), property.GetBoundsHeight()};
707 RRect absClipRRect = RRect(absBounds, property.GetCornerRadius());
708 RSPropertiesPainter::DrawShadow(property, canvas, &absClipRRect);
709 RSPropertiesPainter::DrawOutline(property, canvas);
710
711 if (!property.GetCornerRadius().IsZero()) {
712 canvas.ClipRoundRect(
713 RSPropertiesPainter::RRect2DrawingRRect(absClipRRect), Drawing::ClipOp::INTERSECT, true);
714 } else {
715 canvas.ClipRect(Drawing::Rect(0, 0, property.GetBoundsWidth(), property.GetBoundsHeight()),
716 Drawing::ClipOp::INTERSECT, false);
717 }
718
719 #ifndef ROSEN_CROSS_PLATFORM
720 RSPropertiesPainter::DrawBackground(
721 property, canvas, true, IsSelfDrawingNode() && (surfaceHandler_->GetBuffer() != nullptr));
722 #else
723 RSPropertiesPainter::DrawBackground(property, canvas);
724 #endif
725 RSPropertiesPainter::DrawMask(property, canvas);
726 RSPropertiesPainter::DrawFilter(property, canvas, FilterType::BACKGROUND_FILTER);
727 SetTotalMatrix(canvas.GetTotalMatrix());
728 }
729
ProcessRenderAfterChildren(RSPaintFilterCanvas & canvas)730 void RSSurfaceRenderNode::ProcessRenderAfterChildren(RSPaintFilterCanvas& canvas)
731 {
732 needDrawAnimateProperty_ = true;
733 ProcessAnimatePropertyAfterChildren(canvas);
734 needDrawAnimateProperty_ = false;
735 }
736
ProcessAnimatePropertyAfterChildren(RSPaintFilterCanvas & canvas)737 void RSSurfaceRenderNode::ProcessAnimatePropertyAfterChildren(RSPaintFilterCanvas& canvas)
738 {
739 if (GetCacheType() != CacheType::ANIMATE_PROPERTY && !needDrawAnimateProperty_) {
740 return;
741 }
742 const auto& property = GetRenderProperties();
743 RSPropertiesPainter::DrawFilter(property, canvas, FilterType::FOREGROUND_FILTER);
744 canvas.Save();
745 if (GetSurfaceNodeType() == RSSurfaceNodeType::SELF_DRAWING_NODE) {
746 auto& geoPtr = (property.GetBoundsGeometry());
747 canvas.ConcatMatrix(geoPtr->GetMatrix());
748 }
749 RSPropertiesPainter::DrawOutline(property, canvas);
750 RSPropertiesPainter::DrawBorder(property, canvas);
751 canvas.Restore();
752 }
753
SetContextBounds(const Vector4f bounds)754 void RSSurfaceRenderNode::SetContextBounds(const Vector4f bounds)
755 {
756 std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeSetBounds>(GetId(), bounds);
757 SendCommandFromRT(command, GetId());
758 }
759
GetCacheSurfaceDirtyManager() const760 std::shared_ptr<RSDirtyRegionManager> RSSurfaceRenderNode::GetCacheSurfaceDirtyManager() const
761 {
762 return cacheSurfaceDirtyManager_;
763 }
764
SetSurfaceNodeType(RSSurfaceNodeType nodeType)765 void RSSurfaceRenderNode::SetSurfaceNodeType(RSSurfaceNodeType nodeType)
766 {
767 if (nodeType_ == RSSurfaceNodeType::ABILITY_COMPONENT_NODE ||
768 nodeType_ == RSSurfaceNodeType::UI_EXTENSION_COMMON_NODE ||
769 nodeType_ == RSSurfaceNodeType::UI_EXTENSION_SECURE_NODE ||
770 nodeType_ == RSSurfaceNodeType::CURSOR_NODE) {
771 return;
772 }
773 if (nodeType == RSSurfaceNodeType::UI_EXTENSION_COMMON_NODE ||
774 nodeType == RSSurfaceNodeType::UI_EXTENSION_SECURE_NODE) {
775 RS_LOGE("RSSurfaceRenderNode::SetSurfaceNodeType prohibition of converting surfaceNodeType to uiExtension");
776 return;
777 }
778 nodeType_ = nodeType;
779 }
780
MarkUIHidden(bool isHidden)781 void RSSurfaceRenderNode::MarkUIHidden(bool isHidden)
782 {
783 isUIHidden_ = isHidden;
784 }
785
IsUIHidden() const786 bool RSSurfaceRenderNode::IsUIHidden() const
787 {
788 return isUIHidden_;
789 }
790
IsLeashWindowSurfaceNodeVisible()791 bool RSSurfaceRenderNode::IsLeashWindowSurfaceNodeVisible()
792 {
793 if (!IsLeashWindow()) {
794 return false;
795 }
796 auto nestedSurfaces = GetLeashWindowNestedSurfaces();
797 return std::any_of(nestedSurfaces.begin(), nestedSurfaces.end(),
798 [](const auto& node) -> bool {
799 return node && !node->IsUIHidden();
800 });
801 }
802
SetContextMatrix(const std::optional<Drawing::Matrix> & matrix,bool sendMsg)803 void RSSurfaceRenderNode::SetContextMatrix(const std::optional<Drawing::Matrix>& matrix, bool sendMsg)
804 {
805 if (contextMatrix_ == matrix) {
806 return;
807 }
808 contextMatrix_ = matrix;
809 SetContentDirty();
810 AddDirtyType(ModifierNG::RSModifierType::TRANSFORM);
811 if (!sendMsg) {
812 return;
813 }
814 // send a Command
815 std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeSetContextMatrix>(GetId(), matrix);
816 SendCommandFromRT(command, GetId());
817 }
818
SetContextAlpha(float alpha,bool sendMsg)819 void RSSurfaceRenderNode::SetContextAlpha(float alpha, bool sendMsg)
820 {
821 if (contextAlpha_ == alpha) {
822 return;
823 }
824 contextAlpha_ = alpha;
825 SetContentDirty();
826 AddDirtyType(ModifierNG::RSModifierType::ALPHA);
827 if (!sendMsg) {
828 return;
829 }
830 // send a Command
831 std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeSetContextAlpha>(GetId(), alpha);
832 SendCommandFromRT(command, GetId());
833 }
834
SetContextClipRegion(const std::optional<Drawing::Rect> & clipRegion,bool sendMsg)835 void RSSurfaceRenderNode::SetContextClipRegion(const std::optional<Drawing::Rect>& clipRegion, bool sendMsg)
836 {
837 if (contextClipRect_ == clipRegion) {
838 return;
839 }
840 contextClipRect_ = clipRegion;
841 SetContentDirty();
842 AddDirtyType(ModifierNG::RSModifierType::BOUNDS);
843 if (!sendMsg) {
844 return;
845 }
846 // send a Command
847 std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeSetContextClipRegion>(GetId(), clipRegion);
848 SendCommandFromRT(command, GetId());
849 }
SetBootAnimation(bool isBootAnimation)850 void RSSurfaceRenderNode::SetBootAnimation(bool isBootAnimation)
851 {
852 ROSEN_LOGD("SetBootAnimation:: id:%{public}" PRIu64 ", isBootAnimation:%{public}d",
853 GetId(), isBootAnimation);
854 isBootAnimation_ = isBootAnimation;
855 }
856
GetBootAnimation() const857 bool RSSurfaceRenderNode::GetBootAnimation() const
858 {
859 return isBootAnimation_;
860 }
861
SetGlobalPositionEnabled(bool isEnabled)862 void RSSurfaceRenderNode::SetGlobalPositionEnabled(bool isEnabled)
863 {
864 #ifdef RS_ENABLE_GPU
865 if (isGlobalPositionEnabled_ == isEnabled) {
866 return;
867 }
868 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
869 if (surfaceParams == nullptr) {
870 ROSEN_LOGE("RSSurfaceRenderNode::SetGlobalPositionEnabled failed! surfaceParams is null. id:%{public}"
871 "" PRIu64 ", isEnabled:%{public}d", GetId(), isEnabled);
872 return;
873 }
874 surfaceParams->SetGlobalPositionEnabled(isEnabled);
875 AddToPendingSyncList();
876
877 isGlobalPositionEnabled_ = isEnabled;
878 ROSEN_LOGI("RSSurfaceRenderNode::SetGlobalPositionEnabled id:%{public}" PRIu64 ", isEnabled:%{public}d",
879 GetId(), isEnabled);
880 #endif
881 }
882
SetHwcGlobalPositionEnabled(bool isEnabled)883 void RSSurfaceRenderNode::SetHwcGlobalPositionEnabled(bool isEnabled)
884 {
885 if (isHwcGlobalPositionEnabled_ == isEnabled) {
886 return;
887 }
888 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
889 if (surfaceParams == nullptr) {
890 return;
891 }
892 surfaceParams->SetHwcGlobalPositionEnabled(isEnabled);
893 AddToPendingSyncList();
894
895 isHwcGlobalPositionEnabled_ = isEnabled;
896 }
897
SetHwcCrossNode(bool isHwcCrossNode)898 void RSSurfaceRenderNode::SetHwcCrossNode(bool isHwcCrossNode)
899 {
900 if (isHwcCrossNode_ == isHwcCrossNode) {
901 return;
902 }
903 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
904 if (surfaceParams == nullptr) {
905 return;
906 }
907 surfaceParams->SetHwcCrossNode(isHwcCrossNode);
908 AddToPendingSyncList();
909
910 isHwcCrossNode_ = isHwcCrossNode;
911 }
912
IsHwcCrossNode() const913 bool RSSurfaceRenderNode::IsHwcCrossNode() const
914 {
915 return isHwcCrossNode_;
916 }
917
SetForceHardwareAndFixRotation(bool flag)918 void RSSurfaceRenderNode::SetForceHardwareAndFixRotation(bool flag)
919 {
920 #ifdef RS_ENABLE_GPU
921 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
922 if (surfaceParams == nullptr) {
923 return;
924 }
925 surfaceParams->SetFixRotationByUser(flag);
926 AddToPendingSyncList();
927
928 isFixRotationByUser_ = flag;
929 #endif
930 }
931
IsInFixedRotation() const932 bool RSSurfaceRenderNode::IsInFixedRotation() const
933 {
934 return isInFixedRotation_;
935 }
936
SetInFixedRotation(bool isRotating)937 void RSSurfaceRenderNode::SetInFixedRotation(bool isRotating)
938 {
939 if (isFixRotationByUser_ && !isInFixedRotation_ && isRotating) {
940 #ifndef ROSEN_CROSS_PLATFORM
941 #ifdef RS_ENABLE_GPU
942 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
943 if (surfaceParams) {
944 auto layer = surfaceParams->GetLayerInfo();
945 originalSrcRect_ = { layer.srcRect.x, layer.srcRect.y, layer.srcRect.w, layer.srcRect.h };
946 originalDstRect_ = { layer.dstRect.x, layer.dstRect.y, layer.dstRect.w, layer.dstRect.h };
947 }
948 #endif
949 #endif
950 }
951 isInFixedRotation_ = isFixRotationByUser_ && isRotating;
952 }
953
SetHidePrivacyContent(bool needHidePrivacyContent)954 void RSSurfaceRenderNode::SetHidePrivacyContent(bool needHidePrivacyContent)
955 {
956 if (needHidePrivacyContent_ == needHidePrivacyContent) {
957 return;
958 }
959 needHidePrivacyContent_ = needHidePrivacyContent;
960 SetDirty();
961 if (needHidePrivacyContent) {
962 privacyContentLayerIds_.insert(GetId());
963 } else {
964 privacyContentLayerIds_.erase(GetId());
965 }
966 ROSEN_LOGI("RSSurfaceRenderNode::SetHidePrivacyContent, Node id: %{public}" PRIu64 ", privacyContent:%{public}d",
967 GetId(), needHidePrivacyContent);
968 SyncPrivacyContentInfoToFirstLevelNode();
969 }
970
SetSecurityLayer(bool isSecurityLayer)971 void RSSurfaceRenderNode::SetSecurityLayer(bool isSecurityLayer)
972 {
973 if (specialLayerManager_.Find(SpecialLayerType::SECURITY) == isSecurityLayer) {
974 return;
975 }
976 specialLayerChanged_ = specialLayerManager_.Set(SpecialLayerType::SECURITY, isSecurityLayer);
977 SetDirty();
978 if (isSecurityLayer) {
979 specialLayerManager_.AddIds(SpecialLayerType::SECURITY, GetId());
980 } else {
981 specialLayerManager_.RemoveIds(SpecialLayerType::SECURITY, GetId());
982 }
983 ROSEN_LOGI("RSSurfaceRenderNode::SetSecurityLayer, Node id: %{public}" PRIu64 ", SecurityLayer:%{public}d",
984 GetId(), isSecurityLayer);
985 UpdateSpecialLayerInfoByTypeChange(SpecialLayerType::SECURITY, isSecurityLayer);
986 }
987
SetLeashPersistentId(NodeId leashPersistentId)988 void RSSurfaceRenderNode::SetLeashPersistentId(NodeId leashPersistentId)
989 {
990 if (leashPersistentId_ == leashPersistentId) {
991 return;
992 }
993
994 leashPersistentId_ = leashPersistentId;
995 SetDirty();
996
997 ROSEN_LOGD("RSSurfaceRenderNode::SetLeashPersistentId, Node id: %{public}" PRIu64 ", leashPersistentId:%{public}"
998 "" PRIu64, GetId(), leashPersistentId);
999 }
1000
SetSkipLayer(bool isSkipLayer)1001 void RSSurfaceRenderNode::SetSkipLayer(bool isSkipLayer)
1002 {
1003 if (specialLayerManager_.Find(SpecialLayerType::SKIP) == isSkipLayer) {
1004 return;
1005 }
1006 specialLayerChanged_ = specialLayerManager_.Set(SpecialLayerType::SKIP, isSkipLayer);
1007 SetDirty();
1008 if (isSkipLayer) {
1009 specialLayerManager_.AddIds(SpecialLayerType::SKIP, GetId());
1010 } else {
1011 specialLayerManager_.RemoveIds(SpecialLayerType::SKIP, GetId());
1012 }
1013 UpdateSpecialLayerInfoByTypeChange(SpecialLayerType::SKIP, isSkipLayer);
1014 }
1015
SetSnapshotSkipLayer(bool isSnapshotSkipLayer)1016 void RSSurfaceRenderNode::SetSnapshotSkipLayer(bool isSnapshotSkipLayer)
1017 {
1018 if (specialLayerManager_.Find(SpecialLayerType::SNAPSHOT_SKIP) == isSnapshotSkipLayer) {
1019 return;
1020 }
1021 specialLayerChanged_ = specialLayerManager_.Set(SpecialLayerType::SNAPSHOT_SKIP, isSnapshotSkipLayer);
1022 SetDirty();
1023 if (isSnapshotSkipLayer) {
1024 specialLayerManager_.AddIds(SpecialLayerType::SNAPSHOT_SKIP, GetId());
1025 } else {
1026 specialLayerManager_.RemoveIds(SpecialLayerType::SNAPSHOT_SKIP, GetId());
1027 }
1028 UpdateSpecialLayerInfoByTypeChange(SpecialLayerType::SNAPSHOT_SKIP, isSnapshotSkipLayer);
1029 }
1030
SetProtectedLayer(bool isProtectedLayer)1031 void RSSurfaceRenderNode::SetProtectedLayer(bool isProtectedLayer)
1032 {
1033 if (specialLayerManager_.Find(SpecialLayerType::PROTECTED) == isProtectedLayer) {
1034 return;
1035 }
1036 specialLayerChanged_ = specialLayerManager_.Set(SpecialLayerType::PROTECTED, isProtectedLayer);
1037 SetDirty();
1038 if (isProtectedLayer) {
1039 specialLayerManager_.AddIds(SpecialLayerType::PROTECTED, GetId());
1040 } else {
1041 specialLayerManager_.RemoveIds(SpecialLayerType::PROTECTED, GetId());
1042 }
1043 UpdateSpecialLayerInfoByTypeChange(SpecialLayerType::PROTECTED, isProtectedLayer);
1044 }
1045
SetIsOutOfScreen(bool isOutOfScreen)1046 void RSSurfaceRenderNode::SetIsOutOfScreen(bool isOutOfScreen)
1047 {
1048 auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
1049 if (stagingSurfaceParams) {
1050 stagingSurfaceParams->SetIsOutOfScreen(isOutOfScreen);
1051 AddToPendingSyncList();
1052 }
1053 }
1054
GetHasPrivacyContentLayer() const1055 bool RSSurfaceRenderNode::GetHasPrivacyContentLayer() const
1056 {
1057 return privacyContentLayerIds_.size() != 0;
1058 }
1059
UpdateSpecialLayerInfoByTypeChange(uint32_t type,bool isSpecialLayer)1060 void RSSurfaceRenderNode::UpdateSpecialLayerInfoByTypeChange(uint32_t type, bool isSpecialLayer)
1061 {
1062 if (!IsOnTheTree() || GetFirstLevelNodeId() == GetId()) {
1063 return;
1064 }
1065 auto firstLevelNode = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(GetFirstLevelNode());
1066 // firstLevelNode is the nearest app window / leash node
1067 if (firstLevelNode) {
1068 if (type == SpecialLayerType::PROTECTED) {
1069 firstLevelNode->SetDirty();
1070 }
1071 if (isSpecialLayer) {
1072 firstLevelNode->specialLayerManager_.AddIds(type, GetId());
1073 } else {
1074 firstLevelNode->specialLayerManager_.RemoveIds(type, GetId());
1075 }
1076 firstLevelNode->specialLayerChanged_ = specialLayerChanged_;
1077 }
1078 }
1079
UpdateSpecialLayerInfoByOnTreeStateChange()1080 void RSSurfaceRenderNode::UpdateSpecialLayerInfoByOnTreeStateChange()
1081 {
1082 if (specialLayerManager_.Find(IS_GENERAL_SPECIAL) == false || GetFirstLevelNodeId() == GetId()) {
1083 return;
1084 }
1085 auto firstLevelNode = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(GetFirstLevelNode());
1086 // firstLevelNode is the nearest app window / leash node
1087 if (firstLevelNode) {
1088 if (specialLayerManager_.Find(SpecialLayerType::PROTECTED)) {
1089 firstLevelNode->SetDirty();
1090 }
1091 if (IsOnTheTree()) {
1092 firstLevelNode->specialLayerManager_.AddIds(specialLayerManager_.Get(), GetId());
1093 } else {
1094 firstLevelNode->specialLayerManager_.RemoveIds(specialLayerManager_.Get(), GetId());
1095 }
1096 firstLevelNode->specialLayerChanged_ = specialLayerChanged_;
1097 }
1098 }
1099
UpdateBlackListStatus(ScreenId virtualScreenId,bool isBlackList)1100 void RSSurfaceRenderNode::UpdateBlackListStatus(ScreenId virtualScreenId, bool isBlackList)
1101 {
1102 if (isBlackList) {
1103 if (blackListIds_.find(virtualScreenId) != blackListIds_.end() &&
1104 blackListIds_[virtualScreenId].find(GetId()) != blackListIds_[virtualScreenId].end()) {
1105 return;
1106 }
1107 blackListIds_[virtualScreenId].insert(GetId());
1108 SetDirty();
1109 return;
1110 }
1111 for (const auto& [screenId, nodeIdSet] : blackListIds_) {
1112 if (nodeIdSet.size() > 0 && nodeIdSet.find(GetId()) != nodeIdSet.end()) {
1113 blackListIds_[screenId].erase(GetId());
1114 SetDirty();
1115 }
1116 }
1117 }
1118
SyncBlackListInfoToFirstLevelNode()1119 void RSSurfaceRenderNode::SyncBlackListInfoToFirstLevelNode()
1120 {
1121 if (IsLeashWindow() || GetUifirstRootNodeId() == GetId()) {
1122 return;
1123 }
1124 auto firstLevelNode = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(GetFirstLevelNode());
1125 if (!firstLevelNode || GetFirstLevelNodeId() == GetId()) {
1126 return;
1127 }
1128 // firstLevelNode is the nearest app window / leash node
1129 for (const auto& [screenId, nodeIdSet] : blackListIds_) {
1130 for (const auto& nodeId : nodeIdSet) {
1131 if (IsOnTheTree()) {
1132 firstLevelNode->blackListIds_[screenId].insert(nodeId);
1133 } else {
1134 firstLevelNode->blackListIds_[screenId].erase(nodeId);
1135 }
1136 }
1137 }
1138 }
1139
UpdateVirtualScreenWhiteListInfo(const std::unordered_map<ScreenId,std::unordered_set<uint64_t>> & allWhiteListInfo)1140 void RSSurfaceRenderNode::UpdateVirtualScreenWhiteListInfo(
1141 const std::unordered_map<ScreenId, std::unordered_set<uint64_t>>& allWhiteListInfo)
1142 {
1143 if (!IsLeashOrMainWindow()) {
1144 return;
1145 }
1146 for (const auto& [screenId, whiteList] : allWhiteListInfo) {
1147 bool ret = false;
1148 if ((whiteList.find(GetId()) != whiteList.end()) ||
1149 (whiteList.find(GetLeashPersistentId()) != whiteList.end())) {
1150 ret = true;
1151 SetHasWhiteListNode(screenId, ret);
1152 }
1153 auto nodeParent = GetParent().lock();
1154 if (nodeParent == nullptr) {
1155 continue;
1156 }
1157 nodeParent->SetHasWhiteListNode(screenId, ret);
1158 }
1159 }
1160
SyncPrivacyContentInfoToFirstLevelNode()1161 void RSSurfaceRenderNode::SyncPrivacyContentInfoToFirstLevelNode()
1162 {
1163 auto firstLevelNode = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(GetFirstLevelNode());
1164 // firstLevelNode is the nearest app window / leash node
1165 if (firstLevelNode && GetFirstLevelNodeId() != GetId()) {
1166 if (needHidePrivacyContent_ && IsOnTheTree()) {
1167 firstLevelNode->privacyContentLayerIds_.insert(GetId());
1168 } else {
1169 firstLevelNode->privacyContentLayerIds_.erase(GetId());
1170 }
1171 }
1172 }
1173
SyncColorGamutInfoToFirstLevelNode()1174 void RSSurfaceRenderNode::SyncColorGamutInfoToFirstLevelNode()
1175 {
1176 // When the P3 appWindow node is up or down the tree, it transmits color gamut information to leashWindow node.
1177 if (colorSpace_ != GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB) {
1178 auto firstLevelNode = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(GetFirstLevelNode());
1179 if (firstLevelNode) {
1180 firstLevelNode->SetFirstLevelNodeColorGamutByWindow(IsOnTheTree(), colorSpace_);
1181 }
1182 }
1183 }
1184
SetFingerprint(bool hasFingerprint)1185 void RSSurfaceRenderNode::SetFingerprint(bool hasFingerprint)
1186 {
1187 if (hasFingerprint_ == hasFingerprint) {
1188 return;
1189 }
1190 hasFingerprint_ = hasFingerprint;
1191 SetDirty();
1192 }
1193
SetClonedNodeInfo(NodeId id,bool needOffscreen)1194 void RSSurfaceRenderNode::SetClonedNodeInfo(NodeId id, bool needOffscreen)
1195 {
1196 isCloneNode_ = (id != INVALID_NODEID);
1197 clonedSourceNodeId_ = id;
1198 auto context = GetContext().lock();
1199 if (!context) {
1200 RS_LOGE("RSSurfaceRenderNode::SetClonedNodeInfo invalid context");
1201 return;
1202 }
1203 auto clonedSurfaceNode = context->GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(clonedSourceNodeId_);
1204 if (clonedSurfaceNode) {
1205 clonedSurfaceNode->clonedSourceNodeNeedOffscreen_ = needOffscreen;
1206 }
1207 RS_LOGD("RSSurfaceRenderNode::SetClonedNodeInfo clonedNode[%{public}" PRIu64 "] needOffscreen: %{public}d",
1208 id, needOffscreen);
1209 }
1210
SetForceUIFirst(bool forceUIFirst)1211 void RSSurfaceRenderNode::SetForceUIFirst(bool forceUIFirst)
1212 {
1213 if (forceUIFirst) {
1214 forceUIFirstChanged_ = true;
1215 }
1216 forceUIFirst_ = forceUIFirst;
1217 }
1218
GetForceDrawWithSkipped() const1219 bool RSSurfaceRenderNode::GetForceDrawWithSkipped() const
1220 {
1221 return uifirstForceDrawWithSkipped_;
1222 }
1223
SetHDRPresent(bool hasHdrPresent)1224 void RSSurfaceRenderNode::SetHDRPresent(bool hasHdrPresent)
1225 {
1226 auto surfaceParam = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
1227 if (surfaceParam) {
1228 surfaceParam->SetHDRPresent(hasHdrPresent);
1229 AddToPendingSyncList();
1230 }
1231 }
1232
IncreaseHDRNum(HDRComponentType hdrType)1233 void RSSurfaceRenderNode::IncreaseHDRNum(HDRComponentType hdrType)
1234 {
1235 std::lock_guard<std::mutex> lockGuard(mutexHDR_);
1236 if (hdrType == HDRComponentType::IMAGE) {
1237 hdrPhotoNum_++;
1238 RS_LOGD("RSSurfaceRenderNode::IncreaseHDRNum HDRClient hdrPhotoNum_: %{public}d", hdrPhotoNum_);
1239 } else if (hdrType == HDRComponentType::UICOMPONENT) {
1240 hdrUIComponentNum_++;
1241 RS_LOGD("RSSurfaceRenderNode::IncreaseHDRNum HDRClient hdrUIComponentNum_: %{public}d", hdrUIComponentNum_);
1242 } else if (hdrType == HDRComponentType::EFFECT) {
1243 hdrEffectNum_++;
1244 RS_LOGD("RSSurfaceRenderNode::IncreaseHDRNum HDRClient hdrEffectNum_: %{public}d", hdrEffectNum_);
1245 }
1246 }
1247
ReduceHDRNum(HDRComponentType hdrType)1248 void RSSurfaceRenderNode::ReduceHDRNum(HDRComponentType hdrType)
1249 {
1250 std::lock_guard<std::mutex> lockGuard(mutexHDR_);
1251 if (hdrType == HDRComponentType::IMAGE) {
1252 if (hdrPhotoNum_ == 0) {
1253 ROSEN_LOGE("RSSurfaceRenderNode::ReduceHDRNum error");
1254 return;
1255 }
1256 hdrPhotoNum_--;
1257 RS_LOGD("RSSurfaceRenderNode::ReduceHDRNum HDRClient hdrPhotoNum_: %{public}d", hdrPhotoNum_);
1258 } else if (hdrType == HDRComponentType::UICOMPONENT) {
1259 if (hdrUIComponentNum_ == 0) {
1260 ROSEN_LOGE("RSSurfaceRenderNode::ReduceHDRNum error");
1261 return;
1262 }
1263 hdrUIComponentNum_--;
1264 RS_LOGD("RSSurfaceRenderNode::ReduceHDRNum HDRClient hdrUIComponentNum_: %{public}d", hdrUIComponentNum_);
1265 } else if (hdrType == HDRComponentType::EFFECT) {
1266 if (hdrEffectNum_ == 0) {
1267 ROSEN_LOGE("RSSurfaceRenderNode::ReduceHDRNum effect error");
1268 return;
1269 }
1270 hdrEffectNum_--;
1271 RS_LOGD("RSSurfaceRenderNode::ReduceHDRNum HDRClient hdrEffectNum_: %{public}d", hdrEffectNum_);
1272 }
1273 }
1274
IncreaseCanvasGamutNum(GraphicColorGamut gamut)1275 void RSSurfaceRenderNode::IncreaseCanvasGamutNum(GraphicColorGamut gamut)
1276 {
1277 #ifndef ROSEN_CROSS_PLATFORM
1278 GraphicColorGamut canvasGamut = GamutChange(gamut);
1279 if (gamut == GRAPHIC_COLOR_GAMUT_SRGB) {
1280 return;
1281 }
1282 GraphicColorGamut oldGamut = JudgeGamut(bt2020Num_, p3Num_);
1283 if (canvasGamut == GRAPHIC_COLOR_GAMUT_DISPLAY_P3) {
1284 ++p3Num_;
1285 } else if (canvasGamut == GRAPHIC_COLOR_GAMUT_DISPLAY_BT2020) {
1286 ++bt2020Num_;
1287 }
1288 GraphicColorGamut newGamut = JudgeGamut(bt2020Num_, p3Num_);
1289 if (newGamut != oldGamut) {
1290 auto firstLevelNode = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(GetFirstLevelNode());
1291 if (!firstLevelNode) {
1292 RS_LOGE("RSSurfaceRenderNode::IncreaseWideColorGamutNum firstLevelNode is nullptr");
1293 wideColorGamutNum_++;
1294 return;
1295 }
1296 RS_LOGD("RSSurfaceRenderNode::IncreaseCanvasGamutNum notify firstLevelNodeId[%{public}" PRIu64
1297 "] old gamut[%{public}d] new gamut[%{public}d]", firstLevelNode->GetId(), oldGamut, newGamut);
1298 firstLevelNode->SetFirstLevelNodeColorGamutByResource(false, oldGamut);
1299 firstLevelNode->SetFirstLevelNodeColorGamutByResource(true, newGamut);
1300 }
1301 #endif
1302 }
1303
ReduceCanvasGamutNum(GraphicColorGamut gamut)1304 void RSSurfaceRenderNode::ReduceCanvasGamutNum(GraphicColorGamut gamut)
1305 {
1306 #ifndef ROSEN_CROSS_PLATFORM
1307 GraphicColorGamut canvasGamut = GamutChange(gamut);
1308 if (gamut == GRAPHIC_COLOR_GAMUT_SRGB) {
1309 return;
1310 }
1311 GraphicColorGamut oldGamut = JudgeGamut(bt2020Num_, p3Num_);
1312 if (canvasGamut == GRAPHIC_COLOR_GAMUT_DISPLAY_P3) {
1313 p3Num_ = p3Num_ > 0 ? p3Num_ - 1 : 0;
1314 } else if (canvasGamut == GRAPHIC_COLOR_GAMUT_DISPLAY_BT2020) {
1315 bt2020Num_ = bt2020Num_ > 0 ? bt2020Num_ - 1 : 0;
1316 }
1317 GraphicColorGamut newGamut = JudgeGamut(bt2020Num_, p3Num_);
1318 if (newGamut != oldGamut) {
1319 auto firstLevelNode = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(GetFirstLevelNode());
1320 if (!firstLevelNode) {
1321 RS_LOGE("RSSurfaceRenderNode::IncreaseWideColorGamutNum firstLevelNode is nullptr");
1322 wideColorGamutNum_++;
1323 return;
1324 }
1325 RS_LOGD("RSSurfaceRenderNode::IncreaseCanvasGamutNum notify firstLevelNodeId[%{public}" PRIu64
1326 "] old gamut[%{public}d] new gamut[%{public}d]", firstLevelNode->GetId(), oldGamut, newGamut);
1327 firstLevelNode->SetFirstLevelNodeColorGamutByResource(false, oldGamut);
1328 firstLevelNode->SetFirstLevelNodeColorGamutByResource(true, newGamut);
1329 }
1330 #endif
1331 }
1332
IsHdrEffectColorGamut() const1333 bool RSSurfaceRenderNode::IsHdrEffectColorGamut() const
1334 {
1335 return hdrEffectNum_ > 0;
1336 }
1337
SetForceUIFirstChanged(bool forceUIFirstChanged)1338 void RSSurfaceRenderNode::SetForceUIFirstChanged(bool forceUIFirstChanged)
1339 {
1340 forceUIFirstChanged_ = forceUIFirstChanged;
1341 }
GetForceUIFirstChanged()1342 bool RSSurfaceRenderNode::GetForceUIFirstChanged()
1343 {
1344 return forceUIFirstChanged_;
1345 }
1346
SetAncoForceDoDirect(bool direct)1347 void RSSurfaceRenderNode::SetAncoForceDoDirect(bool direct)
1348 {
1349 ancoForceDoDirect_.store(direct);
1350 }
1351
GetOriAncoForceDoDirect()1352 bool RSSurfaceRenderNode::GetOriAncoForceDoDirect()
1353 {
1354 return ancoForceDoDirect_.load();
1355 }
1356
GetAncoForceDoDirect() const1357 bool RSSurfaceRenderNode::GetAncoForceDoDirect() const
1358 {
1359 return (ancoForceDoDirect_.load() && (GetAncoFlags() & static_cast<uint32_t>(AncoFlags::IS_ANCO_NODE)));
1360 }
1361
SetAncoFlags(uint32_t flags)1362 void RSSurfaceRenderNode::SetAncoFlags(uint32_t flags)
1363 {
1364 ancoFlags_.store(flags);
1365 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
1366 if (surfaceParams == nullptr) {
1367 return;
1368 }
1369 surfaceParams->SetAncoFlags(flags);
1370 }
1371
SetAncoSrcCrop(const Rect & srcCrop)1372 void RSSurfaceRenderNode::SetAncoSrcCrop(const Rect& srcCrop)
1373 {
1374 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
1375 if (surfaceParams == nullptr) {
1376 return;
1377 }
1378 surfaceParams->SetAncoSrcCrop(srcCrop);
1379 }
1380
NotifyTreeStateChange()1381 void RSSurfaceRenderNode::NotifyTreeStateChange()
1382 {
1383 if (treeStateChangeCallback_) {
1384 treeStateChangeCallback_(*this);
1385 }
1386 }
1387
SetTopLayerZOrder(uint32_t zOrder)1388 void RSSurfaceRenderNode::SetTopLayerZOrder(uint32_t zOrder)
1389 {
1390 if (!isLayerTop_) {
1391 return;
1392 }
1393 topLayerZOrder_ = zOrder;
1394 }
1395
SetLayerTop(bool isTop,bool isTopLayerForceRefresh)1396 void RSSurfaceRenderNode::SetLayerTop(bool isTop, bool isTopLayerForceRefresh)
1397 {
1398 #ifdef RS_ENABLE_GPU
1399 isLayerTop_ = isTop;
1400 isTopLayerForceRefresh_ = isTopLayerForceRefresh;
1401 SetContentDirty();
1402 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
1403 if (surfaceParams == nullptr) {
1404 return;
1405 }
1406 surfaceParams->SetLayerTop(isTop);
1407 AddToPendingSyncList();
1408 #endif
1409 }
1410
SetForceRefresh(bool isForceRefresh)1411 void RSSurfaceRenderNode::SetForceRefresh(bool isForceRefresh)
1412 {
1413 #ifdef RS_ENABLE_GPU
1414 isForceRefresh_ = isForceRefresh;
1415 SetContentDirty();
1416 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
1417 if (surfaceParams == nullptr) {
1418 return;
1419 }
1420 surfaceParams->SetForceRefresh(isForceRefresh);
1421 AddToPendingSyncList();
1422 #endif
1423 }
1424
IsHardwareEnabledTopSurface() const1425 bool RSSurfaceRenderNode::IsHardwareEnabledTopSurface() const
1426 {
1427 return GetSurfaceNodeType() == RSSurfaceNodeType::CURSOR_NODE && RSSystemProperties::GetHardCursorEnabled();
1428 }
1429
SetHardCursorStatus(bool status)1430 void RSSurfaceRenderNode::SetHardCursorStatus(bool status)
1431 {
1432 #ifdef RS_ENABLE_GPU
1433 if (isHardCursor_ == status) {
1434 isLastHardCursor_ = isHardCursor_;
1435 return;
1436 }
1437 RS_LOGI("RSSurfaceRenderNode::SetHardCursorStatus status:%{public}d", status);
1438 isLastHardCursor_ = isHardCursor_;
1439 isHardCursor_ = status;
1440 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
1441 if (surfaceParams) {
1442 surfaceParams->SetHardCursorStatus(status);
1443 AddToPendingSyncList();
1444 }
1445 #endif
1446 }
1447
SetColorSpace(GraphicColorGamut colorSpace)1448 void RSSurfaceRenderNode::SetColorSpace(GraphicColorGamut colorSpace)
1449 {
1450 GraphicColorGamut newGamut = GamutChange(colorSpace);
1451 if (colorSpace_ == newGamut) {
1452 return;
1453 }
1454 colorSpace_ = newGamut;
1455 if (!isOnTheTree_) {
1456 return;
1457 }
1458 auto firstLevelNode = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(GetFirstLevelNode());
1459 if (!firstLevelNode) {
1460 RS_LOGE("RSSurfaceRenderNode::SetColorSpace firstLevelNode is nullptr");
1461 return;
1462 }
1463 firstLevelNode->SetFirstLevelNodeColorGamutByWindow(true, colorSpace_);
1464 }
1465
GetColorSpace() const1466 GraphicColorGamut RSSurfaceRenderNode::GetColorSpace() const
1467 {
1468 if (!RSSystemProperties::GetWideColorSpaceEnabled()) {
1469 return GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB;
1470 }
1471 int bt2020Num = 0;
1472 int p3Num = 0;
1473 if (RsCommonHook::Instance().IsAdaptiveColorGamutEnabled()) {
1474 bt2020Num = bt2020Num_;
1475 p3Num = p3Num_;
1476 }
1477 GraphicColorGamut selfGamut = GamutChange(colorSpace_);
1478 if (selfGamut == GRAPHIC_COLOR_GAMUT_DISPLAY_P3) {
1479 ++p3Num;
1480 } else if (selfGamut == GRAPHIC_COLOR_GAMUT_DISPLAY_BT2020) {
1481 ++bt2020Num;
1482 }
1483 return JudgeGamut(bt2020Num, p3Num);
1484 }
1485
GetFirstLevelNodeColorGamut() const1486 GraphicColorGamut RSSurfaceRenderNode::GetFirstLevelNodeColorGamut() const
1487 {
1488 if (!RSSystemProperties::GetWideColorSpaceEnabled()) {
1489 return GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB;
1490 }
1491 int bt2020Num = firstLevelNodeBt2020WindowNum_;
1492 int p3Num = firstLevelNodeP3WindowNum_;
1493 if (RsCommonHook::Instance().IsAdaptiveColorGamutEnabled()) {
1494 bt2020Num += firstLevelNodeBt2020ResourceNum_;
1495 p3Num += firstLevelNodeP3ResourceNum_;
1496 }
1497 return JudgeGamut(bt2020Num, p3Num);
1498 }
1499
SetFirstLevelNodeColorGamutByResource(bool isOnTree,GraphicColorGamut gamut)1500 void RSSurfaceRenderNode::SetFirstLevelNodeColorGamutByResource(bool isOnTree, GraphicColorGamut gamut)
1501 {
1502 int tempNum = isOnTree ? 1 : -1;
1503 if (gamut == GRAPHIC_COLOR_GAMUT_DISPLAY_P3) {
1504 firstLevelNodeP3ResourceNum_ += tempNum;
1505 firstLevelNodeP3ResourceNum_ = std::max(firstLevelNodeP3ResourceNum_, 0);
1506 } else if (gamut == GRAPHIC_COLOR_GAMUT_DISPLAY_BT2020) {
1507 firstLevelNodeBt2020ResourceNum_ += tempNum;
1508 firstLevelNodeP3ResourceNum_ = std::max(firstLevelNodeP3ResourceNum_, 0);
1509 }
1510 }
1511
SetFirstLevelNodeColorGamutByWindow(bool isOnTree,GraphicColorGamut gamut)1512 void RSSurfaceRenderNode::SetFirstLevelNodeColorGamutByWindow(bool isOnTree, GraphicColorGamut gamut)
1513 {
1514 int tempNum = isOnTree ? 1 : -1;
1515 if (gamut == GRAPHIC_COLOR_GAMUT_DISPLAY_P3) {
1516 firstLevelNodeP3WindowNum_ += tempNum;
1517 firstLevelNodeP3WindowNum_ = std::max(firstLevelNodeP3WindowNum_, 0);
1518 } else if (gamut == GRAPHIC_COLOR_GAMUT_DISPLAY_BT2020) {
1519 firstLevelNodeBt2020WindowNum_ += tempNum;
1520 firstLevelNodeP3WindowNum_ = std::max(firstLevelNodeP3WindowNum_, 0);
1521 }
1522 }
1523
UpdateColorSpaceWithMetadata()1524 void RSSurfaceRenderNode::UpdateColorSpaceWithMetadata()
1525 {
1526 #ifndef ROSEN_CROSS_PLATFORM
1527 if (!GetRSSurfaceHandler() || !GetRSSurfaceHandler()->GetBuffer()) {
1528 RS_LOGD("RSSurfaceRenderNode::UpdateColorSpaceWithMetadata node(%{public}s) did not have buffer.",
1529 GetName().c_str());
1530 return;
1531 }
1532 const sptr<SurfaceBuffer>& buffer = GetRSSurfaceHandler()->GetBuffer();
1533 using namespace HDI::Display::Graphic::Common::V1_0;
1534 CM_ColorSpaceInfo colorSpaceInfo;
1535 if (MetadataHelper::GetColorSpaceInfo(buffer, colorSpaceInfo) != GSERROR_OK) {
1536 RS_LOGD("RSSurfaceRenderNode::UpdateColorSpaceWithMetadata get color space info failed.");
1537 return;
1538 }
1539 SetColorSpace(CMPrimariesToGamut(colorSpaceInfo.primaries));
1540 #endif
1541 }
1542
UpdateSurfaceDefaultSize(float width,float height)1543 void RSSurfaceRenderNode::UpdateSurfaceDefaultSize(float width, float height)
1544 {
1545 #ifndef ROSEN_CROSS_PLATFORM
1546 if (!surfaceHandler_) {
1547 return;
1548 }
1549 auto consumer = surfaceHandler_->GetConsumer();
1550 if (!consumer) {
1551 return;
1552 }
1553 consumer->SetDefaultWidthAndHeight(width, height);
1554 #else
1555 #ifdef USE_SURFACE_TEXTURE
1556 auto texture = GetSurfaceTexture();
1557 if (texture) {
1558 texture->UpdateSurfaceDefaultSize(width, height);
1559 }
1560 #endif
1561 #endif
1562 }
1563
1564 #ifndef ROSEN_CROSS_PLATFORM
UpdateBufferInfo(const sptr<SurfaceBuffer> & buffer,const Rect & damageRect,const sptr<SyncFence> & acquireFence,const sptr<SurfaceBuffer> & preBuffer)1565 void RSSurfaceRenderNode::UpdateBufferInfo(const sptr<SurfaceBuffer>& buffer, const Rect& damageRect,
1566 const sptr<SyncFence>& acquireFence, const sptr<SurfaceBuffer>& preBuffer)
1567 {
1568 #ifdef RS_ENABLE_GPU
1569 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
1570 if (!surfaceParams->IsBufferSynced()) {
1571 auto curBuffer = surfaceParams->GetBuffer();
1572 auto consumer = GetRSSurfaceHandler()->GetConsumer();
1573 if (curBuffer && consumer) {
1574 auto fence = surfaceParams->GetAcquireFence();
1575 consumer->ReleaseBuffer(curBuffer, fence);
1576 }
1577 } else {
1578 surfaceParams->SetPreBuffer(preBuffer);
1579 }
1580
1581 surfaceParams->SetBuffer(buffer, damageRect);
1582 surfaceParams->SetAcquireFence(acquireFence);
1583 surfaceParams->SetBufferSynced(false);
1584 surfaceParams->SetIsBufferFlushed(true);
1585 AddToPendingSyncList();
1586 #endif
1587 }
1588
NeedClearBufferCache(std::set<uint32_t> & bufferCacheSet)1589 void RSSurfaceRenderNode::NeedClearBufferCache(std::set<uint32_t>& bufferCacheSet)
1590 {
1591 #ifdef RS_ENABLE_GPU
1592 if (!surfaceHandler_) {
1593 return;
1594 }
1595
1596 if (auto buffer = surfaceHandler_->GetBuffer()) {
1597 bufferCacheSet.insert(buffer->GetSeqNum());
1598 RS_OPTIONAL_TRACE_NAME_FMT("NeedClearBufferCache bufferSeqNum:%d", buffer->GetSeqNum());
1599 }
1600 if (auto preBuffer = surfaceHandler_->GetPreBuffer()) {
1601 bufferCacheSet.insert(preBuffer->GetSeqNum());
1602 RS_OPTIONAL_TRACE_NAME_FMT("NeedClearBufferCache preBufferSeqNum:%d", preBuffer->GetSeqNum());
1603 }
1604 #endif
1605 }
1606
NeedClearPreBuffer(std::set<uint32_t> & bufferCacheSet)1607 void RSSurfaceRenderNode::NeedClearPreBuffer(std::set<uint32_t>& bufferCacheSet)
1608 {
1609 #ifdef RS_ENABLE_GPU
1610 if (!surfaceHandler_) {
1611 return;
1612 }
1613 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
1614 if (surfaceParams == nullptr) {
1615 return;
1616 }
1617 if (auto preBuffer = surfaceHandler_->GetPreBuffer()) {
1618 bufferCacheSet.insert(preBuffer->GetSeqNum());
1619 RS_OPTIONAL_TRACE_NAME_FMT("NeedClearPreBuffer preBufferSeqNum:%d", preBuffer->GetSeqNum());
1620 }
1621 surfaceParams->SetPreBuffer(nullptr);
1622 AddToPendingSyncList();
1623 #endif
1624 }
1625
1626 #endif
1627
RegisterBufferAvailableListener(sptr<RSIBufferAvailableCallback> callback,bool isFromRenderThread)1628 void RSSurfaceRenderNode::RegisterBufferAvailableListener(
1629 sptr<RSIBufferAvailableCallback> callback, bool isFromRenderThread)
1630 {
1631 if (isFromRenderThread) {
1632 std::lock_guard<std::mutex> lock(mutexRT_);
1633 callbackFromRT_ = callback;
1634 } else {
1635 {
1636 std::lock_guard<std::mutex> lock(mutexUI_);
1637 callbackFromUI_ = callback;
1638 }
1639 isNotifyUIBufferAvailable_ = false;
1640 }
1641 }
1642
RegisterBufferClearListener(sptr<RSIBufferClearCallback> callback)1643 void RSSurfaceRenderNode::RegisterBufferClearListener(
1644 sptr<RSIBufferClearCallback> callback)
1645 {
1646 std::lock_guard<std::mutex> lock(mutexClear_);
1647 clearBufferCallback_ = callback;
1648 }
1649
SetNotifyRTBufferAvailable(bool isNotifyRTBufferAvailable)1650 void RSSurfaceRenderNode::SetNotifyRTBufferAvailable(bool isNotifyRTBufferAvailable)
1651 {
1652 isNotifyRTBufferAvailable_ = isNotifyRTBufferAvailable;
1653 if (GetIsTextureExportNode()) {
1654 SetContentDirty();
1655 }
1656 std::lock_guard<std::mutex> lock(mutexClear_);
1657 if (clearBufferCallback_) {
1658 clearBufferCallback_->OnBufferClear();
1659 }
1660 }
1661
ConnectToNodeInRenderService()1662 void RSSurfaceRenderNode::ConnectToNodeInRenderService()
1663 {
1664 ROSEN_LOGI("RSSurfaceRenderNode::ConnectToNodeInRenderService nodeId = %{public}" PRIu64, GetId());
1665 auto renderServiceClient =
1666 std::static_pointer_cast<RSRenderServiceClient>(RSIRenderClient::CreateRenderServiceClient());
1667 if (renderServiceClient != nullptr) {
1668 renderServiceClient->RegisterBufferAvailableListener(
1669 GetId(), [weakThis = weak_from_this()]() {
1670 auto node = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(weakThis.lock());
1671 if (node == nullptr) {
1672 return;
1673 }
1674 node->NotifyRTBufferAvailable(node->GetIsTextureExportNode());
1675 }, true);
1676 renderServiceClient->RegisterBufferClearListener(
1677 GetId(), [weakThis = weak_from_this()]() {
1678 auto node = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(weakThis.lock());
1679 if (node == nullptr) {
1680 return;
1681 }
1682 node->SetNotifyRTBufferAvailable(false);
1683 });
1684 }
1685 }
1686
NotifyRTBufferAvailable(bool isTextureExportNode)1687 void RSSurfaceRenderNode::NotifyRTBufferAvailable(bool isTextureExportNode)
1688 {
1689 // In RS, "isNotifyRTBufferAvailable_ = true" means buffer is ready and need to trigger ipc callback.
1690 // In RT, "isNotifyRTBufferAvailable_ = true" means RT know that RS have had available buffer
1691 // and ready to trigger "callbackForRenderThreadRefresh_" to "clip" on parent surface.
1692 if (!isTextureExportNode) {
1693 isNotifyRTBufferAvailablePre_ = isNotifyRTBufferAvailable_;
1694 if (isNotifyRTBufferAvailable_) {
1695 return;
1696 }
1697 isNotifyRTBufferAvailable_ = true;
1698 }
1699
1700 if (isRefresh_) {
1701 ROSEN_LOGD("RSSurfaceRenderNode::NotifyRTBufferAvailable nodeId = %{public}" PRIu64 " RenderThread", GetId());
1702 RSRTRefreshCallback::Instance().ExecuteRefresh();
1703 }
1704 if (isTextureExportNode) {
1705 SetContentDirty();
1706 }
1707
1708 {
1709 std::lock_guard<std::mutex> lock(mutexRT_);
1710 if (callbackFromRT_) {
1711 ROSEN_LOGD("RSSurfaceRenderNode::NotifyRTBufferAvailable nodeId = %{public}" PRIu64 " RenderService",
1712 GetId());
1713 callbackFromRT_->OnBufferAvailable();
1714 }
1715 if (!isRefresh_ && !callbackFromRT_) {
1716 isNotifyRTBufferAvailable_ = false;
1717 }
1718 }
1719 }
1720
NotifyUIBufferAvailable()1721 void RSSurfaceRenderNode::NotifyUIBufferAvailable()
1722 {
1723 RS_TRACE_NAME_FMT("RSSurfaceRenderNode::NotifyUIBufferAvailable id:%llu bufferAvailable:%d waitUifirst:%d",
1724 GetId(), IsNotifyUIBufferAvailable(), IsWaitUifirstFirstFrame());
1725 if (isNotifyUIBufferAvailable_ || isWaitUifirstFirstFrame_) {
1726 return;
1727 }
1728 isNotifyUIBufferAvailable_ = true;
1729 {
1730 std::lock_guard<std::mutex> lock(mutexUI_);
1731 if (callbackFromUI_) {
1732 RS_TRACE_NAME_FMT("NotifyUIBufferAvailable done. id:%llu", GetId());
1733 ROSEN_LOGI("RSSurfaceRenderNode::NotifyUIBufferAvailable nodeId = %{public}" PRIu64, GetId());
1734 callbackFromUI_->OnBufferAvailable();
1735 #ifdef OHOS_PLATFORM
1736 if (IsAppWindow()) {
1737 RSJankStats::GetInstance().SetAppFirstFrame(ExtractPid(GetId()));
1738 }
1739 #endif
1740 }
1741 }
1742 }
1743
IsNotifyRTBufferAvailable() const1744 bool RSSurfaceRenderNode::IsNotifyRTBufferAvailable() const
1745 {
1746 #if defined(ROSEN_ANDROID) || defined(ROSEN_IOS)
1747 return true;
1748 #else
1749 return isNotifyRTBufferAvailable_;
1750 #endif
1751 }
1752
IsNotifyRTBufferAvailablePre() const1753 bool RSSurfaceRenderNode::IsNotifyRTBufferAvailablePre() const
1754 {
1755 #if defined(ROSEN_ANDROID) || defined(ROSEN_IOS)
1756 return true;
1757 #else
1758 return isNotifyRTBufferAvailablePre_;
1759 #endif
1760 }
1761
IsNotifyUIBufferAvailable() const1762 bool RSSurfaceRenderNode::IsNotifyUIBufferAvailable() const
1763 {
1764 return isNotifyUIBufferAvailable_;
1765 }
1766
SetCallbackForRenderThreadRefresh(bool isRefresh)1767 void RSSurfaceRenderNode::SetCallbackForRenderThreadRefresh(bool isRefresh)
1768 {
1769 isRefresh_ = isRefresh;
1770 }
1771
NeedSetCallbackForRenderThreadRefresh()1772 bool RSSurfaceRenderNode::NeedSetCallbackForRenderThreadRefresh()
1773 {
1774 return !isRefresh_;
1775 }
1776
IsStartAnimationFinished() const1777 bool RSSurfaceRenderNode::IsStartAnimationFinished() const
1778 {
1779 return startAnimationFinished_;
1780 }
1781
SetStartAnimationFinished()1782 void RSSurfaceRenderNode::SetStartAnimationFinished()
1783 {
1784 RS_LOGD("RSSurfaceRenderNode::SetStartAnimationFinished");
1785 startAnimationFinished_ = true;
1786 }
1787
UpdateDirtyIfFrameBufferConsumed()1788 bool RSSurfaceRenderNode::UpdateDirtyIfFrameBufferConsumed()
1789 {
1790 if (surfaceHandler_ && surfaceHandler_->IsCurrentFrameBufferConsumed()) {
1791 SetContentDirty();
1792 return true;
1793 }
1794 return false;
1795 }
1796
IsSurfaceInStartingWindowStage() const1797 bool RSSurfaceRenderNode::IsSurfaceInStartingWindowStage() const
1798 {
1799 auto parentPtr = this->GetParent().lock();
1800 if (parentPtr != nullptr && parentPtr->IsInstanceOf<RSSurfaceRenderNode>()) {
1801 auto surfaceParentPtr = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(parentPtr);
1802 if (surfaceParentPtr->GetSurfaceNodeType() == RSSurfaceNodeType::LEASH_WINDOW_NODE &&
1803 !this->IsNotifyUIBufferAvailable()) {
1804 return true;
1805 }
1806 }
1807 return false;
1808 }
1809
IsParentLeashWindowInScale() const1810 bool RSSurfaceRenderNode::IsParentLeashWindowInScale() const
1811 {
1812 auto parentPtr = this->GetParent().lock();
1813 if (parentPtr != nullptr && parentPtr->IsInstanceOf<RSSurfaceRenderNode>()) {
1814 auto surfaceParentPtr = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(parentPtr);
1815 if (surfaceParentPtr->IsLeashWindow() && surfaceParentPtr->IsScale()) {
1816 return true;
1817 }
1818 }
1819 return false;
1820 }
1821
GetSurfaceOcclusionRect(bool isUniRender)1822 Occlusion::Rect RSSurfaceRenderNode::GetSurfaceOcclusionRect(bool isUniRender)
1823 {
1824 Occlusion::Rect occlusionRect;
1825 if (isUniRender) {
1826 occlusionRect =
1827 IsFirstLevelCrossNode() ? Occlusion::Rect {GetAbsDrawRect()} : Occlusion::Rect {GetOldDirtyInSurface()};
1828 } else {
1829 occlusionRect = Occlusion::Rect {GetDstRect()};
1830 }
1831 return occlusionRect;
1832 }
1833
QueryIfAllHwcChildrenForceDisabledByFilter()1834 bool RSSurfaceRenderNode::QueryIfAllHwcChildrenForceDisabledByFilter()
1835 {
1836 std::shared_ptr<RSSurfaceRenderNode> appWindow;
1837 for (auto& child : *GetSortedChildren()) {
1838 auto node = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(child);
1839 if (node && node->IsAppWindow()) {
1840 appWindow = node;
1841 break;
1842 }
1843 }
1844 if (appWindow) {
1845 auto hardwareEnabledNodes = appWindow->GetChildHardwareEnabledNodes();
1846 for (auto& hardwareEnabledNode : hardwareEnabledNodes) {
1847 auto hardwareEnabledNodePtr = hardwareEnabledNode.lock();
1848 if (hardwareEnabledNodePtr && !hardwareEnabledNodePtr->IsHardwareForcedDisabledByFilter()) {
1849 return false;
1850 }
1851 }
1852 }
1853 return true;
1854 }
1855
AccumulateOcclusionRegion(Occlusion::Region & accumulatedRegion,Occlusion::Region & curRegion,bool & hasFilterCacheOcclusion,bool isUniRender,bool filterCacheOcclusionEnabled)1856 void RSSurfaceRenderNode::AccumulateOcclusionRegion(Occlusion::Region& accumulatedRegion,
1857 Occlusion::Region& curRegion,
1858 bool& hasFilterCacheOcclusion,
1859 bool isUniRender,
1860 bool filterCacheOcclusionEnabled)
1861 {
1862 // when surfacenode is in starting window stage, do not occlude other window surfaces
1863 // fix gray block when directly open app (i.e. setting) from notification center
1864 if (IsSurfaceInStartingWindowStage()) {
1865 return;
1866 }
1867 if (!isUniRender) {
1868 bool diff =
1869 #ifndef ROSEN_CROSS_PLATFORM
1870 (GetDstRect().width_ > surfaceHandler_->GetBuffer()->GetWidth() ||
1871 GetDstRect().height_ > surfaceHandler_->GetBuffer()->GetHeight()) &&
1872 #endif
1873 GetRenderProperties().GetFrameGravity() != Gravity::RESIZE && ROSEN_EQ(GetGlobalAlpha(), 1.0f);
1874 if (!IsTransparent() && !diff) {
1875 accumulatedRegion.OrSelf(curRegion);
1876 }
1877 }
1878
1879 if (GetName().find("hisearch") != std::string::npos) {
1880 return;
1881 }
1882 SetTreatedAsTransparent(false);
1883 // when a surfacenode is in animation (i.e. 3d animation), its dstrect cannot be trusted, we treated it as a full
1884 // transparent layer.
1885 if ((GetAnimateState() || IsParentLeashWindowInScale()) && !isOcclusionInSpecificScenes_) {
1886 SetTreatedAsTransparent(true);
1887 return;
1888 }
1889
1890 // full surfacenode valid filter cache can be treated as opaque
1891 if (filterCacheOcclusionEnabled && IsTransparent() && GetFilterCacheValidForOcclusion()) {
1892 accumulatedRegion.OrSelf(curRegion);
1893 hasFilterCacheOcclusion = true;
1894 } else {
1895 accumulatedRegion.OrSelf(GetOpaqueRegion());
1896 }
1897 return;
1898 }
1899
GetVisibleLevelForWMS(RSVisibleLevel visibleLevel)1900 WINDOW_LAYER_INFO_TYPE RSSurfaceRenderNode::GetVisibleLevelForWMS(RSVisibleLevel visibleLevel)
1901 {
1902 switch (visibleLevel) {
1903 case RSVisibleLevel::RS_INVISIBLE:
1904 return WINDOW_LAYER_INFO_TYPE::INVISIBLE;
1905 case RSVisibleLevel::RS_ALL_VISIBLE:
1906 return WINDOW_LAYER_INFO_TYPE::ALL_VISIBLE;
1907 case RSVisibleLevel::RS_SEMI_NONDEFAULT_VISIBLE:
1908 case RSVisibleLevel::RS_SEMI_DEFAULT_VISIBLE:
1909 return WINDOW_LAYER_INFO_TYPE::SEMI_VISIBLE;
1910 default:
1911 break;
1912 }
1913 return WINDOW_LAYER_INFO_TYPE::SEMI_VISIBLE;
1914 }
1915
IsSCBNode() const1916 bool RSSurfaceRenderNode::IsSCBNode() const
1917 {
1918 return !IS_SCB_WINDOW_TYPE(surfaceWindowType_);
1919 }
1920
UpdateHwcNodeLayerInfo(GraphicTransformType transform,bool isHardCursorEnable)1921 void RSSurfaceRenderNode::UpdateHwcNodeLayerInfo(GraphicTransformType transform, bool isHardCursorEnable)
1922 {
1923 #ifdef RS_ENABLE_GPU
1924 #ifndef ROSEN_CROSS_PLATFORM
1925 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
1926 auto layer = surfaceParams->GetLayerInfo();
1927 layer.srcRect = {srcRect_.left_, srcRect_.top_, srcRect_.width_, srcRect_.height_};
1928 layer.dstRect = {dstRect_.left_, dstRect_.top_, dstRect_.width_, dstRect_.height_};
1929 const auto& properties = GetRenderProperties();
1930 layer.boundRect = {0, 0,
1931 static_cast<uint32_t>(properties.GetBoundsWidth()),
1932 static_cast<uint32_t>(properties.GetBoundsHeight())};
1933 layer.transformType = transform;
1934 layer.zOrder = surfaceHandler_->GetGlobalZOrder();
1935 layer.gravity = static_cast<int32_t>(properties.GetFrameGravity());
1936 layer.blendType = GetBlendType();
1937 layer.matrix = totalMatrix_;
1938 layer.alpha = GetGlobalAlpha();
1939 layer.arsrTag = GetArsrTag();
1940 layer.copybitTag = GetCopybitTag();
1941 layer.ancoFlags = surfaceParams->GetAncoFlags();
1942 const Rect& cropRect = surfaceParams->GetAncoSrcCrop();
1943 layer.ancoCropRect = {cropRect.x, cropRect.y, cropRect.w, cropRect.h};
1944 layer.useDeviceOffline = GetDeviceOfflineEnable();
1945 if (isHardCursorEnable) {
1946 layer.layerType = GraphicLayerType::GRAPHIC_LAYER_TYPE_CURSOR;
1947 } else {
1948 layer.layerType = GraphicLayerType::GRAPHIC_LAYER_TYPE_GRAPHIC;
1949 }
1950 isHardwareForcedDisabled_ = specialLayerManager_.Find(SpecialLayerType::PROTECTED) ?
1951 false : isHardwareForcedDisabled_;
1952 #ifndef ROSEN_CROSS_PLATFORM
1953 auto buffer = surfaceHandler_->GetBuffer();
1954 RS_LOGD("RSSurfaceRenderNode::UpdateHwcNodeLayerInfo: name:%{public}s id:%{public}" PRIu64 ", bufferFormat:%d,"
1955 " src:%{public}s, dst:%{public}s, bounds:[%{public}d, %{public}d] buffer:[%{public}d, %{public}d]"
1956 " transform:%{public}d, zOrder:%{public}d, cur:%{public}d, last:%{public}d",
1957 GetName().c_str(), GetId(), buffer ? buffer->GetFormat() : -1,
1958 srcRect_.ToString().c_str(),
1959 dstRect_.ToString().c_str(),
1960 layer.boundRect.w, layer.boundRect.h,
1961 buffer ? buffer->GetSurfaceBufferWidth() : 0, buffer ? buffer->GetSurfaceBufferHeight() : 0,
1962 transform, layer.zOrder, !IsHardwareForcedDisabled(), isLastFrameHwcEnabled_);
1963 RS_OPTIONAL_TRACE_NAME_FMT("hwc debug:UpdateHwcNodeLayerInfo: name:%s id:%lu, bufferFormat:%d,"
1964 " src:%s, dst:%s, bounds:[%d, %d], buffer:[%d, %d], transform:%d, zOrder:%d, cur:%d, last:%d",
1965 GetName().c_str(), GetId(), buffer ? buffer->GetFormat() : -1,
1966 srcRect_.ToString().c_str(),
1967 dstRect_.ToString().c_str(),
1968 layer.boundRect.w, layer.boundRect.h,
1969 buffer ? buffer->GetSurfaceBufferWidth() : 0, buffer ? buffer->GetSurfaceBufferHeight() : 0,
1970 transform, layer.zOrder, !IsHardwareForcedDisabled(), isLastFrameHwcEnabled_);
1971 #endif
1972 surfaceParams->SetLayerInfo(layer);
1973 surfaceParams->SetHardwareEnabled(!IsHardwareForcedDisabled());
1974 surfaceParams->SetNeedMakeImage(IsHardwareNeedMakeImage());
1975 surfaceParams->SetLastFrameHardwareEnabled(isLastFrameHwcEnabled_);
1976 surfaceParams->SetInFixedRotation(isInFixedRotation_);
1977 surfaceParams->SetAbsRotation(GetAbsRotation());
1978 // 1 means need source tuning
1979 if (RsCommonHook::Instance().GetVideoSurfaceFlag() && IsYUVBufferFormat()) {
1980 surfaceParams->SetLayerSourceTuning(1);
1981 }
1982 // set tuning for anco node
1983 if (GetAncoFlags() & static_cast<uint32_t>(AncoFlags::IS_ANCO_NODE)) {
1984 surfaceParams->SetLayerSourceTuning(1);
1985 }
1986 AddToPendingSyncList();
1987 #endif
1988 #endif
1989 }
1990
SetPreSubHighPriorityType(bool priorityType)1991 void RSSurfaceRenderNode::SetPreSubHighPriorityType(bool priorityType)
1992 {
1993 #ifdef RS_ENABLE_GPU
1994 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
1995 if (surfaceParams == nullptr) {
1996 RS_LOGE("RSSurfaceRenderNode::SetPreSubHighPriorityType surfaceParams is Null");
1997 return;
1998 }
1999 surfaceParams->SetPreSubHighPriorityType(priorityType);
2000 AddToPendingSyncList();
2001 #endif
2002 }
2003
UpdateHardwareDisabledState(bool disabled)2004 void RSSurfaceRenderNode::UpdateHardwareDisabledState(bool disabled)
2005 {
2006 #ifdef RS_ENABLE_GPU
2007 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2008 surfaceParams->SetLastFrameHardwareEnabled(!IsHardwareForcedDisabled());
2009 SetHardwareForcedDisabledState(disabled);
2010 surfaceParams->SetHardwareEnabled(!IsHardwareForcedDisabled());
2011 AddToPendingSyncList();
2012 #endif
2013 }
2014
SetVisibleRegionRecursive(const Occlusion::Region & region,VisibleData & visibleVec,std::map<NodeId,RSVisibleLevel> & visMapForVsyncRate,bool needSetVisibleRegion,RSVisibleLevel visibleLevel,bool isSystemAnimatedScenes)2015 void RSSurfaceRenderNode::SetVisibleRegionRecursive(const Occlusion::Region& region,
2016 VisibleData& visibleVec,
2017 std::map<NodeId, RSVisibleLevel>& visMapForVsyncRate,
2018 bool needSetVisibleRegion,
2019 RSVisibleLevel visibleLevel,
2020 bool isSystemAnimatedScenes)
2021 {
2022 if (nodeType_ == RSSurfaceNodeType::SELF_DRAWING_NODE || IsAbilityComponent()) {
2023 SetOcclusionVisible(true);
2024 visibleVec.emplace_back(std::make_pair(GetId(), ALL_VISIBLE));
2025 return;
2026 }
2027
2028 bool vis = !region.IsEmpty();
2029 if (vis) {
2030 visibleVec.emplace_back(std::make_pair(GetId(), GetVisibleLevelForWMS(visibleLevel)));
2031 }
2032
2033 // collect visible changed pid
2034 if (qosPidCal_ && GetType() == RSRenderNodeType::SURFACE_NODE && !isSystemAnimatedScenes) {
2035 visMapForVsyncRate[GetId()] = !IsSCBNode() ? RSVisibleLevel::RS_ALL_VISIBLE : visibleLevel;
2036 }
2037
2038 visibleRegionForCallBack_ = region;
2039 if (needSetVisibleRegion) {
2040 visibleRegion_ = region;
2041 SetOcclusionVisible(vis);
2042 }
2043 // when there is filter cache occlusion, also save occlusion status without filter cache
2044 SetOcclusionVisibleWithoutFilter(vis);
2045
2046 for (auto& child : *GetChildren()) {
2047 if (auto surfaceChild = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(child)) {
2048 surfaceChild->SetVisibleRegionRecursive(region, visibleVec, visMapForVsyncRate, needSetVisibleRegion,
2049 visibleLevel, isSystemAnimatedScenes);
2050 }
2051 }
2052 }
2053
ResetSurfaceOpaqueRegion(const RectI & screeninfo,const RectI & absRect,const ScreenRotation screenRotation,const bool isFocusWindow,const Vector4<int> & cornerRadius)2054 void RSSurfaceRenderNode::ResetSurfaceOpaqueRegion(const RectI& screeninfo, const RectI& absRect,
2055 const ScreenRotation screenRotation, const bool isFocusWindow, const Vector4<int>& cornerRadius)
2056 {
2057 Occlusion::Region absRegion { absRect };
2058 Occlusion::Region oldOpaqueRegion { opaqueRegion_ };
2059 Occlusion::Region oldOcclusionRegionBehindWindow { occlusionRegionBehindWindow_ };
2060
2061 // The transparent region of surfaceNode should include shadow area
2062 Occlusion::Rect dirtyRect { GetOldDirty() };
2063 transparentRegion_ = Occlusion::Region{ dirtyRect };
2064
2065 if (IsTransparent() && !NeedDrawBehindWindow()) {
2066 RS_OPTIONAL_TRACE_NAME_FMT("CalcOpaqueRegion [%s] transparent: OcclusionBg:[%d], alpha:[%f], IsEmpty:[%d]",
2067 GetName().c_str(), static_cast<int>(GetAbilityBgAlpha()), GetGlobalAlpha(), IsEmptyAppWindow());
2068 opaqueRegion_ = Occlusion::Region();
2069 } else {
2070 auto maxRadius = std::max({ cornerRadius.x_, cornerRadius.y_, cornerRadius.z_, cornerRadius.w_ });
2071 if (IsAppWindow() && HasContainerWindow()) {
2072 containerConfig_.outR_ = maxRadius;
2073 RS_OPTIONAL_TRACE_NAME_FMT("CalcOpaqueRegion [%s] has container: inR:[%d], outR:[%d], innerRect:[%s], "
2074 "isFocus:[%d]", GetName().c_str(), containerConfig_.inR_, containerConfig_.outR_,
2075 containerConfig_.innerRect_.ToString().c_str(), isFocusWindow);
2076 opaqueRegion_ = ResetOpaqueRegion(GetAbsDrawRect(), screenRotation, isFocusWindow);
2077 opaqueRegion_.AndSelf(absRegion);
2078 } else {
2079 if (!cornerRadius.IsZero()) {
2080 Vector4<int> dstCornerRadius((cornerRadius.x_ > 0 ? maxRadius : 0),
2081 (cornerRadius.y_ > 0 ? maxRadius : 0),
2082 (cornerRadius.z_ > 0 ? maxRadius : 0),
2083 (cornerRadius.w_ > 0 ? maxRadius : 0));
2084 RS_OPTIONAL_TRACE_NAME_FMT("CalcOpaqueRegion [%s] with cornerRadius: [%d, %d, %d, %d]",
2085 GetName().c_str(), dstCornerRadius.x_, dstCornerRadius.y_, dstCornerRadius.z_, dstCornerRadius.w_);
2086 SetCornerRadiusOpaqueRegion(absRect, dstCornerRadius);
2087 } else {
2088 opaqueRegion_ = absRegion;
2089 roundedCornerRegion_ = Occlusion::Region();
2090 }
2091 }
2092 DealWithDrawBehindWindowTransparentRegion();
2093 transparentRegion_.SubSelf(opaqueRegion_);
2094 }
2095 Occlusion::Region clipRegion{Occlusion::Rect{GetOldDirtyInSurface()}};
2096 transparentRegion_.AndSelf(clipRegion);
2097 opaqueRegion_.AndSelf(clipRegion);
2098 occlusionRegionBehindWindow_ = Occlusion::Region(Occlusion::Rect(
2099 NeedDrawBehindWindow() ? GetFilterRect() : RectI()));
2100 opaqueRegionChanged_ = !oldOpaqueRegion.Xor(opaqueRegion_).IsEmpty();
2101 behindWindowOcclusionChanged_ = !oldOcclusionRegionBehindWindow.Xor(
2102 occlusionRegionBehindWindow_).IsEmpty();
2103 ResetSurfaceContainerRegion(screeninfo, absRect, screenRotation);
2104 }
2105
DealWithDrawBehindWindowTransparentRegion()2106 void RSSurfaceRenderNode::DealWithDrawBehindWindowTransparentRegion()
2107 {
2108 const auto& absDrawBehindWindowRegion = GetFilterRect();
2109 RS_OPTIONAL_TRACE_NAME_FMT("CalcOpaqueRegion [%s] needDrawBehindWindow: [%d] localRegion: [%s], absRegion: [%s]",
2110 GetName().c_str(), NeedDrawBehindWindow(), drawBehindWindowRegion_.ToString().c_str(),
2111 absDrawBehindWindowRegion.ToString().c_str());
2112 if (!NeedDrawBehindWindow() || drawBehindWindowRegion_.IsEmpty()) {
2113 return;
2114 }
2115 auto partialTransparentRegion = Occlusion::Region{ Occlusion::Rect{ absDrawBehindWindowRegion} };
2116 opaqueRegion_.SubSelf(partialTransparentRegion);
2117 }
2118
CalcFilterCacheValidForOcclusion()2119 void RSSurfaceRenderNode::CalcFilterCacheValidForOcclusion()
2120 {
2121 isFilterCacheStatusChanged_ = false;
2122 bool currentCacheValidForOcclusion = isFilterCacheFullyCovered_ && dirtyManager_->IsFilterCacheRectValid();
2123 if (isFilterCacheValidForOcclusion_ != currentCacheValidForOcclusion) {
2124 isFilterCacheValidForOcclusion_ = currentCacheValidForOcclusion;
2125 isFilterCacheStatusChanged_ = true;
2126 }
2127 }
2128
UpdateFilterNodes(const std::shared_ptr<RSRenderNode> & nodePtr)2129 void RSSurfaceRenderNode::UpdateFilterNodes(const std::shared_ptr<RSRenderNode>& nodePtr)
2130 {
2131 if (nodePtr == nullptr) {
2132 return;
2133 }
2134 filterNodes_.emplace_back(nodePtr);
2135 }
2136
CheckValidFilterCacheFullyCoverTarget(const RSRenderNode & filterNode,const RectI & targetRect)2137 void RSSurfaceRenderNode::CheckValidFilterCacheFullyCoverTarget(const RSRenderNode& filterNode, const RectI& targetRect)
2138 {
2139 if (filterNode.IsInstanceOf<RSEffectRenderNode>()) {
2140 return;
2141 }
2142 if (isFilterCacheFullyCovered_ || !filterNode.IsFilterCacheValid()) {
2143 return;
2144 }
2145 // AbsRect may not update here, so use filterCachedRegion to occlude
2146 isFilterCacheFullyCovered_ = targetRect.IsInsideOf(filterNode.GetFilterCachedRegion());
2147 }
2148
UpdateOccludedByFilterCache(bool val)2149 void RSSurfaceRenderNode::UpdateOccludedByFilterCache(bool val)
2150 {
2151 #ifdef RS_ENABLE_GPU
2152 isOccludedByFilterCache_ = val;
2153 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2154 surfaceParams->SetOccludedByFilterCache(isOccludedByFilterCache_);
2155 #endif
2156 }
2157
UpdateSurfaceCacheContentStaticFlag(bool isAccessibilityChanged)2158 void RSSurfaceRenderNode::UpdateSurfaceCacheContentStaticFlag(bool isAccessibilityChanged)
2159 {
2160 #ifdef RS_ENABLE_GPU
2161 auto contentStatic = false;
2162 auto uifirstContentDirty = false;
2163 if (IsLeashWindow()) {
2164 for (auto& child : *GetSortedChildren()) {
2165 if (!child) {
2166 continue;
2167 }
2168 auto childSurface = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(child);
2169 if (childSurface) {
2170 continue;
2171 }
2172 if (child->IsDirty() || child->IsSubTreeDirty()) {
2173 uifirstContentDirty = true;
2174 }
2175 }
2176 contentStatic = (!IsSubTreeDirty() || GetForceUpdateByUifirst()) && !HasRemovedChild();
2177 } else {
2178 contentStatic = (!IsSubTreeDirty() || GetForceUpdateByUifirst()) && !IsContentDirty();
2179 }
2180 contentStatic = contentStatic && !isAccessibilityChanged;
2181 uifirstContentDirty_ = uifirstContentDirty_ || uifirstContentDirty || HasRemovedChild();
2182 auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2183 if (stagingSurfaceParams) {
2184 stagingSurfaceParams->SetSurfaceCacheContentStatic(contentStatic, lastFrameSynced_);
2185 }
2186 if (stagingRenderParams_->NeedSync()) {
2187 AddToPendingSyncList();
2188 }
2189 RS_OPTIONAL_TRACE_NAME_FMT("RSSurfaceRenderNode::UpdateSurfaceCacheContentStaticFlag: "
2190 "name[%s] Id[%" PRIu64 "], contentStatic[%d] subTreeDirty[%d] contentDirty[%d] forceUpdate[%d] "
2191 "accessibilityChanged[%d] hasRemovedChild[%d], GetChildrenCount[%d], uifirstContentDirty:%d",
2192 GetName().c_str(), GetId(), contentStatic, IsSubTreeDirty(), IsContentDirty(), GetForceUpdateByUifirst(),
2193 isAccessibilityChanged, HasRemovedChild(), GetChildrenCount(), uifirstContentDirty_);
2194 #endif
2195 }
2196
UpdateSurfaceSubTreeDirtyFlag()2197 void RSSurfaceRenderNode::UpdateSurfaceSubTreeDirtyFlag()
2198 {
2199 #ifdef RS_ENABLE_GPU
2200 auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2201 if (stagingSurfaceParams) {
2202 stagingSurfaceParams->SetSurfaceSubTreeDirty(IsSubTreeDirty());
2203 }
2204 if (stagingRenderParams_->NeedSync()) {
2205 AddToPendingSyncList();
2206 }
2207 #endif
2208 }
2209
UpdateDrawingCacheNodes(const std::shared_ptr<RSRenderNode> & nodePtr)2210 void RSSurfaceRenderNode::UpdateDrawingCacheNodes(const std::shared_ptr<RSRenderNode>& nodePtr)
2211 {
2212 if (nodePtr == nullptr) {
2213 return;
2214 }
2215 drawingCacheNodes_.emplace(nodePtr->GetId(), nodePtr);
2216 }
2217
ResetDrawingCacheStatusIfNodeStatic(std::unordered_map<NodeId,std::unordered_set<NodeId>> & allRects)2218 void RSSurfaceRenderNode::ResetDrawingCacheStatusIfNodeStatic(
2219 std::unordered_map<NodeId, std::unordered_set<NodeId>>& allRects)
2220 {
2221 // traversal drawing cache nodes including app window
2222 EraseIf(drawingCacheNodes_, [this, &allRects](const auto& pair) {
2223 auto node = pair.second.lock();
2224 if (node == nullptr || !node->IsOnTheTree()) {
2225 return true;
2226 }
2227 node->SetDrawingCacheChanged(false);
2228 node->GetFilterRectsInCache(allRects);
2229 return false;
2230 });
2231 }
2232
UpdateFilterCacheStatusWithVisible(bool visible)2233 void RSSurfaceRenderNode::UpdateFilterCacheStatusWithVisible(bool visible)
2234 {
2235 if (visible == prevVisible_) {
2236 return;
2237 }
2238 prevVisible_ = visible;
2239 #if (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
2240 if (!RSUniRenderJudgement::IsUniRender() && !visible && !filterNodes_.empty()
2241 && !isOcclusionVisibleWithoutFilter_) {
2242 for (auto& node : filterNodes_) {
2243 node->GetMutableRenderProperties().ClearFilterCache();
2244 }
2245 }
2246 #endif
2247 }
2248
UpdateFilterCacheStatusIfNodeStatic(const RectI & clipRect,bool isRotationChanged)2249 void RSSurfaceRenderNode::UpdateFilterCacheStatusIfNodeStatic(const RectI& clipRect, bool isRotationChanged)
2250 {
2251 // traversal filter nodes including app window
2252 for (auto node : filterNodes_) {
2253 if (node == nullptr || !node->IsOnTheTree() || !node->GetRenderProperties().NeedFilter()) {
2254 continue;
2255 }
2256 if (node->IsInstanceOf<RSEffectRenderNode>()) {
2257 if (auto effectNode = node->ReinterpretCastTo<RSEffectRenderNode>()) {
2258 effectNode->SetRotationChanged(isRotationChanged);
2259 }
2260 }
2261 if (node->GetRenderProperties().GetBackgroundFilter()) {
2262 node->UpdateFilterCacheWithBelowDirty(Occlusion::Rect(dirtyManager_->GetCurrentFrameDirtyRegion()));
2263 }
2264 if (node->GetRenderProperties().GetFilter()) {
2265 node->UpdateFilterCacheWithBelowDirty(Occlusion::Rect(dirtyManager_->GetCurrentFrameDirtyRegion()));
2266 }
2267 node->UpdateFilterCacheWithSelfDirty();
2268 }
2269 SetFilterCacheFullyCovered(false);
2270 if (IsTransparent() && dirtyManager_->IfCacheableFilterRectFullyCover(GetOldDirtyInSurface())) {
2271 SetFilterCacheFullyCovered(true);
2272 RS_LOGD("UpdateFilterCacheStatusIfNodeStatic surfacenode %{public}" PRIu64 " [%{public}s] rectsize %{public}s",
2273 GetId(), GetName().c_str(), GetOldDirtyInSurface().ToString().c_str());
2274 }
2275 CalcFilterCacheValidForOcclusion();
2276 }
2277
GetWindowCornerRadius()2278 Vector4f RSSurfaceRenderNode::GetWindowCornerRadius()
2279 {
2280 if (!GetRenderProperties().GetCornerRadius().IsZero()) {
2281 return GetRenderProperties().GetCornerRadius();
2282 }
2283 auto parent = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(GetParent().lock());
2284 if (parent != nullptr && parent->IsLeashWindow()) {
2285 return parent->GetRenderProperties().GetCornerRadius();
2286 }
2287 return Vector4f();
2288 }
2289
ResetOpaqueRegion(const RectI & absRect,const ScreenRotation screenRotation,const bool isFocusWindow) const2290 Occlusion::Region RSSurfaceRenderNode::ResetOpaqueRegion(const RectI& absRect,
2291 const ScreenRotation screenRotation, const bool isFocusWindow) const
2292 {
2293 if (isFocusWindow) {
2294 return SetFocusedWindowOpaqueRegion(absRect, screenRotation);
2295 } else {
2296 return SetUnfocusedWindowOpaqueRegion(absRect, screenRotation);
2297 }
2298 }
2299
Update(bool hasContainer,RRect rrect)2300 void RSSurfaceRenderNode::ContainerConfig::Update(bool hasContainer, RRect rrect)
2301 {
2302 this->hasContainerWindow_ = hasContainer;
2303 this->inR_ = RoundFloor(rrect.radius_[0].x_);
2304 this->innerRect_ = {
2305 RoundFloor(rrect.rect_.left_),
2306 RoundFloor(rrect.rect_.top_),
2307 RoundFloor(rrect.rect_.width_),
2308 RoundFloor(rrect.rect_.height_) };
2309 }
2310
SetContainerWindow(bool hasContainerWindow,RRect rrect)2311 void RSSurfaceRenderNode::SetContainerWindow(bool hasContainerWindow, RRect rrect)
2312 {
2313 RS_LOGD("RSSurfaceRenderNode::SetContainerWindow %{public}s %{public}" PRIu64 ", rrect: %{public}s",
2314 GetName().c_str(), GetId(), rrect.ToString().c_str());
2315 containerConfig_.Update(hasContainerWindow, rrect);
2316 }
2317
2318 /*
2319 If a surfacenode with containerwindow is not focus window, then its opaque
2320 region is absRect minus four roundCorner corresponding small rectangles.
2321 This corners removed region can be assembled with two crossed rectangles.
2322 Furthermore, when the surfacenode is not focus window, the inner content roundrect's
2323 boundingbox rect can be set opaque.
2324 */
SetUnfocusedWindowOpaqueRegion(const RectI & absRect,const ScreenRotation screenRotation) const2325 Occlusion::Region RSSurfaceRenderNode::SetUnfocusedWindowOpaqueRegion(const RectI& absRect,
2326 const ScreenRotation screenRotation) const
2327 {
2328 RSSurfaceRenderNode::ContainerConfig config = GetAbsContainerConfig();
2329 Occlusion::Rect opaqueRect1{ absRect.left_ + config.outR_,
2330 absRect.top_,
2331 absRect.GetRight() - config.outR_,
2332 absRect.GetBottom()};
2333 Occlusion::Rect opaqueRect2{ absRect.left_,
2334 absRect.top_ + config.outR_,
2335 absRect.GetRight(),
2336 absRect.GetBottom() - config.outR_};
2337 Occlusion::Region r1{opaqueRect1};
2338 Occlusion::Region r2{opaqueRect2};
2339 Occlusion::Region opaqueRegion = r1.Or(r2);
2340 return opaqueRegion;
2341 }
2342
2343 /*
2344 If a surfacenode with containerwindow is a focused window, then its containerWindow region
2345 should be set transparent, including: title, content padding area, border, and content corners.
2346 Note this region is not centrosymmetric, hence it should be differentiated under different
2347 screen rotation state as top/left/bottom/right has changed when screen rotated.
2348 */
SetFocusedWindowOpaqueRegion(const RectI & absRect,const ScreenRotation screenRotation) const2349 Occlusion::Region RSSurfaceRenderNode::SetFocusedWindowOpaqueRegion(const RectI& absRect,
2350 const ScreenRotation screenRotation) const
2351 {
2352 RSSurfaceRenderNode::ContainerConfig config = GetAbsContainerConfig();
2353 Occlusion::Rect outRect1{ absRect.left_ + config.outR_,
2354 absRect.top_,
2355 absRect.GetRight() - config.outR_,
2356 absRect.GetBottom()};
2357 Occlusion::Rect outRect2{ absRect.left_,
2358 absRect.top_ + config.outR_,
2359 absRect.GetRight(),
2360 absRect.GetBottom() - config.outR_};
2361 Occlusion::Region outRegion1{outRect1};
2362 Occlusion::Region outRegion2{outRect2};
2363 Occlusion::Region absRegion{Occlusion::Rect{absRect}};
2364 Occlusion::Region outRRegion = absRegion.Sub(outRegion1).Sub(outRegion2);
2365 RectI innerRect = config.innerRect_;
2366 Occlusion::Rect opaqueRect1{ innerRect.left_ + config.inR_,
2367 innerRect.top_,
2368 innerRect.GetRight() - config.inR_,
2369 innerRect.GetBottom()};
2370 Occlusion::Rect opaqueRect2{ innerRect.left_,
2371 innerRect.top_ + config.inR_,
2372 innerRect.GetRight(),
2373 innerRect.GetBottom() - config.inR_};
2374 Occlusion::Region r1{opaqueRect1};
2375 Occlusion::Region r2{opaqueRect2};
2376 Occlusion::Region opaqueRegion = r1.Or(r2).Sub(outRRegion);
2377 return opaqueRegion;
2378 }
2379
SetCornerRadiusOpaqueRegion(const RectI & absRect,const Vector4<int> & cornerRadius)2380 void RSSurfaceRenderNode::SetCornerRadiusOpaqueRegion(
2381 const RectI& absRect, const Vector4<int>& cornerRadius)
2382 {
2383 Occlusion::Rect opaqueRect0{ absRect.GetLeft(), absRect.GetTop(),
2384 absRect.GetRight(), absRect.GetBottom()};
2385 Occlusion::Rect opaqueRect1{ absRect.GetLeft(), absRect.GetTop(),
2386 absRect.GetLeft() + cornerRadius.x_, absRect.GetTop() + cornerRadius.x_};
2387 Occlusion::Rect opaqueRect2{ absRect.GetRight() - cornerRadius.y_, absRect.GetTop(),
2388 absRect.GetRight(), absRect.GetTop() + cornerRadius.y_};
2389 Occlusion::Rect opaqueRect3{ absRect.GetRight() - cornerRadius.z_, absRect.GetBottom() - cornerRadius.z_,
2390 absRect.GetRight(), absRect.GetBottom()};
2391 Occlusion::Rect opaqueRect4{ absRect.GetLeft(), absRect.GetBottom() - cornerRadius.w_,
2392 absRect.GetLeft() + cornerRadius.w_, absRect.GetBottom()};
2393
2394 Occlusion::Region r0{opaqueRect0};
2395 Occlusion::Region r1{opaqueRect1};
2396 Occlusion::Region r2{opaqueRect2};
2397 Occlusion::Region r3{opaqueRect3};
2398 Occlusion::Region r4{opaqueRect4};
2399 roundedCornerRegion_ = r1.Or(r2).Or(r3).Or(r4);
2400 opaqueRegion_ = r0.Sub(r1).Sub(r2).Sub(r3).Sub(r4);
2401 }
2402
ResetSurfaceContainerRegion(const RectI & screeninfo,const RectI & absRect,const ScreenRotation screenRotation)2403 void RSSurfaceRenderNode::ResetSurfaceContainerRegion(const RectI& screeninfo, const RectI& absRect,
2404 const ScreenRotation screenRotation)
2405 {
2406 if (!HasContainerWindow()) {
2407 containerRegion_ = Occlusion::Region{};
2408 return;
2409 }
2410 Occlusion::Region absRegion{Occlusion::Rect{absRect}};
2411 Occlusion::Region innerRectRegion = SetFocusedWindowOpaqueRegion(absRect, screenRotation);
2412 containerRegion_ = absRegion.Sub(innerRectRegion);
2413 }
2414
GetAbsContainerConfig() const2415 RSSurfaceRenderNode::ContainerConfig RSSurfaceRenderNode::GetAbsContainerConfig() const
2416 {
2417 auto& geoPtr = GetRenderProperties().GetBoundsGeometry();
2418 RSSurfaceRenderNode::ContainerConfig config;
2419 if (geoPtr) {
2420 auto& matrix = geoPtr->GetAbsMatrix();
2421 Drawing::Rect innerRadiusRect(0, 0, containerConfig_.inR_, containerConfig_.inR_);
2422 matrix.MapRect(innerRadiusRect, innerRadiusRect);
2423 Drawing::Rect outerRadiusRect(0, 0, containerConfig_.outR_, containerConfig_.outR_);
2424 matrix.MapRect(outerRadiusRect, outerRadiusRect);
2425 config.inR_ = static_cast<int>(std::round(std::max(innerRadiusRect.GetWidth(), innerRadiusRect.GetHeight())));
2426 config.outR_ = static_cast<int>(
2427 std::round(std::max(outerRadiusRect.GetWidth(), outerRadiusRect.GetHeight())));
2428 RectF r = {
2429 containerConfig_.innerRect_.left_,
2430 containerConfig_.innerRect_.top_,
2431 containerConfig_.innerRect_.width_,
2432 containerConfig_.innerRect_.height_};
2433 auto rect = geoPtr->MapAbsRect(r).IntersectRect(GetAbsDrawRect());
2434 config.innerRect_ = rect;
2435 return config;
2436 } else {
2437 return config;
2438 }
2439 }
2440
OnSync()2441 void RSSurfaceRenderNode::OnSync()
2442 {
2443 #ifdef RS_ENABLE_GPU
2444 if (!skipFrameDirtyRect_.IsEmpty()) {
2445 dirtyManager_->MergeDirtyRect(skipFrameDirtyRect_);
2446 auto uifirstDirtyRect = dirtyManager_->GetUifirstFrameDirtyRegion();
2447 uifirstDirtyRect = uifirstDirtyRect.JoinRect(skipFrameDirtyRect_);
2448 dirtyManager_->SetUifirstFrameDirtyRect(uifirstDirtyRect);
2449 skipFrameDirtyRect_.Clear();
2450 }
2451 RS_OPTIONAL_TRACE_NAME_FMT("RSSurfaceRenderNode::OnSync name[%s] dirty[%s]",
2452 GetName().c_str(), dirtyManager_->GetCurrentFrameDirtyRegion().ToString().c_str());
2453 if (!renderDrawable_) {
2454 return;
2455 }
2456 auto syncDirtyManager = renderDrawable_->GetSyncDirtyManager();
2457 dirtyManager_->OnSync(syncDirtyManager);
2458 if (IsMainWindowType() || IsLeashWindow() || GetLastFrameUifirstFlag() != MultiThreadCacheType::NONE) {
2459 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2460 if (surfaceParams == nullptr) {
2461 RS_LOGE("RSSurfaceRenderNode::OnSync surfaceParams is null");
2462 return;
2463 }
2464 surfaceParams->SetNeedSync(true);
2465 }
2466 #ifndef ROSEN_CROSS_PLATFORM
2467 renderDrawable_->RegisterDeleteBufferListenerOnSync(GetRSSurfaceHandler()->GetConsumer());
2468 #endif
2469 RSRenderNode::OnSync();
2470 #endif
2471 }
2472
OnSkipSync()2473 void RSSurfaceRenderNode::OnSkipSync()
2474 {
2475 if (!dirtyManager_->GetCurrentFrameDirtyRegion().IsEmpty()) {
2476 auto surfaceDirtyRect = dirtyManager_->GetCurrentFrameDirtyRegion();
2477 skipFrameDirtyRect_ = skipFrameDirtyRect_.JoinRect(surfaceDirtyRect);
2478 }
2479 RSRenderNode::OnSkipSync();
2480 }
2481
CheckIfOcclusionReusable(std::queue<NodeId> & surfaceNodesIds) const2482 bool RSSurfaceRenderNode::CheckIfOcclusionReusable(std::queue<NodeId>& surfaceNodesIds) const
2483 {
2484 if (surfaceNodesIds.empty()) {
2485 return true;
2486 }
2487 auto lastFrameSurfaceNodeId = surfaceNodesIds.front();
2488 surfaceNodesIds.pop();
2489 if (lastFrameSurfaceNodeId != GetId()) {
2490 return true;
2491 }
2492 return false;
2493 }
2494
CheckIfOcclusionChanged() const2495 bool RSSurfaceRenderNode::CheckIfOcclusionChanged() const
2496 {
2497 return GetZorderChanged() || GetDstRectChanged() || IsOpaqueRegionChanged() ||
2498 GetDirtyManager()->IsActiveSurfaceRectChanged();
2499 }
2500
CheckParticipateInOcclusion()2501 bool RSSurfaceRenderNode::CheckParticipateInOcclusion()
2502 {
2503 // planning: Need consider others situation
2504 isParentScaling_ = false;
2505 auto nodeParent = GetParent().lock();
2506 if (nodeParent && nodeParent->IsScale()) {
2507 isParentScaling_ = true;
2508 if (GetDstRectChanged() && !isOcclusionInSpecificScenes_) {
2509 return false;
2510 }
2511 }
2512 if ((IsTransparent() && !NeedDrawBehindWindow()) || GetAnimateState() || IsRotating() || IsSubSurfaceNode()) {
2513 return false;
2514 }
2515 return true;
2516 }
2517
RotateCorner(int rotationDegree,Vector4<int> & cornerRadius) const2518 void RSSurfaceRenderNode::RotateCorner(int rotationDegree, Vector4<int>& cornerRadius) const
2519 {
2520 auto begin = cornerRadius.GetData();
2521 auto end = begin + Vector4<int>::V4SIZE;
2522 switch (rotationDegree) {
2523 case RS_ROTATION_90: {
2524 constexpr int moveTime = 1;
2525 std::rotate(begin, end - moveTime, end);
2526 break;
2527 }
2528 case RS_ROTATION_180: {
2529 constexpr int moveTime = 2;
2530 std::rotate(begin, end - moveTime, end);
2531 break;
2532 }
2533 case RS_ROTATION_270: {
2534 constexpr int moveTime = 3;
2535 std::rotate(begin, end - moveTime, end);
2536 break;
2537 }
2538 default:
2539 break;
2540 }
2541 }
2542
CheckAndUpdateOpaqueRegion(const RectI & screeninfo,const ScreenRotation screenRotation,const bool isFocusWindow)2543 void RSSurfaceRenderNode::CheckAndUpdateOpaqueRegion(const RectI& screeninfo, const ScreenRotation screenRotation,
2544 const bool isFocusWindow)
2545 {
2546 auto absRect = GetInnerAbsDrawRect();
2547 Vector4f tmpCornerRadius;
2548 Vector4f::Max(GetWindowCornerRadius(), GetGlobalCornerRadius(), tmpCornerRadius);
2549 Vector4<int> cornerRadius(static_cast<int>(std::round(tmpCornerRadius.x_)),
2550 static_cast<int>(std::round(tmpCornerRadius.y_)),
2551 static_cast<int>(std::round(tmpCornerRadius.z_)),
2552 static_cast<int>(std::round(tmpCornerRadius.w_)));
2553 auto boundsGeometry = GetRenderProperties().GetBoundsGeometry();
2554 if (boundsGeometry) {
2555 absRect = absRect.IntersectRect(boundsGeometry->GetAbsRect());
2556 auto absChildrenRectF = boundsGeometry->MapRectWithoutRounding(GetChildrenRect().ConvertTo<float>(),
2557 boundsGeometry->GetAbsMatrix());
2558 absRect = absRect.IntersectRect(boundsGeometry->DeflateToRectI(absChildrenRectF));
2559 const auto& absMatrix = boundsGeometry->GetAbsMatrix();
2560 auto rotationDegree = static_cast<int>(-round(atan2(absMatrix.Get(Drawing::Matrix::SKEW_X),
2561 absMatrix.Get(Drawing::Matrix::SCALE_X)) * (RS_ROTATION_180 / PI)));
2562 if (rotationDegree < 0) {
2563 rotationDegree += RS_ROTATION_360;
2564 }
2565 RotateCorner(rotationDegree, cornerRadius);
2566 }
2567
2568 if (!CheckOpaqueRegionBaseInfo(screeninfo, absRect, screenRotation, isFocusWindow, cornerRadius)) {
2569 if (absRect.IsEmpty()) {
2570 RS_LOGD("%{public}s absRect is empty, absDrawRect: %{public}s",
2571 GetName().c_str(), GetAbsDrawRect().ToString().c_str());
2572 RS_TRACE_NAME_FMT("%s absRect is empty, absDrawRect: %s",
2573 GetName().c_str(), GetAbsDrawRect().ToString().c_str());
2574 }
2575 ResetSurfaceOpaqueRegion(screeninfo, absRect, screenRotation, isFocusWindow, cornerRadius);
2576 SetOpaqueRegionBaseInfo(screeninfo, absRect, screenRotation, isFocusWindow, cornerRadius);
2577 }
2578 }
2579
CheckOpaqueRegionBaseInfo(const RectI & screeninfo,const RectI & absRect,const ScreenRotation screenRotation,const bool isFocusWindow,const Vector4<int> & cornerRadius) const2580 bool RSSurfaceRenderNode::CheckOpaqueRegionBaseInfo(const RectI& screeninfo, const RectI& absRect,
2581 const ScreenRotation screenRotation, const bool isFocusWindow, const Vector4<int>& cornerRadius) const
2582 {
2583 // OpaqueRegion should be recalculate under following circumstances.
2584 auto ret =
2585 // 1. Screen information changed, such as screen size, screen rotation, etc.
2586 opaqueRegionBaseInfo_.screenRect_ == screeninfo &&
2587 opaqueRegionBaseInfo_.screenRotation_ == screenRotation &&
2588 // 2. Position and size of surface nodes changed.
2589 opaqueRegionBaseInfo_.absRect_ == absRect &&
2590 opaqueRegionBaseInfo_.oldDirty_ == GetOldDirty() &&
2591 // 3. Focus/Non-focus window switching.
2592 opaqueRegionBaseInfo_.isFocusWindow_ == isFocusWindow &&
2593 // 4. Transparent/Non-trasparent wndow switching.
2594 opaqueRegionBaseInfo_.isTransparent_ == IsTransparent() &&
2595 // 5. Round corner changed.
2596 opaqueRegionBaseInfo_.cornerRadius_ == cornerRadius &&
2597 // 6. Container window changed.
2598 opaqueRegionBaseInfo_.hasContainerWindow_ == HasContainerWindow() &&
2599 opaqueRegionBaseInfo_.containerConfig_ == containerConfig_ &&
2600 // 7. Draw behind window region changed.
2601 opaqueRegionBaseInfo_.needDrawBehindWindow_ == NeedDrawBehindWindow() &&
2602 (NeedDrawBehindWindow() ? opaqueRegionBaseInfo_.absDrawBehindWindowRegion_ == GetFilterRect() : true);
2603 return ret;
2604 }
2605
SetOpaqueRegionBaseInfo(const RectI & screeninfo,const RectI & absRect,const ScreenRotation screenRotation,const bool isFocusWindow,const Vector4<int> & cornerRadius)2606 void RSSurfaceRenderNode::SetOpaqueRegionBaseInfo(const RectI& screeninfo, const RectI& absRect,
2607 const ScreenRotation screenRotation, const bool isFocusWindow, const Vector4<int>& cornerRadius)
2608 {
2609 opaqueRegionBaseInfo_.screenRect_ = screeninfo;
2610 opaqueRegionBaseInfo_.absRect_ = absRect;
2611 opaqueRegionBaseInfo_.oldDirty_ = GetOldDirty();
2612 opaqueRegionBaseInfo_.screenRotation_ = screenRotation;
2613 opaqueRegionBaseInfo_.isFocusWindow_ = isFocusWindow;
2614 opaqueRegionBaseInfo_.cornerRadius_ = cornerRadius;
2615 opaqueRegionBaseInfo_.isTransparent_ = IsTransparent();
2616 opaqueRegionBaseInfo_.hasContainerWindow_ = HasContainerWindow();
2617 opaqueRegionBaseInfo_.containerConfig_ = containerConfig_;
2618 opaqueRegionBaseInfo_.needDrawBehindWindow_ = NeedDrawBehindWindow();
2619 opaqueRegionBaseInfo_.absDrawBehindWindowRegion_ = NeedDrawBehindWindow() ? RectI() : GetFilterRect();
2620 }
2621
2622 // [planning] Remove this after skia is upgraded, the clipRegion is supported
ResetChildrenFilterRects()2623 void RSSurfaceRenderNode::ResetChildrenFilterRects()
2624 {
2625 childrenFilterNodes_.clear();
2626 childrenFilterRects_.clear();
2627 childrenFilterRectsCacheValid_.clear();
2628 }
2629
UpdateChildrenFilterRects(std::shared_ptr<RSRenderNode> filternode,const RectI & rect,bool cacheValid)2630 void RSSurfaceRenderNode::UpdateChildrenFilterRects(std::shared_ptr<RSRenderNode> filternode,
2631 const RectI& rect, bool cacheValid)
2632 {
2633 if (!rect.IsEmpty()) {
2634 childrenFilterNodes_.emplace_back(filternode);
2635 childrenFilterRects_.emplace_back(rect);
2636 childrenFilterRectsCacheValid_.emplace_back(cacheValid);
2637 }
2638 }
2639
GetChildrenNeedFilterRects() const2640 const std::vector<RectI>& RSSurfaceRenderNode::GetChildrenNeedFilterRects() const
2641 {
2642 return childrenFilterRects_;
2643 }
2644
GetChildrenNeedFilterRectsCacheValid() const2645 const std::vector<bool>& RSSurfaceRenderNode::GetChildrenNeedFilterRectsCacheValid() const
2646 {
2647 return childrenFilterRectsCacheValid_;
2648 }
2649
GetChildrenFilterNodes() const2650 const std::vector<std::shared_ptr<RSRenderNode>>& RSSurfaceRenderNode::GetChildrenFilterNodes() const
2651 {
2652 return childrenFilterNodes_;
2653 }
2654
GetChildrenNeedFilterRectsWithoutCacheValid()2655 std::vector<RectI> RSSurfaceRenderNode::GetChildrenNeedFilterRectsWithoutCacheValid()
2656 {
2657 std::vector<RectI> childrenFilterRectsWithoutCacheValid;
2658 auto maxSize = std::min(childrenFilterRects_.size(), childrenFilterRectsCacheValid_.size());
2659 for (size_t i = 0; i < maxSize; i++) {
2660 if (!childrenFilterRectsCacheValid_[i]) {
2661 childrenFilterRectsWithoutCacheValid.emplace_back(childrenFilterRects_[i]);
2662 }
2663 }
2664 return childrenFilterRectsWithoutCacheValid;
2665 };
2666
2667 // manage abilities' nodeid info
UpdateAbilityNodeIds(NodeId id,bool isAdded)2668 void RSSurfaceRenderNode::UpdateAbilityNodeIds(NodeId id, bool isAdded)
2669 {
2670 if (isAdded) {
2671 abilityNodeIds_.emplace(id);
2672 } else {
2673 abilityNodeIds_.erase(id);
2674 }
2675 }
2676
AddAbilityComponentNodeIds(std::unordered_set<NodeId> & nodeIds)2677 void RSSurfaceRenderNode::AddAbilityComponentNodeIds(std::unordered_set<NodeId>& nodeIds)
2678 {
2679 abilityNodeIds_.insert(nodeIds.begin(), nodeIds.end());
2680 }
2681
ResetAbilityNodeIds()2682 void RSSurfaceRenderNode::ResetAbilityNodeIds()
2683 {
2684 abilityNodeIds_.clear();
2685 }
2686
UpdateSurfaceCacheContentStatic()2687 void RSSurfaceRenderNode::UpdateSurfaceCacheContentStatic()
2688 {
2689 dirtyContentNodeNum_ = 0;
2690 dirtyGeoNodeNum_ = 0;
2691 dirtynodeNum_ = 0;
2692 surfaceCacheContentStatic_ = IsOnlyBasicGeoTransform() && !IsCurFrameSwitchToPaint();
2693 }
2694
UpdateSurfaceCacheContentStatic(const std::unordered_map<NodeId,std::weak_ptr<RSRenderNode>> & activeNodeIds)2695 void RSSurfaceRenderNode::UpdateSurfaceCacheContentStatic(
2696 const std::unordered_map<NodeId, std::weak_ptr<RSRenderNode>>& activeNodeIds)
2697 {
2698 dirtyContentNodeNum_ = 0;
2699 dirtyGeoNodeNum_ = 0;
2700 dirtynodeNum_ = activeNodeIds.size();
2701 surfaceCacheContentStatic_ = (IsOnlyBasicGeoTransform() || GetForceUpdateByUifirst()) &&
2702 !IsCurFrameSwitchToPaint();
2703 if (dirtynodeNum_ == 0) {
2704 RS_LOGD("Clear surface %{public}" PRIu64 " dirtynodes surfaceCacheContentStatic_:%{public}d",
2705 GetId(), surfaceCacheContentStatic_);
2706 return;
2707 }
2708 for (auto [id, subNode] : activeNodeIds) {
2709 auto node = subNode.lock();
2710 if (node == nullptr || (id == GetId() && surfaceCacheContentStatic_)) {
2711 continue;
2712 }
2713 // classify active nodes except instance surface itself
2714 if (node->IsContentDirty() && !node->IsNewOnTree() && !node->GetRenderProperties().IsGeoDirty()) {
2715 dirtyContentNodeNum_++;
2716 } else {
2717 dirtyGeoNodeNum_++;
2718 }
2719 }
2720 RS_OPTIONAL_TRACE_NAME_FMT("UpdateSurfaceCacheContentStatic [%s-%lu] contentStatic: %d, dirtyContentNode: %d, "
2721 "dirtyGeoNode: %d", GetName().c_str(), GetId(),
2722 surfaceCacheContentStatic_, dirtyContentNodeNum_, dirtyGeoNodeNum_);
2723 // if mainwindow node only basicGeoTransform and no subnode dirty, it is marked as CacheContentStatic_
2724 surfaceCacheContentStatic_ = surfaceCacheContentStatic_ && dirtyContentNodeNum_ == 0 && dirtyGeoNodeNum_ == 0;
2725 }
2726
AddChildHardwareEnabledNode(std::weak_ptr<RSSurfaceRenderNode> childNode)2727 void RSSurfaceRenderNode::AddChildHardwareEnabledNode(std::weak_ptr<RSSurfaceRenderNode> childNode)
2728 {
2729 childHardwareEnabledNodes_.erase(std::remove_if(childHardwareEnabledNodes_.begin(),
2730 childHardwareEnabledNodes_.end(),
2731 [&childNode](const auto& iter) {
2732 auto node = iter.lock();
2733 auto childNodePtr = childNode.lock();
2734 return node && childNodePtr && node == childNodePtr;
2735 }), childHardwareEnabledNodes_.end());
2736 childHardwareEnabledNodes_.emplace_back(childNode);
2737 }
2738
UpdateChildHardwareEnabledNode(NodeId id,bool isOnTree)2739 void RSSurfaceRenderNode::UpdateChildHardwareEnabledNode(NodeId id, bool isOnTree)
2740 {
2741 if (isOnTree) {
2742 needCollectHwcNode_ = true;
2743 } else {
2744 childHardwareEnabledNodes_.erase(std::remove_if(childHardwareEnabledNodes_.begin(),
2745 childHardwareEnabledNodes_.end(),
2746 [&id](std::weak_ptr<RSSurfaceRenderNode> item) {
2747 std::shared_ptr<RSSurfaceRenderNode> hwcNodePtr = item.lock();
2748 if (!hwcNodePtr) {
2749 return false;
2750 }
2751 return hwcNodePtr->GetId() == id;
2752 }), childHardwareEnabledNodes_.end());
2753 }
2754 }
2755
SetHwcChildrenDisabledState()2756 void RSSurfaceRenderNode::SetHwcChildrenDisabledState()
2757 {
2758 const auto TraverseHwcNodes = [](const auto& hwcNodes) {
2759 for (const auto& hwcNode : hwcNodes) {
2760 auto hwcNodePtr = hwcNode.lock();
2761 if (!hwcNodePtr || hwcNodePtr->IsHardwareForcedDisabled()) {
2762 continue;
2763 }
2764 hwcNodePtr->SetHardwareForcedDisabledState(true);
2765 RS_OPTIONAL_TRACE_NAME_FMT("hwc debug: name:%s id:%" PRIu64 " disabled by parent",
2766 hwcNodePtr->GetName().c_str(), hwcNodePtr->GetId());
2767 }
2768 };
2769 TraverseHwcNodes(GetChildHardwareEnabledNodes());
2770 std::vector<std::pair<NodeId, RSSurfaceRenderNode::WeakPtr>> allSubSurfaceNodes;
2771 GetAllSubSurfaceNodes(allSubSurfaceNodes);
2772 for (const auto& [_, weakNode] : allSubSurfaceNodes) {
2773 if (auto surfaceNode = weakNode.lock(); surfaceNode != nullptr) {
2774 TraverseHwcNodes(surfaceNode->GetChildHardwareEnabledNodes());
2775 }
2776 }
2777 }
2778
SetLocalZOrder(float localZOrder)2779 void RSSurfaceRenderNode::SetLocalZOrder(float localZOrder)
2780 {
2781 localZOrder_ = localZOrder;
2782 }
2783
GetLocalZOrder() const2784 float RSSurfaceRenderNode::GetLocalZOrder() const
2785 {
2786 return localZOrder_;
2787 }
2788
OnApplyModifiers()2789 void RSSurfaceRenderNode::OnApplyModifiers()
2790 {
2791 auto& properties = GetMutableRenderProperties();
2792 auto& geoPtr = (properties.GetBoundsGeometry());
2793
2794 // Multiply context alpha into alpha
2795 properties.SetAlpha(properties.GetAlpha() * contextAlpha_);
2796
2797 // Apply the context matrix into the bounds geometry
2798 geoPtr->SetContextMatrix(contextMatrix_);
2799 if (!ShouldPaint()) {
2800 UpdateFilterCacheStatusWithVisible(false);
2801 }
2802 }
2803
SetTotalMatrix(const Drawing::Matrix & totalMatrix)2804 void RSSurfaceRenderNode::SetTotalMatrix(const Drawing::Matrix& totalMatrix)
2805 {
2806 totalMatrix_ = totalMatrix;
2807 stagingRenderParams_->SetTotalMatrix(totalMatrix);
2808 }
2809
GetContextClipRegion() const2810 std::optional<Drawing::Rect> RSSurfaceRenderNode::GetContextClipRegion() const
2811 {
2812 return contextClipRect_;
2813 }
2814
LeashWindowRelatedAppWindowOccluded(std::vector<std::shared_ptr<RSSurfaceRenderNode>> & appNodes)2815 bool RSSurfaceRenderNode::LeashWindowRelatedAppWindowOccluded(
2816 std::vector<std::shared_ptr<RSSurfaceRenderNode>>& appNodes)
2817 {
2818 if (!IsLeashWindow()) {
2819 return false;
2820 }
2821 for (auto& childNode : *GetChildren()) {
2822 const auto& childNodeSurface = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(childNode);
2823 if (childNodeSurface && childNodeSurface->GetVisibleRegion().IsEmpty()) {
2824 appNodes.emplace_back(childNodeSurface);
2825 } else {
2826 return false;
2827 }
2828 }
2829 return true;
2830 }
2831
GetLeashWindowNestedSurfaces()2832 std::vector<std::shared_ptr<RSSurfaceRenderNode>> RSSurfaceRenderNode::GetLeashWindowNestedSurfaces()
2833 {
2834 std::vector<std::shared_ptr<RSSurfaceRenderNode>> res;
2835 if (!IsLeashWindow()) {
2836 return res;
2837 }
2838 for (auto& childNode : *GetSortedChildren()) {
2839 if (auto childNodeSurface = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(childNode)) {
2840 res.emplace_back(childNodeSurface);
2841 }
2842 }
2843 return res;
2844 }
2845
IsHistoryOccludedDirtyRegionNeedSubmit()2846 bool RSSurfaceRenderNode::IsHistoryOccludedDirtyRegionNeedSubmit()
2847 {
2848 return (hasUnSubmittedOccludedDirtyRegion_ &&
2849 !historyUnSubmittedOccludedDirtyRegion_.IsEmpty() &&
2850 !visibleRegion_.IsEmpty() &&
2851 visibleRegion_.IsIntersectWith(historyUnSubmittedOccludedDirtyRegion_));
2852 }
2853
ClearHistoryUnSubmittedDirtyInfo()2854 void RSSurfaceRenderNode::ClearHistoryUnSubmittedDirtyInfo()
2855 {
2856 hasUnSubmittedOccludedDirtyRegion_ = false;
2857 historyUnSubmittedOccludedDirtyRegion_.Clear();
2858 }
2859
UpdateHistoryUnsubmittedDirtyInfo()2860 void RSSurfaceRenderNode::UpdateHistoryUnsubmittedDirtyInfo()
2861 {
2862 hasUnSubmittedOccludedDirtyRegion_ = true;
2863 historyUnSubmittedOccludedDirtyRegion_ = dirtyManager_->GetCurrentFrameDirtyRegion().JoinRect(
2864 historyUnSubmittedOccludedDirtyRegion_);
2865 }
2866
IsUIFirstSelfDrawCheck()2867 bool RSSurfaceRenderNode::IsUIFirstSelfDrawCheck()
2868 {
2869 if (IsAppWindow()) {
2870 auto hardwareEnabledNodes = GetChildHardwareEnabledNodes();
2871 for (auto& hardwareEnabledNode : hardwareEnabledNodes) {
2872 auto hardwareEnabledNodePtr = hardwareEnabledNode.lock();
2873 if (hardwareEnabledNodePtr && hardwareEnabledNodePtr->surfaceHandler_->IsCurrentFrameBufferConsumed()) {
2874 return false;
2875 }
2876 }
2877 }
2878 if (IsMainWindowType()) {
2879 return true;
2880 } else if (IsLeashWindow()) {
2881 auto nestedSurfaceNodes = GetLeashWindowNestedSurfaces();
2882 // leashwindow subthread cache considered static if and only if all nested surfacenode static
2883 // (include appwindow and starting window)
2884 for (auto& nestedSurface: nestedSurfaceNodes) {
2885 if (nestedSurface && !nestedSurface->IsUIFirstSelfDrawCheck()) {
2886 return false;
2887 }
2888 }
2889 return true;
2890 } else if (IsSelfDrawingType()) {
2891 return !surfaceHandler_->IsCurrentFrameBufferConsumed();
2892 } else {
2893 return false;
2894 }
2895 }
2896
UpdateCacheSurfaceDirtyManager(int bufferAge)2897 void RSSurfaceRenderNode::UpdateCacheSurfaceDirtyManager(int bufferAge)
2898 {
2899 if (!cacheSurfaceDirtyManager_ || !dirtyManager_) {
2900 return;
2901 }
2902 cacheSurfaceDirtyManager_->Clear();
2903 cacheSurfaceDirtyManager_->MergeDirtyRect(dirtyManager_->GetLatestDirtyRegion());
2904 cacheSurfaceDirtyManager_->SetBufferAge(bufferAge);
2905 cacheSurfaceDirtyManager_->UpdateDirty(false);
2906 // for leashwindow type, nested app surfacenode's cacheSurfaceDirtyManager update is required
2907 auto nestedSurfaceNodes = GetLeashWindowNestedSurfaces();
2908 for (auto& nestedSurface : nestedSurfaceNodes) {
2909 if (nestedSurface) {
2910 nestedSurface->UpdateCacheSurfaceDirtyManager(bufferAge);
2911 }
2912 }
2913 }
2914
SetIsOnTheTree(bool onTree,NodeId instanceRootNodeId,NodeId firstLevelNodeId,NodeId cacheNodeId,NodeId uifirstRootNodeId,NodeId screenNodeId,NodeId logicalDisplayNodeId)2915 void RSSurfaceRenderNode::SetIsOnTheTree(bool onTree, NodeId instanceRootNodeId, NodeId firstLevelNodeId,
2916 NodeId cacheNodeId, NodeId uifirstRootNodeId, NodeId screenNodeId, NodeId logicalDisplayNodeId)
2917 {
2918 #ifdef RS_MEMORY_INFO_MANAGER
2919 RSMemoryInfoManager::SetSurfaceMemoryInfo(onTree, GetRSSurfaceHandler());
2920 #endif
2921 if (GetSurfaceNodeType() == RSSurfaceNodeType::CURSOR_NODE) {
2922 std::string uniqueIdStr = "null";
2923 #ifndef ROSEN_CROSS_PLATFORM
2924 uniqueIdStr = GetRSSurfaceHandler() != nullptr && GetRSSurfaceHandler()->GetConsumer() != nullptr ?
2925 std::to_string(GetRSSurfaceHandler()->GetConsumer()->GetUniqueId()) : "null";
2926 #endif
2927 RS_LOGI("RSSurfaceRenderNode:SetIsOnTheTree, node:[name: %{public}s, id: %{public}" PRIu64 "], "
2928 "on tree: %{public}d, nodeType: %{public}d, uniqueId: %{public}s, screenNodeId: %{public}" PRIu64,
2929 GetName().c_str(), GetId(), onTree, static_cast<int>(nodeType_), uniqueIdStr.c_str(), screenNodeId);
2930 }
2931 #ifdef ENABLE_FULL_SCREEN_RECONGNIZE
2932 UpdateSurfaceNodeTreeStatusForAps(onTree);
2933 #endif
2934 RS_TRACE_NAME_FMT("RSSurfaceRenderNode:SetIsOnTheTree, node:[name: %s, id: %" PRIu64 "], "
2935 "on tree: %d, nodeType: %d", GetName().c_str(), GetId(), onTree, static_cast<int>(nodeType_));
2936 instanceRootNodeId = IsLeashOrMainWindow() ? GetId() : instanceRootNodeId;
2937 if (IsLeashWindow()) {
2938 firstLevelNodeId = GetId();
2939 } else if (IsAppWindow()) {
2940 firstLevelNodeId = GetId();
2941 auto parentNode = GetParent().lock();
2942 if (parentNode && parentNode->GetFirstLevelNodeId() != INVALID_NODEID) {
2943 firstLevelNodeId = parentNode->GetFirstLevelNodeId();
2944 }
2945 }
2946 if (IsSecureUIExtension() || IsUnobscuredUIExtensionNode()) {
2947 if (onTree) {
2948 secUIExtensionNodes_.insert(std::pair<NodeId, NodeId>(GetId(), instanceRootNodeId));
2949 } else {
2950 secUIExtensionNodes_.erase(GetId());
2951 }
2952 if (auto parent = GetParent().lock()) {
2953 parent->SetChildrenHasUIExtension(onTree);
2954 }
2955 }
2956 auto &monitor = SelfDrawingNodeMonitor::GetInstance();
2957 if (monitor.IsListeningEnabled() && IsSelfDrawingType()) {
2958 if (onTree) {
2959 auto rect = GetRenderProperties().GetBoundsGeometry()->GetAbsRect();
2960 monitor.InsertCurRectMap(GetId(), rect);
2961 } else {
2962 monitor.EraseCurRectMap(GetId());
2963 }
2964 }
2965 // if node is marked as cacheRoot, update subtree status when update surface
2966 // in case prepare stage upper cacheRoot cannot specify dirty subnode
2967 RSBaseRenderNode::SetIsOnTheTree(onTree, instanceRootNodeId, firstLevelNodeId, cacheNodeId,
2968 INVALID_NODEID, screenNodeId, logicalDisplayNodeId);
2969 }
2970
2971 #ifdef ENABLE_FULL_SCREEN_RECONGNIZE
UpdateSurfaceNodeTreeStatusForAps(bool onTree)2972 void RSSurfaceRenderNode::UpdateSurfaceNodeTreeStatusForAps(bool onTree)
2973 {
2974 if (nodeType_ == RSSurfaceNodeType::SELF_DRAWING_NODE) {
2975 ApsMonitorImpl::GetInstance().SetApsSurfaceNodeTreeChange(onTree, name_);
2976 if (!onTree) {
2977 ApsMonitorImpl::GetInstance().SetApsSurfaceDestroyedInfo(std::to_string(GetId()));
2978 prevSelfDrawHeight_ = 0.0f;
2979 prevSelfDrawWidth_ = 0.0f;
2980 }
2981 }
2982 }
2983
SendSurfaceNodeBoundChange()2984 void RSSurfaceRenderNode::SendSurfaceNodeBoundChange()
2985 {
2986 if (nodeType_ == RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE && prevSelfDrawHeight_ != properties.GetBoundHeight()
2987 && prevSelfDrawWidth_ != properties.GetBoundsWidth()) {
2988 prevSelfDrawHeight_ = properties.GetBoundHeight();
2989 prevSelfDrawWidth_ = properties.GetBoundsWidth();
2990 std::shared_ptr<ApsMonitorImpl> apsMonitor_ = std::make_shared<ApsMonitorImpl>();
2991 apsMonitor_->SetApsSurfaceBoundChange(std::to_string(prevSelfDrawHeight_), std::to_string(prevSelfDrawWidth_),
2992 std::to_string((uint64_t)GetId()));
2993 }
2994 }
2995 #endif
2996
SetUIExtensionUnobscured(bool obscured)2997 void RSSurfaceRenderNode::SetUIExtensionUnobscured(bool obscured)
2998 {
2999 UIExtensionUnobscured_ = obscured;
3000 }
3001
SetCacheSurfaceProcessedStatus(CacheProcessStatus cacheProcessStatus)3002 void RSSurfaceRenderNode::SetCacheSurfaceProcessedStatus(CacheProcessStatus cacheProcessStatus)
3003 {
3004 cacheProcessStatus_.store(cacheProcessStatus);
3005 }
3006
HasOnlyOneRootNode() const3007 bool RSSurfaceRenderNode::HasOnlyOneRootNode() const
3008 {
3009 if (GetChildrenCount() != 1) {
3010 return false;
3011 }
3012
3013 const auto child = GetFirstChild();
3014 if (!child || child->GetType() != RSRenderNodeType::ROOT_NODE || child->GetChildrenCount() > 0) {
3015 return false;
3016 }
3017
3018 return true;
3019 }
3020
GetNodeIsSingleFrameComposer() const3021 bool RSSurfaceRenderNode::GetNodeIsSingleFrameComposer() const
3022 {
3023 bool flag = false;
3024 if (RSSystemProperties::GetSingleFrameComposerCanvasNodeEnabled()) {
3025 auto idx = GetName().find("hwstylusfeature");
3026 if (idx != std::string::npos) {
3027 flag = true;
3028 }
3029 }
3030 return isNodeSingleFrameComposer_ || flag;
3031 }
3032
QuerySubAssignable(bool isRotation)3033 bool RSSurfaceRenderNode::QuerySubAssignable(bool isRotation)
3034 {
3035 if (!IsFirstLevelNode()) {
3036 return false;
3037 }
3038 UpdateTransparentSurface();
3039 RS_TRACE_NAME_FMT("SubThreadAssignable node[%lld] hasTransparent: %d, childHasVisibleFilter: %d, "
3040 "hasFilter: %d, isRotation: %d & %d globalAlpha[%f], hasProtectedLayer: %d", GetId(), hasTransparentSurface_,
3041 ChildHasVisibleFilter(), HasFilter(), isRotation, RSSystemProperties::GetCacheOptimizeRotateEnable(),
3042 GetGlobalAlpha(), GetSpecialLayerMgr().Find(SpecialLayerType::HAS_PROTECTED));
3043 bool rotateOptimize = RSSystemProperties::GetCacheOptimizeRotateEnable() ?
3044 !(isRotation && ROSEN_EQ(GetGlobalAlpha(), 0.0f)) : !isRotation;
3045 return !(hasTransparentSurface_ && ChildHasVisibleFilter()) && !HasFilter() && rotateOptimize &&
3046 !GetSpecialLayerMgr().Find(SpecialLayerType::HAS_PROTECTED);
3047 }
3048
UpdateTransparentSurface()3049 void RSSurfaceRenderNode::UpdateTransparentSurface()
3050 {
3051 hasTransparentSurface_ = IsTransparent();
3052 if (IsLeashWindow() && !hasTransparentSurface_) {
3053 for (auto &child : *GetSortedChildren()) {
3054 auto childSurfaceNode = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(child);
3055 if (childSurfaceNode && childSurfaceNode->IsTransparent()) {
3056 hasTransparentSurface_ = true;
3057 break;
3058 }
3059 }
3060 }
3061 }
3062
GetHasTransparentSurface() const3063 bool RSSurfaceRenderNode::GetHasTransparentSurface() const
3064 {
3065 return hasTransparentSurface_;
3066 }
3067
SetHasSharedTransitionNode(bool hasSharedTransitionNode)3068 void RSSurfaceRenderNode::SetHasSharedTransitionNode(bool hasSharedTransitionNode)
3069 {
3070 hasSharedTransitionNode_ = hasSharedTransitionNode;
3071 }
3072
GetGravityTranslate(float imgWidth,float imgHeight)3073 Vector2f RSSurfaceRenderNode::GetGravityTranslate(float imgWidth, float imgHeight)
3074 {
3075 Gravity gravity = GetRenderProperties().GetFrameGravity();
3076 if (IsLeashWindow()) {
3077 for (auto child : *GetSortedChildren()) {
3078 auto childSurfaceNode = child ? child->ReinterpretCastTo<RSSurfaceRenderNode>() : nullptr;
3079 if (childSurfaceNode) {
3080 gravity = childSurfaceNode->GetRenderProperties().GetFrameGravity();
3081 break;
3082 }
3083 }
3084 }
3085
3086 float boundsWidth = GetRenderProperties().GetBoundsWidth();
3087 float boundsHeight = GetRenderProperties().GetBoundsHeight();
3088 Drawing::Matrix gravityMatrix;
3089 RSPropertiesPainter::GetGravityMatrix(gravity, RectF {0.0f, 0.0f, boundsWidth, boundsHeight},
3090 imgWidth, imgHeight, gravityMatrix);
3091 return {gravityMatrix.Get(Drawing::Matrix::TRANS_X), gravityMatrix.Get(Drawing::Matrix::TRANS_Y)};
3092 }
3093
UpdateUIFirstFrameGravity()3094 void RSSurfaceRenderNode::UpdateUIFirstFrameGravity()
3095 {
3096 #ifdef RS_ENABLE_GPU
3097 Gravity gravity = GetRenderProperties().GetFrameGravity();
3098 if (IsLeashWindow()) {
3099 std::vector<Gravity> subGravity{};
3100 for (const auto& child : *GetSortedChildren()) {
3101 auto childSurfaceNode = child ? child->ReinterpretCastTo<RSSurfaceRenderNode>() : nullptr;
3102 if (childSurfaceNode) {
3103 subGravity.push_back(childSurfaceNode->GetRenderProperties().GetFrameGravity());
3104 }
3105 }
3106 // planning: how to handle gravity while leashwindow has multiple subAppWindows is not clear yet
3107 if (subGravity.size() == 1) {
3108 gravity = subGravity.front();
3109 }
3110 }
3111 auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3112 if (!stagingSurfaceParams) {
3113 RS_LOGE("RSSurfaceRenderNode::UpdateUIFirstFrameGravity staingSurfaceParams is null");
3114 return;
3115 }
3116 stagingSurfaceParams->SetUIFirstFrameGravity(gravity);
3117 AddToPendingSyncList();
3118 #endif
3119 }
3120
SetOcclusionVisible(bool visible)3121 void RSSurfaceRenderNode::SetOcclusionVisible(bool visible)
3122 {
3123 #ifdef RS_ENABLE_GPU
3124 auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3125 if (stagingSurfaceParams) {
3126 stagingSurfaceParams->SetOcclusionVisible(visible);
3127 AddToPendingSyncList();
3128 } else {
3129 RS_LOGE("RSSurfaceRenderNode::SetOcclusionVisible stagingSurfaceParams is null");
3130 }
3131
3132 isOcclusionVisible_ = visible;
3133 #endif
3134 }
3135
UpdatePartialRenderParams()3136 void RSSurfaceRenderNode::UpdatePartialRenderParams()
3137 {
3138 #ifdef RS_ENABLE_GPU
3139 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3140 if (surfaceParams == nullptr) {
3141 RS_LOGE("RSSurfaceRenderNode::UpdatePartialRenderParams surfaceParams is null");
3142 return;
3143 }
3144 if (IsMainWindowType()) {
3145 surfaceParams->SetVisibleRegionInVirtual(visibleRegionInVirtual_);
3146 surfaceParams->SetIsParentScaling(isParentScaling_);
3147 }
3148 surfaceParams->SetAbsDrawRect(GetAbsDrawRect());
3149 surfaceParams->SetOldDirtyInSurface(GetOldDirtyInSurface());
3150 surfaceParams->SetTransparentRegion(GetTransparentRegion());
3151 surfaceParams->SetOpaqueRegion(GetOpaqueRegion());
3152 surfaceParams->SetRoundedCornerRegion(GetRoundedCornerRegion());
3153 surfaceParams->SetFirstLevelCrossNode(IsFirstLevelCrossNode());
3154 #endif
3155 }
3156
UpdateExtendVisibleRegion(Occlusion::Region & region)3157 void RSSurfaceRenderNode::UpdateExtendVisibleRegion(Occlusion::Region& region)
3158 {
3159 #ifdef RS_ENABLE_GPU
3160 extendVisibleRegion_.Reset();
3161 extendVisibleRegion_ = region.Or(visibleRegion_);
3162 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3163 if (surfaceParams == nullptr) {
3164 RS_LOGE("RSSurfaceRenderNode::UpdateExtendVisibleRegion surfaceParams is nullptr");
3165 return;
3166 }
3167 surfaceParams->SetVisibleRegion(extendVisibleRegion_);
3168 #endif
3169 }
3170
InitRenderParams()3171 void RSSurfaceRenderNode::InitRenderParams()
3172 {
3173 #ifdef RS_ENABLE_GPU
3174 stagingRenderParams_ = std::make_unique<RSSurfaceRenderParams>(GetId());
3175 DrawableV2::RSRenderNodeDrawableAdapter::OnGenerate(shared_from_this());
3176 if (renderDrawable_ == nullptr) {
3177 RS_LOGE("RSSurfaceRenderNode::InitRenderParams failed");
3178 return;
3179 }
3180 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3181 if (surfaceParams == nullptr) {
3182 RS_LOGE("RSSurfaceRenderNode::InitRenderParams surfaceParams is null");
3183 return;
3184 }
3185 surfaceParams->SetIsUnobscuredUEC(IsUnobscuredUIExtensionNode());
3186 #endif
3187 }
3188
UpdateRenderParams()3189 void RSSurfaceRenderNode::UpdateRenderParams()
3190 {
3191 #ifdef RS_ENABLE_GPU
3192 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3193 if (surfaceParams == nullptr) {
3194 RS_LOGE("RSSurfaceRenderNode::UpdateRenderParams surfaceParams is null");
3195 return;
3196 }
3197 auto& properties = GetRenderProperties();
3198 #ifndef ROSEN_CROSS_PLATFORM
3199 if (surfaceHandler_ && surfaceHandler_->GetConsumer()) {
3200 UpdatePropertyFromConsumer();
3201 }
3202 #endif
3203 surfaceParams->alpha_ = properties.GetAlpha();
3204 surfaceParams->isClonedNodeOnTheTree_ = isClonedNodeOnTheTree_;
3205 surfaceParams->isCrossNode_ = IsCrossNode();
3206 surfaceParams->isSpherizeValid_ = properties.IsSpherizeValid();
3207 surfaceParams->isAttractionValid_ = properties.IsAttractionValid();
3208 surfaceParams->isAttractionAnimation_ = isAttractionAnimation_;
3209 surfaceParams->rsSurfaceNodeType_ = GetSurfaceNodeType();
3210 surfaceParams->backgroundColor_ = properties.GetBackgroundColor();
3211 surfaceParams->rrect_ = properties.GetRRect();
3212 surfaceParams->selfDrawingType_ = GetSelfDrawingNodeType();
3213 surfaceParams->stencilVal_ = stencilVal_;
3214 surfaceParams->needBilinearInterpolation_ = NeedBilinearInterpolation();
3215 surfaceParams->SetWindowInfo(IsMainWindowType(), IsLeashWindow(), IsAppWindow());
3216 surfaceParams->isCloneNode_ = isCloneNode_;
3217 surfaceParams->SetAncestorScreenNode(ancestorScreenNode_);
3218 surfaceParams->specialLayerManager_ = specialLayerManager_;
3219 surfaceParams->blackListIds_ = blackListIds_;
3220 surfaceParams->animateState_ = animateState_;
3221 surfaceParams->isRotating_ = isRotating_;
3222 surfaceParams->privacyContentLayerIds_ = privacyContentLayerIds_;
3223 surfaceParams->name_= name_;
3224 surfaceParams->bundleName_= bundleName_;
3225 surfaceParams->positionZ_ = properties.GetPositionZ();
3226 surfaceParams->SetVisibleRegion(visibleRegion_);
3227 surfaceParams->SetOldDirtyInSurface(GetOldDirtyInSurface());
3228 surfaceParams->dstRect_ = dstRect_;
3229 surfaceParams->overDrawBufferNodeCornerRadius_ = GetOverDrawBufferNodeCornerRadius();
3230 surfaceParams->isGpuOverDrawBufferOptimizeNode_ = isGpuOverDrawBufferOptimizeNode_;
3231 surfaceParams->SetSkipDraw(isSkipDraw_);
3232 surfaceParams->SetHidePrivacyContent(needHidePrivacyContent_);
3233 surfaceParams->visibleFilterChild_ = GetVisibleFilterChild();
3234 surfaceParams->isTransparent_ = IsTransparent();
3235 surfaceParams->leashPersistentId_ = leashPersistentId_;
3236 surfaceParams->hasSubSurfaceNodes_ = HasSubSurfaceNodes();
3237 surfaceParams->allSubSurfaceNodeIds_ = GetAllSubSurfaceNodeIds();
3238 surfaceParams->crossNodeSkipDisplayConversionMatrices_ = crossNodeSkipDisplayConversionMatrices_;
3239 surfaceParams->regionToBeMagnified_ = regionToBeMagnified_;
3240 if (occlusionParams_ != nullptr && occlusionParams_->IsOcclusionCullingOn()) {
3241 surfaceParams->isOcclusionCullingOn_ = true;
3242 surfaceParams->culledNodes_ = occlusionParams_->TakeCulledNodes();
3243 surfaceParams->culledEntireSubtree_ = occlusionParams_->TakeCulledEntireSubtree();
3244 } else {
3245 surfaceParams->isOcclusionCullingOn_ = false;
3246 surfaceParams->culledNodes_.clear();
3247 surfaceParams->culledEntireSubtree_.clear();
3248 }
3249 surfaceParams->SetNeedSync(true);
3250
3251 RSRenderNode::UpdateRenderParams();
3252 #endif
3253 }
3254
3255 #ifndef ROSEN_CROSS_PLATFORM
UpdatePropertyFromConsumer()3256 void RSSurfaceRenderNode::UpdatePropertyFromConsumer()
3257 {
3258 auto consumer = surfaceHandler_->GetConsumer();
3259 int32_t gravity = -1;
3260 consumer->GetFrameGravity(gravity);
3261 if (gravity >= 0) {
3262 GetMutableRenderProperties().SetFrameGravity(static_cast<Gravity>(gravity));
3263 RS_LOGD("RSSurfaceRenderNode, update frame gravity to = %{public}d", gravity);
3264 }
3265
3266 int32_t fixed = -1;
3267 consumer->GetFixedRotation(fixed);
3268 if (fixed >= 0) {
3269 bool fixedRotation = (fixed == 1);
3270 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3271 surfaceParams->SetFixRotationByUser(fixedRotation);
3272 isFixRotationByUser_ = fixedRotation;
3273 RS_LOGD("RSSurfaceRenderNode, update fixed rotation to = %{public}d", fixedRotation);
3274 }
3275 }
3276 #endif
3277
SetNeedOffscreen(bool needOffscreen)3278 void RSSurfaceRenderNode::SetNeedOffscreen(bool needOffscreen)
3279 {
3280 #ifdef RS_ENABLE_GPU
3281 auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3282 if (stagingSurfaceParams) {
3283 stagingSurfaceParams->SetNeedOffscreen(needOffscreen);
3284 stagingSurfaceParams->SetFingerprint(GetFingerprint());
3285 AddToPendingSyncList();
3286 } else {
3287 RS_LOGE("RSSurfaceRenderNode::SetNeedOffscreen stagingSurfaceParams is null");
3288 }
3289 #endif
3290 }
3291
SetClonedNodeRenderDrawable(DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr clonedNodeRenderDrawable)3292 void RSSurfaceRenderNode::SetClonedNodeRenderDrawable(
3293 DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr clonedNodeRenderDrawable)
3294 {
3295 auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3296 if (stagingSurfaceParams == nullptr) {
3297 RS_LOGE("RSSurfaceRenderNode::SetClonedNodeRenderDrawable stagingSurfaceParams is null");
3298 return;
3299 }
3300 stagingSurfaceParams->clonedNodeRenderDrawable_ = clonedNodeRenderDrawable;
3301 AddToPendingSyncList();
3302 }
3303
SetSourceDisplayRenderNodeDrawable(DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr drawable)3304 void RSSurfaceRenderNode::SetSourceDisplayRenderNodeDrawable(
3305 DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr drawable)
3306 {
3307 auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3308 if (stagingSurfaceParams == nullptr) {
3309 RS_LOGE("RSSurfaceRenderNode::SetSourceDisplayRenderNodeDrawable stagingSurfaceParams is null");
3310 return;
3311 }
3312 // CacheImg does not support UIFirst, clost UIFirst
3313 SetUIFirstSwitch(RSUIFirstSwitch::FORCE_DISABLE);
3314 stagingSurfaceParams->sourceDisplayRenderNodeDrawable_ = drawable;
3315 AddToPendingSyncList();
3316 }
3317
UpdateAncestorScreenNodeInRenderParams()3318 void RSSurfaceRenderNode::UpdateAncestorScreenNodeInRenderParams()
3319 {
3320 #ifdef RS_ENABLE_GPU
3321 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3322 if (surfaceParams == nullptr) {
3323 RS_LOGE("RSSurfaceRenderNode::UpdateAncestorScreenNodeInRenderParams surfaceParams is null");
3324 return;
3325 }
3326 surfaceParams->SetAncestorScreenNode(ancestorScreenNode_);
3327 surfaceParams->SetNeedSync(true);
3328 #endif
3329 }
3330
SetUifirstChildrenDirtyRectParam(RectI rect)3331 void RSSurfaceRenderNode::SetUifirstChildrenDirtyRectParam(RectI rect)
3332 {
3333 #ifdef RS_ENABLE_GPU
3334 auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3335 if (stagingSurfaceParams) {
3336 stagingSurfaceParams->SetUifirstChildrenDirtyRectParam(rect);
3337 AddToPendingSyncList();
3338 }
3339 #endif
3340 }
3341
SetUifirstNodeEnableParam(MultiThreadCacheType b)3342 bool RSSurfaceRenderNode::SetUifirstNodeEnableParam(MultiThreadCacheType b)
3343 {
3344 bool ret = false;
3345 #ifdef RS_ENABLE_GPU
3346 auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3347 if (stagingSurfaceParams) {
3348 ret = stagingSurfaceParams->SetUifirstNodeEnableParam(b);
3349 AddToPendingSyncList();
3350 }
3351 #endif
3352 return ret;
3353 }
3354
SetIsParentUifirstNodeEnableParam(bool b)3355 void RSSurfaceRenderNode::SetIsParentUifirstNodeEnableParam(bool b)
3356 {
3357 #ifdef RS_ENABLE_GPU
3358 auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3359 if (stagingSurfaceParams) {
3360 stagingSurfaceParams->SetIsParentUifirstNodeEnableParam(b);
3361 AddToPendingSyncList();
3362 }
3363 #endif
3364 }
3365
SetUifirstUseStarting(NodeId id)3366 void RSSurfaceRenderNode::SetUifirstUseStarting(NodeId id)
3367 {
3368 #ifdef RS_ENABLE_GPU
3369 auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3370 if (stagingSurfaceParams) {
3371 stagingSurfaceParams->SetUifirstUseStarting(id);
3372 AddToPendingSyncList();
3373 }
3374 #endif
3375 }
3376
SetCornerRadiusInfoForDRM(const std::vector<float> & drmCornerRadiusInfo)3377 void RSSurfaceRenderNode::SetCornerRadiusInfoForDRM(const std::vector<float>& drmCornerRadiusInfo)
3378 {
3379 #ifdef RS_ENABLE_GPU
3380 if (drmCornerRadiusInfo_ != drmCornerRadiusInfo) {
3381 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3382 if (surfaceParams) {
3383 surfaceParams->SetCornerRadiusInfoForDRM(drmCornerRadiusInfo);
3384 drmCornerRadiusInfo_ = drmCornerRadiusInfo;
3385 }
3386 AddToPendingSyncList();
3387 }
3388 #endif
3389 }
3390
SetForceDisableClipHoleForDRM(bool isForceDisable)3391 void RSSurfaceRenderNode::SetForceDisableClipHoleForDRM(bool isForceDisable)
3392 {
3393 auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3394 if (stagingSurfaceParams == nullptr) {
3395 return;
3396 }
3397 stagingSurfaceParams->SetForceDisableClipHoleForDRM(isForceDisable);
3398 if (stagingRenderParams_->NeedSync()) {
3399 AddToPendingSyncList();
3400 }
3401 }
3402
SetSkipDraw(bool skip)3403 void RSSurfaceRenderNode::SetSkipDraw(bool skip)
3404 {
3405 isSkipDraw_ = skip;
3406 SetDirty();
3407 }
3408
GetSkipDraw() const3409 bool RSSurfaceRenderNode::GetSkipDraw() const
3410 {
3411 return isSkipDraw_;
3412 }
3413
GetSecUIExtensionNodes()3414 const std::unordered_map<NodeId, NodeId>& RSSurfaceRenderNode::GetSecUIExtensionNodes()
3415 {
3416 return secUIExtensionNodes_;
3417 }
3418
GetWatermark() const3419 const std::unordered_map<std::string, bool>& RSSurfaceRenderNode::GetWatermark() const
3420 {
3421 return watermarkHandles_;
3422 }
3423
IsWatermarkEmpty() const3424 bool RSSurfaceRenderNode::IsWatermarkEmpty() const
3425 {
3426 return watermarkHandles_.empty();
3427 }
3428
SetSdrNit(float sdrNit)3429 void RSSurfaceRenderNode::SetSdrNit(float sdrNit)
3430 {
3431 #ifdef RS_ENABLE_GPU
3432 auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3433 if (stagingSurfaceParams) {
3434 stagingSurfaceParams->SetSdrNit(sdrNit);
3435 }
3436 if (stagingRenderParams_->NeedSync()) {
3437 AddToPendingSyncList();
3438 }
3439 #endif
3440 }
3441
SetDisplayNit(float displayNit)3442 void RSSurfaceRenderNode::SetDisplayNit(float displayNit)
3443 {
3444 #ifdef RS_ENABLE_GPU
3445 auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3446 if (stagingSurfaceParams) {
3447 stagingSurfaceParams->SetDisplayNit(displayNit);
3448 }
3449 if (stagingRenderParams_->NeedSync()) {
3450 AddToPendingSyncList();
3451 }
3452 #endif
3453 }
3454
SetColorFollow(bool colorFollow)3455 void RSSurfaceRenderNode::SetColorFollow(bool colorFollow)
3456 {
3457 #ifdef RS_ENABLE_GPU
3458 auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3459 if (stagingSurfaceParams) {
3460 stagingSurfaceParams->SetColorFollow(colorFollow);
3461 }
3462 if (stagingRenderParams_->NeedSync()) {
3463 AddToPendingSyncList();
3464 }
3465 #endif
3466 }
3467
SetBrightnessRatio(float brightnessRatio)3468 void RSSurfaceRenderNode::SetBrightnessRatio(float brightnessRatio)
3469 {
3470 #ifdef RS_ENABLE_GPU
3471 auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3472 if (stagingSurfaceParams) {
3473 stagingSurfaceParams->SetBrightnessRatio(brightnessRatio);
3474 }
3475 if (stagingRenderParams_->NeedSync()) {
3476 AddToPendingSyncList();
3477 }
3478 #endif
3479 }
3480
SetLayerLinearMatrix(const std::vector<float> & layerLinearMatrix)3481 void RSSurfaceRenderNode::SetLayerLinearMatrix(const std::vector<float>& layerLinearMatrix)
3482 {
3483 #ifdef RS_ENABLE_GPU
3484 auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3485 if (stagingSurfaceParams) {
3486 stagingSurfaceParams->SetLayerLinearMatrix(layerLinearMatrix);
3487 }
3488 if (stagingRenderParams_->NeedSync()) {
3489 AddToPendingSyncList();
3490 }
3491 #endif
3492 }
3493
SetSdrHasMetadata(bool hasMetadata)3494 void RSSurfaceRenderNode::SetSdrHasMetadata(bool hasMetadata)
3495 {
3496 #ifdef RS_ENABLE_GPU
3497 auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3498 if (stagingSurfaceParams) {
3499 stagingSurfaceParams->SetSdrHasMetadata(hasMetadata);
3500 }
3501 if (stagingRenderParams_->NeedSync()) {
3502 AddToPendingSyncList();
3503 }
3504 #endif
3505 }
3506
GetSdrHasMetadata() const3507 bool RSSurfaceRenderNode::GetSdrHasMetadata() const
3508 {
3509 #ifdef RS_ENABLE_GPU
3510 auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3511 return stagingSurfaceParams ? stagingSurfaceParams->GetSdrHasMetadata() : false;
3512 #else
3513 return false;
3514 #endif
3515 }
3516
SetWatermarkEnabled(const std::string & name,bool isEnabled)3517 void RSSurfaceRenderNode::SetWatermarkEnabled(const std::string& name, bool isEnabled)
3518 {
3519 if (isEnabled) {
3520 RS_LOGI("RSSurfaceRenderNode::SetWatermarkEnabled[%{public}d], Name:%{public}s", isEnabled, name.c_str());
3521 }
3522 #ifdef RS_ENABLE_GPU
3523 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3524 if (surfaceParams) {
3525 surfaceParams->SetWatermarkEnabled(name, isEnabled);
3526 }
3527 #endif
3528 AddToPendingSyncList();
3529 }
3530
SetAbilityState(RSSurfaceNodeAbilityState abilityState)3531 void RSSurfaceRenderNode::SetAbilityState(RSSurfaceNodeAbilityState abilityState)
3532 {
3533 if (abilityState_ == abilityState) {
3534 ROSEN_LOGD("RSSurfaceRenderNode::SetAbilityState, surfaceNodeId:[%{public}" PRIu64 "], "
3535 "ability state same with before: %{public}s",
3536 GetId(), abilityState == RSSurfaceNodeAbilityState::FOREGROUND ? "foreground" : "background");
3537 return;
3538 }
3539
3540 abilityState_ = abilityState;
3541 ROSEN_LOGI("RSSurfaceRenderNode::SetAbilityState, surfaceNodeId:[%{public}" PRIu64 "] ability state: %{public}s",
3542 GetId(), abilityState_ == RSSurfaceNodeAbilityState::FOREGROUND ? "foreground" : "background");
3543 }
3544
GetAbilityState() const3545 RSSurfaceNodeAbilityState RSSurfaceRenderNode::GetAbilityState() const
3546 {
3547 return abilityState_;
3548 }
3549
IsWaitUifirstFirstFrame() const3550 bool RSSurfaceRenderNode::IsWaitUifirstFirstFrame() const
3551 {
3552 return isWaitUifirstFirstFrame_;
3553 }
3554
SetWaitUifirstFirstFrame(bool wait)3555 void RSSurfaceRenderNode::SetWaitUifirstFirstFrame(bool wait)
3556 {
3557 if (isWaitUifirstFirstFrame_ == wait) {
3558 return;
3559 }
3560 isWaitUifirstFirstFrame_ = wait;
3561 RS_TRACE_NAME_FMT("SetWaitUifirstFirstFrame id:%" PRIu64 ", wait:%d", GetId(), wait);
3562 RS_LOGI("SetWaitUifirstFirstFrame id:%{public}" PRIu64 ", wait:%{public}d", GetId(), wait);
3563 }
3564
SetNeedCacheSurface(bool needCacheSurface)3565 void RSSurfaceRenderNode::SetNeedCacheSurface(bool needCacheSurface)
3566 {
3567 #ifdef RS_ENABLE_GPU
3568 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3569 if (surfaceParams) {
3570 surfaceParams->SetNeedCacheSurface(needCacheSurface);
3571 }
3572 AddToPendingSyncList();
3573 #endif
3574 }
3575
NeedUpdateDrawableBehindWindow() const3576 bool RSSurfaceRenderNode::NeedUpdateDrawableBehindWindow() const
3577 {
3578 bool needDrawBehindWindow = NeedDrawBehindWindow();
3579 return needDrawBehindWindow != oldNeedDrawBehindWindow_;
3580 }
3581
SetOldNeedDrawBehindWindow(bool val)3582 void RSSurfaceRenderNode::SetOldNeedDrawBehindWindow(bool val)
3583 {
3584 oldNeedDrawBehindWindow_ = val;
3585 }
3586
NeedDrawBehindWindow() const3587 bool RSSurfaceRenderNode::NeedDrawBehindWindow() const
3588 {
3589 return RSSystemProperties::GetBehindWindowFilterEnabled() && !GetRenderProperties().GetBackgroundFilter() &&
3590 !childrenBlurBehindWindow_.empty();
3591 }
3592
AddChildBlurBehindWindow(NodeId id)3593 void RSSurfaceRenderNode::AddChildBlurBehindWindow(NodeId id)
3594 {
3595 childrenBlurBehindWindow_.emplace(id);
3596 }
3597
RemoveChildBlurBehindWindow(NodeId id)3598 void RSSurfaceRenderNode::RemoveChildBlurBehindWindow(NodeId id)
3599 {
3600 childrenBlurBehindWindow_.erase(id);
3601 }
3602
GetChildBlurBehindWindow()3603 const std::unordered_set<NodeId>& RSSurfaceRenderNode::GetChildBlurBehindWindow()
3604 {
3605 return childrenBlurBehindWindow_;
3606 }
3607
CalDrawBehindWindowRegion()3608 void RSSurfaceRenderNode::CalDrawBehindWindowRegion()
3609 {
3610 auto context = GetContext().lock();
3611 if (!context) {
3612 RS_LOGE("RSSurfaceRenderNode::CalDrawBehindWindowRegion, invalid context");
3613 return;
3614 }
3615 RectI region;
3616 auto geoPtr = GetMutableRenderProperties().GetBoundsGeometry();
3617 auto surfaceAbsMatrix = geoPtr->GetAbsMatrix();
3618 Drawing::Matrix invertSurfaceAbsMatrix;
3619 surfaceAbsMatrix.Invert(invertSurfaceAbsMatrix);
3620 for (auto& id : childrenBlurBehindWindow_) {
3621 if (auto child = context->GetNodeMap().GetRenderNode<RSRenderNode>(id)) {
3622 auto childRelativeMatrix = child->GetMutableRenderProperties().GetBoundsGeometry()->GetAbsMatrix();
3623 childRelativeMatrix.PostConcat(invertSurfaceAbsMatrix);
3624 auto childRelativeRect = geoPtr->MapRect(child->GetSelfDrawRect(), childRelativeMatrix);
3625 region = region.JoinRect(childRelativeRect);
3626 } else {
3627 RS_LOGE("RSSurfaceRenderNode::CalDrawBehindWindowRegion, get child failed");
3628 return;
3629 }
3630 }
3631 RS_OPTIONAL_TRACE_NAME_FMT("RSSurfaceRenderNode::CalDrawBehindWindowRegion: Id: %lu, BehindWindowRegion: %s",
3632 GetId(), region.ToString().c_str());
3633 RS_LOGD("RSSurfaceRenderNode::CalDrawBehindWindowRegion: Id: %{public}" PRIu64 ", BehindWindowRegion: %{public}s",
3634 GetId(), region.ToString().c_str());
3635 drawBehindWindowRegion_ = region;
3636 auto filterDrawable = GetFilterDrawable(false);
3637 if (!filterDrawable) {
3638 return;
3639 }
3640 filterDrawable->SetDrawBehindWindowRegion(region);
3641 }
3642
GetFilterRect() const3643 RectI RSSurfaceRenderNode::GetFilterRect() const
3644 {
3645 if (!NeedDrawBehindWindow()) {
3646 return RSRenderNode::GetFilterRect();
3647 }
3648 auto geoPtr = GetRenderProperties().GetBoundsGeometry();
3649 auto surfaceAbsMatrix = geoPtr->GetAbsMatrix();
3650 RectF regionF(drawBehindWindowRegion_.GetLeft(), drawBehindWindowRegion_.GetTop(),
3651 drawBehindWindowRegion_.GetWidth(), drawBehindWindowRegion_.GetHeight());
3652 return geoPtr->MapRect(regionF, surfaceAbsMatrix);
3653 }
3654
GetBehindWindowRegion() const3655 RectI RSSurfaceRenderNode::GetBehindWindowRegion() const
3656 {
3657 return drawBehindWindowRegion_;
3658 }
3659
IsCurFrameSwitchToPaint()3660 bool RSSurfaceRenderNode::IsCurFrameSwitchToPaint()
3661 {
3662 bool shouldPaint = ShouldPaint();
3663 bool changed = shouldPaint && !lastFrameShouldPaint_;
3664 lastFrameShouldPaint_ = shouldPaint;
3665 return changed;
3666 }
3667
SetApiCompatibleVersion(uint32_t apiCompatibleVersion)3668 void RSSurfaceRenderNode::SetApiCompatibleVersion(uint32_t apiCompatibleVersion)
3669 {
3670 if (stagingRenderParams_ == nullptr) {
3671 RS_LOGE("RSSurfaceRenderNode::SetApiCompatibleVersion: stagingRenderPrams is nullptr");
3672 return;
3673 }
3674 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3675 if (surfaceParams == nullptr) {
3676 RS_LOGE("RSSurfaceRenderNode::SetApiCompatibleVersion: surfaceParams is nullptr");
3677 return;
3678 }
3679 surfaceParams->SetApiCompatibleVersion(apiCompatibleVersion);
3680 AddToPendingSyncList();
3681
3682 apiCompatibleVersion_ = apiCompatibleVersion;
3683 }
3684
SetIsCloned(bool isCloned)3685 void RSSurfaceRenderNode::SetIsCloned(bool isCloned)
3686 {
3687 if (stagingRenderParams_ == nullptr) {
3688 RS_LOGE("RSSurfaceRenderNode::SetIsCloned: stagingRenderParams_ is nullptr");
3689 return;
3690 }
3691 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3692 if (surfaceParams == nullptr) {
3693 RS_LOGE("RSSurfaceRenderNode::SetIsCloned: surfaceParams is nullptr");
3694 return;
3695 }
3696 surfaceParams->SetIsCloned(isCloned);
3697 AddToPendingSyncList();
3698 }
3699
ResetIsBufferFlushed()3700 void RSSurfaceRenderNode::ResetIsBufferFlushed()
3701 {
3702 if (stagingRenderParams_ == nullptr) {
3703 RS_LOGE("RSSurfaceRenderNode::ResetIsBufferFlushed: stagingRenderPrams is nullptr");
3704 return;
3705 }
3706 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3707 if (surfaceParams == nullptr) {
3708 RS_LOGE("RSSurfaceRenderNode::ResetIsBufferFlushed: surfaceParams is nullptr");
3709 return;
3710 }
3711 if (!surfaceParams->GetIsBufferFlushed()) {
3712 return;
3713 }
3714 surfaceParams->SetIsBufferFlushed(false);
3715 AddToPendingSyncList();
3716 }
3717
ResetSurfaceNodeStates()3718 void RSSurfaceRenderNode::ResetSurfaceNodeStates()
3719 {
3720 animateState_ = false;
3721 isRotating_ = false;
3722 specialLayerChanged_ = false;
3723 if (stagingRenderParams_ == nullptr) {
3724 RS_LOGE("RSSurfaceRenderNode::ResetSurfaceNodeStates: stagingRenderPrams is nullptr");
3725 return;
3726 }
3727 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3728 if (surfaceParams == nullptr) {
3729 RS_LOGE("RSSurfaceRenderNode::ResetSurfaceNodeStates: surfaceParams is nullptr");
3730 return;
3731 }
3732 if (!surfaceParams->GetIsBufferFlushed()) {
3733 return;
3734 }
3735 surfaceParams->SetIsBufferFlushed(false);
3736 AddToPendingSyncList();
3737 }
3738
SetFrameGravityNewVersionEnabled(bool isEnabled)3739 void RSSurfaceRenderNode::SetFrameGravityNewVersionEnabled(bool isEnabled)
3740 {
3741 if (isFrameGravityNewVersionEnabled_ == isEnabled) {
3742 return;
3743 }
3744 auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
3745 if (surfaceParams == nullptr) {
3746 ROSEN_LOGE("RSSurfaceRenderNode::SetFrameGravityNewVersionEnabled failed! surfaceParams is null. id:%{public}"
3747 "" PRIu64 ", isEnabled:%{public}d", GetId(), isEnabled);
3748 return;
3749 }
3750 surfaceParams->SetFrameGravityNewVersionEnabled(isEnabled);
3751 AddToPendingSyncList();
3752
3753 isFrameGravityNewVersionEnabled_ = isEnabled;
3754 }
3755
isForcedClipHole() const3756 bool RSSurfaceRenderNode::isForcedClipHole() const
3757 {
3758 const std::string& tvPlayerBundleName = RsCommonHook::Instance().GetTvPlayerBundleName();
3759 if (tvPlayerBundleName.empty()) {
3760 return false;
3761 }
3762 return (tvPlayerBundleName == bundleName_);
3763 }
3764 } // namespace Rosen
3765 } // namespace OHOS
3766