Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 1 | # Copyright (c) 2014 The Chromium OS 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 | |
Tom Wai-Hong Tam | 0d83659 | 2014-04-23 11:27:40 +0800 | [diff] [blame] | 5 | import httplib |
| 6 | import logging |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 7 | import os |
Tom Wai-Hong Tam | 0d83659 | 2014-04-23 11:27:40 +0800 | [diff] [blame] | 8 | import socket |
Tom Wai-Hong Tam | 897fcf7 | 2014-04-25 14:02:54 +0800 | [diff] [blame] | 9 | import tempfile |
Tom Wai-Hong Tam | 0d83659 | 2014-04-23 11:27:40 +0800 | [diff] [blame] | 10 | import xmlrpclib |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 11 | |
J. Richard Barnette | 428b344 | 2014-07-22 11:38:55 -0700 | [diff] [blame] | 12 | from PIL import Image |
| 13 | |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 14 | from autotest_lib.client.bin import utils |
Tom Wai-Hong Tam | 0d83659 | 2014-04-23 11:27:40 +0800 | [diff] [blame] | 15 | from autotest_lib.client.common_lib.cros import retry |
Wai-Hong Tam | 44cb545 | 2014-03-18 16:14:24 -0700 | [diff] [blame] | 16 | from autotest_lib.client.cros import constants |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 17 | from autotest_lib.server import autotest |
Tom Wai-Hong Tam | 897fcf7 | 2014-04-25 14:02:54 +0800 | [diff] [blame] | 18 | from autotest_lib.server.cros.chameleon import image_generator |
| 19 | |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 20 | |
Ting-Yuan Cheng | 568083c | 2014-07-08 18:19:10 +0800 | [diff] [blame] | 21 | |
| 22 | class DisplayInfo(object): |
| 23 | """The class match displayInfo object from chrome.system.display API. |
| 24 | """ |
| 25 | |
| 26 | class Bounds(object): |
| 27 | """The class match Bounds object from chrome.system.display API. |
| 28 | |
| 29 | @param left: The x-coordinate of the upper-left corner. |
| 30 | @param top: The y-coordinate of the upper-left corner. |
| 31 | @param width: The width of the display in pixels. |
| 32 | @param height: The height of the display in pixels. |
| 33 | """ |
| 34 | def __init__(self, d): |
| 35 | self.left = d['left']; |
| 36 | self.top = d['top']; |
| 37 | self.width = d['width']; |
| 38 | self.height = d['height']; |
| 39 | |
| 40 | |
| 41 | class Insets(object): |
| 42 | """The class match Insets object from chrome.system.display API. |
| 43 | |
| 44 | @param left: The x-axis distance from the left bound. |
| 45 | @param left: The y-axis distance from the top bound. |
| 46 | @param left: The x-axis distance from the right bound. |
| 47 | @param left: The y-axis distance from the bottom bound. |
| 48 | """ |
| 49 | |
| 50 | def __init__(self, d): |
| 51 | self.left = d['left']; |
| 52 | self.top = d['top']; |
| 53 | self.right = d['right']; |
| 54 | self.bottom = d['bottom']; |
| 55 | |
| 56 | |
| 57 | def __init__(self, d): |
| 58 | self.display_id = d['id']; |
| 59 | self.name = d['name']; |
| 60 | self.mirroring_source_id = d['mirroringSourceId']; |
| 61 | self.is_primary = d['isPrimary']; |
| 62 | self.is_internal = d['isInternal']; |
| 63 | self.is_enabled = d['isEnabled']; |
| 64 | self.dpi_x = d['dpiX']; |
| 65 | self.dpi_y = d['dpiY']; |
| 66 | self.rotation = d['rotation']; |
| 67 | self.bounds = self.Bounds(d['bounds']); |
| 68 | self.overscan = self.Insets(d['overscan']); |
| 69 | self.work_area = self.Bounds(d['workArea']); |
| 70 | |
| 71 | |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 72 | class DisplayClient(object): |
| 73 | """DisplayClient is a layer to control display logic over a remote DUT. |
| 74 | |
| 75 | The Autotest host object representing the remote DUT, passed to this |
| 76 | class on initialization, can be accessed from its _client property. |
| 77 | |
| 78 | """ |
| 79 | |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 80 | X_ENV_VARIABLES = 'DISPLAY=:0.0 XAUTHORITY=/home/chronos/.Xauthority' |
Tom Wai-Hong Tam | a2f21cb | 2014-07-25 08:00:49 +0800 | [diff] [blame] | 81 | XMLRPC_CONNECT_TIMEOUT = 60 |
Tom Wai-Hong Tam | 0d83659 | 2014-04-23 11:27:40 +0800 | [diff] [blame] | 82 | XMLRPC_RETRY_TIMEOUT = 180 |
| 83 | XMLRPC_RETRY_DELAY = 10 |
Tom Wai-Hong Tam | 2336263 | 2014-04-09 16:38:37 +0800 | [diff] [blame] | 84 | HTTP_PORT = 8000 |
Tom Wai-Hong Tam | 897fcf7 | 2014-04-25 14:02:54 +0800 | [diff] [blame] | 85 | DEST_TMP_DIR = '/tmp' |
| 86 | DEST_IMAGE_FILENAME = 'calibration.svg' |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 87 | |
| 88 | |
| 89 | def __init__(self, host): |
| 90 | """Construct a DisplayClient. |
| 91 | |
| 92 | @param host: Host object representing a remote host. |
| 93 | """ |
| 94 | self._client = host |
| 95 | self._display_xmlrpc_client = None |
Tom Wai-Hong Tam | 897fcf7 | 2014-04-25 14:02:54 +0800 | [diff] [blame] | 96 | self._image_generator = image_generator.ImageGenerator() |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 97 | |
| 98 | |
Wai-Hong Tam | 44cb545 | 2014-03-18 16:14:24 -0700 | [diff] [blame] | 99 | def initialize(self): |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 100 | """Initializes some required servers, like HTTP daemon, RPC connection. |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 101 | """ |
| 102 | # Make sure the client library is on the device so that the proxy code |
| 103 | # is there when we try to call it. |
| 104 | client_at = autotest.Autotest(self._client) |
| 105 | client_at.install() |
Tom Wai-Hong Tam | fe39509 | 2014-02-12 20:16:22 +0800 | [diff] [blame] | 106 | self.connect() |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 107 | |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 108 | |
Tom Wai-Hong Tam | fe39509 | 2014-02-12 20:16:22 +0800 | [diff] [blame] | 109 | def connect(self): |
| 110 | """Connects the XML-RPC proxy on the client.""" |
Tom Wai-Hong Tam | 0d83659 | 2014-04-23 11:27:40 +0800 | [diff] [blame] | 111 | @retry.retry((socket.error, |
| 112 | xmlrpclib.ProtocolError, |
| 113 | httplib.BadStatusLine), |
| 114 | timeout_min=self.XMLRPC_RETRY_TIMEOUT / 60.0, |
| 115 | delay_sec=self.XMLRPC_RETRY_DELAY) |
| 116 | def connect_with_retries(): |
| 117 | """Connects the XML-RPC proxy with retries.""" |
Tom Wai-Hong Tam | 1a197c9 | 2014-08-27 14:31:11 +0800 | [diff] [blame^] | 118 | multimedia_xmlrpc_client = self._client.xmlrpc_connect( |
Tom Wai-Hong Tam | 017d902 | 2014-08-27 11:31:47 +0800 | [diff] [blame] | 119 | constants.MULTIMEDIA_XMLRPC_SERVER_COMMAND, |
| 120 | constants.MULTIMEDIA_XMLRPC_SERVER_PORT, |
Tom Wai-Hong Tam | 0d83659 | 2014-04-23 11:27:40 +0800 | [diff] [blame] | 121 | command_name=( |
Tom Wai-Hong Tam | 017d902 | 2014-08-27 11:31:47 +0800 | [diff] [blame] | 122 | constants.MULTIMEDIA_XMLRPC_SERVER_CLEANUP_PATTERN |
Tom Wai-Hong Tam | 0d83659 | 2014-04-23 11:27:40 +0800 | [diff] [blame] | 123 | ), |
| 124 | ready_test_name=( |
Tom Wai-Hong Tam | 017d902 | 2014-08-27 11:31:47 +0800 | [diff] [blame] | 125 | constants.MULTIMEDIA_XMLRPC_SERVER_READY_METHOD), |
Tom Wai-Hong Tam | 0d83659 | 2014-04-23 11:27:40 +0800 | [diff] [blame] | 126 | timeout_seconds=self.XMLRPC_CONNECT_TIMEOUT) |
Tom Wai-Hong Tam | 1a197c9 | 2014-08-27 14:31:11 +0800 | [diff] [blame^] | 127 | self._display_xmlrpc_client = multimedia_xmlrpc_client.display |
Tom Wai-Hong Tam | 0d83659 | 2014-04-23 11:27:40 +0800 | [diff] [blame] | 128 | |
| 129 | logging.info('Setup the display_client RPC server, with retries...') |
| 130 | connect_with_retries() |
Tom Wai-Hong Tam | fe39509 | 2014-02-12 20:16:22 +0800 | [diff] [blame] | 131 | |
| 132 | |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 133 | def cleanup(self): |
| 134 | """Cleans up.""" |
Tom Wai-Hong Tam | 0d83659 | 2014-04-23 11:27:40 +0800 | [diff] [blame] | 135 | self._client.rpc_disconnect( |
Tom Wai-Hong Tam | 017d902 | 2014-08-27 11:31:47 +0800 | [diff] [blame] | 136 | constants.MULTIMEDIA_XMLRPC_SERVER_PORT) |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 137 | |
| 138 | |
| 139 | def __del__(self): |
| 140 | """Destructor of DisplayClient.""" |
| 141 | self.cleanup() |
| 142 | |
| 143 | |
Ting-Yuan Cheng | 0c48150 | 2014-08-13 19:03:47 +0800 | [diff] [blame] | 144 | def get_external_connector_name(self): |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 145 | """Gets the name of the external output connector. |
| 146 | |
| 147 | @return The external output connector name as a string. |
| 148 | """ |
Ting-Yuan Cheng | 0c48150 | 2014-08-13 19:03:47 +0800 | [diff] [blame] | 149 | return self._display_xmlrpc_client.get_external_connector_name() |
| 150 | |
| 151 | |
| 152 | def get_internal_connector_name(self): |
| 153 | """Gets the name of the internal output connector. |
| 154 | |
| 155 | @return The internal output connector name as a string. |
| 156 | """ |
| 157 | return self._display_xmlrpc_client.get_internal_connector_name() |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 158 | |
| 159 | |
| 160 | def load_calibration_image(self, resolution): |
| 161 | """Load a full screen calibration image from the HTTP server. |
| 162 | |
| 163 | @param resolution: A tuple (width, height) of resolution. |
| 164 | """ |
Tom Wai-Hong Tam | 897fcf7 | 2014-04-25 14:02:54 +0800 | [diff] [blame] | 165 | with tempfile.NamedTemporaryFile() as f: |
| 166 | self._image_generator.generate_image( |
| 167 | resolution[0], resolution[1], f.name) |
| 168 | os.chmod(f.name, 0644) |
| 169 | self._client.send_file( |
| 170 | f.name, |
| 171 | os.path.join(self.DEST_TMP_DIR, self.DEST_IMAGE_FILENAME)) |
| 172 | |
| 173 | page_url = 'file://%s/%s' % (self.DEST_TMP_DIR, |
| 174 | self.DEST_IMAGE_FILENAME) |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 175 | self._display_xmlrpc_client.load_url(page_url) |
| 176 | |
| 177 | |
| 178 | def close_tab(self, index=-1): |
| 179 | """Closes the tab of the given index. |
| 180 | |
| 181 | @param index: The tab index to close. Defaults to the last tab. |
| 182 | """ |
| 183 | return self._display_xmlrpc_client.close_tab(index) |
| 184 | |
| 185 | |
| 186 | def set_mirrored(self, is_mirrored): |
| 187 | """Sets mirrored mode. |
| 188 | |
| 189 | @param is_mirrored: True or False to indicate mirrored state. |
| 190 | """ |
| 191 | return self._display_xmlrpc_client.set_mirrored(is_mirrored) |
| 192 | |
| 193 | |
Tom Wai-Hong Tam | 328dbeb | 2014-02-14 11:20:19 +0800 | [diff] [blame] | 194 | def suspend_resume(self, suspend_time=10): |
| 195 | """Suspends the DUT for a given time in second. |
| 196 | |
| 197 | @param suspend_time: Suspend time in second, default: 10s. |
| 198 | """ |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 199 | # TODO(waihong): Use other general API instead of this RPC. |
Tom Wai-Hong Tam | 328dbeb | 2014-02-14 11:20:19 +0800 | [diff] [blame] | 200 | return self._display_xmlrpc_client.suspend_resume(suspend_time) |
| 201 | |
| 202 | |
| 203 | def suspend_resume_bg(self, suspend_time=10): |
| 204 | """Suspends the DUT for a given time in second in the background. |
| 205 | |
| 206 | @param suspend_time: Suspend time in second, default: 10s. |
| 207 | """ |
| 208 | # TODO(waihong): Use other general API instead of this RPC. |
| 209 | return self._display_xmlrpc_client.suspend_resume_bg(suspend_time) |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 210 | |
| 211 | |
Ting-Yuan Cheng | 568083c | 2014-07-08 18:19:10 +0800 | [diff] [blame] | 212 | def reconnect_output_and_wait(self, reconnect=True, |
| 213 | expected_display_count=2): |
| 214 | """Reconnects output and waits it available. |
| 215 | |
| 216 | @param reconnect: True to perform a re-connection from the DUT; False |
| 217 | otherwise. |
| 218 | @param expected_display_count: |
| 219 | number of displays expected to be connected. |
| 220 | """ |
Ting-Yuan Cheng | 0c48150 | 2014-08-13 19:03:47 +0800 | [diff] [blame] | 221 | output = self.get_external_connector_name() |
Ting-Yuan Cheng | 568083c | 2014-07-08 18:19:10 +0800 | [diff] [blame] | 222 | if reconnect: |
| 223 | self._display_xmlrpc_client.reconnect_output(output) |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 224 | self._display_xmlrpc_client.wait_output_connected(output) |
| 225 | utils.wait_for_value(lambda: ( |
| 226 | len(self._display_xmlrpc_client.get_display_info())), |
Ting-Yuan Cheng | 568083c | 2014-07-08 18:19:10 +0800 | [diff] [blame] | 227 | expected_value=expected_display_count) |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 228 | |
| 229 | |
Hung-ying Tyan | 6754165 | 2014-03-12 11:44:46 +0800 | [diff] [blame] | 230 | def hide_cursor(self): |
| 231 | """Hides mouse cursor by sending a keystroke.""" |
Tom Wai-Hong Tam | bd22f8f | 2014-06-03 03:05:56 +0800 | [diff] [blame] | 232 | self._display_xmlrpc_client.press_key('Up') |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 233 | |
| 234 | |
Ting-Yuan Cheng | 0c48150 | 2014-08-13 19:03:47 +0800 | [diff] [blame] | 235 | def _read_root_window_rect(self, w, h, x, y): |
| 236 | """Reads the given rectangle from the X root window. |
| 237 | |
| 238 | @param w: The width of the rectangle to read. |
| 239 | @param h: The height of the rectangle to read. |
| 240 | @param x: The x coordinate. |
| 241 | @param y: The y coordinate. |
| 242 | |
| 243 | @return: An Image object. |
| 244 | """ |
| 245 | with tempfile.NamedTemporaryFile(suffix='.rgb') as f: |
| 246 | basename = os.path.basename(f.name) |
| 247 | remote_path = os.path.join('/tmp', basename) |
| 248 | # TODO(waihong): Abstract this X11 specific method. |
| 249 | command = ('%s import -window root -depth 8 -crop %dx%d+%d+%d %s' % |
| 250 | (self.X_ENV_VARIABLES, w, h, x, y, remote_path)) |
| 251 | self._client.run(command) |
| 252 | self._client.get_file(remote_path, f.name) |
| 253 | return Image.fromstring('RGB', (w, h), open(f.name).read()) |
| 254 | |
| 255 | |
| 256 | def get_internal_display_resolution(self): |
| 257 | """Gets the resolution of internal display on framebuffer. |
| 258 | |
| 259 | @return The resolution tuple (width, height). None if any error. |
| 260 | """ |
| 261 | connector = self.get_internal_connector_name() |
| 262 | if not connector: |
| 263 | return None |
| 264 | w, h, _, _ = self._display_xmlrpc_client.get_resolution(connector) |
| 265 | return (w, h) |
| 266 | |
| 267 | |
| 268 | def capture_internal_screen(self): |
| 269 | """Captures the internal screen framebuffer. |
| 270 | |
| 271 | @return: An Image object. None if any error. |
| 272 | """ |
| 273 | connector = self.get_internal_connector_name() |
| 274 | if not connector: |
| 275 | return None |
| 276 | return self._read_root_window_rect( |
| 277 | *self._display_xmlrpc_client.get_resolution(connector)) |
| 278 | |
| 279 | |
Tom Wai-Hong Tam | 4c8022f | 2014-07-17 09:12:08 +0800 | [diff] [blame] | 280 | def capture_external_screen(self): |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 281 | """Captures the external screen framebuffer. |
| 282 | |
Tom Wai-Hong Tam | 4c8022f | 2014-07-17 09:12:08 +0800 | [diff] [blame] | 283 | @return: An Image object. |
Tom Wai-Hong Tam | b2d39dc | 2014-01-21 15:26:23 +0800 | [diff] [blame] | 284 | """ |
Ting-Yuan Cheng | 0c48150 | 2014-08-13 19:03:47 +0800 | [diff] [blame] | 285 | output = self.get_external_connector_name() |
| 286 | w, h, x, y = self._display_xmlrpc_client.get_resolution(output) |
| 287 | return self._read_root_window_rect(w, h, x, y) |
Tom Wai-Hong Tam | f6bb17f | 2014-04-24 13:36:49 +0800 | [diff] [blame] | 288 | |
| 289 | |
| 290 | def get_resolution(self): |
| 291 | """Gets the external resolution on framebuffer. |
| 292 | |
| 293 | @return The resolution tuple (width, height) |
| 294 | """ |
Ting-Yuan Cheng | 0c48150 | 2014-08-13 19:03:47 +0800 | [diff] [blame] | 295 | output = self.get_external_connector_name() |
Tom Wai-Hong Tam | f6bb17f | 2014-04-24 13:36:49 +0800 | [diff] [blame] | 296 | width, height, _, _ = self._display_xmlrpc_client.get_resolution(output) |
| 297 | return (width, height) |
Ting-Yuan Cheng | 568083c | 2014-07-08 18:19:10 +0800 | [diff] [blame] | 298 | |
| 299 | |
| 300 | def set_resolution(self, display_index, width, height): |
| 301 | """Sets the resolution on the specified display. |
| 302 | |
Hung-ying Tyan | eea5a79 | 2014-08-15 19:07:54 +0800 | [diff] [blame] | 303 | @param display_index: index of the display to set resolutions for. |
Ting-Yuan Cheng | 568083c | 2014-07-08 18:19:10 +0800 | [diff] [blame] | 304 | @param width: width of the resolution |
| 305 | @param height: height of the resolution |
Ting-Yuan Cheng | 568083c | 2014-07-08 18:19:10 +0800 | [diff] [blame] | 306 | """ |
Ting-Yuan Cheng | 325ee94 | 2014-07-29 16:33:58 +0800 | [diff] [blame] | 307 | self._display_xmlrpc_client.set_resolution( |
Ting-Yuan Cheng | 568083c | 2014-07-08 18:19:10 +0800 | [diff] [blame] | 308 | display_index, width, height) |
| 309 | |
| 310 | |
| 311 | def get_display_info(self): |
| 312 | """Gets the information of all the displays that are connected to the |
| 313 | DUT. |
| 314 | |
Hung-ying Tyan | eea5a79 | 2014-08-15 19:07:54 +0800 | [diff] [blame] | 315 | @return: list of object DisplayInfo for display informtion |
Ting-Yuan Cheng | 568083c | 2014-07-08 18:19:10 +0800 | [diff] [blame] | 316 | """ |
| 317 | return map(DisplayInfo, self._display_xmlrpc_client.get_display_info()) |
| 318 | |
| 319 | |
Hung-ying Tyan | eea5a79 | 2014-08-15 19:07:54 +0800 | [diff] [blame] | 320 | def get_display_modes(self, display_index): |
| 321 | """Gets the display modes of the specified display. |
Ting-Yuan Cheng | 568083c | 2014-07-08 18:19:10 +0800 | [diff] [blame] | 322 | |
Hung-ying Tyan | eea5a79 | 2014-08-15 19:07:54 +0800 | [diff] [blame] | 323 | @param display_index: index of the display to get modes from; the index |
| 324 | is from the DisplayInfo list obtained by get_display_info(). |
Ting-Yuan Cheng | 568083c | 2014-07-08 18:19:10 +0800 | [diff] [blame] | 325 | |
Hung-ying Tyan | eea5a79 | 2014-08-15 19:07:54 +0800 | [diff] [blame] | 326 | @return: list of DisplayMode dicts. |
Ting-Yuan Cheng | 568083c | 2014-07-08 18:19:10 +0800 | [diff] [blame] | 327 | """ |
Hung-ying Tyan | eea5a79 | 2014-08-15 19:07:54 +0800 | [diff] [blame] | 328 | return self._display_xmlrpc_client.get_display_modes(display_index) |
Ting-Yuan Cheng | 5d8f341 | 2014-08-14 14:02:14 +0800 | [diff] [blame] | 329 | |
Hung-ying Tyan | eea5a79 | 2014-08-15 19:07:54 +0800 | [diff] [blame] | 330 | |
| 331 | def get_available_resolutions(self, display_index): |
| 332 | """Gets the resolutions from the specified display. |
| 333 | |
| 334 | @return a list of (width, height) tuples. |
| 335 | """ |
| 336 | # Start from M38 (refer to http://codereview.chromium.org/417113012), |
| 337 | # a DisplayMode dict contains 'originalWidth'/'originalHeight' |
| 338 | # in addition to 'width'/'height'. |
| 339 | # OriginalWidth/originalHeight is what is supported by the display |
| 340 | # while width/height is what is shown to users in the display setting. |
| 341 | modes = self.get_display_modes(display_index) |
| 342 | if modes: |
| 343 | if 'originalWidth' in modes[0]: |
| 344 | # M38 or newer |
| 345 | # TODO(tingyuan): fix loading image for cases where original |
| 346 | # width/height is different from width/height. |
| 347 | return list(set([(mode['originalWidth'], mode['originalHeight']) |
| 348 | for mode in modes])) |
| 349 | |
| 350 | # pre-M38 |
| 351 | return [(mode['width'], mode['height']) for mode in modes |
| 352 | if 'scale' not in mode] |