1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.tools.traces.wm
18 
19 import android.graphics.Insets
20 import android.graphics.Rect
21 import android.tools.withCache
22 
23 /** Representation of a display cutout from a WM trace */
24 class DisplayCutout
25 private constructor(
26     val insets: Insets,
27     val boundLeft: Rect,
28     val boundTop: Rect,
29     val boundRight: Rect,
30     val boundBottom: Rect,
31     val waterfallInsets: Insets
32 ) {
equalsnull33     override fun equals(other: Any?): Boolean {
34         if (this === other) return true
35         if (other !is DisplayCutout) return false
36 
37         if (insets != other.insets) return false
38         if (boundLeft != other.boundLeft) return false
39         if (boundTop != other.boundTop) return false
40         if (boundRight != other.boundRight) return false
41         if (boundBottom != other.boundBottom) return false
42         if (waterfallInsets != other.waterfallInsets) return false
43 
44         return true
45     }
46 
hashCodenull47     override fun hashCode(): Int {
48         var result = insets.hashCode()
49         result = 31 * result + boundLeft.hashCode()
50         result = 31 * result + boundTop.hashCode()
51         result = 31 * result + boundRight.hashCode()
52         result = 31 * result + boundBottom.hashCode()
53         result = 31 * result + waterfallInsets.hashCode()
54         return result
55     }
56 
toStringnull57     override fun toString(): String {
58         return "DisplayCutout(" +
59             "insets=$insets, " +
60             "boundLeft=$boundLeft, " +
61             "boundTop=$boundTop, " +
62             "boundRight=$boundRight, " +
63             "boundBottom=$boundBottom, " +
64             "waterfallInsets=$waterfallInsets" +
65             ")"
66     }
67 
68     companion object {
fromnull69         fun from(
70             insets: Insets,
71             boundLeft: Rect,
72             boundTop: Rect,
73             boundRight: Rect,
74             boundBottom: Rect,
75             waterfallInsets: Insets
76         ): DisplayCutout = withCache {
77             DisplayCutout(insets, boundLeft, boundTop, boundRight, boundBottom, waterfallInsets)
78         }
79     }
80 }
81