1 /*
2 * Copyright (c) 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 "cutout_info.h"
17
18 namespace OHOS::Rosen {
CutoutInfo(const std::vector<DMRect> & boundingRects,WaterfallDisplayAreaRects waterfallDisplayAreaRects)19 CutoutInfo::CutoutInfo(const std::vector<DMRect>& boundingRects,
20 WaterfallDisplayAreaRects waterfallDisplayAreaRects) : waterfallDisplayAreaRects_(waterfallDisplayAreaRects),
21 boundingRects_(boundingRects)
22 {
23 }
24
Marshalling(Parcel & parcel) const25 bool CutoutInfo::Marshalling(Parcel &parcel) const
26 {
27 return parcel.WriteInt32(waterfallDisplayAreaRects_.left.posX_) &&
28 parcel.WriteInt32(waterfallDisplayAreaRects_.left.posY_) &&
29 parcel.WriteUint32(waterfallDisplayAreaRects_.left.width_) &&
30 parcel.WriteUint32(waterfallDisplayAreaRects_.left.height_) &&
31 parcel.WriteInt32(waterfallDisplayAreaRects_.top.posX_) &&
32 parcel.WriteInt32(waterfallDisplayAreaRects_.top.posY_) &&
33 parcel.WriteUint32(waterfallDisplayAreaRects_.top.width_) &&
34 parcel.WriteUint32(waterfallDisplayAreaRects_.top.height_) &&
35 parcel.WriteInt32(waterfallDisplayAreaRects_.right.posX_) &&
36 parcel.WriteInt32(waterfallDisplayAreaRects_.right.posY_) &&
37 parcel.WriteUint32(waterfallDisplayAreaRects_.right.width_) &&
38 parcel.WriteUint32(waterfallDisplayAreaRects_.right.height_) &&
39 parcel.WriteInt32(waterfallDisplayAreaRects_.bottom.posX_) &&
40 parcel.WriteInt32(waterfallDisplayAreaRects_.bottom.posY_) &&
41 parcel.WriteUint32(waterfallDisplayAreaRects_.bottom.width_) &&
42 parcel.WriteUint32(waterfallDisplayAreaRects_.bottom.height_) &&
43 WriteBoundingRectsVector(boundingRects_, parcel);
44 }
45
Unmarshalling(Parcel & parcel)46 CutoutInfo *CutoutInfo::Unmarshalling(Parcel &parcel)
47 {
48 WaterfallDisplayAreaRects waterfallDisplayAreaRects;
49 std::vector<DMRect> boundingRects;
50 ReadWaterfallDisplayAreaRects(waterfallDisplayAreaRects, parcel);
51 ReadBoundingRectsVector(boundingRects, parcel);
52 CutoutInfo *cutoutInfo = new CutoutInfo(boundingRects, waterfallDisplayAreaRects);
53 return cutoutInfo;
54 }
55
WriteBoundingRectsVector(const std::vector<DMRect> & boundingRects,Parcel & parcel) const56 bool CutoutInfo::WriteBoundingRectsVector(const std::vector<DMRect>& boundingRects, Parcel &parcel) const
57 {
58 if (!parcel.WriteUint32(static_cast<uint32_t>(boundingRects.size()))) {
59 return false;
60 }
61 for (DMRect rect : boundingRects) {
62 if (!(parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) &&
63 parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_))) {
64 return false;
65 }
66 }
67 return true;
68 }
69
ReadBoundingRectsVector(std::vector<DMRect> & unmarBoundingRects,Parcel & parcel)70 bool CutoutInfo::ReadBoundingRectsVector(std::vector<DMRect>& unmarBoundingRects, Parcel &parcel)
71 {
72 uint32_t size;
73 if (!parcel.ReadUint32(size)) {
74 return false;
75 }
76 for (uint32_t index = 0; index < size; index++) {
77 int32_t posX;
78 int32_t posY;
79 uint32_t width;
80 uint32_t height;
81 if (!(parcel.ReadInt32(posX) && parcel.ReadInt32(posY) &&
82 parcel.ReadUint32(width) && parcel.ReadUint32(height))) {
83 return false;
84 }
85 DMRect rect = {posX, posY, width, height};
86 unmarBoundingRects.push_back(rect);
87 }
88 return true;
89 }
90
ReadWaterfallDisplayAreaRects(WaterfallDisplayAreaRects & waterfallDisplayAreaRects,Parcel & parcel)91 bool CutoutInfo::ReadWaterfallDisplayAreaRects(WaterfallDisplayAreaRects& waterfallDisplayAreaRects, Parcel &parcel)
92 {
93 if (!(parcel.ReadInt32(waterfallDisplayAreaRects.left.posX_) &&
94 parcel.ReadInt32(waterfallDisplayAreaRects.left.posY_) &&
95 parcel.ReadUint32(waterfallDisplayAreaRects.left.width_) &&
96 parcel.ReadUint32(waterfallDisplayAreaRects.left.height_) &&
97 parcel.ReadInt32(waterfallDisplayAreaRects.top.posX_) &&
98 parcel.ReadInt32(waterfallDisplayAreaRects.top.posY_) &&
99 parcel.ReadUint32(waterfallDisplayAreaRects.top.width_) &&
100 parcel.ReadUint32(waterfallDisplayAreaRects.top.height_) &&
101 parcel.ReadInt32(waterfallDisplayAreaRects.right.posX_) &&
102 parcel.ReadInt32(waterfallDisplayAreaRects.right.posY_) &&
103 parcel.ReadUint32(waterfallDisplayAreaRects.right.width_) &&
104 parcel.ReadUint32(waterfallDisplayAreaRects.right.height_) &&
105 parcel.ReadInt32(waterfallDisplayAreaRects.bottom.posX_) &&
106 parcel.ReadInt32(waterfallDisplayAreaRects.bottom.posY_) &&
107 parcel.ReadUint32(waterfallDisplayAreaRects.bottom.width_) &&
108 parcel.ReadUint32(waterfallDisplayAreaRects.bottom.height_))) {
109 return false;
110 }
111 return true;
112 }
113 } // namespace OHOS::Rosen