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').com.android.server.wm.traces. 22 common.windowmanager.WindowManagerTrace; 23const WindowManagerState = require('flicker').com.android.server.wm.traces. 24 common.windowmanager.WindowManagerState; 25const Activity = require('flicker').com.android.server.wm.traces.common. 26 windowmanager.windows.Activity; 27const Configuration = require('flicker').com.android.server.wm.traces.common. 28 windowmanager.windows.Configuration; 29const ConfigurationContainer = require('flicker').com.android.server.wm.traces. 30 common.windowmanager.windows.ConfigurationContainer; 31const DisplayArea = require('flicker').com.android.server.wm.traces.common. 32 windowmanager.windows.DisplayArea; 33const DisplayContent = require('flicker').com.android.server.wm.traces.common. 34 windowmanager.windows.DisplayContent; 35const KeyguardControllerState = require('flicker').com.android.server.wm. 36 traces.common.windowmanager.windows.KeyguardControllerState; 37const RootWindowContainer = require('flicker').com.android.server.wm.traces. 38 common.windowmanager.windows.RootWindowContainer; 39const Task = require('flicker').com.android.server.wm.traces.common. 40 windowmanager.windows.Task; 41const TaskFragment = require('flicker').com.android.server.wm.traces.common. 42 windowmanager.windows.TaskFragment; 43const WindowConfiguration = require('flicker').com.android.server.wm.traces. 44 common.windowmanager.windows.WindowConfiguration; 45const WindowContainer = require('flicker').com.android.server.wm.traces.common. 46 windowmanager.windows.WindowContainer; 47const WindowLayoutParams= require('flicker').com.android.server.wm.traces. 48 common.windowmanager.windows.WindowLayoutParams; 49const WindowManagerPolicy = require('flicker').com.android.server.wm.traces. 50 common.windowmanager.windows.WindowManagerPolicy; 51const WindowState = require('flicker').com.android.server.wm.traces.common. 52 windowmanager.windows.WindowState; 53const WindowToken = require('flicker').com.android.server.wm.traces.common. 54 windowmanager.windows.WindowToken; 55 56// SF 57const Layer = require('flicker').com.android.server.wm.traces.common. 58 layers.Layer; 59const LayerTraceEntry = require('flicker').com.android.server.wm.traces.common. 60 layers.LayerTraceEntry; 61const LayerTraceEntryBuilder = require('flicker').com.android.server.wm.traces. 62 common.layers.LayerTraceEntryBuilder; 63const LayersTrace = require('flicker').com.android.server.wm.traces.common. 64 layers.LayersTrace; 65const Matrix = require('flicker').com.android.server.wm.traces.common.layers. 66 Transform.Matrix; 67const Transform = require('flicker').com.android.server.wm.traces.common. 68 layers.Transform; 69const Display = require('flicker').com.android.server.wm.traces.common. 70 layers.Display; 71 72// Common 73const Size = require('flicker').com.android.server.wm.traces.common.Size; 74const Buffer = require('flicker').com.android.server.wm.traces.common.Buffer; 75const Color = require('flicker').com.android.server.wm.traces.common.Color; 76const Point = require('flicker').com.android.server.wm.traces.common.Point; 77const Rect = require('flicker').com.android.server.wm.traces.common.Rect; 78const RectF = require('flicker').com.android.server.wm.traces.common.RectF; 79const Region = require('flicker').com.android.server.wm.traces.common.Region; 80 81//Tags 82const Tag = require('flicker').com.android.server.wm.traces.common.tags.Tag; 83const TagState = require('flicker').com.android.server.wm.traces.common.tags.TagState; 84const TagTrace = require('flicker').com.android.server.wm.traces.common.tags.TagTrace; 85 86//Errors 87const Error = require('flicker').com.android.server.wm.traces.common.errors.Error; 88const ErrorState = require('flicker').com.android.server.wm.traces.common.errors.ErrorState; 89const ErrorTrace = require('flicker').com.android.server.wm.traces.common.errors.ErrorTrace; 90 91// Service 92const TaggingEngine = require('flicker').com.android.server.wm.traces.common.service.TaggingEngine; 93 94const EMPTY_BUFFER = new Buffer(0, 0, 0, 0); 95const EMPTY_COLOR = new Color(-1, -1, -1, 0); 96const EMPTY_RECT = new Rect(0, 0, 0, 0); 97const EMPTY_RECTF = new RectF(0, 0, 0, 0); 98const EMPTY_POINT = new Point(0, 0); 99const EMPTY_MATRIX = new Matrix(0, 0, 0, 0, 0, 0); 100const EMPTY_TRANSFORM = new Transform(0, EMPTY_MATRIX); 101 102function toSize(proto) { 103 if (proto == null) { 104 return EMPTY_BOUNDS; 105 } 106 const width = proto.width ?? proto.w ?? 0; 107 const height = proto.height ?? proto.h ?? 0; 108 if (width || height) { 109 return new Size(width, height); 110 } 111 return EMPTY_BOUNDS; 112} 113 114function toBuffer(proto) { 115 const width = proto?.width ?? 0; 116 const height = proto?.height ?? 0; 117 const stride = proto?.stride ?? 0; 118 const format = proto?.format ?? 0; 119 120 if (width || height || stride || format) { 121 return new Buffer(width, height, stride, format); 122 } 123 return EMPTY_BUFFER; 124} 125 126function toColor(proto) { 127 if (proto == null) { 128 return EMPTY_COLOR; 129 } 130 const r = proto.r ?? 0; 131 const g = proto.g ?? 0; 132 const b = proto.b ?? 0; 133 const a = proto.a ?? 0; 134 if (r || g || b || a) { 135 return new Color(r, g, b, a); 136 } 137 return EMPTY_COLOR; 138} 139 140function toPoint(proto) { 141 if (proto == null) { 142 return null; 143 } 144 const x = proto.x ?? 0; 145 const y = proto.y ?? 0; 146 if (x || y) { 147 return new Point(x, y); 148 } 149 return EMPTY_POINT; 150} 151 152function toRect(proto) { 153 if (proto == null) { 154 return EMPTY_RECT; 155 } 156 157 const left = proto?.left ?? 0; 158 const top = proto?.top ?? 0; 159 const right = proto?.right ?? 0; 160 const bottom = proto?.bottom ?? 0; 161 if (left || top || right || bottom) { 162 return new Rect(left, top, right, bottom); 163 } 164 return EMPTY_RECT; 165} 166 167function toRectF(proto) { 168 if (proto == null) { 169 return EMPTY_RECTF; 170 } 171 172 const left = proto?.left ?? 0; 173 const top = proto?.top ?? 0; 174 const right = proto?.right ?? 0; 175 const bottom = proto?.bottom ?? 0; 176 if (left || top || right || bottom) { 177 return new RectF(left, top, right, bottom); 178 } 179 return EMPTY_RECTF; 180} 181 182function toRegion(proto) { 183 if (proto == null) { 184 return null; 185 } 186 187 const rects = []; 188 for (let x = 0; x < proto.rect.length; x++) { 189 const rect = proto.rect[x]; 190 const parsedRect = toRect(rect); 191 rects.push(parsedRect); 192 } 193 194 return new Region(rects); 195} 196 197function toTransform(proto) { 198 if (proto == null) { 199 return EMPTY_TRANSFORM; 200 } 201 const dsdx = proto.dsdx ?? 0; 202 const dtdx = proto.dtdx ?? 0; 203 const tx = proto.tx ?? 0; 204 const dsdy = proto.dsdy ?? 0; 205 const dtdy = proto.dtdy ?? 0; 206 const ty = proto.ty ?? 0; 207 208 if (dsdx || dtdx || tx || dsdy || dtdy || ty) { 209 const matrix = new Matrix(dsdx, dtdx, tx, dsdy, dtdy, ty); 210 return new Transform(proto.type ?? 0, matrix); 211 } 212 213 if (proto.type) { 214 return new Transform(proto.type ?? 0, EMPTY_MATRIX); 215 } 216 return EMPTY_TRANSFORM; 217} 218 219export { 220 Activity, 221 Configuration, 222 ConfigurationContainer, 223 DisplayArea, 224 DisplayContent, 225 KeyguardControllerState, 226 RootWindowContainer, 227 Task, 228 TaskFragment, 229 WindowConfiguration, 230 WindowContainer, 231 WindowState, 232 WindowToken, 233 WindowLayoutParams, 234 WindowManagerPolicy, 235 WindowManagerTrace, 236 WindowManagerState, 237 // SF 238 Layer, 239 LayerTraceEntry, 240 LayerTraceEntryBuilder, 241 LayersTrace, 242 Transform, 243 Matrix, 244 Display, 245 // Tags 246 Tag, 247 TagState, 248 TagTrace, 249 // Errors 250 Error, 251 ErrorState, 252 ErrorTrace, 253 // Common 254 Size, 255 Buffer, 256 Color, 257 Point, 258 Rect, 259 RectF, 260 Region, 261 // Service 262 TaggingEngine, 263 toSize, 264 toBuffer, 265 toColor, 266 toPoint, 267 toRect, 268 toRectF, 269 toRegion, 270 toTransform, 271}; 272