dri/swrast: port to dri_sw (drawable)
authorGeorge Sapountzis <gsapountzis@gmail.com>
Sun, 14 Mar 2010 09:36:46 +0000 (11:36 +0200)
committerGeorge Sapountzis <gsapountzis@gmail.com>
Sun, 14 Mar 2010 23:17:17 +0000 (01:17 +0200)
src/mesa/drivers/dri/common/dri_sw.h
src/mesa/drivers/dri/swrast/swrast.c
src/mesa/drivers/dri/swrast/swrast_priv.h
src/mesa/drivers/dri/swrast/swrast_spantemp.h

index 93e9624654876cdb486775b9480e6d9d57d27599..89369a9d00e82e54fc3af5761b244a6e6728bf78 100644 (file)
@@ -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;
 };
 
 
index 8273439fef3e4318e9286a47136dbcd6a350b65b..4450e470c6445f3fe29da9f4f76401c8254b7cfc 100644 (file)
@@ -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()
index 130598bbd81c12165767ea1bb7880143ef46c567..8e87f644c393d6f68ff56cb3e917570b034304be 100644 (file)
@@ -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)
 {
index c73b785683ef1ddee5873b1782e5be82f4e856f4..079726ae4abfc2488da04ad1b34d432281587f9f 100644 (file)
@@ -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;