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