OLD | NEW |
---|---|
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 Loading... | |
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 | |
114 } // namespace | 124 } // namespace |
115 | 125 |
116 std::string GetDisplayName(XID output_id) { | 126 std::string GetDisplayName(XID output_id) { |
117 std::string display_name; | 127 std::string display_name; |
118 GetOutputDeviceData(output_id, NULL, &display_name); | 128 GetOutputDeviceData(output_id, NULL, &display_name); |
119 return display_name; | 129 return display_name; |
120 } | 130 } |
121 | 131 |
122 bool GetDisplayId(XID output_id, size_t output_index, int64* display_id_out) { | 132 bool GetDisplayId(XID output_id, size_t output_index, int64* display_id_out) { |
123 unsigned long nitems = 0; | 133 unsigned long nitems = 0; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 } | 324 } |
315 | 325 |
316 return false; | 326 return false; |
317 } | 327 } |
318 | 328 |
319 bool IsInternalOutputName(const std::string& name) { | 329 bool IsInternalOutputName(const std::string& name) { |
320 return name.find(kInternal_LVDS) == 0 || name.find(kInternal_eDP) == 0 || | 330 return name.find(kInternal_LVDS) == 0 || name.find(kInternal_eDP) == 0 || |
321 name.find(kInternal_DSI) == 0; | 331 name.find(kInternal_DSI) == 0; |
322 } | 332 } |
323 | 333 |
334 const XRRModeInfo* FindModeInfo(const XRRScreenResources* screen_resources, | |
335 XID current_mode) { | |
336 for (int m = 0; m < screen_resources->nmode; m++) { | |
337 XRRModeInfo *mode = &screen_resources->modes[m]; | |
338 if (mode->id == current_mode) | |
339 return mode; | |
340 } | |
341 return NULL; | |
342 } | |
343 | |
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 = FindModeInfo(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 first time. | |
Daniel Erat
2013/07/31 17:34:05
nit: s/found first/found the first/
oshima
2013/07/31 21:59:49
Done.
| |
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 { | |
383 | |
384 XRRModeInfo CreateModeInfo(int id, | |
385 int width, | |
386 int height, | |
387 bool interlaced, | |
388 float refresh_rate) { | |
389 XRRModeInfo mode_info = {0}; | |
390 mode_info.id = id; | |
391 mode_info.width = width; | |
392 mode_info.height = height; | |
393 if (interlaced) | |
394 mode_info.modeFlags = RR_Interlace; | |
395 if (refresh_rate != 0.0f) { | |
396 mode_info.hTotal = 1; | |
397 mode_info.vTotal = 1; | |
398 mode_info.dotClock = refresh_rate; | |
399 } | |
400 return mode_info; | |
401 } | |
402 | |
403 } | |
Daniel Erat
2013/07/31 17:34:05
nit: add // namespace test
oshima
2013/07/31 21:59:49
Done.
| |
404 | |
324 } // namespace chromeos | 405 } // namespace chromeos |
OLD | NEW |