• 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 }
35 
Unmarshalling(Parcel & parcel)36 DisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel)
37 {
38     DisplayInfo *displayInfo = new(std::nothrow) DisplayInfo();
39     if (displayInfo == nullptr) {
40         return nullptr;
41     }
42     uint32_t type = (uint32_t)DisplayType::DEFAULT;
43     uint32_t rotation;
44     uint32_t orientation;
45     uint32_t displayState;
46     bool res = parcel.ReadString(displayInfo->name_) &&
47         parcel.ReadUint64(displayInfo->id_) && parcel.ReadUint32(type) &&
48         parcel.ReadInt32(displayInfo->width_) && parcel.ReadInt32(displayInfo->height_) &&
49         parcel.ReadUint32(displayInfo->refreshRate_) && parcel.ReadUint64(displayInfo->screenId_) &&
50         parcel.ReadFloat(displayInfo->virtualPixelRatio_) &&
51         parcel.ReadFloat(displayInfo->xDpi_) && parcel.ReadFloat(displayInfo->yDpi_) &&
52         parcel.ReadUint32(rotation) && parcel.ReadUint32(orientation) &&
53         parcel.ReadInt32(displayInfo->offsetX_) && parcel.ReadInt32(displayInfo->offsetY_) &&
54         parcel.ReadUint32(displayState) && parcel.ReadBool(displayInfo->waterfallDisplayCompressionStatus_);
55     if (!res) {
56         delete displayInfo;
57         return nullptr;
58     }
59     displayInfo->type_ = (DisplayType)type;
60     displayInfo->rotation_ = static_cast<Rotation>(rotation);
61     displayInfo->orientation_ = static_cast<Orientation>(orientation);
62     displayInfo->displayState_ = static_cast<DisplayState>(displayState);
63     return displayInfo;
64 }
65 } // namespace OHOS::Rosen