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 #ifndef MONITOR_RECONFIGURE_RESOLUTION_SELECTOR_H_ |
| 6 #define MONITOR_RECONFIGURE_RESOLUTION_SELECTOR_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 |
| 13 namespace monitor_reconfig { |
| 14 |
| 15 // ResolutionSelector takes the sets of resolutions supported by the |
| 16 // built-in and external displays as input and attempts to choose a shared |
| 17 // resolution that will work well on both devices. |
| 18 class ResolutionSelector { |
| 19 public: |
| 20 // A single mode supported by a device, equivalent to the XRRModeInfo |
| 21 // struct. |
| 22 struct Mode { |
| 23 Mode(int width, int height, std::string name) |
| 24 : width(width), |
| 25 height(height), |
| 26 name(name) { |
| 27 } |
| 28 |
| 29 // Mode's dimensions. |
| 30 int width; |
| 31 int height; |
| 32 |
| 33 // Mode's name from XRandR. This uniquely describes the mode and can |
| 34 // be used to set the devices's resolution later. |
| 35 std::string name; |
| 36 }; |
| 37 |
| 38 // Maximum screen size for the external output at which we assume that |
| 39 // it's a projector (as opposed to a monitor) and try to find a size that |
| 40 // will also fit on the LCD display. Above this, we just use the |
| 41 // external output's maximum resolution, even if it doesn't fit on the |
| 42 // LCD. |
| 43 static const int kMaxProjectorPixels; |
| 44 |
| 45 ResolutionSelector() {} |
| 46 ~ResolutionSelector() {} |
| 47 |
| 48 // Comparator used to sort Mode objects. |
| 49 // Returns true if |mode_a| has more pixels than |mode_b| and false otherwise. |
| 50 class ModeResolutionComparator { |
| 51 public: |
| 52 bool operator()(const Mode& mode_a, const Mode& mode_b) const { |
| 53 return mode_a.width * mode_a.height > mode_b.width * mode_b.height; |
| 54 } |
| 55 }; |
| 56 |
| 57 // Find the "best" resolutions for various outputs. |
| 58 // The returned strings contain |name| values from the passed-in modes. |
| 59 bool FindBestResolutions( |
| 60 const std::vector<Mode>& lcd_modes, |
| 61 const std::vector<Mode>& external_modes, |
| 62 std::string* lcd_resolution, |
| 63 std::string* external_resolution, |
| 64 std::string* screen_resolution); |
| 65 |
| 66 private: |
| 67 // Find resolutions to use that are reasonably close together. |
| 68 // |larger_device_modes| and |smaller_device_modes| should be sorted by |
| 69 // descending resolution. We choose the highest resolution from |
| 70 // |smaller_device_modes| and the lowest resolution from |larger_device_modes| |
| 71 // that's at least as high as the resolution from the smaller device. |
| 72 // |screen_resolution| gets set to |smaller_resolution| to avoid clipping. |
| 73 bool FindNearestResolutions( |
| 74 const std::vector<Mode>& larger_device_modes, |
| 75 const std::vector<Mode>& smaller_device_modes, |
| 76 std::string* larger_resolution, |
| 77 std::string* smaller_resolution, |
| 78 std::string* screen_resolution); |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(ResolutionSelector); |
| 81 }; |
| 82 |
| 83 } // namespace monitor_reconfig |
| 84 |
| 85 #endif // MONITOR_RECONFIGURE_RESOLUTION_SELECTOR_H_ |
OLD | NEW |