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 "display_info.h" 17 18 #include <new> 19 #include <parcel.h> 20 21 22 namespace OHOS::Rosen { Marshalling(Parcel & parcel) const23bool DisplayInfo::Marshalling(Parcel &parcel) const 24 { 25 return parcel.WriteString(name_) && parcel.WriteUint64(id_) && parcel.WriteUint32(static_cast<uint32_t>(type_)) && 26 parcel.WriteInt32(width_) && parcel.WriteInt32(height_) && 27 parcel.WriteInt32(physicalWidth_) && parcel.WriteInt32(physicalHeight_) && 28 parcel.WriteUint32(refreshRate_) && parcel.WriteUint64(screenId_) && 29 parcel.WriteFloat(virtualPixelRatio_) && parcel.WriteFloat(xDpi_) && parcel.WriteFloat(yDpi_) && 30 parcel.WriteUint32(static_cast<uint32_t>(rotation_)) && 31 parcel.WriteUint32(static_cast<uint32_t>(orientation_)) && 32 parcel.WriteInt32(offsetX_) && parcel.WriteInt32(offsetY_) && 33 parcel.WriteUint32(static_cast<uint32_t>(displayState_)) && 34 parcel.WriteBool(waterfallDisplayCompressionStatus_) && 35 parcel.WriteInt32(dpi_) && parcel.WriteUint32(static_cast<uint32_t>(displayOrientation_)) && 36 parcel.WriteUInt32Vector(colorSpaces_) && parcel.WriteUInt32Vector(hdrFormats_); 37 } 38 Unmarshalling(Parcel & parcel)39DisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel) 40 { 41 DisplayInfo *displayInfo = new(std::nothrow) DisplayInfo(); 42 if (displayInfo == nullptr) { 43 return nullptr; 44 } 45 uint32_t type = (uint32_t)DisplayType::DEFAULT; 46 uint32_t rotation; 47 uint32_t orientation; 48 uint32_t displayState; 49 uint32_t displayOrientation; 50 bool res = parcel.ReadString(displayInfo->name_) && 51 parcel.ReadUint64(displayInfo->id_) && parcel.ReadUint32(type) && 52 parcel.ReadInt32(displayInfo->width_) && parcel.ReadInt32(displayInfo->height_) && 53 parcel.ReadInt32(displayInfo->physicalWidth_) && parcel.ReadInt32(displayInfo->physicalHeight_) && 54 parcel.ReadUint32(displayInfo->refreshRate_) && parcel.ReadUint64(displayInfo->screenId_) && 55 parcel.ReadFloat(displayInfo->virtualPixelRatio_) && 56 parcel.ReadFloat(displayInfo->xDpi_) && parcel.ReadFloat(displayInfo->yDpi_) && 57 parcel.ReadUint32(rotation) && parcel.ReadUint32(orientation) && 58 parcel.ReadInt32(displayInfo->offsetX_) && parcel.ReadInt32(displayInfo->offsetY_) && 59 parcel.ReadUint32(displayState) && parcel.ReadBool(displayInfo->waterfallDisplayCompressionStatus_) && 60 parcel.ReadInt32(displayInfo->dpi_) && parcel.ReadUint32(displayOrientation) && 61 parcel.ReadUInt32Vector(&(displayInfo->colorSpaces_)) && parcel.ReadUInt32Vector(&(displayInfo->hdrFormats_)); 62 if (!res) { 63 delete displayInfo; 64 return nullptr; 65 } 66 displayInfo->type_ = (DisplayType)type; 67 displayInfo->rotation_ = static_cast<Rotation>(rotation); 68 displayInfo->orientation_ = static_cast<Orientation>(orientation); 69 displayInfo->displayState_ = static_cast<DisplayState>(displayState); 70 displayInfo->displayOrientation_ = static_cast<DisplayOrientation>(displayOrientation); 71 return displayInfo; 72 } 73 } // namespace OHOS::Rosen