Removed _swrast_validate_pbo_access().
authorBrian Paul <brian.paul@tungstengraphics.com>
Sun, 31 Oct 2004 15:49:59 +0000 (15:49 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Sun, 31 Oct 2004 15:49:59 +0000 (15:49 +0000)
In x11 driver, map/unmap PBO as needed in DrawPixels functions.

src/mesa/drivers/x11/xm_dd.c
src/mesa/swrast/s_context.c
src/mesa/swrast/swrast.h

index db94e40c211bf1dc2657c85295372f5fe57005e1..a83c5ec3ec8f53012aea8156d8eec03e67bafa3e 100644 (file)
@@ -843,10 +843,27 @@ xmesa_DrawPixels_8R8G8B( GLcontext *ctx,
       int srcY = unpack->SkipRows;
       int rowLength = unpack->RowLength ? unpack->RowLength : width;
 
-      pixels = _swrast_validate_pbo_access(unpack, width, height, 1,
-                                           format, type, (GLvoid *) pixels);
-      if (!pixels)
-         return;
+      if (unpack->BufferObj->Name) {
+         /* unpack from PBO */
+         GLubyte *buf;
+         if (!_mesa_validate_pbo_access(unpack, width, height, 1,
+                                        format, type, pixels)) {
+            _mesa_error(ctx, GL_INVALID_OPERATION,
+                        "glDrawPixels(invalid PBO access)");
+            return;
+         }
+         buf = (GLubyte *) ctx->Driver.MapBuffer(ctx,
+                                                 GL_PIXEL_UNPACK_BUFFER_EXT,
+                                                 GL_READ_ONLY_ARB,
+                                                 unpack->BufferObj);
+         if (!buf) {
+            /* buffer is already mapped - that's an error */
+            _mesa_error(ctx, GL_INVALID_OPERATION,
+                        "glDrawPixels(PBO is mapped)");
+            return;
+         }
+         pixels = ADD_POINTERS(buf, pixels);
+      }
 
       if (_swrast_clip_pixelrect(ctx, &dstX, &dstY, &w, &h, &srcX, &srcY)) {
          /* This is a little tricky since all coordinates up to now have
@@ -872,6 +889,11 @@ xmesa_DrawPixels_8R8G8B( GLcontext *ctx,
          dstY = FLIP(xmesa->xm_draw_buffer, dstY) - h + 1;
          XPutImage(dpy, buffer, gc, &ximage, 0, 0, dstX, dstY, w, h);
       }
+
+      if (unpack->BufferObj->Name) {
+         ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
+                                 unpack->BufferObj);
+      }
    }
    else {
       /* software fallback */
@@ -924,10 +946,27 @@ xmesa_DrawPixels_5R6G5B( GLcontext *ctx,
       int srcY = unpack->SkipRows;
       int rowLength = unpack->RowLength ? unpack->RowLength : width;
 
-      pixels = _swrast_validate_pbo_access(unpack, width, height, 1,
-                                           format, type, (GLvoid *) pixels);
-      if (!pixels)
-         return;
+      if (unpack->BufferObj->Name) {
+         /* unpack from PBO */
+         GLubyte *buf;
+         if (!_mesa_validate_pbo_access(unpack, width, height, 1,
+                                        format, type, pixels)) {
+            _mesa_error(ctx, GL_INVALID_OPERATION,
+                        "glDrawPixels(invalid PBO access)");
+            return;
+         }
+         buf = (GLubyte *) ctx->Driver.MapBuffer(ctx,
+                                                 GL_PIXEL_UNPACK_BUFFER_EXT,
+                                                 GL_READ_ONLY_ARB,
+                                                 unpack->BufferObj);
+         if (!buf) {
+            /* buffer is already mapped - that's an error */
+            _mesa_error(ctx, GL_INVALID_OPERATION,
+                        "glDrawPixels(PBO is mapped)");
+            return;
+         }
+         pixels = ADD_POINTERS(buf, pixels);
+      }
 
       if (_swrast_clip_pixelrect(ctx, &dstX, &dstY, &w, &h, &srcX, &srcY)) {
          /* This is a little tricky since all coordinates up to now have
@@ -953,6 +992,11 @@ xmesa_DrawPixels_5R6G5B( GLcontext *ctx,
          dstY = FLIP(xmesa->xm_draw_buffer, dstY) - h + 1;
          XPutImage(dpy, buffer, gc, &ximage, 0, 0, dstX, dstY, w, h);
       }
+
+      if (unpack->BufferObj->Name) {
+         ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
+                                 unpack->BufferObj);
+      }
    }
    else {
       /* software fallback */
index e9755e9199799fca8d98a0156b804753b1ddf953..a8716d80f509500f8a39a11433caf672e31d58d0 100644 (file)
@@ -771,25 +771,3 @@ _swrast_print_vertex( GLcontext *ctx, const SWvertex *v )
       _mesa_debug(ctx, "\n");
    }
 }
-
-
-/**
- * Validate access to a PBO to be sure we're not going to read/write
- * out of buffer bounds.
- */
-GLvoid *
-_swrast_validate_pbo_access(const struct gl_pixelstore_attrib *pack,
-                            GLsizei width, GLsizei height, GLsizei depth,
-                            GLenum format, GLenum type, GLvoid *ptr)
-{
-   if (pack->BufferObj->Name == 0) {
-      /* no PBO */
-      return ptr;
-   }
-   else if (_mesa_validate_pbo_access(pack, width, height, depth, format,
-                                      type, ptr)) {
-      return ADD_POINTERS(pack->BufferObj->Data, ptr);
-   }
-   /* bad access! */
-   return NULL;
-}
index 7d8cf8c7a8a4d6648edde9b6a2e191f6d5824ede..8f249d94280fbcfcbdeeede861fe3f8c7270b09e 100644 (file)
@@ -201,11 +201,6 @@ extern void
 _swrast_print_vertex( GLcontext *ctx, const SWvertex *v );
 
 
-extern GLvoid *
-_swrast_validate_pbo_access(const struct gl_pixelstore_attrib *pack,
-                            GLsizei width, GLsizei height, GLsizei depth,
-                            GLenum format, GLenum type, GLvoid *ptr);
-
 /*
  * Imaging fallbacks (a better solution should be found, perhaps
  * moving all the imaging fallback code to a new module)