From: Keith Whitwell Date: Wed, 28 Jan 2009 12:25:25 +0000 (+0000) Subject: wgl: move context functions to shared X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f17eb0b13c6a2e70746edd1d882bf71adec129fb;p=mesa.git wgl: move context functions to shared --- diff --git a/src/gallium/state_trackers/wgl/SConscript b/src/gallium/state_trackers/wgl/SConscript index 9516dc5a3c2..37eb650c87f 100644 --- a/src/gallium/state_trackers/wgl/SConscript +++ b/src/gallium/state_trackers/wgl/SConscript @@ -20,6 +20,7 @@ if env['platform'] in ['windows']: sources = [ 'icd/stw_icd.c', + 'shared/stw_context.c', 'shared/stw_device.c', 'shared/stw_framebuffer.c', 'shared/stw_pixelformat.c', @@ -27,8 +28,7 @@ if env['platform'] in ['windows']: 'wgl/stw_wgl_arbextensionsstring.c', 'wgl/stw_wgl_arbmultisample.c', 'wgl/stw_wgl_arbpixelformat.c', - #'wgl/stw_wgl.c', - 'wgl/stw_wgl_context.c', + 'wgl/stw_wgl.c', 'wgl/stw_wgl_getprocaddress.c', 'wgl/stw_wgl_pixelformat.c', 'wgl/stw_wgl_swapbuffers.c', diff --git a/src/gallium/state_trackers/wgl/icd/stw_icd.c b/src/gallium/state_trackers/wgl/icd/stw_icd.c index bf057eb83bd..94c6dfe1081 100644 --- a/src/gallium/state_trackers/wgl/icd/stw_icd.c +++ b/src/gallium/state_trackers/wgl/icd/stw_icd.c @@ -33,15 +33,18 @@ #include "pipe/p_debug.h" #include "shared/stw_device.h" +#include "shared/stw_context.h" #include "icd/stw_icd.h" #include "wgl/stw_wgl.h" static HGLRC -_drv_lookup_hglrc( DHGLRC dhglrc ) +lookup_hglrc( DHGLRC dhglrc ) { - if (dhglrc == 0 || dhglrc >= DRV_CONTEXT_MAX) + if (dhglrc == 0 || + dhglrc >= DRV_CONTEXT_MAX) return NULL; + return stw_dev->ctx_array[dhglrc - 1].hglrc; } @@ -51,9 +54,14 @@ DrvCopyContext( DHGLRC dhrcDest, UINT fuMask ) { - debug_printf( "%s\n", __FUNCTION__ ); - - return FALSE; + HGLRC src = lookup_hglrc( dhrcSource ); + HGLRC dst = lookup_hglrc( dhrcDest ); + + if (src == NULL || + dst == NULL) + return FALSE; + + return stw_wgl_copy_context( src, dst, fuMask ); } DHGLRC APIENTRY @@ -61,26 +69,23 @@ DrvCreateLayerContext( HDC hdc, INT iLayerPlane ) { - DHGLRC dhglrc = 0; - - if (iLayerPlane == 0) { - DWORD i; - - for (i = 0; i < DRV_CONTEXT_MAX; i++) { - if (stw_dev->ctx_array[i].hglrc == NULL) - break; - } - - if (i < DRV_CONTEXT_MAX) { - stw_dev->ctx_array[i].hglrc = wglCreateContext( hdc ); - if (stw_dev->ctx_array[i].hglrc != NULL) - dhglrc = i + 1; - } + DWORD i; + + for (i = 0; i < DRV_CONTEXT_MAX; i++) { + if (stw_dev->ctx_array[i].hglrc == NULL) + goto found_slot; } + + /* No slot available, fail: + */ + return 0; - debug_printf( "%s( 0x%p, %d ) = %u\n", __FUNCTION__, hdc, iLayerPlane, dhglrc ); +found_slot: + stw_dev->ctx_array[i].hglrc = stw_wgl_create_context( hdc, iLayerPlane ); + if (stw_dev->ctx_array[i].hglrc == NULL) + return 0; - return dhglrc; + return (DHGLRC) i + 1; } DHGLRC APIENTRY @@ -94,11 +99,11 @@ BOOL APIENTRY DrvDeleteContext( DHGLRC dhglrc ) { - HGLRC hglrc = _drv_lookup_hglrc( dhglrc ); + HGLRC hglrc = lookup_hglrc( dhglrc ); BOOL success = FALSE; if (hglrc != NULL) { - success = wglDeleteContext( hglrc ); + success = stw_wgl_delete_context( hglrc ); if (success) stw_dev->ctx_array[dhglrc - 1].hglrc = NULL; } @@ -132,7 +137,8 @@ DrvDescribePixelFormat( r = wglDescribePixelFormat( hdc, iPixelFormat, cjpfd, ppfd ); - debug_printf( "%s( 0x%p, %d, %u, 0x%p ) = %d\n", __FUNCTION__, hdc, iPixelFormat, cjpfd, ppfd, r ); + debug_printf( "%s( 0x%p, %d, %u, 0x%p ) = %d\n", + __FUNCTION__, hdc, iPixelFormat, cjpfd, ppfd, r ); return r; } @@ -181,7 +187,7 @@ DrvReleaseContext( BOOL success = FALSE; if (dhglrc == stw_dev->ctx_current) { - HGLRC hglrc = _drv_lookup_hglrc( dhglrc ); + HGLRC hglrc = lookup_hglrc( dhglrc ); if (hglrc != NULL) { success = wglMakeCurrent( NULL, NULL ); @@ -215,7 +221,7 @@ DrvSetContext( DHGLRC dhglrc, PFN_SETPROCTABLE pfnSetProcTable ) { - HGLRC hglrc = _drv_lookup_hglrc( dhglrc ); + HGLRC hglrc = lookup_hglrc( dhglrc ); GLDISPATCHTABLE *disp = &cpt.glDispatchTable; debug_printf( "%s( 0x%p, %u, 0x%p )\n", __FUNCTION__, hdc, dhglrc, pfnSetProcTable ); diff --git a/src/gallium/state_trackers/wgl/shared/stw_context.c b/src/gallium/state_trackers/wgl/shared/stw_context.c new file mode 100644 index 00000000000..b54e084230f --- /dev/null +++ b/src/gallium/state_trackers/wgl/shared/stw_context.c @@ -0,0 +1,288 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 + +#include "main/mtypes.h" +#include "main/context.h" +#include "pipe/p_compiler.h" +#include "pipe/p_context.h" +#include "state_tracker/st_context.h" +#include "state_tracker/st_public.h" +#include "shared/stw_device.h" +#include "shared/stw_winsys.h" +#include "shared/stw_framebuffer.h" +#include "shared/stw_pixelformat.h" +#include "wgl/stw_wgl_arbmultisample.h" +#include "stw_context.h" +//#include "stw_wgl.h" + +static struct wgl_context *ctx_head = NULL; + +static HDC current_hdc = NULL; +static HGLRC current_hrc = NULL; + +BOOL +stw_wgl_copy_context( + HGLRC hglrcSrc, + HGLRC hglrcDst, + UINT mask ) +{ + (void) hglrcSrc; + (void) hglrcDst; + (void) mask; + + return FALSE; +} + +HGLRC +stw_wgl_create_context( + HDC hdc, + int iLayerPlane ) +{ + uint pfi; + const struct pixelformat_info *pf; + struct wgl_context *ctx; + GLvisual *visual; + struct pipe_context *pipe; + + if (iLayerPlane != 0) + return NULL; + + pfi = wglGetPixelFormat( hdc ); + if (pfi == 0) + return NULL; + + pf = pixelformat_get_info( pfi - 1 ); + + ctx = CALLOC_STRUCT( wgl_context ); + if (ctx == NULL) + return NULL; + + ctx->hdc = hdc; + ctx->color_bits = GetDeviceCaps( ctx->hdc, BITSPIXEL ); + + /* Create visual based on flags + */ + visual = _mesa_create_visual( + GL_TRUE, + (pf->flags & PF_FLAG_DOUBLEBUFFER) ? GL_TRUE : GL_FALSE, + GL_FALSE, + pf->color.redbits, + pf->color.greenbits, + pf->color.bluebits, + pf->alpha.alphabits, + 0, + pf->depth.depthbits, + pf->depth.stencilbits, + 0, + 0, + 0, + 0, + (pf->flags & PF_FLAG_MULTISAMPLED) ? wgl_query_samples() : 0 ); + if (visual == NULL) { + FREE( ctx ); + return NULL; + } + + pipe = stw_dev->stw_winsys->create_context( stw_dev->screen ); + if (!pipe) { + _mesa_destroy_visual( visual ); + FREE( ctx ); + return NULL; + } + + assert(!pipe->priv); + pipe->priv = hdc; + + ctx->st = st_create_context( pipe, visual, NULL ); + if (ctx->st == NULL) { + pipe->destroy( pipe ); + _mesa_destroy_visual( visual ); + FREE( ctx ); + return NULL; + } + ctx->st->ctx->DriverCtx = ctx; + + ctx->next = ctx_head; + ctx_head = ctx; + + return (HGLRC) ctx; +} + + +BOOL +stw_wgl_delete_context( + HGLRC hglrc ) +{ + struct wgl_context **link = &ctx_head; + struct wgl_context *ctx = ctx_head; + + while (ctx != NULL) { + if (ctx == (struct wgl_context *) hglrc) { + GLcontext *glctx = ctx->st->ctx; + GET_CURRENT_CONTEXT( glcurctx ); + struct stw_framebuffer *fb; + + /* Unbind current if deleting current context. + */ + if (glcurctx == glctx) + st_make_current( NULL, NULL, NULL ); + + fb = framebuffer_from_hdc( ctx->hdc ); + if (fb) + framebuffer_destroy( fb ); + + if (WindowFromDC( ctx->hdc ) != NULL) + ReleaseDC( WindowFromDC( ctx->hdc ), ctx->hdc ); + + st_destroy_context( ctx->st ); + + *link = ctx->next; + FREE( ctx ); + return TRUE; + } + + link = &ctx->next; + ctx = ctx->next; + } + + return FALSE; +} + +/* Find the width and height of the window named by hdc. + */ +static void +get_window_size( HDC hdc, GLuint *width, GLuint *height ) +{ + if (WindowFromDC( hdc )) { + RECT rect; + + GetClientRect( WindowFromDC( hdc ), &rect ); + *width = rect.right - rect.left; + *height = rect.bottom - rect.top; + } + else { + *width = GetDeviceCaps( hdc, HORZRES ); + *height = GetDeviceCaps( hdc, VERTRES ); + } +} + +HGLRC +stw_wgl_get_current_context( void ) +{ + return current_hrc; +} + +HDC +stw_wgl_get_current_dc( void ) +{ + return current_hdc; +} + +BOOL +stw_wgl_make_current( + HDC hdc, + HGLRC hglrc ) +{ + struct wgl_context *ctx = ctx_head; + GET_CURRENT_CONTEXT( glcurctx ); + struct stw_framebuffer *fb; + GLuint width = 0; + GLuint height = 0; + + current_hdc = hdc; + current_hrc = hglrc; + + if (hdc == NULL || hglrc == NULL) { + st_make_current( NULL, NULL, NULL ); + return TRUE; + } + + while (ctx != NULL) { + if (ctx == (struct wgl_context *) hglrc) + break; + ctx = ctx->next; + } + if (ctx == NULL) + return FALSE; + + /* Return if already current. + */ + if (glcurctx != NULL) { + struct wgl_context *curctx = (struct wgl_context *) glcurctx->DriverCtx; + + if (curctx != NULL && curctx == ctx && ctx->hdc == hdc) + return TRUE; + } + + fb = framebuffer_from_hdc( hdc ); + + if (hdc != NULL) + get_window_size( hdc, &width, &height ); + + /* Lazy creation of framebuffers. + */ + if (fb == NULL && ctx != NULL && hdc != NULL) { + GLvisual *visual = &ctx->st->ctx->Visual; + + fb = framebuffer_create( hdc, visual, width, height ); + if (fb == NULL) + return FALSE; + + fb->dib_hDC = CreateCompatibleDC( hdc ); + fb->hbmDIB = NULL; + fb->pbPixels = NULL; + } + + if (ctx && fb) { + st_make_current( ctx->st, fb->stfb, fb->stfb ); + framebuffer_resize( fb, width, height ); + ctx->hdc = hdc; + ctx->st->pipe->priv = hdc; + } + else { + /* Detach */ + st_make_current( NULL, NULL, NULL ); + } + + return TRUE; +} + +struct wgl_context * +wgl_context_from_hdc( + HDC hdc ) +{ + struct wgl_context *ctx = ctx_head; + + while (ctx != NULL) { + if (ctx->hdc == hdc) + return ctx; + ctx = ctx->next; + } + return NULL; +} diff --git a/src/gallium/state_trackers/wgl/shared/stw_context.h b/src/gallium/state_trackers/wgl/shared/stw_context.h new file mode 100644 index 00000000000..b418e4e02a7 --- /dev/null +++ b/src/gallium/state_trackers/wgl/shared/stw_context.h @@ -0,0 +1,73 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 WGL_CONTEXT_H +#define WGL_CONTEXT_H + +#include + +struct st_context; + +struct wgl_context +{ + struct st_context *st; + HDC hdc; + DWORD color_bits; + struct wgl_context *next; +}; + +struct wgl_context * +wgl_context_from_hdc(HDC hdc ); + +////////////////// + + +BOOL stw_wgl_copy_context( HGLRC hglrcSrc, + HGLRC hglrcDst, + UINT mask ); + +HGLRC stw_wgl_create_context( HDC hdc, int iLayerPlane ); + +BOOL stw_wgl_delete_context( HGLRC hglrc ); + +HGLRC stw_wgl_get_current_context( void ); + +HDC stw_wgl_get_current_dc( void ); + +BOOL stw_wgl_make_current( HDC hdc, HGLRC hglrc ); + + + + + + + + + + + +#endif /* WGL_CONTEXT_H */ diff --git a/src/gallium/state_trackers/wgl/wgl/stw_wgl.c b/src/gallium/state_trackers/wgl/wgl/stw_wgl.c index 0528c369fc8..92fd3406586 100644 --- a/src/gallium/state_trackers/wgl/wgl/stw_wgl.c +++ b/src/gallium/state_trackers/wgl/wgl/stw_wgl.c @@ -28,6 +28,63 @@ #include #include "pipe/p_debug.h" +#include "shared/stw_context.h" +#include "stw_wgl.h" + + +WINGDIAPI BOOL APIENTRY +wglCopyContext( + HGLRC hglrcSrc, + HGLRC hglrcDst, + UINT mask ) +{ + return stw_wgl_copy_context( hglrcSrc, hglrcDst, mask ); +} + +WINGDIAPI HGLRC APIENTRY +wglCreateContext( + HDC hdc ) +{ + return (HGLRC) stw_wgl_create_context( hdc, 0 ); +} + +WINGDIAPI HGLRC APIENTRY +wglCreateLayerContext( + HDC hdc, + int iLayerPlane ) +{ + return (HGLRC) stw_wgl_create_context( hdc, iLayerPlane ); +} + +WINGDIAPI BOOL APIENTRY +wglDeleteContext( + HGLRC hglrc ) +{ + return stw_wgl_delete_context( hglrc ); +} + + +WINGDIAPI HGLRC APIENTRY +wglGetCurrentContext( VOID ) +{ + return stw_wgl_get_current_context(); +} + +WINGDIAPI HDC APIENTRY +wglGetCurrentDC( VOID ) +{ + return stw_wgl_get_current_dc(); +} + +WINGDIAPI BOOL APIENTRY +wglMakeCurrent( + HDC hdc, + HGLRC hglrc ) +{ + return stw_wgl_make_current( hdc, hglrc ); +} + + WINGDIAPI BOOL APIENTRY wglUseFontBitmapsA( diff --git a/src/gallium/state_trackers/wgl/wgl/stw_wgl_context.c b/src/gallium/state_trackers/wgl/wgl/stw_wgl_context.c deleted file mode 100644 index da4688bcb17..00000000000 --- a/src/gallium/state_trackers/wgl/wgl/stw_wgl_context.c +++ /dev/null @@ -1,296 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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 - -#include "main/mtypes.h" -#include "main/context.h" -#include "pipe/p_compiler.h" -#include "pipe/p_context.h" -#include "state_tracker/st_context.h" -#include "state_tracker/st_public.h" -#include "shared/stw_device.h" -#include "shared/stw_winsys.h" -#include "shared/stw_framebuffer.h" -#include "shared/stw_pixelformat.h" -#include "stw_wgl_arbmultisample.h" -#include "stw_wgl_context.h" -#include "stw_wgl.h" - -static struct wgl_context *ctx_head = NULL; - -static HDC current_hdc = NULL; -static HGLRC current_hrc = NULL; - -WINGDIAPI BOOL APIENTRY -wglCopyContext( - HGLRC hglrcSrc, - HGLRC hglrcDst, - UINT mask ) -{ - (void) hglrcSrc; - (void) hglrcDst; - (void) mask; - - return FALSE; -} - -WINGDIAPI HGLRC APIENTRY -wglCreateContext( - HDC hdc ) -{ - uint pfi; - const struct pixelformat_info *pf; - struct wgl_context *ctx; - GLvisual *visual; - struct pipe_context *pipe; - - pfi = wglGetPixelFormat( hdc ); - if (pfi == 0) - return NULL; - - pf = pixelformat_get_info( pfi - 1 ); - - ctx = CALLOC_STRUCT( wgl_context ); - if (ctx == NULL) - return NULL; - - ctx->hdc = hdc; - ctx->color_bits = GetDeviceCaps( ctx->hdc, BITSPIXEL ); - - /* Create visual based on flags - */ - visual = _mesa_create_visual( - GL_TRUE, - (pf->flags & PF_FLAG_DOUBLEBUFFER) ? GL_TRUE : GL_FALSE, - GL_FALSE, - pf->color.redbits, - pf->color.greenbits, - pf->color.bluebits, - pf->alpha.alphabits, - 0, - pf->depth.depthbits, - pf->depth.stencilbits, - 0, - 0, - 0, - 0, - (pf->flags & PF_FLAG_MULTISAMPLED) ? wgl_query_samples() : 0 ); - if (visual == NULL) { - FREE( ctx ); - return NULL; - } - - pipe = stw_dev->stw_winsys->create_context( stw_dev->screen ); - if (!pipe) { - _mesa_destroy_visual( visual ); - FREE( ctx ); - return NULL; - } - - assert(!pipe->priv); - pipe->priv = hdc; - - ctx->st = st_create_context( pipe, visual, NULL ); - if (ctx->st == NULL) { - pipe->destroy( pipe ); - _mesa_destroy_visual( visual ); - FREE( ctx ); - return NULL; - } - ctx->st->ctx->DriverCtx = ctx; - - ctx->next = ctx_head; - ctx_head = ctx; - - return (HGLRC) ctx; -} - -WINGDIAPI HGLRC APIENTRY -wglCreateLayerContext( - HDC hdc, - int iLayerPlane ) -{ - (void) hdc; - (void) iLayerPlane; - - return NULL; -} - -WINGDIAPI BOOL APIENTRY -wglDeleteContext( - HGLRC hglrc ) -{ - struct wgl_context **link = &ctx_head; - struct wgl_context *ctx = ctx_head; - - while (ctx != NULL) { - if (ctx == (struct wgl_context *) hglrc) { - GLcontext *glctx = ctx->st->ctx; - GET_CURRENT_CONTEXT( glcurctx ); - struct stw_framebuffer *fb; - - /* Unbind current if deleting current context. - */ - if (glcurctx == glctx) - st_make_current( NULL, NULL, NULL ); - - fb = framebuffer_from_hdc( ctx->hdc ); - if (fb) - framebuffer_destroy( fb ); - - if (WindowFromDC( ctx->hdc ) != NULL) - ReleaseDC( WindowFromDC( ctx->hdc ), ctx->hdc ); - - st_destroy_context( ctx->st ); - - *link = ctx->next; - FREE( ctx ); - return TRUE; - } - - link = &ctx->next; - ctx = ctx->next; - } - - return FALSE; -} - -/* Find the width and height of the window named by hdc. - */ -static void -get_window_size( HDC hdc, GLuint *width, GLuint *height ) -{ - if (WindowFromDC( hdc )) { - RECT rect; - - GetClientRect( WindowFromDC( hdc ), &rect ); - *width = rect.right - rect.left; - *height = rect.bottom - rect.top; - } - else { - *width = GetDeviceCaps( hdc, HORZRES ); - *height = GetDeviceCaps( hdc, VERTRES ); - } -} - -WINGDIAPI HGLRC APIENTRY -wglGetCurrentContext( VOID ) -{ - return current_hrc; -} - -WINGDIAPI HDC APIENTRY -wglGetCurrentDC( VOID ) -{ - return current_hdc; -} - -WINGDIAPI BOOL APIENTRY -wglMakeCurrent( - HDC hdc, - HGLRC hglrc ) -{ - struct wgl_context *ctx = ctx_head; - GET_CURRENT_CONTEXT( glcurctx ); - struct stw_framebuffer *fb; - GLuint width = 0; - GLuint height = 0; - - current_hdc = hdc; - current_hrc = hglrc; - - if (hdc == NULL || hglrc == NULL) { - st_make_current( NULL, NULL, NULL ); - return TRUE; - } - - while (ctx != NULL) { - if (ctx == (struct wgl_context *) hglrc) - break; - ctx = ctx->next; - } - if (ctx == NULL) - return FALSE; - - /* Return if already current. - */ - if (glcurctx != NULL) { - struct wgl_context *curctx = (struct wgl_context *) glcurctx->DriverCtx; - - if (curctx != NULL && curctx == ctx && ctx->hdc == hdc) - return TRUE; - } - - fb = framebuffer_from_hdc( hdc ); - - if (hdc != NULL) - get_window_size( hdc, &width, &height ); - - /* Lazy creation of framebuffers. - */ - if (fb == NULL && ctx != NULL && hdc != NULL) { - GLvisual *visual = &ctx->st->ctx->Visual; - - fb = framebuffer_create( hdc, visual, width, height ); - if (fb == NULL) - return FALSE; - - fb->dib_hDC = CreateCompatibleDC( hdc ); - fb->hbmDIB = NULL; - fb->pbPixels = NULL; - } - - if (ctx && fb) { - st_make_current( ctx->st, fb->stfb, fb->stfb ); - framebuffer_resize( fb, width, height ); - ctx->hdc = hdc; - ctx->st->pipe->priv = hdc; - } - else { - /* Detach */ - st_make_current( NULL, NULL, NULL ); - } - - return TRUE; -} - -struct wgl_context * -wgl_context_from_hdc( - HDC hdc ) -{ - struct wgl_context *ctx = ctx_head; - - while (ctx != NULL) { - if (ctx->hdc == hdc) - return ctx; - ctx = ctx->next; - } - return NULL; -} - -#include "stw_wgl.c" diff --git a/src/gallium/state_trackers/wgl/wgl/stw_wgl_context.h b/src/gallium/state_trackers/wgl/wgl/stw_wgl_context.h deleted file mode 100644 index d87b3bdce23..00000000000 --- a/src/gallium/state_trackers/wgl/wgl/stw_wgl_context.h +++ /dev/null @@ -1,46 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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 WGL_CONTEXT_H -#define WGL_CONTEXT_H - -#include - -struct st_context; - -struct wgl_context -{ - struct st_context *st; - HDC hdc; - DWORD color_bits; - struct wgl_context *next; -}; - -struct wgl_context * -wgl_context_from_hdc(HDC hdc ); - -#endif /* WGL_CONTEXT_H */