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,std::weak_ptr<RSContext> context)31 RSRootRenderNode::RSRootRenderNode(NodeId id, std::weak_ptr<RSContext> context)
32 : RSCanvasRenderNode(id, context), dirtyManager_(std::make_shared<RSDirtyRegionManager>())
33 {
34 MemoryInfo info = {sizeof(*this), ExtractPid(id), id, MEMORY_TYPE::MEM_RENDER_NODE};
35 MemoryTrack::Instance().AddNodeRecord(id, info);
36 }
37
~RSRootRenderNode()38 RSRootRenderNode::~RSRootRenderNode()
39 {
40 MemoryTrack::Instance().RemoveNodeRecord(GetId());
41 }
42
AttachRSSurfaceNode(NodeId surfaceNodeId)43 void RSRootRenderNode::AttachRSSurfaceNode(NodeId surfaceNodeId)
44 {
45 surfaceNodeId_ = surfaceNodeId;
46 }
47
GetSuggestedBufferWidth() const48 float RSRootRenderNode::GetSuggestedBufferWidth() const
49 {
50 return suggestedBufferWidth_;
51 }
52
GetSuggestedBufferHeight() const53 float RSRootRenderNode::GetSuggestedBufferHeight() const
54 {
55 return suggestedBufferHeight_;
56 }
57
UpdateSuggestedBufferSize(float width,float height)58 void RSRootRenderNode::UpdateSuggestedBufferSize(float width, float height)
59 {
60 suggestedBufferHeight_ = height;
61 suggestedBufferWidth_ = width;
62 }
63 #ifdef NEW_RENDER_CONTEXT
GetSurface()64 std::shared_ptr<RSRenderSurface> RSRootRenderNode::GetSurface()
65 #else
66 std::shared_ptr<RSSurface> RSRootRenderNode::GetSurface()
67 #endif
68 {
69 return rsSurface_;
70 }
71
GetRSSurfaceNodeId()72 NodeId RSRootRenderNode::GetRSSurfaceNodeId()
73 {
74 return surfaceNodeId_;
75 }
76
GetDirtyManager() const77 std::shared_ptr<RSDirtyRegionManager> RSRootRenderNode::GetDirtyManager() const
78 {
79 return dirtyManager_;
80 }
81
Prepare(const std::shared_ptr<RSNodeVisitor> & visitor)82 void RSRootRenderNode::Prepare(const std::shared_ptr<RSNodeVisitor>& visitor)
83 {
84 if (!visitor) {
85 return;
86 }
87 visitor->PrepareRootRenderNode(*this);
88 }
89
Process(const std::shared_ptr<RSNodeVisitor> & visitor)90 void RSRootRenderNode::Process(const std::shared_ptr<RSNodeVisitor>& visitor)
91 {
92 if (!visitor) {
93 return;
94 }
95 RSRenderNode::RenderTraceDebug();
96 visitor->ProcessRootRenderNode(*this);
97 }
98 } // namespace Rosen
99 } // namespace OHOS
100