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