forked from doitsujin/dxvk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwsi_monitor_glfw.cpp
More file actions
160 lines (114 loc) · 3.4 KB
/
wsi_monitor_glfw.cpp
File metadata and controls
160 lines (114 loc) · 3.4 KB
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
#include "../wsi_monitor.h"
#include "wsi/native_wsi.h"
#include "wsi_platform_glfw.h"
#include "../../util/util_string.h"
#include "../../util/log/log.h"
#include <string>
#include <sstream>
namespace dxvk::wsi {
HMONITOR getDefaultMonitor() {
return enumMonitors(0);
}
HMONITOR enumMonitors(uint32_t index) {
return isDisplayValid(int32_t(index))
? toHmonitor(index)
: nullptr;
}
bool getDisplayName(
HMONITOR hMonitor,
WCHAR (&Name)[32]) {
const int32_t displayId = fromHmonitor(hMonitor);
if (!isDisplayValid(displayId))
return false;
std::wstringstream nameStream;
nameStream << LR"(\\.\DISPLAY)" << (displayId + 1);
std::wstring name = nameStream.str();
std::memset(Name, 0, sizeof(Name));
name.copy(Name, name.length(), 0);
return true;
}
bool getDesktopCoordinates(
HMONITOR hMonitor,
RECT *pRect) {
const int32_t displayId = fromHmonitor(hMonitor);
if (!isDisplayValid(displayId))
return false;
int32_t displayCount = 0;
GLFWmonitor **monitors = glfwGetMonitors(&displayCount);
GLFWmonitor *monitor = monitors[displayId];
int32_t x;
int32_t y;
int32_t w;
int32_t h;
glfwGetMonitorWorkarea(monitor, &x, &y, &w, &h);
pRect->left = x;
pRect->top = y;
pRect->right = x + w;
pRect->bottom = y + h;
return true;
}
static inline uint32_t roundToNextPow2(uint32_t num) {
if (num-- == 0)
return 0;
num |= num >> 1;
num |= num >> 2;
num |= num >> 4;
num |= num >> 8;
num |= num >> 16;
return ++num;
}
static inline void convertMode(const GLFWvidmode &mode, WsiMode *pMode) {
pMode->width = uint32_t(mode.width);
pMode->height = uint32_t(mode.height);
pMode->refreshRate = WsiRational{uint32_t(mode.refreshRate) * 1000, 1000};
// BPP should always be a power of two
// to match Windows behaviour of including padding.
pMode->bitsPerPixel = roundToNextPow2(mode.blueBits + mode.redBits + mode.greenBits);
pMode->interlaced = false;
}
bool getDisplayMode(
HMONITOR hMonitor,
uint32_t ModeNumber,
WsiMode *pMode) {
const int32_t displayId = fromHmonitor(hMonitor);
int32_t displayCount = 0;
GLFWmonitor **monitors = glfwGetMonitors(&displayCount);
GLFWmonitor *monitor = monitors[displayId];
if (!isDisplayValid(displayId))
return false;
int32_t count = 0;
const GLFWvidmode *modes = glfwGetVideoModes(monitor, &count);
convertMode(modes[ModeNumber], pMode);
return true;
}
bool getCurrentDisplayMode(
HMONITOR hMonitor,
WsiMode *pMode) {
const int32_t displayId = fromHmonitor(hMonitor);
if (!isDisplayValid(displayId))
return false;
int32_t displayCount = 0;
GLFWmonitor **monitors = glfwGetMonitors(&displayCount);
GLFWmonitor *monitor = monitors[displayId];
auto mode = glfwGetVideoMode(monitor);
convertMode(*mode, pMode);
return true;
}
bool getDesktopDisplayMode(
HMONITOR hMonitor,
WsiMode *pMode) {
const int32_t displayId = fromHmonitor(hMonitor);
if (!isDisplayValid(displayId))
return false;
int32_t displayCount = 0;
GLFWmonitor **monitors = glfwGetMonitors(&displayCount);
GLFWmonitor *monitor = monitors[displayId];
//TODO: actually implement this properly, currently we just grab the current one
convertMode(*glfwGetVideoMode(monitor), pMode);
return true;
}
std::vector<uint8_t> getMonitorEdid(HMONITOR hMonitor) {
Logger::err("getMonitorEdid not implemented on this platform.");
return {};
}
}