Alexandre Julliard : opengl32: Move checks of the context thread id to opengl32.
Alexandre Julliard
julliard at winehq.org
Fri Jun 29 14:24:28 CDT 2012
Module: wine
Branch: master
Commit: d89f7f25631850be571ca1a93854d048e9e7c776
URL: http://source.winehq.org/git/wine.git/?a=commit;h=d89f7f25631850be571ca1a93854d048e9e7c776
Author: Alexandre Julliard <julliard at winehq.org>
Date: Fri Jun 29 14:13:13 2012 +0200
opengl32: Move checks of the context thread id to opengl32.
---
dlls/gdi32/driver.c | 3 +-
dlls/opengl32/wgl.c | 71 ++++++++++++++++++++++++++++++++++----------
dlls/winex11.drv/opengl.c | 23 +--------------
include/wine/gdi_driver.h | 2 +-
4 files changed, 58 insertions(+), 41 deletions(-)
diff --git a/dlls/gdi32/driver.c b/dlls/gdi32/driver.c
index 2b62c46..1dfdbb1 100644
--- a/dlls/gdi32/driver.c
+++ b/dlls/gdi32/driver.c
@@ -682,9 +682,8 @@ static struct wgl_context *nulldrv_wglCreateContextAttribsARB( HDC hdc, struct w
return 0;
}
-static BOOL nulldrv_wglDeleteContext( struct wgl_context *context )
+static void nulldrv_wglDeleteContext( struct wgl_context *context )
{
- return FALSE;
}
static HDC nulldrv_wglGetCurrentDC(void)
diff --git a/dlls/opengl32/wgl.c b/dlls/opengl32/wgl.c
index abd38e1..6906b56 100644
--- a/dlls/opengl32/wgl.c
+++ b/dlls/opengl32/wgl.c
@@ -86,6 +86,7 @@ extern BOOL WINAPI GdiSwapBuffers( HDC hdc );
struct wgl_handle
{
UINT handle;
+ DWORD tid;
struct wgl_context *context;
};
@@ -110,6 +111,13 @@ static inline HGLRC next_handle( struct wgl_handle *ptr )
return ULongToHandle( ptr->handle );
}
+/* the current handle is assumed valid and doesn't need locking */
+static inline struct wgl_handle *get_current_handle_ptr(void)
+{
+ if (!NtCurrentTeb()->glCurrentRC) return NULL;
+ return &wgl_handles[LOWORD(NtCurrentTeb()->glCurrentRC)];
+}
+
static struct wgl_handle *get_handle_ptr( HGLRC handle )
{
unsigned int index = LOWORD( handle );
@@ -191,12 +199,15 @@ BOOL WINAPI wglDeleteContext(HGLRC hglrc)
struct wgl_handle *ptr = get_handle_ptr( hglrc );
if (!ptr) return FALSE;
- if (hglrc == NtCurrentTeb()->glCurrentRC) wglMakeCurrent( 0, 0 );
- if (!wgl_driver->p_wglDeleteContext( ptr->context ))
+
+ if (ptr->tid && ptr->tid != GetCurrentThreadId())
{
+ SetLastError( ERROR_BUSY );
release_handle_ptr( ptr );
return FALSE;
}
+ if (hglrc == NtCurrentTeb()->glCurrentRC) wglMakeCurrent( 0, 0 );
+ wgl_driver->p_wglDeleteContext( ptr->context );
free_handle_ptr( ptr );
return TRUE;
}
@@ -206,18 +217,32 @@ BOOL WINAPI wglDeleteContext(HGLRC hglrc)
*/
BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC hglrc)
{
- struct wgl_handle *ptr = NULL;
- BOOL ret;
+ BOOL ret = TRUE;
+ struct wgl_handle *ptr, *prev = get_current_handle_ptr();
- if (!hglrc && !hdc && !NtCurrentTeb()->glCurrentRC)
+ if (hglrc)
+ {
+ if (!(ptr = get_handle_ptr( hglrc ))) return FALSE;
+ ret = wgl_driver->p_wglMakeCurrent( hdc, ptr->context );
+ if (ret)
+ {
+ if (prev) prev->tid = 0;
+ ptr->tid = GetCurrentThreadId();
+ NtCurrentTeb()->glCurrentRC = hglrc;
+ }
+ release_handle_ptr( ptr );
+ }
+ else if (prev)
+ {
+ if (!wgl_driver->p_wglMakeCurrent( 0, NULL )) return FALSE;
+ prev->tid = 0;
+ NtCurrentTeb()->glCurrentRC = 0;
+ }
+ else if (!hdc)
{
SetLastError( ERROR_INVALID_HANDLE );
- return FALSE;
+ ret = FALSE;
}
- if (hglrc && !(ptr = get_handle_ptr( hglrc ))) return FALSE;
- ret = wgl_driver->p_wglMakeCurrent( hdc, ptr ? ptr->context : NULL );
- if (ret) NtCurrentTeb()->glCurrentRC = hglrc;
- release_handle_ptr( ptr );
return ret;
}
@@ -247,13 +272,27 @@ static HGLRC WINAPI wglCreateContextAttribsARB( HDC hdc, HGLRC share, const int
*/
static BOOL WINAPI wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, HGLRC hglrc )
{
- struct wgl_handle *ptr = NULL;
- BOOL ret;
+ BOOL ret = TRUE;
+ struct wgl_handle *ptr, *prev = get_current_handle_ptr();
- if (hglrc && !(ptr = get_handle_ptr( hglrc ))) return FALSE;
- ret = wgl_driver->p_wglMakeContextCurrentARB( draw_hdc, read_hdc, ptr ? ptr->context : NULL );
- if (ret) NtCurrentTeb()->glCurrentRC = hglrc;
- release_handle_ptr( ptr );
+ if (hglrc)
+ {
+ if (!(ptr = get_handle_ptr( hglrc ))) return FALSE;
+ ret = wgl_driver->p_wglMakeContextCurrentARB( draw_hdc, read_hdc, ptr->context );
+ if (ret)
+ {
+ if (prev) prev->tid = 0;
+ ptr->tid = GetCurrentThreadId();
+ NtCurrentTeb()->glCurrentRC = hglrc;
+ }
+ release_handle_ptr( ptr );
+ }
+ else if (prev)
+ {
+ if (!wgl_driver->p_wglMakeCurrent( 0, NULL )) return FALSE;
+ prev->tid = 0;
+ NtCurrentTeb()->glCurrentRC = 0;
+ }
return ret;
}
diff --git a/dlls/winex11.drv/opengl.c b/dlls/winex11.drv/opengl.c
index e87fe5d..c278c46 100644
--- a/dlls/winex11.drv/opengl.c
+++ b/dlls/winex11.drv/opengl.c
@@ -115,7 +115,6 @@ struct wgl_context
HDC hdc;
BOOL has_been_current;
BOOL sharing;
- DWORD tid;
BOOL gl3_context;
XVisualInfo *vis;
WineGLPixelFormat *fmt;
@@ -1453,18 +1452,10 @@ static struct wgl_context *glxdrv_wglCreateContext( HDC hdc )
/***********************************************************************
* glxdrv_wglDeleteContext
*/
-static BOOL glxdrv_wglDeleteContext(struct wgl_context *ctx)
+static void glxdrv_wglDeleteContext(struct wgl_context *ctx)
{
TRACE("(%p)\n", ctx);
- /* WGL doesn't allow deletion of a context which is current in another thread */
- if (ctx->tid != 0 && ctx->tid != GetCurrentThreadId())
- {
- TRACE("Cannot delete context=%p because it is current in another thread.\n", ctx);
- SetLastError(ERROR_BUSY);
- return FALSE;
- }
-
wine_tsx11_lock();
list_remove( &ctx->entry );
if (ctx->ctx) pglXDestroyContext( gdi_display, ctx->ctx );
@@ -1474,7 +1465,6 @@ static BOOL glxdrv_wglDeleteContext(struct wgl_context *ctx)
wine_tsx11_unlock();
HeapFree( GetProcessHeap(), 0, ctx );
- return TRUE;
}
/**
@@ -1551,15 +1541,12 @@ static GLXPixmap get_context_pixmap( HDC hdc, struct wgl_context *ctx )
static BOOL glxdrv_wglMakeCurrent(HDC hdc, struct wgl_context *ctx)
{
BOOL ret;
- struct wgl_context *prev_ctx = NtCurrentTeb()->glContext;
struct x11drv_escape_get_drawable escape;
TRACE("(%p,%p)\n", hdc, ctx);
if (!ctx)
{
- if (prev_ctx) prev_ctx->tid = 0;
-
wine_tsx11_lock();
ret = pglXMakeCurrent(gdi_display, None, NULL);
wine_tsx11_unlock();
@@ -1603,11 +1590,9 @@ static BOOL glxdrv_wglMakeCurrent(HDC hdc, struct wgl_context *ctx)
if (ret)
{
- if (prev_ctx) prev_ctx->tid = 0;
NtCurrentTeb()->glContext = ctx;
ctx->has_been_current = TRUE;
- ctx->tid = GetCurrentThreadId();
ctx->hdc = hdc;
ctx->read_hdc = hdc;
ctx->drawables[0] = escape.drawable;
@@ -1629,7 +1614,6 @@ static BOOL glxdrv_wglMakeCurrent(HDC hdc, struct wgl_context *ctx)
*/
static BOOL glxdrv_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct wgl_context *ctx )
{
- struct wgl_context *prev_ctx = NtCurrentTeb()->glContext;
struct x11drv_escape_get_drawable escape_draw, escape_read;
BOOL ret;
@@ -1637,8 +1621,6 @@ static BOOL glxdrv_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct
if (!ctx)
{
- if (prev_ctx) prev_ctx->tid = 0;
-
wine_tsx11_lock();
ret = pglXMakeCurrent(gdi_display, None, NULL);
wine_tsx11_unlock();
@@ -1673,10 +1655,7 @@ static BOOL glxdrv_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct
ret = pglXMakeContextCurrent(gdi_display, escape_draw.drawable, escape_read.drawable, ctx->ctx);
if (ret)
{
- if (prev_ctx) prev_ctx->tid = 0;
-
ctx->has_been_current = TRUE;
- ctx->tid = GetCurrentThreadId();
ctx->hdc = draw_hdc;
ctx->read_hdc = read_hdc;
ctx->drawables[0] = escape_draw.drawable;
diff --git a/include/wine/gdi_driver.h b/include/wine/gdi_driver.h
index 4626371..22214f2 100644
--- a/include/wine/gdi_driver.h
+++ b/include/wine/gdi_driver.h
@@ -234,7 +234,7 @@ struct wgl_funcs
BOOL (*p_wglCopyContext)(struct wgl_context*,struct wgl_context*,UINT);
struct wgl_context* (*p_wglCreateContext)(HDC);
struct wgl_context* (*p_wglCreateContextAttribsARB)(HDC,struct wgl_context*,const int*);
- BOOL (*p_wglDeleteContext)(struct wgl_context*);
+ void (*p_wglDeleteContext)(struct wgl_context*);
HDC (*p_wglGetCurrentDC)(void);
PROC (*p_wglGetProcAddress)(LPCSTR);
BOOL (*p_wglMakeContextCurrentARB)(HDC,HDC,struct wgl_context*);
More information about the wine-cvs
mailing list