From f87c1084d08be78a7b6f4338f5b755d094903226 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 10 Feb 2009 22:59:47 +0000 Subject: Context stuff --- src/mesa/drivers/dri/glamo/Makefile | 5 +- src/mesa/drivers/dri/glamo/glamo_context.c | 154 ++++++++++++++++++++++++++ src/mesa/drivers/dri/glamo/glamo_context.h | 70 ++++++++++++ src/mesa/drivers/dri/glamo/glamo_dri.c | 125 --------------------- src/mesa/drivers/dri/glamo/glamo_screen.c | 170 +++++++++++++++++++++++++++++ src/mesa/drivers/dri/glamo/glamo_screen.h | 40 +++++++ 6 files changed, 436 insertions(+), 128 deletions(-) create mode 100644 src/mesa/drivers/dri/glamo/glamo_context.c create mode 100644 src/mesa/drivers/dri/glamo/glamo_context.h delete mode 100644 src/mesa/drivers/dri/glamo/glamo_dri.c create mode 100644 src/mesa/drivers/dri/glamo/glamo_screen.c create mode 100644 src/mesa/drivers/dri/glamo/glamo_screen.h diff --git a/src/mesa/drivers/dri/glamo/Makefile b/src/mesa/drivers/dri/glamo/Makefile index 0ef3afcc51..e72577198a 100644 --- a/src/mesa/drivers/dri/glamo/Makefile +++ b/src/mesa/drivers/dri/glamo/Makefile @@ -6,13 +6,13 @@ include $(TOP)/configs/current LIBNAME = glamo_dri.so DRIVER_SOURCES = \ - glamo_dri.c + glamo_screen.c glamo_context.c C_SOURCES = \ $(COMMON_SOURCES) \ $(DRIVER_SOURCES) -ASM_SOURCES = +ASM_SOURCES = # XXX not 100% sure this is right #WINDOW_SYSTEM = solo @@ -20,4 +20,3 @@ ASM_SOURCES = include ../Makefile.template symlinks: - diff --git a/src/mesa/drivers/dri/glamo/glamo_context.c b/src/mesa/drivers/dri/glamo/glamo_context.c new file mode 100644 index 0000000000..627f8f56a0 --- /dev/null +++ b/src/mesa/drivers/dri/glamo/glamo_context.c @@ -0,0 +1,154 @@ +/* + * Direct Rendering Support for SMedia Glamo 336x/337x + * + * (c) 2009 Thomas White + * Roughly based on sis_context.c (c) 2003 Eric Anholt + * + * 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, sublicense, + * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS 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 "dri_util.h" +#include "utils.h" +#include "swrast/swrast.h" +#include "swrast_setup/swrast_setup.h" +#include "drivers/common/driverfuncs.h" +#include "vbo/vbo.h" +#include "tnl/tnl.h" +#include "tnl/t_pipeline.h" + +#include "glamo_context.h" +#include "glamo_screen.h" + + +GLboolean glamoCreateContext(const __GLcontextModes *glVisual, + __DRIcontext *driContextPriv, + void *sharedContextPrivate) +{ + GLcontext *ctx, *shareCtx; + __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv; + glamoContextPtr context; + glamoScreenPtr glamoScreen; + struct dd_function_table functions; + + context = (glamoContextPtr)CALLOC(sizeof(*context)); + if ( context == NULL ) return GL_FALSE; + + _mesa_init_driver_functions(&functions); + + /* Allocate the Mesa context */ + if ( sharedContextPrivate ) + shareCtx = ((glamoContextPtr)sharedContextPrivate)->glCtx; + else + shareCtx = NULL; + context->glCtx = _mesa_create_context(glVisual, shareCtx, + &functions, (void *)context); + if ( context->glCtx == NULL ) { + FREE(context); + return GL_FALSE; + } + driContextPriv->driverPrivate = context; + ctx = context->glCtx; + + glamoScreen = context->glamoScreen = (glamoScreenPtr)sPriv->private; + + context->driContext = driContextPriv; + context->driScreen = sPriv; + context->driDrawable = NULL; + context->driFd = sPriv->fd; + + /* Parse configuration files */ + driParseConfigFiles(&context->optionCache, &glamoScreen->optionCache, + glamoScreen->driScreen->myNum, "glamo"); + + /* Initialize the software rasterizer and helper modules. */ + _swrast_CreateContext( ctx ); + _vbo_CreateContext( ctx ); + _tnl_CreateContext( ctx ); + _swsetup_CreateContext( ctx ); + + _swrast_allow_pixel_fog( ctx, GL_TRUE ); + _swrast_allow_vertex_fog( ctx, GL_FALSE ); + _tnl_allow_pixel_fog( ctx, GL_TRUE ); + _tnl_allow_vertex_fog( ctx, GL_FALSE ); + + return GL_TRUE; +} + + +void glamoDestroyContext(__DRIcontext *driContextPriv) +{ + glamoContextPtr context; + + context = (glamoContextPtr)driContextPriv->driverPrivate; + assert(context != NULL); + + if ( context != NULL ) { + + _swsetup_DestroyContext(context->glCtx); + _tnl_DestroyContext(context->glCtx); + _vbo_DestroyContext(context->glCtx); + _swrast_DestroyContext(context->glCtx); + + _mesa_destroy_context(context->glCtx); + + } + + FREE(context); +} + + +GLboolean glamoMakeCurrent(__DRIcontext *driContextPriv, + __DRIdrawable *driDrawPriv, + __DRIdrawable *driReadPriv) +{ + if ( driContextPriv ) { + + GET_CURRENT_CONTEXT(ctx); + glamoContextPtr oldGlamoCtx; + glamoContextPtr newGlamoCtx; + struct gl_framebuffer *drawBuffer, *readBuffer; + + oldGlamoCtx = ctx ? GLAMO_CONTEXT(ctx) : NULL; + newGlamoCtx = (glamoContextPtr)driContextPriv->driverPrivate; + + if ( newGlamoCtx != oldGlamoCtx) { + newGlamoCtx->GlobalFlag = GFLAG_ALL; + } + + newGlamoCtx->driDrawable = driDrawPriv; + + drawBuffer = (GLframebuffer *)driDrawPriv->driverPrivate; + readBuffer = (GLframebuffer *)driReadPriv->driverPrivate; + + _mesa_make_current(newGlamoCtx->glCtx, drawBuffer, readBuffer); + + } else { + _mesa_make_current(NULL, NULL, NULL); + } + + return GL_TRUE; +} + + +GLboolean glamoUnbindContext(__DRIcontext *driContextPriv) +{ + return GL_TRUE; +} + +/* kate: space-indent on; indent-width 3; mixedindent off; indent-mode cstyle; */ diff --git a/src/mesa/drivers/dri/glamo/glamo_context.h b/src/mesa/drivers/dri/glamo/glamo_context.h new file mode 100644 index 0000000000..8f4d811c61 --- /dev/null +++ b/src/mesa/drivers/dri/glamo/glamo_context.h @@ -0,0 +1,70 @@ +/* + * Direct Rendering Support for SMedia Glamo 336x/337x + * + * (c) 2009 Thomas White + * Roughly based on sis_context.h (c) 2003 Eric Anholt + * + * 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, sublicense, + * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS 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 __GLAMO_CONTEXT_H +#define __GLAMO_CONTEXT_H + +#include "dri_util.h" +#include "utils.h" +#include "glamo_screen.h" + +/* Flags for hardware state that needs to be updated */ +#define GFLAG_ALL 0xffffffff + +typedef struct glamo_context glamoContextRec; +typedef struct glamo_context *glamoContextPtr; + +struct glamo_context { + + /* This must be first in this structure */ + GLcontext *glCtx; + + int driFd; /* DRM fd */ + + __DRIcontextPrivate *driContext; /* DRI context */ + __DRIscreenPrivate *driScreen; /* DRI screen */ + __DRIdrawablePrivate *driDrawable; /* DRI drawable bound to this ctx */ + + glamoScreenPtr glamoScreen; /* Screen private DRI data */ + + driOptionCache optionCache; + + GLint GlobalFlag; /* What needs to be updated */ + +}; + +#define GLAMO_CONTEXT(ctx) ((glamoContextPtr)(ctx->DriverCtx)) + +extern GLboolean glamoCreateContext(const __GLcontextModes *glVis, + __DRIcontext *driContextPriv, + void *sharedContextPrivate); +extern void glamoDestroyContext(__DRIcontext *dcp); +extern GLboolean glamoMakeCurrent(__DRIcontext *driContextPriv, + __DRIdrawable *driDrawPriv, + __DRIdrawable *driReadPriv); +extern GLboolean glamoUnbindContext(__DRIcontext *driContextPriv); + +#endif /* __GLAMO_CONTEXT_H */ + +/* kate: space-indent on; indent-width 3; mixedindent off; indent-mode cstyle; */ diff --git a/src/mesa/drivers/dri/glamo/glamo_dri.c b/src/mesa/drivers/dri/glamo/glamo_dri.c deleted file mode 100644 index a6351dc46b..0000000000 --- a/src/mesa/drivers/dri/glamo/glamo_dri.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Direct Rendering Support for SMedia Glamo 336x/337x - * - * (c) 2009 Thomas White - * - * 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, sublicense, - * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS 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 "dri_util.h" -#include "utils.h" - -static int glamoInitDriver(__DRIscreenPrivate *psp) -{ - return 0; -} - - -static const __DRIconfig **glamoInitScreen(__DRIscreenPrivate *psp) -{ - uint8_t depth_bits_array[1]; - uint8_t stencil_bits_array[1]; - static const GLenum db_modes[1] = { GLX_NONE }; - - /* Our basic initialisation */ - if ( glamoInitDriver(psp) ) { - return NULL; - } - - depth_bits_array[0] = 24; - stencil_bits_array[0] = 8; - - /* Report what modes we can handle */ - return driCreateConfigs(GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, - depth_bits_array, stencil_bits_array, 1, - db_modes, 1); -} - - -static void glamoDestroyScreen(__DRIscreenPrivate *psp) -{ -} - - -static GLboolean glamoCreateContext(const __GLcontextModes *glVis, - __DRIcontext *driContextPriv, - void *sharedContextPrivate) -{ -} - - -static void glamoDestroyContext(__DRIcontext *dcp) -{ -} - - -static GLboolean glamoCreateBuffer(__DRIscreen *driScrnPriv, - __DRIdrawable *driDrawPriv, - const __GLcontextModes *glVis, - GLboolean pixmapBuffer) -{ -} - - -static void glamoDestroyBuffer(__DRIdrawable *driDrawPriv) -{ -} - - -static void glamoSwapBuffers(__DRIdrawable *driDrawPriv) -{ -} - - -static GLboolean glamoMakeCurrent(__DRIcontext *driContextPriv, - __DRIdrawable *driDrawPriv, - __DRIdrawable *driReadPriv) -{ -} - - -static GLboolean glamoUnbindContext(__DRIcontext *driContextPriv) -{ -} - - -/* - * Mesa entry points - * - * See src/mesa/drivers/dri/common/dri_util.h for information about these - */ -const struct __DriverAPIRec driDriverAPI = { - .InitScreen = glamoInitScreen, - .DestroyScreen = glamoDestroyScreen, - .CreateContext = glamoCreateContext, - .DestroyContext = glamoDestroyContext, - .CreateBuffer = glamoCreateBuffer, - .DestroyBuffer = glamoDestroyBuffer, - .SwapBuffers = glamoSwapBuffers, - .MakeCurrent = glamoMakeCurrent, - .UnbindContext = glamoUnbindContext, - .GetSwapInfo = NULL, /* Not used */ - .WaitForMSC = NULL, - .WaitForSBC = NULL, - .SwapBuffersMSC = NULL, - .CopySubBuffer = NULL, - .GetDrawableMSC = NULL, /* Not used */ - .InitScreen2 = NULL /* For DRI2 */ -}; - -/* kate: space-indent on; indent-width 3; mixedindent off; indent-mode cstyle; */ diff --git a/src/mesa/drivers/dri/glamo/glamo_screen.c b/src/mesa/drivers/dri/glamo/glamo_screen.c new file mode 100644 index 0000000000..7ec44ac161 --- /dev/null +++ b/src/mesa/drivers/dri/glamo/glamo_screen.c @@ -0,0 +1,170 @@ +/* + * Direct Rendering Support for SMedia Glamo 336x/337x + * + * (c) 2009 Thomas White + * Roughly based on sis_screen.c (c) 2003 Eric Anholt + * + * 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, sublicense, + * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS 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 "dri_util.h" +#include "utils.h" +#include "xmlconfig.h" +#include "GL/internal/dri_interface.h" +#include "framebuffer.h" +#include "renderbuffer.h" + +#include "glamo_screen.h" +#include "glamo_context.h" + + +static int glamoInitDriver(__DRIscreenPrivate *psp) +{ + return 0; +} + + +static glamoScreenPtr glamoCreateScreen(__DRIscreenPrivate *sPriv) +{ + glamoScreenPtr glamoScreen; + + /* Allocate the private area */ + glamoScreen = (glamoScreenPtr)CALLOC(sizeof(*glamoScreen)); + if ( glamoScreen == NULL ) + return NULL; + + glamoScreen->driScreen = sPriv; + + /* parse information in __driConfigOptions */ +// driParseOptionInfo(&glamoScreen->optionCache, +// __driConfigOptions, __driNConfigOptions); + + return glamoScreen; +} + + +static void glamoDestroyScreen(__DRIscreenPrivate *sPriv) +{ + glamoScreenPtr glamoScreen = (glamoScreenPtr)sPriv->private; + + if ( glamoScreen == NULL ) + return; + + FREE(glamoScreen); + sPriv->private = NULL; +} + + +static const __DRIconfig **glamoInitScreen(__DRIscreenPrivate *sPriv) +{ + __DRIconfig **configs; + uint8_t depth_bits_array[2]; + uint8_t stencil_bits_array[2]; + static const GLenum db_modes[] = { GLX_SWAP_COPY_OML, GLX_NONE }; + + /* Driver initialisation */ + if ( glamoInitDriver(sPriv) ) { + return NULL; + } + + /* Screen-specific initialisation */ + sPriv->private = glamoCreateScreen(sPriv); + if ( !sPriv->private ) { + glamoDestroyScreen(sPriv); + return NULL; + } + + depth_bits_array[0] = 0; + stencil_bits_array[0] = 0; + depth_bits_array[1] = 16; + stencil_bits_array[1] = 0; + + configs = driCreateConfigs(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, + depth_bits_array, stencil_bits_array, 2, + db_modes, 2); + + if ( configs == NULL ) { + fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__, __LINE__); + return NULL; + } + + return (const __DRIconfig **)configs; +} + + +static GLboolean glamoCreateBuffer(__DRIscreen *driScrnPriv, + __DRIdrawable *driDrawPriv, + const __GLcontextModes *glVis, + GLboolean pixmapBuffer) +{ + struct gl_framebuffer *fb; + + if ( pixmapBuffer ) + return GL_FALSE; /* not implemented */ + + fb = _mesa_create_framebuffer(glVis); + + _mesa_add_soft_renderbuffers(fb, + GL_FALSE, /* color */ + GL_FALSE, /* depth */ + glVis->stencilBits > 0, + glVis->accumRedBits > 0, + GL_FALSE, /* alpha */ + GL_FALSE /* aux */); + driDrawPriv->driverPrivate = (void *)fb; + + return (driDrawPriv->driverPrivate != NULL); +} + + +static void glamoDestroyBuffer(__DRIdrawable *driDrawPriv) +{ +} + + +static void glamoSwapBuffers(__DRIdrawable *driDrawPriv) +{ +} + + +/* + * Mesa entry points + * + * See src/mesa/drivers/dri/common/dri_util.h for information about these + */ +const struct __DriverAPIRec driDriverAPI = { + .InitScreen = glamoInitScreen, + .DestroyScreen = glamoDestroyScreen, + .CreateContext = glamoCreateContext, + .DestroyContext = glamoDestroyContext, + .CreateBuffer = glamoCreateBuffer, + .DestroyBuffer = glamoDestroyBuffer, + .SwapBuffers = glamoSwapBuffers, + .MakeCurrent = glamoMakeCurrent, + .UnbindContext = glamoUnbindContext, + .GetSwapInfo = NULL, /* Not used */ + .WaitForMSC = NULL, + .WaitForSBC = NULL, + .SwapBuffersMSC = NULL, + .CopySubBuffer = NULL, + .GetDrawableMSC = NULL, /* Not used */ + .InitScreen2 = NULL /* For DRI2 */ +}; + +/* kate: space-indent on; indent-width 3; mixedindent off; indent-mode cstyle; */ diff --git a/src/mesa/drivers/dri/glamo/glamo_screen.h b/src/mesa/drivers/dri/glamo/glamo_screen.h new file mode 100644 index 0000000000..79ff949ad7 --- /dev/null +++ b/src/mesa/drivers/dri/glamo/glamo_screen.h @@ -0,0 +1,40 @@ +/* + * Direct Rendering Support for SMedia Glamo 336x/337x + * + * (c) 2009 Thomas White + * Roughly based on sis_screen.h (c) 2003 Eric Anholt + * + * 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, sublicense, + * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS 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 __GLAMO_SCREEN_H +#define __GLAMO_SCREEN_H + +#include "xmlconfig.h" +#include "dri_util.h" + +typedef struct { + + __DRIscreenPrivate *driScreen; + driOptionCache optionCache; + +} glamoScreenRec, *glamoScreenPtr; + +#endif /* __GLAMO_SCREEN_H */ + +/* kate: space-indent on; indent-width 3; mixedindent off; indent-mode cstyle; */ -- cgit v1.2.3