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
content / browser / resources / gpu / browser_bridge.ts [blame]
// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {assert} from 'chrome://resources/js/assert.js';
import {addWebUiListener, sendWithPromise} from 'chrome://resources/js/cr.js';
export interface ClientInfo {
angle_commit_id: string;
command_line: string;
graphics_backend: string;
operating_system: string;
revision_identifier: string;
version: string;
}
export interface Problem {
affectedGpuSettings: string[];
crBugs: string[];
description: string;
tag: string;
}
export interface FeatureStatus {
featureStatus: Record<string, string>;
problems: Problem[];
workarounds: string[];
}
export interface AngleFeature {
category: string;
name: string;
bug: string;
status: string;
condition?: string;
description?: string;
}
interface GpuInfo {
ANGLEFeatures?: AngleFeature[];
basicInfo: any[];
basicInfoForHardwareGpu: any[];
compositorInfo: any[];
dawnInfo?: string[];
devicePerfInfo: any[];
diagnostics?: any[];
displayInfo: any[];
featureStatus: FeatureStatus;
featureStatusForHardwareGpu: FeatureStatus;
gpuMemoryBufferInfo: any[];
videoAcceleratorsInfo: any[];
vulkanInfo: string;
}
interface LogMessasge {
header: string;
message: string;
}
interface SimulatedData {
gpuInfo: GpuInfo;
clientInfo: ClientInfo;
logMessages: LogMessasge[];
}
/**
* This class provides a 'bridge' for communicating between javascript and the
* browser. When run outside of WebUI, e.g. as a regular webpage, it provides
* synthetic data to assist in testing.
*/
export class BrowserBridge extends EventTarget {
private clientInfo_: ClientInfo|null = null;
private gpuInfo_: GpuInfo|null = null;
private logMessages_: LogMessasge[] = [];
constructor() {
super();
this.clientInfo_ = null;
this.gpuInfo_ = null;
this.logMessages_ = [];
// Request initial gpu info from the C++ backend.
sendWithPromise('getGpuInfo').then(this.onGpuInfoUpdate_.bind(this));
// Register a listener to receive future gpu info updates.
addWebUiListener('gpu-info-updated', this.onGpuInfoUpdate_.bind(this));
this.updateClientInfo_();
this.updateLogMessages_();
}
private dispatchEvent_(eventName: string) {
this.dispatchEvent(
new CustomEvent(eventName, {bubbles: true, composed: true}));
}
applySimulatedData(data: SimulatedData) {
// set up things according to the simulated data
this.gpuInfo_ = data.gpuInfo;
this.clientInfo_ = data.clientInfo;
this.logMessages_ = data.logMessages;
this.dispatchEvent_('gpuInfoUpdate');
this.dispatchEvent_('clientInfoChange');
this.dispatchEvent_('logMessagesChange');
}
/**
* Get gpuInfo data.
*/
get gpuInfo() {
return this.gpuInfo_;
}
/**
* Called when GPU Info is updated.
*/
private onGpuInfoUpdate_(gpuInfo: GpuInfo) {
this.gpuInfo_ = gpuInfo;
this.dispatchEvent_('gpuInfoUpdate');
}
/**
* This function begins a request for the ClientInfo. If it comes back
* as undefined, then we will issue the request again in 250ms.
*/
private async updateClientInfo_() {
const data = await sendWithPromise('getClientInfo');
if (data === undefined) { // try again in 250 ms
window.setTimeout(this.updateClientInfo_.bind(this), 250);
} else {
this.clientInfo_ = data;
this.dispatchEvent_('clientInfoChange');
}
}
/**
* Returns information about the currently running Chrome build.
*/
get clientInfo() {
return this.clientInfo_;
}
/**
* This function checks for new GPU_LOG messages.
* If any are found, a refresh is triggered.
*/
private async updateLogMessages_() {
const messages = await sendWithPromise('getLogMessages');
if (messages.length !== this.logMessages_.length) {
this.logMessages_ = messages;
this.dispatchEvent_('logMessagesChange');
}
// check again in 250 ms
window.setTimeout(this.updateLogMessages_.bind(this), 250);
}
/**
* Returns an array of log messages issued by the GPU process, if any.
*/
get logMessages() {
return this.logMessages_;
}
/**
* Returns the value of the "Sandboxed" row.
*/
isSandboxedForTesting() {
assert(this.gpuInfo_);
for (const info of this.gpuInfo_.basicInfo) {
if (info.description === 'Sandboxed') {
return info.value;
}
}
return false;
}
}