stw: Keep per-thread storage for current context and pixel format.

This commit is contained in:
Michal Krol 2009-03-20 13:05:51 +01:00
parent 3d4246e22e
commit 4489f9efee
7 changed files with 193 additions and 12 deletions

View file

@ -30,6 +30,7 @@ if env['platform'] in ['windows']:
'shared/stw_arbextensionsstring.c',
'shared/stw_getprocaddress.c',
'shared/stw_arbpixelformat.c',
'shared/stw_tls.c',
]
wgl = env.ConvenienceLibrary(

View file

@ -39,9 +39,7 @@
#include "shared/stw_pixelformat.h"
#include "stw_public.h"
#include "stw_context.h"
static HDC current_hdc = NULL;
static UINT_PTR current_hglrc = 0;
#include "stw_tls.h"
BOOL
stw_copy_context(
@ -264,13 +262,13 @@ get_window_size( HDC hdc, GLuint *width, GLuint *height )
UINT_PTR
stw_get_current_context( void )
{
return current_hglrc;
return stw_tls_get_data()->currentGLRC;
}
HDC
stw_get_current_dc( void )
{
return current_hdc;
return stw_tls_get_data()->currentDC;
}
BOOL
@ -295,8 +293,8 @@ stw_make_current(
if (ctx == NULL)
return FALSE;
current_hdc = hdc;
current_hglrc = hglrc;
stw_tls_get_data()->currentDC = hdc;
stw_tls_get_data()->currentGLRC = hglrc;
if (glcurctx != NULL) {
curctx = (struct stw_context *) glcurctx->DriverCtx;

View file

@ -35,6 +35,7 @@
#include "shared/stw_winsys.h"
#include "shared/stw_pixelformat.h"
#include "shared/stw_public.h"
#include "shared/stw_tls.h"
#ifdef WIN32_THREADS
extern _glthread_Mutex OneTimeLock;
@ -70,6 +71,8 @@ st_init(const struct stw_winsys *stw_winsys)
assert(!stw_dev);
stw_tls_init();
stw_dev = &stw_dev_storage;
memset(stw_dev, 0, sizeof(*stw_dev));
@ -101,6 +104,24 @@ error1:
}
boolean
st_init_thread(void)
{
if (!stw_tls_init_thread()) {
return FALSE;
}
return TRUE;
}
void
st_cleanup_thread(void)
{
stw_tls_cleanup_thread();
}
void
st_cleanup(void)
{
@ -133,6 +154,8 @@ st_cleanup(void)
debug_memory_end(stw_dev->memdbg_no);
#endif
stw_tls_cleanup();
stw_dev = NULL;
}

View file

@ -28,6 +28,7 @@
#include "util/u_debug.h"
#include "stw_pixelformat.h"
#include "stw_public.h"
#include "stw_tls.h"
#define MAX_PIXELFORMATS 16
@ -35,8 +36,6 @@ static struct pixelformat_info pixelformats[MAX_PIXELFORMATS];
static uint pixelformat_count = 0;
static uint pixelformat_extended_count = 0;
static uint currentpixelformat = 0;
static void
add_standard_pixelformats(
@ -248,7 +247,7 @@ int
stw_pixelformat_get(
HDC hdc )
{
return currentpixelformat;
return stw_tls_get_data()->currentPixelFormat;
}
@ -267,8 +266,8 @@ stw_pixelformat_set(
if (index >= count)
return FALSE;
currentpixelformat = iPixelFormat;
stw_tls_get_data()->currentPixelFormat = iPixelFormat;
/* Some applications mistakenly use the undocumented wglSetPixelFormat
* function instead of SetPixelFormat, so we call SetPixelFormat here to
* avoid opengl32.dll's wglCreateContext to fail */

View file

@ -0,0 +1,101 @@
/**************************************************************************
*
* Copyright 2009 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#include <windows.h>
#include "pipe/p_compiler.h"
#include "util/u_memory.h"
#include "stw_tls.h"
static DWORD tlsIndex = TLS_OUT_OF_INDEXES;
boolean
stw_tls_init(void)
{
tlsIndex = TlsAlloc();
if (tlsIndex == TLS_OUT_OF_INDEXES) {
return FALSE;
}
return TRUE;
}
boolean
stw_tls_init_thread(void)
{
struct stw_tls_data *data;
if (tlsIndex == TLS_OUT_OF_INDEXES) {
return FALSE;
}
data = MALLOC(sizeof(*data));
if (!data) {
return FALSE;
}
data->currentPixelFormat = 0;
data->currentDC = NULL;
data->currentGLRC = 0;
TlsSetValue(tlsIndex, data);
return TRUE;
}
void
stw_tls_cleanup_thread(void)
{
struct stw_tls_data *data;
if (tlsIndex == TLS_OUT_OF_INDEXES) {
return;
}
data = (struct stw_tls_data *) TlsGetValue(tlsIndex);
TlsSetValue(tlsIndex, NULL);
FREE(data);
}
void
stw_tls_cleanup(void)
{
if (tlsIndex != TLS_OUT_OF_INDEXES) {
TlsFree(tlsIndex);
tlsIndex = TLS_OUT_OF_INDEXES;
}
}
struct stw_tls_data *
stw_tls_get_data(void)
{
if (tlsIndex == TLS_OUT_OF_INDEXES) {
return NULL;
}
return (struct stw_tls_data *) TlsGetValue(tlsIndex);
}

View file

@ -0,0 +1,53 @@
/**************************************************************************
*
* Copyright 2009 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#ifndef STW_TLS_H
#define STW_TLS_H
struct stw_tls_data
{
uint currentPixelFormat;
HDC currentDC;
UINT_PTR currentGLRC;
};
boolean
stw_tls_init(void);
boolean
stw_tls_init_thread(void);
void
stw_tls_cleanup_thread(void);
void
stw_tls_cleanup(void);
struct stw_tls_data *
stw_tls_get_data(void);
#endif /* STW_TLS_H */

View file

@ -53,6 +53,12 @@ struct stw_winsys
boolean
st_init(const struct stw_winsys *stw_winsys);
boolean
st_init_thread(void);
void
st_cleanup_thread(void);
void
st_cleanup(void);