1 /*
2 * Copyright (c) 2021 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 "screen_manager/rs_screen_capability.h"
17 #include "platform/common/rs_log.h"
18
19 namespace OHOS {
20 namespace Rosen {
RSScreenCapability(std::string name,ScreenInterfaceType type,uint32_t phyWidth,uint32_t phyHeight,uint32_t supportLayers,uint32_t virtualDispCount,bool supportWriteBack,const std::vector<RSScreenProps> & props)21 RSScreenCapability::RSScreenCapability(std::string name, ScreenInterfaceType type, uint32_t phyWidth,
22 uint32_t phyHeight, uint32_t supportLayers, uint32_t virtualDispCount,
23 bool supportWriteBack, const std::vector<RSScreenProps>& props)
24 : name_(name), type_(type), phyWidth_(phyWidth),
25 phyHeight_(phyHeight), supportLayers_(supportLayers),
26 virtualDispCount_(virtualDispCount), supportWriteBack_(supportWriteBack), props_(props)
27 {
28 }
29
SetName(const std::string & name)30 void RSScreenCapability::SetName(const std::string& name)
31 {
32 name_ = name;
33 }
34
SetType(ScreenInterfaceType type)35 void RSScreenCapability::SetType(ScreenInterfaceType type)
36 {
37 type_ = type;
38 }
39
SetPhyWidth(uint32_t phyWidth)40 void RSScreenCapability::SetPhyWidth(uint32_t phyWidth)
41 {
42 phyWidth_ = phyWidth;
43 }
44
SetPhyHeight(uint32_t phyHeight)45 void RSScreenCapability::SetPhyHeight(uint32_t phyHeight)
46 {
47 phyHeight_ = phyHeight;
48 }
49
SetSupportLayers(uint32_t supportLayers)50 void RSScreenCapability::SetSupportLayers(uint32_t supportLayers)
51 {
52 supportLayers_ = supportLayers;
53 }
54
SetVirtualDispCount(uint32_t virtualDispCount)55 void RSScreenCapability::SetVirtualDispCount(uint32_t virtualDispCount)
56 {
57 virtualDispCount_ = virtualDispCount;
58 }
59
SetSupportWriteBack(bool supportWriteBack)60 void RSScreenCapability::SetSupportWriteBack(bool supportWriteBack)
61 {
62 supportWriteBack_ = supportWriteBack;
63 }
64
SetProps(const std::vector<RSScreenProps> & props)65 void RSScreenCapability::SetProps(const std::vector<RSScreenProps>& props)
66 {
67 props_ = props;
68 }
69
GetName() const70 const std::string& RSScreenCapability::GetName() const
71 {
72 return name_;
73 }
74
GetType() const75 ScreenInterfaceType RSScreenCapability::GetType() const
76 {
77 return type_;
78 }
79
GetPhyWidth() const80 uint32_t RSScreenCapability::GetPhyWidth() const
81 {
82 return phyWidth_;
83 }
84
GetPhyHeight() const85 uint32_t RSScreenCapability::GetPhyHeight() const
86 {
87 return phyHeight_;
88 }
89
GetSupportLayers() const90 uint32_t RSScreenCapability::GetSupportLayers() const
91 {
92 return supportLayers_;
93 }
94
GetVirtualDispCount() const95 uint32_t RSScreenCapability::GetVirtualDispCount() const
96 {
97 return virtualDispCount_;
98 }
99
GetSupportWriteBack() const100 bool RSScreenCapability::GetSupportWriteBack() const
101 {
102 return supportWriteBack_;
103 }
104
GetProps() const105 const std::vector<RSScreenProps>& RSScreenCapability::GetProps() const
106 {
107 return props_;
108 }
109
WriteVector(const std::vector<RSScreenProps> & props,Parcel & parcel) const110 bool RSScreenCapability::WriteVector(const std::vector<RSScreenProps> &props, Parcel &parcel) const
111 {
112 for (uint32_t propIndex = 0; propIndex < props.size(); propIndex++) {
113 if (!parcel.WriteParcelable(&props[propIndex])) {
114 ROSEN_LOGE("RSScreenCapability::WriteVector WriteParcelable failed");
115 return false;
116 }
117 }
118 return true;
119 }
120
ReadVector(std::vector<RSScreenProps> & unmarProps,uint32_t unmarPropCount,Parcel & parcel)121 bool RSScreenCapability::ReadVector(std::vector<RSScreenProps> &unmarProps, uint32_t unmarPropCount, Parcel &parcel)
122 {
123 for (uint32_t propIndex = 0; propIndex < unmarPropCount; propIndex++) {
124 sptr<RSScreenProps> itemProp = parcel.ReadParcelable<RSScreenProps>();
125 if (itemProp == nullptr) {
126 return false;
127 } else {
128 unmarProps.push_back(*itemProp);
129 }
130 }
131 return true;
132 }
133
Marshalling(Parcel & parcel) const134 bool RSScreenCapability::Marshalling(Parcel &parcel) const
135 {
136 if (!parcel.WriteString(name_)) {
137 ROSEN_LOGE("RSScreenCapability::Marshalling WriteString failed");
138 return false;
139 }
140 if (!parcel.WriteUint32(static_cast<uint32_t>(type_))) {
141 ROSEN_LOGE("RSScreenCapability::Marshalling WriteUint32 1 failed");
142 return false;
143 }
144 if (!parcel.WriteUint32(phyWidth_)) {
145 ROSEN_LOGE("RSScreenCapability::Marshalling WriteUint32 2 failed");
146 return false;
147 }
148 if (!parcel.WriteUint32(phyHeight_)) {
149 ROSEN_LOGE("RSScreenCapability::Marshalling WriteUint32 3 failed");
150 return false;
151 }
152 if (!parcel.WriteUint32(supportLayers_)) {
153 ROSEN_LOGE("RSScreenCapability::Marshalling WriteUint32 4 failed");
154 return false;
155 }
156 if (!parcel.WriteUint32(virtualDispCount_)) {
157 ROSEN_LOGE("RSScreenCapability::Marshalling WriteUint32 5 failed");
158 return false;
159 }
160 if (!parcel.WriteBool(supportWriteBack_)) {
161 ROSEN_LOGE("RSScreenCapability::Marshalling WriteBool failed");
162 return false;
163 }
164 if (!parcel.WriteUint32(static_cast<uint32_t>(props_.size()))) {
165 ROSEN_LOGE("RSScreenCapability::Marshalling WriteUint32 6 failed");
166 return false;
167 }
168 if (!WriteVector(props_, parcel)) {
169 ROSEN_LOGE("RSScreenCapability::Marshalling WriteVector failed");
170 return false;
171 }
172 return true;
173 }
174
Unmarshalling(Parcel & parcel)175 RSScreenCapability* RSScreenCapability::Unmarshalling(Parcel &parcel)
176 {
177 std::string name;
178 uint32_t type;
179 uint32_t phyWidth;
180 uint32_t phyHeight;
181 uint32_t supportLayers;
182 uint32_t virtualDispCount;
183 bool supportWriteBack = false;
184 uint32_t propCount;
185 std::vector<RSScreenProps> props;
186 if (!parcel.ReadString(name)) {
187 ROSEN_LOGE("RSScreenCapability::Unmarshalling ReadString failed");
188 return nullptr;
189 }
190 if (!parcel.ReadUint32(type)) {
191 ROSEN_LOGE("RSScreenCapability::Unmarshalling ReadUint32 type failed");
192 return nullptr;
193 }
194 if (!parcel.ReadUint32(phyWidth)) {
195 ROSEN_LOGE("RSScreenCapability::Unmarshalling ReadUint32 phyWidth failed");
196 return nullptr;
197 }
198 if (!parcel.ReadUint32(phyHeight)) {
199 ROSEN_LOGE("RSScreenCapability::Unmarshalling ReadUint32 phyHeight failed");
200 return nullptr;
201 }
202 if (!parcel.ReadUint32(supportLayers)) {
203 ROSEN_LOGE("RSScreenCapability::Unmarshalling ReadUint32 supportLayers failed");
204 return nullptr;
205 }
206 if (!parcel.ReadUint32(virtualDispCount)) {
207 ROSEN_LOGE("RSScreenCapability::Unmarshalling ReadUint32 virtualDispCount failed");
208 return nullptr;
209 }
210 if (!parcel.ReadBool(supportWriteBack)) {
211 ROSEN_LOGE("RSScreenCapability::Unmarshalling ReadBool supportWriteBack failed");
212 return nullptr;
213 }
214 if (!parcel.ReadUint32(propCount)) {
215 ROSEN_LOGE("RSScreenCapability::Unmarshalling ReadUint32 propCount failed");
216 return nullptr;
217 }
218 if (!ReadVector(props, propCount, parcel)) {
219 ROSEN_LOGE("RSScreenCapability::Unmarshalling ReadVector failed");
220 return nullptr;
221 }
222 RSScreenCapability* screenCapability = new RSScreenCapability(name, static_cast<ScreenInterfaceType>(type),
223 phyWidth, phyHeight, supportLayers, virtualDispCount, supportWriteBack, props);
224 return screenCapability;
225 }
226 }
227 }