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_display_render_node.h"
17
18 #include "common/rs_obj_abs_geometry.h"
19 #include "common/rs_optional_trace.h"
20 #include "common/rs_special_layer_manager.h"
21 #include "params/rs_display_render_params.h"
22 #include "pipeline/rs_render_node.h"
23 #include "pipeline/rs_surface_render_node.h"
24 #include "platform/common/rs_log.h"
25 #include "screen_manager/screen_types.h"
26 #include "visitor/rs_node_visitor.h"
27 #include "transaction/rs_render_service_client.h"
28 namespace OHOS {
29 namespace Rosen {
30 constexpr int64_t MAX_JITTER_NS = 2000000; // 2ms
31
RSDisplayRenderNode(NodeId id,const RSDisplayNodeConfig & config,const std::weak_ptr<RSContext> & context)32 RSDisplayRenderNode::RSDisplayRenderNode(
33 NodeId id, const RSDisplayNodeConfig& config, const std::weak_ptr<RSContext>& context)
34 : RSRenderNode(id, context), isMirroredDisplay_(config.isMirrored), offsetX_(0), offsetY_(0),
35 screenId_(config.screenId), dirtyManager_(std::make_shared<RSDirtyRegionManager>(true))
36 {
37 RS_LOGI("RSScreen RSDisplayRenderNode ctor id:%{public}" PRIu64 ", config[screenid:%{public}" PRIu64
38 ", isMirrored:%{public}d, mirrorNodeId:%{public}" PRIu64 ", isSync:%{public}d]",
39 id, screenId_, config.isMirrored, config.mirrorNodeId, config.isSync);
40 MemoryInfo info = {sizeof(*this), ExtractPid(id), id, MEMORY_TYPE::MEM_RENDER_NODE};
41 MemoryTrack::Instance().AddNodeRecord(id, info);
42 MemorySnapshot::Instance().AddCpuMemory(ExtractPid(id), sizeof(*this));
43 }
44
~RSDisplayRenderNode()45 RSDisplayRenderNode::~RSDisplayRenderNode()
46 {
47 RS_LOGI("RSScreen RSDisplayRenderNode dtor id:%{public}" PRIu64 ", screenId:%{public}" PRIu64, GetId(), screenId_);
48 MemoryTrack::Instance().RemoveNodeRecord(GetId());
49 MemorySnapshot::Instance().RemoveCpuMemory(ExtractPid(GetId()), sizeof(*this));
50 }
51
CollectSurface(const std::shared_ptr<RSBaseRenderNode> & node,std::vector<RSBaseRenderNode::SharedPtr> & vec,bool isUniRender,bool onlyFirstLevel)52 void RSDisplayRenderNode::CollectSurface(
53 const std::shared_ptr<RSBaseRenderNode>& node, std::vector<RSBaseRenderNode::SharedPtr>& vec, bool isUniRender,
54 bool onlyFirstLevel)
55 {
56 for (auto& child : *node->GetSortedChildren()) {
57 child->CollectSurface(child, vec, isUniRender, onlyFirstLevel);
58 }
59 }
60
QuickPrepare(const std::shared_ptr<RSNodeVisitor> & visitor)61 void RSDisplayRenderNode::QuickPrepare(const std::shared_ptr<RSNodeVisitor>& visitor)
62 {
63 if (!visitor) {
64 return;
65 }
66 ApplyModifiers();
67 visitor->QuickPrepareDisplayRenderNode(*this);
68 }
69
Prepare(const std::shared_ptr<RSNodeVisitor> & visitor)70 void RSDisplayRenderNode::Prepare(const std::shared_ptr<RSNodeVisitor>& visitor)
71 {
72 if (!visitor) {
73 return;
74 }
75 ApplyModifiers();
76 visitor->PrepareDisplayRenderNode(*this);
77 }
78
Process(const std::shared_ptr<RSNodeVisitor> & visitor)79 void RSDisplayRenderNode::Process(const std::shared_ptr<RSNodeVisitor>& visitor)
80 {
81 if (!visitor) {
82 return;
83 }
84 RSRenderNode::RenderTraceDebug();
85 visitor->ProcessDisplayRenderNode(*this);
86 }
87
SetIsOnTheTree(bool flag,NodeId instanceRootNodeId,NodeId firstLevelNodeId,NodeId cacheNodeId,NodeId uifirstRootNodeId,NodeId displayNodeId)88 void RSDisplayRenderNode::SetIsOnTheTree(bool flag, NodeId instanceRootNodeId, NodeId firstLevelNodeId,
89 NodeId cacheNodeId, NodeId uifirstRootNodeId, NodeId displayNodeId)
90 {
91 // if node is marked as cacheRoot, update subtree status when update surface
92 // in case prepare stage upper cacheRoot cannot specify dirty subnode
93 RSRenderNode::SetIsOnTheTree(flag, GetId(), firstLevelNodeId, cacheNodeId, uifirstRootNodeId, GetId());
94 }
95
SetScreenId(uint64_t screenId)96 void RSDisplayRenderNode::SetScreenId(uint64_t screenId)
97 {
98 RS_TRACE_NAME_FMT("RSScreenManager %s:displayNode[%" PRIu64 "] change screen [%" PRIu64 "] "
99 "to [%" PRIu64 "].", __func__, GetId(), screenId_, screenId);
100 RS_LOGI("RSScreenManager %{public}s:displayNode[%{public}" PRIu64 "] change screen [%{public}" PRIu64 "] "
101 "to [%{public}" PRIu64 "].", __func__, GetId(), screenId_, screenId);
102 if (releaseScreenDmaBufferTask_ && screenId_ != screenId) {
103 releaseScreenDmaBufferTask_(screenId_);
104 }
105 screenId_ = screenId;
106 }
107
GetCompositeType() const108 RSDisplayRenderNode::CompositeType RSDisplayRenderNode::GetCompositeType() const
109 {
110 return compositeType_;
111 }
112
SetCompositeType(RSDisplayRenderNode::CompositeType type)113 void RSDisplayRenderNode::SetCompositeType(RSDisplayRenderNode::CompositeType type)
114 {
115 compositeType_ = type;
116 }
117
SetForceSoftComposite(bool flag)118 void RSDisplayRenderNode::SetForceSoftComposite(bool flag)
119 {
120 forceSoftComposite_ = flag;
121 }
122
IsForceSoftComposite() const123 bool RSDisplayRenderNode::IsForceSoftComposite() const
124 {
125 return forceSoftComposite_;
126 }
127
SetMirrorSource(SharedPtr node)128 void RSDisplayRenderNode::SetMirrorSource(SharedPtr node)
129 {
130 if (!isMirroredDisplay_ || node == nullptr) {
131 return;
132 }
133 mirrorSource_ = node;
134 }
135
ResetMirrorSource()136 void RSDisplayRenderNode::ResetMirrorSource()
137 {
138 mirrorSource_.reset();
139 }
140
IsMirrorDisplay() const141 bool RSDisplayRenderNode::IsMirrorDisplay() const
142 {
143 return isMirroredDisplay_;
144 }
145
SetSecurityDisplay(bool isSecurityDisplay)146 void RSDisplayRenderNode::SetSecurityDisplay(bool isSecurityDisplay)
147 {
148 isSecurityDisplay_ = isSecurityDisplay;
149 }
150
GetSecurityDisplay() const151 bool RSDisplayRenderNode::GetSecurityDisplay() const
152 {
153 return isSecurityDisplay_;
154 }
155
SetIsMirrorDisplay(bool isMirror)156 void RSDisplayRenderNode::SetIsMirrorDisplay(bool isMirror)
157 {
158 if (isMirroredDisplay_ != isMirror) {
159 hasMirroredDisplayChanged_ = true;
160 }
161 isMirroredDisplay_ = isMirror;
162 RS_TRACE_NAME_FMT("RSDisplayRenderNode::SetIsMirrorDisplay, node id:[%" PRIu64 "], isMirrorDisplay: [%s]",
163 GetId(), IsMirrorDisplay() ? "true" : "false");
164 RS_LOGI("RSDisplayRenderNode::SetIsMirrorDisplay, node id:[%{public}" PRIu64 "], isMirrorDisplay: [%{public}s]",
165 GetId(), IsMirrorDisplay() ? "true" : "false");
166 }
167
SetBootAnimation(bool isBootAnimation)168 void RSDisplayRenderNode::SetBootAnimation(bool isBootAnimation)
169 {
170 ROSEN_LOGD("SetBootAnimation:: id:[%{public}" PRIu64 ", isBootAnimation:%{public}d",
171 GetId(), isBootAnimation);
172 isBootAnimation_ = isBootAnimation;
173
174 auto parent = GetParent().lock();
175 if (parent == nullptr) {
176 return;
177 }
178 if (isBootAnimation) {
179 parent->SetContainBootAnimation(true);
180 }
181 }
182
GetBootAnimation() const183 bool RSDisplayRenderNode::GetBootAnimation() const
184 {
185 return isBootAnimation_;
186 }
187
InitRenderParams()188 void RSDisplayRenderNode::InitRenderParams()
189 {
190 #ifdef RS_ENABLE_GPU
191 stagingRenderParams_ = std::make_unique<RSDisplayRenderParams>(GetId());
192 DrawableV2::RSRenderNodeDrawableAdapter::OnGenerate(shared_from_this());
193 if (renderDrawable_ == nullptr) {
194 RS_LOGE("RSDisplayRenderNode::InitRenderParams failed");
195 return;
196 }
197 #endif
198 }
199
200 ReleaseDmaBufferTask RSDisplayRenderNode::releaseScreenDmaBufferTask_;
SetReleaseTask(ReleaseDmaBufferTask callback)201 void RSDisplayRenderNode::SetReleaseTask(ReleaseDmaBufferTask callback)
202 {
203 if (!releaseScreenDmaBufferTask_ && callback) {
204 releaseScreenDmaBufferTask_ = callback;
205 } else {
206 RS_LOGE("RreleaseScreenDmaBufferTask_ register failed!");
207 }
208 }
209
OnSync()210 void RSDisplayRenderNode::OnSync()
211 {
212 #ifdef RS_ENABLE_GPU
213 RS_OPTIONAL_TRACE_NAME_FMT("RSDisplayRenderNode::OnSync global dirty[%s]",
214 dirtyManager_->GetCurrentFrameDirtyRegion().ToString().c_str());
215 auto displayParams = static_cast<RSDisplayRenderParams*>(stagingRenderParams_.get());
216 if (displayParams == nullptr) {
217 RS_LOGE("RSDisplayRenderNode::OnSync displayParams is null");
218 return;
219 }
220 if (!renderDrawable_) {
221 return;
222 }
223 auto syncDirtyManager = renderDrawable_->GetSyncDirtyManager();
224 dirtyManager_->OnSync(syncDirtyManager);
225 displayParams->SetZoomed(curZoomState_);
226 displayParams->SetNeedSync(true);
227 RSRenderNode::OnSync();
228 #endif
229 }
230
HandleCurMainAndLeashSurfaceNodes()231 void RSDisplayRenderNode::HandleCurMainAndLeashSurfaceNodes()
232 {
233 surfaceCountForMultiLayersPerf_ = 0;
234 for (const auto& surface : curMainAndLeashSurfaceNodes_) {
235 auto surfaceNode = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(surface);
236 if (!surfaceNode || surfaceNode->IsLeashWindow() || !surfaceNode->IsOnTheTree()) {
237 continue;
238 }
239 surfaceCountForMultiLayersPerf_++;
240 }
241 curMainAndLeashSurfaceNodes_.clear();
242 topSurfaceOpaqueRects_.clear();
243 }
244
RecordMainAndLeashSurfaces(RSBaseRenderNode::SharedPtr surface)245 void RSDisplayRenderNode::RecordMainAndLeashSurfaces(RSBaseRenderNode::SharedPtr surface)
246 {
247 curMainAndLeashSurfaceNodes_.push_back(surface);
248 }
249
RecordTopSurfaceOpaqueRects(Occlusion::Rect rect)250 void RSDisplayRenderNode::RecordTopSurfaceOpaqueRects(Occlusion::Rect rect)
251 {
252 topSurfaceOpaqueRects_.push_back(rect);
253 }
254
UpdateRenderParams()255 void RSDisplayRenderNode::UpdateRenderParams()
256 {
257 #ifdef RS_ENABLE_GPU
258 auto displayParams = static_cast<RSDisplayRenderParams*>(stagingRenderParams_.get());
259 if (displayParams == nullptr) {
260 RS_LOGE("RSDisplayRenderNode::UpdateRenderParams displayParams is null");
261 return;
262 }
263 displayParams->offsetX_ = GetDisplayOffsetX();
264 displayParams->offsetY_ = GetDisplayOffsetY();
265 displayParams->nodeRotation_ = GetRotation();
266 auto mirroredNode = GetMirrorSource().lock();
267 if (mirroredNode == nullptr) {
268 displayParams->mirrorSourceId_ = INVALID_NODEID;
269 displayParams->mirrorSourceDrawable_.reset();
270 RS_LOGW("RSDisplayRenderNode::UpdateRenderParams mirroredNode is null");
271 } else {
272 displayParams->mirrorSourceDrawable_ = mirroredNode->GetRenderDrawable();
273 displayParams->mirrorSourceId_ = mirroredNode->GetId();
274 displayParams->virtualScreenMuteStatus_ = virtualScreenMuteStatus_;
275 }
276 displayParams->isSecurityExemption_ = isSecurityExemption_;
277 displayParams->mirrorSource_ = GetMirrorSource();
278 displayParams->hasSecLayerInVisibleRect_ = hasSecLayerInVisibleRect_;
279 displayParams->hasSecLayerInVisibleRectChanged_ = hasSecLayerInVisibleRectChanged_;
280 displayParams->roundCornerSurfaceDrawables_.clear();
281 if (rcdSurfaceNodeTop_ && rcdSurfaceNodeTop_->GetRenderDrawable() != nullptr) {
282 displayParams->roundCornerSurfaceDrawables_.push_back(rcdSurfaceNodeTop_->GetRenderDrawable());
283 }
284 if (rcdSurfaceNodeBottom_ && rcdSurfaceNodeBottom_->GetRenderDrawable() != nullptr) {
285 displayParams->roundCornerSurfaceDrawables_.push_back(rcdSurfaceNodeBottom_->GetRenderDrawable());
286 }
287 RSRenderNode::UpdateRenderParams();
288 #endif
289 }
290
UpdateScreenRenderParams(ScreenRenderParams & screenRenderParams)291 void RSDisplayRenderNode::UpdateScreenRenderParams(ScreenRenderParams& screenRenderParams)
292 {
293 #ifdef RS_ENABLE_GPU
294 auto displayParams = static_cast<RSDisplayRenderParams*>(stagingRenderParams_.get());
295 if (displayParams == nullptr) {
296 RS_LOGE("RSDisplayRenderNode::UpdateScreenRenderParams displayParams is null");
297 return;
298 }
299 displayParams->screenId_ = GetScreenId();
300 displayParams->screenRotation_ = GetScreenRotation();
301 displayParams->compositeType_ = GetCompositeType();
302 displayParams->hasChildCrossNode_ = HasChildCrossNode();
303 displayParams->isMirrorScreen_ = IsMirrorScreen();
304 displayParams->isFirstVisitCrossNodeDisplay_ = IsFirstVisitCrossNodeDisplay();
305 displayParams->isSecurityDisplay_ = GetSecurityDisplay();
306 displayParams->screenInfo_ = std::move(screenRenderParams.screenInfo);
307 displayParams->specialLayerManager_ = specialLayerManager_;
308 displayParams->displaySpecailSurfaceChanged_ = std::move(screenRenderParams.displaySpecailSurfaceChanged);
309 displayParams->hasCaptureWindow_ = std::move(screenRenderParams.hasCaptureWindow);
310 #endif
311 }
312
UpdateOffscreenRenderParams(bool needOffscreen)313 void RSDisplayRenderNode::UpdateOffscreenRenderParams(bool needOffscreen)
314 {
315 #ifdef RS_ENABLE_GPU
316 auto displayParams = static_cast<RSDisplayRenderParams*>(stagingRenderParams_.get());
317 if (displayParams == nullptr) {
318 RS_LOGE("RSDisplayRenderNode::UpdateOffscreenRenderParams displayParams is null");
319 return;
320 }
321 displayParams->SetNeedOffscreen(needOffscreen);
322 #endif
323 }
324
UpdatePartialRenderParams()325 void RSDisplayRenderNode::UpdatePartialRenderParams()
326 {
327 #ifdef RS_ENABLE_GPU
328 auto displayParams = static_cast<RSDisplayRenderParams*>(stagingRenderParams_.get());
329 if (displayParams == nullptr) {
330 RS_LOGE("RSDisplayRenderNode::UpdatePartialRenderParams displayParams is null");
331 return;
332 }
333 displayParams->SetAllMainAndLeashSurfaces(curMainAndLeashSurfaceNodes_);
334 displayParams->SetTopSurfaceOpaqueRects(std::move(topSurfaceOpaqueRects_));
335 #endif
336 }
337
SkipFrame(uint32_t refreshRate,uint32_t skipFrameInterval)338 bool RSDisplayRenderNode::SkipFrame(uint32_t refreshRate, uint32_t skipFrameInterval)
339 {
340 if (refreshRate == 0 || skipFrameInterval <= 1) {
341 return false;
342 }
343 int64_t currentTime = std::chrono::duration_cast<std::chrono::nanoseconds>(
344 std::chrono::steady_clock::now().time_since_epoch()).count();
345 // when refreshRate % skipFrameInterval != 0 means the skipFrameInterval is the virtual screen refresh rate
346 if (refreshRate % skipFrameInterval != 0) {
347 int64_t minFrameInterval = 1000000000LL / skipFrameInterval;
348 if (minFrameInterval == 0) {
349 return false;
350 }
351 // lastRefreshTime_ is next frame expected refresh time for virtual display
352 if (lastRefreshTime_ <= 0) {
353 lastRefreshTime_ = currentTime + minFrameInterval;
354 return false;
355 }
356 if (currentTime < (lastRefreshTime_ - MAX_JITTER_NS)) {
357 return true;
358 }
359 int64_t intervalNums = (currentTime - lastRefreshTime_ + MAX_JITTER_NS) / minFrameInterval;
360 lastRefreshTime_ += (intervalNums + 1) * minFrameInterval;
361 return false;
362 }
363 // the skipFrameInterval is equal to 60 divide the virtual screen refresh rate
364 int64_t refreshInterval = currentTime - lastRefreshTime_;
365 // 1000000000ns == 1s, 110/100 allows 10% over.
366 bool needSkip = refreshInterval < (1000000000LL / refreshRate) * (skipFrameInterval - 1) * 110 / 100;
367 if (!needSkip) {
368 lastRefreshTime_ = currentTime;
369 }
370 return needSkip;
371 }
372
SetDisplayGlobalZOrder(float zOrder)373 void RSDisplayRenderNode::SetDisplayGlobalZOrder(float zOrder)
374 {
375 #ifdef RS_ENABLE_GPU
376 auto displayParams = static_cast<RSDisplayRenderParams*>(stagingRenderParams_.get());
377 if (displayParams == nullptr) {
378 RS_LOGE("RSDisplayRenderNode::SetDisplayGlobalZOrder displayParams is null");
379 return;
380 }
381 displayParams->SetGlobalZOrder(zOrder);
382 #endif
383 }
384
385
GetRotation() const386 ScreenRotation RSDisplayRenderNode::GetRotation() const
387 {
388 auto& boundsGeoPtr = (GetRenderProperties().GetBoundsGeometry());
389 if (boundsGeoPtr == nullptr) {
390 return ScreenRotation::ROTATION_0;
391 }
392 // -90.0f: convert rotation degree to 4 enum values
393 return static_cast<ScreenRotation>(static_cast<int32_t>(std::roundf(boundsGeoPtr->GetRotation() / -90.0f)) % 4);
394 }
395
IsRotationChanged() const396 bool RSDisplayRenderNode::IsRotationChanged() const
397 {
398 auto& boundsGeoPtr = (GetRenderProperties().GetBoundsGeometry());
399 if (boundsGeoPtr == nullptr) {
400 return false;
401 }
402 // boundsGeoPtr->IsNeedClientCompose() return false if rotation degree is times of 90
403 // which means rotation is end.
404 bool isRotationEnd = !boundsGeoPtr->IsNeedClientCompose();
405 return !(ROSEN_EQ(boundsGeoPtr->GetRotation(), lastRotation_) && isRotationEnd);
406 }
407
IsRotationFinished() const408 bool RSDisplayRenderNode::IsRotationFinished() const
409 {
410 auto& boundsGeoPtr = (GetRenderProperties().GetBoundsGeometry());
411 if (boundsGeoPtr == nullptr) {
412 return false;
413 }
414 // boundsGeoPtr->IsNeedClientCompose() return false if rotation degree is times of 90
415 // which means rotation is end.
416 bool isRotationEnd = !boundsGeoPtr->IsNeedClientCompose();
417 return !ROSEN_EQ(boundsGeoPtr->GetRotation(), lastRotation_) && isRotationEnd;
418 }
419
UpdateRotation()420 void RSDisplayRenderNode::UpdateRotation()
421 {
422 #ifdef RS_ENABLE_GPU
423 auto displayParams = static_cast<RSDisplayRenderParams*>(stagingRenderParams_.get());
424 if (displayParams == nullptr) {
425 RS_LOGE("%{public}s displayParams is nullptr", __func__);
426 return;
427 }
428 AddToPendingSyncList();
429
430 auto& boundsGeoPtr = (GetRenderProperties().GetBoundsGeometry());
431 if (boundsGeoPtr == nullptr) {
432 return;
433 }
434 displayParams->SetRotationFinished(IsRotationFinished());
435 lastRotationChanged_ = IsRotationChanged();
436 lastRotation_ = boundsGeoPtr->GetRotation();
437 preRotationStatus_ = curRotationStatus_;
438 curRotationStatus_ = IsRotationChanged();
439 displayParams->SetRotationChanged(curRotationStatus_);
440 #endif
441 }
442
UpdateDisplayDirtyManager(int32_t bufferage,bool useAlignedDirtyRegion)443 void RSDisplayRenderNode::UpdateDisplayDirtyManager(int32_t bufferage, bool useAlignedDirtyRegion)
444 {
445 dirtyManager_->SetBufferAge(bufferage);
446 dirtyManager_->UpdateDirty(useAlignedDirtyRegion);
447 }
448
ClearCurrentSurfacePos()449 void RSDisplayRenderNode::ClearCurrentSurfacePos()
450 {
451 lastFrameSurfacePos_ = std::move(currentFrameSurfacePos_);
452 lastFrameSurfacesByDescZOrder_ = std::move(currentFrameSurfacesByDescZOrder_);
453 }
454
SetMainAndLeashSurfaceDirty(bool isDirty)455 void RSDisplayRenderNode::SetMainAndLeashSurfaceDirty(bool isDirty)
456 {
457 #ifdef RS_ENABLE_GPU
458 auto displayParams = static_cast<RSDisplayRenderParams*>(stagingRenderParams_.get());
459 if (displayParams == nullptr) {
460 RS_LOGE("%{public}s displayParams is nullptr", __func__);
461 return;
462 }
463 displayParams->SetMainAndLeashSurfaceDirty(isDirty);
464 if (stagingRenderParams_->NeedSync()) {
465 AddToPendingSyncList();
466 }
467 #endif
468 }
469
SetFingerprint(bool hasFingerprint)470 void RSDisplayRenderNode::SetFingerprint(bool hasFingerprint)
471 {
472 #ifdef RS_ENABLE_GPU
473 if (hasFingerprint_ == hasFingerprint) {
474 return;
475 }
476 auto displayParams = static_cast<RSDisplayRenderParams*>(stagingRenderParams_.get());
477 if (displayParams == nullptr) {
478 RS_LOGE("%{public}s displayParams is nullptr", __func__);
479 return;
480 }
481 displayParams->SetFingerprint(hasFingerprint);
482 if (stagingRenderParams_->NeedSync()) {
483 AddToPendingSyncList();
484 }
485 hasFingerprint_ = hasFingerprint;
486 #endif
487 }
488
SetHDRPresent(bool hdrPresent)489 void RSDisplayRenderNode::SetHDRPresent(bool hdrPresent)
490 {
491 #ifdef RS_ENABLE_GPU
492 auto displayParams = static_cast<RSDisplayRenderParams*>(stagingRenderParams_.get());
493 if (displayParams == nullptr) {
494 RS_LOGE("%{public}s displayParams is nullptr", __func__);
495 return;
496 }
497 displayParams->SetHDRPresent(hdrPresent);
498 if (stagingRenderParams_->NeedSync()) {
499 AddToPendingSyncList();
500 }
501 #endif
502 }
503
SetBrightnessRatio(float brightnessRatio)504 void RSDisplayRenderNode::SetBrightnessRatio(float brightnessRatio)
505 {
506 #ifdef RS_ENABLE_GPU
507 auto displayParams = static_cast<RSDisplayRenderParams*>(stagingRenderParams_.get());
508 if (displayParams == nullptr) {
509 RS_LOGE("%{public}s displayParams is nullptr", __func__);
510 return;
511 }
512 displayParams->SetBrightnessRatio(brightnessRatio);
513 if (stagingRenderParams_->NeedSync()) {
514 AddToPendingSyncList();
515 }
516 #endif
517 }
518
SetColorSpace(const GraphicColorGamut & colorSpace)519 void RSDisplayRenderNode::SetColorSpace(const GraphicColorGamut& colorSpace)
520 {
521 #ifdef RS_ENABLE_GPU
522 if (colorSpace_ == colorSpace) {
523 return;
524 }
525 auto displayParams = static_cast<RSDisplayRenderParams*>(stagingRenderParams_.get());
526 if (displayParams == nullptr) {
527 RS_LOGE("%{public}s displayParams is nullptr", __func__);
528 return;
529 }
530 displayParams->SetNewColorSpace(colorSpace);
531 if (stagingRenderParams_->NeedSync()) {
532 AddToPendingSyncList();
533 }
534 colorSpace_ = colorSpace;
535 #endif
536 }
537
GetColorSpace() const538 GraphicColorGamut RSDisplayRenderNode::GetColorSpace() const
539 {
540 return colorSpace_;
541 }
542
GetSortedChildren() const543 RSRenderNode::ChildrenListSharedPtr RSDisplayRenderNode::GetSortedChildren() const
544 {
545 int32_t currentScbPid = GetCurrentScbPid();
546 ChildrenListSharedPtr fullChildrenList = RSRenderNode::GetSortedChildren();
547 if (currentScbPid < 0) {
548 return fullChildrenList;
549 }
550 if (isNeedWaitNewScbPid_) {
551 for (auto it = (*fullChildrenList).rbegin(); it != (*fullChildrenList).rend(); ++it) {
552 auto& child = *it;
553 auto childPid = ExtractPid(child->GetId());
554 if (childPid == currentScbPid) {
555 RS_LOGI("child scb pid equals current scb pid");
556 isNeedWaitNewScbPid_ = false;
557 break;
558 }
559 }
560 }
561 if (isNeedWaitNewScbPid_ && lastScbPid_ < 0) {
562 return fullChildrenList;
563 }
564 std::vector<int32_t> oldScbPids = GetOldScbPids();
565 currentChildrenList_->clear();
566 for (auto& child : *fullChildrenList) {
567 if (child == nullptr) {
568 continue;
569 }
570 auto childPid = ExtractPid(child->GetId());
571 auto pidIter = std::find(oldScbPids.begin(), oldScbPids.end(), childPid);
572 // only when isNeedWaitNewScbPid_ is ture, put lastScb's child to currentChildrenList_
573 if (pidIter != oldScbPids.end() && (!isNeedWaitNewScbPid_ || childPid != lastScbPid_)) {
574 child->SetIsOntheTreeOnlyFlag(false);
575 continue;
576 } else if (childPid == currentScbPid) {
577 child->SetIsOntheTreeOnlyFlag(true);
578 }
579 currentChildrenList_->emplace_back(child);
580 }
581 isFullChildrenListValid_ = false;
582 return std::atomic_load_explicit(¤tChildrenList_, std::memory_order_acquire);
583 }
584
GetDisappearedSurfaceRegionBelowCurrent(NodeId currentSurface) const585 Occlusion::Region RSDisplayRenderNode::GetDisappearedSurfaceRegionBelowCurrent(NodeId currentSurface) const
586 {
587 Occlusion::Region result;
588 auto it = std::find_if(lastFrameSurfacesByDescZOrder_.begin(), lastFrameSurfacesByDescZOrder_.end(),
589 [currentSurface](const std::pair<NodeId, RectI>& surface) { return surface.first == currentSurface; });
590 if (it == lastFrameSurfacesByDescZOrder_.end()) {
591 return result;
592 }
593
594 for (++it; it != lastFrameSurfacesByDescZOrder_.end(); ++it) {
595 if (currentFrameSurfacePos_.count(it->first) != 0) {
596 break;
597 }
598 Occlusion::Region disappearedSurface{ Occlusion::Rect{ it->second } };
599 result.OrSelf(disappearedSurface);
600 }
601 return result;
602 }
603
IsZoomStateChange() const604 bool RSDisplayRenderNode::IsZoomStateChange() const
605 {
606 return preZoomState_ != curZoomState_;
607 }
608
609
SetScreenStatusNotifyTask(ScreenStatusNotifyTask task)610 void RSDisplayRenderNode::SetScreenStatusNotifyTask(ScreenStatusNotifyTask task)
611 {
612 screenStatusNotifyTask_ = task;
613 }
614
NotifyScreenNotSwitching()615 void RSDisplayRenderNode::NotifyScreenNotSwitching()
616 {
617 if (screenStatusNotifyTask_) {
618 screenStatusNotifyTask_(false);
619 ROSEN_LOGI("RSDisplayRenderNode::NotifyScreenNotSwitching SetScreenSwitchStatus true");
620 RS_TRACE_NAME_FMT("NotifyScreenNotSwitching");
621 }
622 }
623
SetWindowContainer(std::shared_ptr<RSBaseRenderNode> container)624 void RSDisplayRenderNode::SetWindowContainer(std::shared_ptr<RSBaseRenderNode> container)
625 {
626 if (auto oldContainer = std::exchange(windowContainer_, container)) {
627 if (container) {
628 RS_LOGD("RSDisplayRenderNode::SetWindowContainer oldContainer: %{public}" PRIu64
629 ", newContainer: %{public}" PRIu64, oldContainer->GetId(), container->GetId());
630 } else {
631 RS_LOGD("RSDisplayRenderNode::SetWindowContainer oldContainer: %{public}" PRIu64,
632 oldContainer->GetId());
633 }
634 }
635 }
636
GetWindowContainer() const637 std::shared_ptr<RSBaseRenderNode> RSDisplayRenderNode::GetWindowContainer() const
638 {
639 return windowContainer_;
640 }
641
SetTargetSurfaceRenderNodeDrawable(DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr drawable)642 void RSDisplayRenderNode::SetTargetSurfaceRenderNodeDrawable(DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr drawable)
643 {
644 auto displayParams = static_cast<RSDisplayRenderParams*>(stagingRenderParams_.get());
645 if (displayParams == nullptr) {
646 RS_LOGE("RSDisplayRenderNode::SetTargetSurfaceRenderNodeDrawable displayParams is null");
647 return;
648 }
649 displayParams->SetTargetSurfaceRenderNodeDrawable(drawable);
650 if (stagingRenderParams_->NeedSync()) {
651 AddToPendingSyncList();
652 }
653 }
654 } // namespace Rosen
655 } // namespace OHOS
656