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 uint32_t size = static_cast<uint32_t>(boundingRects.size());
59 if (!parcel.WriteUint32(size)) {
60 return false;
61 }
62 if (size > MAX_CUTOUT_INFO_SIZE) {
63 return false;
64 }
65 for (DMRect rect : boundingRects) {
66 if (!(parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) &&
67 parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_))) {
68 return false;
69 }
70 }
71 return true;
72 }
73
ReadBoundingRectsVector(std::vector<DMRect> & unmarBoundingRects,Parcel & parcel)74 bool CutoutInfo::ReadBoundingRectsVector(std::vector<DMRect>& unmarBoundingRects, Parcel &parcel)
75 {
76 uint32_t size;
77 if (!parcel.ReadUint32(size)) {
78 return false;
79 }
80 if (size > MAX_CUTOUT_INFO_SIZE) {
81 return false;
82 }
83 for (uint32_t index = 0; index < size; index++) {
84 int32_t posX;
85 int32_t posY;
86 uint32_t width;
87 uint32_t height;
88 if (!(parcel.ReadInt32(posX) && parcel.ReadInt32(posY) &&
89 parcel.ReadUint32(width) && parcel.ReadUint32(height))) {
90 return false;
91 }
92 DMRect rect = {posX, posY, width, height};
93 unmarBoundingRects.push_back(rect);
94 }
95 return true;
96 }
97
ReadWaterfallDisplayAreaRects(WaterfallDisplayAreaRects & waterfallDisplayAreaRects,Parcel & parcel)98 bool CutoutInfo::ReadWaterfallDisplayAreaRects(WaterfallDisplayAreaRects& waterfallDisplayAreaRects, Parcel &parcel)
99 {
100 if (!(parcel.ReadInt32(waterfallDisplayAreaRects.left.posX_) &&
101 parcel.ReadInt32(waterfallDisplayAreaRects.left.posY_) &&
102 parcel.ReadUint32(waterfallDisplayAreaRects.left.width_) &&
103 parcel.ReadUint32(waterfallDisplayAreaRects.left.height_) &&
104 parcel.ReadInt32(waterfallDisplayAreaRects.top.posX_) &&
105 parcel.ReadInt32(waterfallDisplayAreaRects.top.posY_) &&
106 parcel.ReadUint32(waterfallDisplayAreaRects.top.width_) &&
107 parcel.ReadUint32(waterfallDisplayAreaRects.top.height_) &&
108 parcel.ReadInt32(waterfallDisplayAreaRects.right.posX_) &&
109 parcel.ReadInt32(waterfallDisplayAreaRects.right.posY_) &&
110 parcel.ReadUint32(waterfallDisplayAreaRects.right.width_) &&
111 parcel.ReadUint32(waterfallDisplayAreaRects.right.height_) &&
112 parcel.ReadInt32(waterfallDisplayAreaRects.bottom.posX_) &&
113 parcel.ReadInt32(waterfallDisplayAreaRects.bottom.posY_) &&
114 parcel.ReadUint32(waterfallDisplayAreaRects.bottom.width_) &&
115 parcel.ReadUint32(waterfallDisplayAreaRects.bottom.height_))) {
116 return false;
117 }
118 return true;
119 }
120 } // namespace OHOS::Rosen