radeon/r200/r300: cleanup some of the renderbuffer code
authorDave Airlie <airlied@redhat.com>
Thu, 19 Mar 2009 05:31:03 +0000 (15:31 +1000)
committerDave Airlie <airlied@redhat.com>
Thu, 19 Mar 2009 05:31:03 +0000 (15:31 +1000)
src/mesa/drivers/dri/r200/r200_texstate.c
src/mesa/drivers/dri/r300/r300_texstate.c
src/mesa/drivers/dri/radeon/radeon_common.h
src/mesa/drivers/dri/radeon/radeon_common_context.c
src/mesa/drivers/dri/radeon/radeon_common_context.h
src/mesa/drivers/dri/radeon/radeon_lock.c
src/mesa/drivers/dri/radeon/radeon_screen.c
src/mesa/drivers/dri/radeon/radeon_texstate.c

index 4937b0665d1cfc6cdfd63b50a0ace5a36cb69f2d..058e0ee5bec394be4ae64eaa4da352e7351b8198 100644 (file)
@@ -806,7 +806,7 @@ void r200SetTexBuffer(__DRIcontext *pDRICtx, GLint target, __DRIdrawable *dPriv)
                radeon_bo_unref(rb->bo);
                rb->bo = NULL;
        }
-       rb = (void*)rfb->base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
+       rb = rfb->color_rb[0];
        if (rb->bo == NULL) {
                /* Failed to BO for the buffer */
                return;
index 2d7f392e7c8e36bf6b1158c0b430388295f4c169..14d470a11c01f8b3f66edfdaf8f23b8f8dfd62c9 100644 (file)
@@ -425,7 +425,7 @@ void r300SetTexBuffer(__DRIcontext *pDRICtx, GLint target, __DRIdrawable *dPriv)
                radeon_bo_unref(rb->bo);
                rb->bo = NULL;
        }
-       rb = (void*)rfb->base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
+       rb = rfb->color_rb[0];
        if (rb->bo == NULL) {
                /* Failed to BO for the buffer */
                return;
index 95b718184b742b683b496a424de30ad48c16ffc9..814da1b4f5bb52f0a66ec945cf309b0ae770c03a 100644 (file)
@@ -30,6 +30,23 @@ void radeonDrawBuffer( GLcontext *ctx, GLenum mode );
 void radeonReadBuffer( GLcontext *ctx, GLenum mode );
 void radeon_viewport(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height);
 
+static inline struct radeon_renderbuffer *radeon_renderbuffer(struct gl_renderbuffer *rb)
+{
+       struct radeon_renderbuffer *rrb = (struct radeon_renderbuffer *)rb;
+       if (rrb && rrb->base.ClassID == RADEON_RB_CLASS)
+               return rrb;
+       else
+               return NULL;
+}
+
+static inline struct radeon_renderbuffer *radeon_get_renderbuffer(struct gl_framebuffer *fb, int att_index)
+{
+       if (att_index >= 0)
+               return radeon_renderbuffer(fb->Attachment[att_index].Renderbuffer);
+       else
+               return NULL;
+}
+
 static inline struct radeon_renderbuffer *radeon_get_depthbuffer(radeonContextPtr rmesa)
 {
        struct radeon_renderbuffer *rrb;
@@ -47,7 +64,7 @@ static inline struct radeon_renderbuffer *radeon_get_colorbuffer(radeonContextPt
 
        rrb = rmesa->state.color.rrb;
        if (rmesa->radeonScreen->driScreen->dri2.enabled) {
-               rrb = (struct radeon_renderbuffer *)rfb->base.Attachment[BUFFER_BACK_LEFT].Renderbuffer;
+               rrb = radeon_get_renderbuffer(&rfb->base, BUFFER_BACK_LEFT);
        }
        if (!rrb)
                return NULL;
index b63aba2f8947c3d037bc83d7608edf638e2a0355..a818440faf87a715feb5f11f5527d71d6726a6d3 100644 (file)
@@ -183,33 +183,33 @@ void radeonCleanupContext(radeonContextPtr radeon)
        _mesa_destroy_context(radeon->glCtx);
        
        rfb = (void*)radeon->dri.drawable->driverPrivate;
-       rb = (void *)rfb->base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
+       rb = rfb->color_rb[0];
        if (rb && rb->bo) {
                radeon_bo_unref(rb->bo);
                rb->bo = NULL;
        }
-       rb = (void *)rfb->base.Attachment[BUFFER_BACK_LEFT].Renderbuffer;
+       rb = rfb->color_rb[1];
        if (rb && rb->bo) {
                radeon_bo_unref(rb->bo);
                rb->bo = NULL;
        }
-       rb = (void *)rfb->base.Attachment[BUFFER_DEPTH].Renderbuffer;
+       rb = radeon_get_renderbuffer(&rfb->base, BUFFER_DEPTH);
        if (rb && rb->bo) {
                radeon_bo_unref(rb->bo);
                rb->bo = NULL;
        }
        rfb = (void*)radeon->dri.readable->driverPrivate;
-       rb = (void *)rfb->base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
+       rb = rfb->color_rb[0];
        if (rb && rb->bo) {
                radeon_bo_unref(rb->bo);
                rb->bo = NULL;
        }
-       rb = (void *)rfb->base.Attachment[BUFFER_BACK_LEFT].Renderbuffer;
+       rb = rfb->color_rb[1];
        if (rb && rb->bo) {
                radeon_bo_unref(rb->bo);
                rb->bo = NULL;
        }
-       rb = (void *)rfb->base.Attachment[BUFFER_DEPTH].Renderbuffer;
+       rb = radeon_get_renderbuffer(&rfb->base, BUFFER_DEPTH);
        if (rb && rb->bo) {
                radeon_bo_unref(rb->bo);
                rb->bo = NULL;
@@ -391,6 +391,7 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
        int i, count;
        struct radeon_framebuffer *draw;
        radeonContextPtr radeon;
+       char *regname;
 
        if (RADEON_DEBUG & DEBUG_DRI)
            fprintf(stderr, "enter %s, drawable %p\n", __func__, drawable);
@@ -399,15 +400,14 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
        screen = context->driScreenPriv;
        radeon = (radeonContextPtr) context->driverPrivate;
        i = 0;
-       if ((rb = (void *)draw->base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer)) {
+       if (draw->color_rb[0])
                attachments[i++] = __DRI_BUFFER_FRONT_LEFT;
-       }
-       if ((rb = (void *)draw->base.Attachment[BUFFER_BACK_LEFT].Renderbuffer)) {
+       if (draw->color_rb[1])
                attachments[i++] = __DRI_BUFFER_BACK_LEFT;
-       }
-       if ((rb = (void *)draw->base.Attachment[BUFFER_DEPTH].Renderbuffer)) {
+       if (radeon_get_renderbuffer(&draw->base, BUFFER_DEPTH))
                attachments[i++] = __DRI_BUFFER_DEPTH;
-       }
+       if (radeon_get_renderbuffer(&draw->base, BUFFER_STENCIL))
+               attachments[i++] = __DRI_BUFFER_STENCIL;
        
        buffers = (*screen->dri2.loader->getBuffers)(drawable,
                                                     &drawable->w,
@@ -436,64 +436,20 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
        for (i = 0; i < count; i++) {
                switch (buffers[i].attachment) {
                case __DRI_BUFFER_FRONT_LEFT:
-                       rb = (void *)draw->base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
-                       if (rb->bo) {
-                               radeon_bo_unref(rb->bo);
-                               rb->bo = NULL;
-                       }
-                       rb->cpp = buffers[i].cpp;
-                       rb->pitch = buffers[i].pitch;
-                       rb->width = drawable->w;
-                       rb->height = drawable->h;
-                       rb->has_surface = 0;
-                       rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
-                                               buffers[i].name,
-                                               0,
-                                               0,
-                                               RADEON_GEM_DOMAIN_VRAM,
-                                               buffers[i].flags);
-                       if (rb->bo == NULL) {
-                               fprintf(stderr, "failled to attach front %d\n",
-                                       buffers[i].name);
-                       }
+                       rb = draw->color_rb[0];
+                       regname = "dri2 front buffer";
                        break;
                case __DRI_BUFFER_BACK_LEFT:
-                       rb = (void *)draw->base.Attachment[BUFFER_BACK_LEFT].Renderbuffer;
-                       if (rb->bo) {
-                               radeon_bo_unref(rb->bo);
-                               rb->bo = NULL;
-                       }
-                       rb->cpp = buffers[i].cpp;
-                       rb->pitch = buffers[i].pitch;
-                       rb->width = drawable->w;
-                       rb->height = drawable->h;
-                       rb->has_surface = 0;
-                       rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
-                                               buffers[i].name,
-                                               0,
-                                               0,
-                                               RADEON_GEM_DOMAIN_VRAM,
-                                               buffers[i].flags);
+                       rb = draw->color_rb[1];
+                       regname = "dri2 back buffer";
                        break;
                case __DRI_BUFFER_DEPTH:
-                       rb = (void *)draw->base.Attachment[BUFFER_DEPTH].Renderbuffer;
-                       if (rb->bo) {
-                               radeon_bo_unref(rb->bo);
-                               rb->bo = NULL;
-                       }
-                       rb->cpp = buffers[i].cpp;
-                       rb->pitch = buffers[i].pitch;
-                       rb->width = drawable->w;
-                       rb->height = drawable->h;
-                       rb->has_surface = 0;
-                       rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
-                                               buffers[i].name,
-                                               0,
-                                               0,
-                                               RADEON_GEM_DOMAIN_VRAM,
-                                               buffers[i].flags);
+                       rb = radeon_get_renderbuffer(&draw->base, BUFFER_DEPTH);
+                       regname = "dri2 depth buffer";
                        break;
                case __DRI_BUFFER_STENCIL:
+                       rb = radeon_get_renderbuffer(&draw->base, BUFFER_DEPTH);
+                       regname = "dri2 stencil buffer";
                        break;
                case __DRI_BUFFER_ACCUM:
                default:
@@ -502,8 +458,32 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
                                buffers[i].attachment);
                        return;
                }
+
+               if (rb == NULL)
+                       continue;
+
+               if (rb->bo) {
+                       radeon_bo_unref(rb->bo);
+                       rb->bo = NULL;
+               }
+               rb->cpp = buffers[i].cpp;
+               rb->pitch = buffers[i].pitch;
+               rb->width = drawable->w;
+               rb->height = drawable->h;
+               rb->has_surface = 0;
+               rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
+                                       buffers[i].name,
+                                       0,
+                                       0,
+                                       RADEON_GEM_DOMAIN_VRAM,
+                                       buffers[i].flags);
+               if (rb->bo == NULL) {
+                       fprintf(stderr, "failed to attach %s %d\n",
+                               regname, buffers[i].name);
+
+               }
        }
-       radeon = (radeonContextPtr) context->driverPrivate;
+
        driUpdateFramebufferSize(radeon->glCtx, drawable);
 }
 
@@ -534,9 +514,9 @@ GLboolean radeonMakeCurrent(__DRIcontextPrivate * driContextPriv,
                if (driDrawPriv != driReadPriv)
                        radeon_update_renderbuffers(driContextPriv, driReadPriv);
                radeon->state.color.rrb =
-                       (void *)drfb->base.Attachment[BUFFER_BACK_LEFT].Renderbuffer;
+                       radeon_get_renderbuffer(&drfb->base, BUFFER_BACK_LEFT);
                radeon->state.depth.rrb =
-                       (void *)drfb->base.Attachment[BUFFER_DEPTH].Renderbuffer;
+                       radeon_get_renderbuffer(&drfb->base, BUFFER_DEPTH);
        } else {
                radeon_make_renderbuffer_current(radeon, drfb);
        }
index 4aeb50fe68e5652b9f126bb6d08ccfe3110ce43a..e5ada622b0facf2e0b4925b417fe50dded089c6f 100644 (file)
@@ -70,6 +70,8 @@ typedef struct radeon_context *radeonContextPtr;
 #include "tnl_dd/t_dd_vertex.h"
 #undef TAG
 
+#define RADEON_RB_CLASS 0xdeadbeef
+
 struct radeon_renderbuffer
 {
        struct gl_renderbuffer base;
index fb9e5e025ead02a1ca813d252661078127095e16..e1bb2cd6e21629b29f22c36702b950f1a6440d90 100644 (file)
@@ -90,15 +90,6 @@ void radeonGetLock(radeonContextPtr rmesa, GLuint flags)
        rmesa->lost_context = GL_TRUE;
 }
 
-static INLINE struct radeon_renderbuffer *
-radeon_get_renderbuffer(struct gl_framebuffer *fb, int attIndex)
-{
-       if (attIndex >= 0)
-               return (struct radeon_renderbuffer *)fb->Attachment[attIndex].Renderbuffer;
-       else
-               return NULL;
-}
-
 void radeon_lock_hardware(radeonContextPtr radeon)
 {
        __DRIdrawable *dPriv = radeon->dri.drawable;
index e90dffd7669a95c55de6a16df7e22a3a3447340f..02101978ac4ce38e7ac4284e63a37b82e6cb56a2 100644 (file)
@@ -1197,6 +1197,7 @@ radeon_create_renderbuffer(GLenum format, __DRIdrawablePrivate *driDrawPriv)
        return NULL;
 
     _mesa_init_renderbuffer(&ret->base, 0);
+    ret->base.ClassID = RADEON_RB_CLASS;
 
     /* XXX format junk */
     switch (format) {
index 06771a359b9fd5a6c558b1fadab79dd58a918732..b9adab18d491e493b0cfe4e943e2de7f6aee1b91 100644 (file)
@@ -678,7 +678,7 @@ void radeonSetTexBuffer(__DRIcontext *pDRICtx, GLint target, __DRIdrawable *dPri
                radeon_bo_unref(rb->bo);
                rb->bo = NULL;
        }
-       rb = (void*)rfb->base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
+       rb = rfb->color_rb[0];
        if (rb->bo == NULL) {
                /* Failed to BO for the buffer */
                return;