• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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) const23 bool 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.WriteUint32(refreshRate_) && parcel.WriteUint64(screenId_) &&
28         parcel.WriteFloat(virtualPixelRatio_) && parcel.WriteFloat(xDpi_) && parcel.WriteFloat(yDpi_) &&
29         parcel.WriteUint32(static_cast<uint32_t>(rotation_)) &&
30         parcel.WriteUint32(static_cast<uint32_t>(orientation_)) &&
31         parcel.WriteInt32(offsetX_) && parcel.WriteInt32(offsetY_) &&
32         parcel.WriteUint32(static_cast<uint32_t>(displayState_)) &&
33         parcel.WriteBool(waterfallDisplayCompressionStatus_) &&
34         parcel.WriteInt32(dpi_) && parcel.WriteUint32(static_cast<uint32_t>(displayOrientation_));
35 }
36 
Unmarshalling(Parcel & parcel)37 DisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel)
38 {
39     DisplayInfo *displayInfo = new(std::nothrow) DisplayInfo();
40     if (displayInfo == nullptr) {
41         return nullptr;
42     }
43     uint32_t type = (uint32_t)DisplayType::DEFAULT;
44     uint32_t rotation;
45     uint32_t orientation;
46     uint32_t displayState;
47     uint32_t displayOrientation;
48     bool res = parcel.ReadString(displayInfo->name_) &&
49         parcel.ReadUint64(displayInfo->id_) && parcel.ReadUint32(type) &&
50         parcel.ReadInt32(displayInfo->width_) && parcel.ReadInt32(displayInfo->height_) &&
51         parcel.ReadUint32(displayInfo->refreshRate_) && parcel.ReadUint64(displayInfo->screenId_) &&
52         parcel.ReadFloat(displayInfo->virtualPixelRatio_) &&
53         parcel.ReadFloat(displayInfo->xDpi_) && parcel.ReadFloat(displayInfo->yDpi_) &&
54         parcel.ReadUint32(rotation) && parcel.ReadUint32(orientation) &&
55         parcel.ReadInt32(displayInfo->offsetX_) && parcel.ReadInt32(displayInfo->offsetY_) &&
56         parcel.ReadUint32(displayState) && parcel.ReadBool(displayInfo->waterfallDisplayCompressionStatus_) &&
57         parcel.ReadInt32(displayInfo->dpi_) && parcel.ReadUint32(displayOrientation);
58     if (!res) {
59         delete displayInfo;
60         return nullptr;
61     }
62     displayInfo->type_ = (DisplayType)type;
63     displayInfo->rotation_ = static_cast<Rotation>(rotation);
64     displayInfo->orientation_ = static_cast<Orientation>(orientation);
65     displayInfo->displayState_ = static_cast<DisplayState>(displayState);
66     displayInfo->displayOrientation_ = static_cast<DisplayOrientation>(displayOrientation);
67     return displayInfo;
68 }
69 } // namespace OHOS::Rosen