Mesa (master): intel: Refactor use of intel_miptree_map

Chad Versace chadversary at kemper.freedesktop.org
Tue Aug 7 16:31:17 UTC 2012


Module: Mesa
Branch: master
Commit: 4c0ccc13bd3ec149c4a51c4937811894fbe713f0
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=4c0ccc13bd3ec149c4a51c4937811894fbe713f0

Author: Chad Versace <chad.versace at linux.intel.com>
Date:   Fri Jul 27 19:39:10 2012 -0700

intel: Refactor use of intel_miptree_map

Move the opencoded construction and destruction of intel_miptree_map into
new functions, intel_miptree_attach_map and intel_miptree_release_map.
This patch prevents code duplication in a future commit that adds support
for mapping multisample miptrees.

Reviewed-by: Eric Anholt <eric at anholt.net>
Signed-off-by: Chad Versace <chad.versace at linux.intel.com>

---

 src/mesa/drivers/dri/intel/intel_mipmap_tree.c |   65 ++++++++++++++++++------
 1 files changed, 50 insertions(+), 15 deletions(-)

diff --git a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
index 8be8d13..9b0b4f7 100644
--- a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
@@ -1448,6 +1448,52 @@ intel_miptree_unmap_depthstencil(struct intel_context *intel,
    free(map->buffer);
 }
 
+/**
+ * Create and attach a map to the miptree at (level, slice). Return the
+ * attached map.
+ */
+static struct intel_miptree_map*
+intel_miptree_attach_map(struct intel_mipmap_tree *mt,
+                         unsigned int level,
+                         unsigned int slice,
+                         unsigned int x,
+                         unsigned int y,
+                         unsigned int w,
+                         unsigned int h,
+                         GLbitfield mode)
+{
+   struct intel_miptree_map *map = calloc(1, sizeof(*map));
+
+   if (!map)
+      return NULL;
+
+   assert(mt->level[level].slice[slice].map == NULL);
+   mt->level[level].slice[slice].map = map;
+
+   map->mode = mode;
+   map->x = x;
+   map->y = y;
+   map->w = w;
+   map->h = h;
+
+   return map;
+}
+
+/**
+ * Release the map at (level, slice).
+ */
+static void
+intel_miptree_release_map(struct intel_mipmap_tree *mt,
+                         unsigned int level,
+                         unsigned int slice)
+{
+   struct intel_miptree_map **map;
+
+   map = &mt->level[level].slice[slice].map;
+   free(*map);
+   *map = NULL;
+}
+
 static void
 intel_miptree_map_singlesample(struct intel_context *intel,
                                struct intel_mipmap_tree *mt,
@@ -1465,21 +1511,13 @@ intel_miptree_map_singlesample(struct intel_context *intel,
 
    assert(mt->num_samples <= 1);
 
-   map = calloc(1, sizeof(struct intel_miptree_map));
+   map = intel_miptree_attach_map(mt, level, slice, x, y, w, h, mode);
    if (!map){
       *out_ptr = NULL;
       *out_stride = 0;
       return;
    }
 
-   assert(!mt->level[level].slice[slice].map);
-   mt->level[level].slice[slice].map = map;
-   map->mode = mode;
-   map->x = x;
-   map->y = y;
-   map->w = w;
-   map->h = h;
-
    intel_miptree_slice_resolve_depth(intel, mt, level, slice);
    if (map->mode & GL_MAP_WRITE_BIT) {
       intel_miptree_slice_set_needs_hiz_resolve(mt, level, slice);
@@ -1503,10 +1541,8 @@ intel_miptree_map_singlesample(struct intel_context *intel,
    *out_ptr = map->ptr;
    *out_stride = map->stride;
 
-   if (map->ptr == NULL) {
-      mt->level[level].slice[slice].map = NULL;
-      free(map);
-   }
+   if (map->ptr == NULL)
+      intel_miptree_release_map(mt, level, slice);
 }
 
 static void
@@ -1537,8 +1573,7 @@ intel_miptree_unmap_singlesample(struct intel_context *intel,
       intel_miptree_unmap_gtt(intel, mt, map, level, slice);
    }
 
-   mt->level[level].slice[slice].map = NULL;
-   free(map);
+   intel_miptree_release_map(mt, level, slice);
 }
 
 void




More information about the mesa-commit mailing list