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 "screen_info.h" 17 18 namespace OHOS::Rosen { Marshalling(Parcel & parcel) const19bool ScreenInfo::Marshalling(Parcel &parcel) const 20 { 21 bool res = parcel.WriteString(name_) && parcel.WriteUint64(id_) && 22 parcel.WriteUint32(virtualWidth_) && parcel.WriteUint32(virtualHeight_) && 23 parcel.WriteFloat(virtualPixelRatio_) && parcel.WriteUint64(lastParent_) && parcel.WriteUint64(parent_) && 24 parcel.WriteBool(isScreenGroup_) && parcel.WriteUint32(static_cast<uint32_t>(rotation_)) && 25 parcel.WriteUint32(static_cast<uint32_t>(orientation_)) && 26 parcel.WriteUint32(static_cast<uint32_t>(type_)) && 27 parcel.WriteUint32(modeId_) && parcel.WriteUint32(static_cast<uint32_t>(modes_.size())); 28 if (!res) { 29 return false; 30 } 31 for (uint32_t modeIndex = 0; modeIndex < modes_.size(); modeIndex++) { 32 if (parcel.WriteUint32(modes_[modeIndex]->height_) && 33 parcel.WriteUint32(modes_[modeIndex]->width_) && 34 parcel.WriteUint32(modes_[modeIndex]->refreshRate_)) { 35 continue; 36 } 37 return false; 38 } 39 return true; 40 } 41 Unmarshalling(Parcel & parcel)42ScreenInfo* ScreenInfo::Unmarshalling(Parcel &parcel) 43 { 44 ScreenInfo* info = new(std::nothrow) ScreenInfo(); 45 if (info == nullptr) { 46 return info; 47 } 48 bool res = info->InnerUnmarshalling(parcel); 49 if (res) { 50 return info; 51 } 52 delete info; 53 return nullptr; 54 } 55 InnerUnmarshalling(Parcel & parcel)56bool ScreenInfo::InnerUnmarshalling(Parcel& parcel) 57 { 58 uint32_t size = 0; 59 uint32_t rotation; 60 uint32_t orientation; 61 uint32_t type; 62 name_ = parcel.ReadString(); 63 bool res1 = parcel.ReadUint64(id_) && 64 parcel.ReadUint32(virtualWidth_) && parcel.ReadUint32(virtualHeight_) && 65 parcel.ReadFloat(virtualPixelRatio_) && parcel.ReadUint64(lastParent_) && parcel.ReadUint64(parent_) && 66 parcel.ReadBool(isScreenGroup_) && parcel.ReadUint32(rotation) && 67 parcel.ReadUint32(orientation) && parcel.ReadUint32(type) && 68 parcel.ReadUint32(modeId_) && parcel.ReadUint32(size); 69 if (!res1) { 70 return false; 71 } 72 modes_.clear(); 73 for (uint32_t modeIndex = 0; modeIndex < size; modeIndex++) { 74 sptr<SupportedScreenModes> mode = new(std::nothrow) SupportedScreenModes(); 75 if (mode == nullptr) { 76 return false; 77 } 78 if (parcel.ReadUint32(mode->height_) && 79 parcel.ReadUint32(mode->width_) && 80 parcel.ReadUint32(mode->refreshRate_)) { 81 modes_.push_back(mode); 82 } else { 83 return false; 84 } 85 } 86 rotation_ = static_cast<Rotation>(rotation); 87 orientation_ = static_cast<Orientation>(orientation); 88 type_ = static_cast<ScreenType>(type); 89 return true; 90 } 91 } // namespace OHOS::Rosen