Mesa (master): mesa: combined PBO validate/map helpers
Brian Paul
brianp at kemper.freedesktop.org
Thu Sep 3 17:48:36 UTC 2009
Module: Mesa
Branch: master
Commit: dc947c8f92732fab75f89015e2d506e964a41ace
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=dc947c8f92732fab75f89015e2d506e964a41ace
Author: Brian Paul <brianp at vmware.com>
Date: Thu Sep 3 11:22:27 2009 -0600
mesa: combined PBO validate/map helpers
---
src/mesa/main/bufferobj.c | 82 +++++++++++++++++++++++++++++++++++++++++++++
src/mesa/main/bufferobj.h | 16 +++++++++
2 files changed, 98 insertions(+), 0 deletions(-)
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index 1ae63a0..b95e00a 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -746,6 +746,47 @@ _mesa_map_pbo_source(GLcontext *ctx,
/**
+ * Combine PBO-read validation and mapping.
+ * If any GL errors are detected, they'll be recorded and NULL returned.
+ * \sa _mesa_validate_pbo_access
+ * \sa _mesa_map_pbo_source
+ * A call to this function should have a matching call to
+ * _mesa_unmap_pbo_source().
+ */
+const GLvoid *
+_mesa_map_validate_pbo_source(GLcontext *ctx,
+ GLuint dimensions,
+ const struct gl_pixelstore_attrib *unpack,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLenum type, const GLvoid *ptr,
+ const char *where)
+{
+ ASSERT(dimensions == 1 || dimensions == 2 || dimensions == 3);
+
+ if (!_mesa_is_bufferobj(unpack->BufferObj)) {
+ /* non-PBO access: no validation to be done */
+ return ptr;
+ }
+
+ if (!_mesa_validate_pbo_access(dimensions, unpack,
+ width, height, depth, format, type, ptr)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "%s(out of bounds PBO access)", where);
+ return NULL;
+ }
+
+ if (_mesa_bufferobj_mapped(unpack->BufferObj)) {
+ /* buffer is already mapped - that's an error */
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s(PBO is mapped)", where);
+ return NULL;
+ }
+
+ ptr = _mesa_map_pbo_source(ctx, unpack, ptr);
+ return ptr;
+}
+
+
+/**
* Counterpart to _mesa_map_pbo_source()
*/
void
@@ -795,6 +836,47 @@ _mesa_map_pbo_dest(GLcontext *ctx,
/**
+ * Combine PBO-write validation and mapping.
+ * If any GL errors are detected, they'll be recorded and NULL returned.
+ * \sa _mesa_validate_pbo_access
+ * \sa _mesa_map_pbo_dest
+ * A call to this function should have a matching call to
+ * _mesa_unmap_pbo_dest().
+ */
+GLvoid *
+_mesa_map_validate_pbo_dest(GLcontext *ctx,
+ GLuint dimensions,
+ const struct gl_pixelstore_attrib *unpack,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLenum type, GLvoid *ptr,
+ const char *where)
+{
+ ASSERT(dimensions == 1 || dimensions == 2 || dimensions == 3);
+
+ if (!_mesa_is_bufferobj(unpack->BufferObj)) {
+ /* non-PBO access: no validation to be done */
+ return ptr;
+ }
+
+ if (!_mesa_validate_pbo_access(dimensions, unpack,
+ width, height, depth, format, type, ptr)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "%s(out of bounds PBO access)", where);
+ return NULL;
+ }
+
+ if (_mesa_bufferobj_mapped(unpack->BufferObj)) {
+ /* buffer is already mapped - that's an error */
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s(PBO is mapped)", where);
+ return NULL;
+ }
+
+ ptr = _mesa_map_pbo_dest(ctx, unpack, ptr);
+ return ptr;
+}
+
+
+/**
* Counterpart to _mesa_map_pbo_dest()
*/
void
diff --git a/src/mesa/main/bufferobj.h b/src/mesa/main/bufferobj.h
index 2e7afc2..9f732ec 100644
--- a/src/mesa/main/bufferobj.h
+++ b/src/mesa/main/bufferobj.h
@@ -86,6 +86,14 @@ _mesa_map_pbo_source(GLcontext *ctx,
const struct gl_pixelstore_attrib *unpack,
const GLvoid *src);
+extern const GLvoid *
+_mesa_map_validate_pbo_source(GLcontext *ctx,
+ GLuint dimensions,
+ const struct gl_pixelstore_attrib *unpack,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLenum type, const GLvoid *ptr,
+ const char *where);
+
extern void
_mesa_unmap_pbo_source(GLcontext *ctx,
const struct gl_pixelstore_attrib *unpack);
@@ -95,6 +103,14 @@ _mesa_map_pbo_dest(GLcontext *ctx,
const struct gl_pixelstore_attrib *pack,
GLvoid *dest);
+extern GLvoid *
+_mesa_map_validate_pbo_dest(GLcontext *ctx,
+ GLuint dimensions,
+ const struct gl_pixelstore_attrib *unpack,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLenum type, GLvoid *ptr,
+ const char *where);
+
extern void
_mesa_unmap_pbo_dest(GLcontext *ctx,
const struct gl_pixelstore_attrib *pack);
More information about the mesa-commit
mailing list