1e0dac50fSopenharmony_ci/*
2e0dac50fSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3e0dac50fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4e0dac50fSopenharmony_ci * you may not use this file except in compliance with the License.
5e0dac50fSopenharmony_ci * You may obtain a copy of the License at
6e0dac50fSopenharmony_ci *
7e0dac50fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8e0dac50fSopenharmony_ci *
9e0dac50fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10e0dac50fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11e0dac50fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e0dac50fSopenharmony_ci * See the License for the specific language governing permissions and
13e0dac50fSopenharmony_ci * limitations under the License.
14e0dac50fSopenharmony_ci */
15e0dac50fSopenharmony_ci
16e0dac50fSopenharmony_ci#include "display_info.h"
17e0dac50fSopenharmony_ci
18e0dac50fSopenharmony_ci#include <new>
19e0dac50fSopenharmony_ci#include <parcel.h>
20e0dac50fSopenharmony_ci
21e0dac50fSopenharmony_ci
22e0dac50fSopenharmony_cinamespace OHOS::Rosen {
23e0dac50fSopenharmony_cibool DisplayInfo::Marshalling(Parcel &parcel) const
24e0dac50fSopenharmony_ci{
25e0dac50fSopenharmony_ci    return parcel.WriteString(name_) && parcel.WriteUint64(id_) && parcel.WriteUint32(static_cast<uint32_t>(type_)) &&
26e0dac50fSopenharmony_ci        parcel.WriteInt32(width_) && parcel.WriteInt32(height_) &&
27e0dac50fSopenharmony_ci        parcel.WriteInt32(physicalWidth_) && parcel.WriteInt32(physicalHeight_) &&
28e0dac50fSopenharmony_ci        parcel.WriteUint32(refreshRate_) && parcel.WriteUint64(screenId_) &&
29e0dac50fSopenharmony_ci        parcel.WriteFloat(virtualPixelRatio_) && parcel.WriteFloat(densityInCurResolution_) &&
30e0dac50fSopenharmony_ci        parcel.WriteFloat(defaultVirtualPixelRatio_) &&
31e0dac50fSopenharmony_ci        parcel.WriteFloat(xDpi_) && parcel.WriteFloat(yDpi_) &&
32e0dac50fSopenharmony_ci        parcel.WriteUint32(static_cast<uint32_t>(rotation_)) &&
33e0dac50fSopenharmony_ci        parcel.WriteUint32(static_cast<uint32_t>(orientation_)) &&
34e0dac50fSopenharmony_ci        parcel.WriteInt32(offsetX_) && parcel.WriteInt32(offsetY_) &&
35e0dac50fSopenharmony_ci        parcel.WriteUint32(static_cast<uint32_t>(displayState_)) &&
36e0dac50fSopenharmony_ci        parcel.WriteBool(waterfallDisplayCompressionStatus_) &&
37e0dac50fSopenharmony_ci        parcel.WriteInt32(dpi_) && parcel.WriteUint32(static_cast<uint32_t>(displayOrientation_)) &&
38e0dac50fSopenharmony_ci        parcel.WriteUInt32Vector(colorSpaces_) && parcel.WriteUInt32Vector(hdrFormats_) &&
39e0dac50fSopenharmony_ci        parcel.WriteUint32(defaultDeviceRotationOffset_) &&
40e0dac50fSopenharmony_ci        parcel.WriteUint32(availableWidth_) &&
41e0dac50fSopenharmony_ci        parcel.WriteUint32(availableHeight_) && parcel.WriteFloat(scaleX_) &&
42e0dac50fSopenharmony_ci        parcel.WriteFloat(scaleY_) && parcel.WriteFloat(pivotX_) && parcel.WriteFloat(pivotY_) &&
43e0dac50fSopenharmony_ci        parcel.WriteFloat(translateX_) && parcel.WriteFloat(translateY_);
44e0dac50fSopenharmony_ci}
45e0dac50fSopenharmony_ci
46e0dac50fSopenharmony_ciDisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel)
47e0dac50fSopenharmony_ci{
48e0dac50fSopenharmony_ci    DisplayInfo *displayInfo = new(std::nothrow) DisplayInfo();
49e0dac50fSopenharmony_ci    if (displayInfo == nullptr) {
50e0dac50fSopenharmony_ci        return nullptr;
51e0dac50fSopenharmony_ci    }
52e0dac50fSopenharmony_ci    uint32_t type = (uint32_t)DisplayType::DEFAULT;
53e0dac50fSopenharmony_ci    uint32_t rotation;
54e0dac50fSopenharmony_ci    uint32_t orientation;
55e0dac50fSopenharmony_ci    uint32_t displayState;
56e0dac50fSopenharmony_ci    uint32_t displayOrientation;
57e0dac50fSopenharmony_ci    bool res = parcel.ReadString(displayInfo->name_) &&
58e0dac50fSopenharmony_ci        parcel.ReadUint64(displayInfo->id_) && parcel.ReadUint32(type) &&
59e0dac50fSopenharmony_ci        parcel.ReadInt32(displayInfo->width_) && parcel.ReadInt32(displayInfo->height_) &&
60e0dac50fSopenharmony_ci        parcel.ReadInt32(displayInfo->physicalWidth_) && parcel.ReadInt32(displayInfo->physicalHeight_) &&
61e0dac50fSopenharmony_ci        parcel.ReadUint32(displayInfo->refreshRate_) && parcel.ReadUint64(displayInfo->screenId_) &&
62e0dac50fSopenharmony_ci        parcel.ReadFloat(displayInfo->virtualPixelRatio_) && parcel.ReadFloat(displayInfo->densityInCurResolution_) &&
63e0dac50fSopenharmony_ci        parcel.ReadFloat(displayInfo->defaultVirtualPixelRatio_) &&
64e0dac50fSopenharmony_ci        parcel.ReadFloat(displayInfo->xDpi_) && parcel.ReadFloat(displayInfo->yDpi_) &&
65e0dac50fSopenharmony_ci        parcel.ReadUint32(rotation) && parcel.ReadUint32(orientation) &&
66e0dac50fSopenharmony_ci        parcel.ReadInt32(displayInfo->offsetX_) && parcel.ReadInt32(displayInfo->offsetY_) &&
67e0dac50fSopenharmony_ci        parcel.ReadUint32(displayState) && parcel.ReadBool(displayInfo->waterfallDisplayCompressionStatus_) &&
68e0dac50fSopenharmony_ci        parcel.ReadInt32(displayInfo->dpi_) && parcel.ReadUint32(displayOrientation) &&
69e0dac50fSopenharmony_ci        parcel.ReadUInt32Vector(&(displayInfo->colorSpaces_)) &&
70e0dac50fSopenharmony_ci        parcel.ReadUInt32Vector(&(displayInfo->hdrFormats_)) &&
71e0dac50fSopenharmony_ci        parcel.ReadUint32(displayInfo->defaultDeviceRotationOffset_) &&
72e0dac50fSopenharmony_ci        parcel.ReadUint32(displayInfo->availableWidth_) &&
73e0dac50fSopenharmony_ci        parcel.ReadUint32(displayInfo->availableHeight_) && parcel.ReadFloat(displayInfo->scaleX_) &&
74e0dac50fSopenharmony_ci        parcel.ReadFloat(displayInfo->scaleY_) && parcel.ReadFloat(displayInfo->pivotX_) &&
75e0dac50fSopenharmony_ci        parcel.ReadFloat(displayInfo->pivotY_) && parcel.ReadFloat(displayInfo->translateX_) &&
76e0dac50fSopenharmony_ci        parcel.ReadFloat(displayInfo->translateY_);
77e0dac50fSopenharmony_ci    if (!res) {
78e0dac50fSopenharmony_ci        delete displayInfo;
79e0dac50fSopenharmony_ci        return nullptr;
80e0dac50fSopenharmony_ci    }
81e0dac50fSopenharmony_ci    displayInfo->type_ = (DisplayType)type;
82e0dac50fSopenharmony_ci    displayInfo->rotation_ = static_cast<Rotation>(rotation);
83e0dac50fSopenharmony_ci    displayInfo->orientation_ = static_cast<Orientation>(orientation);
84e0dac50fSopenharmony_ci    displayInfo->displayState_ = static_cast<DisplayState>(displayState);
85e0dac50fSopenharmony_ci    displayInfo->displayOrientation_ = static_cast<DisplayOrientation>(displayOrientation);
86e0dac50fSopenharmony_ci    return displayInfo;
87e0dac50fSopenharmony_ci}
88e0dac50fSopenharmony_ci} // namespace OHOS::Rosen