opengl32: Move checks of the context thread id to opengl32.
This commit is contained in:
parent
0045ec9dfb
commit
d89f7f2563
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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*);
|
||||
|
|
Loading…
Reference in New Issue