liyujie
2025-08-28 b3810562527858a3b3d98ffa6e9c9c5b0f4a9a8e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
// Copyright 2017 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
 
library fuchsia.ui.gfx;
 
struct vec2 {
  float32 x;
  float32 y;
};
 
struct vec3 {
  float32 x;
  float32 y;
  float32 z;
};
 
struct vec4 {
  float32 x;
  float32 y;
  float32 z;
  float32 w;
};
 
struct mat4 {
  // Column major order.
  array<float32>:16 matrix;
};
 
// TODO(MZ-238): use float32s instead of uint8.
struct ColorRgba {
  uint8 red;
  uint8 green;
  uint8 blue;
  uint8 alpha;
};
 
struct ColorRgb {
  float32 red;
  float32 green;
  float32 blue;
};
 
struct Quaternion {
  float32 x;
  float32 y;
  float32 z;
  float32 w;
};
 
struct FactoredTransform {
  vec3 translation;
  vec3 scale;
  // Point around which rotation and scaling occur.
  vec3 anchor;
  Quaternion rotation;
};
 
union Value {
  float32 vector1;
  vec2 vector2;
  vec3 vector3;
  vec4 vector4;
  mat4 matrix4x4;
  ColorRgba color_rgba;
  ColorRgb color_rgb;
  // Degrees of counter-clockwise rotation in the XY plane.
  float32 degrees;
  Quaternion quaternion;
  FactoredTransform transform;
  // ID of a value-producing resource (an animation or an expression).
  // The type of this value matches the type produced by the named resource.
  uint32 variable_id;
};
 
// A value that is specified explicitly by |value| if |variable_id| is zero,
// or is the value produced by the resource identified by |variable_id|, e.g.
// an animation or expression.  In the latter case, the value produced by the
// resource must be a float32, and |value| is ignored.
struct FloatValue {
  float32 value;
  uint32 variable_id;
};
 
// A value that is specified explicitly by |value| if |variable_id| is zero,
// or is the value produced by the resource identified by |variable_id|, e.g.
// an animation or expression.  In the latter case, the value produced by the
// resource must be a vec2, and |value| is ignored.
struct Vector2Value {
  vec2 value;
  uint32 variable_id;
};
 
// A value that is specified explicitly by |value| if |variable_id| is zero,
// or is the value produced by the resource identified by |variable_id|, e.g.
// an animation or expression.  In the latter case, the value produced by the
// resource must be a vec3, and |value| is ignored.
struct Vector3Value {
  vec3 value;
  uint32 variable_id;
};
 
// A value that is specified explicitly by |value| if |variable_id| is zero,
// or is the value produced by the resource identified by |variable_id|, e.g.
// an animation or expression.  In the latter case, the value produced by the
// resource must be a vec4, and |value| is ignored.
struct Vector4Value {
  vec4 value;
  uint32 variable_id;
};
 
// A value that is specified explicitly by |value| if |variable_id| is zero,
// or is the value produced by the resource identified by |variable_id|, e.g.
// an animation or expression.  In the latter case, the value produced by the
// resource must be a vec4, and |value| is ignored.
struct Matrix4Value {
  mat4 value;
  uint32 variable_id;
};
 
// A value that is specified explicitly by |value| if |variable_id| is zero,
// or is the value produced by the resource identified by |variable_id|, e.g.
// an animation or expression.  In the latter case, the value produced by the
// resource must be a ColorRgb, and |value| is ignored.
struct ColorRgbValue {
  ColorRgb value;
  uint32 variable_id;
};
 
// A value that is specified explicitly by |value| if |variable_id| is zero,
// or is the value produced by the resource identified by |variable_id|, e.g.
// an animation or expression.  In the latter case, the value produced by the
// resource must be a ColorRgba, and |value| is ignored.
struct ColorRgbaValue {
  ColorRgba value;
  uint32 variable_id;
};
 
// A value that is specified explicitly by |value| if |variable_id| is zero,
// or is the value produced by the resource identified by |variable_id|, e.g.
// an animation or expression.  In the latter case, the value produced by the
// resource must be a Quaternion, and |value| is ignored.
struct QuaternionValue {
  Quaternion value;
  uint32 variable_id;
};
 
enum ValueType {
  kNone = 0;
  kVector1 = 1;
  kVector2 = 2;
  kVector3 = 3;
  kVector4 = 4;
  kMatrix4 = 5;
  kColorRgb = 6;
  kColorRgba = 7;
  kQuaternion = 8;
  kFactoredTransform = 9;
};
 
// Describes how nodes interact with hit testings.
enum HitTestBehavior {
  // Apply hit testing to the node's content, its parts, and its children.
  kDefault = 0;
 
  // Suppress hit testing of the node and everything it contains.
  kSuppress = 1;
};
 
// Rendering target metrics associated with a node.
// See also |MetricsEvent|.
struct Metrics {
  // The ratio between the size of one logical pixel within the node's local
  // coordinate system and the size of one physical pixel of the rendering
  // target.
  //
  // This scale factors change in relation to the resolution of the rendering
  // target and the scale transformations applied by containing nodes.
  // They are always strictly positive and non-zero.
  //
  // For example, suppose the rendering target is a high resolution display
  // with a device pixel ratio of 2.0 meaning that each logical pixel
  // within the model corresponds to two physical pixels of the display.
  // Assuming no scale transformations affect the node, then its metrics event
  // will report a scale factor of 2.0.
  //
  // Building on this example, if instead the node's parent applies a
  // scale transformation of 0.25 to the node, then the node's metrics event
  // will report a scale factor of 0.5 indicating that the node should render
  // its content at a reduced resolution and level of detail since a smaller
  // area of physical pixels (half the size in each dimension) will be rendered.
  float32 scale_x;
  float32 scale_y;
  float32 scale_z;
};
 
// Represents an axis-aligned bounding box.  If any of the dimensions has a
// negative extent (e.g. max.x < min.x) then the bounding box is treated as
// empty.
struct BoundingBox {
  vec3 min;
  vec3 max;
};
 
// Represents the properties for a View.
struct ViewProperties {
  // The View's bounding box extents can be defined as:
  //    { bounding_box.min - inset_from_min, bounding_box.max + inset_from_max }
  // Content contained within the View is clipped to this bounding box.
  //
  // TODO(SCN-819): should we just have a vec3 extent instead of a bounding box
  // with a potentially non-zero min?
  BoundingBox bounding_box;
 
  // |insets_from_min| and |insets_from_max| specify the distances between the
  // view's bounding box and that of its parent.
  vec3 inset_from_min;
  vec3 inset_from_max;
 
  // Whether the View can receive a focus event; default is true.  When
  // false, and this View is eligible to receive a focus event, no
  // focus/unfocus event is actually sent to any View.
  bool focus_change = true;
 
  // Whether the View allows geometrically underlying Views to receive input;
  // default is true. When false, Scenic does not send input events to
  // underlying Views.
  bool downward_input = true;
};
 
// Represents the state of a View in Scenic.
struct ViewState {
  // Whether the View is rendering. Default is false. Delivered to the View's
  // corresponding ViewHolder after the View's first frame render request.
  bool is_rendering;
};