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_display_node_command.h"
17
18 #include "pipeline/rs_display_render_node.h"
19 #include "pipeline/rs_render_node_gc.h"
20 #include "platform/common/rs_log.h"
21
22 namespace OHOS {
23 namespace Rosen {
24
Create(RSContext & context,NodeId id,const RSDisplayNodeConfig & config)25 void DisplayNodeCommandHelper::Create(RSContext& context, NodeId id, const RSDisplayNodeConfig& config)
26 {
27 auto node = std::shared_ptr<RSDisplayRenderNode>(new RSDisplayRenderNode(id,
28 config, context.weak_from_this()), RSRenderNodeGC::NodeDestructor);
29 auto& nodeMap = context.GetMutableNodeMap();
30 nodeMap.RegisterDisplayRenderNode(node);
31 context.GetGlobalRootRenderNode()->AddChild(node);
32 if (config.isMirrored) {
33 auto mirrorSourceNode = nodeMap.GetRenderNode<RSDisplayRenderNode>(config.mirrorNodeId);
34 if (mirrorSourceNode == nullptr) {
35 return;
36 }
37 auto displayNode = RSBaseRenderNode::ReinterpretCast<RSDisplayRenderNode>(node);
38 if (displayNode == nullptr) {
39 RS_LOGE("DisplayNodeCommandHelper::Create displayNode is nullptr");
40 return;
41 }
42 displayNode->SetMirrorSource(mirrorSourceNode);
43 }
44 }
45
CreateWithConfigInRS(RSContext & context,NodeId id,const RSDisplayNodeConfig & config)46 std::shared_ptr<RSDisplayRenderNode> DisplayNodeCommandHelper::CreateWithConfigInRS(
47 RSContext& context, NodeId id, const RSDisplayNodeConfig& config)
48 {
49 auto node = std::shared_ptr<RSDisplayRenderNode>(new RSDisplayRenderNode(id, config,
50 context.weak_from_this()), RSRenderNodeGC::NodeDestructor);
51 return node;
52 }
53
AddDisplayNodeToTree(RSContext & context,NodeId id)54 void DisplayNodeCommandHelper::AddDisplayNodeToTree(RSContext& context, NodeId id)
55 {
56 auto& nodeMap = context.GetMutableNodeMap();
57 auto node = nodeMap.GetRenderNode<RSDisplayRenderNode>(id);
58 context.GetGlobalRootRenderNode()->AddChild(node);
59
60 ROSEN_LOGD("DisplayNodeCommandHelper::AddDisplayNodeToTree, id:[%{public}" PRIu64 "]", id);
61 }
62
RemoveDisplayNodeFromTree(RSContext & context,NodeId id)63 void DisplayNodeCommandHelper::RemoveDisplayNodeFromTree(RSContext& context, NodeId id)
64 {
65 auto& nodeMap = context.GetMutableNodeMap();
66 auto node = nodeMap.GetRenderNode<RSDisplayRenderNode>(id);
67 context.GetGlobalRootRenderNode()->RemoveChild(node);
68
69 ROSEN_LOGD("DisplayNodeCommandHelper::RemoveDisplayNodeFromTree, id:[%{public}" PRIu64 "]", id);
70 }
71
SetScreenId(RSContext & context,NodeId id,uint64_t screenId)72 void DisplayNodeCommandHelper::SetScreenId(RSContext& context, NodeId id, uint64_t screenId)
73 {
74 if (auto node = context.GetNodeMap().GetRenderNode<RSDisplayRenderNode>(id)) {
75 node->SetScreenId(screenId);
76 node->NotifyScreenNotSwitching();
77 }
78 }
79
SetRogSize(RSContext & context,NodeId id,uint32_t rogWidth,uint32_t rogHeight)80 void DisplayNodeCommandHelper::SetRogSize(RSContext& context, NodeId id, uint32_t rogWidth, uint32_t rogHeight)
81 {
82 if (auto node = context.GetNodeMap().GetRenderNode<RSDisplayRenderNode>(id)) {
83 node->SetRogSize(rogWidth, rogHeight);
84 }
85 }
86
SetDisplayOffset(RSContext & context,NodeId id,int32_t offsetX,int32_t offsetY)87 void DisplayNodeCommandHelper::SetDisplayOffset(RSContext& context, NodeId id, int32_t offsetX, int32_t offsetY)
88 {
89 if (auto node = context.GetNodeMap().GetRenderNode<RSDisplayRenderNode>(id)) {
90 node->SetDisplayOffset(offsetX, offsetY);
91 }
92 }
93
SetScreenRotation(RSContext & context,NodeId id,const ScreenRotation & screenRotation)94 void DisplayNodeCommandHelper::SetScreenRotation(RSContext& context, NodeId id, const ScreenRotation& screenRotation)
95 {
96 if (auto node = context.GetNodeMap().GetRenderNode<RSDisplayRenderNode>(id)) {
97 node->SetScreenRotation(screenRotation);
98 }
99 }
100
SetSecurityDisplay(RSContext & context,NodeId id,bool isSecurityDisplay)101 void DisplayNodeCommandHelper::SetSecurityDisplay(RSContext& context, NodeId id, bool isSecurityDisplay)
102 {
103 if (auto node = context.GetNodeMap().GetRenderNode<RSDisplayRenderNode>(id)) {
104 node->SetSecurityDisplay(isSecurityDisplay);
105 }
106 }
107
SetDisplayMode(RSContext & context,NodeId id,const RSDisplayNodeConfig & config)108 void DisplayNodeCommandHelper::SetDisplayMode(RSContext& context, NodeId id, const RSDisplayNodeConfig& config)
109 {
110 if (auto node = context.GetNodeMap().GetRenderNode<RSDisplayRenderNode>(id)) {
111 bool isMirror = config.isMirrored;
112 node->SetIsMirrorDisplay(isMirror);
113 if (isMirror) {
114 NodeId mirrorNodeId = config.mirrorNodeId;
115 auto& nodeMap = context.GetNodeMap();
116 auto mirrorSourceNode = nodeMap.GetRenderNode<RSDisplayRenderNode>(mirrorNodeId);
117 if (mirrorSourceNode == nullptr) {
118 ROSEN_LOGW("DisplayNodeCommandHelper::SetDisplayMode fail, displayNodeId:[%{public}" PRIu64 "]"
119 "mirrorNodeId:[%{public}" PRIu64 "]", id, mirrorNodeId);
120 return;
121 }
122 node->SetMirrorSource(mirrorSourceNode);
123 } else {
124 node->ResetMirrorSource();
125 }
126 }
127 }
128
SetBootAnimation(RSContext & context,NodeId nodeId,bool isBootAnimation)129 void DisplayNodeCommandHelper::SetBootAnimation(RSContext& context, NodeId nodeId, bool isBootAnimation)
130 {
131 if (auto node = context.GetNodeMap().GetRenderNode<RSDisplayRenderNode>(nodeId)) {
132 node->SetBootAnimation(isBootAnimation);
133 }
134 }
135
SetScbNodePid(RSContext & context,NodeId nodeId,const std::vector<int32_t> & oldScbPids,int32_t currentScbPid)136 void DisplayNodeCommandHelper::SetScbNodePid(RSContext& context, NodeId nodeId,
137 const std::vector<int32_t>& oldScbPids, int32_t currentScbPid)
138 {
139 if (auto node = context.GetNodeMap().GetRenderNode<RSDisplayRenderNode>(nodeId)) {
140 ROSEN_LOGI("SetScbNodePid NodeId:[%{public}" PRIu64 "] currentPid:[%{public}d]", nodeId, currentScbPid);
141 node->SetScbNodePid(oldScbPids, currentScbPid);
142 }
143 }
144
SetVirtualScreenMuteStatus(RSContext & context,NodeId nodeId,bool virtualScreenMuteStatus)145 void DisplayNodeCommandHelper::SetVirtualScreenMuteStatus(RSContext& context, NodeId nodeId,
146 bool virtualScreenMuteStatus)
147 {
148 if (auto node = context.GetNodeMap().GetRenderNode<RSDisplayRenderNode>(nodeId)) {
149 ROSEN_LOGI("SetVirtualScreenMuteStatus NodeId:[%{public}" PRIu64 "]"
150 " screenId: %{public}" PRIu64 " virtualScreenMuteStatus: %{public}d",
151 nodeId, node->GetScreenId(), virtualScreenMuteStatus);
152 node->SetVirtualScreenMuteStatus(virtualScreenMuteStatus);
153 }
154 }
155 } // namespace Rosen
156 } // namespace OHOS
157