1 /*
2 * Copyright (c) 2021-2022 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 "command/rs_root_node_command.h"
17
18 #include "pipeline/rs_root_render_node.h"
19 #include "pipeline/rs_surface_render_node.h"
20 #include "platform/common/rs_log.h"
21
22 namespace OHOS {
23 namespace Rosen {
24
Create(RSContext & context,NodeId id)25 void RootNodeCommandHelper::Create(RSContext& context, NodeId id)
26 {
27 auto node = std::make_shared<RSRootRenderNode>(id, context.weak_from_this());
28 context.GetMutableNodeMap().RegisterRenderNode(node);
29 }
30
AttachRSSurfaceNode(RSContext & context,NodeId id,NodeId surfaceNodeId)31 void RootNodeCommandHelper::AttachRSSurfaceNode(RSContext& context, NodeId id, NodeId surfaceNodeId)
32 {
33 if (auto node = context.GetNodeMap().GetRenderNode<RSRootRenderNode>(id)) {
34 node->AttachRSSurfaceNode(surfaceNodeId);
35 context.GetGlobalRootRenderNode()->AddChild(node);
36 }
37 }
38
SetEnableRender(RSContext & context,NodeId id,bool flag)39 void RootNodeCommandHelper::SetEnableRender(RSContext& context, NodeId id, bool flag)
40 {
41 if (auto node = context.GetNodeMap().GetRenderNode<RSRootRenderNode>(id)) {
42 node->SetEnableRender(flag);
43 }
44 }
45
AttachToUniSurfaceNode(RSContext & context,NodeId id,NodeId surfaceNodeId)46 void RootNodeCommandHelper::AttachToUniSurfaceNode(RSContext& context, NodeId id, NodeId surfaceNodeId)
47 {
48 auto& nodeMap = context.GetNodeMap();
49 auto parent = nodeMap.GetRenderNode<RSSurfaceRenderNode>(surfaceNodeId);
50 auto node = nodeMap.GetRenderNode<RSRootRenderNode>(id);
51 if (!parent || !node) {
52 RS_LOGE("unirender: RootNodeCommandHelper::AttachToUniSurfaceNode surfaceNodeId:%" PRIu64 " id:%" PRIu64
53 ", parent "
54 "valid:%d, node valid:%d",
55 surfaceNodeId, id, parent != nullptr, node != nullptr);
56 return;
57 }
58 parent->AddChild(node);
59 parent->SetSurfaceNodeType(RSSurfaceNodeType::APP_WINDOW_NODE);
60 }
61
UpdateSuggestedBufferSize(RSContext & context,NodeId id,float width,float height)62 void RootNodeCommandHelper::UpdateSuggestedBufferSize(RSContext& context, NodeId id, float width, float height)
63 {
64 if (auto node = context.GetNodeMap().GetRenderNode<RSRootRenderNode>(id)) {
65 node->UpdateSuggestedBufferSize(width, height);
66 }
67 }
68 } // namespace Rosen
69 } // namespace OHOS
70