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
18 namespace OHOS {
19 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)20 RSScreenCapability::RSScreenCapability(std::string name, ScreenInterfaceType type, uint32_t phyWidth,
21 uint32_t phyHeight, uint32_t supportLayers, uint32_t virtualDispCount,
22 bool supportWriteBack, const std::vector<RSScreenProps>& props)
23 : name_(name), type_(type), phyWidth_(phyWidth),
24 phyHeight_(phyHeight), supportLayers_(supportLayers),
25 virtualDispCount_(virtualDispCount), supportWriteBack_(supportWriteBack), props_(props)
26 {
27 }
28
SetName(const std::string & name)29 void RSScreenCapability::SetName(const std::string& name)
30 {
31 name_ = name;
32 }
33
SetType(ScreenInterfaceType type)34 void RSScreenCapability::SetType(ScreenInterfaceType type)
35 {
36 type_ = type;
37 }
38
SetPhyWidth(uint32_t phyWidth)39 void RSScreenCapability::SetPhyWidth(uint32_t phyWidth)
40 {
41 phyWidth_ = phyWidth;
42 }
43
SetPhyHeight(uint32_t phyHeight)44 void RSScreenCapability::SetPhyHeight(uint32_t phyHeight)
45 {
46 phyHeight_ = phyHeight;
47 }
48
SetSupportLayers(uint32_t supportLayers)49 void RSScreenCapability::SetSupportLayers(uint32_t supportLayers)
50 {
51 supportLayers_ = supportLayers;
52 }
53
SetVirtualDispCount(uint32_t virtualDispCount)54 void RSScreenCapability::SetVirtualDispCount(uint32_t virtualDispCount)
55 {
56 virtualDispCount_ = virtualDispCount;
57 }
58
SetSupportWriteBack(bool supportWriteBack)59 void RSScreenCapability::SetSupportWriteBack(bool supportWriteBack)
60 {
61 supportWriteBack_ = supportWriteBack;
62 }
63
SetProps(const std::vector<RSScreenProps> & props)64 void RSScreenCapability::SetProps(const std::vector<RSScreenProps>& props)
65 {
66 props_ = props;
67 }
68
GetName() const69 const std::string& RSScreenCapability::GetName() const
70 {
71 return name_;
72 }
73
GetType() const74 ScreenInterfaceType RSScreenCapability::GetType() const
75 {
76 return type_;
77 }
78
GetPhyWidth() const79 uint32_t RSScreenCapability::GetPhyWidth() const
80 {
81 return phyWidth_;
82 }
83
GetPhyHeight() const84 uint32_t RSScreenCapability::GetPhyHeight() const
85 {
86 return phyHeight_;
87 }
88
GetSupportLayers() const89 uint32_t RSScreenCapability::GetSupportLayers() const
90 {
91 return supportLayers_;
92 }
93
GetVirtualDispCount() const94 uint32_t RSScreenCapability::GetVirtualDispCount() const
95 {
96 return virtualDispCount_;
97 }
98
GetSupportWriteBack() const99 bool RSScreenCapability::GetSupportWriteBack() const
100 {
101 return supportWriteBack_;
102 }
103
GetProps() const104 const std::vector<RSScreenProps>& RSScreenCapability::GetProps() const
105 {
106 return props_;
107 }
108
WriteVector(const std::vector<RSScreenProps> & props,Parcel & parcel) const109 bool RSScreenCapability::WriteVector(const std::vector<RSScreenProps> &props, Parcel &parcel) const
110 {
111 for (uint32_t propIndex = 0; propIndex < props.size(); propIndex++) {
112 if (!parcel.WriteParcelable(&props[propIndex])) {
113 return false;
114 }
115 }
116 return true;
117 }
118
ReadVector(std::vector<RSScreenProps> & unmarProps,uint32_t unmarPropCount,Parcel & parcel)119 bool RSScreenCapability::ReadVector(std::vector<RSScreenProps> &unmarProps, uint32_t unmarPropCount, Parcel &parcel)
120 {
121 for (uint32_t propIndex = 0; propIndex < unmarPropCount; propIndex++) {
122 sptr<RSScreenProps> itemProp = parcel.ReadParcelable<RSScreenProps>();
123 if (itemProp == nullptr) {
124 return false;
125 } else {
126 unmarProps.push_back(*itemProp);
127 }
128 }
129 return true;
130 }
131
Marshalling(Parcel & parcel) const132 bool RSScreenCapability::Marshalling(Parcel &parcel) const
133 {
134 if (!parcel.WriteString(name_)) {
135 return false;
136 }
137 if (!parcel.WriteUint32(static_cast<uint32_t>(type_))) {
138 return false;
139 }
140 if (!parcel.WriteUint32(phyWidth_)) {
141 return false;
142 }
143 if (!parcel.WriteUint32(phyHeight_)) {
144 return false;
145 }
146 if (!parcel.WriteUint32(supportLayers_)) {
147 return false;
148 }
149 if (!parcel.WriteUint32(virtualDispCount_)) {
150 return false;
151 }
152 if (!parcel.WriteBool(supportWriteBack_)) {
153 return false;
154 }
155 if (!parcel.WriteUint32(static_cast<uint32_t>(props_.size()))) {
156 return false;
157 }
158 if (!WriteVector(props_, parcel)) {
159 return false;
160 }
161 return true;
162 }
163
Unmarshalling(Parcel & parcel)164 RSScreenCapability* RSScreenCapability::Unmarshalling(Parcel &parcel)
165 {
166 std::string name;
167 uint32_t type;
168 uint32_t phyWidth;
169 uint32_t phyHeight;
170 uint32_t supportLayers;
171 uint32_t virtualDispCount;
172 bool supportWriteBack = false;
173 uint32_t propCount;
174 std::vector<RSScreenProps> props;
175 if (!parcel.ReadString(name)) {
176 return nullptr;
177 }
178 if (!parcel.ReadUint32(type)) {
179 return nullptr;
180 }
181 if (!parcel.ReadUint32(phyWidth)) {
182 return nullptr;
183 }
184 if (!parcel.ReadUint32(phyHeight)) {
185 return nullptr;
186 }
187 if (!parcel.ReadUint32(supportLayers)) {
188 return nullptr;
189 }
190 if (!parcel.ReadUint32(virtualDispCount)) {
191 return nullptr;
192 }
193 if (!parcel.ReadBool(supportWriteBack)) {
194 return nullptr;
195 }
196 if (!parcel.ReadUint32(propCount)) {
197 return nullptr;
198 }
199 if (!ReadVector(props, propCount, parcel)) {
200 return nullptr;
201 }
202 RSScreenCapability* screenCapability = new RSScreenCapability(name, static_cast<ScreenInterfaceType>(type),
203 phyWidth, phyHeight, supportLayers, virtualDispCount, supportWriteBack, props);
204 return screenCapability;
205 }
206 }
207 }