[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / powermanagement / DPMSSupport.h
1 /*
2  *      Copyright (C) 2009-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #ifndef DPMSSUPPORT_H
22 #define DPMSSUPPORT_H
23
24 #include <vector>
25
26 // This class encapsulates support for monitor power-saving features (DPMS).
27 // An instance is connected to a Surface, provides information on which
28 // power-saving features are available for that screen, and it is able to
29 // turn power-saving on an off.
30 // Note that SDL turns off DPMS timeouts at the beginning of the application.
31 class DPMSSupport
32 {
33 public:
34   // All known DPMS power-saving modes, on any platform.
35   enum PowerSavingMode
36   {
37     STANDBY, SUSPEND, OFF,
38     NUM_MODES
39   };
40
41   // Initializes an instance tied to the specified Surface. The Surface object
42   // must be alive for as long as this instance is in use.
43   DPMSSupport();
44
45   // Whether power-saving is supported on this screen.
46   bool IsSupported() const { return !m_supportedModes.empty(); }
47   // Which power-saving modes are supported, in the order of preference (i.e.
48   // the first mode should be the best choice).
49   const std::vector<PowerSavingMode>& GetSupportedModes() const
50   {
51     return m_supportedModes;
52   }
53   // Whether a given mode is supported.
54   bool IsModeSupported(PowerSavingMode mode) const;
55
56   // Untranslated name of the mode, for logging.
57   static const char* GetModeName(PowerSavingMode mode);
58   // Returns true if the given mode is valid (a member of PowerSavingMode).
59   // Returns false and logs an error message otherwise.
60   static bool CheckValidMode(PowerSavingMode mode);
61
62   // Turns on the specified power-saving mode, which must be valid
63   // and supported. Returns false if this failed.
64   bool EnablePowerSaving(PowerSavingMode mode);
65   // Turns off power-saving mode. You should only call this if the display
66   // is currently in a power-saving mode, to avoid visual artifacts.
67   bool DisablePowerSaving();
68
69 private:
70   std::vector<PowerSavingMode> m_supportedModes;
71
72   // Platform-specific code: add new #ifdef'ed implementations in the .cc file.
73   //
74   // Initializes DPMS support. Should populate m_supportedModes with the
75   // preferred order of the modes, if supported, otherwise leave it empty.
76   // If the latter, it should log a message about exactly why DPMS is not
77   // available.
78   void PlatformSpecificInit();
79   // Should turn on power-saving on the current platform. The mode is
80   // guaranteed to be one of m_supportedModes. Should return false on failure,
81   // and log a (platform-specific) ERROR message.
82   bool PlatformSpecificEnablePowerSaving(PowerSavingMode mode);
83   // Should turn off power-saving on the current platform. Should return
84   // false on failure and log a (platform-specific) ERROR message.
85   bool PlatformSpecificDisablePowerSaving();
86 };
87
88 #endif  // DPMSSUPPORT_H