summaryrefslogtreecommitdiff
path: root/tools/winscope/src/flickerlib/common.js
blob: 7e329f18ec6ac18ba64a4d960a9f15e4ca111e79 (plain)
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
/*
 * Copyright 2020, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Imports all the compiled common Flicker library classes and exports them
// as clean es6 modules rather than having them be commonjs modules

const WindowManagerTrace = require('flicker').com.android.server.wm.traces.common.
    windowmanager.WindowManagerTrace;
const WindowManagerState = require('flicker').com.android.server.wm.traces.common.
    windowmanager.WindowManagerState;

const Activity = require('flicker').com.android.server.wm.traces.common.
    windowmanager.windows.Activity;
const ActivityTask = require('flicker').com.android.server.wm.traces.common.
    windowmanager.windows.ActivityTask;
const Configuration = require('flicker').com.android.server.wm.traces.common.
    windowmanager.windows.Configuration;
const ConfigurationContainer = require('flicker').com.android.server.wm.traces.common.
    windowmanager.windows.ConfigurationContainer;
const DisplayArea = require('flicker').com.android.server.wm.traces.common.
    windowmanager.windows.DisplayArea;
const DisplayContent = require('flicker').com.android.server.wm.traces.common.
    windowmanager.windows.DisplayContent;
const KeyguardControllerState = require('flicker').com.android.server.wm.traces.common.
    windowmanager.windows.KeyguardControllerState;
const RootWindowContainer = require('flicker').com.android.server.wm.traces.common.
    windowmanager.windows.RootWindowContainer;
const WindowConfiguration = require('flicker').com.android.server.wm.traces.common.
    windowmanager.windows.WindowConfiguration;
const WindowContainer = require('flicker').com.android.server.wm.traces.common.
    windowmanager.windows.WindowContainer;
const WindowLayoutParams= require('flicker').com.android.server.wm.traces.common.
    windowmanager.windows.WindowLayoutParams;
const WindowManagerPolicy = require('flicker').com.android.server.wm.traces.common.
    windowmanager.windows.WindowManagerPolicy;
const WindowState = require('flicker').com.android.server.wm.traces.common.
    windowmanager.windows.WindowState;
const WindowToken = require('flicker').com.android.server.wm.traces.common.
    windowmanager.windows.WindowToken;

const Matrix = require('flicker').com.android.server.wm.traces.common.layers.Transform.Matrix;
const Transform = require('flicker').com.android.server.wm.traces.common.layers.Transform;

const Bounds = require('flicker').com.android.server.wm.traces.common.Bounds;
const Buffer = require('flicker').com.android.server.wm.traces.common.Buffer;
const Color = require('flicker').com.android.server.wm.traces.common.Color;
const Point = require('flicker').com.android.server.wm.traces.common.Point;
const Rect = require('flicker').com.android.server.wm.traces.common.Rect;
const RectF = require('flicker').com.android.server.wm.traces.common.RectF;
const Region = require('flicker').com.android.server.wm.traces.common.Region;

function toBounds(proto) {
    if (proto == null) {
        return null
    }
    return new Bounds(proto.width ?? proto.w ?? 0, proto.height ?? proto.h ?? 0)
}

function toBuffer(proto) {
    if (proto == null) {
        return null
    }
    return new Buffer(proto.width ?? 0, proto.height ?? 0, proto.stride ?? 0, proto.format ?? 0)
}

function toColor(proto) {
    if (proto == null) {
        return null
    }
    return new Color(proto.r ?? 0, proto.g ?? 0, proto.b ?? 0, proto.a ?? 0)
}

function toPoint(proto) {
    if (proto == null) {
        return null
    }
    return new Point(proto.x ?? 0, proto.y ?? 0)
}

function toRect(proto) {
    if (proto == null) {
        return null
    }
    return new Rect(proto.left ?? 0, proto.top ?? 0, proto.right ?? 0, proto.bottom ?? 0)
}

function toRectF(proto) {
    if (proto == null) {
        return null
    }
    return new RectF(proto.left ?? 0, proto.top ?? 0, proto.right ?? 0, proto.bottom ?? 0)
}

function toRegion(proto) {
    if (proto == null) {
        return null
    }

    let rects = []
    for (let rectNr in proto.rect) {
        const rect = proto.rect[rectNr]
        const parsedRect = toRect(rect)
        rects.push(parsedRect)
    }

    return new Region(rects)
}

function toTransform(proto) {
    if (proto == null) {
        return null
    }
    const matrix = new Matrix(proto.dsdx ?? 0, proto.dtdx ?? 0,
        proto.tx ?? 0, proto.dsdy ?? 0, proto.dtdy ?? 0, proto.ty ?? 0)
    return new Transform(proto.type ?? 0, matrix)
}

export {
    Activity,
    ActivityTask,
    Configuration,
    ConfigurationContainer,
    DisplayArea,
    DisplayContent,
    KeyguardControllerState,
    RootWindowContainer,
    WindowConfiguration,
    WindowContainer,
    WindowState,
    WindowToken,
    WindowLayoutParams,
    WindowManagerPolicy,
    WindowManagerTrace,
    WindowManagerState,
    Bounds,
    Buffer,
    Color,
    Point,
    Rect,
    RectF,
    Region,
    toBounds,
    toBuffer,
    toColor,
    toPoint,
    toRect,
    toRectF,
    toRegion,
    toTransform
};