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