Blender V4.3
GHOST_DisplayManagerWin32.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10#include "GHOST_Debug.hh"
11
12#define WIN32_LEAN_AND_MEAN
13#include <windows.h>
14
15/* We do not support multiple monitors at the moment. */
16#define COMPILE_MULTIMON_STUBS
17
18#include <multimon.h>
19
21
23{
24 numDisplays = ::GetSystemMetrics(SM_CMONITORS);
25 return numDisplays > 0 ? GHOST_kSuccess : GHOST_kFailure;
26}
27
28static BOOL get_dd(DWORD d, DISPLAY_DEVICE *dd)
29{
30 dd->cb = sizeof(DISPLAY_DEVICE);
31 return ::EnumDisplayDevices(nullptr, d, dd, 0);
32}
33
35 int32_t &numSettings) const
36{
37 /* When you call #EnumDisplaySettings with #iModeNum set to zero, the operating system
38 * initializes and caches information about the display device.
39 * When you call #EnumDisplaySettings with #iModeNum set to a non-zero value,
40 * the function returns the information that was cached the last time the
41 * function was called with #iModeNum set to zero. */
42
43 DISPLAY_DEVICE display_device;
44 if (!get_dd(display, &display_device)) {
45 return GHOST_kFailure;
46 }
47
48 numSettings = 0;
49 DEVMODE dm;
50 while (::EnumDisplaySettings(display_device.DeviceName, numSettings, &dm)) {
51 numSettings++;
52 }
53 return GHOST_kSuccess;
54}
55
57 int32_t index,
58 GHOST_DisplaySetting &setting) const
59{
60 DISPLAY_DEVICE display_device;
61 if (!get_dd(display, &display_device)) {
62 return GHOST_kFailure;
63 }
64
65 GHOST_TSuccess success;
66 DEVMODE dm;
67 if (::EnumDisplaySettings(display_device.DeviceName, index, &dm)) {
68#ifdef WITH_GHOST_DEBUG
69 printf("display mode: width=%d, height=%d, bpp=%d, frequency=%d\n",
70 dm.dmPelsWidth,
71 dm.dmPelsHeight,
72 dm.dmBitsPerPel,
73 dm.dmDisplayFrequency);
74#endif /* WITH_GHOST_DEBUG */
75 setting.xPixels = dm.dmPelsWidth;
76 setting.yPixels = dm.dmPelsHeight;
77 setting.bpp = dm.dmBitsPerPel;
78 /* When you call the #EnumDisplaySettings function, the #dmDisplayFrequency member
79 * may return with the value 0 or 1. These values represent the display hardware's
80 * default refresh rate. This default rate is typically set by switches on a display
81 * card or computer motherboard, or by a configuration program that does not use
82 * Win32 display functions such as #ChangeDisplaySettings. */
83
84 /* First, we tried to explicitly set the frequency to 60 if #EnumDisplaySettings
85 * returned 0 or 1 but this doesn't work since later on an exact match will
86 * be searched. And this will never happen if we change it to 60. Now we rely
87 * on the default hardware setting. */
88 setting.frequency = dm.dmDisplayFrequency;
89 success = GHOST_kSuccess;
90 }
91 else {
92 success = GHOST_kFailure;
93 }
94 return success;
95}
96
98 uint8_t display, GHOST_DisplaySetting &setting) const
99{
100 return getDisplaySetting(display, ENUM_CURRENT_SETTINGS, setting);
101}
102
104 uint8_t display, const GHOST_DisplaySetting &setting)
105{
106 DISPLAY_DEVICE display_device;
107 if (!get_dd(display, &display_device)) {
108 return GHOST_kFailure;
109 }
110
112 findMatch(display, setting, match);
113 DEVMODE dm;
114 int i = 0;
115 while (::EnumDisplaySettings(display_device.DeviceName, i++, &dm)) {
116 if ((dm.dmBitsPerPel == match.bpp) && (dm.dmPelsWidth == match.xPixels) &&
117 (dm.dmPelsHeight == match.yPixels) && (dm.dmDisplayFrequency == match.frequency))
118 {
119 break;
120 }
121 }
122#if 0
123 dm.dmBitsPerPel = match.bpp;
124 dm.dmPelsWidth = match.xPixels;
125 dm.dmPelsHeight = match.yPixels;
126 dm.dmDisplayFrequency = match.frequency;
127 dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
128 dm.dmSize = sizeof(DEVMODE);
129 dm.dmDriverExtra = 0;
130#endif
131
132#ifdef WITH_GHOST_DEBUG
133 printf("display change: Requested settings:\n");
134 printf(" dmBitsPerPel=%d\n", dm.dmBitsPerPel);
135 printf(" dmPelsWidth=%d\n", dm.dmPelsWidth);
136 printf(" dmPelsHeight=%d\n", dm.dmPelsHeight);
137 printf(" dmDisplayFrequency=%d\n", dm.dmDisplayFrequency);
138#endif /* WITH_GHOST_DEBUG */
139
140 LONG status = ::ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
141#ifdef WITH_GHOST_DEBUG
142 switch (status) {
143 case DISP_CHANGE_SUCCESSFUL:
144 printf("display change: The settings change was successful.\n");
145 break;
146 case DISP_CHANGE_RESTART:
147 printf(
148 "display change: The computer must be restarted in order for the graphics mode to "
149 "work.\n");
150 break;
151 case DISP_CHANGE_BADFLAGS:
152 printf("display change: An invalid set of flags was passed in.\n");
153 break;
154 case DISP_CHANGE_BADPARAM:
155 printf(
156 "display change: An invalid parameter was passed in. "
157 "This can include an invalid flag or combination of flags.\n");
158 break;
159 case DISP_CHANGE_FAILED:
160 printf("display change: The display driver failed the specified graphics mode.\n");
161 break;
162 case DISP_CHANGE_BADMODE:
163 printf("display change: The graphics mode is not supported.\n");
164 break;
165 case DISP_CHANGE_NOTUPDATED:
166 printf("display change: Windows NT: Unable to write settings to the registry.\n");
167 break;
168 default:
169 printf("display change: Return value invalid\n");
170 break;
171 }
172#endif /* WITH_GHOST_DEBUG */
173 return status == DISP_CHANGE_SUCCESSFUL ? GHOST_kSuccess : GHOST_kFailure;
174}
static BOOL get_dd(DWORD d, DISPLAY_DEVICE *dd)
GHOST_TSuccess
Definition GHOST_Types.h:87
@ GHOST_kFailure
Definition GHOST_Types.h:87
@ GHOST_kSuccess
Definition GHOST_Types.h:87
GHOST_TSuccess getNumDisplaySettings(uint8_t display, int32_t &numSettings) const
GHOST_TSuccess getDisplaySetting(uint8_t display, int32_t index, GHOST_DisplaySetting &setting) const
GHOST_TSuccess setCurrentDisplaySetting(uint8_t display, const GHOST_DisplaySetting &setting)
GHOST_TSuccess getNumDisplays(uint8_t &numDisplays) const
GHOST_TSuccess getCurrentDisplaySetting(uint8_t display, GHOST_DisplaySetting &setting) const
GHOST_TSuccess findMatch(uint8_t display, const GHOST_DisplaySetting &setting, GHOST_DisplaySetting &match) const
#define printf
signed int int32_t
Definition stdint.h:77
unsigned char uint8_t
Definition stdint.h:78