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