radeon: fixup render buffer cleanups
authorDave Airlie <airlied@redhat.com>
Wed, 1 Apr 2009 05:41:58 +0000 (15:41 +1000)
committerDave Airlie <airlied@redhat.com>
Wed, 1 Apr 2009 05:41:58 +0000 (15:41 +1000)
this fixes qtdemo-qt4 starting and a leak in glxgears exit

src/mesa/drivers/dri/radeon/radeon_common_context.c
src/mesa/drivers/dri/radeon/radeon_screen.c
src/mesa/drivers/dri/radeon/radeon_screen.h

index 5766c9ec7bcfed33d71472804466ba3d1c438cb9..9103c8c0f669a634d2a5a4b372d465c38388d00e 100644 (file)
@@ -37,6 +37,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "utils.h"
 #include "vblank.h"
 #include "drirenderbuffer.h"
+#include "main/framebuffer.h"
 #include "main/state.h"
 
 #define DRIVER_DATE "20090101"
@@ -183,45 +184,14 @@ void radeonCleanupContext(radeonContextPtr radeon)
 #ifdef RADEON_BO_TRACK
        FILE *track;
 #endif
-       struct radeon_renderbuffer *rb;
        struct radeon_framebuffer *rfb;
 
+       radeonDestroyBuffer(radeon->dri.drawable);
+       radeonDestroyBuffer(radeon->dri.readable);
+
        /* free the Mesa context */
        _mesa_destroy_context(radeon->glCtx);
-       
-       rfb = (void*)radeon->dri.drawable->driverPrivate;
-       rb = rfb->color_rb[0];
-       if (rb && rb->bo) {
-               radeon_bo_unref(rb->bo);
-               rb->bo = NULL;
-       }
-       rb = rfb->color_rb[1];
-       if (rb && rb->bo) {
-               radeon_bo_unref(rb->bo);
-               rb->bo = NULL;
-       }
-       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 = rfb->color_rb[0];
-       if (rb && rb->bo) {
-               radeon_bo_unref(rb->bo);
-               rb->bo = NULL;
-       }
-       rb = rfb->color_rb[1];
-       if (rb && rb->bo) {
-               radeon_bo_unref(rb->bo);
-               rb->bo = NULL;
-       }
-       rb = radeon_get_renderbuffer(&rfb->base, BUFFER_DEPTH);
-       if (rb && rb->bo) {
-               radeon_bo_unref(rb->bo);
-               rb->bo = NULL;
-       }
-       
+
        /* _mesa_destroy_context() might result in calls to functions that
         * depend on the DriverCtx, so don't set it to NULL before.
         *
index 98fa1417f9adf2e851d1530893ce2d7e7e78ef25..ea400a672ddf3d4e3a8aaba03beb4c77398b170f 100644 (file)
@@ -1296,28 +1296,39 @@ radeonCreateBuffer( __DRIscreenPrivate *driScrnPriv,
     return (driDrawPriv->driverPrivate != NULL);
 }
 
-static void
+
+static void radeon_cleanup_renderbuffers(struct radeon_framebuffer *rfb)
+{
+       struct radeon_renderbuffer *rb;
+
+       rb = rfb->color_rb[0];
+       if (rb && rb->bo) {
+               radeon_bo_unref(rb->bo);
+               rb->bo = NULL;
+       }
+       rb = rfb->color_rb[1];
+       if (rb && rb->bo) {
+               radeon_bo_unref(rb->bo);
+               rb->bo = NULL;
+       }
+       rb = radeon_get_renderbuffer(&rfb->base, BUFFER_DEPTH);
+       if (rb && rb->bo) {
+               radeon_bo_unref(rb->bo);
+               rb->bo = NULL;
+       }
+}
+
+void
 radeonDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-    struct radeon_renderbuffer *rb;
     struct radeon_framebuffer *rfb;
-    
+    if (!driDrawPriv)
+       return;
+
     rfb = (void*)driDrawPriv->driverPrivate;
-    rb = (void *)rfb->base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
-    if (rb && rb->bo) {
-        radeon_bo_unref(rb->bo);
-        rb->bo = NULL;
-    }
-    rb = (void *)rfb->base.Attachment[BUFFER_BACK_LEFT].Renderbuffer;
-    if (rb && rb->bo) {
-        radeon_bo_unref(rb->bo);
-        rb->bo = NULL;
-    }
-    rb = (void *)rfb->base.Attachment[BUFFER_DEPTH].Renderbuffer;
-    if (rb && rb->bo) {
-        radeon_bo_unref(rb->bo);
-        rb->bo = NULL;
-    }
+    if (!rfb)
+       return;
+    radeon_cleanup_renderbuffers(rfb);
     _mesa_reference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)), NULL);
 }
 
index 1c0f5bb9bc7db468b38a26dea1a16f2dd0606b05..8605eb4f0756486b43a905d1a895430992cbcc2a 100644 (file)
@@ -118,4 +118,5 @@ typedef struct radeon_screen {
 #define IS_R300_CLASS(screen) \
        ((screen->chip_flags & RADEON_CLASS_MASK) == RADEON_CLASS_R300)
 
+extern void radeonDestroyBuffer(__DRIdrawablePrivate *driDrawPriv);
 #endif /* __RADEON_SCREEN_H__ */