• 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 namespace OHOS::Rosen {
Marshalling(Parcel & parcel) const19 bool DisplayInfo::Marshalling(Parcel &parcel) const
20 {
21     return parcel.WriteString(name_) && parcel.WriteUint64(id_) && parcel.WriteUint32(type_) &&
22         parcel.WriteInt32(width_) && parcel.WriteInt32(height_) &&
23         parcel.WriteUint32(freshRate_) && parcel.WriteUint32(refreshRate_) && parcel.WriteUint64(screenId_) &&
24         parcel.WriteFloat(virtualPixelRatio_) && parcel.WriteFloat(xDpi_) && parcel.WriteFloat(yDpi_) &&
25         parcel.WriteUint32(static_cast<uint32_t>(rotation_)) &&
26         parcel.WriteUint32(static_cast<uint32_t>(orientation_)) &&
27         parcel.WriteUint32(static_cast<uint32_t>(displayState_));
28 }
29 
Unmarshalling(Parcel & parcel)30 DisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel)
31 {
32     DisplayInfo *displayInfo = new DisplayInfo();
33     uint32_t type = (uint32_t)DisplayType::DEFAULT;
34     uint32_t rotation;
35     uint32_t orientation;
36     uint32_t displayState;
37     bool res =  parcel.ReadString(displayInfo->name_) &&
38         parcel.ReadUint64(displayInfo->id_) && parcel.ReadUint32(type) &&
39         parcel.ReadInt32(displayInfo->width_) && parcel.ReadInt32(displayInfo->height_) &&
40         parcel.ReadUint32(displayInfo->freshRate_) &&
41         parcel.ReadUint32(displayInfo->refreshRate_) && parcel.ReadUint64(displayInfo->screenId_) &&
42         parcel.ReadFloat(displayInfo->virtualPixelRatio_) &&
43         parcel.ReadFloat(displayInfo->xDpi_) && parcel.ReadFloat(displayInfo->yDpi_) &&
44         parcel.ReadUint32(rotation) && parcel.ReadUint32(orientation) &&
45         parcel.ReadUint32(displayState);
46     if (!res) {
47         delete displayInfo;
48         return nullptr;
49     }
50     displayInfo->type_ = (DisplayType)type;
51     displayInfo->rotation_ = static_cast<Rotation>(rotation);
52     displayInfo->orientation_ = static_cast<Orientation>(orientation);
53     displayInfo->displayState_ = static_cast<DisplayState>(displayState);
54     return displayInfo;
55 }
56 } // namespace OHOS::Rosen