intel: Allow src == NULL and *dst != NULL in intel_miptree_reference().
authorEric Anholt <eric@anholt.net>
Wed, 21 Sep 2011 22:38:32 +0000 (15:38 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 26 Sep 2011 22:33:42 +0000 (15:33 -0700)
This makes this API consistent with intel_region_reference, and the
consumers wanted it this way.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/intel/intel_mipmap_tree.c
src/mesa/drivers/dri/intel/intel_tex_image.c
src/mesa/drivers/dri/intel/intel_tex_validate.c

index fb4695ce6357e8282fa9f8cff16bb32f2f42ef3f..8289c398ff175e37e2a27570706947ab9a46b03a 100644 (file)
@@ -173,9 +173,17 @@ void
 intel_miptree_reference(struct intel_mipmap_tree **dst,
                         struct intel_mipmap_tree *src)
 {
-   src->refcount++;
+   if (*dst == src)
+      return;
+
+   intel_miptree_release(dst);
+
+   if (src) {
+      src->refcount++;
+      DBG("%s %p refcount now %d\n", __FUNCTION__, src, src->refcount);
+   }
+
    *dst = src;
-   DBG("%s %p refcount now %d\n", __FUNCTION__, src, src->refcount);
 }
 
 
index 69da0e25d1ff9d4cb5cd108962cbe1e7301744f3..30c3cfbafd941ede1911bc0d05187b39e42ed5bb 100644 (file)
@@ -370,8 +370,6 @@ intelTexImage(struct gl_context * ctx,
       }
    }
 
-   assert(!intelImage->mt);
-
    if (intelObj->mt &&
        intel_miptree_match_image(intelObj->mt, &intelImage->base.Base)) {
       /* Use an existing miptree when possible */
@@ -391,10 +389,7 @@ intelTexImage(struct gl_context * ctx,
        * whole object since our level didn't fit what was there
        * before, and any lower levels would fit into our miptree.
        */
-      if (intelImage->mt) {
-        intel_miptree_release(&intelObj->mt);
-        intel_miptree_reference(&intelObj->mt, intelImage->mt);
-      }
+      intel_miptree_reference(&intelObj->mt, intelImage->mt);
    }
 
    /* Attempt to use the blitter for PBO image uploads.
index 59354d66e34f1861c085e66cb413f3edd8f14c92..137910816f5b95344e80c174365f527df6d4762b 100644 (file)
@@ -43,8 +43,6 @@ copy_image_data_to_tree(struct intel_context *intel,
                                intelObj->mt,
                                intelImage->base.Base.Face,
                                intelImage->base.Base.Level, intelImage->mt);
-
-      intel_miptree_release(&intelImage->mt);
    }
    else {
       assert(intelImage->base.Base.Data != NULL);