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     }
77 }
78 
SetRogSize(RSContext & context,NodeId id,uint32_t rogWidth,uint32_t rogHeight)79 void DisplayNodeCommandHelper::SetRogSize(RSContext& context, NodeId id, uint32_t rogWidth, uint32_t rogHeight)
80 {
81     if (auto node = context.GetNodeMap().GetRenderNode<RSDisplayRenderNode>(id)) {
82         node->SetRogSize(rogWidth, rogHeight);
83     }
84 }
85 
SetDisplayOffset(RSContext & context,NodeId id,int32_t offsetX,int32_t offsetY)86 void DisplayNodeCommandHelper::SetDisplayOffset(RSContext& context, NodeId id, int32_t offsetX, int32_t offsetY)
87 {
88     if (auto node = context.GetNodeMap().GetRenderNode<RSDisplayRenderNode>(id)) {
89         node->SetDisplayOffset(offsetX, offsetY);
90     }
91 }
92 
SetScreenRotation(RSContext & context,NodeId id,const ScreenRotation & screenRotation)93 void DisplayNodeCommandHelper::SetScreenRotation(RSContext& context, NodeId id, const ScreenRotation& screenRotation)
94 {
95     if (auto node = context.GetNodeMap().GetRenderNode<RSDisplayRenderNode>(id)) {
96         node->SetScreenRotation(screenRotation);
97     }
98 }
99 
SetSecurityDisplay(RSContext & context,NodeId id,bool isSecurityDisplay)100 void DisplayNodeCommandHelper::SetSecurityDisplay(RSContext& context, NodeId id, bool isSecurityDisplay)
101 {
102     if (auto node = context.GetNodeMap().GetRenderNode<RSDisplayRenderNode>(id)) {
103         node->SetSecurityDisplay(isSecurityDisplay);
104     }
105 }
106 
SetDisplayMode(RSContext & context,NodeId id,const RSDisplayNodeConfig & config)107 void DisplayNodeCommandHelper::SetDisplayMode(RSContext& context, NodeId id, const RSDisplayNodeConfig& config)
108 {
109     if (auto node = context.GetNodeMap().GetRenderNode<RSDisplayRenderNode>(id)) {
110         bool isMirror = config.isMirrored;
111         node->SetIsMirrorDisplay(isMirror);
112         if (isMirror) {
113             NodeId mirrorNodeId = config.mirrorNodeId;
114             auto& nodeMap = context.GetNodeMap();
115             auto mirrorSourceNode = nodeMap.GetRenderNode<RSDisplayRenderNode>(mirrorNodeId);
116             if (mirrorSourceNode == nullptr) {
117                 ROSEN_LOGD("DisplayNodeCommandHelper::SetDisplayMode fail, displayNodeId:[%{public}" PRIu64 "]"
118                     "mirrorNodeId:[%{public}" PRIu64 "]", id, mirrorNodeId);
119                 return;
120             }
121             node->SetMirrorSource(mirrorSourceNode);
122         } else {
123             node->ResetMirrorSource();
124         }
125     }
126 }
127 
SetBootAnimation(RSContext & context,NodeId nodeId,bool isBootAnimation)128 void DisplayNodeCommandHelper::SetBootAnimation(RSContext& context, NodeId nodeId, bool isBootAnimation)
129 {
130     if (auto node = context.GetNodeMap().GetRenderNode<RSDisplayRenderNode>(nodeId)) {
131         node->SetBootAnimation(isBootAnimation);
132     }
133 }
134 
SetScbNodePid(RSContext & context,NodeId nodeId,const std::vector<int32_t> & oldScbPids,int32_t currentScbPid)135 void DisplayNodeCommandHelper::SetScbNodePid(RSContext& context, NodeId nodeId,
136     const std::vector<int32_t>& oldScbPids, int32_t currentScbPid)
137 {
138     if (auto node = context.GetNodeMap().GetRenderNode<RSDisplayRenderNode>(nodeId)) {
139         ROSEN_LOGI("SetScbNodePid NodeId:[%{public}" PRIu64 "] currentPid:[%{public}d]", nodeId, currentScbPid);
140         node->SetScbNodePid(oldScbPids, currentScbPid);
141     }
142 }
143 } // namespace Rosen
144 } // namespace OHOS
145