forked from stepmania/stepmania
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplaySpec.h
204 lines (182 loc) · 6.23 KB
/
DisplaySpec.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#ifndef DisplaySpec_H
#define DisplaySpec_H
#include <set>
#include <rage/RageRect.hpp>
#include "RageTypes.h"
struct DisplayMode {
// Width (in pixels) of the display in this mode
unsigned int width;
// Height (in pixels) of the display in this mode
unsigned int height;
/** Refresh rate, in hz, of the display for the given mode
* MacOS Quartz Display Services provides rate as double,
* winapi DEVMODE uses 32bit unsigned int (still gives rate as hz),
* RandR gives 32 bit pixel clock, which is then divided by width*height.
*/
double refreshRate;
/*
* Bits-per-pixel is *not* a property of the DisplayMode for our purposes:
* bit-depth is going to be a property of the OpenGL/D3D context, not a display
* configuration
*/
bool operator<( const DisplayMode &other ) const
{
/** @brief A quick way to compare the two DisplayResolutions. */
#define COMPARE(x) if( x != other.x ) return x < other.x;
COMPARE( width );
COMPARE( height );
COMPARE( refreshRate );
#undef COMPARE
return false;
}
// Lua
void PushSelf( lua_State *L );
};
/** @brief The dimensions of the program. */
class DisplaySpec
{
public:
/*
* Construct a specification for the display with the given ID, which supports the given modes,
* and is currently using the specified mode with the specified logical screen bounds
*/
DisplaySpec(const std::string &id,
const std::string &name,
const std::set<DisplayMode> &modes,
const DisplayMode &curMode,
const Rage::RectI &curBounds,
const bool isVirtual=false):
m_sId( id ), m_sName( name ),
m_sModes( modes ), m_bCurModeActive( true ), m_CurMode( curMode ),
m_rectBounds( curBounds ), m_bIsVirtual( isVirtual )
{
if ( m_sModes.find( curMode ) == m_sModes.end() )
{
// This is an error, make a failing assertion with a descriptive error message
std::stringstream msgStream;
msgStream << "DisplaySpec current mode (" << curMode.width << "x" <<
curMode.height << "@" << curMode.refreshRate << ") not in given list of supported modes: ";
for ( auto &m : modes )
{
msgStream << m.width << "x" << m.height << "@" << m.refreshRate << ", ";
}
auto msg = msgStream.str();
// Drop the trailing ", "
msg.resize( msg.size() - 2 );
ASSERT_M( false, msg );
}
}
/*
* Construct a specification for the display with the given ID, which supports the given modes,
* and is currently disabled (has no active mode)
*/
DisplaySpec(const std::string id,
const std::string name,
const std::set<DisplayMode> modes,
const bool isVirtual=false):
m_sId( id ), m_sName( name ),
m_sModes( modes ), m_bCurModeActive( false ), m_CurMode( { 0 } ),
m_bIsVirtual( isVirtual )
{
}
// Create a specification for a display supporting a single (and currently active) mode
DisplaySpec(std::string id, std::string name, DisplayMode mode) : m_sId( id ), m_sName( name ), m_bIsVirtual( false ),
m_bCurModeActive( true ), m_CurMode( mode )
{
m_sModes.insert( mode );
m_rectBounds = Rage::RectI( 0, 0, mode.width, mode.height );
}
DisplaySpec( const DisplaySpec &other ) = default;
std::string name() const
{
return m_sName;
}
std::string id() const
{
return m_sId;
}
const std::set<DisplayMode> &supportedModes() const
{
return m_sModes;
}
/*
* Return a pointer to the currently active display mode, or NULL if
* display is inactive
*
* Note that inactive *does not* necessarily mean unusable. E.g., in X11,
* an output can be enabled/disabled by an application by connecting/disconnecting
* a crtc
*/
const DisplayMode *currentMode() const
{
return m_bCurModeActive ? &m_CurMode : nullptr;
}
const Rage::RectI ¤tBounds() const
{
return m_rectBounds;
}
bool isVirtual() const
{
return m_bIsVirtual;
}
/**
* @brief Determine if one DisplaySpec compares less than the other.
*
* Used to enforce a consistent ordering of displays, e.g. for consistent option
* presentation. Also allows DisplaySpec to be placed in a std::set
*
* @param other the other DisplaySpec to check.
* @return true if this DisplaySpec is less than the other, or false otherwise. */
bool operator<( const DisplaySpec &other ) const
{
return m_sId < other.id();
}
// Lua
void PushSelf( lua_State *L );
private:
// Unique identifier of the display
std::string m_sId;
// "Human-readable" display name
std::string m_sName;
// Modes supported by this display
std::set<DisplayMode> m_sModes;
// currently configured mode, if available
bool m_bCurModeActive;
DisplayMode m_CurMode;
// The current bounds of this display in global display coordinate space
Rage::RectI m_rectBounds;
// Flag is "true" when display represents a logical display like an X screen
// or the Win32 "Virtual screen"
bool m_bIsVirtual;
};
/** @brief The collection of DisplaySpec available within the program. */
typedef std::set<DisplaySpec> DisplaySpecs;
//Lua
DisplaySpecs *pushDisplaySpecs(lua_State *L, const DisplaySpecs &specs);
#endif
/**
* @file
* @author Chris Danford (c) 2001-2005
* @section LICENSE
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/