Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(548)

Side by Side Diff: chromeos/display/output_util.cc

Issue 24081004: chromeos: Fix display failures when going to mirrored mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: uploading yet again Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromeos/display/output_util.h" 5 #include "chromeos/display/output_util.h"
6 6
7 #include <X11/Xlib.h> 7 #include <X11/Xlib.h>
8 #include <X11/extensions/Xrandr.h> 8 #include <X11/extensions/Xrandr.h>
9 #include <X11/Xatom.h> 9 #include <X11/Xatom.h>
10 10
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 unsigned char *prop = NULL; 104 unsigned char *prop = NULL;
105 if (!GetEDIDProperty(output, &nitems, &prop)) 105 if (!GetEDIDProperty(output, &nitems, &prop))
106 return false; 106 return false;
107 107
108 bool result = ParseOutputDeviceData( 108 bool result = ParseOutputDeviceData(
109 prop, nitems, manufacturer_id, human_readable_name); 109 prop, nitems, manufacturer_id, human_readable_name);
110 XFree(prop); 110 XFree(prop);
111 return result; 111 return result;
112 } 112 }
113 113
114 float GetRefreshRate(const XRRModeInfo* mode_info) {
115 if (mode_info->hTotal && mode_info->vTotal) {
116 return static_cast<float>(mode_info->dotClock) /
117 (static_cast<float>(mode_info->hTotal) *
118 static_cast<float>(mode_info->vTotal));
119 } else {
120 return 0.0f;
121 }
122 }
123
124 } // namespace 114 } // namespace
125 115
126 std::string GetDisplayName(XID output_id) { 116 std::string GetDisplayName(XID output_id) {
127 std::string display_name; 117 std::string display_name;
128 GetOutputDeviceData(output_id, NULL, &display_name); 118 GetOutputDeviceData(output_id, NULL, &display_name);
129 return display_name; 119 return display_name;
130 } 120 }
131 121
132 bool GetDisplayId(XID output_id, size_t output_index, int64* display_id_out) { 122 bool GetDisplayId(XID output_id, size_t output_index, int64* display_id_out) {
133 unsigned long nitems = 0; 123 unsigned long nitems = 0;
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 const XRRModeInfo* FindXRRModeInfo(const XRRScreenResources* screen_resources, 324 const XRRModeInfo* FindXRRModeInfo(const XRRScreenResources* screen_resources,
335 XID current_mode) { 325 XID current_mode) {
336 for (int m = 0; m < screen_resources->nmode; m++) { 326 for (int m = 0; m < screen_resources->nmode; m++) {
337 XRRModeInfo *mode = &screen_resources->modes[m]; 327 XRRModeInfo *mode = &screen_resources->modes[m];
338 if (mode->id == current_mode) 328 if (mode->id == current_mode)
339 return mode; 329 return mode;
340 } 330 }
341 return NULL; 331 return NULL;
342 } 332 }
343 333
344 // Find a mode that matches the given size with highest
345 // reflesh rate.
346 RRMode FindOutputModeMatchingSize(
347 const XRRScreenResources* screen_resources,
348 const XRROutputInfo* output_info,
349 size_t width,
350 size_t height) {
351 RRMode found = None;
352 float best_rate = 0;
353 bool non_interlaced_found = false;
354 for (int i = 0; i < output_info->nmode; ++i) {
355 RRMode mode = output_info->modes[i];
356 const XRRModeInfo* info = FindXRRModeInfo(screen_resources, mode);
357
358 if (info->width == width && info->height == height) {
359 float rate = GetRefreshRate(info);
360
361 if (info->modeFlags & RR_Interlace) {
362 if (non_interlaced_found)
363 continue;
364 } else {
365 // Reset the best rate if the non interlaced is
366 // found the first time.
367 if (!non_interlaced_found) {
368 best_rate = rate;
369 }
370 non_interlaced_found = true;
371 }
372 if (rate < best_rate)
373 continue;
374
375 found = mode;
376 best_rate = rate;
377 }
378 }
379 return found;
380 }
381
382 namespace test { 334 namespace test {
383 335
384 XRRModeInfo CreateModeInfo(int id, 336 XRRModeInfo CreateModeInfo(int id,
385 int width, 337 int width,
386 int height, 338 int height,
387 bool interlaced, 339 bool interlaced,
388 float refresh_rate) { 340 float refresh_rate) {
389 XRRModeInfo mode_info = {0}; 341 XRRModeInfo mode_info = {0};
390 mode_info.id = id; 342 mode_info.id = id;
391 mode_info.width = width; 343 mode_info.width = width;
392 mode_info.height = height; 344 mode_info.height = height;
393 if (interlaced) 345 if (interlaced)
394 mode_info.modeFlags = RR_Interlace; 346 mode_info.modeFlags = RR_Interlace;
395 if (refresh_rate != 0.0f) { 347 if (refresh_rate != 0.0f) {
396 mode_info.hTotal = 1; 348 mode_info.hTotal = 1;
397 mode_info.vTotal = 1; 349 mode_info.vTotal = 1;
398 mode_info.dotClock = refresh_rate; 350 mode_info.dotClock = refresh_rate;
399 } 351 }
400 return mode_info; 352 return mode_info;
401 } 353 }
402 354
403 } // namespace test 355 } // namespace test
404 356
405 } // namespace chromeos 357 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698