Commit d89f7f25 authored by Alexandre Julliard's avatar Alexandre Julliard

opengl32: Move checks of the context thread id to opengl32.

parent 0045ec9d
...@@ -682,9 +682,8 @@ static struct wgl_context *nulldrv_wglCreateContextAttribsARB( HDC hdc, struct w ...@@ -682,9 +682,8 @@ static struct wgl_context *nulldrv_wglCreateContextAttribsARB( HDC hdc, struct w
return 0; 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) static HDC nulldrv_wglGetCurrentDC(void)
......
...@@ -86,6 +86,7 @@ extern BOOL WINAPI GdiSwapBuffers( HDC hdc ); ...@@ -86,6 +86,7 @@ extern BOOL WINAPI GdiSwapBuffers( HDC hdc );
struct wgl_handle struct wgl_handle
{ {
UINT handle; UINT handle;
DWORD tid;
struct wgl_context *context; struct wgl_context *context;
}; };
...@@ -110,6 +111,13 @@ static inline HGLRC next_handle( struct wgl_handle *ptr ) ...@@ -110,6 +111,13 @@ static inline HGLRC next_handle( struct wgl_handle *ptr )
return ULongToHandle( ptr->handle ); 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 ) static struct wgl_handle *get_handle_ptr( HGLRC handle )
{ {
unsigned int index = LOWORD( handle ); unsigned int index = LOWORD( handle );
...@@ -191,12 +199,15 @@ BOOL WINAPI wglDeleteContext(HGLRC hglrc) ...@@ -191,12 +199,15 @@ BOOL WINAPI wglDeleteContext(HGLRC hglrc)
struct wgl_handle *ptr = get_handle_ptr( hglrc ); struct wgl_handle *ptr = get_handle_ptr( hglrc );
if (!ptr) return FALSE; 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 ); release_handle_ptr( ptr );
return FALSE; return FALSE;
} }
if (hglrc == NtCurrentTeb()->glCurrentRC) wglMakeCurrent( 0, 0 );
wgl_driver->p_wglDeleteContext( ptr->context );
free_handle_ptr( ptr ); free_handle_ptr( ptr );
return TRUE; return TRUE;
} }
...@@ -206,18 +217,32 @@ BOOL WINAPI wglDeleteContext(HGLRC hglrc) ...@@ -206,18 +217,32 @@ BOOL WINAPI wglDeleteContext(HGLRC hglrc)
*/ */
BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC hglrc) BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC hglrc)
{ {
struct wgl_handle *ptr = NULL; BOOL ret = TRUE;
BOOL ret; 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 ); 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; return ret;
} }
...@@ -247,13 +272,27 @@ static HGLRC WINAPI wglCreateContextAttribsARB( HDC hdc, HGLRC share, const int ...@@ -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 ) static BOOL WINAPI wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, HGLRC hglrc )
{ {
struct wgl_handle *ptr = NULL; BOOL ret = TRUE;
BOOL ret; struct wgl_handle *ptr, *prev = get_current_handle_ptr();
if (hglrc && !(ptr = get_handle_ptr( hglrc ))) return FALSE; if (hglrc)
ret = wgl_driver->p_wglMakeContextCurrentARB( draw_hdc, read_hdc, ptr ? ptr->context : NULL ); {
if (ret) NtCurrentTeb()->glCurrentRC = hglrc; if (!(ptr = get_handle_ptr( hglrc ))) return FALSE;
release_handle_ptr( ptr ); 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; return ret;
} }
......
...@@ -115,7 +115,6 @@ struct wgl_context ...@@ -115,7 +115,6 @@ struct wgl_context
HDC hdc; HDC hdc;
BOOL has_been_current; BOOL has_been_current;
BOOL sharing; BOOL sharing;
DWORD tid;
BOOL gl3_context; BOOL gl3_context;
XVisualInfo *vis; XVisualInfo *vis;
WineGLPixelFormat *fmt; WineGLPixelFormat *fmt;
...@@ -1453,18 +1452,10 @@ static struct wgl_context *glxdrv_wglCreateContext( HDC hdc ) ...@@ -1453,18 +1452,10 @@ static struct wgl_context *glxdrv_wglCreateContext( HDC hdc )
/*********************************************************************** /***********************************************************************
* glxdrv_wglDeleteContext * glxdrv_wglDeleteContext
*/ */
static BOOL glxdrv_wglDeleteContext(struct wgl_context *ctx) static void glxdrv_wglDeleteContext(struct wgl_context *ctx)
{ {
TRACE("(%p)\n", 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(); wine_tsx11_lock();
list_remove( &ctx->entry ); list_remove( &ctx->entry );
if (ctx->ctx) pglXDestroyContext( gdi_display, ctx->ctx ); if (ctx->ctx) pglXDestroyContext( gdi_display, ctx->ctx );
...@@ -1474,7 +1465,6 @@ static BOOL glxdrv_wglDeleteContext(struct wgl_context *ctx) ...@@ -1474,7 +1465,6 @@ static BOOL glxdrv_wglDeleteContext(struct wgl_context *ctx)
wine_tsx11_unlock(); wine_tsx11_unlock();
HeapFree( GetProcessHeap(), 0, ctx ); HeapFree( GetProcessHeap(), 0, ctx );
return TRUE;
} }
/** /**
...@@ -1551,15 +1541,12 @@ static GLXPixmap get_context_pixmap( HDC hdc, struct wgl_context *ctx ) ...@@ -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) static BOOL glxdrv_wglMakeCurrent(HDC hdc, struct wgl_context *ctx)
{ {
BOOL ret; BOOL ret;
struct wgl_context *prev_ctx = NtCurrentTeb()->glContext;
struct x11drv_escape_get_drawable escape; struct x11drv_escape_get_drawable escape;
TRACE("(%p,%p)\n", hdc, ctx); TRACE("(%p,%p)\n", hdc, ctx);
if (!ctx) if (!ctx)
{ {
if (prev_ctx) prev_ctx->tid = 0;
wine_tsx11_lock(); wine_tsx11_lock();
ret = pglXMakeCurrent(gdi_display, None, NULL); ret = pglXMakeCurrent(gdi_display, None, NULL);
wine_tsx11_unlock(); wine_tsx11_unlock();
...@@ -1603,11 +1590,9 @@ static BOOL glxdrv_wglMakeCurrent(HDC hdc, struct wgl_context *ctx) ...@@ -1603,11 +1590,9 @@ static BOOL glxdrv_wglMakeCurrent(HDC hdc, struct wgl_context *ctx)
if (ret) if (ret)
{ {
if (prev_ctx) prev_ctx->tid = 0;
NtCurrentTeb()->glContext = ctx; NtCurrentTeb()->glContext = ctx;
ctx->has_been_current = TRUE; ctx->has_been_current = TRUE;
ctx->tid = GetCurrentThreadId();
ctx->hdc = hdc; ctx->hdc = hdc;
ctx->read_hdc = hdc; ctx->read_hdc = hdc;
ctx->drawables[0] = escape.drawable; ctx->drawables[0] = escape.drawable;
...@@ -1629,7 +1614,6 @@ static BOOL glxdrv_wglMakeCurrent(HDC hdc, struct wgl_context *ctx) ...@@ -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 ) 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; struct x11drv_escape_get_drawable escape_draw, escape_read;
BOOL ret; BOOL ret;
...@@ -1637,8 +1621,6 @@ static BOOL glxdrv_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct ...@@ -1637,8 +1621,6 @@ static BOOL glxdrv_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct
if (!ctx) if (!ctx)
{ {
if (prev_ctx) prev_ctx->tid = 0;
wine_tsx11_lock(); wine_tsx11_lock();
ret = pglXMakeCurrent(gdi_display, None, NULL); ret = pglXMakeCurrent(gdi_display, None, NULL);
wine_tsx11_unlock(); wine_tsx11_unlock();
...@@ -1673,10 +1655,7 @@ static BOOL glxdrv_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct ...@@ -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); ret = pglXMakeContextCurrent(gdi_display, escape_draw.drawable, escape_read.drawable, ctx->ctx);
if (ret) if (ret)
{ {
if (prev_ctx) prev_ctx->tid = 0;
ctx->has_been_current = TRUE; ctx->has_been_current = TRUE;
ctx->tid = GetCurrentThreadId();
ctx->hdc = draw_hdc; ctx->hdc = draw_hdc;
ctx->read_hdc = read_hdc; ctx->read_hdc = read_hdc;
ctx->drawables[0] = escape_draw.drawable; ctx->drawables[0] = escape_draw.drawable;
......
...@@ -234,7 +234,7 @@ struct wgl_funcs ...@@ -234,7 +234,7 @@ struct wgl_funcs
BOOL (*p_wglCopyContext)(struct wgl_context*,struct wgl_context*,UINT); BOOL (*p_wglCopyContext)(struct wgl_context*,struct wgl_context*,UINT);
struct wgl_context* (*p_wglCreateContext)(HDC); struct wgl_context* (*p_wglCreateContext)(HDC);
struct wgl_context* (*p_wglCreateContextAttribsARB)(HDC,struct wgl_context*,const int*); 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); HDC (*p_wglGetCurrentDC)(void);
PROC (*p_wglGetProcAddress)(LPCSTR); PROC (*p_wglGetProcAddress)(LPCSTR);
BOOL (*p_wglMakeContextCurrentARB)(HDC,HDC,struct wgl_context*); BOOL (*p_wglMakeContextCurrentARB)(HDC,HDC,struct wgl_context*);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment