From 06ebc46e65d7dea6f146db85150021814d2439bf Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Sun, 14 Mar 2010 11:36:45 +0200 Subject: dri: add dri_sw.c helper This is dri_util.c stripped from the drm-specific bits and will be used for both classic and gallium swrast_dri.so --- src/mesa/drivers/dri/common/dri_sw.h | 115 +++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/mesa/drivers/dri/common/dri_sw.h (limited to 'src/mesa/drivers/dri/common/dri_sw.h') diff --git a/src/mesa/drivers/dri/common/dri_sw.h b/src/mesa/drivers/dri/common/dri_sw.h new file mode 100644 index 0000000000..b7257b14a2 --- /dev/null +++ b/src/mesa/drivers/dri/common/dri_sw.h @@ -0,0 +1,115 @@ +/* + * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. + * All Rights Reserved. + * Copyright 2010 George Sapountzis + * + * 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 + * BRIAN PAUL 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 _DRI_SW_H +#define _DRI_SW_H + +#include +#include +#include "main/mtypes.h" + + +/** + * Extensions + */ +extern const __DRIcoreExtension driCoreExtension; +extern const __DRIswrastExtension driSWRastExtension; + + +/** + * Data types + */ +struct __DRIscreenRec { + int myNum; + + int fd; + + void *private; + + const __DRIextension **extensions; + + const __DRIswrastLoaderExtension *swrast_loader; +}; + +struct __DRIcontextRec { + + GLcontext Base; + + void *loaderPrivate; + + __DRIdrawable *driDrawablePriv; + + __DRIdrawable *driReadablePriv; + + __DRIscreen *driScreenPriv; +}; + +struct __DRIdrawableRec { + + GLframebuffer Base; + + void *loaderPrivate; + + __DRIscreen *driScreenPriv; + + int refcount; + + /* scratch row for optimized front-buffer rendering */ + char *row; +}; + + +/** + * Driver callback functions + */ +struct __DriverAPIRec { + const __DRIconfig **(*InitScreen) (__DRIscreen * priv); + + void (*DestroyScreen)(__DRIscreen *driScrnPriv); + + GLboolean (*CreateContext)(const __GLcontextModes *glVis, + __DRIcontext *driContextPriv, + void *sharedContextPrivate); + + void (*DestroyContext)(__DRIcontext *driContextPriv); + + GLboolean (*CreateBuffer)(__DRIscreen *driScrnPriv, + __DRIdrawable *driDrawPriv, + const __GLcontextModes *glVis, + GLboolean pixmapBuffer); + + void (*DestroyBuffer)(__DRIdrawable *driDrawPriv); + + void (*SwapBuffers)(__DRIdrawable *driDrawPriv); + + GLboolean (*MakeCurrent)(__DRIcontext *driContextPriv, + __DRIdrawable *driDrawPriv, + __DRIdrawable *driReadPriv); + + GLboolean (*UnbindContext)(__DRIcontext *driContextPriv); +}; + +extern const struct __DriverAPIRec driDriverAPI; + +#endif /* _DRI_SW_H */ -- cgit v1.2.3 From cf8a1caa231b748d3ba7c776ab076ad3de99e963 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Sun, 14 Mar 2010 11:36:45 +0200 Subject: dri/swrast: port to dri_sw (context) --- src/mesa/drivers/dri/common/dri_sw.c | 2 +- src/mesa/drivers/dri/common/dri_sw.h | 2 +- src/mesa/drivers/dri/swrast/swrast.c | 41 ++++++++++++++++++++------- src/mesa/drivers/dri/swrast/swrast_priv.h | 27 ++++++++++++++---- src/mesa/drivers/dri/swrast/swrast_spantemp.h | 8 +++--- 5 files changed, 58 insertions(+), 22 deletions(-) (limited to 'src/mesa/drivers/dri/common/dri_sw.h') diff --git a/src/mesa/drivers/dri/common/dri_sw.c b/src/mesa/drivers/dri/common/dri_sw.c index 4b87a7f32f..b7f9036f47 100644 --- a/src/mesa/drivers/dri/common/dri_sw.c +++ b/src/mesa/drivers/dri/common/dri_sw.c @@ -99,7 +99,7 @@ driCreateNewContext(__DRIscreen *psp, const __DRIconfig *config, __DRIcontext *shared, void *data) { __DRIcontext *pcp; - void * const shareCtx = (shared != NULL) ? &shared->Base : NULL; + void * const shareCtx = (shared != NULL) ? shared->driverPrivate : NULL; pcp = CALLOC_STRUCT(__DRIcontextRec); if (!pcp) diff --git a/src/mesa/drivers/dri/common/dri_sw.h b/src/mesa/drivers/dri/common/dri_sw.h index b7257b14a2..93e9624654 100644 --- a/src/mesa/drivers/dri/common/dri_sw.h +++ b/src/mesa/drivers/dri/common/dri_sw.h @@ -54,7 +54,7 @@ struct __DRIscreenRec { struct __DRIcontextRec { - GLcontext Base; + void *driverPrivate; void *loaderPrivate; diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c index 8c858ab2da..8273439fef 100644 --- a/src/mesa/drivers/dri/swrast/swrast.c +++ b/src/mesa/drivers/dri/swrast/swrast.c @@ -474,25 +474,36 @@ static GLboolean dri_create_context(const __GLcontextModes * visual, __DRIcontext * cPriv, void *sharedContextPrivate) { - GLcontext *mesaCtx; - GLcontext *sharedCtx; + struct dri_context *ctx = NULL; + struct dri_context *share = (struct dri_context *)sharedContextPrivate; + GLcontext *mesaCtx = NULL; + GLcontext *sharedCtx = NULL; struct dd_function_table functions; TRACE; + ctx = CALLOC_STRUCT(dri_context); + if (ctx == NULL) + goto context_fail; + + cPriv->driverPrivate = ctx; + ctx->cPriv = cPriv; + /* build table of device driver functions */ _mesa_init_driver_functions(&functions); swrast_init_driver_functions(&functions); - sharedCtx = sharedContextPrivate; + if (share) { + sharedCtx = &share->Base; + } + + mesaCtx = &ctx->Base; /* basic context setup */ - if (!_mesa_initialize_context(&cPriv->Base, visual, sharedCtx, &functions, (void *) cPriv)) { - return GL_FALSE; + if (!_mesa_initialize_context(mesaCtx, visual, sharedCtx, &functions, (void *) cPriv)) { + goto context_fail; } - mesaCtx = &cPriv->Base; - /* do bounds checking to prevent segfaults and server crashes! */ mesaCtx->Const.CheckArrayBounds = GL_TRUE; @@ -521,16 +532,24 @@ dri_create_context(const __GLcontextModes * visual, driInitExtensions( mesaCtx, NULL, GL_FALSE ); return GL_TRUE; + +context_fail: + + FREE(ctx); + + return GL_FALSE; } static void dri_destroy_context(__DRIcontext * cPriv) { - GLcontext *mesaCtx; TRACE; if (cPriv) { - mesaCtx = &cPriv->Base; + struct dri_context *ctx = dri_context(cPriv); + GLcontext *mesaCtx; + + mesaCtx = &ctx->Base; _mesa_meta_free(mesaCtx); _swsetup_DestroyContext( mesaCtx ); @@ -552,10 +571,12 @@ dri_make_current(__DRIcontext * cPriv, TRACE; if (cPriv) { + struct dri_context *ctx = dri_context(cPriv); + if (!driDrawPriv || !driReadPriv) return GL_FALSE; - mesaCtx = &cPriv->Base; + mesaCtx = &ctx->Base; mesaDraw = &driDrawPriv->Base; mesaRead = &driReadPriv->Base; diff --git a/src/mesa/drivers/dri/swrast/swrast_priv.h b/src/mesa/drivers/dri/swrast/swrast_priv.h index c83c64b487..130598bbd8 100644 --- a/src/mesa/drivers/dri/swrast/swrast_priv.h +++ b/src/mesa/drivers/dri/swrast/swrast_priv.h @@ -59,6 +59,27 @@ /** * Data types */ +struct dri_context +{ + /* mesa */ + GLcontext Base; + + /* dri */ + __DRIcontext *cPriv; +}; + +static INLINE struct dri_context * +dri_context(__DRIcontext * driContextPriv) +{ + return (struct dri_context *)driContextPriv->driverPrivate; +} + +static INLINE struct dri_context * +swrast_context(GLcontext *ctx) +{ + return (struct dri_context *) ctx; +} + struct swrast_renderbuffer { struct gl_renderbuffer Base; @@ -68,12 +89,6 @@ struct swrast_renderbuffer { GLuint bpp; }; -static INLINE __DRIcontext * -swrast_context(GLcontext *ctx) -{ - return (__DRIcontext *) ctx; -} - static INLINE __DRIdrawable * swrast_drawable(GLframebuffer *fb) { diff --git a/src/mesa/drivers/dri/swrast/swrast_spantemp.h b/src/mesa/drivers/dri/swrast/swrast_spantemp.h index 879a0c12e7..c73b785683 100644 --- a/src/mesa/drivers/dri/swrast/swrast_spantemp.h +++ b/src/mesa/drivers/dri/swrast/swrast_spantemp.h @@ -39,7 +39,7 @@ static INLINE void PUT_PIXEL( GLcontext *glCtx, GLint x, GLint y, GLubyte *p ) { - __DRIcontext *ctx = swrast_context(glCtx); + __DRIcontext *ctx = swrast_context(glCtx)->cPriv; __DRIdrawable *draw = swrast_drawable(glCtx->DrawBuffer); __DRIscreen *screen = ctx->driScreenPriv; @@ -53,7 +53,7 @@ PUT_PIXEL( GLcontext *glCtx, GLint x, GLint y, GLubyte *p ) static INLINE void GET_PIXEL( GLcontext *glCtx, GLint x, GLint y, GLubyte *p ) { - __DRIcontext *ctx = swrast_context(glCtx); + __DRIcontext *ctx = swrast_context(glCtx)->cPriv; __DRIdrawable *read = swrast_drawable(glCtx->ReadBuffer); __DRIscreen *screen = ctx->driScreenPriv; @@ -65,7 +65,7 @@ GET_PIXEL( GLcontext *glCtx, GLint x, GLint y, GLubyte *p ) static INLINE void PUT_ROW( GLcontext *glCtx, GLint x, GLint y, GLuint n, char *row ) { - __DRIcontext *ctx = swrast_context(glCtx); + __DRIcontext *ctx = swrast_context(glCtx)->cPriv; __DRIdrawable *draw = swrast_drawable(glCtx->DrawBuffer); __DRIscreen *screen = ctx->driScreenPriv; @@ -78,7 +78,7 @@ PUT_ROW( GLcontext *glCtx, GLint x, GLint y, GLuint n, char *row ) static INLINE void GET_ROW( GLcontext *glCtx, GLint x, GLint y, GLuint n, char *row ) { - __DRIcontext *ctx = swrast_context(glCtx); + __DRIcontext *ctx = swrast_context(glCtx)->cPriv; __DRIdrawable *read = swrast_drawable(glCtx->ReadBuffer); __DRIscreen *screen = ctx->driScreenPriv; -- cgit v1.2.3 From c1bde793598bcb5d5f8744c290a66ea6586eb29f Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Sun, 14 Mar 2010 11:36:46 +0200 Subject: dri/swrast: port to dri_sw (drawable) --- src/mesa/drivers/dri/common/dri_sw.h | 5 +--- src/mesa/drivers/dri/swrast/swrast.c | 39 +++++++++++++++++++++------ src/mesa/drivers/dri/swrast/swrast_priv.h | 30 ++++++++++++++++----- src/mesa/drivers/dri/swrast/swrast_spantemp.h | 8 +++--- 4 files changed, 60 insertions(+), 22 deletions(-) (limited to 'src/mesa/drivers/dri/common/dri_sw.h') diff --git a/src/mesa/drivers/dri/common/dri_sw.h b/src/mesa/drivers/dri/common/dri_sw.h index 93e9624654..89369a9d00 100644 --- a/src/mesa/drivers/dri/common/dri_sw.h +++ b/src/mesa/drivers/dri/common/dri_sw.h @@ -67,16 +67,13 @@ struct __DRIcontextRec { struct __DRIdrawableRec { - GLframebuffer Base; + void *driverPrivate; void *loaderPrivate; __DRIscreen *driScreenPriv; int refcount; - - /* scratch row for optimized front-buffer rendering */ - char *row; }; diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c index 8273439fef..4450e470c6 100644 --- a/src/mesa/drivers/dri/swrast/swrast.c +++ b/src/mesa/drivers/dri/swrast/swrast.c @@ -308,14 +308,24 @@ dri_create_buffer(__DRIscreen * sPriv, __DRIdrawable * dPriv, const __GLcontextModes * visual, GLboolean isPixmap) { + struct dri_drawable *drawable = NULL; GLframebuffer *fb; struct swrast_renderbuffer *frontrb, *backrb; TRACE; - fb = &dPriv->Base; + drawable = CALLOC_STRUCT(dri_drawable); + if (drawable == NULL) + goto drawable_fail; - dPriv->row = malloc(MAX_WIDTH * 4); + dPriv->driverPrivate = drawable; + drawable->dPriv = dPriv; + + drawable->row = malloc(MAX_WIDTH * 4); + if (drawable->row == NULL) + goto drawable_fail; + + fb = &drawable->Base; /* basic framebuffer setup */ _mesa_initialize_window_framebuffer(fb, visual); @@ -340,6 +350,15 @@ dri_create_buffer(__DRIscreen * sPriv, GL_FALSE /* aux bufs */); return GL_TRUE; + +drawable_fail: + + if (drawable) + free(drawable->row); + + FREE(drawable); + + return GL_FALSE; } static void @@ -348,11 +367,12 @@ dri_destroy_buffer(__DRIdrawable * dPriv) TRACE; if (dPriv) { + struct dri_drawable *drawable = dri_drawable(dPriv); GLframebuffer *fb; - free(dPriv->row); + free(drawable->row); - fb = &dPriv->Base; + fb = &drawable->Base; fb->DeletePending = GL_TRUE; _mesa_reference_framebuffer(&fb, NULL); @@ -366,12 +386,13 @@ dri_swap_buffers(__DRIdrawable * dPriv) GET_CURRENT_CONTEXT(ctx); + struct dri_drawable *drawable = dri_drawable(dPriv); GLframebuffer *fb; struct swrast_renderbuffer *frontrb, *backrb; TRACE; - fb = &dPriv->Base; + fb = &drawable->Base; frontrb = swrast_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer); backrb = swrast_renderbuffer(fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer); @@ -402,7 +423,7 @@ dri_swap_buffers(__DRIdrawable * dPriv) static void get_window_size( GLframebuffer *fb, GLsizei *w, GLsizei *h ) { - __DRIdrawable *dPriv = swrast_drawable(fb); + __DRIdrawable *dPriv = swrast_drawable(fb)->dPriv; __DRIscreen *sPriv = dPriv->driScreenPriv; int x, y; @@ -572,13 +593,15 @@ dri_make_current(__DRIcontext * cPriv, if (cPriv) { struct dri_context *ctx = dri_context(cPriv); + struct dri_drawable *draw = dri_drawable(driDrawPriv); + struct dri_drawable *read = dri_drawable(driReadPriv); if (!driDrawPriv || !driReadPriv) return GL_FALSE; mesaCtx = &ctx->Base; - mesaDraw = &driDrawPriv->Base; - mesaRead = &driReadPriv->Base; + mesaDraw = &draw->Base; + mesaRead = &read->Base; /* check for same context and buffer */ if (mesaCtx == _mesa_get_current_context() diff --git a/src/mesa/drivers/dri/swrast/swrast_priv.h b/src/mesa/drivers/dri/swrast/swrast_priv.h index 130598bbd8..8e87f644c3 100644 --- a/src/mesa/drivers/dri/swrast/swrast_priv.h +++ b/src/mesa/drivers/dri/swrast/swrast_priv.h @@ -80,6 +80,30 @@ swrast_context(GLcontext *ctx) return (struct dri_context *) ctx; } +struct dri_drawable +{ + /* mesa */ + GLframebuffer Base; + + /* dri */ + __DRIdrawable *dPriv; + + /* scratch row for optimized front-buffer rendering */ + char *row; +}; + +static INLINE struct dri_drawable * +dri_drawable(__DRIdrawable * driDrawPriv) +{ + return (struct dri_drawable *)driDrawPriv->driverPrivate; +} + +static INLINE struct dri_drawable * +swrast_drawable(GLframebuffer *fb) +{ + return (struct dri_drawable *) fb; +} + struct swrast_renderbuffer { struct gl_renderbuffer Base; @@ -89,12 +113,6 @@ struct swrast_renderbuffer { GLuint bpp; }; -static INLINE __DRIdrawable * -swrast_drawable(GLframebuffer *fb) -{ - return (__DRIdrawable *) fb; -} - static INLINE struct swrast_renderbuffer * swrast_renderbuffer(struct gl_renderbuffer *rb) { diff --git a/src/mesa/drivers/dri/swrast/swrast_spantemp.h b/src/mesa/drivers/dri/swrast/swrast_spantemp.h index c73b785683..079726ae4a 100644 --- a/src/mesa/drivers/dri/swrast/swrast_spantemp.h +++ b/src/mesa/drivers/dri/swrast/swrast_spantemp.h @@ -40,7 +40,7 @@ static INLINE void PUT_PIXEL( GLcontext *glCtx, GLint x, GLint y, GLubyte *p ) { __DRIcontext *ctx = swrast_context(glCtx)->cPriv; - __DRIdrawable *draw = swrast_drawable(glCtx->DrawBuffer); + __DRIdrawable *draw = swrast_drawable(glCtx->DrawBuffer)->dPriv; __DRIscreen *screen = ctx->driScreenPriv; @@ -54,7 +54,7 @@ static INLINE void GET_PIXEL( GLcontext *glCtx, GLint x, GLint y, GLubyte *p ) { __DRIcontext *ctx = swrast_context(glCtx)->cPriv; - __DRIdrawable *read = swrast_drawable(glCtx->ReadBuffer); + __DRIdrawable *read = swrast_drawable(glCtx->ReadBuffer)->dPriv; __DRIscreen *screen = ctx->driScreenPriv; @@ -66,7 +66,7 @@ static INLINE void PUT_ROW( GLcontext *glCtx, GLint x, GLint y, GLuint n, char *row ) { __DRIcontext *ctx = swrast_context(glCtx)->cPriv; - __DRIdrawable *draw = swrast_drawable(glCtx->DrawBuffer); + __DRIdrawable *draw = swrast_drawable(glCtx->DrawBuffer)->dPriv; __DRIscreen *screen = ctx->driScreenPriv; @@ -79,7 +79,7 @@ static INLINE void GET_ROW( GLcontext *glCtx, GLint x, GLint y, GLuint n, char *row ) { __DRIcontext *ctx = swrast_context(glCtx)->cPriv; - __DRIdrawable *read = swrast_drawable(glCtx->ReadBuffer); + __DRIdrawable *read = swrast_drawable(glCtx->ReadBuffer)->dPriv; __DRIscreen *screen = ctx->driScreenPriv; -- cgit v1.2.3 From e557c2e14f1481abff75af912feb5dce79a65ab8 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Sun, 14 Mar 2010 11:36:46 +0200 Subject: dri/swrast: drop mtypes.h from dri_sw --- src/mesa/drivers/dri/common/dri_sw.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mesa/drivers/dri/common/dri_sw.h') diff --git a/src/mesa/drivers/dri/common/dri_sw.h b/src/mesa/drivers/dri/common/dri_sw.h index 89369a9d00..e353e26b34 100644 --- a/src/mesa/drivers/dri/common/dri_sw.h +++ b/src/mesa/drivers/dri/common/dri_sw.h @@ -26,8 +26,8 @@ #define _DRI_SW_H #include +#include #include -#include "main/mtypes.h" /** -- cgit v1.2.3