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>(sourceMode_)) && 27 parcel.WriteUint32(static_cast<uint32_t>(type_)) && 28 parcel.WriteUint32(modeId_) && parcel.WriteUint32(static_cast<uint32_t>(modes_.size())) && 29 parcel.WriteBool(isExtend_) && parcel.WriteString(serialNumber_) && parcel.WriteUint64(rsId_) && 30 parcel.WriteUint32(mirrorWidth_) && parcel.WriteUint32(mirrorHeight_); 31 if (!res) { 32 return false; 33 } 34 if (modes_.size() > MAX_SUPPORTED_SCREEN_MODES_SIZE) { 35 return false; 36 } 37 for (uint32_t modeIndex = 0; modeIndex < modes_.size(); modeIndex++) { 38 if (parcel.WriteUint32(modes_[modeIndex]->id_) && 39 parcel.WriteUint32(modes_[modeIndex]->height_) && 40 parcel.WriteUint32(modes_[modeIndex]->width_) && 41 parcel.WriteUint32(modes_[modeIndex]->refreshRate_)) { 42 continue; 43 } 44 return false; 45 } 46 return true; 47 } 48 Unmarshalling(Parcel & parcel)49ScreenInfo* ScreenInfo::Unmarshalling(Parcel &parcel) 50 { 51 ScreenInfo* info = new(std::nothrow) ScreenInfo(); 52 if (info == nullptr) { 53 return info; 54 } 55 bool res = info->InnerUnmarshalling(parcel); 56 if (res) { 57 return info; 58 } 59 delete info; 60 return nullptr; 61 } 62 InnerUnmarshalling(Parcel & parcel)63bool ScreenInfo::InnerUnmarshalling(Parcel& parcel) 64 { 65 uint32_t size = 0; 66 uint32_t rotation; 67 uint32_t orientation; 68 uint32_t sourceMode; 69 uint32_t type; 70 name_ = parcel.ReadString(); 71 bool res1 = parcel.ReadUint64(id_) && 72 parcel.ReadUint32(virtualWidth_) && parcel.ReadUint32(virtualHeight_) && 73 parcel.ReadFloat(virtualPixelRatio_) && parcel.ReadUint64(lastParent_) && parcel.ReadUint64(parent_) && 74 parcel.ReadBool(isScreenGroup_) && parcel.ReadUint32(rotation) && 75 parcel.ReadUint32(orientation) && parcel.ReadUint32(sourceMode) && parcel.ReadUint32(type) && 76 parcel.ReadUint32(modeId_) && parcel.ReadUint32(size) && 77 parcel.ReadBool(isExtend_) && parcel.ReadString(serialNumber_) && parcel.ReadUint64(rsId_) && 78 parcel.ReadUint32(mirrorWidth_) && parcel.ReadUint32(mirrorHeight_); 79 if (!res1) { 80 return false; 81 } 82 if (size > MAX_SUPPORTED_SCREEN_MODES_SIZE) { 83 return false; 84 } 85 modes_.clear(); 86 for (uint32_t modeIndex = 0; modeIndex < size; modeIndex++) { 87 sptr<SupportedScreenModes> mode = new(std::nothrow) SupportedScreenModes(); 88 if (mode == nullptr) { 89 return false; 90 } 91 if (parcel.ReadUint32(mode->id_) && 92 parcel.ReadUint32(mode->height_) && 93 parcel.ReadUint32(mode->width_) && 94 parcel.ReadUint32(mode->refreshRate_)) { 95 modes_.push_back(mode); 96 } else { 97 return false; 98 } 99 } 100 rotation_ = static_cast<Rotation>(rotation); 101 orientation_ = static_cast<Orientation>(orientation); 102 sourceMode_ = static_cast<ScreenSourceMode>(sourceMode); 103 type_ = static_cast<ScreenType>(type); 104 return true; 105 } 106 } // namespace OHOS::Rosen