src/video/windows/SDL_windowsmodes.c
author Alfred Reynolds <alfred@valvesoftware.com>
Wed, 29 Jul 2015 17:19:13 -0700
changeset 9819 2361f732e8cb
parent 9813 0652406e46c6
child 9889 7cb2c3ec8205
permissions -rw-r--r--
Fix up monitor enumeration for Windows 8.1 case.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
     2
  Simple DirectMedia Layer
9619
b94b6d0bff0f Updated the copyright year to 2015
Sam Lantinga <slouken@libsdl.org>
parents: 8795
diff changeset
     3
  Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
     7
  arising from the use of this software.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
    11
  freely, subject to the following restrictions:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 8086
diff changeset
    21
#include "../../SDL_internal.h"
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    23
#if SDL_VIDEO_DRIVER_WINDOWS
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    24
5062
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 4569
diff changeset
    25
#include "SDL_windowsvideo.h"
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
5086
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
    27
/* Windows CE compatibility */
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
    28
#ifndef CDS_FULLSCREEN
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
    29
#define CDS_FULLSCREEN 0
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
    30
#endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    32
typedef struct _WIN_GetMonitorDPIData {
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    33
	SDL_VideoData *vid_data;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    34
	SDL_DisplayMode *mode;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    35
	SDL_DisplayModeData *mode_data;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    36
} WIN_GetMonitorDPIData;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    37
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    38
static BOOL CALLBACK
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    39
WIN_GetMonitorDPI(HMONITOR hMonitor,
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    40
				  HDC      hdcMonitor,
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    41
				  LPRECT   lprcMonitor,
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    42
				  LPARAM   dwData)
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    43
{
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    44
	WIN_GetMonitorDPIData *data = (WIN_GetMonitorDPIData*) dwData;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    45
	UINT hdpi, vdpi;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    46
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    47
	if (data->vid_data->GetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &hdpi, &vdpi) == S_OK &&
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    48
		hdpi > 0 &&
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    49
		vdpi > 0) {
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    50
		float hsize, vsize;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    51
		
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    52
		data->mode_data->HorzDPI = (float)hdpi;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    53
		data->mode_data->VertDPI = (float)vdpi;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    54
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    55
		// Figure out the monitor size and compute the diagonal DPI.
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    56
		hsize = data->mode->w / data->mode_data->HorzDPI;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    57
		vsize = data->mode->h / data->mode_data->VertDPI;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    58
		
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    59
		data->mode_data->DiagDPI = SDL_ComputeDiagonalDPI( data->mode->w,
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    60
														   data->mode->h,
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    61
														   hsize,
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    62
														   vsize );
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    63
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    64
		// We can only handle one DPI per display mode so end the enumeration.
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    65
		return FALSE;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    66
	}
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    67
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    68
	// We didn't get DPI information so keep going.
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    69
	return TRUE;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    70
}
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    71
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
static SDL_bool
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    73
WIN_GetDisplayMode(_THIS, LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
{
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    75
    SDL_VideoData *vid_data = (SDL_VideoData *) _this->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
    SDL_DisplayModeData *data;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
    DEVMODE devmode;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
    HDC hdc;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
    devmode.dmSize = sizeof(devmode);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
    devmode.dmDriverExtra = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
    if (!EnumDisplaySettings(deviceName, index, &devmode)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
        return SDL_FALSE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
    data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data));
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
    if (!data) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
        return SDL_FALSE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
    data->DeviceMode = devmode;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
    data->DeviceMode.dmFields =
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
        (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY |
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
         DM_DISPLAYFLAGS);
8086
b744b3f8754b Fixed display mode calculations for applications which are not DPI aware.
Sam Lantinga <slouken@libsdl.org>
parents: 7102
diff changeset
    94
	data->ScaleX = 1.0f;
b744b3f8754b Fixed display mode calculations for applications which are not DPI aware.
Sam Lantinga <slouken@libsdl.org>
parents: 7102
diff changeset
    95
	data->ScaleY = 1.0f;
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    96
	data->DiagDPI = 0.0f;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    97
	data->HorzDPI = 0.0f;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    98
	data->VertDPI = 0.0f;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
    /* Fill in the mode information */
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
   101
    mode->format = SDL_PIXELFORMAT_UNKNOWN;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
    mode->w = devmode.dmPelsWidth;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
    mode->h = devmode.dmPelsHeight;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
    mode->refresh_rate = devmode.dmDisplayFrequency;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
    mode->driverdata = data;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   107
    if (index == ENUM_CURRENT_SETTINGS
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   108
        && (hdc = CreateDC(deviceName, NULL, NULL, NULL)) != NULL) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
        char bmi_data[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
        LPBITMAPINFO bmi;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
        HBITMAP hbm;
8086
b744b3f8754b Fixed display mode calculations for applications which are not DPI aware.
Sam Lantinga <slouken@libsdl.org>
parents: 7102
diff changeset
   112
		int logical_width = GetDeviceCaps( hdc, HORZRES );
b744b3f8754b Fixed display mode calculations for applications which are not DPI aware.
Sam Lantinga <slouken@libsdl.org>
parents: 7102
diff changeset
   113
		int logical_height = GetDeviceCaps( hdc, VERTRES );
b744b3f8754b Fixed display mode calculations for applications which are not DPI aware.
Sam Lantinga <slouken@libsdl.org>
parents: 7102
diff changeset
   114
b744b3f8754b Fixed display mode calculations for applications which are not DPI aware.
Sam Lantinga <slouken@libsdl.org>
parents: 7102
diff changeset
   115
		data->ScaleX = (float)logical_width / devmode.dmPelsWidth;
b744b3f8754b Fixed display mode calculations for applications which are not DPI aware.
Sam Lantinga <slouken@libsdl.org>
parents: 7102
diff changeset
   116
		data->ScaleY = (float)logical_height / devmode.dmPelsHeight;
b744b3f8754b Fixed display mode calculations for applications which are not DPI aware.
Sam Lantinga <slouken@libsdl.org>
parents: 7102
diff changeset
   117
		mode->w = logical_width;
b744b3f8754b Fixed display mode calculations for applications which are not DPI aware.
Sam Lantinga <slouken@libsdl.org>
parents: 7102
diff changeset
   118
		mode->h = logical_height;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   120
		// WIN_GetMonitorDPI needs mode->w and mode->h
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   121
		// so only call after those are set.
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   122
		if (vid_data->GetDpiForMonitor) {
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   123
			WIN_GetMonitorDPIData dpi_data;
9819
2361f732e8cb Fix up monitor enumeration for Windows 8.1 case.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9813
diff changeset
   124
            RECT monitor_rect;
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   125
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   126
			dpi_data.vid_data = vid_data;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   127
			dpi_data.mode = mode;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   128
			dpi_data.mode_data = data;
9819
2361f732e8cb Fix up monitor enumeration for Windows 8.1 case.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9813
diff changeset
   129
            monitor_rect.left = devmode.dmPosition.x;
2361f732e8cb Fix up monitor enumeration for Windows 8.1 case.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9813
diff changeset
   130
            monitor_rect.top = devmode.dmPosition.y;
2361f732e8cb Fix up monitor enumeration for Windows 8.1 case.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9813
diff changeset
   131
            monitor_rect.right = monitor_rect.left + 1;
2361f732e8cb Fix up monitor enumeration for Windows 8.1 case.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9813
diff changeset
   132
            monitor_rect.bottom = monitor_rect.top + 1;
2361f732e8cb Fix up monitor enumeration for Windows 8.1 case.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9813
diff changeset
   133
			EnumDisplayMonitors(NULL, &monitor_rect, WIN_GetMonitorDPI, (LPARAM)&dpi_data);
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   134
		} else {
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   135
			// We don't have the Windows 8.1 routine so just
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   136
			// get system DPI.
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   137
			data->HorzDPI = (float)GetDeviceCaps( hdc, LOGPIXELSX );
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   138
			data->VertDPI = (float)GetDeviceCaps( hdc, LOGPIXELSY );
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   139
			if (data->HorzDPI == data->VertDPI) {
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   140
				data->DiagDPI = data->HorzDPI;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   141
			} else {
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   142
				data->DiagDPI = SDL_ComputeDiagonalDPI( mode->w,
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   143
														mode->h,
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   144
														(float)GetDeviceCaps( hdc, HORZSIZE ) / 25.4f,
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   145
														(float)GetDeviceCaps( hdc, VERTSIZE ) / 25.4f );
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   146
			}
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   147
		}
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   148
		
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
        SDL_zero(bmi_data);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
        bmi = (LPBITMAPINFO) bmi_data;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
        bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
        hbm = CreateCompatibleBitmap(hdc, 1, 1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
        GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
        GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
        DeleteObject(hbm);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
        DeleteDC(hdc);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   158
        if (bmi->bmiHeader.biCompression == BI_BITFIELDS) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
            switch (*(Uint32 *) bmi->bmiColors) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
            case 0x00FF0000:
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
   161
                mode->format = SDL_PIXELFORMAT_RGB888;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
                break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
            case 0x000000FF:
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
   164
                mode->format = SDL_PIXELFORMAT_BGR888;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
                break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
            case 0xF800:
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
   167
                mode->format = SDL_PIXELFORMAT_RGB565;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
                break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   169
            case 0x7C00:
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
   170
                mode->format = SDL_PIXELFORMAT_RGB555;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
                break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   172
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   173
        } else if (bmi->bmiHeader.biBitCount == 8) {
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
   174
            mode->format = SDL_PIXELFORMAT_INDEX8;
3175
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   175
        } else if (bmi->bmiHeader.biBitCount == 4) {
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   176
            mode->format = SDL_PIXELFORMAT_INDEX4LSB;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   177
        }
8086
b744b3f8754b Fixed display mode calculations for applications which are not DPI aware.
Sam Lantinga <slouken@libsdl.org>
parents: 7102
diff changeset
   178
	} else {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   179
        /* FIXME: Can we tell what this will be? */
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3175
diff changeset
   180
        if ((devmode.dmFields & DM_BITSPERPEL) == DM_BITSPERPEL) {
3175
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   181
            switch (devmode.dmBitsPerPel) {
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   182
            case 32:
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   183
                mode->format = SDL_PIXELFORMAT_RGB888;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   184
                break;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   185
            case 24:
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   186
                mode->format = SDL_PIXELFORMAT_RGB24;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   187
                break;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   188
            case 16:
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   189
                mode->format = SDL_PIXELFORMAT_RGB565;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   190
                break;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   191
            case 15:
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   192
                mode->format = SDL_PIXELFORMAT_RGB555;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   193
                break;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   194
            case 8:
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   195
                mode->format = SDL_PIXELFORMAT_INDEX8;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   196
                break;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   197
            case 4:
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   198
                mode->format = SDL_PIXELFORMAT_INDEX4LSB;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   199
                break;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   200
            }
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3175
diff changeset
   201
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   202
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   203
    return SDL_TRUE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   204
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   205
2149
eba4fd03b4f6 Fixed mode code under VMware running Windows 98
Sam Lantinga <slouken@libsdl.org>
parents: 2119
diff changeset
   206
static SDL_bool
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   207
WIN_AddDisplay(_THIS, LPTSTR DeviceName)
2119
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   208
{
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   209
    SDL_VideoDisplay display;
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   210
    SDL_DisplayData *displaydata;
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   211
    SDL_DisplayMode mode;
6793
c8d1036975b7 Implemented getting the display name on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   212
    DISPLAY_DEVICE device;
2119
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   213
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   214
#ifdef DEBUG_MODES
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   215
    printf("Display: %s\n", WIN_StringToUTF8(DeviceName));
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   216
#endif
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   217
    if (!WIN_GetDisplayMode(_this, DeviceName, ENUM_CURRENT_SETTINGS, &mode)) {
2149
eba4fd03b4f6 Fixed mode code under VMware running Windows 98
Sam Lantinga <slouken@libsdl.org>
parents: 2119
diff changeset
   218
        return SDL_FALSE;
2119
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   219
    }
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   220
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   221
    displaydata = (SDL_DisplayData *) SDL_malloc(sizeof(*displaydata));
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   222
    if (!displaydata) {
2149
eba4fd03b4f6 Fixed mode code under VMware running Windows 98
Sam Lantinga <slouken@libsdl.org>
parents: 2119
diff changeset
   223
        return SDL_FALSE;
2119
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   224
    }
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   225
    SDL_memcpy(displaydata->DeviceName, DeviceName,
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   226
               sizeof(displaydata->DeviceName));
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   227
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   228
    SDL_zero(display);
6793
c8d1036975b7 Implemented getting the display name on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   229
    device.cb = sizeof(device);
c8d1036975b7 Implemented getting the display name on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   230
    if (EnumDisplayDevices(DeviceName, 0, &device, 0)) {
c8d1036975b7 Implemented getting the display name on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   231
        display.name = WIN_StringToUTF8(device.DeviceString);
c8d1036975b7 Implemented getting the display name on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   232
    }
2119
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   233
    display.desktop_mode = mode;
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   234
    display.current_mode = mode;
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   235
    display.driverdata = displaydata;
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   236
    SDL_AddVideoDisplay(&display);
6793
c8d1036975b7 Implemented getting the display name on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   237
    SDL_free(display.name);
2149
eba4fd03b4f6 Fixed mode code under VMware running Windows 98
Sam Lantinga <slouken@libsdl.org>
parents: 2119
diff changeset
   238
    return SDL_TRUE;
2119
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   239
}
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   240
3521
76f9b76ddf0f Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
   241
int
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   242
WIN_InitModes(_THIS)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   243
{
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   244
    int pass;
2149
eba4fd03b4f6 Fixed mode code under VMware running Windows 98
Sam Lantinga <slouken@libsdl.org>
parents: 2119
diff changeset
   245
    DWORD i, j, count;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   246
    DISPLAY_DEVICE device;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   247
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   248
    device.cb = sizeof(device);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   249
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   250
    /* Get the primary display in the first pass */
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   251
    for (pass = 0; pass < 2; ++pass) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   252
        for (i = 0; ; ++i) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   253
            TCHAR DeviceName[32];
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   254
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   255
            if (!EnumDisplayDevices(NULL, i, &device, 0)) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   256
                break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   257
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   258
            if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   259
                continue;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   260
            }
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   261
            if (pass == 0) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   262
                if (!(device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   263
                    continue;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   264
                }
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   265
            } else {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   266
                if (device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   267
                    continue;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   268
                }
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   269
            }
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   270
            SDL_memcpy(DeviceName, device.DeviceName, sizeof(DeviceName));
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   271
#ifdef DEBUG_MODES
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   272
            printf("Device: %s\n", WIN_StringToUTF8(DeviceName));
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   273
#endif
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   274
            count = 0;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   275
            for (j = 0; ; ++j) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   276
                if (!EnumDisplayDevices(DeviceName, j, &device, 0)) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   277
                    break;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   278
                }
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   279
                if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   280
                    continue;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   281
                }
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   282
                if (pass == 0) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   283
                    if (!(device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   284
                        continue;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   285
                    }
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   286
                } else {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   287
                    if (device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   288
                        continue;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   289
                    }
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   290
                }
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   291
                count += WIN_AddDisplay(_this, device.DeviceName);
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   292
            }
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   293
            if (count == 0) {
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   294
                WIN_AddDisplay(_this, DeviceName);
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   295
            }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   296
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   297
    }
3521
76f9b76ddf0f Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
   298
    if (_this->num_displays == 0) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   299
        return SDL_SetError("No displays available");
3521
76f9b76ddf0f Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
   300
    }
76f9b76ddf0f Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
   301
    return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   302
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   303
3528
59ff7a2beb57 Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents: 3521
diff changeset
   304
int
59ff7a2beb57 Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents: 3521
diff changeset
   305
WIN_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
59ff7a2beb57 Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents: 3521
diff changeset
   306
{
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   307
    SDL_DisplayModeData *data = (SDL_DisplayModeData *) display->current_mode.driverdata;
3528
59ff7a2beb57 Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents: 3521
diff changeset
   308
8086
b744b3f8754b Fixed display mode calculations for applications which are not DPI aware.
Sam Lantinga <slouken@libsdl.org>
parents: 7102
diff changeset
   309
    rect->x = (int)SDL_ceil(data->DeviceMode.dmPosition.x * data->ScaleX);
b744b3f8754b Fixed display mode calculations for applications which are not DPI aware.
Sam Lantinga <slouken@libsdl.org>
parents: 7102
diff changeset
   310
    rect->y = (int)SDL_ceil(data->DeviceMode.dmPosition.y * data->ScaleY);
b744b3f8754b Fixed display mode calculations for applications which are not DPI aware.
Sam Lantinga <slouken@libsdl.org>
parents: 7102
diff changeset
   311
    rect->w = (int)SDL_ceil(data->DeviceMode.dmPelsWidth * data->ScaleX);
b744b3f8754b Fixed display mode calculations for applications which are not DPI aware.
Sam Lantinga <slouken@libsdl.org>
parents: 7102
diff changeset
   312
    rect->h = (int)SDL_ceil(data->DeviceMode.dmPelsHeight * data->ScaleY);
6430
48d519500f7e Removed Windows CE support from SDL 2.0.
Ryan C. Gordon <icculus@icculus.org>
parents: 6138
diff changeset
   313
3528
59ff7a2beb57 Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents: 3521
diff changeset
   314
    return 0;
59ff7a2beb57 Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents: 3521
diff changeset
   315
}
59ff7a2beb57 Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents: 3521
diff changeset
   316
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   317
int
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   318
WIN_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi)
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   319
{
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   320
    SDL_DisplayModeData *data = (SDL_DisplayModeData *) display->current_mode.driverdata;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   321
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   322
	if (ddpi) {
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   323
		*ddpi = data->DiagDPI;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   324
	}
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   325
	if (hdpi) {
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   326
		*hdpi = data->HorzDPI;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   327
	}
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   328
	if (vdpi) {
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   329
		*vdpi = data->VertDPI;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   330
	}
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   331
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   332
	return data->DiagDPI != 0.0f ? 0 : -1;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   333
}
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   334
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   335
void
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3186
diff changeset
   336
WIN_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   337
{
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3186
diff changeset
   338
    SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   339
    DWORD i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   340
    SDL_DisplayMode mode;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   341
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   342
    for (i = 0;; ++i) {
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   343
        if (!WIN_GetDisplayMode(_this, data->DeviceName, i, &mode)) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   344
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   345
        }
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   346
        if (SDL_ISPIXELFORMAT_INDEXED(mode.format)) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   347
            /* We don't support palettized modes now */
7102
b9fa5a2acbfd Bug 1786 - memory leak in WIN_GetDisplayModes by Marcel Bakker
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7037
diff changeset
   348
            SDL_free(mode.driverdata);
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   349
            continue;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   350
        }
3521
76f9b76ddf0f Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
   351
        if (mode.format != SDL_PIXELFORMAT_UNKNOWN) {
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3186
diff changeset
   352
            if (!SDL_AddDisplayMode(display, &mode)) {
3175
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   353
                SDL_free(mode.driverdata);
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3175
diff changeset
   354
            }
8086
b744b3f8754b Fixed display mode calculations for applications which are not DPI aware.
Sam Lantinga <slouken@libsdl.org>
parents: 7102
diff changeset
   355
        } else {
7102
b9fa5a2acbfd Bug 1786 - memory leak in WIN_GetDisplayModes by Marcel Bakker
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7037
diff changeset
   356
            SDL_free(mode.driverdata);
b9fa5a2acbfd Bug 1786 - memory leak in WIN_GetDisplayModes by Marcel Bakker
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7037
diff changeset
   357
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   358
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   359
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   360
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   361
int
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3186
diff changeset
   362
WIN_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   363
{
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3186
diff changeset
   364
    SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   365
    SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   366
    LONG status;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3097
diff changeset
   367
8795
513d97ffe10d Fullscreen to windowed mode switch
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   368
    if (mode->driverdata == display->desktop_mode.driverdata) {
513d97ffe10d Fullscreen to windowed mode switch
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   369
        status = ChangeDisplaySettingsEx(displaydata->DeviceName, NULL, NULL, 0, NULL);
513d97ffe10d Fullscreen to windowed mode switch
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   370
    } else {
513d97ffe10d Fullscreen to windowed mode switch
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   371
        status = ChangeDisplaySettingsEx(displaydata->DeviceName, &data->DeviceMode, NULL, CDS_FULLSCREEN, NULL);
513d97ffe10d Fullscreen to windowed mode switch
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   372
    }
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   373
    if (status != DISP_CHANGE_SUCCESSFUL) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   374
        const char *reason = "Unknown reason";
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   375
        switch (status) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   376
        case DISP_CHANGE_BADFLAGS:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   377
            reason = "DISP_CHANGE_BADFLAGS";
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   378
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   379
        case DISP_CHANGE_BADMODE:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   380
            reason = "DISP_CHANGE_BADMODE";
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   381
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   382
        case DISP_CHANGE_BADPARAM:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   383
            reason = "DISP_CHANGE_BADPARAM";
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   384
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   385
        case DISP_CHANGE_FAILED:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   386
            reason = "DISP_CHANGE_FAILED";
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   387
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   388
        }
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   389
        return SDL_SetError("ChangeDisplaySettingsEx() failed: %s", reason);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   390
    }
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   391
    EnumDisplaySettings(displaydata->DeviceName, ENUM_CURRENT_SETTINGS, &data->DeviceMode);
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   392
    return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   393
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   394
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   395
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   396
WIN_QuitModes(_THIS)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   397
{
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   398
    /* All fullscreen windows should have restored modes by now */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   399
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   400
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   401
#endif /* SDL_VIDEO_DRIVER_WINDOWS */
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   402
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   403
/* vi: set ts=4 sw=4 expandtab: */