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