• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef NEW_RENDER_CONTEXT
23 #include "rs_render_surface.h"
24 #else
25 #include "platform/drawing/rs_surface.h"
26 #endif
27 
28 namespace OHOS {
29 namespace Rosen {
30 
Create(RSContext & context,NodeId id)31 void RootNodeCommandHelper::Create(RSContext& context, NodeId id)
32 {
33     auto node = std::make_shared<RSRootRenderNode>(id, context.weak_from_this());
34     context.GetMutableNodeMap().RegisterRenderNode(node);
35 }
36 
AttachRSSurfaceNode(RSContext & context,NodeId id,NodeId surfaceNodeId)37 void RootNodeCommandHelper::AttachRSSurfaceNode(RSContext& context, NodeId id, NodeId surfaceNodeId)
38 {
39     if (auto node = context.GetNodeMap().GetRenderNode<RSRootRenderNode>(id)) {
40         node->AttachRSSurfaceNode(surfaceNodeId);
41         context.GetGlobalRootRenderNode()->AddChild(node);
42     }
43 }
44 
SetEnableRender(RSContext & context,NodeId id,bool flag)45 void RootNodeCommandHelper::SetEnableRender(RSContext& context, NodeId id, bool flag)
46 {
47     if (auto node = context.GetNodeMap().GetRenderNode<RSRootRenderNode>(id)) {
48         node->SetEnableRender(flag);
49     }
50 }
51 
AttachToUniSurfaceNode(RSContext & context,NodeId id,NodeId surfaceNodeId)52 void RootNodeCommandHelper::AttachToUniSurfaceNode(RSContext& context, NodeId id, NodeId surfaceNodeId)
53 {
54     auto& nodeMap = context.GetNodeMap();
55     auto parent = nodeMap.GetRenderNode<RSSurfaceRenderNode>(surfaceNodeId);
56     auto node = nodeMap.GetRenderNode<RSRootRenderNode>(id);
57     if (!parent || !node) {
58         RS_LOGE("unirender: RootNodeCommandHelper::AttachToUniSurfaceNode surfaceNodeId:%" PRIu64 " id:%" PRIu64
59                 ", parent "
60                 "valid:%d, node valid:%d",
61             surfaceNodeId, id, parent != nullptr, node != nullptr);
62         return;
63     }
64     parent->AddChild(node);
65     parent->SetSurfaceNodeType(RSSurfaceNodeType::APP_WINDOW_NODE);
66 }
67 
UpdateSuggestedBufferSize(RSContext & context,NodeId id,float width,float height)68 void RootNodeCommandHelper::UpdateSuggestedBufferSize(RSContext& context, NodeId id, float width, float height)
69 {
70     if (auto node = context.GetNodeMap().GetRenderNode<RSRootRenderNode>(id)) {
71         node->UpdateSuggestedBufferSize(width, height);
72     }
73 }
74 } // namespace Rosen
75 } // namespace OHOS
76