summaryrefslogtreecommitdiff
path: root/chromium/content/browser/resources/gpu/info_view.js
blob: 780b52a28b3e098d0a721ffb038501532767428b (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
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.


/**
 * @fileoverview This view displays information on the current GPU
 * hardware.  Its primary usefulness is to allow users to copy-paste
 * their data in an easy to read format for bug reports.
 */
cr.define('gpu', function() {
  /**
   * Provides information on the GPU process and underlying graphics hardware.
   * @constructor
   * @extends {cr.ui.TabPanel}
   */
  var InfoView = cr.ui.define(cr.ui.TabPanel);

  InfoView.prototype = {
    __proto__: cr.ui.TabPanel.prototype,

    decorate: function() {
      cr.ui.TabPanel.prototype.decorate.apply(this);

      browserBridge.addEventListener('gpuInfoUpdate', this.refresh.bind(this));
      browserBridge.addEventListener('logMessagesChange',
                                     this.refresh.bind(this));
      browserBridge.addEventListener('clientInfoChange',
                                     this.refresh.bind(this));

      // Add handler to 'copy to clipboard' button
      document.getElementById('copy-to-clipboard').onclick = function() {
        // Make sure nothing is selected
        window.getSelection().removeAllRanges();

        document.execCommand('selectAll');
        document.execCommand('copy');

        // And deselect everything at the end.
        window.getSelection().removeAllRanges();
      }

      this.refresh();
    },

    /**
    * Updates the view based on its currently known data
    */
    refresh: function(data) {
      function createSourcePermalink(revisionIdentifier, filepath) {
        if (revisionIdentifier.length !== 40) {
          // If the revision id isn't a hash, just use the 0.0.0.0 version
          // from the Chrome version string "Chrome/0.0.0.0".
          revisionIdentifier = clientInfo.version.split('/')[1];
        }
        return `https://chromium.googlesource.com/chromium/src/+/${revisionIdentifier}/${filepath}`;
      }

      // Client info
      if (browserBridge.clientInfo) {
        var clientInfo = browserBridge.clientInfo;

        this.setTable_('client-info', [
          {
            description: 'Data exported',
            value: (new Date()).toISOString()
          },
          {
            description: 'Chrome version',
            value: clientInfo.version
          },
          {
            description: 'Operating system',
            value: clientInfo.operating_system
          },
          {
            description: 'Software rendering list URL',
            value: createSourcePermalink(clientInfo.revision_identifier,
              'gpu/config/software_rendering_list.json')
          },
          {
            description: 'Driver bug list URL',
            value: createSourcePermalink(clientInfo.revision_identifier,
              'gpu/config/gpu_driver_bug_list.json')
          },
          {
            description: 'ANGLE commit id',
            value: clientInfo.angle_commit_id
          },
          {
            description: '2D graphics backend',
            value: clientInfo.graphics_backend
          },
          {
            description: 'Command Line',
            value: clientInfo.command_line
          }]);
      } else {
        this.setText_('client-info', '... loading...');
      }


      // GPU info, basic
      var diagnosticsDiv = this.querySelector('.diagnostics');
      var diagnosticsLoadingDiv = this.querySelector('.diagnostics-loading');
      var featureStatusList = this.querySelector('.feature-status-list');
      var problemsDiv = this.querySelector('.problems-div');
      var problemsList = this.querySelector('.problems-list');
      var workaroundsDiv = this.querySelector('.workarounds-div');
      var workaroundsList = this.querySelector('.workarounds-list');

      var basicInfoForHardwareGpuDiv =
          this.querySelector('.basic-info-for-hardware-gpu-div');
      var featureStatusForHardwareGpuDiv =
          this.querySelector('.feature-status-for-hardware-gpu-div');
      var featureStatusForHardwareGpuList =
          this.querySelector('.feature-status-for-hardware-gpu-list');
      var problemsForHardwareGpuDiv =
          this.querySelector('.problems-for-hardware-gpu-div');
      var problemsForHardwareGpuList =
          this.querySelector('.problems-for-hardware-gpu-list');
      var workaroundsForHardwareGpuDiv =
          this.querySelector('.workarounds-for-hardware-gpu-div');
      var workaroundsForHardwareGpuList =
          this.querySelector('.workarounds-for-hardware-gpu-list');

      var gpuInfo = browserBridge.gpuInfo;
      var i;
      if (gpuInfo) {
        // Not using jstemplate here for blacklist status because we construct
        // href from data, which jstemplate can't seem to do.
        if (gpuInfo.featureStatus) {
          this.appendFeatureInfo_(gpuInfo.featureStatus, featureStatusList,
                                  problemsDiv, problemsList,
                                  workaroundsDiv, workaroundsList);
        } else {
          featureStatusList.textContent = '';
          problemsList.hidden = true;
          workaroundsList.hidden = true;
        }

        if (gpuInfo.featureStatusForHardwareGpu) {
          basicInfoForHardwareGpuDiv.hidden = false;
          featureStatusForHardwareGpuDiv.hidden = false;
          problemsForHardwareGpuDiv.hidden = false;
          workaroundsForHardwareGpuDiv.hidden = false;
          this.appendFeatureInfo_(gpuInfo.featureStatusForHardwareGpu,
                                  featureStatusForHardwareGpuList,
                                  problemsForHardwareGpuDiv,
                                  problemsForHardwareGpuList,
                                  workaroundsForHardwareGpuDiv,
                                  workaroundsForHardwareGpuList);
          if (gpuInfo.basicInfoForHardwareGpu) {
            this.setTable_('basic-info-for-hardware-gpu',
                           gpuInfo.basicInfoForHardwareGpu);
          } else {
            this.setTable_('basic-info-for-hardware-gpu', []);
          }
        } else {
          basicInfoForHardwareGpuDiv.hidden = true;
          featureStatusForHardwareGpuDiv.hidden = true;
          problemsForHardwareGpuDiv.hidden = true;
          workaroundsForHardwareGpuDiv.hidden = true;
        }

        if (gpuInfo.basicInfo)
          this.setTable_('basic-info', gpuInfo.basicInfo);
        else
          this.setTable_('basic-info', []);

        if (gpuInfo.compositorInfo)
          this.setTable_('compositor-info', gpuInfo.compositorInfo);
        else
          this.setTable_('compositor-info', []);

        if (gpuInfo.gpuMemoryBufferInfo)
          this.setTable_('gpu-memory-buffer-info', gpuInfo.gpuMemoryBufferInfo);
        else
          this.setTable_('gpu-memory-buffer-info', []);

        if (gpuInfo.displayInfo)
          this.setTable_('display-info', gpuInfo.displayInfo);
        else
          this.setTable_('display-info', []);

        if (gpuInfo.videoAcceleratorsInfo) {
          this.setTable_(
              'video-acceleration-info', gpuInfo.videoAcceleratorsInfo);
        } else {
          this.setTable_('video-acceleration-info', []);
        }

        if (gpuInfo.diagnostics) {
          diagnosticsDiv.hidden = false;
          diagnosticsLoadingDiv.hidden = true;
          $('diagnostics-table').hidden = false;
          this.setTable_('diagnostics-table', gpuInfo.diagnostics);
        } else if (gpuInfo.diagnostics === null) {
          // gpu_internals.cc sets diagnostics to null when it is being loaded
          diagnosticsDiv.hidden = false;
          diagnosticsLoadingDiv.hidden = false;
          $('diagnostics-table').hidden = true;
        } else {
          diagnosticsDiv.hidden = true;
        }
      } else {
        this.setText_('basic-info', '... loading ...');
        diagnosticsDiv.hidden = true;
        featureStatusList.textContent = '';
        problemsDiv.hidden = true;
      }

      // Log messages
      jstProcess(new JsEvalContext({values: browserBridge.logMessages}),
                 $('log-messages'));
    },

    appendFeatureInfo_: function(featureInfo, featureStatusList,
                                 problemsDiv, problemsList,
                                 workaroundsDiv, workaroundsList) {
      // Feature map
      var featureLabelMap = {
        '2d_canvas': 'Canvas',
        'gpu_compositing': 'Compositing',
        'webgl': 'WebGL',
        'multisampling': 'WebGL multisampling',
        'flash_3d': 'Flash',
        'flash_stage3d': 'Flash Stage3D',
        'flash_stage3d_baseline': 'Flash Stage3D Baseline profile',
        'texture_sharing': 'Texture Sharing',
        'video_decode': 'Video Decode',
        'rasterization': 'Rasterization',
        'oop_rasterization': 'Out-of-process Rasterization',
        'multiple_raster_threads': 'Multiple Raster Threads',
        'native_gpu_memory_buffers': 'Native GpuMemoryBuffers',
        'protected_video_decode': 'Hardware Protected Video Decode',
        'surface_synchronization': 'Surface Synchronization',
        'surface_control': 'Surface Control',
        'vpx_decode': 'VPx Video Decode',
        'webgl2': 'WebGL2',
        'viz_display_compositor': 'Viz Service Display Compositor',
        'skia_renderer': 'Skia Renderer',
        'skia_deferred_display_list': 'Skia Deferred Display List',
      };

      var statusMap =  {
        'disabled_software': {
          'label': 'Software only. Hardware acceleration disabled',
          'class': 'feature-yellow'
        },
        'disabled_off': {
          'label': 'Disabled',
          'class': 'feature-red'
        },
        'disabled_off_ok': {
          'label': 'Disabled',
          'class': 'feature-yellow'
        },
        'unavailable_software': {
          'label': 'Software only, hardware acceleration unavailable',
          'class': 'feature-yellow'
        },
        'unavailable_off': {
          'label': 'Unavailable',
          'class': 'feature-red'
        },
        'unavailable_off_ok': {
          'label': 'Unavailable',
          'class': 'feature-yellow'
        },
        'enabled_readback': {
          'label': 'Hardware accelerated but at reduced performance',
          'class': 'feature-yellow'
        },
        'enabled_force': {
          'label': 'Hardware accelerated on all pages',
          'class': 'feature-green'
        },
        'enabled': {
          'label': 'Hardware accelerated',
          'class': 'feature-green'
        },
        'enabled_on': {
          'label': 'Enabled',
          'class': 'feature-green'
        },
        'enabled_force_on': {
          'label': 'Force enabled',
          'class': 'feature-green'
        },
      };

      // feature status list
      featureStatusList.textContent = '';
      for (var featureName in featureInfo.featureStatus) {
        var featureStatus = featureInfo.featureStatus[featureName];
        var featureEl = document.createElement('li');

        var nameEl = document.createElement('span');
        if (!featureLabelMap[featureName])
          console.log('Missing featureLabel for', featureName);
        nameEl.textContent = featureLabelMap[featureName] + ': ';
        featureEl.appendChild(nameEl);

        var statusEl = document.createElement('span');
        var statusInfo = statusMap[featureStatus];
        if (!statusInfo) {
          console.log('Missing status for ', featureStatus);
          statusEl.textContent = 'Unknown';
          statusEl.className = 'feature-red';
        } else {
          statusEl.textContent = statusInfo['label'];
          statusEl.className = statusInfo['class'];
        }
        featureEl.appendChild(statusEl);

        featureStatusList.appendChild(featureEl);
      }

      // problems list
      if (featureInfo.problems.length) {
        problemsDiv.hidden = false;
        problemsList.textContent = '';
        for (i = 0; i < featureInfo.problems.length; i++) {
          var problem = featureInfo.problems[i];
          var problemEl = this.createProblemEl_(problem);
          problemsList.appendChild(problemEl);
        }
      } else {
        problemsDiv.hidden = true;
      }

      // driver bug workarounds list
      if (featureInfo.workarounds.length) {
        workaroundsDiv.hidden = false;
        workaroundsList.textContent = '';
        for (i = 0; i < featureInfo.workarounds.length; i++) {
          var workaroundEl = document.createElement('li');
          workaroundEl.textContent = featureInfo.workarounds[i];
          workaroundsList.appendChild(workaroundEl);
        }
      } else {
        workaroundsDiv.hidden = true;
      }
    },

    createProblemEl_: function(problem) {
      var problemEl;
      problemEl = document.createElement('li');

      // Description of issue
      var desc = document.createElement('a');
      desc.textContent = problem.description;
      problemEl.appendChild(desc);

      // Spacing ':' element
      if (problem.crBugs.length > 0) {
        var tmp = document.createElement('span');
        tmp.textContent = ': ';
        problemEl.appendChild(tmp);
      }

      var nbugs = 0;
      var j;

      // crBugs
      for (j = 0; j < problem.crBugs.length; ++j) {
        if (nbugs > 0) {
          var tmp = document.createElement('span');
          tmp.textContent = ', ';
          problemEl.appendChild(tmp);
        }

        var link = document.createElement('a');
        var bugid = parseInt(problem.crBugs[j]);
        link.textContent = bugid;
        link.href = 'http://crbug.com/' + bugid;
        problemEl.appendChild(link);
        nbugs++;
      }

      if (problem.affectedGpuSettings.length > 0) {
        var brNode = document.createElement('br');
        problemEl.appendChild(brNode);

        var iNode = document.createElement('i');
        problemEl.appendChild(iNode);

        var headNode = document.createElement('span');
        if (problem.tag == 'disabledFeatures')
          headNode.textContent = 'Disabled Features: ';
        else  // problem.tag == 'workarounds'
          headNode.textContent = 'Applied Workarounds: ';
        iNode.appendChild(headNode);
        for (j = 0; j < problem.affectedGpuSettings.length; ++j) {
          if (j > 0) {
            var separateNode = document.createElement('span');
            separateNode.textContent = ', ';
            iNode.appendChild(separateNode);
          }
          var nameNode = document.createElement('span');
          if (problem.tag == 'disabledFeatures')
            nameNode.classList.add('feature-red');
          else  // problem.tag == 'workarounds'
            nameNode.classList.add('feature-yellow');
          nameNode.textContent = problem.affectedGpuSettings[j];
          iNode.appendChild(nameNode);
        }
      }

      return problemEl;
    },

    setText_: function(outputElementId, text) {
      var peg = document.getElementById(outputElementId);
      peg.textContent = text;
    },

    setTable_: function(outputElementId, inputData) {
      var template = jstGetTemplate('info-view-table-template');
      jstProcess(new JsEvalContext({value: inputData}),
                 template);

      var peg = document.getElementById(outputElementId);
      if (!peg)
        throw new Error('Node ' + outputElementId + ' not found');

      peg.innerHTML = '';
      peg.appendChild(template);
    }
  };

  return {
    InfoView: InfoView
  };
});