Refactor PBO validate/map code.
We always need to do PBO validation, so do that in core Mesa before calling driver routine.
This commit is contained in:
@@ -570,31 +570,17 @@ _mesa_validate_pbo_access(GLuint dimensions,
|
|||||||
* If not sourcing from a PBO, just return the bitmap pointer.
|
* If not sourcing from a PBO, just return the bitmap pointer.
|
||||||
* This is a helper function for (some) drivers.
|
* This is a helper function for (some) drivers.
|
||||||
* Return NULL if error.
|
* Return NULL if error.
|
||||||
* If non-null return, must call validate_and_map_bitmap_pbo() when done.
|
* If non-null return, must call _mesa_unmap_bitmap_pbo() when done.
|
||||||
*/
|
*/
|
||||||
const GLubyte *
|
const GLubyte *
|
||||||
_mesa_validate_and_map_bitmap_pbo(GLcontext *ctx,
|
_mesa_map_bitmap_pbo(GLcontext *ctx,
|
||||||
GLsizei width, GLsizei height,
|
const struct gl_pixelstore_attrib *unpack,
|
||||||
const struct gl_pixelstore_attrib *unpack,
|
const GLubyte *bitmap)
|
||||||
const GLubyte *bitmap)
|
|
||||||
{
|
{
|
||||||
const GLubyte *buf;
|
const GLubyte *buf;
|
||||||
|
|
||||||
if (unpack->BufferObj->Name) {
|
if (unpack->BufferObj->Name) {
|
||||||
/* unpack from PBO */
|
/* unpack from PBO */
|
||||||
if (!_mesa_validate_pbo_access(2, unpack, width, height, 1,
|
|
||||||
GL_COLOR_INDEX, GL_BITMAP,
|
|
||||||
(GLvoid *) bitmap)) {
|
|
||||||
_mesa_error(ctx, GL_INVALID_OPERATION,"glBitmap(invalid PBO access)");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unpack->BufferObj->Pointer) {
|
|
||||||
/* buffer is already mapped - that's an error */
|
|
||||||
_mesa_error(ctx, GL_INVALID_OPERATION, "glBitmap(PBO is mapped)");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
|
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
|
||||||
GL_READ_ONLY_ARB,
|
GL_READ_ONLY_ARB,
|
||||||
unpack->BufferObj);
|
unpack->BufferObj);
|
||||||
@@ -613,7 +599,7 @@ _mesa_validate_and_map_bitmap_pbo(GLcontext *ctx,
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Counterpart to validate_and_map_bitmap_pbo()
|
* Counterpart to _mesa_map_bitmap_pbo()
|
||||||
* This is a helper function for (some) drivers.
|
* This is a helper function for (some) drivers.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
@@ -628,33 +614,17 @@ _mesa_unmap_bitmap_pbo(GLcontext *ctx,
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \sa _mesa_validate_and_map_bitmap_pbo
|
* \sa _mesa_map_bitmap_pbo
|
||||||
*/
|
*/
|
||||||
const GLvoid *
|
const GLvoid *
|
||||||
_mesa_validate_and_map_drawpix_pbo(GLcontext *ctx,
|
_mesa_map_drawpix_pbo(GLcontext *ctx,
|
||||||
GLsizei width, GLsizei height,
|
const struct gl_pixelstore_attrib *unpack,
|
||||||
GLenum format, GLenum type,
|
const GLvoid *pixels)
|
||||||
const struct gl_pixelstore_attrib *unpack,
|
|
||||||
const GLvoid *pixels)
|
|
||||||
{
|
{
|
||||||
const GLvoid *buf;
|
const GLvoid *buf;
|
||||||
|
|
||||||
if (unpack->BufferObj->Name) {
|
if (unpack->BufferObj->Name) {
|
||||||
/* unpack from PBO */
|
/* unpack from PBO */
|
||||||
|
|
||||||
if (!_mesa_validate_pbo_access(2, unpack, width, height, 1,
|
|
||||||
format, type, pixels)) {
|
|
||||||
_mesa_error(ctx, GL_INVALID_OPERATION,
|
|
||||||
"glDrawPixels(invalid PBO access)");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unpack->BufferObj->Pointer) {
|
|
||||||
/* buffer is already mapped - that's an error */
|
|
||||||
_mesa_error(ctx, GL_INVALID_OPERATION, "glDrawPixels(PBO is mapped)");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
|
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
|
||||||
GL_READ_ONLY_ARB,
|
GL_READ_ONLY_ARB,
|
||||||
unpack->BufferObj);
|
unpack->BufferObj);
|
||||||
@@ -687,36 +657,19 @@ _mesa_unmap_drapix_pbo(GLcontext *ctx,
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When doing glReadPixels into a PBO, this function will check for errors
|
* If PBO is bound, map the buffer, return dest pointer in mapped buffer.
|
||||||
* and map the buffer.
|
|
||||||
* Call _mesa_unmap_readpix_pbo() when finished
|
* Call _mesa_unmap_readpix_pbo() when finished
|
||||||
* \return NULL if error
|
* \return NULL if error
|
||||||
*/
|
*/
|
||||||
void *
|
void *
|
||||||
_mesa_validate_and_map_readpix_pbo(GLcontext *ctx,
|
_mesa_map_readpix_pbo(GLcontext *ctx,
|
||||||
GLint x, GLint y,
|
const struct gl_pixelstore_attrib *pack,
|
||||||
GLsizei width, GLsizei height,
|
GLvoid *dest)
|
||||||
GLenum format, GLenum type,
|
|
||||||
const struct gl_pixelstore_attrib *pack,
|
|
||||||
GLvoid *dest)
|
|
||||||
{
|
{
|
||||||
void *buf;
|
void *buf;
|
||||||
|
|
||||||
if (pack->BufferObj->Name) {
|
if (pack->BufferObj->Name) {
|
||||||
/* pack into PBO */
|
/* pack into PBO */
|
||||||
if (!_mesa_validate_pbo_access(2, pack, width, height, 1,
|
|
||||||
format, type, dest)) {
|
|
||||||
_mesa_error(ctx, GL_INVALID_OPERATION,
|
|
||||||
"glReadPixels(invalid PBO access)");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pack->BufferObj->Pointer) {
|
|
||||||
/* buffer is already mapped - that's an error */
|
|
||||||
_mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(PBO is mapped)");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
|
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
|
||||||
GL_WRITE_ONLY_ARB,
|
GL_WRITE_ONLY_ARB,
|
||||||
pack->BufferObj);
|
pack->BufferObj);
|
||||||
@@ -735,7 +688,7 @@ _mesa_validate_and_map_readpix_pbo(GLcontext *ctx,
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Counterpart to validate_and_map_readpix_pbo()
|
* Counterpart to _mesa_map_readpix_pbo()
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
_mesa_unmap_readpix_pbo(GLcontext *ctx,
|
_mesa_unmap_readpix_pbo(GLcontext *ctx,
|
||||||
@@ -747,6 +700,7 @@ _mesa_unmap_readpix_pbo(GLcontext *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the gl_buffer_object for the given ID.
|
* Return the gl_buffer_object for the given ID.
|
||||||
* Always return NULL for ID 0.
|
* Always return NULL for ID 0.
|
||||||
|
@@ -90,21 +90,18 @@ _mesa_validate_pbo_access(GLuint dimensions,
|
|||||||
GLenum format, GLenum type, const GLvoid *ptr);
|
GLenum format, GLenum type, const GLvoid *ptr);
|
||||||
|
|
||||||
extern const GLubyte *
|
extern const GLubyte *
|
||||||
_mesa_validate_and_map_bitmap_pbo(GLcontext *ctx,
|
_mesa_map_bitmap_pbo(GLcontext *ctx,
|
||||||
GLsizei width, GLsizei height,
|
const struct gl_pixelstore_attrib *unpack,
|
||||||
const struct gl_pixelstore_attrib *unpack,
|
const GLubyte *bitmap);
|
||||||
const GLubyte *bitmap);
|
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
_mesa_unmap_bitmap_pbo(GLcontext *ctx,
|
_mesa_unmap_bitmap_pbo(GLcontext *ctx,
|
||||||
const struct gl_pixelstore_attrib *unpack);
|
const struct gl_pixelstore_attrib *unpack);
|
||||||
|
|
||||||
extern const GLvoid *
|
extern const GLvoid *
|
||||||
_mesa_validate_and_map_drawpix_pbo(GLcontext *ctx,
|
_mesa_map_drawpix_pbo(GLcontext *ctx,
|
||||||
GLsizei width, GLsizei height,
|
const struct gl_pixelstore_attrib *unpack,
|
||||||
GLenum format, GLenum type,
|
const GLvoid *pixels);
|
||||||
const struct gl_pixelstore_attrib *unpack,
|
|
||||||
const GLvoid *pixels);
|
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
_mesa_unmap_drapix_pbo(GLcontext *ctx,
|
_mesa_unmap_drapix_pbo(GLcontext *ctx,
|
||||||
@@ -112,12 +109,9 @@ _mesa_unmap_drapix_pbo(GLcontext *ctx,
|
|||||||
|
|
||||||
|
|
||||||
extern void *
|
extern void *
|
||||||
_mesa_validate_and_map_readpix_pbo(GLcontext *ctx,
|
_mesa_map_readpix_pbo(GLcontext *ctx,
|
||||||
GLint x, GLint y,
|
const struct gl_pixelstore_attrib *pack,
|
||||||
GLsizei width, GLsizei height,
|
GLvoid *dest);
|
||||||
GLenum format, GLenum type,
|
|
||||||
const struct gl_pixelstore_attrib *pack,
|
|
||||||
GLvoid *dest);
|
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
_mesa_unmap_readpix_pbo(GLcontext *ctx,
|
_mesa_unmap_readpix_pbo(GLcontext *ctx,
|
||||||
|
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include "glheader.h"
|
#include "glheader.h"
|
||||||
#include "imports.h"
|
#include "imports.h"
|
||||||
|
#include "bufferobj.h"
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
#include "drawpix.h"
|
#include "drawpix.h"
|
||||||
#include "feedback.h"
|
#include "feedback.h"
|
||||||
@@ -182,6 +183,23 @@ _mesa_DrawPixels( GLsizei width, GLsizei height,
|
|||||||
/* Round, to satisfy conformance tests (matches SGI's OpenGL) */
|
/* Round, to satisfy conformance tests (matches SGI's OpenGL) */
|
||||||
GLint x = IROUND(ctx->Current.RasterPos[0]);
|
GLint x = IROUND(ctx->Current.RasterPos[0]);
|
||||||
GLint y = IROUND(ctx->Current.RasterPos[1]);
|
GLint y = IROUND(ctx->Current.RasterPos[1]);
|
||||||
|
|
||||||
|
if (ctx->Unpack.BufferObj->Name) {
|
||||||
|
/* unpack from PBO */
|
||||||
|
if (!_mesa_validate_pbo_access(2, &ctx->Unpack, width, height, 1,
|
||||||
|
format, type, pixels)) {
|
||||||
|
_mesa_error(ctx, GL_INVALID_OPERATION,
|
||||||
|
"glDrawPixels(invalid PBO access)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ctx->Unpack.BufferObj->Pointer) {
|
||||||
|
/* buffer is mapped - that's an error */
|
||||||
|
_mesa_error(ctx, GL_INVALID_OPERATION,
|
||||||
|
"glDrawPixels(PBO is mapped)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ctx->Driver.DrawPixels(ctx, x, y, width, height, format, type,
|
ctx->Driver.DrawPixels(ctx, x, y, width, height, format, type,
|
||||||
&ctx->Unpack, pixels);
|
&ctx->Unpack, pixels);
|
||||||
}
|
}
|
||||||
@@ -300,6 +318,21 @@ _mesa_ReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ctx->Pack.BufferObj->Name) {
|
||||||
|
if (!_mesa_validate_pbo_access(2, &ctx->Pack, width, height, 1,
|
||||||
|
format, type, pixels)) {
|
||||||
|
_mesa_error(ctx, GL_INVALID_OPERATION,
|
||||||
|
"glReadPixels(invalid PBO access)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx->Pack.BufferObj->Pointer) {
|
||||||
|
/* buffer is mapped - that's an error */
|
||||||
|
_mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(PBO is mapped)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ctx->Driver.ReadPixels(ctx, x, y, width, height,
|
ctx->Driver.ReadPixels(ctx, x, y, width, height,
|
||||||
format, type, &ctx->Pack, pixels);
|
format, type, &ctx->Pack, pixels);
|
||||||
}
|
}
|
||||||
@@ -343,6 +376,23 @@ _mesa_Bitmap( GLsizei width, GLsizei height,
|
|||||||
/* Truncate, to satisfy conformance tests (matches SGI's OpenGL). */
|
/* Truncate, to satisfy conformance tests (matches SGI's OpenGL). */
|
||||||
GLint x = IFLOOR(ctx->Current.RasterPos[0] - xorig);
|
GLint x = IFLOOR(ctx->Current.RasterPos[0] - xorig);
|
||||||
GLint y = IFLOOR(ctx->Current.RasterPos[1] - yorig);
|
GLint y = IFLOOR(ctx->Current.RasterPos[1] - yorig);
|
||||||
|
|
||||||
|
if (ctx->Unpack.BufferObj->Name) {
|
||||||
|
/* unpack from PBO */
|
||||||
|
if (!_mesa_validate_pbo_access(2, &ctx->Unpack, width, height, 1,
|
||||||
|
GL_COLOR_INDEX, GL_BITMAP,
|
||||||
|
(GLvoid *) bitmap)) {
|
||||||
|
_mesa_error(ctx, GL_INVALID_OPERATION,
|
||||||
|
"glBitmap(invalid PBO access)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ctx->Unpack.BufferObj->Pointer) {
|
||||||
|
/* buffer is mapped - that's an error */
|
||||||
|
_mesa_error(ctx, GL_INVALID_OPERATION, "glBitmap(PBO is mapped)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ctx->Driver.Bitmap( ctx, x, y, width, height, &ctx->Unpack, bitmap );
|
ctx->Driver.Bitmap( ctx, x, y, width, height, &ctx->Unpack, bitmap );
|
||||||
}
|
}
|
||||||
#if _HAVE_FULL_GL
|
#if _HAVE_FULL_GL
|
||||||
|
@@ -57,11 +57,9 @@ _swrast_Bitmap( GLcontext *ctx, GLint px, GLint py,
|
|||||||
|
|
||||||
ASSERT(ctx->RenderMode == GL_RENDER);
|
ASSERT(ctx->RenderMode == GL_RENDER);
|
||||||
|
|
||||||
bitmap = _mesa_validate_and_map_bitmap_pbo(ctx, width, height,
|
bitmap = _mesa_map_bitmap_pbo(ctx, unpack, bitmap);
|
||||||
unpack, bitmap);
|
if (!bitmap)
|
||||||
if (!bitmap) {
|
return;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
RENDER_START(swrast,ctx);
|
RENDER_START(swrast,ctx);
|
||||||
|
|
||||||
|
@@ -839,8 +839,7 @@ _swrast_DrawPixels( GLcontext *ctx,
|
|||||||
if (swrast->NewState)
|
if (swrast->NewState)
|
||||||
_swrast_validate_derived( ctx );
|
_swrast_validate_derived( ctx );
|
||||||
|
|
||||||
pixels = _mesa_validate_and_map_drawpix_pbo(ctx, width, height,
|
pixels = _mesa_map_drawpix_pbo(ctx, unpack, pixels);
|
||||||
format, type, unpack, pixels);
|
|
||||||
if (!pixels)
|
if (!pixels)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@@ -574,11 +574,9 @@ _swrast_ReadPixels( GLcontext *ctx,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pixels = _mesa_validate_and_map_readpix_pbo(ctx, x, y, width, height,
|
pixels = _mesa_map_readpix_pbo(ctx, &clippedPacking, pixels);
|
||||||
format, type,
|
if (!pixels)
|
||||||
&clippedPacking, pixels);
|
return;
|
||||||
if (!pixels)
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case GL_COLOR_INDEX:
|
case GL_COLOR_INDEX:
|
||||||
|
Reference in New Issue
Block a user