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 "ui/rs_display_node.h"
17
18 #include "command/rs_display_node_command.h"
19 #include "pipeline/rs_node_map.h"
20 #include "platform/common/rs_log.h"
21 #include "transaction/rs_transaction_proxy.h"
22 namespace OHOS {
23 namespace Rosen {
24
Create(const RSDisplayNodeConfig & displayNodeConfig)25 RSDisplayNode::SharedPtr RSDisplayNode::Create(const RSDisplayNodeConfig& displayNodeConfig)
26 {
27 SharedPtr node(new RSDisplayNode(displayNodeConfig));
28 RSNodeMap::MutableInstance().RegisterNode(node);
29
30 std::unique_ptr<RSCommand> command = std::make_unique<RSDisplayNodeCreate>(node->GetId(), displayNodeConfig);
31 auto transactionProxy = RSTransactionProxy::GetInstance();
32 if (transactionProxy != nullptr) {
33 transactionProxy->AddCommand(command, true);
34 }
35 ROSEN_LOGD("RSDisplayNode::Create, id:%" PRIu64, node->GetId());
36 return node;
37 }
38
ClearChildren()39 void RSDisplayNode::ClearChildren()
40 {
41 auto children = GetChildren();
42 for (auto child : children) {
43 if (auto childPtr = RSNodeMap::Instance().GetNode(child)) {
44 RemoveChild(childPtr);
45 }
46 }
47 }
48
SetScreenId(uint64_t screenId)49 void RSDisplayNode::SetScreenId(uint64_t screenId)
50 {
51 std::unique_ptr<RSCommand> command = std::make_unique<RSDisplayNodeSetScreenId>(GetId(), screenId);
52 auto transactionProxy = RSTransactionProxy::GetInstance();
53 if (transactionProxy != nullptr) {
54 transactionProxy->AddCommand(command, true);
55 }
56 ROSEN_LOGD("RSDisplayNode::SetScreenId, ScreenId:%" PRIu64, screenId);
57 }
58
SetDisplayOffset(int32_t offsetX,int32_t offsetY)59 void RSDisplayNode::SetDisplayOffset(int32_t offsetX, int32_t offsetY)
60 {
61 std::unique_ptr<RSCommand> command = std::make_unique<RSDisplayNodeSetDisplayOffset>(GetId(), offsetX, offsetY);
62 auto transactionProxy = RSTransactionProxy::GetInstance();
63 if (transactionProxy != nullptr) {
64 transactionProxy->AddCommand(command, true);
65 }
66 ROSEN_LOGD("RSDisplayNode::SetDisplayOffset, offsetX:%d, offsetY:%d", offsetX, offsetY);
67 }
68
SetSecurityDisplay(bool isSecurityDisplay)69 void RSDisplayNode::SetSecurityDisplay(bool isSecurityDisplay)
70 {
71 isSecurityDisplay_ = isSecurityDisplay;
72 std::unique_ptr<RSCommand> command = std::make_unique<RSDisplayNodeSetSecurityDisplay>(GetId(), isSecurityDisplay);
73 auto transactionProxy = RSTransactionProxy::GetInstance();
74 if (transactionProxy != nullptr) {
75 transactionProxy->AddCommand(command, true);
76 }
77 ROSEN_LOGD("RSDisplayNode::SetSecurityDisplay, displayNodeId:[%" PRIu64 "] isSecurityDisplay:[%s]", GetId(),
78 isSecurityDisplay ? "true" : "false");
79 }
80
GetSecurityDisplay() const81 bool RSDisplayNode::GetSecurityDisplay() const
82 {
83 return isSecurityDisplay_;
84 }
85
SetDisplayNodeMirrorConfig(const RSDisplayNodeConfig & displayNodeConfig)86 void RSDisplayNode::SetDisplayNodeMirrorConfig(const RSDisplayNodeConfig& displayNodeConfig)
87 {
88 isMirroredDisplay_ = displayNodeConfig.isMirrored;
89 std::unique_ptr<RSCommand> command = std::make_unique<RSDisplayNodeSetDisplayMode>(GetId(), displayNodeConfig);
90 auto transactionProxy = RSTransactionProxy::GetInstance();
91 if (transactionProxy != nullptr) {
92 transactionProxy->AddCommand(command, true);
93 }
94 ROSEN_LOGD("RSDisplayNode::SetDisplayNodeMirrorConfig, displayNodeId:[%" PRIu64 "] isMirrored:[%s]", GetId(),
95 displayNodeConfig.isMirrored ? "true" : "false");
96 }
97
IsMirrorDisplay() const98 bool RSDisplayNode::IsMirrorDisplay() const
99 {
100 return isMirroredDisplay_;
101 }
102
RSDisplayNode(const RSDisplayNodeConfig & config)103 RSDisplayNode::RSDisplayNode(const RSDisplayNodeConfig& config)
104 : RSNode(true), screenId_(config.screenId), offsetX_(0), offsetY_(0), isMirroredDisplay_(config.isMirrored)
105 {
106 (void)screenId_;
107 (void)offsetX_;
108 (void)offsetY_;
109 }
110
111 RSDisplayNode::~RSDisplayNode() = default;
112
113 } // namespace Rosen
114 } // namespace OHOS
115