OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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 |
| 5 #include "monitor_reconfig/resolution_selector.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 |
| 9 namespace monitor_reconfig { |
| 10 |
| 11 using std::string; |
| 12 using std::vector; |
| 13 |
| 14 |
| 15 const int ResolutionSelector::kMaxProjectorPixels = 1280 * 720; |
| 16 |
| 17 |
| 18 bool ResolutionSelector::FindBestResolutions( |
| 19 const vector<Mode>& lcd_modes, |
| 20 const vector<Mode>& external_modes, |
| 21 string* lcd_resolution, |
| 22 string* external_resolution, |
| 23 string* screen_resolution) { |
| 24 DCHECK(!lcd_modes.empty()); |
| 25 |
| 26 // If there's no external display, just use the highest resolution |
| 27 // available from the LCD. |
| 28 if (external_modes.empty()) { |
| 29 *lcd_resolution = *screen_resolution = lcd_modes[0].name; |
| 30 external_resolution->clear(); |
| 31 return true; |
| 32 } |
| 33 |
| 34 const int max_lcd_size = lcd_modes[0].width * lcd_modes[0].height; |
| 35 const int max_external_size = |
| 36 external_modes[0].width * external_modes[0].height; |
| 37 |
| 38 if (max_lcd_size >= max_external_size) { |
| 39 return FindNearestResolutions( |
| 40 lcd_modes, external_modes, |
| 41 lcd_resolution, external_resolution, screen_resolution); |
| 42 } else { |
| 43 // If the external output is large enough that we think it's a monitor |
| 44 // (as opposed to a projector), then we just use its max resolution and |
| 45 // forget about trying to choose a screen size that'll fit on the |
| 46 // built-in display. |
| 47 if (max_external_size > kMaxProjectorPixels) { |
| 48 *external_resolution = *screen_resolution = external_modes[0].name; |
| 49 *lcd_resolution = lcd_modes[0].name; |
| 50 return true; |
| 51 } |
| 52 return FindNearestResolutions( |
| 53 external_modes, lcd_modes, |
| 54 external_resolution, lcd_resolution, screen_resolution); |
| 55 } |
| 56 } |
| 57 |
| 58 bool ResolutionSelector::FindNearestResolutions( |
| 59 const vector<Mode>& larger_device_modes, |
| 60 const vector<Mode>& smaller_device_modes, |
| 61 std::string* larger_resolution, |
| 62 std::string* smaller_resolution, |
| 63 std::string* screen_resolution) { |
| 64 DCHECK(!larger_device_modes.empty()); |
| 65 DCHECK(!smaller_device_modes.empty()); |
| 66 DCHECK(larger_resolution); |
| 67 DCHECK(smaller_resolution); |
| 68 DCHECK(screen_resolution); |
| 69 |
| 70 // Start with the best that the smaller device has to offer. |
| 71 *smaller_resolution = smaller_device_modes[0].name; |
| 72 *screen_resolution = *smaller_resolution; |
| 73 int smaller_width = smaller_device_modes[0].width; |
| 74 int smaller_height = smaller_device_modes[0].height; |
| 75 |
| 76 for (vector<Mode>::const_reverse_iterator it = |
| 77 larger_device_modes.rbegin(); |
| 78 it != larger_device_modes.rend(); ++it) { |
| 79 if (it->width >= smaller_width && it->height >= smaller_height) { |
| 80 *larger_resolution = it->name; |
| 81 return true; |
| 82 } |
| 83 } |
| 84 |
| 85 LOG(WARNING) << "Failed to find a resolution from larger device " |
| 86 << "exceeding chosen resolution from smaller device (" |
| 87 << *smaller_resolution << ")"; |
| 88 return false; |
| 89 } |
| 90 |
| 91 } // namespace monitor_reconfig |
OLD | NEW |