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_data.h"
17
18 namespace OHOS {
19 namespace Rosen {
RSScreenData(RSScreenCapability capability,RSScreenModeInfo activityModeInfo,const std::vector<RSScreenModeInfo> & supportModeInfo,ScreenPowerStatus powerStatus)20 RSScreenData::RSScreenData(RSScreenCapability capability, RSScreenModeInfo activityModeInfo,
21 const std::vector<RSScreenModeInfo>& supportModeInfo, ScreenPowerStatus powerStatus)
22 : capability_(capability), activityModeInfo_(activityModeInfo),
23 supportModeInfo_(supportModeInfo), powerStatus_(powerStatus)
24 {
25 }
26
SetCapability(const RSScreenCapability & capability)27 void RSScreenData::SetCapability(const RSScreenCapability& capability)
28 {
29 capability_ = capability;
30 }
31
SetActivityModeInfo(const RSScreenModeInfo & activityModeInfo)32 void RSScreenData::SetActivityModeInfo(const RSScreenModeInfo& activityModeInfo)
33 {
34 activityModeInfo_ = activityModeInfo;
35 }
36
SetSupportModeInfo(const std::vector<RSScreenModeInfo> & supportModeInfo)37 void RSScreenData::SetSupportModeInfo(const std::vector<RSScreenModeInfo>& supportModeInfo)
38 {
39 supportModeInfo_ = supportModeInfo;
40 }
41
SetPowerStatus(ScreenPowerStatus powerStatus)42 void RSScreenData::SetPowerStatus(ScreenPowerStatus powerStatus)
43 {
44 powerStatus_ = powerStatus;
45 }
46
47
GetCapability() const48 RSScreenCapability RSScreenData::GetCapability() const
49 {
50 return capability_;
51 }
52
GetActivityModeInfo() const53 RSScreenModeInfo RSScreenData::GetActivityModeInfo() const
54 {
55 return activityModeInfo_;
56 }
57
GetSupportModeInfo() const58 const std::vector<RSScreenModeInfo>& RSScreenData::GetSupportModeInfo() const
59 {
60 return supportModeInfo_;
61 }
62
GetPowerStatus() const63 ScreenPowerStatus RSScreenData::GetPowerStatus() const
64 {
65 return powerStatus_;
66 }
67
WriteVector(const std::vector<RSScreenModeInfo> & supportModes,Parcel & parcel) const68 bool RSScreenData::WriteVector(const std::vector<RSScreenModeInfo> &supportModes, Parcel &parcel) const
69 {
70 for (uint32_t modeIndex = 0; modeIndex < supportModes.size(); modeIndex++) {
71 if (!parcel.WriteParcelable(&supportModes[modeIndex])) {
72 return false;
73 }
74 }
75 return true;
76 }
77
ReadVector(std::vector<RSScreenModeInfo> & unmarsupportModes,uint32_t unmarModeCount,Parcel & parcel)78 bool RSScreenData::ReadVector(std::vector<RSScreenModeInfo> &unmarsupportModes, uint32_t unmarModeCount, Parcel &parcel)
79 {
80 for (uint32_t modeIndex = 0; modeIndex < unmarModeCount; modeIndex++) {
81 sptr<RSScreenModeInfo> itemMode = parcel.ReadParcelable<RSScreenModeInfo>();
82 if (itemMode == nullptr) {
83 return false;
84 } else {
85 unmarsupportModes.push_back(*itemMode);
86 }
87 }
88 return true;
89 }
90
Marshalling(Parcel & parcel) const91 bool RSScreenData::Marshalling(Parcel &parcel) const
92 {
93 if (!parcel.WriteParcelable(&capability_)) {
94 return false;
95 }
96 if (!parcel.WriteParcelable(&activityModeInfo_)) {
97 return false;
98 }
99 if (!parcel.WriteUint32(static_cast<uint32_t>(supportModeInfo_.size()))) {
100 return false;
101 }
102 if (!WriteVector(supportModeInfo_, parcel)) {
103 return false;
104 }
105 if (!parcel.WriteUint8(static_cast<uint8_t>(powerStatus_))) {
106 return false;
107 }
108 return true;
109 }
110
Unmarshalling(Parcel & parcel)111 RSScreenData* RSScreenData::Unmarshalling(Parcel &parcel)
112 {
113 sptr<RSScreenCapability> capability;
114 sptr<RSScreenModeInfo> activityModeInfo;
115 uint32_t modeCount;
116 std::vector<RSScreenModeInfo> supportModeInfo;
117 uint8_t powerStatus;
118 capability = parcel.ReadParcelable<RSScreenCapability>();
119 if (capability == nullptr) {
120 return nullptr;
121 }
122 activityModeInfo = parcel.ReadParcelable<RSScreenModeInfo>();
123 if (activityModeInfo == nullptr) {
124 return nullptr;
125 }
126 if (!parcel.ReadUint32(modeCount)) {
127 return nullptr;
128 }
129 if (!ReadVector(supportModeInfo, modeCount, parcel)) {
130 return nullptr;
131 }
132 if (!parcel.ReadUint8(powerStatus)) {
133 return nullptr;
134 }
135 RSScreenData* screenData = new RSScreenData(*capability, *activityModeInfo,
136 supportModeInfo, static_cast<ScreenPowerStatus>(powerStatus));
137 return screenData;
138 }
139 }
140 }
141