diff options
Diffstat (limited to 'src/gallium/state_trackers/wgl')
18 files changed, 590 insertions, 755 deletions
diff --git a/src/gallium/state_trackers/wgl/SConscript b/src/gallium/state_trackers/wgl/SConscript index 038a7a31b32..61fd8bfc0c8 100644 --- a/src/gallium/state_trackers/wgl/SConscript +++ b/src/gallium/state_trackers/wgl/SConscript @@ -26,7 +26,6 @@ if env['platform'] in ['windows']: 'shared/stw_device.c', 'shared/stw_framebuffer.c', 'shared/stw_pixelformat.c', - 'shared/stw_quirks.c', 'shared/stw_arbextensionsstring.c', 'shared/stw_getprocaddress.c', 'shared/stw_arbpixelformat.c', diff --git a/src/gallium/state_trackers/wgl/icd/stw_icd.h b/src/gallium/state_trackers/wgl/icd/stw_icd.h index 8e676fb5b74..cbc1a665481 100644 --- a/src/gallium/state_trackers/wgl/icd/stw_icd.h +++ b/src/gallium/state_trackers/wgl/icd/stw_icd.h @@ -25,8 +25,8 @@ * **************************************************************************/ -#ifndef DRV_H -#define DRV_H +#ifndef STW_ICD_H +#define STW_ICD_H #include <windows.h> @@ -486,4 +486,4 @@ BOOL APIENTRY DrvValidateVersion( ULONG ulVersion ); -#endif /* DRV_H */ +#endif /* STW_ICD_H */ diff --git a/src/gallium/state_trackers/wgl/shared/stw_arbextensionsstring.c b/src/gallium/state_trackers/wgl/shared/stw_arbextensionsstring.c index b3934cb4643..cd9fe93eeec 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_arbextensionsstring.c +++ b/src/gallium/state_trackers/wgl/shared/stw_arbextensionsstring.c @@ -27,7 +27,11 @@ #include <windows.h> -#include "stw_arbextensionsstring.h" +#define WGL_WGLEXT_PROTOTYPES + +#include <GL/gl.h> +#include <GL/wglext.h> + WINGDIAPI const char * APIENTRY wglGetExtensionsStringARB( diff --git a/src/gallium/state_trackers/wgl/shared/stw_arbextensionsstring.h b/src/gallium/state_trackers/wgl/shared/stw_arbextensionsstring.h deleted file mode 100644 index a0e4c5d98e8..00000000000 --- a/src/gallium/state_trackers/wgl/shared/stw_arbextensionsstring.h +++ /dev/null @@ -1,35 +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_ARBEXTENSIONSSTRING_H -#define WGL_ARBEXTENSIONSSTRING_H - -WINGDIAPI const char * APIENTRY -wglGetExtensionsStringARB( - HDC hdc ); - -#endif /* WGL_ARBEXTENSIONSSTRING_H */ diff --git a/src/gallium/state_trackers/wgl/shared/stw_arbpixelformat.c b/src/gallium/state_trackers/wgl/shared/stw_arbpixelformat.c index f5636354202..0e2d4076993 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_arbpixelformat.c +++ b/src/gallium/state_trackers/wgl/shared/stw_arbpixelformat.c @@ -25,75 +25,30 @@ * **************************************************************************/ +/** + * @file + * + * WGL_ARB_pixel_format extension implementation. + * + * @sa http://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt + */ + + #include <windows.h> +#define WGL_WGLEXT_PROTOTYPES + +#include <GL/gl.h> +#include <GL/wglext.h> + #include "pipe/p_compiler.h" #include "util/u_memory.h" #include "stw_public.h" #include "stw_pixelformat.h" -#include "stw_arbpixelformat.h" - -#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 -#define WGL_DRAW_TO_WINDOW_ARB 0x2001 -#define WGL_DRAW_TO_BITMAP_ARB 0x2002 -#define WGL_ACCELERATION_ARB 0x2003 -#define WGL_NEED_PALETTE_ARB 0x2004 -#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005 -#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006 -#define WGL_SWAP_METHOD_ARB 0x2007 -#define WGL_NUMBER_OVERLAYS_ARB 0x2008 -#define WGL_NUMBER_UNDERLAYS_ARB 0x2009 -#define WGL_TRANSPARENT_ARB 0x200A -#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037 -#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038 -#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039 -#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A -#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B -#define WGL_SHARE_DEPTH_ARB 0x200C -#define WGL_SHARE_STENCIL_ARB 0x200D -#define WGL_SHARE_ACCUM_ARB 0x200E -#define WGL_SUPPORT_GDI_ARB 0x200F -#define WGL_SUPPORT_OPENGL_ARB 0x2010 -#define WGL_DOUBLE_BUFFER_ARB 0x2011 -#define WGL_STEREO_ARB 0x2012 -#define WGL_PIXEL_TYPE_ARB 0x2013 -#define WGL_COLOR_BITS_ARB 0x2014 -#define WGL_RED_BITS_ARB 0x2015 -#define WGL_RED_SHIFT_ARB 0x2016 -#define WGL_GREEN_BITS_ARB 0x2017 -#define WGL_GREEN_SHIFT_ARB 0x2018 -#define WGL_BLUE_BITS_ARB 0x2019 -#define WGL_BLUE_SHIFT_ARB 0x201A -#define WGL_ALPHA_BITS_ARB 0x201B -#define WGL_ALPHA_SHIFT_ARB 0x201C -#define WGL_ACCUM_BITS_ARB 0x201D -#define WGL_ACCUM_RED_BITS_ARB 0x201E -#define WGL_ACCUM_GREEN_BITS_ARB 0x201F -#define WGL_ACCUM_BLUE_BITS_ARB 0x2020 -#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021 -#define WGL_DEPTH_BITS_ARB 0x2022 -#define WGL_STENCIL_BITS_ARB 0x2023 -#define WGL_AUX_BUFFERS_ARB 0x2024 - -#define WGL_NO_ACCELERATION_ARB 0x2025 -#define WGL_GENERIC_ACCELERATION_ARB 0x2026 -#define WGL_FULL_ACCELERATION_ARB 0x2027 - -#define WGL_SWAP_EXCHANGE_ARB 0x2028 -#define WGL_SWAP_COPY_ARB 0x2029 -#define WGL_SWAP_UNDEFINED_ARB 0x202A - -#define WGL_TYPE_RGBA_ARB 0x202B -#define WGL_TYPE_COLORINDEX_ARB 0x202C - -/* From arb_multisample: - */ -#define WGL_SAMPLE_BUFFERS_ARB 0x2041 -#define WGL_SAMPLES_ARB 0x2042 static boolean -query_attrib( +stw_query_attrib( int iPixelFormat, int iLayerPlane, int attrib, @@ -101,9 +56,9 @@ query_attrib( { uint count; uint index; - const struct pixelformat_info *pf; + const struct stw_pixelformat_info *pfi; - count = pixelformat_get_extended_count(); + count = stw_pixelformat_get_extended_count(); if (attrib == WGL_NUMBER_PIXEL_FORMATS_ARB) { *pvalue = (int) count; @@ -114,30 +69,27 @@ query_attrib( if (index >= count) return FALSE; - pf = pixelformat_get_info( index ); + pfi = stw_pixelformat_get_info( index ); switch (attrib) { case WGL_DRAW_TO_WINDOW_ARB: - *pvalue = TRUE; + *pvalue = pfi->pfd.dwFlags & PFD_DRAW_TO_WINDOW ? TRUE : FALSE; return TRUE; case WGL_DRAW_TO_BITMAP_ARB: - *pvalue = FALSE; + *pvalue = pfi->pfd.dwFlags & PFD_DRAW_TO_BITMAP ? TRUE : FALSE; return TRUE; case WGL_NEED_PALETTE_ARB: - *pvalue = FALSE; + *pvalue = pfi->pfd.dwFlags & PFD_NEED_PALETTE ? TRUE : FALSE; return TRUE; case WGL_NEED_SYSTEM_PALETTE_ARB: - *pvalue = FALSE; + *pvalue = pfi->pfd.dwFlags & PFD_NEED_SYSTEM_PALETTE ? TRUE : FALSE; return TRUE; case WGL_SWAP_METHOD_ARB: - if (pf->flags & PF_FLAG_DOUBLEBUFFER) - *pvalue = WGL_SWAP_COPY_ARB; - else - *pvalue = WGL_SWAP_UNDEFINED_ARB; + *pvalue = pfi->pfd.dwFlags & PFD_SWAP_COPY ? WGL_SWAP_COPY_ARB : WGL_SWAP_UNDEFINED_ARB; return TRUE; case WGL_SWAP_LAYER_BUFFERS_ARB: @@ -179,96 +131,108 @@ query_attrib( break; case WGL_SUPPORT_GDI_ARB: - *pvalue = FALSE; + *pvalue = pfi->pfd.dwFlags & PFD_SUPPORT_GDI ? TRUE : FALSE; break; case WGL_SUPPORT_OPENGL_ARB: - *pvalue = TRUE; + *pvalue = pfi->pfd.dwFlags & PFD_SUPPORT_OPENGL ? TRUE : FALSE; break; case WGL_DOUBLE_BUFFER_ARB: - if (pf->flags & PF_FLAG_DOUBLEBUFFER) - *pvalue = TRUE; - else - *pvalue = FALSE; + *pvalue = pfi->pfd.dwFlags & PFD_DOUBLEBUFFER ? TRUE : FALSE; break; case WGL_STEREO_ARB: - *pvalue = FALSE; + *pvalue = pfi->pfd.dwFlags & PFD_STEREO ? TRUE : FALSE; break; case WGL_PIXEL_TYPE_ARB: - *pvalue = WGL_TYPE_RGBA_ARB; + switch (pfi->pfd.iPixelType) { + case PFD_TYPE_RGBA: + *pvalue = WGL_TYPE_RGBA_ARB; + break; + case PFD_TYPE_COLORINDEX: + *pvalue = WGL_TYPE_COLORINDEX_ARB; + break; + default: + return FALSE; + } break; case WGL_COLOR_BITS_ARB: - *pvalue = (int) (pf->color.redbits + pf->color.greenbits + pf->color.bluebits); + *pvalue = pfi->pfd.cColorBits; break; case WGL_RED_BITS_ARB: - *pvalue = (int) pf->color.redbits; + *pvalue = pfi->pfd.cRedBits; break; case WGL_RED_SHIFT_ARB: - *pvalue = (int) pf->color.redshift; + *pvalue = pfi->pfd.cRedShift; break; case WGL_GREEN_BITS_ARB: - *pvalue = (int) pf->color.greenbits; + *pvalue = pfi->pfd.cGreenBits; break; case WGL_GREEN_SHIFT_ARB: - *pvalue = (int) pf->color.greenshift; + *pvalue = pfi->pfd.cGreenShift; break; case WGL_BLUE_BITS_ARB: - *pvalue = (int) pf->color.bluebits; + *pvalue = pfi->pfd.cBlueBits; break; case WGL_BLUE_SHIFT_ARB: - *pvalue = (int) pf->color.blueshift; + *pvalue = pfi->pfd.cBlueShift; break; case WGL_ALPHA_BITS_ARB: - *pvalue = (int) pf->alpha.alphabits; + *pvalue = pfi->pfd.cAlphaBits; break; case WGL_ALPHA_SHIFT_ARB: - *pvalue = (int) pf->alpha.alphashift; + *pvalue = pfi->pfd.cAlphaShift; break; case WGL_ACCUM_BITS_ARB: + *pvalue = pfi->pfd.cAccumBits; + break; + case WGL_ACCUM_RED_BITS_ARB: + *pvalue = pfi->pfd.cAccumRedBits; + break; + case WGL_ACCUM_GREEN_BITS_ARB: + *pvalue = pfi->pfd.cAccumGreenBits; + break; + case WGL_ACCUM_BLUE_BITS_ARB: + *pvalue = pfi->pfd.cAccumBlueBits; + break; + case WGL_ACCUM_ALPHA_BITS_ARB: - *pvalue = 0; + *pvalue = pfi->pfd.cAccumAlphaBits; break; case WGL_DEPTH_BITS_ARB: - *pvalue = (int) pf->depth.depthbits; + *pvalue = pfi->pfd.cDepthBits; break; case WGL_STENCIL_BITS_ARB: - *pvalue = (int) pf->depth.stencilbits; + *pvalue = pfi->pfd.cStencilBits; break; case WGL_AUX_BUFFERS_ARB: - *pvalue = 0; + *pvalue = pfi->pfd.cAuxBuffers; break; case WGL_SAMPLE_BUFFERS_ARB: - if (pf->flags & PF_FLAG_MULTISAMPLED) - *pvalue = stw_query_sample_buffers(); - else - *pvalue = 0; + *pvalue = pfi->numSampleBuffers; break; case WGL_SAMPLES_ARB: - if (pf->flags & PF_FLAG_MULTISAMPLED) - *pvalue = stw_query_samples(); - else - *pvalue = 0; + *pvalue = pfi->numSamples; break; default: @@ -285,7 +249,7 @@ struct attrib_match_info BOOL exact; }; -static struct attrib_match_info attrib_match[] = { +static const struct attrib_match_info attrib_match[] = { /* WGL_ARB_pixel_format */ { WGL_DRAW_TO_WINDOW_ARB, 0, TRUE }, @@ -324,7 +288,7 @@ static struct attrib_match_info attrib_match[] = { { WGL_SAMPLES_ARB, 2, FALSE } }; -struct pixelformat_score +struct stw_pixelformat_score { int points; uint index; @@ -332,13 +296,13 @@ struct pixelformat_score static BOOL score_pixelformats( - struct pixelformat_score *scores, + struct stw_pixelformat_score *scores, uint count, int attribute, int expected_value ) { uint i; - struct attrib_match_info *ami = NULL; + const struct attrib_match_info *ami = NULL; uint index; /* Find out if a given attribute should be considered for score calculation. @@ -358,7 +322,7 @@ score_pixelformats( for (index = 0; index < count; index++) { int actual_value; - if (!query_attrib( index + 1, 0, attribute, &actual_value )) + if (!stw_query_attrib( index + 1, 0, attribute, &actual_value )) return FALSE; if (ami->exact) { @@ -395,7 +359,7 @@ wglChoosePixelFormatARB( UINT *nNumFormats ) { uint count; - struct pixelformat_score *scores; + struct stw_pixelformat_score *scores; uint i; *nNumFormats = 0; @@ -405,8 +369,8 @@ wglChoosePixelFormatARB( * points for a mismatch when the match does not have to be exact. * Set a score to 0 if there is a mismatch for an exact match criteria. */ - count = pixelformat_get_extended_count(); - scores = (struct pixelformat_score *) MALLOC( count * sizeof( struct pixelformat_score ) ); + count = stw_pixelformat_get_extended_count(); + scores = (struct stw_pixelformat_score *) MALLOC( count * sizeof( struct stw_pixelformat_score ) ); if (scores == NULL) return FALSE; for (i = 0; i < count; i++) { @@ -446,7 +410,7 @@ wglChoosePixelFormatARB( swapped = FALSE; for (i = 1; i < n; i++) { if (scores[i - 1].points < scores[i].points) { - struct pixelformat_score score = scores[i - 1]; + struct stw_pixelformat_score score = scores[i - 1]; scores[i - 1] = scores[i]; scores[i] = score; @@ -489,7 +453,7 @@ wglGetPixelFormatAttribfvARB( for (i = 0; i < nAttributes; i++) { int value; - if (!query_attrib( iPixelFormat, iLayerPlane, piAttributes[i], &value )) + if (!stw_query_attrib( iPixelFormat, iLayerPlane, piAttributes[i], &value )) return FALSE; pfValues[i] = (FLOAT) value; } @@ -511,7 +475,7 @@ wglGetPixelFormatAttribivARB( (void) hdc; for (i = 0; i < nAttributes; i++) { - if (!query_attrib( iPixelFormat, iLayerPlane, piAttributes[i], &piValues[i] )) + if (!stw_query_attrib( iPixelFormat, iLayerPlane, piAttributes[i], &piValues[i] )) return FALSE; } diff --git a/src/gallium/state_trackers/wgl/shared/stw_arbpixelformat.h b/src/gallium/state_trackers/wgl/shared/stw_arbpixelformat.h deleted file mode 100644 index a6c42599424..00000000000 --- a/src/gallium/state_trackers/wgl/shared/stw_arbpixelformat.h +++ /dev/null @@ -1,61 +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_ARBPIXELFORMAT_H -#define WGL_ARBPIXELFORMAT_H - - -/* Extension functions for get_proc_address: - */ -WINGDIAPI BOOL APIENTRY -wglChoosePixelFormatARB( - HDC hdc, - const int *piAttribIList, - const FLOAT *pfAttribFList, - UINT nMaxFormats, - int *piFormats, - UINT *nNumFormats ); - -WINGDIAPI BOOL APIENTRY -wglGetPixelFormatAttribfvARB( - HDC hdc, - int iPixelFormat, - int iLayerPlane, - UINT nAttributes, - const int *piAttributes, - FLOAT *pfValues ); - -WINGDIAPI BOOL APIENTRY -wglGetPixelFormatAttribivARB( - HDC hdc, - int iPixelFormat, - int iLayerPlane, - UINT nAttributes, - const int *piAttributes, - int *piValues ); - -#endif /* WGL_ARBPIXELFORMAT_H */ diff --git a/src/gallium/state_trackers/wgl/shared/stw_context.c b/src/gallium/state_trackers/wgl/shared/stw_context.c index f890225242a..f3c7af93f50 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_context.c +++ b/src/gallium/state_trackers/wgl/shared/stw_context.c @@ -59,8 +59,8 @@ stw_copy_context( pipe_mutex_lock( stw_dev->mutex ); - src = stw_lookup_context( hglrcSrc ); - dst = stw_lookup_context( hglrcDst ); + src = stw_lookup_context_locked( hglrcSrc ); + dst = stw_lookup_context_locked( hglrcDst ); if (src && dst) { /* FIXME */ @@ -80,7 +80,7 @@ stw_create_layer_context( int iLayerPlane ) { uint pfi; - const struct pixelformat_info *pf = NULL; + const struct stw_pixelformat_info *pf = NULL; struct stw_context *ctx = NULL; GLvisual *visual = NULL; struct pipe_screen *screen = NULL; @@ -97,7 +97,7 @@ stw_create_layer_context( if (pfi == 0) return 0; - pf = pixelformat_get_info( pfi - 1 ); + pf = stw_pixelformat_get_info( pfi - 1 ); ctx = CALLOC_STRUCT( stw_context ); if (ctx == NULL) @@ -109,21 +109,21 @@ stw_create_layer_context( /* 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) ? stw_query_samples() : 0 ); + (pf->pfd.iPixelType == PFD_TYPE_RGBA) ? GL_TRUE : GL_FALSE, + (pf->pfd.dwFlags & PFD_DOUBLEBUFFER) ? GL_TRUE : GL_FALSE, + (pf->pfd.dwFlags & PFD_STEREO) ? GL_TRUE : GL_FALSE, + pf->pfd.cRedBits, + pf->pfd.cGreenBits, + pf->pfd.cBlueBits, + pf->pfd.cAlphaBits, + (pf->pfd.iPixelType == PFD_TYPE_COLORINDEX) ? pf->pfd.cColorBits : 0, + pf->pfd.cDepthBits, + pf->pfd.cStencilBits, + pf->pfd.cAccumRedBits, + pf->pfd.cAccumGreenBits, + pf->pfd.cAccumBlueBits, + pf->pfd.cAccumAlphaBits, + pf->numSamples ); if (visual == NULL) goto fail; @@ -153,11 +153,10 @@ stw_create_layer_context( goto fail; ctx->st->ctx->DriverCtx = ctx; + ctx->pfi = pf; pipe_mutex_lock( stw_dev->mutex ); - { - hglrc = handle_table_add(stw_dev->ctx_table, ctx); - } + hglrc = handle_table_add(stw_dev->ctx_table, ctx); pipe_mutex_unlock( stw_dev->mutex ); /* Success? @@ -187,8 +186,10 @@ stw_delete_context( return FALSE; pipe_mutex_lock( stw_dev->mutex ); + ctx = stw_lookup_context_locked(hglrc); + handle_table_remove(stw_dev->ctx_table, hglrc); + pipe_mutex_unlock( stw_dev->mutex ); - ctx = stw_lookup_context(hglrc); if (ctx) { GLcontext *glctx = ctx->st->ctx; GET_CURRENT_CONTEXT( glcurctx ); @@ -199,26 +200,19 @@ stw_delete_context( if (glcurctx == glctx) st_make_current( NULL, NULL, NULL ); - fb = framebuffer_from_hdc( ctx->hdc ); + fb = stw_framebuffer_from_hdc( ctx->hdc ); if (fb) - framebuffer_destroy( fb ); + stw_framebuffer_destroy( fb ); if (WindowFromDC( ctx->hdc ) != NULL) ReleaseDC( WindowFromDC( ctx->hdc ), ctx->hdc ); - pipe_mutex_lock(stw_dev->mutex); - { - st_destroy_context(ctx->st); - FREE(ctx); - handle_table_remove(stw_dev->ctx_table, hglrc); - } - pipe_mutex_unlock(stw_dev->mutex); + st_destroy_context(ctx->st); + FREE(ctx); ret = TRUE; } - pipe_mutex_unlock( stw_dev->mutex ); - return ret; } @@ -226,38 +220,40 @@ BOOL stw_release_context( UINT_PTR hglrc ) { - BOOL ret = FALSE; + struct stw_context *ctx; if (!stw_dev) - return ret; + return FALSE; pipe_mutex_lock( stw_dev->mutex ); - { - struct stw_context *ctx; - - /* XXX: The expectation is that ctx is the same context which is - * current for this thread. We should check that and return False - * if not the case. - */ - ctx = stw_lookup_context( hglrc ); - if (ctx == NULL) - goto done; + ctx = stw_lookup_context_locked( hglrc ); + pipe_mutex_unlock( stw_dev->mutex ); - if (stw_make_current( NULL, 0 ) == FALSE) - goto done; + if (!ctx) + return FALSE; + + /* The expectation is that ctx is the same context which is + * current for this thread. We should check that and return False + * if not the case. + */ + { + GLcontext *glctx = ctx->st->ctx; + GET_CURRENT_CONTEXT( glcurctx ); - ret = TRUE; + if (glcurctx != glctx) + return FALSE; } -done: - pipe_mutex_unlock( stw_dev->mutex ); - return ret; + if (stw_make_current( NULL, 0 ) == FALSE) + return FALSE; + + return TRUE; } /* Find the width and height of the window named by hdc. */ static void -get_window_size( HDC hdc, GLuint *width, GLuint *height ) +stw_get_window_size( HDC hdc, GLuint *width, GLuint *height ) { if (WindowFromDC( hdc )) { RECT rect; @@ -300,7 +296,7 @@ stw_make_current( return FALSE; pipe_mutex_lock( stw_dev->mutex ); - ctx = stw_lookup_context( hglrc ); + ctx = stw_lookup_context_locked( hglrc ); pipe_mutex_unlock( stw_dev->mutex ); stw_tls_get_data()->currentDC = hdc; @@ -325,24 +321,27 @@ stw_make_current( return TRUE; } - fb = framebuffer_from_hdc( hdc ); + fb = stw_framebuffer_from_hdc( hdc ); if (hdc != NULL) - get_window_size( hdc, &width, &height ); + stw_get_window_size( hdc, &width, &height ); - /* Lazy creation of framebuffers. + /* Lazy creation of stw_framebuffers. */ if (fb == NULL && ctx != NULL && hdc != NULL) { GLvisual *visual = &ctx->st->ctx->Visual; - fb = framebuffer_create( hdc, visual, width, height ); + fb = stw_framebuffer_create( hdc, visual, ctx->pfi, width, height ); if (fb == NULL) return FALSE; } if (ctx && fb) { + pipe_mutex_lock( fb->mutex ); st_make_current( ctx->st, fb->stfb, fb->stfb ); - framebuffer_resize( fb, width, height ); + st_resize_framebuffer( fb->stfb, width, height ); + pipe_mutex_unlock( fb->mutex ); + ctx->hdc = hdc; ctx->st->pipe->priv = hdc; } diff --git a/src/gallium/state_trackers/wgl/shared/stw_context.h b/src/gallium/state_trackers/wgl/shared/stw_context.h index b2896152724..bc3b1dc880d 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_context.h +++ b/src/gallium/state_trackers/wgl/shared/stw_context.h @@ -31,12 +31,14 @@ #include <windows.h> struct st_context; +struct stw_pixelformat_info; struct stw_context { struct st_context *st; HDC hdc; DWORD color_bits; + const struct stw_pixelformat_info *pfi; }; #endif /* STW_CONTEXT_H */ diff --git a/src/gallium/state_trackers/wgl/shared/stw_device.c b/src/gallium/state_trackers/wgl/shared/stw_device.c index 51936c2bdd6..eef848988c0 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_device.c +++ b/src/gallium/state_trackers/wgl/shared/stw_device.c @@ -41,6 +41,7 @@ #include "shared/stw_pixelformat.h" #include "shared/stw_public.h" #include "shared/stw_tls.h" +#include "shared/stw_framebuffer.h" #ifdef WIN32_THREADS extern _glthread_Mutex OneTimeLock; @@ -75,7 +76,7 @@ st_flush_frontbuffer(struct pipe_screen *screen, boolean -st_init(const struct stw_winsys *stw_winsys) +stw_init(const struct stw_winsys *stw_winsys) { static struct stw_device stw_dev_storage; struct pipe_screen *screen; @@ -119,7 +120,7 @@ st_init(const struct stw_winsys *stw_winsys) goto error1; } - pixelformat_init(); + stw_pixelformat_init(); return TRUE; @@ -130,25 +131,28 @@ error1: boolean -st_init_thread(void) +stw_init_thread(void) { - if (!stw_tls_init_thread()) { + if (!stw_tls_init_thread()) + return FALSE; + + if (!stw_framebuffer_init_thread()) return FALSE; - } return TRUE; } void -st_cleanup_thread(void) +stw_cleanup_thread(void) { + stw_framebuffer_cleanup_thread(); stw_tls_cleanup_thread(); } void -st_cleanup(void) +stw_cleanup(void) { unsigned i; @@ -189,7 +193,7 @@ st_cleanup(void) struct stw_context * -stw_lookup_context( UINT_PTR dhglrc ) +stw_lookup_context_locked( UINT_PTR dhglrc ) { if (dhglrc == 0) return NULL; diff --git a/src/gallium/state_trackers/wgl/shared/stw_device.h b/src/gallium/state_trackers/wgl/shared/stw_device.h index 703cb670816..969e3843e76 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_device.h +++ b/src/gallium/state_trackers/wgl/shared/stw_device.h @@ -29,12 +29,19 @@ #define STW_DEVICE_H_ +#include <windows.h> + #include "pipe/p_compiler.h" #include "pipe/p_thread.h" #include "util/u_handle_table.h" +#include "stw_pixelformat.h" + + +#define STW_MAX_PIXELFORMATS 128 struct pipe_screen; +struct stw_framebuffer; struct stw_device { @@ -45,18 +52,24 @@ struct stw_device #ifdef DEBUG boolean trace_running; #endif - + + struct stw_pixelformat_info pixelformats[STW_MAX_PIXELFORMATS]; + unsigned pixelformat_count; + unsigned pixelformat_extended_count; + pipe_mutex mutex; struct handle_table *ctx_table; + struct stw_framebuffer *fb_head; + #ifdef DEBUG unsigned long memdbg_no; #endif }; struct stw_context * -stw_lookup_context( UINT_PTR hglrc ); +stw_lookup_context_locked( UINT_PTR hglrc ); extern struct stw_device *stw_dev; diff --git a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c index c96c4b8dfa8..4348b8f3262 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c +++ b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c @@ -42,143 +42,94 @@ #include "stw_device.h" #include "stw_public.h" #include "stw_winsys.h" +#include "stw_tls.h" -void -framebuffer_resize( - struct stw_framebuffer *fb, - GLuint width, - GLuint height ) -{ - st_resize_framebuffer( fb->stfb, width, height ); -} - -static struct stw_framebuffer *fb_head = NULL; - +/** + * @sa http://msdn.microsoft.com/en-us/library/ms644975(VS.85).aspx + * @sa http://msdn.microsoft.com/en-us/library/ms644960(VS.85).aspx + */ static LRESULT CALLBACK -window_proc( - HWND hWnd, - UINT uMsg, +stw_call_window_proc( + int nCode, WPARAM wParam, LPARAM lParam ) { - struct stw_framebuffer *fb; - - for (fb = fb_head; fb != NULL; fb = fb->next) - if (fb->hWnd == hWnd) - break; - assert( fb != NULL ); - - if (uMsg == WM_SIZE && wParam != SIZE_MINIMIZED) - framebuffer_resize( fb, LOWORD( lParam ), HIWORD( lParam ) ); - - return CallWindowProc( fb->WndProc, hWnd, uMsg, wParam, lParam ); -} + struct stw_tls_data *tls_data; + PCWPSTRUCT pParams = (PCWPSTRUCT)lParam; + + tls_data = stw_tls_get_data(); + if(!tls_data) + return 0; + + if (nCode < 0) + return CallNextHookEx(tls_data->hCallWndProcHook, nCode, wParam, lParam); + + if (pParams->message == WM_SIZE && pParams->wParam != SIZE_MINIMIZED) { + struct stw_framebuffer *fb; + + pipe_mutex_lock( stw_dev->mutex ); + for (fb = stw_dev->fb_head; fb != NULL; fb = fb->next) + if (fb->hWnd == pParams->hwnd) + break; + pipe_mutex_unlock( stw_dev->mutex ); + + if(fb) { + unsigned width = LOWORD( pParams->lParam ); + unsigned height = HIWORD( pParams->lParam ); + + /* FIXME: The mesa statetracker makes the assumptions that only + * one context is using the framebuffer, and that that context is the + * current one. However neither holds true, as WGL allows more than + * one context to be bound to the same drawable, and this function can + * be called from any thread. + */ + pipe_mutex_lock( fb->mutex ); + st_resize_framebuffer( fb->stfb, width, height ); + pipe_mutex_unlock( fb->mutex ); + } + } -static INLINE boolean -stw_is_supported_color(enum pipe_format format) -{ - struct pipe_screen *screen = stw_dev->screen; - return screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_RENDER_TARGET, 0); + return CallNextHookEx(tls_data->hCallWndProcHook, nCode, wParam, lParam); } -static INLINE boolean -stw_is_supported_depth_stencil(enum pipe_format format) -{ - struct pipe_screen *screen = stw_dev->screen; - return screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); -} /* Create a new framebuffer object which will correspond to the given HDC. */ struct stw_framebuffer * -framebuffer_create( +stw_framebuffer_create( HDC hdc, GLvisual *visual, + const struct stw_pixelformat_info *pfi, GLuint width, GLuint height ) { - struct stw_framebuffer *fb; enum pipe_format colorFormat, depthFormat, stencilFormat; + struct stw_framebuffer *fb; - /* Determine PIPE_FORMATs for buffers. - */ - - if(visual->alphaBits <= 0 && visual->redBits <= 5 && visual->blueBits <= 6 && visual->greenBits <= 5 && - stw_is_supported_color(PIPE_FORMAT_R5G6B5_UNORM)) { - colorFormat = PIPE_FORMAT_R5G6B5_UNORM; - } - else if(visual->alphaBits <= 0 && visual->redBits <= 8 && visual->blueBits <= 8 && visual->greenBits <= 8 && - stw_is_supported_color(PIPE_FORMAT_X8R8G8B8_UNORM)) { - colorFormat = PIPE_FORMAT_X8R8G8B8_UNORM; - } - else if(visual->alphaBits <= 1 && visual->redBits <= 5 && visual->blueBits <= 5 && visual->greenBits <= 5 && - stw_is_supported_color(PIPE_FORMAT_A1R5G5B5_UNORM)) { - colorFormat = PIPE_FORMAT_A1R5G5B5_UNORM; - } - else if(visual->alphaBits <= 4 && visual->redBits <= 4 && visual->blueBits <= 4 && visual->greenBits <= 4 && - stw_is_supported_color(PIPE_FORMAT_A4R4G4B4_UNORM)) { - colorFormat = PIPE_FORMAT_A4R4G4B4_UNORM; - } - else if(visual->alphaBits <= 8 && visual->redBits <= 8 && visual->blueBits <= 8 && visual->greenBits <= 8 && - stw_is_supported_color(PIPE_FORMAT_A8R8G8B8_UNORM)) { - colorFormat = PIPE_FORMAT_A8R8G8B8_UNORM; - } - else { - assert(0); - return NULL; - } + colorFormat = pfi->color_format; + + assert(pf_layout( pfi->depth_stencil_format ) == PIPE_FORMAT_LAYOUT_RGBAZS ); - if (visual->depthBits == 0) + if(pf_get_component_bits( pfi->depth_stencil_format, PIPE_FORMAT_COMP_Z )) + depthFormat = pfi->depth_stencil_format; + else depthFormat = PIPE_FORMAT_NONE; - else if (visual->depthBits <= 16 && - stw_is_supported_depth_stencil(PIPE_FORMAT_Z16_UNORM)) - depthFormat = PIPE_FORMAT_Z16_UNORM; - else if (visual->depthBits <= 24 && visual->stencilBits != 8 && - stw_is_supported_depth_stencil(PIPE_FORMAT_X8Z24_UNORM)) { - depthFormat = PIPE_FORMAT_X8Z24_UNORM; - } - else if (visual->depthBits <= 24 && visual->stencilBits != 8 && - stw_is_supported_depth_stencil(PIPE_FORMAT_Z24X8_UNORM)) { - depthFormat = PIPE_FORMAT_Z24X8_UNORM; - } - else if (visual->depthBits <= 24 && visual->stencilBits == 8 && - stw_is_supported_depth_stencil(PIPE_FORMAT_S8Z24_UNORM)) { - depthFormat = PIPE_FORMAT_S8Z24_UNORM; - } - else if (visual->depthBits <= 24 && visual->stencilBits == 8 && - stw_is_supported_depth_stencil(PIPE_FORMAT_Z24S8_UNORM)) { - depthFormat = PIPE_FORMAT_Z24S8_UNORM; - } - else if(stw_is_supported_depth_stencil(PIPE_FORMAT_Z32_UNORM)) { - depthFormat = PIPE_FORMAT_Z32_UNORM; - } - else if(stw_is_supported_depth_stencil(PIPE_FORMAT_Z32_FLOAT)) { - depthFormat = PIPE_FORMAT_Z32_FLOAT; - } - else { - assert(0); - depthFormat = PIPE_FORMAT_NONE; - } - if (depthFormat == PIPE_FORMAT_S8Z24_UNORM || - depthFormat == PIPE_FORMAT_Z24S8_UNORM) { - stencilFormat = depthFormat; - } - else if (visual->stencilBits == 8 && - stw_is_supported_depth_stencil(PIPE_FORMAT_S8_UNORM)) { - stencilFormat = PIPE_FORMAT_S8_UNORM; - } - else { + if(pf_get_component_bits( pfi->depth_stencil_format, PIPE_FORMAT_COMP_S )) + stencilFormat = pfi->depth_stencil_format; + else stencilFormat = PIPE_FORMAT_NONE; - } fb = CALLOC_STRUCT( stw_framebuffer ); if (fb == NULL) return NULL; + fb->hDC = hdc; + fb->hWnd = WindowFromDC( hdc ); + + pipe_mutex_init( fb->mutex ); + fb->stfb = st_create_framebuffer( visual, colorFormat, @@ -187,63 +138,60 @@ framebuffer_create( width, height, (void *) fb ); - - fb->cColorBits = GetDeviceCaps( hdc, BITSPIXEL ); - fb->hDC = hdc; - - /* Subclass a window associated with the device context. - */ - fb->hWnd = WindowFromDC( hdc ); - if (fb->hWnd != NULL) { - fb->WndProc = (WNDPROC) SetWindowLongPtr( - fb->hWnd, - GWLP_WNDPROC, - (LONG_PTR) window_proc ); + if(!fb->stfb) { + FREE(fb); + return NULL; } - fb->next = fb_head; - fb_head = fb; + pipe_mutex_lock( stw_dev->mutex ); + fb->next = stw_dev->fb_head; + stw_dev->fb_head = fb; + pipe_mutex_unlock( stw_dev->mutex ); + return fb; } void -framebuffer_destroy( +stw_framebuffer_destroy( struct stw_framebuffer *fb ) { - struct stw_framebuffer **link = &fb_head; - struct stw_framebuffer *pfb = fb_head; - - while (pfb != NULL) { - if (pfb == fb) { - if (fb->hWnd != NULL) { - SetWindowLongPtr( - fb->hWnd, - GWLP_WNDPROC, - (LONG_PTR) fb->WndProc ); - } - - *link = fb->next; - FREE( fb ); - return; - } + struct stw_framebuffer **link; - link = &pfb->next; - pfb = pfb->next; - } + pipe_mutex_lock( stw_dev->mutex ); + + link = &stw_dev->fb_head; + while (link && *link != fb) + link = &(*link)->next; + assert(*link); + if (link) + *link = fb->next; + fb->next = NULL; + + pipe_mutex_unlock( stw_dev->mutex ); + + st_unreference_framebuffer(fb->stfb); + + pipe_mutex_destroy( fb->mutex ); + + FREE( fb ); } -/* Given an hdc, return the corresponding stw_framebuffer. +/** + * Given an hdc, return the corresponding stw_framebuffer. */ struct stw_framebuffer * -framebuffer_from_hdc( +stw_framebuffer_from_hdc( HDC hdc ) { struct stw_framebuffer *fb; - for (fb = fb_head; fb != NULL; fb = fb->next) + pipe_mutex_lock( stw_dev->mutex ); + for (fb = stw_dev->fb_head; fb != NULL; fb = fb->next) if (fb->hDC == hdc) - return fb; - return NULL; + break; + pipe_mutex_unlock( stw_dev->mutex ); + + return fb; } @@ -255,10 +203,12 @@ stw_swap_buffers( struct pipe_screen *screen; struct pipe_surface *surface; - fb = framebuffer_from_hdc( hdc ); + fb = stw_framebuffer_from_hdc( hdc ); if (fb == NULL) return FALSE; + pipe_mutex_lock( fb->mutex ); + /* If we're swapping the buffer associated with the current context * we have to flush any pending rendering commands first. */ @@ -266,9 +216,11 @@ stw_swap_buffers( screen = stw_dev->screen; - if(!st_get_framebuffer_surface( fb->stfb, ST_SURFACE_BACK_LEFT, &surface )) + if(!st_get_framebuffer_surface( fb->stfb, ST_SURFACE_BACK_LEFT, &surface )) { /* FIXME: this shouldn't happen, but does on glean */ + pipe_mutex_unlock( fb->mutex ); return FALSE; + } #ifdef DEBUG if(stw_dev->trace_running) { @@ -279,5 +231,42 @@ stw_swap_buffers( stw_dev->stw_winsys->flush_frontbuffer( screen, surface, hdc ); + pipe_mutex_unlock( fb->mutex ); + return TRUE; } + + +boolean +stw_framebuffer_init_thread(void) +{ + struct stw_tls_data *tls_data; + + tls_data = stw_tls_get_data(); + if(!tls_data) + return FALSE; + + tls_data->hCallWndProcHook = SetWindowsHookEx(WH_CALLWNDPROC, + stw_call_window_proc, + NULL, + GetCurrentThreadId()); + if(tls_data->hCallWndProcHook == NULL) + return FALSE; + + return TRUE; +} + +void +stw_framebuffer_cleanup_thread(void) +{ + struct stw_tls_data *tls_data; + + tls_data = stw_tls_get_data(); + if(!tls_data) + return; + + if(tls_data->hCallWndProcHook) { + UnhookWindowsHookEx(tls_data->hCallWndProcHook); + tls_data->hCallWndProcHook = NULL; + } +} diff --git a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.h b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.h index 5abdf189970..f5b48db048c 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.h +++ b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.h @@ -28,39 +28,49 @@ #ifndef STW_FRAMEBUFFER_H #define STW_FRAMEBUFFER_H +#include <windows.h> + #include "main/mtypes.h" -/* Windows framebuffer, derived from gl_framebuffer. +#include "pipe/p_thread.h" + +struct stw_pixelformat_info; + +/** + * Windows framebuffer, derived from gl_framebuffer. */ struct stw_framebuffer { - struct st_framebuffer *stfb; HDC hDC; - BYTE cColorBits; HWND hWnd; - WNDPROC WndProc; + + pipe_mutex mutex; + struct st_framebuffer *stfb; + + /** This is protected by stw_device::mutex, not the mutex above */ struct stw_framebuffer *next; }; struct stw_framebuffer * -framebuffer_create( +stw_framebuffer_create( HDC hdc, GLvisual *visual, + const struct stw_pixelformat_info *pfi, GLuint width, GLuint height ); void -framebuffer_destroy( +stw_framebuffer_destroy( struct stw_framebuffer *fb ); -void -framebuffer_resize( - struct stw_framebuffer *fb, - GLuint width, - GLuint height ); - struct stw_framebuffer * -framebuffer_from_hdc( +stw_framebuffer_from_hdc( HDC hdc ); +boolean +stw_framebuffer_init_thread(void); + +void +stw_framebuffer_cleanup_thread(void); + #endif /* STW_FRAMEBUFFER_H */ diff --git a/src/gallium/state_trackers/wgl/shared/stw_getprocaddress.c b/src/gallium/state_trackers/wgl/shared/stw_getprocaddress.c index ac2d6fc2605..aa43120955e 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_getprocaddress.c +++ b/src/gallium/state_trackers/wgl/shared/stw_getprocaddress.c @@ -27,28 +27,31 @@ #include <windows.h> +#define WGL_WGLEXT_PROTOTYPES + +#include <GL/gl.h> +#include <GL/wglext.h> + #include "glapi/glapi.h" -#include "stw_arbextensionsstring.h" -#include "stw_arbpixelformat.h" #include "stw_public.h" -struct extension_entry +struct stw_extension_entry { const char *name; PROC proc; }; -#define EXTENTRY(P) { #P, (PROC) P } +#define STW_EXTENSION_ENTRY(P) { #P, (PROC) P } -static struct extension_entry extension_entries[] = { +static const struct stw_extension_entry stw_extension_entries[] = { /* WGL_ARB_extensions_string */ - EXTENTRY( wglGetExtensionsStringARB ), + STW_EXTENSION_ENTRY( wglGetExtensionsStringARB ), /* WGL_ARB_pixel_format */ - EXTENTRY( wglChoosePixelFormatARB ), - EXTENTRY( wglGetPixelFormatAttribfvARB ), - EXTENTRY( wglGetPixelFormatAttribivARB ), + STW_EXTENSION_ENTRY( wglChoosePixelFormatARB ), + STW_EXTENSION_ENTRY( wglGetPixelFormatAttribfvARB ), + STW_EXTENSION_ENTRY( wglGetPixelFormatAttribivARB ), { NULL, NULL } }; @@ -57,13 +60,13 @@ PROC stw_get_proc_address( LPCSTR lpszProc ) { - struct extension_entry *entry; + const struct stw_extension_entry *entry; - PROC p = (PROC) _glapi_get_proc_address( (const char *) lpszProc ); + PROC p = (PROC) _glapi_get_proc_address( lpszProc ); if (p) return p; - for (entry = extension_entries; entry->name; entry++) + for (entry = stw_extension_entries; entry->name; entry++) if (strcmp( lpszProc, entry->name ) == 0) return entry->proc; diff --git a/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c b/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c index b216ca5c823..9e642cbdd48 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c +++ b/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c @@ -25,113 +25,237 @@ * **************************************************************************/ +#include "pipe/p_format.h" +#include "pipe/p_defines.h" +#include "pipe/p_screen.h" + #include "util/u_debug.h" +#include "util/u_memory.h" + +#include "stw_device.h" #include "stw_pixelformat.h" #include "stw_public.h" #include "stw_tls.h" -#define MAX_PIXELFORMATS 16 -static struct pixelformat_info pixelformats[MAX_PIXELFORMATS]; -static uint pixelformat_count = 0; -static uint pixelformat_extended_count = 0; +struct stw_pf_color_info +{ + enum pipe_format format; + struct { + unsigned char red; + unsigned char green; + unsigned char blue; + unsigned char alpha; + } bits; + struct { + unsigned char red; + unsigned char green; + unsigned char blue; + unsigned char alpha; + } shift; +}; + +struct stw_pf_depth_info +{ + enum pipe_format format; + struct { + unsigned char depth; + unsigned char stencil; + } bits; +}; + + +/* NOTE: order matters, since in otherwise equal circumstances the first + * format listed will get chosen */ + +static const struct stw_pf_color_info +stw_pf_color[] = { + /* no-alpha */ + { PIPE_FORMAT_X8R8G8B8_UNORM, { 8, 8, 8, 0}, {16, 8, 0, 0} }, + { PIPE_FORMAT_B8G8R8X8_UNORM, { 8, 8, 8, 0}, { 8, 16, 24, 0} }, + { PIPE_FORMAT_R5G6B5_UNORM, { 5, 6, 5, 0}, {11, 5, 0, 0} }, + /* alpha */ + { PIPE_FORMAT_A8R8G8B8_UNORM, { 8, 8, 8, 8}, {16, 8, 0, 24} }, + { PIPE_FORMAT_B8G8R8A8_UNORM, { 8, 8, 8, 8}, { 8, 16, 24, 0} }, +#if 0 + { PIPE_FORMAT_A2B10G10R10_UNORM, {10, 10, 10, 2}, { 0, 10, 20, 30} }, +#endif + { PIPE_FORMAT_A1R5G5B5_UNORM, { 5, 5, 5, 1}, {10, 5, 0, 15} }, + { PIPE_FORMAT_A4R4G4B4_UNORM, { 4, 4, 4, 4}, {16, 4, 0, 12} } +}; + + +static const struct stw_pf_depth_info +stw_pf_depth_stencil[] = { + /* pure depth */ + { PIPE_FORMAT_Z32_UNORM, {32, 0} }, + { PIPE_FORMAT_Z24X8_UNORM, {24, 0} }, + { PIPE_FORMAT_X8Z24_UNORM, {24, 0} }, + { PIPE_FORMAT_Z16_UNORM, {16, 0} }, + /* pure stencil */ + { PIPE_FORMAT_S8_UNORM, { 0, 8} }, + /* combined depth-stencil */ + { PIPE_FORMAT_S8Z24_UNORM, {24, 8} }, + { PIPE_FORMAT_Z24S8_UNORM, {24, 8} } +}; + + +static const boolean +stw_pf_doublebuffer[] = { + FALSE, + TRUE, +}; + + +const unsigned +stw_pf_multisample[] = { + 0, + 4 +}; static void -add_standard_pixelformats( - struct pixelformat_info **ppf, - uint flags ) +stw_pixelformat_add( + struct stw_device *stw_dev, + const struct stw_pf_color_info *color, + const struct stw_pf_depth_info *depth, + boolean doublebuffer, + unsigned samples ) { - struct pixelformat_info *pf = *ppf; - struct pixelformat_color_info color24 = { 8, 0, 8, 8, 8, 16 }; - struct pixelformat_alpha_info alpha8 = { 8, 24 }; - struct pixelformat_alpha_info noalpha = { 0, 0 }; - struct pixelformat_depth_info depth24s8 = { 24, 8 }; - struct pixelformat_depth_info depth16 = { 16, 0 }; - - pf->flags = PF_FLAG_DOUBLEBUFFER | flags; - pf->color = color24; - pf->alpha = alpha8; - pf->depth = depth16; - pf++; - - pf->flags = PF_FLAG_DOUBLEBUFFER | flags; - pf->color = color24; - pf->alpha = alpha8; - pf->depth = depth24s8; - pf++; - - pf->flags = PF_FLAG_DOUBLEBUFFER | flags; - pf->color = color24; - pf->alpha = noalpha; - pf->depth = depth16; - pf++; - - pf->flags = PF_FLAG_DOUBLEBUFFER | flags; - pf->color = color24; - pf->alpha = noalpha; - pf->depth = depth24s8; - pf++; - - pf->flags = flags; - pf->color = color24; - pf->alpha = alpha8; - pf->depth = depth16; - pf++; - - pf->flags = flags; - pf->color = color24; - pf->alpha = alpha8; - pf->depth = depth24s8; - pf++; - - pf->flags = flags; - pf->color = color24; - pf->alpha = noalpha; - pf->depth = depth16; - pf++; - - pf->flags = flags; - pf->color = color24; - pf->alpha = noalpha; - pf->depth = depth24s8; - pf++; - - *ppf = pf; + boolean extended = FALSE; + struct stw_pixelformat_info *pfi; + + assert(stw_dev->pixelformat_extended_count < STW_MAX_PIXELFORMATS); + if(stw_dev->pixelformat_extended_count >= STW_MAX_PIXELFORMATS) + return; + + assert(pf_layout( color->format ) == PIPE_FORMAT_LAYOUT_RGBAZS ); + assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_R ) == color->bits.red ); + assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_G ) == color->bits.green ); + assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_B ) == color->bits.blue ); + assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_A ) == color->bits.alpha ); + assert(pf_layout( depth->format ) == PIPE_FORMAT_LAYOUT_RGBAZS ); + assert(pf_get_component_bits( depth->format, PIPE_FORMAT_COMP_Z ) == depth->bits.depth ); + assert(pf_get_component_bits( depth->format, PIPE_FORMAT_COMP_S ) == depth->bits.stencil ); + + pfi = &stw_dev->pixelformats[stw_dev->pixelformat_extended_count]; + + memset(pfi, 0, sizeof *pfi); + + pfi->color_format = color->format; + pfi->depth_stencil_format = depth->format; + + pfi->pfd.nSize = sizeof pfi->pfd; + pfi->pfd.nVersion = 1; + + pfi->pfd.dwFlags = PFD_SUPPORT_OPENGL; + + /* TODO: also support non-native pixel formats */ + pfi->pfd.dwFlags |= PFD_DRAW_TO_WINDOW ; + + if (doublebuffer) + pfi->pfd.dwFlags |= PFD_DOUBLEBUFFER | PFD_SWAP_COPY; + + pfi->pfd.iPixelType = PFD_TYPE_RGBA; + + pfi->pfd.cColorBits = color->bits.red + color->bits.green + color->bits.blue; + pfi->pfd.cRedBits = color->bits.red; + pfi->pfd.cRedShift = color->shift.red; + pfi->pfd.cGreenBits = color->bits.green; + pfi->pfd.cGreenShift = color->shift.green; + pfi->pfd.cBlueBits = color->bits.blue; + pfi->pfd.cBlueShift = color->shift.blue; + pfi->pfd.cAlphaBits = color->bits.alpha; + pfi->pfd.cAlphaShift = color->shift.alpha; + pfi->pfd.cAccumBits = 0; + pfi->pfd.cAccumRedBits = 0; + pfi->pfd.cAccumGreenBits = 0; + pfi->pfd.cAccumBlueBits = 0; + pfi->pfd.cAccumAlphaBits = 0; + pfi->pfd.cDepthBits = depth->bits.depth; + pfi->pfd.cStencilBits = depth->bits.stencil; + pfi->pfd.cAuxBuffers = 0; + pfi->pfd.iLayerType = 0; + pfi->pfd.bReserved = 0; + pfi->pfd.dwLayerMask = 0; + pfi->pfd.dwVisibleMask = 0; + pfi->pfd.dwDamageMask = 0; + + if(samples) { + pfi->numSampleBuffers = 1; + pfi->numSamples = samples; + extended = TRUE; + } + + ++stw_dev->pixelformat_extended_count; + + if(!extended) { + ++stw_dev->pixelformat_count; + assert(stw_dev->pixelformat_count == stw_dev->pixelformat_extended_count); + } } void -pixelformat_init( void ) +stw_pixelformat_init( void ) { - struct pixelformat_info *pf = pixelformats; - - add_standard_pixelformats( &pf, 0 ); - pixelformat_count = pf - pixelformats; - - add_standard_pixelformats( &pf, PF_FLAG_MULTISAMPLED ); - pixelformat_extended_count = pf - pixelformats; + struct pipe_screen *screen = stw_dev->screen; + unsigned i, j, k, l; + + assert( !stw_dev->pixelformat_count ); + assert( !stw_dev->pixelformat_extended_count ); + + for(i = 0; i < Elements(stw_pf_multisample); ++i) { + unsigned samples = stw_pf_multisample[i]; + + /* FIXME: re-enabled MSAA when we can query it */ + if(samples) + continue; - assert( pixelformat_extended_count <= MAX_PIXELFORMATS ); + for(j = 0; j < Elements(stw_pf_color); ++j) { + const struct stw_pf_color_info *color = &stw_pf_color[j]; + + if(!screen->is_format_supported(screen, color->format, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) + continue; + + for(k = 0; k < Elements(stw_pf_doublebuffer); ++k) { + unsigned doublebuffer = stw_pf_doublebuffer[k]; + + for(l = 0; l < Elements(stw_pf_depth_stencil); ++l) { + const struct stw_pf_depth_info *depth = &stw_pf_depth_stencil[l]; + + if(!screen->is_format_supported(screen, depth->format, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0)) + continue; + + stw_pixelformat_add( stw_dev, color, depth, doublebuffer, samples ); + } + } + } + } + + assert( stw_dev->pixelformat_count <= stw_dev->pixelformat_extended_count ); + assert( stw_dev->pixelformat_extended_count <= STW_MAX_PIXELFORMATS ); } uint -pixelformat_get_count( void ) +stw_pixelformat_get_count( void ) { - return pixelformat_count; + return stw_dev->pixelformat_count; } uint -pixelformat_get_extended_count( void ) +stw_pixelformat_get_extended_count( void ) { - return pixelformat_extended_count; + return stw_dev->pixelformat_extended_count; } -const struct pixelformat_info * -pixelformat_get_info( uint index ) +const struct stw_pixelformat_info * +stw_pixelformat_get_info( uint index ) { - assert( index < pixelformat_extended_count ); + assert( index < stw_dev->pixelformat_extended_count ); - return &pixelformats[index]; + return &stw_dev->pixelformats[index]; } @@ -144,11 +268,11 @@ stw_pixelformat_describe( { uint count; uint index; - const struct pixelformat_info *pf; + const struct stw_pixelformat_info *pfi; (void) hdc; - count = pixelformat_get_extended_count(); + count = stw_pixelformat_get_extended_count(); index = (uint) iPixelFormat - 1; if (ppfd == NULL) @@ -156,36 +280,9 @@ stw_pixelformat_describe( if (index >= count || nBytes != sizeof( PIXELFORMATDESCRIPTOR )) return 0; - pf = pixelformat_get_info( index ); - - ppfd->nSize = sizeof( PIXELFORMATDESCRIPTOR ); - ppfd->nVersion = 1; - ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; - if (pf->flags & PF_FLAG_DOUBLEBUFFER) - ppfd->dwFlags |= PFD_DOUBLEBUFFER | PFD_SWAP_COPY; - ppfd->iPixelType = PFD_TYPE_RGBA; - ppfd->cColorBits = pf->color.redbits + pf->color.greenbits + pf->color.bluebits; - ppfd->cRedBits = pf->color.redbits; - ppfd->cRedShift = pf->color.redshift; - ppfd->cGreenBits = pf->color.greenbits; - ppfd->cGreenShift = pf->color.greenshift; - ppfd->cBlueBits = pf->color.bluebits; - ppfd->cBlueShift = pf->color.blueshift; - ppfd->cAlphaBits = pf->alpha.alphabits; - ppfd->cAlphaShift = pf->alpha.alphashift; - ppfd->cAccumBits = 0; - ppfd->cAccumRedBits = 0; - ppfd->cAccumGreenBits = 0; - ppfd->cAccumBlueBits = 0; - ppfd->cAccumAlphaBits = 0; - ppfd->cDepthBits = pf->depth.depthbits; - ppfd->cStencilBits = pf->depth.stencilbits; - ppfd->cAuxBuffers = 0; - ppfd->iLayerType = 0; - ppfd->bReserved = 0; - ppfd->dwLayerMask = 0; - ppfd->dwVisibleMask = 0; - ppfd->dwDamageMask = 0; + pfi = stw_pixelformat_get_info( index ); + + memcpy(ppfd, &pfi->pfd, sizeof( PIXELFORMATDESCRIPTOR )); return count; } @@ -203,29 +300,30 @@ int stw_pixelformat_choose( HDC hdc, (void) hdc; - count = pixelformat_get_count(); + count = stw_pixelformat_get_count(); bestindex = count; - bestdelta = 0xffffffff; + bestdelta = ~0U; for (index = 0; index < count; index++) { uint delta = 0; - const struct pixelformat_info *pf = pixelformat_get_info( index ); + const struct stw_pixelformat_info *pfi = stw_pixelformat_get_info( index ); if (!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) && !!(ppfd->dwFlags & PFD_DOUBLEBUFFER) != - !!(pf->flags & PF_FLAG_DOUBLEBUFFER)) + !!(pfi->pfd.dwFlags & PFD_DOUBLEBUFFER)) continue; - if (ppfd->cColorBits != pf->color.redbits + pf->color.greenbits + pf->color.bluebits) + /* FIXME: Take in account individual channel bits */ + if (ppfd->cColorBits != pfi->pfd.cColorBits) delta += 8; - if (ppfd->cDepthBits != pf->depth.depthbits) + if (ppfd->cDepthBits != pfi->pfd.cDepthBits) delta += 4; - if (ppfd->cStencilBits != pf->depth.stencilbits) + if (ppfd->cStencilBits != pfi->pfd.cStencilBits) delta += 2; - if (ppfd->cAlphaBits != pf->alpha.alphabits) + if (ppfd->cAlphaBits != pfi->pfd.cAlphaBits) delta++; if (delta < bestdelta) { @@ -262,7 +360,7 @@ stw_pixelformat_set( (void) hdc; index = (uint) iPixelFormat - 1; - count = pixelformat_get_extended_count(); + count = stw_pixelformat_get_extended_count(); if (index >= count) return FALSE; @@ -277,21 +375,3 @@ stw_pixelformat_set( return TRUE; } - - - -/* XXX: this needs to be turned into queries on pipe_screen or - * stw_winsys. - */ -int -stw_query_sample_buffers( void ) -{ - return 1; -} - -int -stw_query_samples( void ) -{ - return 4; -} - diff --git a/src/gallium/state_trackers/wgl/shared/stw_pixelformat.h b/src/gallium/state_trackers/wgl/shared/stw_pixelformat.h index 7ca4194a2ae..34522ebef38 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_pixelformat.h +++ b/src/gallium/state_trackers/wgl/shared/stw_pixelformat.h @@ -25,59 +25,36 @@ * **************************************************************************/ -#ifndef PIXELFORMAT_H -#define PIXELFORMAT_H +#ifndef STW_PIXELFORMAT_H +#define STW_PIXELFORMAT_H #include <windows.h> -#include "pipe/p_compiler.h" - -#define PF_FLAG_DOUBLEBUFFER 0x00000001 -#define PF_FLAG_MULTISAMPLED 0x00000002 - -struct pixelformat_color_info -{ - uint redbits; - uint redshift; - uint greenbits; - uint greenshift; - uint bluebits; - uint blueshift; -}; - -struct pixelformat_alpha_info -{ - uint alphabits; - uint alphashift; -}; -struct pixelformat_depth_info -{ - uint depthbits; - uint stencilbits; -}; +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" -struct pixelformat_info +struct stw_pixelformat_info { - uint flags; - struct pixelformat_color_info color; - struct pixelformat_alpha_info alpha; - struct pixelformat_depth_info depth; + enum pipe_format color_format; + enum pipe_format depth_stencil_format; + + PIXELFORMATDESCRIPTOR pfd; + + unsigned numSampleBuffers; + unsigned numSamples; }; void -pixelformat_init( void ); +stw_pixelformat_init( void ); uint -pixelformat_get_count( void ); +stw_pixelformat_get_count( void ); uint -pixelformat_get_extended_count( void ); - -const struct pixelformat_info * -pixelformat_get_info( uint index ); +stw_pixelformat_get_extended_count( void ); -int stw_query_sample_buffers( void ); -int stw_query_samples( void ); +const struct stw_pixelformat_info * +stw_pixelformat_get_info( uint index ); -#endif /* PIXELFORMAT_H */ +#endif /* STW_PIXELFORMAT_H */ diff --git a/src/gallium/state_trackers/wgl/shared/stw_quirks.c b/src/gallium/state_trackers/wgl/shared/stw_quirks.c deleted file mode 100644 index 2f7091a52c0..00000000000 --- a/src/gallium/state_trackers/wgl/shared/stw_quirks.c +++ /dev/null @@ -1,116 +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. - * - **************************************************************************/ - -/** - * @file - * - * This is hopefully a temporary hack to define some needed dispatch - * table entries. Hopefully, I'll find a better solution. The - * dispatch table generation scripts ought to be making these dummy - * stubs as well. - */ - -void gl_dispatch_stub_543(void){} -void gl_dispatch_stub_544(void){} -void gl_dispatch_stub_545(void){} -void gl_dispatch_stub_546(void){} -void gl_dispatch_stub_547(void){} -void gl_dispatch_stub_548(void){} -void gl_dispatch_stub_549(void){} -void gl_dispatch_stub_550(void){} -void gl_dispatch_stub_551(void){} -void gl_dispatch_stub_552(void){} -void gl_dispatch_stub_553(void){} -void gl_dispatch_stub_554(void){} -void gl_dispatch_stub_555(void){} -void gl_dispatch_stub_556(void){} -void gl_dispatch_stub_557(void){} -void gl_dispatch_stub_558(void){} -void gl_dispatch_stub_559(void){} -void gl_dispatch_stub_560(void){} -void gl_dispatch_stub_561(void){} -void gl_dispatch_stub_565(void){} -void gl_dispatch_stub_566(void){} -void gl_dispatch_stub_570(void){} -void gl_dispatch_stub_577(void){} -void gl_dispatch_stub_578(void){} -void gl_dispatch_stub_582(void){} -void gl_dispatch_stub_603(void){} -void gl_dispatch_stub_607(void){} -void gl_dispatch_stub_645(void){} -void gl_dispatch_stub_646(void){} -void gl_dispatch_stub_647(void){} -void gl_dispatch_stub_648(void){} -void gl_dispatch_stub_649(void){} -void gl_dispatch_stub_650(void){} -void gl_dispatch_stub_651(void){} -void gl_dispatch_stub_652(void){} -void gl_dispatch_stub_653(void){} -void gl_dispatch_stub_657(void){} -void gl_dispatch_stub_733(void){} -void gl_dispatch_stub_734(void){} -void gl_dispatch_stub_735(void){} -void gl_dispatch_stub_736(void){} -void gl_dispatch_stub_737(void){} -void gl_dispatch_stub_738(void){} -void gl_dispatch_stub_744(void){} -void gl_dispatch_stub_745(void){} -void gl_dispatch_stub_746(void){} -void gl_dispatch_stub_760(void){} -void gl_dispatch_stub_761(void){} -void gl_dispatch_stub_763(void){} -void gl_dispatch_stub_764(void){} -void gl_dispatch_stub_765(void){} -void gl_dispatch_stub_766(void){} -void gl_dispatch_stub_767(void){} -void gl_dispatch_stub_768(void){} - -void gl_dispatch_stub_562(void){} -void gl_dispatch_stub_563(void){} -void gl_dispatch_stub_564(void){} -void gl_dispatch_stub_567(void){} -void gl_dispatch_stub_568(void){} -void gl_dispatch_stub_569(void){} -void gl_dispatch_stub_580(void){} -void gl_dispatch_stub_581(void){} -void gl_dispatch_stub_606(void){} -void gl_dispatch_stub_654(void){} -void gl_dispatch_stub_655(void){} -void gl_dispatch_stub_656(void){} -void gl_dispatch_stub_739(void){} -void gl_dispatch_stub_740(void){} -void gl_dispatch_stub_741(void){} -void gl_dispatch_stub_748(void){} -void gl_dispatch_stub_749(void){} -void gl_dispatch_stub_769(void){} -void gl_dispatch_stub_770(void){} -void gl_dispatch_stub_771(void){} -void gl_dispatch_stub_772(void){} -void gl_dispatch_stub_773(void){} -void gl_dispatch_stub_774(void){} -void gl_dispatch_stub_750(void){} -void gl_dispatch_stub_742(void){} diff --git a/src/gallium/state_trackers/wgl/shared/stw_tls.h b/src/gallium/state_trackers/wgl/shared/stw_tls.h index 23b61e68ff5..f5a6bdf4b1a 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_tls.h +++ b/src/gallium/state_trackers/wgl/shared/stw_tls.h @@ -28,11 +28,14 @@ #ifndef STW_TLS_H #define STW_TLS_H +#include <windows.h> + struct stw_tls_data { uint currentPixelFormat; HDC currentDC; UINT_PTR currentGLRC; + HHOOK hCallWndProcHook; }; boolean diff --git a/src/gallium/state_trackers/wgl/shared/stw_winsys.h b/src/gallium/state_trackers/wgl/shared/stw_winsys.h index e4a1d4f979f..c0bf82c9ed7 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_winsys.h +++ b/src/gallium/state_trackers/wgl/shared/stw_winsys.h @@ -51,15 +51,15 @@ struct stw_winsys }; boolean -st_init(const struct stw_winsys *stw_winsys); +stw_init(const struct stw_winsys *stw_winsys); boolean -st_init_thread(void); +stw_init_thread(void); void -st_cleanup_thread(void); +stw_cleanup_thread(void); void -st_cleanup(void); +stw_cleanup(void); #endif /* STW_WINSYS_H */ |