• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 #ifndef FOUNDATION_DMSERVER_CUTOUT_INFO_H
17 #define FOUNDATION_DMSERVER_CUTOUT_INFO_H
18 
19 #include <parcel.h>
20 
21 #include "class_var_definition.h"
22 #include "display.h"
23 #include "dm_common.h"
24 #include "noncopyable.h"
25 
26 namespace OHOS::Rosen {
27 struct DMRect {
28     int32_t posX_;
29     int32_t posY_;
30     uint32_t width_;
31     uint32_t height_;
32 
33     bool operator==(const DMRect& a) const
34     {
35         return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_);
36     }
37 
38     bool operator!=(const DMRect& a) const
39     {
40         return !this->operator==(a);
41     }
42 
IsUninitializedRectDMRect43     bool IsUninitializedRect() const
44     {
45         return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0);
46     }
47 
IsInsideOfDMRect48     bool IsInsideOf(const DMRect& a) const
49     {
50         return (posX_ >= a.posX_ && posY_ >= a.posY_ &&
51             posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_);
52     }
53 };
54 
55 struct WaterfallDisplayAreaRects {
56     DMRect left;
57     DMRect top;
58     DMRect right;
59     DMRect bottom;
60 
isUninitializedWaterfallDisplayAreaRects61     bool isUninitialized() const
62     {
63         return (left.IsUninitializedRect() && top.IsUninitializedRect() && right.IsUninitializedRect() &&
64             bottom.IsUninitializedRect());
65     }
66 };
67 
68 class CutoutInfo : public Parcelable {
69 public:
70     CutoutInfo() = default;
71     CutoutInfo(const std::vector<DMRect>& boundingRects, WaterfallDisplayAreaRects waterfallDisplayAreaRects);
72     ~CutoutInfo() = default;
73     WM_DISALLOW_COPY_AND_MOVE(CutoutInfo);
74 
75     virtual bool Marshalling(Parcel& parcel) const override;
76     static CutoutInfo *Unmarshalling(Parcel& parcel);
77 
78     DEFINE_VAR_FUNC_GET_SET(WaterfallDisplayAreaRects, WaterfallDisplayAreaRects, waterfallDisplayAreaRects);
79     DEFINE_VAR_FUNC_GET_SET(std::vector<DMRect>, BoundingRects, boundingRects);
80 private:
81     const static uint32_t MAX_CUTOUT_INFO_SIZE = 20;
82     bool WriteBoundingRectsVector(const std::vector<DMRect>& boundingRects, Parcel &parcel) const;
83     static bool ReadBoundingRectsVector(std::vector<DMRect>& unmarBoundingRects, Parcel &parcel);
84     static bool ReadWaterfallDisplayAreaRects(WaterfallDisplayAreaRects& waterfallDisplayAreaRects, Parcel &parcel);
85 };
86 } // namespace OHOS::Rosen
87 #endif // FOUNDATION_DMSERVER_CUTOUT_INFO_H