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_MONITOR_RECONFIGURE_H_ |
| 6 #define POWER_MANAGER_MONITOR_RECONFIGURE_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <vector> |
| 10 |
| 11 #include <X11/Xlib.h> |
| 12 #include <X11/extensions/Xrandr.h> |
| 13 |
| 14 #include "power_manager/resolution_selector.h" |
| 15 #include "power_manager/udev_controller.h" |
| 16 |
| 17 namespace power_manager { |
| 18 |
| 19 class BacklightController; |
| 20 class MonitorReconfigure; |
| 21 |
| 22 // Delegate class for udev events. |
| 23 class MonitorReconfigureDelegate : public UdevDelegate { |
| 24 public: |
| 25 MonitorReconfigureDelegate(MonitorReconfigure* monitor_reconfigure) |
| 26 : monitor_reconfigure_(monitor_reconfigure) {} |
| 27 |
| 28 virtual void Run(GIOChannel* source, GIOCondition condition); |
| 29 private: |
| 30 MonitorReconfigure* monitor_reconfigure_; |
| 31 }; |
| 32 |
| 33 // MonitorReconfigure is the class responsible for setting the external |
| 34 // monitor to the max resolution based on the modes supported by the native |
| 35 // monitor and the external monitor. |
| 36 class MonitorReconfigure { |
| 37 public: |
| 38 // We need a default constructor for unit tests. |
| 39 MonitorReconfigure(); |
| 40 // |backlight_ctl| is a pointer to the backlight controller for the |
| 41 // internal screen. |
| 42 MonitorReconfigure(BacklightController* backlight_ctl); |
| 43 ~MonitorReconfigure(); |
| 44 |
| 45 // Initialization. |
| 46 bool Init(); |
| 47 |
| 48 // Main entry point. |
| 49 void Run(); |
| 50 |
| 51 private: |
| 52 // Initializes the |lcd_output_| and |external_output_| members. |
| 53 void DetermineOutputs(); |
| 54 |
| 55 // Returns whether an external monitor is connected. |
| 56 bool IsExternalMonitorConnected(); |
| 57 |
| 58 // Sorts |output_info|'s modes by decreasing number of pixels, storing the |
| 59 // results in |modes_out|. |
| 60 void SortModesByResolution(RROutput output, |
| 61 std::vector<ResolutionSelector::Mode>* modes_out); |
| 62 |
| 63 // Set the resolution for a particular device or for the screen. |
| 64 bool SetDeviceResolution(RROutput output, |
| 65 const XRROutputInfo* output_info, |
| 66 const ResolutionSelector::Mode& resolution); |
| 67 bool SetScreenResolution(const ResolutionSelector::Mode& resolution); |
| 68 |
| 69 // Disable output to a device. |
| 70 bool DisableDevice(const XRROutputInfo* output_info); |
| 71 |
| 72 // Mapping between mode XIDs and mode information structures. |
| 73 std::map<int, XRRModeInfo*> mode_map_; |
| 74 |
| 75 // X Resources needed between functions. |
| 76 Display* display_; |
| 77 Window window_; |
| 78 XRRScreenResources* screen_info_; |
| 79 |
| 80 RROutput lcd_output_; |
| 81 XRROutputInfo* lcd_output_info_; |
| 82 |
| 83 RROutput external_output_; |
| 84 XRROutputInfo* external_output_info_; |
| 85 |
| 86 // Not owned. |
| 87 BacklightController* backlight_ctl_; |
| 88 |
| 89 // Delegate for the Udev controller. |
| 90 MonitorReconfigureDelegate* delegate_; |
| 91 |
| 92 // Udev controller. |
| 93 UdevController* controller_; |
| 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(MonitorReconfigure); |
| 96 }; |
| 97 |
| 98 } // namespace power_manager |
| 99 |
| 100 #endif // POWER_MANAGER_MONITOR_RECONFIGURE_H_ |
OLD | NEW |