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