• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_LOGI("RSDisplayNode::Create, id:%{public}" PRIu64, node->GetId());
36     return node;
37 }
38 
Marshalling(Parcel & parcel) const39 bool RSDisplayNode::Marshalling(Parcel& parcel) const
40 {
41     return parcel.WriteUint64(GetId()) && parcel.WriteUint64(screenId_) && parcel.WriteBool(isMirroredDisplay_);
42 }
43 
Unmarshalling(Parcel & parcel)44 RSDisplayNode::SharedPtr RSDisplayNode::Unmarshalling(Parcel& parcel)
45 {
46     uint64_t id = UINT64_MAX;
47     uint64_t screenId = UINT64_MAX;
48     bool isMirrored = false;
49     if (!(parcel.ReadUint64(id) && parcel.ReadUint64(screenId) && parcel.ReadBool(isMirrored))) {
50         ROSEN_LOGE("RSDisplayNode::Unmarshalling, read param failed");
51         return nullptr;
52     }
53 
54     if (auto prevNode = RSNodeMap::Instance().GetNode(id)) {
55         // if the node id is already in the map, we should not create a new node
56         return prevNode->ReinterpretCastTo<RSDisplayNode>();
57     }
58 
59     RSDisplayNodeConfig config { .screenId = screenId, .isMirrored = isMirrored };
60 
61     SharedPtr displayNode(new RSDisplayNode(config, id));
62     RSNodeMap::MutableInstance().RegisterNode(displayNode);
63 
64     return displayNode;
65 }
66 
ClearChildren()67 void RSDisplayNode::ClearChildren()
68 {
69     auto children = GetChildren();
70     for (auto child : children) {
71         if (auto childPtr = RSNodeMap::Instance().GetNode(child)) {
72             RemoveChild(childPtr);
73         }
74     }
75 }
76 
SetScreenId(uint64_t screenId)77 void RSDisplayNode::SetScreenId(uint64_t screenId)
78 {
79     std::unique_ptr<RSCommand> command = std::make_unique<RSDisplayNodeSetScreenId>(GetId(), screenId);
80     auto transactionProxy = RSTransactionProxy::GetInstance();
81     if (transactionProxy != nullptr) {
82         transactionProxy->AddCommand(command, true);
83     }
84     ROSEN_LOGD("RSDisplayNode::SetScreenId, ScreenId:%{public}" PRIu64, screenId);
85 }
86 
OnBoundsSizeChanged() const87 void RSDisplayNode::OnBoundsSizeChanged() const
88 {
89     auto bounds = GetStagingProperties().GetBounds();
90     ROSEN_LOGI("RSDisplayNode::OnBoundsSizeChanged, w: %{public}d, h: %{public}d.",
91         (uint32_t)bounds.z_, (uint32_t)bounds.w_);
92     std::unique_ptr<RSCommand> command = std::make_unique<RSDisplayNodeSetRogSize>(GetId(), bounds.z_, bounds.w_);
93     auto transactionProxy = RSTransactionProxy::GetInstance();
94     if (transactionProxy != nullptr) {
95         transactionProxy->AddCommand(command, true);
96     }
97 }
98 
SetDisplayOffset(int32_t offsetX,int32_t offsetY)99 void RSDisplayNode::SetDisplayOffset(int32_t offsetX, int32_t offsetY)
100 {
101     std::unique_ptr<RSCommand> command = std::make_unique<RSDisplayNodeSetDisplayOffset>(GetId(), offsetX, offsetY);
102     auto transactionProxy = RSTransactionProxy::GetInstance();
103     if (transactionProxy != nullptr) {
104         transactionProxy->AddCommand(command, true);
105     }
106     ROSEN_LOGD("RSDisplayNode::SetDisplayOffset, offsetX:%{public}d, offsetY:%{public}d", offsetX, offsetY);
107 }
108 
SetSecurityDisplay(bool isSecurityDisplay)109 void RSDisplayNode::SetSecurityDisplay(bool isSecurityDisplay)
110 {
111     isSecurityDisplay_ = isSecurityDisplay;
112     std::unique_ptr<RSCommand> command = std::make_unique<RSDisplayNodeSetSecurityDisplay>(GetId(), isSecurityDisplay);
113     auto transactionProxy = RSTransactionProxy::GetInstance();
114     if (transactionProxy != nullptr) {
115         transactionProxy->AddCommand(command, true);
116     }
117     ROSEN_LOGD("RSDisplayNode::SetSecurityDisplay, displayNodeId:[%{public}" PRIu64 "]"
118         " isSecurityDisplay:[%{public}s]", GetId(), isSecurityDisplay ? "true" : "false");
119 }
120 
GetSecurityDisplay() const121 bool RSDisplayNode::GetSecurityDisplay() const
122 {
123     return isSecurityDisplay_;
124 }
125 
SetDisplayNodeMirrorConfig(const RSDisplayNodeConfig & displayNodeConfig)126 void RSDisplayNode::SetDisplayNodeMirrorConfig(const RSDisplayNodeConfig& displayNodeConfig)
127 {
128     isMirroredDisplay_ = displayNodeConfig.isMirrored;
129     std::unique_ptr<RSCommand> command = std::make_unique<RSDisplayNodeSetDisplayMode>(GetId(), displayNodeConfig);
130     auto transactionProxy = RSTransactionProxy::GetInstance();
131     if (transactionProxy != nullptr) {
132         transactionProxy->AddCommand(command, true);
133     }
134     ROSEN_LOGD("RSDisplayNode::SetDisplayNodeMirrorConfig, displayNodeId:[%{public}" PRIu64 "]"
135         " isMirrored:[%{public}s]", GetId(), displayNodeConfig.isMirrored ? "true" : "false");
136 }
137 
SetScreenRotation(const uint32_t & rotation)138 void RSDisplayNode::SetScreenRotation(const uint32_t& rotation)
139 {
140     ScreenRotation screenRotation = ScreenRotation::ROTATION_0;
141     switch (rotation) {
142         case 0: // Rotation::ROTATION_0
143             screenRotation = ScreenRotation::ROTATION_0;
144             break;
145         case 1: // Rotation::ROTATION_90
146             screenRotation = ScreenRotation::ROTATION_90;
147             break;
148         case 2: // Rotation::ROTATION_180
149             screenRotation = ScreenRotation::ROTATION_180;
150             break;
151         case 3: // Rotation::ROTATION_270
152             screenRotation = ScreenRotation::ROTATION_270;
153             break;
154         default:
155             screenRotation = ScreenRotation::INVALID_SCREEN_ROTATION;
156             break;
157     }
158     std::unique_ptr<RSCommand> command = std::make_unique<RSDisplayNodeSetScreenRotation>(GetId(), screenRotation);
159     auto transactionProxy = RSTransactionProxy::GetInstance();
160     if (transactionProxy != nullptr) {
161         transactionProxy->AddCommand(command, true);
162     }
163     ROSEN_LOGI("RSDisplayNode::SetScreenRotation, displayNodeId:[%{public}" PRIu64 "]"
164                " screenRotation:[%{public}d]", GetId(), rotation);
165 }
166 
IsMirrorDisplay() const167 bool RSDisplayNode::IsMirrorDisplay() const
168 {
169     return isMirroredDisplay_;
170 }
171 
RSDisplayNode(const RSDisplayNodeConfig & config)172 RSDisplayNode::RSDisplayNode(const RSDisplayNodeConfig& config)
173     : RSNode(true), screenId_(config.screenId), offsetX_(0), offsetY_(0), isMirroredDisplay_(config.isMirrored)
174 {
175     (void)screenId_;
176     (void)offsetX_;
177     (void)offsetY_;
178 }
179 
RSDisplayNode(const RSDisplayNodeConfig & config,NodeId id)180 RSDisplayNode::RSDisplayNode(const RSDisplayNodeConfig& config, NodeId id)
181     : RSNode(true, id), screenId_(config.screenId), offsetX_(0), offsetY_(0), isMirroredDisplay_(config.isMirrored)
182 {}
183 
SetBootAnimation(bool isBootAnimation)184 void RSDisplayNode::SetBootAnimation(bool isBootAnimation)
185 {
186     isBootAnimation_ = isBootAnimation;
187     std::unique_ptr<RSCommand> command = std::make_unique<RSDisplayNodeSetBootAnimation>(GetId(), isBootAnimation);
188     auto transactionProxy = RSTransactionProxy::GetInstance();
189     if (transactionProxy != nullptr) {
190         transactionProxy->AddCommand(command, true);
191     }
192 }
193 
GetBootAnimation() const194 bool RSDisplayNode::GetBootAnimation() const
195 {
196     return isBootAnimation_;
197 }
198 
199 RSDisplayNode::~RSDisplayNode() = default;
200 
201 } // namespace Rosen
202 } // namespace OHOS
203