Mercurial > sdl-ios-xcode
view src/video/win32/SDL_win32modes.c @ 4426:1bceff8f008f
Fixed bug #943
Ozkan Sezer 2010-02-06 12:31:06 PST
Hi:
Here are some small fixes for compiling SDL against mingw-w64.
(see http://mingw-w64.sourceforge.net/ . Despite the name, it
supports both win32 and win64.)
src/audio/windx5/directx.h and src/video/windx5/directx.h (both
SDL-1.2 and SDL-1.3.) I get compilation errors about some union
not having a member named u1 and alike, because of other system
headers being included before this one and them already defining
DUMMYUNIONNAME and stuff. This header probably assumes that those
stuff are defined in windef.h, but mingw-w64 headers define them
in _mingw.h. Easily fixed by moving NONAMELESSUNION definition to
the top of the file.
src/thread/win32/SDL_systhread.c (both SDL-1.2 and SDL-1.3.) :
The __GNUC__ case for pfnSDL_CurrentBeginThread is 32-bit centric
because _beginthreadex returns uintptr_t, not unsigned long which
is 32 bits in win64. Changing the return type to uintptr_t fixes
it.
video/SDL_blit.h (and configure.in) (SDL-1.3-only) : MinGW-w64
uses msvcrt version of _aligned_malloc and _aligned_free and
they are defined in intrin.h (similar to VC). Adding proper
ifdefs fixes it. (Notes about macros to check: __MINGW32__ is
defined for both mingw.org and for mingw-w64 for both win32 and
win64, __MINGW64__ is only defined for _WIN64, so __MINGW64__
can't be used to detect mingw-w64: including _mingw.h and then
checking for __MINGW64_VERSION_MAJOR does the trick.)
SDL_win32video.h (SDL-1.3-only) : Tweaked the VINWER definition
and location in order to avoid multiple redefinition warnings.
Hope these are useful. Thanks.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 10 Mar 2010 15:02:58 +0000 |
parents | f7b03b6838cb |
children | 3e69e077cb95 |
line wrap: on
line source
/* SDL - Simple DirectMedia Layer Copyright (C) 1997-2010 Sam Lantinga This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Sam Lantinga slouken@libsdl.org */ #include "SDL_config.h" #include "SDL_win32video.h" static SDL_bool WIN_GetDisplayMode(LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode) { SDL_DisplayModeData *data; DEVMODE devmode; HDC hdc; devmode.dmSize = sizeof(devmode); devmode.dmDriverExtra = 0; if (!EnumDisplaySettings(deviceName, index, &devmode)) { return SDL_FALSE; } data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data)); if (!data) { return SDL_FALSE; } data->DeviceMode = devmode; data->DeviceMode.dmFields = (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS); /* Fill in the mode information */ mode->format = SDL_PIXELFORMAT_UNKNOWN; mode->w = devmode.dmPelsWidth; mode->h = devmode.dmPelsHeight; mode->refresh_rate = devmode.dmDisplayFrequency; mode->driverdata = data; #ifdef _WIN32_WCE /* In WinCE EnumDisplaySettings(ENUM_CURRENT_SETTINGS) doesn't take the user defined orientation into account but GetSystemMetrics does. */ if (index == ENUM_CURRENT_SETTINGS) { mode->w = GetSystemMetrics(SM_CXSCREEN); mode->h = GetSystemMetrics(SM_CYSCREEN); } #endif /* WinCE has no GetDIBits, therefore we can't use it to get the display format */ #ifndef _WIN32_WCE if (index == ENUM_CURRENT_SETTINGS && (hdc = CreateDC(deviceName, NULL, NULL, NULL)) != NULL) { char bmi_data[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)]; LPBITMAPINFO bmi; HBITMAP hbm; SDL_zero(bmi_data); bmi = (LPBITMAPINFO) bmi_data; bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); hbm = CreateCompatibleBitmap(hdc, 1, 1); GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS); GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS); DeleteObject(hbm); DeleteDC(hdc); if (bmi->bmiHeader.biCompression == BI_BITFIELDS) { switch (*(Uint32 *) bmi->bmiColors) { case 0x00FF0000: mode->format = SDL_PIXELFORMAT_RGB888; break; case 0x000000FF: mode->format = SDL_PIXELFORMAT_BGR888; break; case 0xF800: mode->format = SDL_PIXELFORMAT_RGB565; break; case 0x7C00: mode->format = SDL_PIXELFORMAT_RGB555; break; } } else if (bmi->bmiHeader.biBitCount == 8) { mode->format = SDL_PIXELFORMAT_INDEX8; } else if (bmi->bmiHeader.biBitCount == 4) { mode->format = SDL_PIXELFORMAT_INDEX4LSB; } } else #endif /* _WIN32_WCE */ { /* FIXME: Can we tell what this will be? */ if ((devmode.dmFields & DM_BITSPERPEL) == DM_BITSPERPEL) { switch (devmode.dmBitsPerPel) { case 32: mode->format = SDL_PIXELFORMAT_RGB888; break; case 24: mode->format = SDL_PIXELFORMAT_RGB24; break; case 16: mode->format = SDL_PIXELFORMAT_RGB565; break; case 15: mode->format = SDL_PIXELFORMAT_RGB555; break; case 8: mode->format = SDL_PIXELFORMAT_INDEX8; break; case 4: mode->format = SDL_PIXELFORMAT_INDEX4LSB; break; } } } return SDL_TRUE; } static SDL_bool WIN_AddDisplay(LPTSTR DeviceName) { SDL_VideoDisplay display; SDL_DisplayData *displaydata; SDL_DisplayMode mode; #ifdef DEBUG_MODES printf("Display: %s\n", WIN_StringToUTF8(DeviceName)); #endif if (!WIN_GetDisplayMode(DeviceName, ENUM_CURRENT_SETTINGS, &mode)) { return SDL_FALSE; } displaydata = (SDL_DisplayData *) SDL_malloc(sizeof(*displaydata)); if (!displaydata) { return SDL_FALSE; } SDL_memcpy(displaydata->DeviceName, DeviceName, sizeof(displaydata->DeviceName)); SDL_zero(display); display.desktop_mode = mode; display.current_mode = mode; display.driverdata = displaydata; SDL_AddVideoDisplay(&display); return SDL_TRUE; } int WIN_InitModes(_THIS) { SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; DWORD i, j, count; DISPLAY_DEVICE device; device.cb = sizeof(device); for (i = 0;; ++i) { TCHAR DeviceName[32]; if (!EnumDisplayDevices(NULL, i, &device, 0)) { break; } if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) { continue; } SDL_memcpy(DeviceName, device.DeviceName, sizeof(DeviceName)); #ifdef DEBUG_MODES printf("Device: %s\n", WIN_StringToUTF8(DeviceName)); #endif count = 0; for (j = 0;; ++j) { if (!EnumDisplayDevices(DeviceName, j, &device, 0)) { break; } if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) { continue; } count += WIN_AddDisplay(device.DeviceName); } if (count == 0) { WIN_AddDisplay(DeviceName); } } if (_this->num_displays == 0) { SDL_SetError("No displays available"); return -1; } return 0; } int WIN_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect) { SDL_DisplayModeData *data = (SDL_DisplayModeData *) display->desktop_mode.driverdata; rect->x = (int)data->DeviceMode.dmPosition.x; rect->y = (int)data->DeviceMode.dmPosition.y; rect->w = data->DeviceMode.dmPelsWidth; rect->h = data->DeviceMode.dmPelsHeight; return 0; } void WIN_GetDisplayModes(_THIS, SDL_VideoDisplay * display) { SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata; DWORD i; SDL_DisplayMode mode; for (i = 0;; ++i) { if (!WIN_GetDisplayMode(data->DeviceName, i, &mode)) { break; } if (mode.format != SDL_PIXELFORMAT_UNKNOWN) { if (!SDL_AddDisplayMode(display, &mode)) { SDL_free(mode.driverdata); } } } } int WIN_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) { SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata; SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata; LONG status; #ifdef _WIN32_WCE /* TODO: implement correctly. On my Asus MyPAL, if I execute the code below I get DISP_CHANGE_BADFLAGS and the Titlebar of the fullscreen window stays visible ... (SDL_RaiseWindow() would fix that one) */ return 0; #endif status = ChangeDisplaySettingsEx(displaydata->DeviceName, &data->DeviceMode, NULL, CDS_FULLSCREEN, NULL); if (status == DISP_CHANGE_SUCCESSFUL) { return 0; } else { const char *reason = "Unknown reason"; switch (status) { case DISP_CHANGE_BADFLAGS: reason = "DISP_CHANGE_BADFLAGS"; break; case DISP_CHANGE_BADMODE: reason = "DISP_CHANGE_BADMODE"; break; case DISP_CHANGE_BADPARAM: reason = "DISP_CHANGE_BADPARAM"; break; case DISP_CHANGE_FAILED: reason = "DISP_CHANGE_FAILED"; break; } SDL_SetError("ChangeDisplaySettingsEx() failed: %s", reason); return -1; } } void WIN_QuitModes(_THIS) { ChangeDisplaySettingsEx(NULL, NULL, NULL, 0, NULL); } /* vi: set ts=4 sw=4 expandtab: */