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 "params/rs_render_params.h"
17 #include "pipeline/rs_root_render_node.h"
18 #include "platform/common/rs_log.h"
19 #include "platform/drawing/rs_surface.h"
20 #include "transaction/rs_transaction_proxy.h"
21 #include "visitor/rs_node_visitor.h"
22 #ifndef ROSEN_CROSS_PLATFORM
23 #include <surface.h>
24 #endif
25
26 namespace OHOS {
27 namespace Rosen {
RSRootRenderNode(NodeId id,const std::weak_ptr<RSContext> & context,bool isTextureExportNode)28 RSRootRenderNode::RSRootRenderNode(NodeId id, const std::weak_ptr<RSContext>& context, bool isTextureExportNode)
29 : RSCanvasRenderNode(id, context, isTextureExportNode), dirtyManager_(std::make_shared<RSDirtyRegionManager>())
30 {
31 #ifndef ROSEN_ARKUI_X
32 MemoryInfo info = {sizeof(*this), ExtractPid(id), id, MEMORY_TYPE::MEM_RENDER_NODE};
33 MemoryTrack::Instance().AddNodeRecord(id, info);
34 #endif
35 MemorySnapshot::Instance().AddCpuMemory(ExtractPid(id), sizeof(*this) - sizeof(RSCanvasRenderNode));
36 }
37
~RSRootRenderNode()38 RSRootRenderNode::~RSRootRenderNode()
39 {
40 #ifndef ROSEN_ARKUI_X
41 MemoryTrack::Instance().RemoveNodeRecord(GetId());
42 #endif
43 MemorySnapshot::Instance().RemoveCpuMemory(ExtractPid(GetId()), sizeof(*this) - sizeof(RSCanvasRenderNode));
44 }
45
AttachRSSurfaceNode(NodeId surfaceNodeId)46 void RSRootRenderNode::AttachRSSurfaceNode(NodeId surfaceNodeId)
47 {
48 surfaceNodeId_ = surfaceNodeId;
49 }
50
AttachToken(uint64_t token)51 void RSRootRenderNode::AttachToken(uint64_t token)
52 {
53 token_ = token;
54 }
55
GetSuggestedBufferWidth() const56 float RSRootRenderNode::GetSuggestedBufferWidth() const
57 {
58 return suggestedBufferWidth_;
59 }
60
GetSuggestedBufferHeight() const61 float RSRootRenderNode::GetSuggestedBufferHeight() const
62 {
63 return suggestedBufferHeight_;
64 }
65
UpdateSuggestedBufferSize(float width,float height)66 void RSRootRenderNode::UpdateSuggestedBufferSize(float width, float height)
67 {
68 suggestedBufferHeight_ = height;
69 suggestedBufferWidth_ = width;
70 }
71
GetSurface()72 std::shared_ptr<RSSurface> RSRootRenderNode::GetSurface()
73 {
74 return rsSurface_;
75 }
76
GetRSSurfaceNodeId()77 NodeId RSRootRenderNode::GetRSSurfaceNodeId()
78 {
79 return surfaceNodeId_;
80 }
81
GetDirtyManager() const82 std::shared_ptr<RSDirtyRegionManager> RSRootRenderNode::GetDirtyManager() const
83 {
84 return dirtyManager_;
85 }
86
Prepare(const std::shared_ptr<RSNodeVisitor> & visitor)87 void RSRootRenderNode::Prepare(const std::shared_ptr<RSNodeVisitor>& visitor)
88 {
89 if (!visitor) {
90 return;
91 }
92 ApplyModifiers();
93 visitor->PrepareRootRenderNode(*this);
94 }
95
QuickPrepare(const std::shared_ptr<RSNodeVisitor> & visitor)96 void RSRootRenderNode::QuickPrepare(const std::shared_ptr<RSNodeVisitor>& visitor)
97 {
98 if (!visitor) {
99 return;
100 }
101 ApplyModifiers();
102 visitor->PrepareRootRenderNode(*this);
103 }
104
Process(const std::shared_ptr<RSNodeVisitor> & visitor)105 void RSRootRenderNode::Process(const std::shared_ptr<RSNodeVisitor>& visitor)
106 {
107 if (!visitor) {
108 return;
109 }
110 RSRenderNode::RenderTraceDebug();
111 visitor->ProcessRootRenderNode(*this);
112 }
113
114 // [Attention] Only used in PC window resize scene now
EnableWindowKeyFrame(bool enable)115 void RSRootRenderNode::EnableWindowKeyFrame(bool enable)
116 {
117 if (stagingRenderParams_ == nullptr) {
118 RS_LOGE("RSRootRenderNode::EnableWindowKeyFrame stagingRenderParams is null");
119 return;
120 }
121
122 stagingRenderParams_->EnableWindowKeyFrame(enable);
123 AddToPendingSyncList();
124 }
125
126 // [Attention] Only used in PC window resize scene now
IsWindowKeyFrameEnabled()127 bool RSRootRenderNode::IsWindowKeyFrameEnabled()
128 {
129 return stagingRenderParams_ != nullptr ? stagingRenderParams_->IsWindowKeyFrameEnabled() : false;
130 }
131
132 } // namespace Rosen
133 } // namespace OHOS
134