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