xref: /aosp_15_r20/development/tools/winscope/src/trace/trace_rect_builder.ts (revision 90c8c64db3049935a07c6143d7fd006e26f8ecca)
1/*
2 * Copyright (C) 2024 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
17import {Region} from 'common/geometry/region';
18import {TransformMatrix} from 'common/geometry/transform_matrix';
19import {Transform} from 'parsers/surface_flinger/transform_utils';
20import {TraceRect} from './trace_rect';
21
22export class TraceRectBuilder {
23  x: number | undefined;
24  y: number | undefined;
25  w: number | undefined;
26  h: number | undefined;
27  id: string | undefined;
28  name: string | undefined;
29  cornerRadius: number | undefined;
30  transform: TransformMatrix = Transform.EMPTY.matrix;
31  groupId: number | undefined;
32  isVisible: boolean | undefined;
33  isDisplay: boolean | undefined;
34  isActiveDisplay = false;
35  depth: number | undefined;
36  opacity: number | undefined;
37  isSpy: boolean | undefined;
38  fillRegion: Region | undefined;
39
40  setX(value: number) {
41    this.x = value;
42    return this;
43  }
44
45  setY(value: number) {
46    this.y = value;
47    return this;
48  }
49
50  setWidth(value: number) {
51    this.w = value;
52    return this;
53  }
54
55  setHeight(value: number) {
56    this.h = value;
57    return this;
58  }
59
60  setId(value: string) {
61    this.id = value;
62    return this;
63  }
64
65  setName(value: string) {
66    this.name = value;
67    return this;
68  }
69
70  setCornerRadius(value: number) {
71    this.cornerRadius = value;
72    return this;
73  }
74
75  setTransform(value: TransformMatrix) {
76    this.transform = value;
77    return this;
78  }
79
80  setGroupId(value: number) {
81    this.groupId = value;
82    return this;
83  }
84
85  setIsVisible(value: boolean) {
86    this.isVisible = value;
87    return this;
88  }
89
90  setIsDisplay(value: boolean) {
91    this.isDisplay = value;
92    return this;
93  }
94
95  setIsActiveDisplay(value: boolean) {
96    this.isActiveDisplay = value;
97    return this;
98  }
99
100  setDepth(value: number) {
101    this.depth = value;
102    return this;
103  }
104
105  setOpacity(value: number) {
106    this.opacity = value;
107    return this;
108  }
109
110  setIsSpy(value: boolean) {
111    this.isSpy = value;
112    return this;
113  }
114
115  setFillRegion(region: Region | undefined) {
116    this.fillRegion = region;
117    return this;
118  }
119
120  build(): TraceRect {
121    if (this.x === undefined) {
122      throw new Error('x not set');
123    }
124
125    if (this.y === undefined) {
126      throw new Error('y not set');
127    }
128
129    if (this.w === undefined) {
130      throw new Error('width not set');
131    }
132
133    if (this.h === undefined) {
134      throw new Error('height not set');
135    }
136
137    if (this.id === undefined) {
138      throw new Error('id not set');
139    }
140
141    if (this.name === undefined) {
142      throw new Error('name not set');
143    }
144
145    if (this.cornerRadius === undefined) {
146      throw new Error('cornerRadius not set');
147    }
148
149    if (this.groupId === undefined) {
150      throw new Error('groupId not set');
151    }
152
153    if (this.isVisible === undefined) {
154      throw new Error('isVisible not set');
155    }
156
157    if (this.isDisplay === undefined) {
158      throw new Error('isDisplay not set');
159    }
160
161    if (this.depth === undefined) {
162      throw new Error('depth not set');
163    }
164
165    if (this.isSpy === undefined) {
166      throw new Error('isSpy not set');
167    }
168
169    return new TraceRect(
170      this.x,
171      this.y,
172      this.w,
173      this.h,
174      this.id,
175      this.name,
176      this.cornerRadius,
177      this.transform,
178      this.groupId,
179      this.isVisible,
180      this.isDisplay,
181      this.isActiveDisplay,
182      this.depth,
183      this.opacity,
184      this.isSpy,
185      this.fillRegion,
186    );
187  }
188}
189