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