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