Mesa (map-tex-branch): mesa: use RowStride if it' s non-zero in _mesa_alloc_texture_image_data()

Brian Paul brianp at kemper.freedesktop.org
Sat Dec 5 09:36:04 PST 2009


Module: Mesa
Branch: map-tex-branch
Commit: bb09759f141a521f7232f9dff746c5277b617794
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=bb09759f141a521f7232f9dff746c5277b617794

Author: Brian Paul <brianp at vmware.com>
Date:   Sat Dec  5 10:35:05 2009 -0700

mesa: use RowStride if it's non-zero in _mesa_alloc_texture_image_data()

Fixes a regression found in DRI drivers when the row stride is larger
than the image width.

---

 src/mesa/main/texmem.c |   26 +++++++++++++++++++++++---
 1 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/mesa/main/texmem.c b/src/mesa/main/texmem.c
index 166e648..8de835a 100644
--- a/src/mesa/main/texmem.c
+++ b/src/mesa/main/texmem.c
@@ -38,13 +38,33 @@
 /**
  * Allocate space for the given texture image.
  * This is a fallback called via ctx->Driver.AllocTexImageData().
+ * Hardware drivers typically won't use this unless they need to temporarily
+ * store texture data in user memory rather than video memory.
  */
 GLboolean
 _mesa_alloc_texture_image_data(GLcontext *ctx, struct gl_texture_image *tImage)
 {
-   GLint bytes = _mesa_format_image_size(tImage->TexFormat, tImage->Width,
-                                         tImage->Height, tImage->Depth);
-   /* XXX store data on tImgae->DriverData */
+   GLuint width, bytes;
+
+   /*
+    * XXX in the future, we probably don't want to rely on Map.RowStride
+    * here since it may only be valid while the texture memory is mapped.
+    * Drivers should implement their own version of this function which
+    * does the proper alignment.
+    */
+   if (tImage->Map.RowStride > 0) {
+      /* sanity check: the stride should be at least as large as the width */
+      assert(tImage->Map.RowStride >= tImage->Width);
+      width = tImage->Map.RowStride;
+   }
+   else {
+      width = tImage->Width;
+   }
+
+   bytes = _mesa_format_image_size(tImage->TexFormat, width,
+                                   tImage->Height, tImage->Depth);
+
+   /* XXX future step: store data off of tImage->DriverData */
    tImage->Map.Data = _mesa_align_malloc(bytes, 512);
    return tImage->Map.Data != NULL;
 }



More information about the mesa-commit mailing list