• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright 2020, 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// Imports all the compiled common Flicker library classes and exports them
18// as clean es6 modules rather than having them be commonjs modules
19
20// WM
21const WindowManagerTrace = require('flicker').android.tools.common.traces.wm.WindowManagerTrace;
22const WindowManagerState = require('flicker').android.tools.common.traces.wm.WindowManagerState;
23const WindowManagerTraceEntryBuilder =
24  require('flicker').android.tools.common.traces.wm.WindowManagerTraceEntryBuilder;
25const Activity = require('flicker').android.tools.common.traces.wm.Activity;
26const Configuration = require('flicker').android.tools.common.traces.wm.Configuration;
27const ConfigurationContainer =
28  require('flicker').android.tools.common.traces.wm.ConfigurationContainer;
29const DisplayArea = require('flicker').android.tools.common.traces.wm.DisplayArea;
30const DisplayContent = require('flicker').android.tools.common.traces.wm.DisplayContent;
31const DisplayCutout = require('flicker').android.tools.common.traces.wm.DisplayCutout;
32const KeyguardControllerState =
33  require('flicker').android.tools.common.traces.wm.KeyguardControllerState;
34const RootWindowContainer = require('flicker').android.tools.common.traces.wm.RootWindowContainer;
35const Task = require('flicker').android.tools.common.traces.wm.Task;
36const TaskFragment = require('flicker').android.tools.common.traces.wm.TaskFragment;
37const WindowConfiguration = require('flicker').android.tools.common.traces.wm.WindowConfiguration;
38const WindowContainer = require('flicker').android.tools.common.traces.wm.WindowContainer;
39const WindowLayoutParams = require('flicker').android.tools.common.traces.wm.WindowLayoutParams;
40const WindowManagerPolicy = require('flicker').android.tools.common.traces.wm.WindowManagerPolicy;
41const WindowState = require('flicker').android.tools.common.traces.wm.WindowState;
42const WindowToken = require('flicker').android.tools.common.traces.wm.WindowToken;
43
44// SF
45const HwcCompositionType =
46  require('flicker').android.tools.common.traces.surfaceflinger.HwcCompositionType;
47const Layer = require('flicker').android.tools.common.traces.surfaceflinger.Layer;
48const LayerProperties =
49  require('flicker').android.tools.common.traces.surfaceflinger.LayerProperties;
50const LayerTraceEntry =
51  require('flicker').android.tools.common.traces.surfaceflinger.LayerTraceEntry;
52const LayerTraceEntryBuilder =
53  require('flicker').android.tools.common.traces.surfaceflinger.LayerTraceEntryBuilder;
54const LayersTrace = require('flicker').android.tools.common.traces.surfaceflinger.LayersTrace;
55const Transform = require('flicker').android.tools.common.traces.surfaceflinger.Transform;
56const Display = require('flicker').android.tools.common.traces.surfaceflinger.Display;
57const Region = require('flicker').android.tools.common.datatypes.Region;
58
59// Event Log
60const EventLog = require('flicker').android.tools.common.traces.events.EventLog;
61const CujEvent = require('flicker').android.tools.common.traces.events.CujEvent;
62const CujType = require('flicker').android.tools.common.traces.events.CujType;
63const Event = require('flicker').android.tools.common.traces.events.Event;
64const FlickerEvent = require('flicker').android.tools.common.traces.events.FlickerEvent;
65const FocusEvent = require('flicker').android.tools.common.traces.events.FocusEvent;
66const EventLogParser = require('flicker').android.tools.common.parsers.events.EventLogParser;
67const CujTrace = require('flicker').android.tools.common.parsers.events.CujTrace;
68const Cuj = require('flicker').android.tools.common.parsers.events.Cuj;
69
70// Transitions
71const Transition = require('flicker').android.tools.common.traces.wm.Transition;
72const TransitionType = require('flicker').android.tools.common.traces.wm.TransitionType;
73const TransitionChange = require('flicker').android.tools.common.traces.wm.TransitionChange;
74const TransitionsTrace = require('flicker').android.tools.common.traces.wm.TransitionsTrace;
75const ShellTransitionData = require('flicker').android.tools.common.traces.wm.ShellTransitionData;
76const WmTransitionData = require('flicker').android.tools.common.traces.wm.WmTransitionData;
77
78// Common
79const Size = require('flicker').android.tools.common.datatypes.Size;
80const ActiveBuffer = require('flicker').android.tools.common.datatypes.ActiveBuffer;
81const Color = require('flicker').android.tools.common.datatypes.Color;
82const Insets = require('flicker').android.tools.common.datatypes.Insets;
83const Matrix33 = require('flicker').android.tools.common.datatypes.Matrix33;
84const PlatformConsts = require('flicker').android.tools.common.PlatformConsts;
85const Rotation = require('flicker').android.tools.common.Rotation;
86const Point = require('flicker').android.tools.common.datatypes.Point;
87const PointF = require('flicker').android.tools.common.datatypes.PointF;
88const Rect = require('flicker').android.tools.common.datatypes.Rect;
89const RectF = require('flicker').android.tools.common.datatypes.RectF;
90const WindowingMode = require('flicker').android.tools.common.traces.wm.WindowingMode;
91const CrossPlatform = require('flicker').android.tools.common.CrossPlatform;
92const TimestampFactory = require('flicker').android.tools.common.TimestampFactory;
93
94const EMPTY_SIZE = Size.Companion.EMPTY;
95const EMPTY_BUFFER = ActiveBuffer.Companion.EMPTY;
96const EMPTY_COLOR = Color.Companion.EMPTY;
97const EMPTY_INSETS = Insets.Companion.EMPTY;
98const EMPTY_RECT = Rect.Companion.EMPTY;
99const EMPTY_RECTF = RectF.Companion.EMPTY;
100const EMPTY_POINT = Point.Companion.EMPTY;
101const EMPTY_POINTF = PointF.Companion.EMPTY;
102const EMPTY_MATRIX33 = Matrix33.Companion.identity(0, 0);
103const EMPTY_TRANSFORM = new Transform(0, EMPTY_MATRIX33);
104
105function toSize(proto) {
106  if (proto == null) {
107    return EMPTY_SIZE;
108  }
109  const width = proto.width ?? proto.w ?? 0;
110  const height = proto.height ?? proto.h ?? 0;
111  if (width || height) {
112    return new Size(width, height);
113  }
114  return EMPTY_SIZE;
115}
116
117function toActiveBuffer(proto) {
118  const width = proto?.width ?? 0;
119  const height = proto?.height ?? 0;
120  const stride = proto?.stride ?? 0;
121  const format = proto?.format ?? 0;
122
123  if (width || height || stride || format) {
124    return new ActiveBuffer(width, height, stride, format);
125  }
126  return EMPTY_BUFFER;
127}
128
129function toColor(proto, hasAlpha = true) {
130  if (proto == null) {
131    return EMPTY_COLOR;
132  }
133  const r = proto.r ?? 0;
134  const g = proto.g ?? 0;
135  const b = proto.b ?? 0;
136  let a = proto.a;
137  if (a === null && !hasAlpha) {
138    a = 1;
139  }
140  if (r || g || b || a) {
141    return new Color(r, g, b, a);
142  }
143  return EMPTY_COLOR;
144}
145
146function toPoint(proto) {
147  if (proto == null) {
148    return null;
149  }
150  const x = proto.x ?? 0;
151  const y = proto.y ?? 0;
152  if (x || y) {
153    return new Point(x, y);
154  }
155  return EMPTY_POINT;
156}
157
158function toPointF(proto) {
159  if (proto == null) {
160    return null;
161  }
162  const x = proto.x ?? 0;
163  const y = proto.y ?? 0;
164  if (x || y) {
165    return new PointF(x, y);
166  }
167  return EMPTY_POINTF;
168}
169
170function toInsets(proto) {
171  if (proto == null) {
172    return EMPTY_INSETS;
173  }
174
175  const left = proto?.left ?? 0;
176  const top = proto?.top ?? 0;
177  const right = proto?.right ?? 0;
178  const bottom = proto?.bottom ?? 0;
179  if (left || top || right || bottom) {
180    return new Insets(left, top, right, bottom);
181  }
182  return EMPTY_INSETS;
183}
184
185function toCropRect(proto) {
186  if (proto == null) return EMPTY_RECT;
187
188  const right = proto.right || 0;
189  const left = proto.left || 0;
190  const bottom = proto.bottom || 0;
191  const top = proto.top || 0;
192
193  // crop (0,0) (-1,-1) means no crop
194  if (right == -1 && left == 0 && bottom == -1 && top == 0) EMPTY_RECT;
195
196  if (right - left <= 0 || bottom - top <= 0) return EMPTY_RECT;
197
198  return Rect.Companion.from(left, top, right, bottom);
199}
200
201function toRect(proto) {
202  if (proto == null) {
203    return EMPTY_RECT;
204  }
205
206  const left = proto?.left ?? 0;
207  const top = proto?.top ?? 0;
208  const right = proto?.right ?? 0;
209  const bottom = proto?.bottom ?? 0;
210  if (left || top || right || bottom) {
211    return new Rect(left, top, right, bottom);
212  }
213  return EMPTY_RECT;
214}
215
216function toRectF(proto) {
217  if (proto == null) {
218    return EMPTY_RECTF;
219  }
220
221  const left = proto?.left ?? 0;
222  const top = proto?.top ?? 0;
223  const right = proto?.right ?? 0;
224  const bottom = proto?.bottom ?? 0;
225  if (left || top || right || bottom) {
226    return new RectF(left, top, right, bottom);
227  }
228  return EMPTY_RECTF;
229}
230
231function toRegion(proto) {
232  if (proto == null) {
233    return null;
234  }
235
236  const rects = [];
237  for (let x = 0; x < proto.rect.length; x++) {
238    const rect = proto.rect[x];
239    const parsedRect = toRect(rect);
240    rects.push(parsedRect);
241  }
242
243  return new Region(rects);
244}
245
246function toTransform(proto) {
247  if (proto == null) {
248    return EMPTY_TRANSFORM;
249  }
250  const dsdx = proto.dsdx ?? 0;
251  const dtdx = proto.dtdx ?? 0;
252  const tx = proto.tx ?? 0;
253  const dsdy = proto.dsdy ?? 0;
254  const dtdy = proto.dtdy ?? 0;
255  const ty = proto.ty ?? 0;
256
257  if (dsdx || dtdx || tx || dsdy || dtdy || ty) {
258    const matrix = new Matrix33(dsdx, dtdx, tx, dsdy, dtdy, ty);
259    return new Transform(proto.type ?? 0, matrix);
260  }
261
262  if (proto.type) {
263    return new Transform(proto.type ?? 0, EMPTY_MATRIX33);
264  }
265  return EMPTY_TRANSFORM;
266}
267
268export {
269  Activity,
270  Configuration,
271  ConfigurationContainer,
272  DisplayArea,
273  DisplayContent,
274  KeyguardControllerState,
275  DisplayCutout,
276  RootWindowContainer,
277  Task,
278  TaskFragment,
279  WindowConfiguration,
280  WindowContainer,
281  WindowState,
282  WindowToken,
283  WindowLayoutParams,
284  WindowManagerPolicy,
285  WindowManagerTrace,
286  WindowManagerState,
287  WindowManagerTraceEntryBuilder,
288  // SF
289  HwcCompositionType,
290  Layer,
291  LayerProperties,
292  LayerTraceEntry,
293  LayerTraceEntryBuilder,
294  LayersTrace,
295  Transform,
296  Matrix33,
297  Display,
298  // Eventlog
299  EventLog,
300  CujEvent,
301  CujType,
302  Event,
303  FlickerEvent,
304  FocusEvent,
305  EventLogParser,
306  CujTrace,
307  Cuj,
308  // Transitions
309  Transition,
310  TransitionType,
311  TransitionChange,
312  TransitionsTrace,
313  ShellTransitionData,
314  WmTransitionData,
315  // Common
316  Size,
317  ActiveBuffer,
318  Color,
319  Insets,
320  PlatformConsts,
321  Point,
322  Rect,
323  RectF,
324  Region,
325  Rotation,
326  WindowingMode,
327  CrossPlatform,
328  TimestampFactory,
329  // Service
330  toSize,
331  toActiveBuffer,
332  toColor,
333  toCropRect,
334  toInsets,
335  toPoint,
336  toPointF,
337  toRect,
338  toRectF,
339  toRegion,
340  toTransform,
341  // Constants
342  EMPTY_BUFFER,
343  EMPTY_COLOR,
344  EMPTY_RECT,
345  EMPTY_RECTF,
346  EMPTY_POINT,
347  EMPTY_POINTF,
348  EMPTY_MATRIX33,
349  EMPTY_TRANSFORM,
350};
351