1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-26 20:28:49 -05:00

Add suffixes to platform specific helper functions

Also merge win32_tls.h into win32_platform.h.
This commit is contained in:
Camilla Berglund 2015-12-03 18:16:46 +01:00
parent 0a3b5952e0
commit 12b6c56903
42 changed files with 375 additions and 358 deletions

View File

@ -17,8 +17,7 @@ if (_GLFW_COCOA)
set(glfw_SOURCES ${common_SOURCES} cocoa_init.m cocoa_monitor.m set(glfw_SOURCES ${common_SOURCES} cocoa_init.m cocoa_monitor.m
cocoa_window.m iokit_joystick.m mach_time.c posix_tls.c) cocoa_window.m iokit_joystick.m mach_time.c posix_tls.c)
elseif (_GLFW_WIN32) elseif (_GLFW_WIN32)
set(glfw_HEADERS ${common_HEADERS} win32_platform.h win32_tls.h set(glfw_HEADERS ${common_HEADERS} win32_platform.h winmm_joystick.h)
winmm_joystick.h)
set(glfw_SOURCES ${common_SOURCES} win32_init.c win32_monitor.c win32_time.c set(glfw_SOURCES ${common_SOURCES} win32_init.c win32_monitor.c win32_time.c
win32_tls.c win32_window.c winmm_joystick.c) win32_tls.c win32_window.c winmm_joystick.c)
elseif (_GLFW_X11) elseif (_GLFW_X11)

View File

@ -232,11 +232,14 @@ int _glfwPlatformInit(void)
if (!_glfw.ns.unicodeData) if (!_glfw.ns.unicodeData)
return GLFW_FALSE; return GLFW_FALSE;
if (!_glfwInitContextAPI()) if (!_glfwInitThreadLocalStoragePOSIX())
return GLFW_FALSE; return GLFW_FALSE;
_glfwInitTimer(); if (!_glfwInitNSGL())
_glfwInitJoysticks(); return GLFW_FALSE;
_glfwInitTimerNS();
_glfwInitJoysticksNS();
return GLFW_TRUE; return GLFW_TRUE;
} }
@ -270,8 +273,9 @@ void _glfwPlatformTerminate(void)
free(_glfw.ns.clipboardString); free(_glfw.ns.clipboardString);
_glfwTerminateJoysticks(); _glfwTerminateNSGL();
_glfwTerminateContextAPI(); _glfwTerminateJoysticksNS();
_glfwTerminateThreadLocalStoragePOSIX();
} }
const char* _glfwPlatformGetVersionString(void) const char* _glfwPlatformGetVersionString(void)

View File

@ -166,7 +166,7 @@ static void endFadeReservation(CGDisplayFadeReservationToken token)
// Change the current video mode // Change the current video mode
// //
GLFWbool _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired) GLFWbool _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired)
{ {
CFArrayRef modes; CFArrayRef modes;
CFIndex count, i; CFIndex count, i;
@ -224,7 +224,7 @@ GLFWbool _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired)
// Restore the previously saved (original) video mode // Restore the previously saved (original) video mode
// //
void _glfwRestoreVideoMode(_GLFWmonitor* monitor) void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor)
{ {
if (monitor->ns.previousMode) if (monitor->ns.previousMode)
{ {

View File

@ -120,9 +120,9 @@ typedef struct _GLFWtimeNS
} _GLFWtimeNS; } _GLFWtimeNS;
void _glfwInitTimer(void); void _glfwInitTimerNS(void);
GLFWbool _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired); GLFWbool _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired);
void _glfwRestoreVideoMode(_GLFWmonitor* monitor); void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor);
#endif // _glfw3_cocoa_platform_h_ #endif // _glfw3_cocoa_platform_h_

View File

@ -76,7 +76,7 @@ static float transformY(float y)
// //
static GLFWbool enterFullscreenMode(_GLFWwindow* window) static GLFWbool enterFullscreenMode(_GLFWwindow* window)
{ {
const GLFWbool status = _glfwSetVideoMode(window->monitor, &window->videoMode); const GLFWbool status = _glfwSetVideoModeNS(window->monitor, &window->videoMode);
const CGRect bounds = CGDisplayBounds(window->monitor->ns.displayID); const CGRect bounds = CGDisplayBounds(window->monitor->ns.displayID);
const NSRect frame = NSMakeRect(bounds.origin.x, const NSRect frame = NSMakeRect(bounds.origin.x,
transformY(bounds.origin.y + bounds.size.height), transformY(bounds.origin.y + bounds.size.height),
@ -91,7 +91,7 @@ static GLFWbool enterFullscreenMode(_GLFWwindow* window)
// //
static void leaveFullscreenMode(_GLFWwindow* window) static void leaveFullscreenMode(_GLFWwindow* window)
{ {
_glfwRestoreVideoMode(window->monitor); _glfwRestoreVideoModeNS(window->monitor);
} }
// Translates OS X key modifiers into GLFW ones // Translates OS X key modifiers into GLFW ones
@ -262,7 +262,7 @@ static int translateKey(unsigned int key)
int i; int i;
for (i = 0; i < _glfw.monitorCount; i++) for (i = 0; i < _glfw.monitorCount; i++)
_glfwRestoreVideoMode(_glfw.monitors[i]); _glfwRestoreVideoModeNS(_glfw.monitors[i]);
} }
@end @end
@ -886,7 +886,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
if (ctxconfig->api != GLFW_NO_API) if (ctxconfig->api != GLFW_NO_API)
{ {
if (!_glfwCreateContext(window, ctxconfig, fbconfig)) if (!_glfwCreateContextNSGL(window, ctxconfig, fbconfig))
return GLFW_FALSE; return GLFW_FALSE;
} }
@ -908,7 +908,7 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
leaveFullscreenMode(window); leaveFullscreenMode(window);
if (window->context.api != GLFW_NO_API) if (window->context.api != GLFW_NO_API)
_glfwDestroyContext(window); _glfwDestroyContextNSGL(window);
[window->ns.object setDelegate:nil]; [window->ns.object setDelegate:nil];
[window->ns.delegate release]; [window->ns.delegate release];

View File

@ -176,7 +176,7 @@ static GLFWbool chooseFBConfigs(const _GLFWctxconfig* ctxconfig,
// Initialize EGL // Initialize EGL
// //
int _glfwInitContextAPI(void) int _glfwInitEGL(void)
{ {
int i; int i;
const char* sonames[] = const char* sonames[] =
@ -192,9 +192,6 @@ int _glfwInitContextAPI(void)
NULL NULL
}; };
if (!_glfwCreateContextTLS())
return GLFW_FALSE;
for (i = 0; sonames[i]; i++) for (i = 0; sonames[i]; i++)
{ {
_glfw.egl.handle = _glfw_dlopen(sonames[i]); _glfw.egl.handle = _glfw_dlopen(sonames[i]);
@ -268,7 +265,7 @@ int _glfwInitContextAPI(void)
// Terminate EGL // Terminate EGL
// //
void _glfwTerminateContextAPI(void) void _glfwTerminateEGL(void)
{ {
if (_glfw.egl.handle) if (_glfw.egl.handle)
{ {
@ -276,8 +273,6 @@ void _glfwTerminateContextAPI(void)
_glfw_dlclose(_glfw.egl.handle); _glfw_dlclose(_glfw.egl.handle);
_glfw.egl.handle = NULL; _glfw.egl.handle = NULL;
} }
_glfwDestroyContextTLS();
} }
#define setEGLattrib(attribName, attribValue) \ #define setEGLattrib(attribName, attribValue) \
@ -289,9 +284,9 @@ void _glfwTerminateContextAPI(void)
// Create the OpenGL or OpenGL ES context // Create the OpenGL or OpenGL ES context
// //
int _glfwCreateContext(_GLFWwindow* window, int _glfwCreateContextEGL(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig, const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig) const _GLFWfbconfig* fbconfig)
{ {
int attribs[40]; int attribs[40];
EGLConfig config; EGLConfig config;
@ -492,7 +487,7 @@ int _glfwCreateContext(_GLFWwindow* window,
// Destroy the OpenGL context // Destroy the OpenGL context
// //
void _glfwDestroyContext(_GLFWwindow* window) void _glfwDestroyContextEGL(_GLFWwindow* window)
{ {
#if defined(_GLFW_X11) #if defined(_GLFW_X11)
// NOTE: Do not unload libGL.so.1 while the X11 display is still open, // NOTE: Do not unload libGL.so.1 while the X11 display is still open,
@ -523,9 +518,9 @@ void _glfwDestroyContext(_GLFWwindow* window)
// Returns the Visual and depth of the chosen EGLConfig // Returns the Visual and depth of the chosen EGLConfig
// //
#if defined(_GLFW_X11) #if defined(_GLFW_X11)
GLFWbool _glfwChooseVisual(const _GLFWctxconfig* ctxconfig, GLFWbool _glfwChooseVisualEGL(const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig, const _GLFWfbconfig* fbconfig,
Visual** visual, int* depth) Visual** visual, int* depth)
{ {
XVisualInfo* result; XVisualInfo* result;
XVisualInfo desired; XVisualInfo desired;
@ -584,7 +579,7 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
EGL_NO_CONTEXT); EGL_NO_CONTEXT);
} }
_glfwSetContextTLS(window); _glfwPlatformSetCurrentContext(window);
} }
void _glfwPlatformSwapBuffers(_GLFWwindow* window) void _glfwPlatformSwapBuffers(_GLFWwindow* window)

View File

@ -207,16 +207,16 @@ typedef struct _GLFWlibraryEGL
} _GLFWlibraryEGL; } _GLFWlibraryEGL;
int _glfwInitContextAPI(void); int _glfwInitEGL(void);
void _glfwTerminateContextAPI(void); void _glfwTerminateEGL(void);
int _glfwCreateContext(_GLFWwindow* window, int _glfwCreateContextEGL(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig, const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig); const _GLFWfbconfig* fbconfig);
void _glfwDestroyContext(_GLFWwindow* window); void _glfwDestroyContextEGL(_GLFWwindow* window);
#if defined(_GLFW_X11) #if defined(_GLFW_X11)
GLFWbool _glfwChooseVisual(const _GLFWctxconfig* ctxconfig, GLFWbool _glfwChooseVisualEGL(const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig, const _GLFWfbconfig* fbconfig,
Visual** visual, int* depth); Visual** visual, int* depth);
#endif /*_GLFW_X11*/ #endif /*_GLFW_X11*/
#endif // _glfw3_egl_context_h_ #endif // _glfw3_egl_context_h_

View File

@ -150,7 +150,7 @@ static GLXContext createLegacyContext(_GLFWwindow* window,
// Initialize GLX // Initialize GLX
// //
int _glfwInitContextAPI(void) int _glfwInitGLX(void)
{ {
int i; int i;
const char* sonames[] = const char* sonames[] =
@ -165,9 +165,6 @@ int _glfwInitContextAPI(void)
}; };
if (!_glfwCreateContextTLS())
return GLFW_FALSE;
for (i = 0; sonames[i]; i++) for (i = 0; sonames[i]; i++)
{ {
_glfw.glx.handle = dlopen(sonames[i], RTLD_LAZY | RTLD_GLOBAL); _glfw.glx.handle = dlopen(sonames[i], RTLD_LAZY | RTLD_GLOBAL);
@ -296,7 +293,7 @@ int _glfwInitContextAPI(void)
// Terminate GLX // Terminate GLX
// //
void _glfwTerminateContextAPI(void) void _glfwTerminateGLX(void)
{ {
// NOTE: This function must not call any X11 functions, as it is called // NOTE: This function must not call any X11 functions, as it is called
// after XCloseDisplay (see _glfwPlatformTerminate for details) // after XCloseDisplay (see _glfwPlatformTerminate for details)
@ -306,8 +303,6 @@ void _glfwTerminateContextAPI(void)
dlclose(_glfw.glx.handle); dlclose(_glfw.glx.handle);
_glfw.glx.handle = NULL; _glfw.glx.handle = NULL;
} }
_glfwDestroyContextTLS();
} }
#define setGLXattrib(attribName, attribValue) \ #define setGLXattrib(attribName, attribValue) \
@ -319,9 +314,9 @@ void _glfwTerminateContextAPI(void)
// Create the OpenGL or OpenGL ES context // Create the OpenGL or OpenGL ES context
// //
int _glfwCreateContext(_GLFWwindow* window, int _glfwCreateContextGLX(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig, const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig) const _GLFWfbconfig* fbconfig)
{ {
int attribs[40]; int attribs[40];
GLXFBConfig native = NULL; GLXFBConfig native = NULL;
@ -370,7 +365,7 @@ int _glfwCreateContext(_GLFWwindow* window,
} }
} }
_glfwGrabXErrorHandler(); _glfwGrabErrorHandlerX11();
if (_glfw.glx.ARB_create_context) if (_glfw.glx.ARB_create_context)
{ {
@ -473,11 +468,11 @@ int _glfwCreateContext(_GLFWwindow* window,
else else
window->context.glx.handle = createLegacyContext(window, native, share); window->context.glx.handle = createLegacyContext(window, native, share);
_glfwReleaseXErrorHandler(); _glfwReleaseErrorHandlerX11();
if (!window->context.glx.handle) if (!window->context.glx.handle)
{ {
_glfwInputXError(GLFW_VERSION_UNAVAILABLE, "GLX: Failed to create context"); _glfwInputErrorX11(GLFW_VERSION_UNAVAILABLE, "GLX: Failed to create context");
return GLFW_FALSE; return GLFW_FALSE;
} }
@ -496,7 +491,7 @@ int _glfwCreateContext(_GLFWwindow* window,
// Destroy the OpenGL context // Destroy the OpenGL context
// //
void _glfwDestroyContext(_GLFWwindow* window) void _glfwDestroyContextGLX(_GLFWwindow* window)
{ {
if (window->context.glx.window) if (window->context.glx.window)
{ {
@ -513,9 +508,9 @@ void _glfwDestroyContext(_GLFWwindow* window)
// Returns the Visual and depth of the chosen GLXFBConfig // Returns the Visual and depth of the chosen GLXFBConfig
// //
GLFWbool _glfwChooseVisual(const _GLFWctxconfig* ctxconfig, GLFWbool _glfwChooseVisualGLX(const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig, const _GLFWfbconfig* fbconfig,
Visual** visual, int* depth) Visual** visual, int* depth)
{ {
GLXFBConfig native; GLXFBConfig native;
XVisualInfo* result; XVisualInfo* result;
@ -558,7 +553,7 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
else else
glXMakeCurrent(_glfw.x11.display, None, NULL); glXMakeCurrent(_glfw.x11.display, None, NULL);
_glfwSetContextTLS(window); _glfwPlatformSetCurrentContext(window);
} }
void _glfwPlatformSwapBuffers(_GLFWwindow* window) void _glfwPlatformSwapBuffers(_GLFWwindow* window)

View File

@ -171,14 +171,14 @@ typedef struct _GLFWlibraryGLX
} _GLFWlibraryGLX; } _GLFWlibraryGLX;
int _glfwInitContextAPI(void); int _glfwInitGLX(void);
void _glfwTerminateContextAPI(void); void _glfwTerminateGLX(void);
int _glfwCreateContext(_GLFWwindow* window, int _glfwCreateContextGLX(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig, const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig); const _GLFWfbconfig* fbconfig);
void _glfwDestroyContext(_GLFWwindow* window); void _glfwDestroyContextGLX(_GLFWwindow* window);
GLFWbool _glfwChooseVisual(const _GLFWctxconfig* ctxconfig, GLFWbool _glfwChooseVisualGLX(const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig, const _GLFWfbconfig* fbconfig,
Visual** visual, int* depth); Visual** visual, int* depth);
#endif // _glfw3_glx_context_h_ #endif // _glfw3_glx_context_h_

View File

@ -637,6 +637,10 @@ void _glfwPlatformPostEmptyEvent(void);
*/ */
void _glfwPlatformMakeContextCurrent(_GLFWwindow* window); void _glfwPlatformMakeContextCurrent(_GLFWwindow* window);
/*! @ingroup platform
*/
void _glfwPlatformSetCurrentContext(_GLFWwindow* context);
/*! @copydoc glfwGetCurrentContext /*! @copydoc glfwGetCurrentContext
* @ingroup platform * @ingroup platform
*/ */

View File

@ -1,5 +1,5 @@
//======================================================================== //========================================================================
// GLFW 3.2 IOKit - www.glfw.org // GLFW 3.2 Cocoa - www.glfw.org
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Copyright (c) 2006-2014 Camilla Berglund <elmindreda@elmindreda.org> // Copyright (c) 2006-2014 Camilla Berglund <elmindreda@elmindreda.org>
// //
@ -32,13 +32,12 @@
#include <IOKit/hid/IOHIDLib.h> #include <IOKit/hid/IOHIDLib.h>
#include <IOKit/hid/IOHIDKeys.h> #include <IOKit/hid/IOHIDKeys.h>
#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE \ #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE _GLFWjoystickNS ns_js
_GLFWjoystickIOKit iokit_js
// IOKit-specific per-joystick data // IOKit-specific per-joystick data
// //
typedef struct _GLFWjoydevice typedef struct _GLFWjoydeviceNS
{ {
int present; int present;
char name[256]; char name[256];
@ -51,18 +50,18 @@ typedef struct _GLFWjoydevice
float* axes; float* axes;
unsigned char* buttons; unsigned char* buttons;
} _GLFWjoydevice; } _GLFWjoydeviceNS;
// IOKit-specific joystick API data // IOKit-specific joystick API data
// //
typedef struct _GLFWjoystickIOKit typedef struct _GLFWjoystickNS
{ {
_GLFWjoydevice devices[GLFW_JOYSTICK_LAST + 1]; _GLFWjoydeviceNS devices[GLFW_JOYSTICK_LAST + 1];
IOHIDManagerRef managerRef; IOHIDManagerRef managerRef;
} _GLFWjoystickIOKit; } _GLFWjoystickNS;
void _glfwInitJoysticks(void); void _glfwInitJoysticksNS(void);
void _glfwTerminateJoysticks(void); void _glfwTerminateJoysticksNS(void);
#endif // _glfw3_iokit_joystick_h_ #endif // _glfw3_iokit_joystick_h_

View File

@ -1,5 +1,5 @@
//======================================================================== //========================================================================
// GLFW 3.2 IOKit - www.glfw.org // GLFW 3.2 Cocoa - www.glfw.org
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Copyright (c) 2009-2010 Camilla Berglund <elmindreda@elmindreda.org> // Copyright (c) 2009-2010 Camilla Berglund <elmindreda@elmindreda.org>
// Copyright (c) 2012 Torsten Walluhn <tw@mad-cad.net> // Copyright (c) 2012 Torsten Walluhn <tw@mad-cad.net>
@ -40,7 +40,7 @@
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Joystick element information // Joystick element information
//------------------------------------------------------------------------ //------------------------------------------------------------------------
typedef struct typedef struct _GLFWjoyelementNS
{ {
IOHIDElementRef elementRef; IOHIDElementRef elementRef;
@ -50,14 +50,14 @@ typedef struct
long minReport; long minReport;
long maxReport; long maxReport;
} _GLFWjoyelement; } _GLFWjoyelementNS;
static void getElementsCFArrayHandler(const void* value, void* parameter); static void getElementsCFArrayHandler(const void* value, void* parameter);
// Adds an element to the specified joystick // Adds an element to the specified joystick
// //
static void addJoystickElement(_GLFWjoydevice* joystick, static void addJoystickElement(_GLFWjoydeviceNS* joystick,
IOHIDElementRef elementRef) IOHIDElementRef elementRef)
{ {
IOHIDElementType elementType; IOHIDElementType elementType;
@ -109,7 +109,7 @@ static void addJoystickElement(_GLFWjoydevice* joystick,
if (elementsArray) if (elementsArray)
{ {
_GLFWjoyelement* element = calloc(1, sizeof(_GLFWjoyelement)); _GLFWjoyelementNS* element = calloc(1, sizeof(_GLFWjoyelementNS));
CFArrayAppendValue(elementsArray, element); CFArrayAppendValue(elementsArray, element);
@ -126,14 +126,14 @@ static void getElementsCFArrayHandler(const void* value, void* parameter)
{ {
if (CFGetTypeID(value) == IOHIDElementGetTypeID()) if (CFGetTypeID(value) == IOHIDElementGetTypeID())
{ {
addJoystickElement((_GLFWjoydevice*) parameter, addJoystickElement((_GLFWjoydeviceNS*) parameter,
(IOHIDElementRef) value); (IOHIDElementRef) value);
} }
} }
// Returns the value of the specified element of the specified joystick // Returns the value of the specified element of the specified joystick
// //
static long getElementValue(_GLFWjoydevice* joystick, _GLFWjoyelement* element) static long getElementValue(_GLFWjoydeviceNS* joystick, _GLFWjoyelementNS* element)
{ {
IOReturn result = kIOReturnSuccess; IOReturn result = kIOReturnSuccess;
IOHIDValueRef valueRef; IOHIDValueRef valueRef;
@ -163,7 +163,7 @@ static long getElementValue(_GLFWjoydevice* joystick, _GLFWjoyelement* element)
// Removes the specified joystick // Removes the specified joystick
// //
static void removeJoystick(_GLFWjoydevice* joystick) static void removeJoystick(_GLFWjoydeviceNS* joystick)
{ {
int i; int i;
@ -188,7 +188,7 @@ static void removeJoystick(_GLFWjoydevice* joystick)
free(joystick->axes); free(joystick->axes);
free(joystick->buttons); free(joystick->buttons);
memset(joystick, 0, sizeof(_GLFWjoydevice)); memset(joystick, 0, sizeof(_GLFWjoydeviceNS));
} }
// Polls for joystick events and updates GLFW state // Polls for joystick events and updates GLFW state
@ -201,14 +201,14 @@ static void pollJoystickEvents(void)
{ {
CFIndex i; CFIndex i;
int buttonIndex = 0; int buttonIndex = 0;
_GLFWjoydevice* joystick = _glfw.iokit_js.devices + joy; _GLFWjoydeviceNS* joystick = _glfw.ns_js.devices + joy;
if (!joystick->present) if (!joystick->present)
continue; continue;
for (i = 0; i < CFArrayGetCount(joystick->buttonElements); i++) for (i = 0; i < CFArrayGetCount(joystick->buttonElements); i++)
{ {
_GLFWjoyelement* button = (_GLFWjoyelement*) _GLFWjoyelementNS* button = (_GLFWjoyelementNS*)
CFArrayGetValueAtIndex(joystick->buttonElements, i); CFArrayGetValueAtIndex(joystick->buttonElements, i);
if (getElementValue(joystick, button)) if (getElementValue(joystick, button))
@ -219,7 +219,7 @@ static void pollJoystickEvents(void)
for (i = 0; i < CFArrayGetCount(joystick->axisElements); i++) for (i = 0; i < CFArrayGetCount(joystick->axisElements); i++)
{ {
_GLFWjoyelement* axis = (_GLFWjoyelement*) _GLFWjoyelementNS* axis = (_GLFWjoyelementNS*)
CFArrayGetValueAtIndex(joystick->axisElements, i); CFArrayGetValueAtIndex(joystick->axisElements, i);
long value = getElementValue(joystick, axis); long value = getElementValue(joystick, axis);
@ -233,7 +233,7 @@ static void pollJoystickEvents(void)
for (i = 0; i < CFArrayGetCount(joystick->hatElements); i++) for (i = 0; i < CFArrayGetCount(joystick->hatElements); i++)
{ {
_GLFWjoyelement* hat = (_GLFWjoyelement*) _GLFWjoyelementNS* hat = (_GLFWjoyelementNS*)
CFArrayGetValueAtIndex(joystick->hatElements, i); CFArrayGetValueAtIndex(joystick->hatElements, i);
// Bit fields of button presses for each direction, including nil // Bit fields of button presses for each direction, including nil
@ -261,12 +261,12 @@ static void matchCallback(void* context,
void* sender, void* sender,
IOHIDDeviceRef deviceRef) IOHIDDeviceRef deviceRef)
{ {
_GLFWjoydevice* joystick; _GLFWjoydeviceNS* joystick;
int joy; int joy;
for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++) for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++)
{ {
joystick = _glfw.iokit_js.devices + joy; joystick = _glfw.ns_js.devices + joy;
if (!joystick->present) if (!joystick->present)
continue; continue;
@ -277,7 +277,7 @@ static void matchCallback(void* context,
for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++) for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++)
{ {
joystick = _glfw.iokit_js.devices + joy; joystick = _glfw.ns_js.devices + joy;
if (!joystick->present) if (!joystick->present)
break; break;
@ -328,7 +328,7 @@ static void removeCallback(void* context,
for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++) for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++)
{ {
_GLFWjoydevice* joystick = _glfw.iokit_js.devices + joy; _GLFWjoydeviceNS* joystick = _glfw.ns_js.devices + joy;
if (joystick->deviceRef == deviceRef) if (joystick->deviceRef == deviceRef)
{ {
removeJoystick(joystick); removeJoystick(joystick);
@ -384,12 +384,12 @@ static CFMutableDictionaryRef createMatchingDictionary(long usagePage,
// Initialize joystick interface // Initialize joystick interface
// //
void _glfwInitJoysticks(void) void _glfwInitJoysticksNS(void)
{ {
CFMutableArrayRef matchingCFArrayRef; CFMutableArrayRef matchingCFArrayRef;
_glfw.iokit_js.managerRef = IOHIDManagerCreate(kCFAllocatorDefault, _glfw.ns_js.managerRef = IOHIDManagerCreate(kCFAllocatorDefault,
kIOHIDOptionsTypeNone); kIOHIDOptionsTypeNone);
matchingCFArrayRef = CFArrayCreateMutable(kCFAllocatorDefault, matchingCFArrayRef = CFArrayCreateMutable(kCFAllocatorDefault,
0, 0,
@ -422,21 +422,21 @@ void _glfwInitJoysticks(void)
CFRelease(matchingCFDictRef); CFRelease(matchingCFDictRef);
} }
IOHIDManagerSetDeviceMatchingMultiple(_glfw.iokit_js.managerRef, IOHIDManagerSetDeviceMatchingMultiple(_glfw.ns_js.managerRef,
matchingCFArrayRef); matchingCFArrayRef);
CFRelease(matchingCFArrayRef); CFRelease(matchingCFArrayRef);
} }
IOHIDManagerRegisterDeviceMatchingCallback(_glfw.iokit_js.managerRef, IOHIDManagerRegisterDeviceMatchingCallback(_glfw.ns_js.managerRef,
&matchCallback, NULL); &matchCallback, NULL);
IOHIDManagerRegisterDeviceRemovalCallback(_glfw.iokit_js.managerRef, IOHIDManagerRegisterDeviceRemovalCallback(_glfw.ns_js.managerRef,
&removeCallback, NULL); &removeCallback, NULL);
IOHIDManagerScheduleWithRunLoop(_glfw.iokit_js.managerRef, IOHIDManagerScheduleWithRunLoop(_glfw.ns_js.managerRef,
CFRunLoopGetMain(), CFRunLoopGetMain(),
kCFRunLoopDefaultMode); kCFRunLoopDefaultMode);
IOHIDManagerOpen(_glfw.iokit_js.managerRef, kIOHIDOptionsTypeNone); IOHIDManagerOpen(_glfw.ns_js.managerRef, kIOHIDOptionsTypeNone);
// Execute the run loop once in order to register any initially-attached // Execute the run loop once in order to register any initially-attached
// joysticks // joysticks
@ -445,18 +445,18 @@ void _glfwInitJoysticks(void)
// Close all opened joystick handles // Close all opened joystick handles
// //
void _glfwTerminateJoysticks(void) void _glfwTerminateJoysticksNS(void)
{ {
int joy; int joy;
for (joy = 0; joy <= GLFW_JOYSTICK_LAST; joy++) for (joy = 0; joy <= GLFW_JOYSTICK_LAST; joy++)
{ {
_GLFWjoydevice* joystick = _glfw.iokit_js.devices + joy; _GLFWjoydeviceNS* joystick = _glfw.ns_js.devices + joy;
removeJoystick(joystick); removeJoystick(joystick);
} }
CFRelease(_glfw.iokit_js.managerRef); CFRelease(_glfw.ns_js.managerRef);
_glfw.iokit_js.managerRef = NULL; _glfw.ns_js.managerRef = NULL;
} }
@ -468,12 +468,12 @@ int _glfwPlatformJoystickPresent(int joy)
{ {
pollJoystickEvents(); pollJoystickEvents();
return _glfw.iokit_js.devices[joy].present; return _glfw.ns_js.devices[joy].present;
} }
const float* _glfwPlatformGetJoystickAxes(int joy, int* count) const float* _glfwPlatformGetJoystickAxes(int joy, int* count)
{ {
_GLFWjoydevice* joystick = _glfw.iokit_js.devices + joy; _GLFWjoydeviceNS* joystick = _glfw.ns_js.devices + joy;
pollJoystickEvents(); pollJoystickEvents();
@ -486,7 +486,7 @@ const float* _glfwPlatformGetJoystickAxes(int joy, int* count)
const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count) const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count)
{ {
_GLFWjoydevice* joystick = _glfw.iokit_js.devices + joy; _GLFWjoydeviceNS* joystick = _glfw.ns_js.devices + joy;
pollJoystickEvents(); pollJoystickEvents();
@ -502,6 +502,6 @@ const char* _glfwPlatformGetJoystickName(int joy)
{ {
pollJoystickEvents(); pollJoystickEvents();
return _glfw.iokit_js.devices[joy].name; return _glfw.ns_js.devices[joy].name;
} }

View File

@ -173,7 +173,7 @@ static GLFWbool pollJoystickEvents(_GLFWjoystickLinux* js)
// Initialize joystick interface // Initialize joystick interface
// //
int _glfwInitJoysticks(void) int _glfwInitJoysticksLinux(void)
{ {
#if defined(__linux__) #if defined(__linux__)
const char* dirname = "/dev/input"; const char* dirname = "/dev/input";
@ -244,7 +244,7 @@ int _glfwInitJoysticks(void)
// Close all opened joystick handles // Close all opened joystick handles
// //
void _glfwTerminateJoysticks(void) void _glfwTerminateJoysticksLinux(void)
{ {
#if defined(__linux__) #if defined(__linux__)
int i; int i;

View File

@ -61,7 +61,7 @@ typedef struct _GLFWjoylistLinux
} _GLFWjoylistLinux; } _GLFWjoylistLinux;
int _glfwInitJoysticks(void); int _glfwInitJoysticksLinux(void);
void _glfwTerminateJoysticks(void); void _glfwTerminateJoysticksLinux(void);
#endif // _glfw3_linux_joystick_h_ #endif // _glfw3_linux_joystick_h_

View File

@ -43,7 +43,7 @@ static uint64_t getRawTime(void)
// Initialise timer // Initialise timer
// //
void _glfwInitTimer(void) void _glfwInitTimerNS(void)
{ {
mach_timebase_info_data_t info; mach_timebase_info_data_t info;
mach_timebase_info(&info); mach_timebase_info(&info);

View File

@ -179,17 +179,20 @@ int _glfwPlatformInit(void)
createKeyTables(); createKeyTables();
if (!_glfwInitContextAPI()) if (!_glfwInitThreadLocalStoragePOSIX())
return GLFW_FALSE;
if (!_glfwInitEGL())
return GLFW_FALSE; return GLFW_FALSE;
// Need the default conf for when we set a NULL cursor // Need the default conf for when we set a NULL cursor
_glfw.mir.default_conf = mir_cursor_configuration_from_name(mir_arrow_cursor_name); _glfw.mir.default_conf = mir_cursor_configuration_from_name(mir_arrow_cursor_name);
_glfwInitTimer(); _glfwInitTimerPOSIX();
_glfwInitJoysticks(); _glfwInitJoysticksLinux();
_glfw.mir.event_queue = calloc(1, sizeof(EventQueue)); _glfw.mir.event_queue = calloc(1, sizeof(EventQueue));
_glfwInitEventQueue(_glfw.mir.event_queue); _glfwInitEventQueueMir(_glfw.mir.event_queue);
error = pthread_mutex_init(&_glfw.mir.event_mutex, NULL); error = pthread_mutex_init(&_glfw.mir.event_mutex, NULL);
if (error) if (error)
@ -205,10 +208,11 @@ int _glfwPlatformInit(void)
void _glfwPlatformTerminate(void) void _glfwPlatformTerminate(void)
{ {
_glfwTerminateContextAPI(); _glfwTerminateEGL();
_glfwTerminateJoysticks(); _glfwTerminateJoysticksLinux();
_glfwTerminateThreadLocalStoragePOSIX();
_glfwDeleteEventQueue(_glfw.mir.event_queue); _glfwDeleteEventQueueMir(_glfw.mir.event_queue);
pthread_mutex_destroy(&_glfw.mir.event_mutex); pthread_mutex_destroy(&_glfw.mir.event_mutex);

View File

@ -110,7 +110,7 @@ typedef struct _GLFWcursorMir
} _GLFWcursorMir; } _GLFWcursorMir;
extern void _glfwInitEventQueue(EventQueue* queue); extern void _glfwInitEventQueueMir(EventQueue* queue);
extern void _glfwDeleteEventQueue(EventQueue* queue); extern void _glfwDeleteEventQueueMir(EventQueue* queue);
#endif // _glfw3_mir_platform_h_ #endif // _glfw3_mir_platform_h_

View File

@ -310,12 +310,12 @@ static GLFWbool createSurface(_GLFWwindow* window)
////// GLFW internal API ////// ////// GLFW internal API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void _glfwInitEventQueue(EventQueue* queue) void _glfwInitEventQueueMir(EventQueue* queue)
{ {
TAILQ_INIT(&queue->head); TAILQ_INIT(&queue->head);
} }
void _glfwDeleteEventQueue(EventQueue* queue) void _glfwDeleteEventQueueMir(EventQueue* queue)
{ {
if (queue) if (queue)
{ {
@ -347,7 +347,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
{ {
if (ctxconfig->api != GLFW_NO_API) if (ctxconfig->api != GLFW_NO_API)
{ {
if (!_glfwCreateContext(window, ctxconfig, fbconfig)) if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig))
return GLFW_FALSE; return GLFW_FALSE;
} }
@ -388,7 +388,7 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
window->mir.surface = NULL; window->mir.surface = NULL;
} }
_glfwDestroyContext(window); _glfwDestroyContextEGL(window);
} }
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)

View File

@ -52,11 +52,11 @@ typedef struct _GLFWlibraryNSGL
} _GLFWlibraryNSGL; } _GLFWlibraryNSGL;
int _glfwInitContextAPI(void); int _glfwInitNSGL(void);
void _glfwTerminateContextAPI(void); void _glfwTerminateNSGL(void);
int _glfwCreateContext(_GLFWwindow* window, int _glfwCreateContextNSGL(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig, const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig); const _GLFWfbconfig* fbconfig);
void _glfwDestroyContext(_GLFWwindow* window); void _glfwDestroyContextNSGL(_GLFWwindow* window);
#endif // _glfw3_nsgl_context_h_ #endif // _glfw3_nsgl_context_h_

View File

@ -33,11 +33,8 @@
// Initialize OpenGL support // Initialize OpenGL support
// //
int _glfwInitContextAPI(void) int _glfwInitNSGL(void)
{ {
if (!_glfwCreateContextTLS())
return GLFW_FALSE;
_glfw.nsgl.framework = _glfw.nsgl.framework =
CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl")); CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
if (_glfw.nsgl.framework == NULL) if (_glfw.nsgl.framework == NULL)
@ -52,16 +49,15 @@ int _glfwInitContextAPI(void)
// Terminate OpenGL support // Terminate OpenGL support
// //
void _glfwTerminateContextAPI(void) void _glfwTerminateNSGL(void)
{ {
_glfwDestroyContextTLS();
} }
// Create the OpenGL context // Create the OpenGL context
// //
int _glfwCreateContext(_GLFWwindow* window, int _glfwCreateContextNSGL(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig, const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig) const _GLFWfbconfig* fbconfig)
{ {
unsigned int attributeCount = 0; unsigned int attributeCount = 0;
@ -225,7 +221,7 @@ int _glfwCreateContext(_GLFWwindow* window,
// Destroy the OpenGL context // Destroy the OpenGL context
// //
void _glfwDestroyContext(_GLFWwindow* window) void _glfwDestroyContextNSGL(_GLFWwindow* window)
{ {
[window->context.nsgl.pixelFormat release]; [window->context.nsgl.pixelFormat release];
window->context.nsgl.pixelFormat = nil; window->context.nsgl.pixelFormat = nil;
@ -246,7 +242,7 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
else else
[NSOpenGLContext clearCurrentContext]; [NSOpenGLContext clearCurrentContext];
_glfwSetContextTLS(window); _glfwPlatformSetCurrentContext(window);
} }
void _glfwPlatformSwapBuffers(_GLFWwindow* window) void _glfwPlatformSwapBuffers(_GLFWwindow* window)

View File

@ -59,7 +59,7 @@ static uint64_t getRawTime(void)
// Initialise timer // Initialise timer
// //
void _glfwInitTimer(void) void _glfwInitTimerPOSIX(void)
{ {
#if defined(CLOCK_MONOTONIC) #if defined(CLOCK_MONOTONIC)
struct timespec ts; struct timespec ts;

View File

@ -44,6 +44,6 @@ typedef struct _GLFWtimePOSIX
} _GLFWtimePOSIX; } _GLFWtimePOSIX;
void _glfwInitTimer(void); void _glfwInitTimerPOSIX(void);
#endif // _glfw3_posix_time_h_ #endif // _glfw3_posix_time_h_

View File

@ -32,7 +32,7 @@
////// GLFW internal API ////// ////// GLFW internal API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
GLFWbool _glfwCreateContextTLS(void) GLFWbool _glfwInitThreadLocalStoragePOSIX(void)
{ {
if (pthread_key_create(&_glfw.posix_tls.context, NULL) != 0) if (pthread_key_create(&_glfw.posix_tls.context, NULL) != 0)
{ {
@ -45,22 +45,22 @@ GLFWbool _glfwCreateContextTLS(void)
return GLFW_TRUE; return GLFW_TRUE;
} }
void _glfwDestroyContextTLS(void) void _glfwTerminateThreadLocalStoragePOSIX(void)
{ {
if (_glfw.posix_tls.allocated) if (_glfw.posix_tls.allocated)
pthread_key_delete(_glfw.posix_tls.context); pthread_key_delete(_glfw.posix_tls.context);
} }
void _glfwSetContextTLS(_GLFWwindow* context)
{
pthread_setspecific(_glfw.posix_tls.context, context);
}
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////// GLFW platform API ////// ////// GLFW platform API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void _glfwPlatformSetCurrentContext(_GLFWwindow* context)
{
pthread_setspecific(_glfw.posix_tls.context, context);
}
_GLFWwindow* _glfwPlatformGetCurrentContext(void) _GLFWwindow* _glfwPlatformGetCurrentContext(void)
{ {
return pthread_getspecific(_glfw.posix_tls.context); return pthread_getspecific(_glfw.posix_tls.context);

View File

@ -43,8 +43,7 @@ typedef struct _GLFWtlsPOSIX
} _GLFWtlsPOSIX; } _GLFWtlsPOSIX;
GLFWbool _glfwCreateContextTLS(void); GLFWbool _glfwInitThreadLocalStoragePOSIX(void);
void _glfwDestroyContextTLS(void); void _glfwTerminateThreadLocalStoragePOSIX(void);
void _glfwSetContextTLS(_GLFWwindow* context);
#endif // _glfw3_posix_tls_h_ #endif // _glfw3_posix_tls_h_

View File

@ -287,11 +287,8 @@ static GLFWbool isCompositionEnabled(void)
// Initialize WGL // Initialize WGL
// //
int _glfwInitContextAPI(void) int _glfwInitWGL(void)
{ {
if (!_glfwCreateContextTLS())
return GLFW_FALSE;
_glfw.wgl.instance = LoadLibraryA("opengl32.dll"); _glfw.wgl.instance = LoadLibraryA("opengl32.dll");
if (!_glfw.wgl.instance) if (!_glfw.wgl.instance)
{ {
@ -315,12 +312,10 @@ int _glfwInitContextAPI(void)
// Terminate WGL // Terminate WGL
// //
void _glfwTerminateContextAPI(void) void _glfwTerminateWGL(void)
{ {
if (_glfw.wgl.instance) if (_glfw.wgl.instance)
FreeLibrary(_glfw.wgl.instance); FreeLibrary(_glfw.wgl.instance);
_glfwDestroyContextTLS();
} }
#define setWGLattrib(attribName, attribValue) \ #define setWGLattrib(attribName, attribValue) \
@ -332,15 +327,18 @@ void _glfwTerminateContextAPI(void)
// Create the OpenGL or OpenGL ES context // Create the OpenGL or OpenGL ES context
// //
int _glfwCreateContext(_GLFWwindow* window, int _glfwCreateContextWGL(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig, const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig) const _GLFWfbconfig* fbconfig)
{ {
int attribs[40]; int attribs[40];
int pixelFormat = 0; int pixelFormat = 0;
PIXELFORMATDESCRIPTOR pfd; PIXELFORMATDESCRIPTOR pfd;
HGLRC share = NULL; HGLRC share = NULL;
if (ctxconfig->api == GLFW_NO_API)
return GLFW_TRUE;
if (ctxconfig->share) if (ctxconfig->share)
share = ctxconfig->share->context.wgl.handle; share = ctxconfig->share->context.wgl.handle;
@ -483,7 +481,7 @@ int _glfwCreateContext(_GLFWwindow* window,
// Destroy the OpenGL context // Destroy the OpenGL context
// //
void _glfwDestroyContext(_GLFWwindow* window) void _glfwDestroyContextWGL(_GLFWwindow* window)
{ {
if (window->context.wgl.handle) if (window->context.wgl.handle)
{ {
@ -494,9 +492,9 @@ void _glfwDestroyContext(_GLFWwindow* window)
// Analyzes the specified context for possible recreation // Analyzes the specified context for possible recreation
// //
int _glfwAnalyzeContext(_GLFWwindow* window, int _glfwAnalyzeContextWGL(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig, const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig) const _GLFWfbconfig* fbconfig)
{ {
GLFWbool required = GLFW_FALSE; GLFWbool required = GLFW_FALSE;
@ -600,7 +598,7 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
else else
wglMakeCurrent(NULL, NULL); wglMakeCurrent(NULL, NULL);
_glfwSetContextTLS(window); _glfwPlatformSetCurrentContext(window);
} }
void _glfwPlatformSwapBuffers(_GLFWwindow* window) void _glfwPlatformSwapBuffers(_GLFWwindow* window)

View File

@ -144,14 +144,14 @@ typedef struct _GLFWlibraryWGL
} _GLFWlibraryWGL; } _GLFWlibraryWGL;
int _glfwInitContextAPI(void); int _glfwInitWGL(void);
void _glfwTerminateContextAPI(void); void _glfwTerminateWGL(void);
int _glfwCreateContext(_GLFWwindow* window, int _glfwCreateContextWGL(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig, const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig); const _GLFWfbconfig* fbconfig);
void _glfwDestroyContext(_GLFWwindow* window); void _glfwDestroyContextWGL(_GLFWwindow* window);
int _glfwAnalyzeContext(_GLFWwindow* window, int _glfwAnalyzeContextWGL(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig, const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig); const _GLFWfbconfig* fbconfig);
#endif // _glfw3_wgl_context_h_ #endif // _glfw3_wgl_context_h_

View File

@ -292,7 +292,7 @@ static HWND createHelperWindow(void)
// Returns a wide string version of the specified UTF-8 string // Returns a wide string version of the specified UTF-8 string
// //
WCHAR* _glfwCreateWideStringFromUTF8(const char* source) WCHAR* _glfwCreateWideStringFromUTF8Win32(const char* source)
{ {
WCHAR* target; WCHAR* target;
int length; int length;
@ -314,7 +314,7 @@ WCHAR* _glfwCreateWideStringFromUTF8(const char* source)
// Returns a UTF-8 string version of the specified wide string // Returns a UTF-8 string version of the specified wide string
// //
char* _glfwCreateUTF8FromWideString(const WCHAR* source) char* _glfwCreateUTF8FromWideStringWin32(const WCHAR* source)
{ {
char* target; char* target;
int length; int length;
@ -341,6 +341,9 @@ char* _glfwCreateUTF8FromWideString(const WCHAR* source)
int _glfwPlatformInit(void) int _glfwPlatformInit(void)
{ {
if (!_glfwInitThreadLocalStorageWin32())
return GLFW_FALSE;
// To make SetForegroundWindow work as we want, we need to fiddle // To make SetForegroundWindow work as we want, we need to fiddle
// with the FOREGROUNDLOCKTIMEOUT system setting (we do this as early // with the FOREGROUNDLOCKTIMEOUT system setting (we do this as early
// as possible in the hope of still being the foreground process) // as possible in the hope of still being the foreground process)
@ -359,7 +362,7 @@ int _glfwPlatformInit(void)
else if (_glfw_SetProcessDPIAware) else if (_glfw_SetProcessDPIAware)
_glfw_SetProcessDPIAware(); _glfw_SetProcessDPIAware();
if (!_glfwRegisterWindowClass()) if (!_glfwRegisterWindowClassWin32())
return GLFW_FALSE; return GLFW_FALSE;
_glfw.win32.helperWindow = createHelperWindow(); _glfw.win32.helperWindow = createHelperWindow();
@ -368,18 +371,23 @@ int _glfwPlatformInit(void)
_glfwPlatformPollEvents(); _glfwPlatformPollEvents();
if (!_glfwInitContextAPI()) #if defined(_GLFW_WGL)
if (!_glfwInitWGL())
return GLFW_FALSE; return GLFW_FALSE;
#elif defined(_GLFW_EGL)
if (!_glfwInitEGL())
return GLFW_FALSE;
#endif
_glfwInitTimer(); _glfwInitTimerWin32();
_glfwInitJoysticks(); _glfwInitJoysticksWin32();
return GLFW_TRUE; return GLFW_TRUE;
} }
void _glfwPlatformTerminate(void) void _glfwPlatformTerminate(void)
{ {
_glfwUnregisterWindowClass(); _glfwUnregisterWindowClassWin32();
// Restore previous foreground lock timeout system setting // Restore previous foreground lock timeout system setting
SystemParametersInfoW(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, SystemParametersInfoW(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
@ -388,8 +396,14 @@ void _glfwPlatformTerminate(void)
free(_glfw.win32.clipboardString); free(_glfw.win32.clipboardString);
_glfwTerminateJoysticks(); #if defined(_GLFW_WGL)
_glfwTerminateContextAPI(); _glfwTerminateWGL();
#elif defined(_GLFW_EGL)
_glfwTerminateEGL();
#endif
_glfwTerminateJoysticksWin32();
_glfwTerminateThreadLocalStorageWin32();
if (_glfw.win32.helperWindow) if (_glfw.win32.helperWindow)
DestroyWindow(_glfw.win32.helperWindow); DestroyWindow(_glfw.win32.helperWindow);

View File

@ -47,7 +47,7 @@
// Change the current video mode // Change the current video mode
// //
GLFWbool _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired) GLFWbool _glfwSetVideoModeWin32(_GLFWmonitor* monitor, const GLFWvidmode* desired)
{ {
GLFWvidmode current; GLFWvidmode current;
const GLFWvidmode* best; const GLFWvidmode* best;
@ -86,7 +86,7 @@ GLFWbool _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired)
// Restore the previously saved (original) video mode // Restore the previously saved (original) video mode
// //
void _glfwRestoreVideoMode(_GLFWmonitor* monitor) void _glfwRestoreVideoModeWin32(_GLFWmonitor* monitor)
{ {
if (monitor->win32.modeChanged) if (monitor->win32.modeChanged)
{ {
@ -141,7 +141,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
if (!EnumDisplayDevicesW(adapter.DeviceName, displayIndex, &display, 0)) if (!EnumDisplayDevicesW(adapter.DeviceName, displayIndex, &display, 0))
break; break;
name = _glfwCreateUTF8FromWideString(display.DeviceString); name = _glfwCreateUTF8FromWideStringWin32(display.DeviceString);
if (!name) if (!name)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,

View File

@ -140,7 +140,6 @@ typedef HRESULT (WINAPI * DWMFLUSH_T)(VOID);
typedef HRESULT (WINAPI * SETPROCESSDPIAWARENESS_T)(PROCESS_DPI_AWARENESS); typedef HRESULT (WINAPI * SETPROCESSDPIAWARENESS_T)(PROCESS_DPI_AWARENESS);
#define _glfw_SetProcessDPIAwareness _glfw.win32.shcore.SetProcessDPIAwareness #define _glfw_SetProcessDPIAwareness _glfw.win32.shcore.SetProcessDPIAwareness
#include "win32_tls.h"
#include "winmm_joystick.h" #include "winmm_joystick.h"
#if defined(_GLFW_WGL) #if defined(_GLFW_WGL)
@ -158,6 +157,7 @@ typedef HRESULT (WINAPI * SETPROCESSDPIAWARENESS_T)(PROCESS_DPI_AWARENESS);
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 win32 #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 win32
#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWin32 win32 #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWin32 win32
#define _GLFW_PLATFORM_LIBRARY_TIME_STATE _GLFWtimeWin32 win32_time #define _GLFW_PLATFORM_LIBRARY_TIME_STATE _GLFWtimeWin32 win32_time
#define _GLFW_PLATFORM_LIBRARY_TLS_STATE _GLFWtlsWin32 win32_tls
#define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorWin32 win32 #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorWin32 win32
#define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorWin32 win32 #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorWin32 win32
@ -259,15 +259,28 @@ typedef struct _GLFWtimeWin32
} _GLFWtimeWin32; } _GLFWtimeWin32;
GLFWbool _glfwRegisterWindowClass(void); // Win32-specific global TLS data
void _glfwUnregisterWindowClass(void); //
typedef struct _GLFWtlsWin32
{
GLFWbool allocated;
DWORD context;
WCHAR* _glfwCreateWideStringFromUTF8(const char* source); } _GLFWtlsWin32;
char* _glfwCreateUTF8FromWideString(const WCHAR* source);
void _glfwInitTimer(void);
GLFWbool _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired); GLFWbool _glfwRegisterWindowClassWin32(void);
void _glfwRestoreVideoMode(_GLFWmonitor* monitor); void _glfwUnregisterWindowClassWin32(void);
GLFWbool _glfwInitThreadLocalStorageWin32(void);
void _glfwTerminateThreadLocalStorageWin32(void);
WCHAR* _glfwCreateWideStringFromUTF8Win32(const char* source);
char* _glfwCreateUTF8FromWideStringWin32(const WCHAR* source);
void _glfwInitTimerWin32(void);
GLFWbool _glfwSetVideoModeWin32(_GLFWmonitor* monitor, const GLFWvidmode* desired);
void _glfwRestoreVideoModeWin32(_GLFWmonitor* monitor);
#endif // _glfw3_win32_platform_h_ #endif // _glfw3_win32_platform_h_

View File

@ -49,7 +49,7 @@ static unsigned __int64 getRawTime(void)
// Initialise timer // Initialise timer
// //
void _glfwInitTimer(void) void _glfwInitTimerWin32(void)
{ {
unsigned __int64 frequency; unsigned __int64 frequency;

View File

@ -32,7 +32,7 @@
////// GLFW internal API ////// ////// GLFW internal API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
GLFWbool _glfwCreateContextTLS(void) GLFWbool _glfwInitThreadLocalStorageWin32(void)
{ {
_glfw.win32_tls.context = TlsAlloc(); _glfw.win32_tls.context = TlsAlloc();
if (_glfw.win32_tls.context == TLS_OUT_OF_INDEXES) if (_glfw.win32_tls.context == TLS_OUT_OF_INDEXES)
@ -46,22 +46,22 @@ GLFWbool _glfwCreateContextTLS(void)
return GLFW_TRUE; return GLFW_TRUE;
} }
void _glfwDestroyContextTLS(void) void _glfwTerminateThreadLocalStorageWin32(void)
{ {
if (_glfw.win32_tls.allocated) if (_glfw.win32_tls.allocated)
TlsFree(_glfw.win32_tls.context); TlsFree(_glfw.win32_tls.context);
} }
void _glfwSetContextTLS(_GLFWwindow* context)
{
TlsSetValue(_glfw.win32_tls.context, context);
}
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////// GLFW platform API ////// ////// GLFW platform API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void _glfwPlatformSetCurrentContext(_GLFWwindow* context)
{
TlsSetValue(_glfw.win32_tls.context, context);
}
_GLFWwindow* _glfwPlatformGetCurrentContext(void) _GLFWwindow* _glfwPlatformGetCurrentContext(void)
{ {
return TlsGetValue(_glfw.win32_tls.context); return TlsGetValue(_glfw.win32_tls.context);

View File

@ -1,48 +0,0 @@
//========================================================================
// GLFW 3.2 Win32 - www.glfw.org
//------------------------------------------------------------------------
// Copyright (c) 2002-2006 Marcus Geelnard
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
#ifndef _glfw3_win32_tls_h_
#define _glfw3_win32_tls_h_
#define _GLFW_PLATFORM_LIBRARY_TLS_STATE _GLFWtlsWin32 win32_tls
// Win32-specific global TLS data
//
typedef struct _GLFWtlsWin32
{
GLFWbool allocated;
DWORD context;
} _GLFWtlsWin32;
GLFWbool _glfwCreateContextTLS(void);
void _glfwDestroyContextTLS(void);
void _glfwSetContextTLS(_GLFWwindow* context);
#endif // _glfw3_win32_tls_h_

View File

@ -229,7 +229,7 @@ static GLFWbool enterFullscreenMode(_GLFWwindow* window)
GLFWbool status; GLFWbool status;
int xpos, ypos; int xpos, ypos;
status = _glfwSetVideoMode(window->monitor, &window->videoMode); status = _glfwSetVideoModeWin32(window->monitor, &window->videoMode);
_glfwPlatformGetVideoMode(window->monitor, &mode); _glfwPlatformGetVideoMode(window->monitor, &mode);
_glfwPlatformGetMonitorPos(window->monitor, &xpos, &ypos); _glfwPlatformGetMonitorPos(window->monitor, &xpos, &ypos);
@ -244,7 +244,7 @@ static GLFWbool enterFullscreenMode(_GLFWwindow* window)
// //
static void leaveFullscreenMode(_GLFWwindow* window) static void leaveFullscreenMode(_GLFWwindow* window)
{ {
_glfwRestoreVideoMode(window->monitor); _glfwRestoreVideoModeWin32(window->monitor);
} }
// Window callback function (handles window messages) // Window callback function (handles window messages)
@ -628,7 +628,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
WCHAR* buffer = calloc(length + 1, sizeof(WCHAR)); WCHAR* buffer = calloc(length + 1, sizeof(WCHAR));
DragQueryFileW(drop, i, buffer, length + 1); DragQueryFileW(drop, i, buffer, length + 1);
paths[i] = _glfwCreateUTF8FromWideString(buffer); paths[i] = _glfwCreateUTF8FromWideStringWin32(buffer);
free(buffer); free(buffer);
} }
@ -676,7 +676,7 @@ static int createWindow(_GLFWwindow* window, const _GLFWwndconfig* wndconfig)
&fullWidth, &fullHeight); &fullWidth, &fullHeight);
} }
wideTitle = _glfwCreateWideStringFromUTF8(wndconfig->title); wideTitle = _glfwCreateWideStringFromUTF8Win32(wndconfig->title);
if (!wideTitle) if (!wideTitle)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
@ -751,7 +751,7 @@ static void destroyWindow(_GLFWwindow* window)
// Registers the GLFW window class // Registers the GLFW window class
// //
GLFWbool _glfwRegisterWindowClass(void) GLFWbool _glfwRegisterWindowClassWin32(void)
{ {
WNDCLASSEXW wc; WNDCLASSEXW wc;
@ -788,7 +788,7 @@ GLFWbool _glfwRegisterWindowClass(void)
// Unregisters the GLFW window class // Unregisters the GLFW window class
// //
void _glfwUnregisterWindowClass(void) void _glfwUnregisterWindowClassWin32(void)
{ {
UnregisterClassW(_GLFW_WNDCLASSNAME, GetModuleHandleW(NULL)); UnregisterClassW(_GLFW_WNDCLASSNAME, GetModuleHandleW(NULL));
} }
@ -810,11 +810,11 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
if (ctxconfig->api != GLFW_NO_API) if (ctxconfig->api != GLFW_NO_API)
{ {
if (!_glfwCreateContext(window, ctxconfig, fbconfig)) #if defined(_GLFW_WGL)
if (!_glfwCreateContextWGL(window, ctxconfig, fbconfig))
return GLFW_FALSE; return GLFW_FALSE;
#if defined(_GLFW_WGL) status = _glfwAnalyzeContextWGL(window, ctxconfig, fbconfig);
status = _glfwAnalyzeContext(window, ctxconfig, fbconfig);
if (status == _GLFW_RECREATION_IMPOSSIBLE) if (status == _GLFW_RECREATION_IMPOSSIBLE)
return GLFW_FALSE; return GLFW_FALSE;
@ -844,16 +844,19 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
// Next destroy the Win32 window and WGL context (without resetting // Next destroy the Win32 window and WGL context (without resetting
// or destroying the GLFW window object) // or destroying the GLFW window object)
_glfwDestroyContext(window); _glfwDestroyContextWGL(window);
destroyWindow(window); destroyWindow(window);
// ...and then create them again, this time with better APIs // ...and then create them again, this time with better APIs
if (!createWindow(window, wndconfig)) if (!createWindow(window, wndconfig))
return GLFW_FALSE; return GLFW_FALSE;
if (!_glfwCreateContext(window, ctxconfig, fbconfig)) if (!_glfwCreateContextWGL(window, ctxconfig, fbconfig))
return GLFW_FALSE; return GLFW_FALSE;
} }
#endif // _GLFW_WGL #elif defined(_GLFW_EGL)
if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig))
return GLFW_FALSE;
#endif
} }
if (window->monitor) if (window->monitor)
@ -872,14 +875,20 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
leaveFullscreenMode(window); leaveFullscreenMode(window);
if (window->context.api != GLFW_NO_API) if (window->context.api != GLFW_NO_API)
_glfwDestroyContext(window); {
#if defined(_GLFW_WGL)
_glfwDestroyContextWGL(window);
#elif defined(_GLFW_EGL)
_glfwDestroyContextEGL(window);
#endif
}
destroyWindow(window); destroyWindow(window);
} }
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
{ {
WCHAR* wideTitle = _glfwCreateWideStringFromUTF8(title); WCHAR* wideTitle = _glfwCreateWideStringFromUTF8Win32(title);
if (!wideTitle) if (!wideTitle)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
@ -1318,7 +1327,7 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
HANDLE stringHandle; HANDLE stringHandle;
size_t wideSize; size_t wideSize;
wideString = _glfwCreateWideStringFromUTF8(string); wideString = _glfwCreateWideStringFromUTF8Win32(string);
if (!wideString) if (!wideString)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
@ -1379,7 +1388,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
free(_glfw.win32.clipboardString); free(_glfw.win32.clipboardString);
_glfw.win32.clipboardString = _glfw.win32.clipboardString =
_glfwCreateUTF8FromWideString(GlobalLock(stringHandle)); _glfwCreateUTF8FromWideStringWin32(GlobalLock(stringHandle));
GlobalUnlock(stringHandle); GlobalUnlock(stringHandle);
CloseClipboard(); CloseClipboard();

View File

@ -52,13 +52,13 @@ static float normalizeAxis(DWORD pos, DWORD min, DWORD max)
// Initialize joystick interface // Initialize joystick interface
// //
void _glfwInitJoysticks(void) void _glfwInitJoysticksWin32(void)
{ {
} }
// Close all opened joystick handles // Close all opened joystick handles
// //
void _glfwTerminateJoysticks(void) void _glfwTerminateJoysticksWin32(void)
{ {
int i; int i;
@ -170,7 +170,7 @@ const char* _glfwPlatformGetJoystickName(int joy)
return NULL; return NULL;
free(_glfw.winmm_js[joy].name); free(_glfw.winmm_js[joy].name);
_glfw.winmm_js[joy].name = _glfwCreateUTF8FromWideString(jc.szPname); _glfw.winmm_js[joy].name = _glfwCreateUTF8FromWideStringWin32(jc.szPname);
return _glfw.winmm_js[joy].name; return _glfw.winmm_js[joy].name;
} }

View File

@ -395,7 +395,7 @@ static void registryHandleGlobal(void* data,
} }
else if (strcmp(interface, "wl_output") == 0) else if (strcmp(interface, "wl_output") == 0)
{ {
_glfwAddOutput(name, version); _glfwAddOutputWayland(name, version);
} }
else if (strcmp(interface, "wl_seat") == 0) else if (strcmp(interface, "wl_seat") == 0)
{ {
@ -581,11 +581,14 @@ int _glfwPlatformInit(void)
// Sync so we got all initial output events // Sync so we got all initial output events
wl_display_roundtrip(_glfw.wl.display); wl_display_roundtrip(_glfw.wl.display);
if (!_glfwInitContextAPI()) if (!_glfwInitThreadLocalStoragePOSIX())
return GLFW_FALSE; return GLFW_FALSE;
_glfwInitTimer(); if (!_glfwInitEGL())
_glfwInitJoysticks(); return GLFW_FALSE;
_glfwInitTimerPOSIX();
_glfwInitJoysticksLinux();
if (_glfw.wl.pointer && _glfw.wl.shm) if (_glfw.wl.pointer && _glfw.wl.shm)
{ {
@ -605,8 +608,9 @@ int _glfwPlatformInit(void)
void _glfwPlatformTerminate(void) void _glfwPlatformTerminate(void)
{ {
_glfwTerminateContextAPI(); _glfwTerminateEGL();
_glfwTerminateJoysticks(); _glfwTerminateJoysticksLinux();
_glfwTerminateThreadLocalStoragePOSIX();
if (_glfw.wl.cursorTheme) if (_glfw.wl.cursorTheme)
wl_cursor_theme_destroy(_glfw.wl.cursorTheme); wl_cursor_theme_destroy(_glfw.wl.cursorTheme);

View File

@ -111,7 +111,7 @@ static const struct wl_output_listener output_listener = {
////// GLFW internal API ////// ////// GLFW internal API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void _glfwAddOutput(uint32_t name, uint32_t version) void _glfwAddOutputWayland(uint32_t name, uint32_t version)
{ {
_GLFWmonitor *monitor; _GLFWmonitor *monitor;
struct wl_output *output; struct wl_output *output;

View File

@ -138,6 +138,6 @@ typedef struct _GLFWcursorWayland
} _GLFWcursorWayland; } _GLFWcursorWayland;
void _glfwAddOutput(uint32_t name, uint32_t version); void _glfwAddOutputWayland(uint32_t name, uint32_t version);
#endif // _glfw3_wayland_platform_h_ #endif // _glfw3_wayland_platform_h_

View File

@ -243,7 +243,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
if (ctxconfig->api != GLFW_NO_API) if (ctxconfig->api != GLFW_NO_API)
{ {
if (!_glfwCreateContext(window, ctxconfig, fbconfig)) if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig))
return GLFW_FALSE; return GLFW_FALSE;
} }
@ -278,7 +278,7 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
_glfwInputWindowFocus(window, GLFW_FALSE); _glfwInputWindowFocus(window, GLFW_FALSE);
} }
_glfwDestroyContext(window); _glfwDestroyContextEGL(window);
if (window->wl.native) if (window->wl.native)
wl_egl_window_destroy(window->wl.native); wl_egl_window_destroy(window->wl.native);

View File

@ -387,24 +387,24 @@ static void detectEWMH(void)
return; return;
// Then we look for the _NET_SUPPORTING_WM_CHECK property of the root window // Then we look for the _NET_SUPPORTING_WM_CHECK property of the root window
if (_glfwGetWindowProperty(_glfw.x11.root, if (_glfwGetWindowPropertyX11(_glfw.x11.root,
supportingWmCheck, supportingWmCheck,
XA_WINDOW, XA_WINDOW,
(unsigned char**) &windowFromRoot) != 1) (unsigned char**) &windowFromRoot) != 1)
{ {
if (windowFromRoot) if (windowFromRoot)
XFree(windowFromRoot); XFree(windowFromRoot);
return; return;
} }
_glfwGrabXErrorHandler(); _glfwGrabErrorHandlerX11();
// It should be the ID of a child window (of the root) // It should be the ID of a child window (of the root)
// Then we look for the same property on the child window // Then we look for the same property on the child window
if (_glfwGetWindowProperty(*windowFromRoot, if (_glfwGetWindowPropertyX11(*windowFromRoot,
supportingWmCheck, supportingWmCheck,
XA_WINDOW, XA_WINDOW,
(unsigned char**) &windowFromChild) != 1) (unsigned char**) &windowFromChild) != 1)
{ {
XFree(windowFromRoot); XFree(windowFromRoot);
if (windowFromChild) if (windowFromChild)
@ -412,7 +412,7 @@ static void detectEWMH(void)
return; return;
} }
_glfwReleaseXErrorHandler(); _glfwReleaseErrorHandlerX11();
// It should be the ID of that same child window // It should be the ID of that same child window
if (*windowFromRoot != *windowFromChild) if (*windowFromRoot != *windowFromChild)
@ -432,10 +432,10 @@ static void detectEWMH(void)
// Now we need to check the _NET_SUPPORTED property of the root window // Now we need to check the _NET_SUPPORTED property of the root window
// It should be a list of supported WM protocol and state atoms // It should be a list of supported WM protocol and state atoms
atomCount = _glfwGetWindowProperty(_glfw.x11.root, atomCount = _glfwGetWindowPropertyX11(_glfw.x11.root,
wmSupported, wmSupported,
XA_ATOM, XA_ATOM,
(unsigned char**) &supportedAtoms); (unsigned char**) &supportedAtoms);
// See which of the atoms we support that are supported by the WM // See which of the atoms we support that are supported by the WM
_glfw.x11.NET_WM_STATE = _glfw.x11.NET_WM_STATE =
@ -635,7 +635,7 @@ static Cursor createNULLCursor(void)
memset(pixels, 0, sizeof(pixels)); memset(pixels, 0, sizeof(pixels));
return _glfwCreateCursor(&image, 0, 0); return _glfwCreateCursorX11(&image, 0, 0);
} }
// X error handler // X error handler
@ -653,7 +653,7 @@ static int errorHandler(Display *display, XErrorEvent* event)
// Sets the X error handler callback // Sets the X error handler callback
// //
void _glfwGrabXErrorHandler(void) void _glfwGrabErrorHandlerX11(void)
{ {
_glfw.x11.errorCode = Success; _glfw.x11.errorCode = Success;
XSetErrorHandler(errorHandler); XSetErrorHandler(errorHandler);
@ -661,7 +661,7 @@ void _glfwGrabXErrorHandler(void)
// Clears the X error handler callback // Clears the X error handler callback
// //
void _glfwReleaseXErrorHandler(void) void _glfwReleaseErrorHandlerX11(void)
{ {
// Synchronize to make sure all commands are processed // Synchronize to make sure all commands are processed
XSync(_glfw.x11.display, False); XSync(_glfw.x11.display, False);
@ -670,7 +670,7 @@ void _glfwReleaseXErrorHandler(void)
// Reports the specified error, appending information about the last X error // Reports the specified error, appending information about the last X error
// //
void _glfwInputXError(int error, const char* message) void _glfwInputErrorX11(int error, const char* message)
{ {
char buffer[8192]; char buffer[8192];
XGetErrorText(_glfw.x11.display, _glfw.x11.errorCode, XGetErrorText(_glfw.x11.display, _glfw.x11.errorCode,
@ -681,7 +681,7 @@ void _glfwInputXError(int error, const char* message)
// Creates a native cursor object from the specified image and hotspot // Creates a native cursor object from the specified image and hotspot
// //
Cursor _glfwCreateCursor(const GLFWimage* image, int xhot, int yhot) Cursor _glfwCreateCursorX11(const GLFWimage* image, int xhot, int yhot)
{ {
int i; int i;
Cursor cursor; Cursor cursor;
@ -768,13 +768,21 @@ int _glfwPlatformInit(void)
} }
} }
if (!_glfwInitContextAPI()) if (!_glfwInitThreadLocalStoragePOSIX())
return GLFW_FALSE; return GLFW_FALSE;
if (!_glfwInitJoysticks()) #if defined(_GLFW_GLX)
if (!_glfwInitGLX())
return GLFW_FALSE;
#elif defined(_GLFW_EGL)
if (!_glfwInitEGL())
return GLFW_FALSE;
#endif
if (!_glfwInitJoysticksLinux())
return GLFW_FALSE; return GLFW_FALSE;
_glfwInitTimer(); _glfwInitTimerPOSIX();
return GLFW_TRUE; return GLFW_TRUE;
} }
@ -795,6 +803,10 @@ void _glfwPlatformTerminate(void)
_glfw.x11.im = NULL; _glfw.x11.im = NULL;
} }
#if defined(_GLFW_EGL)
_glfwTerminateEGL();
#endif
if (_glfw.x11.display) if (_glfw.x11.display)
{ {
XCloseDisplay(_glfw.x11.display); XCloseDisplay(_glfw.x11.display);
@ -803,8 +815,12 @@ void _glfwPlatformTerminate(void)
// NOTE: This needs to be done after XCloseDisplay, as libGL registers // NOTE: This needs to be done after XCloseDisplay, as libGL registers
// cleanup callbacks that get called by it // cleanup callbacks that get called by it
_glfwTerminateContextAPI(); #if defined(_GLFW_GLX)
_glfwTerminateJoysticks(); _glfwTerminateGLX();
#endif
_glfwTerminateJoysticksLinux();
_glfwTerminateThreadLocalStoragePOSIX();
} }
const char* _glfwPlatformGetVersionString(void) const char* _glfwPlatformGetVersionString(void)

View File

@ -97,7 +97,7 @@ static GLFWvidmode vidmodeFromModeInfo(const XRRModeInfo* mi,
// Set the current video mode for the specified monitor // Set the current video mode for the specified monitor
// //
GLFWbool _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired) GLFWbool _glfwSetVideoModeX11(_GLFWmonitor* monitor, const GLFWvidmode* desired)
{ {
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken) if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken)
{ {
@ -164,7 +164,7 @@ GLFWbool _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired)
// Restore the saved (original) video mode for the specified monitor // Restore the saved (original) video mode for the specified monitor
// //
void _glfwRestoreVideoMode(_GLFWmonitor* monitor) void _glfwRestoreVideoModeX11(_GLFWmonitor* monitor)
{ {
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken) if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken)
{ {

View File

@ -253,18 +253,18 @@ typedef struct _GLFWcursorX11
} _GLFWcursorX11; } _GLFWcursorX11;
GLFWbool _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired); GLFWbool _glfwSetVideoModeX11(_GLFWmonitor* monitor, const GLFWvidmode* desired);
void _glfwRestoreVideoMode(_GLFWmonitor* monitor); void _glfwRestoreVideoModeX11(_GLFWmonitor* monitor);
Cursor _glfwCreateCursor(const GLFWimage* image, int xhot, int yhot); Cursor _glfwCreateCursorX11(const GLFWimage* image, int xhot, int yhot);
unsigned long _glfwGetWindowProperty(Window window, unsigned long _glfwGetWindowPropertyX11(Window window,
Atom property, Atom property,
Atom type, Atom type,
unsigned char** value); unsigned char** value);
void _glfwGrabXErrorHandler(void); void _glfwGrabErrorHandlerX11(void);
void _glfwReleaseXErrorHandler(void); void _glfwReleaseErrorHandlerX11(void);
void _glfwInputXError(int error, const char* message); void _glfwInputErrorX11(int error, const char* message);
#endif // _glfw3_x11_platform_h_ #endif // _glfw3_x11_platform_h_

View File

@ -83,10 +83,10 @@ static int getWindowState(_GLFWwindow* window)
Window icon; Window icon;
} *state = NULL; } *state = NULL;
if (_glfwGetWindowProperty(window->x11.handle, if (_glfwGetWindowPropertyX11(window->x11.handle,
_glfw.x11.WM_STATE, _glfw.x11.WM_STATE,
_glfw.x11.WM_STATE, _glfw.x11.WM_STATE,
(unsigned char**) &state) >= 2) (unsigned char**) &state) >= 2)
{ {
result = state->state; result = state->state;
} }
@ -272,7 +272,7 @@ static GLFWbool createWindow(_GLFWwindow* window,
ExposureMask | FocusChangeMask | VisibilityChangeMask | ExposureMask | FocusChangeMask | VisibilityChangeMask |
EnterWindowMask | LeaveWindowMask | PropertyChangeMask; EnterWindowMask | LeaveWindowMask | PropertyChangeMask;
_glfwGrabXErrorHandler(); _glfwGrabErrorHandlerX11();
window->x11.handle = XCreateWindow(_glfw.x11.display, window->x11.handle = XCreateWindow(_glfw.x11.display,
_glfw.x11.root, _glfw.x11.root,
@ -285,12 +285,12 @@ static GLFWbool createWindow(_GLFWwindow* window,
wamask, wamask,
&wa); &wa);
_glfwReleaseXErrorHandler(); _glfwReleaseErrorHandlerX11();
if (!window->x11.handle) if (!window->x11.handle)
{ {
_glfwInputXError(GLFW_PLATFORM_ERROR, _glfwInputErrorX11(GLFW_PLATFORM_ERROR,
"X11: Failed to create window"); "X11: Failed to create window");
return GLFW_FALSE; return GLFW_FALSE;
} }
@ -552,10 +552,10 @@ static Atom writeTargetToProperty(const XSelectionRequestEvent* request)
Atom* targets; Atom* targets;
unsigned long i, count; unsigned long i, count;
count = _glfwGetWindowProperty(request->requestor, count = _glfwGetWindowPropertyX11(request->requestor,
request->property, request->property,
_glfw.x11.ATOM_PAIR, _glfw.x11.ATOM_PAIR,
(unsigned char**) &targets); (unsigned char**) &targets);
for (i = 0; i < count; i += 2) for (i = 0; i < count; i += 2)
{ {
@ -728,7 +728,7 @@ static void enterFullscreenMode(_GLFWwindow* window)
_glfw.x11.saver.count++; _glfw.x11.saver.count++;
_glfwSetVideoMode(window->monitor, &window->videoMode); _glfwSetVideoModeX11(window->monitor, &window->videoMode);
if (_glfw.x11.NET_WM_BYPASS_COMPOSITOR) if (_glfw.x11.NET_WM_BYPASS_COMPOSITOR)
{ {
@ -793,7 +793,7 @@ static void enterFullscreenMode(_GLFWwindow* window)
// //
static void leaveFullscreenMode(_GLFWwindow* window) static void leaveFullscreenMode(_GLFWwindow* window)
{ {
_glfwRestoreVideoMode(window->monitor); _glfwRestoreVideoModeX11(window->monitor);
_glfw.x11.saver.count--; _glfw.x11.saver.count--;
@ -1243,10 +1243,10 @@ static void processEvent(XEvent *event)
// The converted data from the drag operation has arrived // The converted data from the drag operation has arrived
char* data; char* data;
const int result = const int result =
_glfwGetWindowProperty(event->xselection.requestor, _glfwGetWindowPropertyX11(event->xselection.requestor,
event->xselection.property, event->xselection.property,
event->xselection.target, event->xselection.target,
(unsigned char**) &data); (unsigned char**) &data);
if (result) if (result)
{ {
@ -1429,10 +1429,10 @@ static void processEvent(XEvent *event)
// Retrieve a single window property of the specified type // Retrieve a single window property of the specified type
// Inspired by fghGetWindowProperty from freeglut // Inspired by fghGetWindowProperty from freeglut
// //
unsigned long _glfwGetWindowProperty(Window window, unsigned long _glfwGetWindowPropertyX11(Window window,
Atom property, Atom property,
Atom type, Atom type,
unsigned char** value) unsigned char** value)
{ {
Atom actualType; Atom actualType;
int actualFormat; int actualFormat;
@ -1470,16 +1470,26 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
Visual* visual; Visual* visual;
int depth; int depth;
if (!_glfwChooseVisual(ctxconfig, fbconfig, &visual, &depth)) #if defined(_GLFW_GLX)
if (!_glfwChooseVisualGLX(ctxconfig, fbconfig, &visual, &depth))
return GLFW_FALSE; return GLFW_FALSE;
#elif defined(_GLFW_EGL)
if (!_glfwChooseVisualEGL(ctxconfig, fbconfig, &visual, &depth))
return GLFW_FALSE;
#endif
if (!createWindow(window, wndconfig, visual, depth)) if (!createWindow(window, wndconfig, visual, depth))
return GLFW_FALSE; return GLFW_FALSE;
if (ctxconfig->api != GLFW_NO_API) if (ctxconfig->api != GLFW_NO_API)
{ {
if (!_glfwCreateContext(window, ctxconfig, fbconfig)) #if defined(_GLFW_GLX)
if (!_glfwCreateContextGLX(window, ctxconfig, fbconfig))
return GLFW_FALSE; return GLFW_FALSE;
#elif defined(_GLFW_EGL)
if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig))
return GLFW_FALSE;
#endif
} }
if (wndconfig->monitor) if (wndconfig->monitor)
@ -1503,7 +1513,13 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
} }
if (window->context.api != GLFW_NO_API) if (window->context.api != GLFW_NO_API)
_glfwDestroyContext(window); {
#if defined(_GLFW_GLX)
_glfwDestroyContextGLX(window);
#elif defined(_GLFW_EGL)
_glfwDestroyContextEGL(window);
#endif
}
if (window->x11.handle) if (window->x11.handle)
{ {
@ -1610,7 +1626,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
{ {
if (window->monitor) if (window->monitor)
{ {
_glfwSetVideoMode(window->monitor, &window->videoMode); _glfwSetVideoModeX11(window->monitor, &window->videoMode);
if (!_glfw.x11.NET_WM_STATE || !_glfw.x11.NET_WM_STATE_FULLSCREEN) if (!_glfw.x11.NET_WM_STATE || !_glfw.x11.NET_WM_STATE_FULLSCREEN)
{ {
@ -1751,10 +1767,10 @@ void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
} }
} }
if (_glfwGetWindowProperty(window->x11.handle, if (_glfwGetWindowPropertyX11(window->x11.handle,
_glfw.x11.NET_FRAME_EXTENTS, _glfw.x11.NET_FRAME_EXTENTS,
XA_CARDINAL, XA_CARDINAL,
(unsigned char**) &extents) == 4) (unsigned char**) &extents) == 4)
{ {
if (left) if (left)
*left = extents[0]; *left = extents[0];
@ -1971,7 +1987,7 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
const GLFWimage* image, const GLFWimage* image,
int xhot, int yhot) int xhot, int yhot)
{ {
cursor->x11.handle = _glfwCreateCursor(image, xhot, yhot); cursor->x11.handle = _glfwCreateCursorX11(image, xhot, yhot);
if (!cursor->x11.handle) if (!cursor->x11.handle)
return GLFW_FALSE; return GLFW_FALSE;
@ -2066,10 +2082,10 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
if (event.xselection.property == None) if (event.xselection.property == None)
continue; continue;
if (_glfwGetWindowProperty(event.xselection.requestor, if (_glfwGetWindowPropertyX11(event.xselection.requestor,
event.xselection.property, event.xselection.property,
event.xselection.target, event.xselection.target,
(unsigned char**) &data)) (unsigned char**) &data))
{ {
_glfw.x11.clipboardString = strdup(data); _glfw.x11.clipboardString = strdup(data);
} }