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_root_render_node.h"
17
18 #ifdef NEW_RENDER_CONTEXT
19 #include "rs_render_surface.h"
20 #else
21 #include "platform/drawing/rs_surface.h"
22 #endif
23 #include "transaction/rs_transaction_proxy.h"
24 #include "visitor/rs_node_visitor.h"
25 #ifndef ROSEN_CROSS_PLATFORM
26 #include <surface.h>
27 #endif
28
29 namespace OHOS {
30 namespace Rosen {
RSRootRenderNode(NodeId id,const std::weak_ptr<RSContext> & context,bool isTextureExportNode)31 RSRootRenderNode::RSRootRenderNode(NodeId id, const std::weak_ptr<RSContext>& context, bool isTextureExportNode)
32 : RSCanvasRenderNode(id, context, isTextureExportNode), dirtyManager_(std::make_shared<RSDirtyRegionManager>())
33 {
34 #ifndef ROSEN_ARKUI_X
35 MemoryInfo info = {sizeof(*this), ExtractPid(id), id, MEMORY_TYPE::MEM_RENDER_NODE};
36 MemoryTrack::Instance().AddNodeRecord(id, info);
37 #endif
38 MemorySnapshot::Instance().AddCpuMemory(ExtractPid(id), sizeof(*this) - sizeof(RSCanvasRenderNode));
39 }
40
~RSRootRenderNode()41 RSRootRenderNode::~RSRootRenderNode()
42 {
43 #ifndef ROSEN_ARKUI_X
44 MemoryTrack::Instance().RemoveNodeRecord(GetId());
45 #endif
46 MemorySnapshot::Instance().RemoveCpuMemory(ExtractPid(GetId()), sizeof(*this) - sizeof(RSCanvasRenderNode));
47 }
48
AttachRSSurfaceNode(NodeId surfaceNodeId)49 void RSRootRenderNode::AttachRSSurfaceNode(NodeId surfaceNodeId)
50 {
51 surfaceNodeId_ = surfaceNodeId;
52 }
53
GetSuggestedBufferWidth() const54 float RSRootRenderNode::GetSuggestedBufferWidth() const
55 {
56 return suggestedBufferWidth_;
57 }
58
GetSuggestedBufferHeight() const59 float RSRootRenderNode::GetSuggestedBufferHeight() const
60 {
61 return suggestedBufferHeight_;
62 }
63
UpdateSuggestedBufferSize(float width,float height)64 void RSRootRenderNode::UpdateSuggestedBufferSize(float width, float height)
65 {
66 suggestedBufferHeight_ = height;
67 suggestedBufferWidth_ = width;
68 }
69 #ifdef NEW_RENDER_CONTEXT
GetSurface()70 std::shared_ptr<RSRenderSurface> RSRootRenderNode::GetSurface()
71 #else
72 std::shared_ptr<RSSurface> RSRootRenderNode::GetSurface()
73 #endif
74 {
75 return rsSurface_;
76 }
77
GetRSSurfaceNodeId()78 NodeId RSRootRenderNode::GetRSSurfaceNodeId()
79 {
80 return surfaceNodeId_;
81 }
82
GetDirtyManager() const83 std::shared_ptr<RSDirtyRegionManager> RSRootRenderNode::GetDirtyManager() const
84 {
85 return dirtyManager_;
86 }
87
Prepare(const std::shared_ptr<RSNodeVisitor> & visitor)88 void RSRootRenderNode::Prepare(const std::shared_ptr<RSNodeVisitor>& visitor)
89 {
90 if (!visitor) {
91 return;
92 }
93 ApplyModifiers();
94 visitor->PrepareRootRenderNode(*this);
95 }
96
QuickPrepare(const std::shared_ptr<RSNodeVisitor> & visitor)97 void RSRootRenderNode::QuickPrepare(const std::shared_ptr<RSNodeVisitor>& visitor)
98 {
99 if (!visitor) {
100 return;
101 }
102 ApplyModifiers();
103 visitor->PrepareRootRenderNode(*this);
104 }
105
Process(const std::shared_ptr<RSNodeVisitor> & visitor)106 void RSRootRenderNode::Process(const std::shared_ptr<RSNodeVisitor>& visitor)
107 {
108 if (!visitor) {
109 return;
110 }
111 RSRenderNode::RenderTraceDebug();
112 visitor->ProcessRootRenderNode(*this);
113 }
114 } // namespace Rosen
115 } // namespace OHOS
116