intel: Clean up the function chain for mapping texture images for swrast.
authorEric Anholt <eric@anholt.net>
Wed, 28 Sep 2011 22:25:30 +0000 (15:25 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 3 Oct 2011 20:29:38 +0000 (13:29 -0700)
Too many separate functions each called from one location (in
different files).  This code should all die soon when swrast starts
using MapTextureImage.

src/mesa/drivers/dri/intel/intel_mipmap_tree.c
src/mesa/drivers/dri/intel/intel_mipmap_tree.h
src/mesa/drivers/dri/intel/intel_tex_validate.c

index 8289c398ff175e37e2a27570706947ab9a46b03a..c25df35ff84a2feece25c8052bc57d807aaa4733 100644 (file)
@@ -309,63 +309,6 @@ intel_miptree_get_image_offset(struct intel_mipmap_tree *mt,
    }
 }
 
-/**
- * Map a teximage in a mipmap tree.
- * \param row_stride  returns row stride in bytes
- * \param image_stride  returns image stride in bytes (for 3D textures).
- * \param image_offsets pointer to array of pixel offsets from the returned
- *       pointer to each depth image
- * \return address of mapping
- */
-GLubyte *
-intel_miptree_image_map(struct intel_context * intel,
-                        struct intel_mipmap_tree * mt,
-                        GLuint face,
-                        GLuint level,
-                        GLuint * row_stride, GLuint * image_offsets)
-{
-   GLuint x, y;
-
-   if (row_stride)
-      *row_stride = mt->region->pitch * mt->cpp;
-
-   if (mt->target == GL_TEXTURE_3D) {
-      int i;
-
-      for (i = 0; i < mt->level[level].depth; i++) {
-
-        intel_miptree_get_image_offset(mt, level, face, i,
-                                       &x, &y);
-        image_offsets[i] = x + y * mt->region->pitch;
-      }
-
-      DBG("%s \n", __FUNCTION__);
-
-      return intel_region_map(intel, mt->region);
-   } else {
-      assert(mt->level[level].depth == 1);
-      intel_miptree_get_image_offset(mt, level, face, 0,
-                                    &x, &y);
-      image_offsets[0] = 0;
-
-      DBG("%s: (%d,%d) -> (%d, %d)/%d\n",
-         __FUNCTION__, face, level, x, y, mt->region->pitch * mt->cpp);
-
-      return intel_region_map(intel, mt->region) +
-        (x + y * mt->region->pitch) * mt->cpp;
-   }
-}
-
-
-void
-intel_miptree_image_unmap(struct intel_context *intel,
-                          struct intel_mipmap_tree *mt)
-{
-   DBG("%s\n", __FUNCTION__);
-   intel_region_unmap(intel, mt->region);
-}
-
-
 /**
  * Upload data for a particular image.
  */
index 0d4d2f91f7af9bd9a6dd6d0c68fe2b213d4e3908..7ca24f9bb60e9c63adf3439c06d4cd8ee108a8d1 100644 (file)
@@ -165,18 +165,6 @@ void intel_miptree_release(struct intel_mipmap_tree **mt);
 GLboolean intel_miptree_match_image(struct intel_mipmap_tree *mt,
                                     struct gl_texture_image *image);
 
-/* Return a pointer to an image within a tree.  Return image stride as
- * well.
- */
-GLubyte *intel_miptree_image_map(struct intel_context *intel,
-                                 struct intel_mipmap_tree *mt,
-                                 GLuint face,
-                                 GLuint level,
-                                 GLuint * row_stride, GLuint * image_stride);
-
-void intel_miptree_image_unmap(struct intel_context *intel,
-                               struct intel_mipmap_tree *mt);
-
 void
 intel_miptree_get_image_offset(struct intel_mipmap_tree *mt,
                               GLuint level, GLuint face, GLuint depth,
index 137910816f5b95344e80c174365f527df6d4762b..f227ab8f8b1fd2919aca8f8945ddb64574cb8ba6 100644 (file)
@@ -156,70 +156,91 @@ intel_finalize_mipmap_tree(struct intel_context *intel, GLuint unit)
    return GL_TRUE;
 }
 
-void
-intel_tex_map_level_images(struct intel_context *intel,
-                          struct intel_texture_object *intelObj,
-                          int level)
+static void
+intel_tex_map_image_for_swrast(struct intel_context *intel,
+                              struct intel_texture_image *intel_image)
 {
-   GLuint nr_faces = (intelObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
-   GLuint face;
+   int level = intel_image->base.Base.Level;
+   int face = intel_image->base.Base.Face;
+   struct intel_mipmap_tree *mt;
+   unsigned int x, y;
 
-   for (face = 0; face < nr_faces; face++) {
-      struct intel_texture_image *intelImage =
-        intel_texture_image(intelObj->base.Image[face][level]);
-
-      if (intelImage && intelImage->mt) {
-        intelImage->base.Base.Data =
-           intel_miptree_image_map(intel,
-                                   intelImage->mt,
-                                   intelImage->base.Base.Face,
-                                   intelImage->base.Base.Level,
-                                   &intelImage->base.Base.RowStride,
-                                   intelImage->base.Base.ImageOffsets);
-        /* convert stride to texels, not bytes */
-        intelImage->base.Base.RowStride /= intelImage->mt->cpp;
-        /* intelImage->base.ImageStride /= intelImage->mt->cpp; */
+   if (!intel_image || !intel_image->mt)
+      return;
+
+   mt = intel_image->mt;
+
+   if (mt->target == GL_TEXTURE_3D) {
+      int i;
+
+      /* ImageOffsets[] is only used for swrast's fetch_texel_3d, so we can't
+       * share code with the normal path.
+       */
+      for (i = 0; i < mt->level[level].depth; i++) {
+        intel_miptree_get_image_offset(mt, level, face, i, &x, &y);
+        intel_image->base.Base.ImageOffsets[i] = x + y * mt->region->pitch;
       }
+
+      DBG("%s \n", __FUNCTION__);
+
+      intel_image->base.Base.Data = intel_region_map(intel, mt->region);
+   } else {
+      assert(mt->level[level].depth == 1);
+      intel_miptree_get_image_offset(mt, level, face, 0, &x, &y);
+      intel_image->base.Base.ImageOffsets[0] = 0;
+
+      DBG("%s: (%d,%d) -> (%d, %d)/%d\n",
+         __FUNCTION__, face, level, x, y, mt->region->pitch * mt->cpp);
+
+      intel_image->base.Base.Data = intel_region_map(intel, mt->region) +
+        (x + y * mt->region->pitch) * mt->cpp;
    }
+
+   intel_image->base.Base.RowStride = mt->region->pitch;
 }
 
-void
-intel_tex_unmap_level_images(struct intel_context *intel,
-                            struct intel_texture_object *intelObj,
-                            int level)
+static void
+intel_tex_unmap_image_for_swrast(struct intel_context *intel,
+                                struct intel_texture_image *intel_image)
 {
-   GLuint nr_faces = (intelObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
-   GLuint face;
-
-   for (face = 0; face < nr_faces; face++) {
-      struct intel_texture_image *intelImage =
-        intel_texture_image(intelObj->base.Image[face][level]);
-
-      if (intelImage && intelImage->mt) {
-        intel_miptree_image_unmap(intel, intelImage->mt);
-        intelImage->base.Base.Data = NULL;
-      }
+   if (intel_image && intel_image->mt) {
+      intel_region_unmap(intel, intel_image->mt->region);
+      intel_image->base.Base.Data = NULL;
    }
 }
 
 void
 intel_tex_map_images(struct intel_context *intel,
-                     struct intel_texture_object *intelObj)
+                    struct intel_texture_object *intelObj)
 {
-   int i;
+   GLuint nr_faces = (intelObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
+   int i, face;
 
    DBG("%s\n", __FUNCTION__);
 
-   for (i = intelObj->base.BaseLevel; i <= intelObj->_MaxLevel; i++)
-      intel_tex_map_level_images(intel, intelObj, i);
+   for (i = intelObj->base.BaseLevel; i <= intelObj->_MaxLevel; i++) {
+      for (face = 0; face < nr_faces; face++) {
+        struct intel_texture_image *intel_image =
+           intel_texture_image(intelObj->base.Image[face][i]);
+
+        intel_tex_map_image_for_swrast(intel, intel_image);
+      }
+   }
 }
 
 void
 intel_tex_unmap_images(struct intel_context *intel,
-                       struct intel_texture_object *intelObj)
+                      struct intel_texture_object *intelObj)
 {
-   int i;
+   GLuint nr_faces = (intelObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
+   int i, face;
 
-   for (i = intelObj->base.BaseLevel; i <= intelObj->_MaxLevel; i++)
-      intel_tex_unmap_level_images(intel, intelObj, i);
+   for (i = intelObj->base.BaseLevel; i <= intelObj->_MaxLevel; i++) {
+      for (face = 0; face < nr_faces; face++) {
+        struct intel_texture_image *intel_image =
+           intel_texture_image(intelObj->base.Image[face][i]);
+
+        intel_tex_unmap_image_for_swrast(intel, intel_image);
+      }
+   }
 }