1# Copyright 2013 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5from telemetry.internal.platform import gpu_device
6
7
8class GPUInfo(object):
9  """Provides information about the GPUs on the system."""
10
11  def __init__(self, device_array, aux_attributes,
12               feature_status, driver_bug_workarounds):
13    if device_array == None:
14      raise Exception('Missing required "devices" property')
15    if len(device_array) == 0:
16      raise Exception('Missing at least one GPU in device_array')
17
18    self._devices = [gpu_device.GPUDevice.FromDict(d) for d in device_array]
19    self._aux_attributes = aux_attributes
20    self._feature_status = feature_status
21    self._driver_bug_workarounds = driver_bug_workarounds
22
23  @classmethod
24  def FromDict(cls, attrs):
25    """Constructs a GPUInfo from a dictionary of attributes.
26
27    Attributes currently required to be present in the dictionary:
28      devices (array of dictionaries, each of which contains
29          GPUDevice's required attributes)
30    """
31    return cls(attrs['devices'], attrs.get('aux_attributes'),
32               attrs.get('feature_status'),
33               attrs.get('driver_bug_workarounds'))
34
35  @property
36  def devices(self):
37    """An array of GPUDevices. Element 0 is the primary GPU on the system."""
38    return self._devices
39
40  @property
41  def aux_attributes(self):
42    """Returns a dictionary of auxiliary, optional, attributes.
43
44    On the Chrome browser, for example, this dictionary contains:
45      optimus (boolean)
46      amd_switchable (boolean)
47      lenovo_dcute (boolean)
48      driver_vendor (string)
49      driver_version (string)
50      driver_date (string)
51      gl_version_string (string)
52      gl_vendor (string)
53      gl_renderer (string)
54      gl_extensions (string)
55      display_link_version (string)
56    """
57    return self._aux_attributes
58
59  @property
60  def feature_status(self):
61    """Returns an optional dictionary of graphics features and their status."""
62    return self._feature_status
63
64  @property
65  def driver_bug_workarounds(self):
66    """Returns an optional array of driver bug workarounds."""
67    return self._driver_bug_workarounds
68