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