Win32 port work dump.

This commit is contained in:
Camilla Berglund 2010-09-12 16:26:00 +02:00
parent 8c507dc333
commit 90df26ac3c
8 changed files with 355 additions and 421 deletions

View File

@ -307,7 +307,6 @@ typedef struct _GLFWwindowWin32
HWND handle; // Window handle
ATOM classAtom; // Window class atom
int modeID; // Mode ID for fullscreen mode
HHOOK keyboardHook; // Keyboard hook handle
DWORD dwStyle; // Window styles used for window creation
DWORD dwExStyle; // --"--
@ -326,8 +325,9 @@ typedef struct _GLFWwindowWin32
//------------------------------------------------------------------------
typedef struct _GLFWlibraryWin32
{
// Instance of the application
HINSTANCE instance;
HINSTANCE instance; // Instance of the application
HHOOK keyboardHook; // Keyboard hook handle
DWORD foregroundLockTimeout;
// Timer data
struct {
@ -340,8 +340,6 @@ typedef struct _GLFWlibraryWin32
// System information
struct {
int winVer;
int hasUnicode;
DWORD foregroundLockTimeout;
} sys;
#if !defined(_GLFW_NO_DLOAD_WINMM) || !defined(_GLFW_NO_DLOAD_GDI32)

View File

@ -37,7 +37,7 @@
// GLFW DLL entry point
//========================================================================
BOOL WINAPI DllMain( HINSTANCE instance, DWORD reason, LPVOID reserved )
BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
{
// NOTE: Some compilers complains about instance and x never being used -
// never mind that (we don't want to use them)!

View File

@ -78,9 +78,11 @@ static LRESULT CALLBACK keyboardHook(int nCode, WPARAM wParam, LPARAM lParam)
// Was it a system key combination (e.g. ALT+TAB)?
if (syskeys)
{
_GLFWwindow* window = _glfwLibrary.activeWindow;
// Pass the key event to our window message loop
if (_glfwWin.opened)
PostMessage(_glfwWin.window, (UINT) wParam, p->vkCode, 0);
if (window)
PostMessage(window->Win32.handle, (UINT) wParam, p->vkCode, 0);
// We've taken care of it - don't let the system know about this
// key event
@ -89,7 +91,7 @@ static LRESULT CALLBACK keyboardHook(int nCode, WPARAM wParam, LPARAM lParam)
else
{
// It's a harmless key press, let the system deal with it
return CallNextHookEx(_glfwWin.keyboardHook, nCode, wParam, lParam);
return CallNextHookEx(_glfwLibrary.Win32.keyboardHook, nCode, wParam, lParam);
}
}
@ -104,19 +106,11 @@ static LRESULT CALLBACK keyboardHook(int nCode, WPARAM wParam, LPARAM lParam)
void _glfwPlatformEnableSystemKeys(void)
{
BOOL dummy;
// Use different methods depending on operating system version
if (_glfwLibrary.Sys.winVer >= _GLFW_WIN_NT4)
if (_glfwLibrary.Win32.keyboardHook != NULL)
{
if (_glfwWin.keyboardHook != NULL)
{
UnhookWindowsHookEx(_glfwWin.keyboardHook);
_glfwWin.keyboardHook = NULL;
}
UnhookWindowsHookEx(_glfwLibrary.Win32.keyboardHook);
_glfwLibrary.Win32.keyboardHook = NULL;
}
else
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, FALSE, &dummy, 0);
}
@ -126,22 +120,9 @@ void _glfwPlatformEnableSystemKeys(void)
void _glfwPlatformDisableSystemKeys(void)
{
BOOL dummy;
// Use different methods depending on operating system version
if (_glfwLibrary.Sys.winVer >= _GLFW_WIN_NT4)
{
// Under Windows NT, install a low level keyboard hook
_glfwWin.keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL,
keyboardHook,
_glfwLibrary.instance,
0);
}
else
{
// Under Windows 95/98/ME, fool Windows that a screensaver
// is running => prevents ALT+TAB, CTRL+ESC and CTRL+ALT+DEL
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, TRUE, &dummy, 0);
}
_glfwLibrary.Win32.keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL,
keyboardHook,
_glfwLibrary.Win32.instance,
0);
}

View File

@ -43,9 +43,11 @@ int _glfwPlatformExtensionSupported(const char* extension)
{
const GLubyte* extensions;
if (_glfwWin.GetExtensionsStringEXT != NULL)
_GLFWwindow* window = _glfwLibrary.currentWindow;
if (window->WGL.GetExtensionsStringEXT != NULL)
{
extensions = (GLubyte*) _glfwWin.GetExtensionsStringEXT();
extensions = (GLubyte*) window->WGL.GetExtensionsStringEXT();
if (extensions != NULL)
{
if (_glfwStringInExtensionString(extension, extensions))
@ -53,9 +55,9 @@ int _glfwPlatformExtensionSupported(const char* extension)
}
}
if (_glfwWin.GetExtensionsStringARB != NULL)
if (window->WGL.GetExtensionsStringARB != NULL)
{
extensions = (GLubyte*) _glfwWin.GetExtensionsStringARB(_glfwWin.DC);
extensions = (GLubyte*) window->WGL.GetExtensionsStringARB(window->WGL.DC);
if (extensions != NULL)
{
if (_glfwStringInExtensionString(extension, extensions))

View File

@ -44,28 +44,28 @@ static GLboolean initLibraries(void)
{
// gdi32.dll (OpenGL pixel format functions & SwapBuffers)
#ifndef _GLFW_NO_DLOAD_GDI32
_glfwLibrary.Libs.gdi32 = LoadLibrary("gdi32.dll");
if (_glfwLibrary.Libs.gdi32 != NULL)
_glfwLibrary.Win32.libs.gdi32 = LoadLibrary("gdi32.dll");
if (_glfwLibrary.Win32.libs.gdi32 != NULL)
{
_glfwLibrary.Libs.ChoosePixelFormat = (CHOOSEPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Libs.gdi32, "ChoosePixelFormat");
_glfwLibrary.Libs.DescribePixelFormat = (DESCRIBEPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Libs.gdi32, "DescribePixelFormat");
_glfwLibrary.Libs.GetPixelFormat = (GETPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Libs.gdi32, "GetPixelFormat");
_glfwLibrary.Libs.SetPixelFormat = (SETPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Libs.gdi32, "SetPixelFormat");
_glfwLibrary.Libs.SwapBuffers = (SWAPBUFFERS_T)
GetProcAddress(_glfwLibrary.Libs.gdi32, "SwapBuffers");
_glfwLibrary.Win32.libs.ChoosePixelFormat = (CHOOSEPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Win32.libs.gdi32, "ChoosePixelFormat");
_glfwLibrary.Win32.libs.DescribePixelFormat = (DESCRIBEPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Win32.libs.gdi32, "DescribePixelFormat");
_glfwLibrary.Win32.libs.GetPixelFormat = (GETPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Win32.libs.gdi32, "GetPixelFormat");
_glfwLibrary.Win32.libs.SetPixelFormat = (SETPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Win32.libs.gdi32, "SetPixelFormat");
_glfwLibrary.Win32.libs.SwapBuffers = (SWAPBUFFERS_T)
GetProcAddress(_glfwLibrary.Win32.libs.gdi32, "SwapBuffers");
if (_glfwLibrary.Libs.ChoosePixelFormat &&
_glfwLibrary.Libs.DescribePixelFormat &&
_glfwLibrary.Libs.GetPixelFormat &&
_glfwLibrary.Libs.SetPixelFormat &&
_glfwLibrary.Libs.SwapBuffers)
if (_glfwLibrary.Win32.libs.ChoosePixelFormat &&
_glfwLibrary.Win32.libs.DescribePixelFormat &&
_glfwLibrary.Win32.libs.GetPixelFormat &&
_glfwLibrary.Win32.libs.SetPixelFormat &&
_glfwLibrary.Win32.libs.SwapBuffers)
{
FreeLibrary(_glfwLibrary.Libs.gdi32);
_glfwLibrary.Libs.gdi32 = NULL;
FreeLibrary(_glfwLibrary.Win32.libs.gdi32);
_glfwLibrary.Win32.libs.gdi32 = NULL;
return GL_FALSE;
}
}
@ -75,25 +75,25 @@ static GLboolean initLibraries(void)
// winmm.dll (for joystick and timer support)
#ifndef _GLFW_NO_DLOAD_WINMM
_glfwLibrary.Libs.winmm = LoadLibrary("winmm.dll");
if (_glfwLibrary.Libs.winmm != NULL)
_glfwLibrary.Win32.libs.winmm = LoadLibrary("winmm.dll");
if (_glfwLibrary.Win32.libs.winmm != NULL)
{
_glfwLibrary.Libs.joyGetDevCapsA = (JOYGETDEVCAPSA_T)
GetProcAddress(_glfwLibrary.Libs.winmm, "joyGetDevCapsA");
_glfwLibrary.Libs.joyGetPos = (JOYGETPOS_T)
GetProcAddress(_glfwLibrary.Libs.winmm, "joyGetPos");
_glfwLibrary.Libs.joyGetPosEx = (JOYGETPOSEX_T)
GetProcAddress(_glfwLibrary.Libs.winmm, "joyGetPosEx");
_glfwLibrary.Libs.timeGetTime = (TIMEGETTIME_T)
GetProcAddress(_glfwLibrary.Libs.winmm, "timeGetTime");
_glfwLibrary.Win32.libs.joyGetDevCapsA = (JOYGETDEVCAPSA_T)
GetProcAddress(_glfwLibrary.Win32.libs.winmm, "joyGetDevCapsA");
_glfwLibrary.Win32.libs.joyGetPos = (JOYGETPOS_T)
GetProcAddress(_glfwLibrary.Win32.libs.winmm, "joyGetPos");
_glfwLibrary.Win32.libs.joyGetPosEx = (JOYGETPOSEX_T)
GetProcAddress(_glfwLibrary.Win32.libs.winmm, "joyGetPosEx");
_glfwLibrary.Win32.libs.timeGetTime = (TIMEGETTIME_T)
GetProcAddress(_glfwLibrary.Win32.libs.winmm, "timeGetTime");
if (_glfwLibrary.Libs.joyGetDevCapsA &&
_glfwLibrary.Libs.joyGetPos &&
_glfwLibrary.Libs.joyGetPosEx &&
_glfwLibrary.Libs.timeGetTime)
if (_glfwLibrary.Win32.libs.joyGetDevCapsA &&
_glfwLibrary.Win32.libs.joyGetPos &&
_glfwLibrary.Win32.libs.joyGetPosEx &&
_glfwLibrary.Win32.libs.timeGetTime)
{
FreeLibrary(_glfwLibrary.Libs.winmm);
_glfwLibrary.Libs.winmm = NULL;
FreeLibrary(_glfwLibrary.Win32.libs.winmm);
_glfwLibrary.Win32.libs.winmm = NULL;
return GL_FALSE;
}
}
@ -113,19 +113,19 @@ static void freeLibraries(void)
{
// gdi32.dll
#ifndef _GLFW_NO_DLOAD_GDI32
if (_glfwLibrary.Libs.gdi32 != NULL)
if (_glfwLibrary.Win32.libs.gdi32 != NULL)
{
FreeLibrary(_glfwLibrary.Libs.gdi32);
_glfwLibrary.Libs.gdi32 = NULL;
FreeLibrary(_glfwLibrary.Win32.libs.gdi32);
_glfwLibrary.Win32.libs.gdi32 = NULL;
}
#endif // _GLFW_NO_DLOAD_GDI32
// winmm.dll
#ifndef _GLFW_NO_DLOAD_WINMM
if (_glfwLibrary.Libs.winmm != NULL)
if (_glfwLibrary.Win32.libs.winmm != NULL)
{
FreeLibrary(_glfwLibrary.Libs.winmm);
_glfwLibrary.Libs.winmm = NULL;
FreeLibrary(_glfwLibrary.Win32.libs.winmm);
_glfwLibrary.Win32.libs.winmm = NULL;
}
#endif // _GLFW_NO_DLOAD_WINMM
}
@ -157,7 +157,7 @@ int _glfwPlatformInit(void)
// with the FOREGROUNDLOCKTIMEOUT system setting (we do this as early
// as possible in the hope of still being the foreground process)
SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0,
&_glfwLibrary.Sys.foregroundLockTimeout, 0);
&_glfwLibrary.Win32.foregroundLockTimeout, 0);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID) 0,
SPIF_SENDCHANGE);
@ -165,43 +165,31 @@ int _glfwPlatformInit(void)
osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osi);
_glfwLibrary.Sys.winVer = _GLFW_WIN_UNKNOWN;
_glfwLibrary.Win32.sys.winVer = _GLFW_WIN_UNKNOWN;
if (osi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
{
if (osi.dwMajorVersion == 4 && osi.dwMinorVersion < 10)
_glfwLibrary.Sys.winVer = _GLFW_WIN_95;
_glfwLibrary.Win32.sys.winVer = _GLFW_WIN_95;
else if (osi.dwMajorVersion == 4 && osi.dwMinorVersion < 90)
_glfwLibrary.Sys.winVer = _GLFW_WIN_98;
_glfwLibrary.Win32.sys.winVer = _GLFW_WIN_98;
else if (osi.dwMajorVersion == 4 && osi.dwMinorVersion == 90)
_glfwLibrary.Sys.winVer = _GLFW_WIN_ME;
_glfwLibrary.Win32.sys.winVer = _GLFW_WIN_ME;
else if (osi.dwMajorVersion >= 4)
_glfwLibrary.Sys.winVer = _GLFW_WIN_UNKNOWN_9x;
_glfwLibrary.Win32.sys.winVer = _GLFW_WIN_UNKNOWN_9x;
}
else if (osi.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
if (osi.dwMajorVersion == 4 && osi.dwMinorVersion == 0)
_glfwLibrary.Sys.winVer = _GLFW_WIN_NT4;
_glfwLibrary.Win32.sys.winVer = _GLFW_WIN_NT4;
else if (osi.dwMajorVersion == 5 && osi.dwMinorVersion == 0)
_glfwLibrary.Sys.winVer = _GLFW_WIN_2K;
_glfwLibrary.Win32.sys.winVer = _GLFW_WIN_2K;
else if (osi.dwMajorVersion == 5 && osi.dwMinorVersion == 1)
_glfwLibrary.Sys.winVer = _GLFW_WIN_XP;
_glfwLibrary.Win32.sys.winVer = _GLFW_WIN_XP;
else if (osi.dwMajorVersion == 5 && osi.dwMinorVersion == 2)
_glfwLibrary.Sys.winVer = _GLFW_WIN_NET_SERVER;
_glfwLibrary.Win32.sys.winVer = _GLFW_WIN_NET_SERVER;
else if (osi.dwMajorVersion >= 5)
_glfwLibrary.Sys.winVer = _GLFW_WIN_UNKNOWN_NT;
}
// Do we have Unicode support?
if (_glfwLibrary.Sys.winVer >= _GLFW_WIN_NT4)
{
// Windows NT/2000/XP/.NET has Unicode support
_glfwLibrary.Sys.hasUnicode = GL_TRUE;
}
else
{
// Windows 9x/ME does not have Unicode support
_glfwLibrary.Sys.hasUnicode = GL_FALSE;
_glfwLibrary.Win32.sys.winVer = _GLFW_WIN_UNKNOWN_NT;
}
// Load libraries (DLLs)
@ -215,10 +203,10 @@ int _glfwPlatformInit(void)
#endif
// Retrieve GLFW instance handle
_glfwLibrary.instance = GetModuleHandle(NULL);
_glfwLibrary.Win32.instance = GetModuleHandle(NULL);
// System keys are not disabled
_glfwWin.keyboardHook = NULL;
_glfwLibrary.Win32.keyboardHook = NULL;
// Install atexit() routine
atexit(glfw_atexit);
@ -247,7 +235,7 @@ int _glfwPlatformTerminate(void)
// Restore FOREGROUNDLOCKTIMEOUT system setting
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
(LPVOID) _glfwLibrary.Sys.foregroundLockTimeout,
(LPVOID) _glfwLibrary.Win32.foregroundLockTimeout,
SPIF_SENDCHANGE);
return GL_TRUE;

View File

@ -43,11 +43,6 @@ static GLboolean isJoystickPresent(int joy)
{
JOYINFO ji;
// Windows NT 4.0 MMSYSTEM only supports 2 sticks (other Windows
// versions support 16 sticks)
if (_glfwLibrary.Sys.winVer == _GLFW_WIN_NT4 && joy > GLFW_JOYSTICK_2)
return GL_FALSE;
// Is it a valid stick ID (Windows don't support more than 16 sticks)?
if (joy < GLFW_JOYSTICK_1 || joy > GLFW_JOYSTICK_16)
return GL_FALSE;

View File

@ -47,24 +47,24 @@ void _glfwInitTimer(void)
if (QueryPerformanceFrequency((LARGE_INTEGER*) &freq))
{
// Performance counter is available => use it!
_glfwLibrary.Timer.HasPerformanceCounter = GL_TRUE;
_glfwLibrary.Win32.timer.HasPerformanceCounter = GL_TRUE;
// Counter resolution is 1 / counter frequency
_glfwLibrary.Timer.Resolution = 1.0 / (double) freq;
_glfwLibrary.Win32.timer.Resolution = 1.0 / (double) freq;
// Set start time for timer
QueryPerformanceCounter((LARGE_INTEGER*) &_glfwLibrary.Timer.t0_64);
QueryPerformanceCounter((LARGE_INTEGER*) &_glfwLibrary.Win32.timer.t0_64);
}
else
{
// No performace counter available => use the tick counter
_glfwLibrary.Timer.HasPerformanceCounter = GL_FALSE;
_glfwLibrary.Win32.timer.HasPerformanceCounter = GL_FALSE;
// Counter resolution is 1 ms
_glfwLibrary.Timer.Resolution = 0.001;
_glfwLibrary.Win32.timer.Resolution = 0.001;
// Set start time for timer
_glfwLibrary.Timer.t0_32 = _glfw_timeGetTime();
_glfwLibrary.Win32.timer.t0_32 = _glfw_timeGetTime();
}
}
@ -82,16 +82,16 @@ double _glfwPlatformGetTime(void)
double t;
__int64 t_64;
if (_glfwLibrary.Timer.HasPerformanceCounter)
if (_glfwLibrary.Win32.timer.HasPerformanceCounter)
{
QueryPerformanceCounter((LARGE_INTEGER*) &t_64);
t = (double)(t_64 - _glfwLibrary.Timer.t0_64);
t = (double)(t_64 - _glfwLibrary.Win32.timer.t0_64);
}
else
t = (double)(_glfw_timeGetTime() - _glfwLibrary.Timer.t0_32);
t = (double)(_glfw_timeGetTime() - _glfwLibrary.Win32.timer.t0_32);
// Calculate the current time in seconds
return t * _glfwLibrary.Timer.Resolution;
return t * _glfwLibrary.Win32.timer.Resolution;
}
@ -103,12 +103,12 @@ void _glfwPlatformSetTime(double t)
{
__int64 t_64;
if (_glfwLibrary.Timer.HasPerformanceCounter)
if (_glfwLibrary.Win32.timer.HasPerformanceCounter)
{
QueryPerformanceCounter((LARGE_INTEGER*) &t_64);
_glfwLibrary.Timer.t0_64 = t_64 - (__int64) (t / _glfwLibrary.Timer.Resolution);
_glfwLibrary.Win32.timer.t0_64 = t_64 - (__int64) (t / _glfwLibrary.Win32.timer.Resolution);
}
else
_glfwLibrary.Timer.t0_32 = _glfw_timeGetTime() - (int)(t * 1000.0);
_glfwLibrary.Win32.timer.t0_32 = _glfw_timeGetTime() - (int)(t * 1000.0);
}

File diff suppressed because it is too large Load Diff