[Mesa-dev] [PATCH 05/17] swrast: Move ImageOffsets allocation to shared code.

Eric Anholt eric at anholt.net
Mon Apr 22 09:14:46 PDT 2013


---
 src/mesa/drivers/dri/intel/intel_tex.c       |   20 ++------------------
 src/mesa/drivers/dri/radeon/radeon_texture.c |   15 ++-------------
 src/mesa/swrast/s_texture.c                  |   24 ++++++++++++------------
 src/mesa/swrast/swrast.h                     |    2 +-
 4 files changed, 17 insertions(+), 44 deletions(-)

diff --git a/src/mesa/drivers/dri/intel/intel_tex.c b/src/mesa/drivers/dri/intel/intel_tex.c
index ee8db71..2fbd5c4 100644
--- a/src/mesa/drivers/dri/intel/intel_tex.c
+++ b/src/mesa/drivers/dri/intel/intel_tex.c
@@ -64,7 +64,6 @@ intel_alloc_texture_image_buffer(struct gl_context *ctx,
    struct intel_texture_image *intel_image = intel_texture_image(image);
    struct gl_texture_object *texobj = image->TexObject;
    struct intel_texture_object *intel_texobj = intel_texture_object(texobj);
-   GLuint slices;
 
    assert(image->Border == 0);
 
@@ -81,23 +80,8 @@ intel_alloc_texture_image_buffer(struct gl_context *ctx,
     */
    ctx->Driver.FreeTextureImageBuffer(ctx, image);
 
-   /* Allocate the swrast_texture_image::ImageOffsets array now */
-   switch (texobj->Target) {
-   case GL_TEXTURE_3D:
-   case GL_TEXTURE_2D_ARRAY:
-   case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
-      slices = image->Depth;
-      break;
-   case GL_TEXTURE_1D_ARRAY:
-      slices = image->Height;
-      break;
-   default:
-      slices = 1;
-   }
-   assert(!intel_image->base.ImageOffsets);
-   intel_image->base.ImageOffsets = malloc(slices * sizeof(GLuint));
-
-   _swrast_init_texture_image(image);
+   if (!_swrast_init_texture_image(image))
+      return false;
 
    if (intel_texobj->mt &&
        intel_miptree_match_image(intel_texobj->mt, image)) {
diff --git a/src/mesa/drivers/dri/radeon/radeon_texture.c b/src/mesa/drivers/dri/radeon/radeon_texture.c
index b6e551c..a953858 100644
--- a/src/mesa/drivers/dri/radeon/radeon_texture.c
+++ b/src/mesa/drivers/dri/radeon/radeon_texture.c
@@ -105,23 +105,12 @@ radeonAllocTextureImageBuffer(struct gl_context *ctx,
 			      struct gl_texture_image *timage)
 {
 	radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
-	radeon_texture_image *image = get_radeon_texture_image(timage);
 	struct gl_texture_object *texobj = timage->TexObject;
-	int slices;
 
 	ctx->Driver.FreeTextureImageBuffer(ctx, timage);
 
-	switch (texobj->Target) {
-	case GL_TEXTURE_3D:
-		slices = timage->Depth;
-		break;
-	default:
-		slices = 1;
-	}
-	assert(!image->base.ImageOffsets);
-	image->base.ImageOffsets = malloc(slices * sizeof(GLuint));
-
-	_swrast_init_texture_image(timage);
+	if (!_swrast_init_texture_image(timage))
+		return GL_FALSE;
 
 	teximage_assign_miptree(rmesa, texobj, timage);
 				
diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c
index b6dd8cb..c60fe2d 100644
--- a/src/mesa/swrast/s_texture.c
+++ b/src/mesa/swrast/s_texture.c
@@ -79,6 +79,9 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
                                           texImage->Height, texImage->Depth);
    GLuint i;
 
+   if (!_swrast_init_texture_image(texImage))
+      return GL_FALSE;
+
    assert(!swImg->Buffer);
    swImg->Buffer = _mesa_align_malloc(bytes, 512);
    if (!swImg->Buffer)
@@ -87,20 +90,10 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
    /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
    swImg->RowStride = texImage->Width;
 
-   /* Allocate the ImageOffsets array and initialize to typical values.
-    * We allocate the array for 1D/2D textures too in order to avoid special-
-    * case code in the texstore routines.
-    */
-   swImg->ImageOffsets = malloc(texture_slices(texImage) * sizeof(GLuint));
-   if (!swImg->ImageOffsets)
-      return GL_FALSE;
-
    for (i = 0; i < texture_slices(texImage); i++) {
       swImg->ImageOffsets[i] = i * texImage->Width * texImage->Height;
    }
 
-   _swrast_init_texture_image(texImage);
-
    return GL_TRUE;
 }
 
@@ -108,11 +101,11 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
 /**
  * Code that overrides ctx->Driver.AllocTextureImageBuffer may use this to
  * initialize the fields of swrast_texture_image without allocating the image
- * buffer or initializing ImageOffsets or RowStride.
+ * buffer or initializing RowStride or the contents of ImageOffsets.
  *
  * Returns GL_TRUE on success, GL_FALSE on memory allocation failure.
  */
-void
+GLboolean
 _swrast_init_texture_image(struct gl_texture_image *texImage)
 {
    struct swrast_texture_image *swImg = swrast_texture_image(texImage);
@@ -136,6 +129,13 @@ _swrast_init_texture_image(struct gl_texture_image *texImage)
       swImg->HeightScale = (GLfloat) texImage->Height;
       swImg->DepthScale = (GLfloat) texImage->Depth;
    }
+
+   assert(!swImg->ImageOffsets);
+   swImg->ImageOffsets = malloc(texture_slices(texImage) * sizeof(GLuint));
+   if (!swImg->ImageOffsets)
+      return GL_FALSE;
+
+   return GL_TRUE;
 }
 
 
diff --git a/src/mesa/swrast/swrast.h b/src/mesa/swrast/swrast.h
index 0f74bb9..ccb4ff8 100644
--- a/src/mesa/swrast/swrast.h
+++ b/src/mesa/swrast/swrast.h
@@ -217,7 +217,7 @@ extern GLboolean
 _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
                                    struct gl_texture_image *texImage);
 
-extern void
+extern GLboolean
 _swrast_init_texture_image(struct gl_texture_image *texImage);
 
 extern void
-- 
1.7.10.4



More information about the mesa-dev mailing list