mesa: consolidate PBO map/unmap helpers

Instead of _mesa_map_readpix_pbo() use _mesa_map_pbo_source().

Instead of _mesa_map_drawpix_pbo() and _mesa_map_bitmap_pbo() use
_mesa_map_pbo_dest().
This commit is contained in:
Brian Paul
2009-09-03 11:29:18 -06:00
parent e0ec405a9f
commit 1b448c7a5c
9 changed files with 60 additions and 104 deletions

View File

@@ -658,6 +658,8 @@ _mesa_update_default_objects_buffer_objects(GLcontext *ctx)
* currently mapped. Whoever calls this function should check for that. * currently mapped. Whoever calls this function should check for that.
* Remember, we can't use a PBO when it's mapped! * Remember, we can't use a PBO when it's mapped!
* *
* If we're not using a PBO, this is a no-op.
*
* \param width width of image to read/write * \param width width of image to read/write
* \param height height of image to read/write * \param height height of image to read/write
* \param depth depth of image to read/write * \param depth depth of image to read/write
@@ -676,7 +678,8 @@ _mesa_validate_pbo_access(GLuint dimensions,
GLvoid *start, *end; GLvoid *start, *end;
const GLubyte *sizeAddr; /* buffer size, cast to a pointer */ const GLubyte *sizeAddr; /* buffer size, cast to a pointer */
ASSERT(_mesa_is_bufferobj(pack->BufferObj)); if (!_mesa_is_bufferobj(pack->BufferObj))
return GL_TRUE; /* no PBO, OK */
if (pack->BufferObj->Size == 0) if (pack->BufferObj->Size == 0)
/* no buffer! */ /* no buffer! */
@@ -708,17 +711,18 @@ _mesa_validate_pbo_access(GLuint dimensions,
/** /**
* If the source of glBitmap data is a PBO, check that we won't read out * For commands that read from a PBO (glDrawPixels, glTexImage,
* of buffer bounds, then map the buffer. * glPolygonStipple, etc), if we're reading from a PBO, map it read-only
* If not sourcing from a PBO, just return the bitmap pointer. * and return the pointer into the PBO. If we're not reading from a
* This is a helper function for (some) drivers. * PBO, return \p src as-is.
* Return NULL if error. * If non-null return, must call _mesa_unmap_pbo_source() when done.
* If non-null return, must call _mesa_unmap_bitmap_pbo() when done. *
* \return NULL if error, else pointer to start of data
*/ */
const GLubyte * const GLvoid *
_mesa_map_bitmap_pbo(GLcontext *ctx, _mesa_map_pbo_source(GLcontext *ctx,
const struct gl_pixelstore_attrib *unpack, const struct gl_pixelstore_attrib *unpack,
const GLubyte *bitmap) const GLvoid *src)
{ {
const GLubyte *buf; const GLubyte *buf;
@@ -730,11 +734,11 @@ _mesa_map_bitmap_pbo(GLcontext *ctx,
if (!buf) if (!buf)
return NULL; return NULL;
buf = ADD_POINTERS(buf, bitmap); buf = ADD_POINTERS(buf, src);
} }
else { else {
/* unpack from normal memory */ /* unpack from normal memory */
buf = bitmap; buf = src;
} }
return buf; return buf;
@@ -742,13 +746,13 @@ _mesa_map_bitmap_pbo(GLcontext *ctx,
/** /**
* Counterpart to _mesa_map_bitmap_pbo() * Counterpart to _mesa_map_pbo_source()
* This is a helper function for (some) drivers.
*/ */
void void
_mesa_unmap_bitmap_pbo(GLcontext *ctx, _mesa_unmap_pbo_source(GLcontext *ctx,
const struct gl_pixelstore_attrib *unpack) const struct gl_pixelstore_attrib *unpack)
{ {
ASSERT(unpack != &ctx->Pack); /* catch pack/unpack mismatch */
if (_mesa_is_bufferobj(unpack->BufferObj)) { if (_mesa_is_bufferobj(unpack->BufferObj)) {
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
unpack->BufferObj); unpack->BufferObj);
@@ -757,57 +761,17 @@ _mesa_unmap_bitmap_pbo(GLcontext *ctx,
/** /**
* \sa _mesa_map_bitmap_pbo * For commands that write to a PBO (glReadPixels, glGetColorTable, etc),
*/ * if we're writing to a PBO, map it write-only and return the pointer
const GLvoid * * into the PBO. If we're not writing to a PBO, return \p dst as-is.
_mesa_map_drawpix_pbo(GLcontext *ctx, * If non-null return, must call _mesa_unmap_pbo_dest() when done.
const struct gl_pixelstore_attrib *unpack, *
const GLvoid *pixels) * \return NULL if error, else pointer to start of data
{
const GLvoid *buf;
if (_mesa_is_bufferobj(unpack->BufferObj)) {
/* unpack from PBO */
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
GL_READ_ONLY_ARB,
unpack->BufferObj);
if (!buf)
return NULL;
buf = ADD_POINTERS(buf, pixels);
}
else {
/* unpack from normal memory */
buf = pixels;
}
return buf;
}
/**
* \sa _mesa_unmap_bitmap_pbo
*/
void
_mesa_unmap_drawpix_pbo(GLcontext *ctx,
const struct gl_pixelstore_attrib *unpack)
{
if (_mesa_is_bufferobj(unpack->BufferObj)) {
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
unpack->BufferObj);
}
}
/**
* If PBO is bound, map the buffer, return dest pointer in mapped buffer.
* Call _mesa_unmap_readpix_pbo() when finished
* \return NULL if error
*/ */
void * void *
_mesa_map_readpix_pbo(GLcontext *ctx, _mesa_map_pbo_dest(GLcontext *ctx,
const struct gl_pixelstore_attrib *pack, const struct gl_pixelstore_attrib *pack,
GLvoid *dest) GLvoid *dest)
{ {
void *buf; void *buf;
@@ -831,12 +795,13 @@ _mesa_map_readpix_pbo(GLcontext *ctx,
/** /**
* Counterpart to _mesa_map_readpix_pbo() * Counterpart to _mesa_map_pbo_dest()
*/ */
void void
_mesa_unmap_readpix_pbo(GLcontext *ctx, _mesa_unmap_pbo_dest(GLcontext *ctx,
const struct gl_pixelstore_attrib *pack) const struct gl_pixelstore_attrib *pack)
{ {
ASSERT(pack != &ctx->Unpack); /* catch pack/unpack mismatch */
if (_mesa_is_bufferobj(pack->BufferObj)) { if (_mesa_is_bufferobj(pack->BufferObj)) {
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, pack->BufferObj); ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, pack->BufferObj);
} }

View File

@@ -81,32 +81,23 @@ _mesa_validate_pbo_access(GLuint dimensions,
GLsizei width, GLsizei height, GLsizei depth, GLsizei width, GLsizei height, GLsizei depth,
GLenum format, GLenum type, const GLvoid *ptr); GLenum format, GLenum type, const GLvoid *ptr);
extern const GLubyte * extern const GLvoid *
_mesa_map_bitmap_pbo(GLcontext *ctx, _mesa_map_pbo_source(GLcontext *ctx,
const struct gl_pixelstore_attrib *unpack, const struct gl_pixelstore_attrib *unpack,
const GLubyte *bitmap); const GLvoid *src);
extern void extern void
_mesa_unmap_bitmap_pbo(GLcontext *ctx, _mesa_unmap_pbo_source(GLcontext *ctx,
const struct gl_pixelstore_attrib *unpack); const struct gl_pixelstore_attrib *unpack);
extern const GLvoid *
_mesa_map_drawpix_pbo(GLcontext *ctx,
const struct gl_pixelstore_attrib *unpack,
const GLvoid *pixels);
extern void
_mesa_unmap_drawpix_pbo(GLcontext *ctx,
const struct gl_pixelstore_attrib *unpack);
extern void * extern void *
_mesa_map_readpix_pbo(GLcontext *ctx, _mesa_map_pbo_dest(GLcontext *ctx,
const struct gl_pixelstore_attrib *pack, const struct gl_pixelstore_attrib *pack,
GLvoid *dest); GLvoid *dest);
extern void extern void
_mesa_unmap_readpix_pbo(GLcontext *ctx, _mesa_unmap_pbo_dest(GLcontext *ctx,
const struct gl_pixelstore_attrib *pack); const struct gl_pixelstore_attrib *pack);
extern void extern void

View File

@@ -275,7 +275,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height,
struct pipe_texture *pt; struct pipe_texture *pt;
/* PBO source... */ /* PBO source... */
bitmap = _mesa_map_bitmap_pbo(ctx, unpack, bitmap); bitmap = _mesa_map_pbo_source(ctx, unpack, bitmap);
if (!bitmap) { if (!bitmap) {
return NULL; return NULL;
} }
@@ -287,7 +287,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height,
0, width, height, 1, 0, width, height, 1,
PIPE_TEXTURE_USAGE_SAMPLER); PIPE_TEXTURE_USAGE_SAMPLER);
if (!pt) { if (!pt) {
_mesa_unmap_bitmap_pbo(ctx, unpack); _mesa_unmap_pbo_source(ctx, unpack);
return NULL; return NULL;
} }
@@ -302,7 +302,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height,
unpack_bitmap(ctx->st, 0, 0, width, height, unpack, bitmap, unpack_bitmap(ctx->st, 0, 0, width, height, unpack, bitmap,
dest, transfer->stride); dest, transfer->stride);
_mesa_unmap_bitmap_pbo(ctx, unpack); _mesa_unmap_pbo_source(ctx, unpack);
/* Release transfer */ /* Release transfer */
screen->transfer_unmap(screen, transfer); screen->transfer_unmap(screen, transfer);

View File

@@ -353,7 +353,7 @@ make_texture(struct st_context *st,
assert(pipeFormat); assert(pipeFormat);
cpp = st_sizeof_format(pipeFormat); cpp = st_sizeof_format(pipeFormat);
pixels = _mesa_map_drawpix_pbo(ctx, unpack, pixels); pixels = _mesa_map_pbo_source(ctx, unpack, pixels);
if (!pixels) if (!pixels)
return NULL; return NULL;
@@ -381,7 +381,7 @@ make_texture(struct st_context *st,
pt = st_texture_create(st, PIPE_TEXTURE_2D, pipeFormat, 0, ptw, pth, 1, pt = st_texture_create(st, PIPE_TEXTURE_2D, pipeFormat, 0, ptw, pth, 1,
PIPE_TEXTURE_USAGE_SAMPLER); PIPE_TEXTURE_USAGE_SAMPLER);
if (!pt) { if (!pt) {
_mesa_unmap_drawpix_pbo(ctx, unpack); _mesa_unmap_pbo_source(ctx, unpack);
return NULL; return NULL;
} }
@@ -428,7 +428,7 @@ make_texture(struct st_context *st,
ctx->_ImageTransferState = imageTransferStateSave; ctx->_ImageTransferState = imageTransferStateSave;
} }
_mesa_unmap_drawpix_pbo(ctx, unpack); _mesa_unmap_pbo_source(ctx, unpack);
return pt; return pt;
} }
@@ -681,7 +681,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
stmap = screen->transfer_map(screen, pt); stmap = screen->transfer_map(screen, pt);
pixels = _mesa_map_drawpix_pbo(ctx, unpack, pixels); pixels = _mesa_map_pbo_source(ctx, unpack, pixels);
assert(pixels); assert(pixels);
/* if width > MAX_WIDTH, have to process image in chunks */ /* if width > MAX_WIDTH, have to process image in chunks */
@@ -775,7 +775,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
skipPixels += spanWidth; skipPixels += spanWidth;
} }
_mesa_unmap_drawpix_pbo(ctx, unpack); _mesa_unmap_pbo_source(ctx, unpack);
/* unmap the stencil buffer */ /* unmap the stencil buffer */
screen->transfer_unmap(screen, pt); screen->transfer_unmap(screen, pt);

View File

@@ -353,7 +353,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
return; return;
} }
dest = _mesa_map_readpix_pbo(ctx, &clippedPacking, dest); dest = _mesa_map_pbo_dest(ctx, &clippedPacking, dest);
if (!dest) if (!dest)
return; return;
@@ -380,7 +380,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
if (st_fast_readpixels(ctx, strb, x, y, width, height, if (st_fast_readpixels(ctx, strb, x, y, width, height,
format, type, pack, dest)) { format, type, pack, dest)) {
/* success! */ /* success! */
_mesa_unmap_readpix_pbo(ctx, &clippedPacking); _mesa_unmap_pbo_dest(ctx, &clippedPacking);
return; return;
} }
@@ -534,7 +534,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
screen->tex_transfer_destroy(trans); screen->tex_transfer_destroy(trans);
_mesa_unmap_readpix_pbo(ctx, &clippedPacking); _mesa_unmap_pbo_dest(ctx, &clippedPacking);
} }

View File

@@ -870,7 +870,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
PIPE_TRANSFER_READ, PIPE_TRANSFER_READ,
0, 0, width, height); 0, 0, width, height);
pixels = _mesa_map_readpix_pbo(ctx, &ctx->Pack, pixels); pixels = _mesa_map_pbo_dest(ctx, &ctx->Pack, pixels);
/* copy/pack data into user buffer */ /* copy/pack data into user buffer */
if (st_equal_formats(stImage->pt->format, format, type)) { if (st_equal_formats(stImage->pt->format, format, type)) {
@@ -903,7 +903,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
} }
} }
_mesa_unmap_readpix_pbo(ctx, &ctx->Pack); _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
/* destroy the temp / dest surface */ /* destroy the temp / dest surface */
util_destroy_rgba_surface(dst_texture, dst_surface); util_destroy_rgba_surface(dst_texture, dst_surface);

View File

@@ -56,7 +56,7 @@ _swrast_Bitmap( GLcontext *ctx, GLint px, GLint py,
ASSERT(ctx->RenderMode == GL_RENDER); ASSERT(ctx->RenderMode == GL_RENDER);
bitmap = _mesa_map_bitmap_pbo(ctx, unpack, bitmap); bitmap = (const GLubyte *) _mesa_map_pbo_source(ctx, unpack, bitmap);
if (!bitmap) if (!bitmap)
return; return;
@@ -133,7 +133,7 @@ _swrast_Bitmap( GLcontext *ctx, GLint px, GLint py,
swrast_render_finish(ctx); swrast_render_finish(ctx);
_mesa_unmap_bitmap_pbo(ctx, unpack); _mesa_unmap_pbo_source(ctx, unpack);
} }

View File

@@ -847,7 +847,7 @@ _swrast_DrawPixels( GLcontext *ctx,
if (swrast->NewState) if (swrast->NewState)
_swrast_validate_derived( ctx ); _swrast_validate_derived( ctx );
pixels = _mesa_map_drawpix_pbo(ctx, unpack, pixels); pixels = _mesa_map_pbo_source(ctx, unpack, pixels);
if (!pixels) { if (!pixels) {
swrast_render_finish(ctx); swrast_render_finish(ctx);
_mesa_set_vp_override(ctx, save_vp_override); _mesa_set_vp_override(ctx, save_vp_override);
@@ -892,7 +892,7 @@ _swrast_DrawPixels( GLcontext *ctx,
swrast_render_finish(ctx); swrast_render_finish(ctx);
_mesa_set_vp_override(ctx, save_vp_override); _mesa_set_vp_override(ctx, save_vp_override);
_mesa_unmap_drawpix_pbo(ctx, unpack); _mesa_unmap_pbo_source(ctx, unpack);
} }

View File

@@ -574,7 +574,7 @@ _swrast_ReadPixels( GLcontext *ctx,
return; return;
} }
pixels = _mesa_map_readpix_pbo(ctx, &clippedPacking, pixels); pixels = _mesa_map_pbo_dest(ctx, &clippedPacking, pixels);
if (!pixels) if (!pixels)
return; return;
@@ -616,5 +616,5 @@ _swrast_ReadPixels( GLcontext *ctx,
swrast_render_finish(ctx); swrast_render_finish(ctx);
_mesa_unmap_readpix_pbo(ctx, &clippedPacking); _mesa_unmap_pbo_dest(ctx, &clippedPacking);
} }