Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: resolution_selector.h

Issue 6812041: Refactor monitor_reconfigure to stop using system("xrandr"). (Closed) Base URL: ssh://gitrw.chromium.org:9222/monitor_reconfig.git@0.11.257.B
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « monitor_reconfigure_main.cc ('k') | resolution_selector.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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, int height, std::string name, int id)
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
30 Mode()
31 : width(0),
32 height(0),
33 name(""),
34 id(0) {
35 }
29 // Mode's dimensions. 36 // Mode's dimensions.
30 int width; 37 int width;
31 int height; 38 int height;
32 39
33 // Mode's name from XRandR. This uniquely describes the mode and can 40 // Mode's name from XRandR. This uniquely describes the mode and can
34 // be used to set the devices's resolution later. 41 // be used to set the devices's resolution later.
35 std::string name; 42 std::string name;
43
44 // The mode id, used for setting this mode.
45 unsigned id;
36 }; 46 };
37 47
38 // Maximum screen size for the external output at which we assume that 48 // 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 49 // 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 50 // 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 51 // external output's maximum resolution, even if it doesn't fit on the
42 // LCD. 52 // LCD.
43 static const int kMaxProjectorPixels; 53 static const int kMaxProjectorPixels;
44 54
45 ResolutionSelector() {} 55 ResolutionSelector() {}
46 ~ResolutionSelector() {} 56 ~ResolutionSelector() {}
47 57
48 // Comparator used to sort Mode objects. 58 // Comparator used to sort Mode objects.
49 // Returns true if |mode_a| has more pixels than |mode_b| and false otherwise. 59 // Returns true if |mode_a| has more pixels than |mode_b| and false otherwise.
50 class ModeResolutionComparator { 60 class ModeResolutionComparator {
51 public: 61 public:
52 bool operator()(const Mode& mode_a, const Mode& mode_b) const { 62 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; 63 return mode_a.width * mode_a.height > mode_b.width * mode_b.height;
54 } 64 }
55 }; 65 };
56 66
57 // Find the "best" resolutions for various outputs. 67 // Find the "best" resolutions for various outputs.
58 // The returned strings contain |name| values from the passed-in modes. 68 // Returns the modes for both screens and the total screen resolution.
59 bool FindBestResolutions( 69 bool FindBestResolutions(
60 const std::vector<Mode>& lcd_modes, 70 const std::vector<Mode>& lcd_modes,
61 const std::vector<Mode>& external_modes, 71 const std::vector<Mode>& external_modes,
62 std::string* lcd_resolution, 72 Mode* lcd_resolution,
63 std::string* external_resolution, 73 Mode* external_resolution,
64 std::string* screen_resolution); 74 Mode* screen_resolution);
65 75
66 private: 76 private:
67 // Find resolutions to use that are reasonably close together. 77 // Find resolutions to use that are reasonably close together.
68 // |larger_device_modes| and |smaller_device_modes| should be sorted by 78 // |larger_device_modes| and |smaller_device_modes| should be sorted by
69 // descending resolution. We choose the highest resolution from 79 // descending resolution. We choose the highest resolution from
70 // |smaller_device_modes| and the lowest resolution from |larger_device_modes| 80 // |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. 81 // that's at least as high as the resolution from the smaller device.
72 // |screen_resolution| gets set to |smaller_resolution| to avoid clipping. 82 // |screen_resolution| gets set to |smaller_resolution| to avoid clipping.
73 bool FindNearestResolutions( 83 bool FindNearestResolutions(
74 const std::vector<Mode>& larger_device_modes, 84 const std::vector<Mode>& larger_device_modes,
75 const std::vector<Mode>& smaller_device_modes, 85 const std::vector<Mode>& smaller_device_modes,
76 std::string* larger_resolution, 86 Mode* larger_resolution,
77 std::string* smaller_resolution, 87 Mode* smaller_resolution,
78 std::string* screen_resolution); 88 Mode* screen_resolution);
79 89
80 DISALLOW_COPY_AND_ASSIGN(ResolutionSelector); 90 DISALLOW_COPY_AND_ASSIGN(ResolutionSelector);
81 }; 91 };
82 92
83 } // namespace monitor_reconfig 93 } // namespace monitor_reconfig
84 94
85 #endif // MONITOR_RECONFIGURE_RESOLUTION_SELECTOR_H_ 95 #endif // MONITOR_RECONFIGURE_RESOLUTION_SELECTOR_H_
OLDNEW
« no previous file with comments | « monitor_reconfigure_main.cc ('k') | resolution_selector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698