#include "stdint.h"
#include "main/bufferobj.h"
#include "main/enums.h"
+#include "main/fbobject.h"
#include "main/image.h"
+#include "main/readpix.h"
#include "main/state.h"
-#include "swrast/swrast.h"
#include "radeon_common_context.h"
+#include "radeon_buffer_objects.h"
#include "radeon_debug.h"
#include "radeon_mipmap_tree.h"
-static gl_format gl_format_and_type_to_mesa_format(GLenum format, GLenum type)
+static mesa_format gl_format_and_type_to_mesa_format(GLenum format, GLenum type)
{
switch (format)
{
case GL_RGB:
switch (type) {
case GL_UNSIGNED_SHORT_5_6_5:
- return MESA_FORMAT_RGB565;
+ return MESA_FORMAT_B5G6R5_UNORM;
case GL_UNSIGNED_SHORT_5_6_5_REV:
- return MESA_FORMAT_RGB565_REV;
+ return MESA_FORMAT_R5G6B5_UNORM;
}
break;
case GL_RGBA:
case GL_FLOAT:
return MESA_FORMAT_RGBA_FLOAT32;
case GL_UNSIGNED_SHORT_5_5_5_1:
- return MESA_FORMAT_RGBA5551;
+ return MESA_FORMAT_A1B5G5R5_UNORM;
case GL_UNSIGNED_INT_8_8_8_8:
- return MESA_FORMAT_RGBA8888;
+ return MESA_FORMAT_A8B8G8R8_UNORM;
case GL_UNSIGNED_BYTE:
case GL_UNSIGNED_INT_8_8_8_8_REV:
- return MESA_FORMAT_RGBA8888_REV;
+ return MESA_FORMAT_R8G8B8A8_UNORM;
}
break;
case GL_BGRA:
switch (type) {
case GL_UNSIGNED_SHORT_4_4_4_4:
- return MESA_FORMAT_ARGB4444_REV;
+ return MESA_FORMAT_A4R4G4B4_UNORM;
case GL_UNSIGNED_SHORT_4_4_4_4_REV:
- return MESA_FORMAT_ARGB4444;
+ return MESA_FORMAT_B4G4R4A4_UNORM;
case GL_UNSIGNED_SHORT_5_5_5_1:
- return MESA_FORMAT_ARGB1555_REV;
+ return MESA_FORMAT_A1R5G5B5_UNORM;
case GL_UNSIGNED_SHORT_1_5_5_5_REV:
- return MESA_FORMAT_ARGB1555;
+ return MESA_FORMAT_B5G5R5A1_UNORM;
case GL_UNSIGNED_INT_8_8_8_8:
- return MESA_FORMAT_ARGB8888_REV;
+ return MESA_FORMAT_A8R8G8B8_UNORM;
case GL_UNSIGNED_BYTE:
case GL_UNSIGNED_INT_8_8_8_8_REV:
- return MESA_FORMAT_ARGB8888;
+ return MESA_FORMAT_B8G8R8A8_UNORM;
}
break;
}
static GLboolean
-do_blit_readpixels(GLcontext * ctx,
+do_blit_readpixels(struct gl_context * ctx,
GLint x, GLint y, GLsizei width, GLsizei height,
GLenum format, GLenum type,
const struct gl_pixelstore_attrib *pack, GLvoid * pixels)
{
radeonContextPtr radeon = RADEON_CONTEXT(ctx);
const struct radeon_renderbuffer *rrb = radeon_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer);
- const gl_format dst_format = gl_format_and_type_to_mesa_format(format, type);
+ const mesa_format dst_format = gl_format_and_type_to_mesa_format(format, type);
unsigned dst_rowstride, dst_imagesize, aligned_rowstride, flip_y;
struct radeon_bo *dst_buffer;
GLint dst_x = 0, dst_y = 0;
+ intptr_t dst_offset;
/* It's not worth if number of pixels to copy is really small */
if (width * height < 100) {
}
if (dst_format == MESA_FORMAT_NONE ||
- !radeon->vtbl.check_blit(dst_format) || !radeon->vtbl.blit) {
+ !radeon->vtbl.check_blit(dst_format, rrb->pitch / rrb->cpp) || !radeon->vtbl.blit) {
return GL_FALSE;
}
- if (ctx->_ImageTransferState || ctx->Color._LogicOpEnabled) {
+ if (ctx->_ImageTransferState || ctx->Color.ColorLogicOpEnabled) {
return GL_FALSE;
}
}
assert(x >= 0 && y >= 0);
- aligned_rowstride = get_texture_image_row_stride(radeon, dst_format, dst_rowstride, 0);
+ aligned_rowstride = get_texture_image_row_stride(radeon, dst_format, dst_rowstride, 0, GL_TEXTURE_2D);
+ dst_rowstride *= _mesa_get_format_bytes(dst_format);
+ if (_mesa_is_bufferobj(pack->BufferObj) && aligned_rowstride != dst_rowstride)
+ return GL_FALSE;
dst_imagesize = get_texture_image_size(dst_format,
aligned_rowstride,
height, 1, 0);
- dst_buffer = radeon_bo_open(radeon->radeonScreen->bom, 0, dst_imagesize, 1024, RADEON_GEM_DOMAIN_GTT, 0);
+
+ if (!_mesa_is_bufferobj(pack->BufferObj))
+ {
+ dst_buffer = radeon_bo_open(radeon->radeonScreen->bom, 0, dst_imagesize, 1024, RADEON_GEM_DOMAIN_GTT, 0);
+ dst_offset = 0;
+ }
+ else
+ {
+ dst_buffer = get_radeon_buffer_object(pack->BufferObj)->bo;
+ dst_offset = (intptr_t)pixels;
+ }
/* Disable source Y flipping for FBOs */
- flip_y = (ctx->ReadBuffer->Name == 0);
+ flip_y = _mesa_is_winsys_fbo(ctx->ReadBuffer);
if (pack->Invert) {
- y = rrb->base.Height - height - y;
+ y = rrb->base.Base.Height - height - y;
flip_y = !flip_y;
}
if (radeon->vtbl.blit(ctx,
rrb->bo,
rrb->draw_offset,
- rrb->base.Format,
+ rrb->base.Base.Format,
rrb->pitch / rrb->cpp,
- rrb->base.Width,
- rrb->base.Height,
+ rrb->base.Base.Width,
+ rrb->base.Base.Height,
x,
y,
dst_buffer,
- 0, /* dst_offset */
+ dst_offset,
dst_format,
aligned_rowstride / _mesa_get_format_bytes(dst_format),
width,
height,
flip_y))
{
- radeon_bo_map(dst_buffer, 0);
- dst_rowstride *= _mesa_get_format_bytes(dst_format);
- copy_rows(pixels, dst_rowstride, dst_buffer->ptr,
- aligned_rowstride, height, dst_rowstride);
- radeon_bo_unmap(dst_buffer);
- radeon_bo_unref(dst_buffer);
+ if (!_mesa_is_bufferobj(pack->BufferObj))
+ {
+ radeon_bo_map(dst_buffer, 0);
+ copy_rows(pixels, dst_rowstride, dst_buffer->ptr,
+ aligned_rowstride, height, dst_rowstride);
+ radeon_bo_unmap(dst_buffer);
+ radeon_bo_unref(dst_buffer);
+ }
+
return GL_TRUE;
- } else {
- radeon_bo_unref(dst_buffer);
- return GL_FALSE;
}
+
+ if (!_mesa_is_bufferobj(pack->BufferObj))
+ radeon_bo_unref(dst_buffer);
+
+ return GL_FALSE;
}
void
-radeonReadPixels(GLcontext * ctx,
+radeonReadPixels(struct gl_context * ctx,
GLint x, GLint y, GLsizei width, GLsizei height,
GLenum format, GLenum type,
const struct gl_pixelstore_attrib *pack, GLvoid * pixels)
if (do_blit_readpixels(ctx, x, y, width, height, format, type, pack, pixels))
return;
- /* Update Mesa state before calling down into _swrast_ReadPixels, as
- * the spans code requires the computed buffer states to be up to date,
- * but _swrast_ReadPixels only updates Mesa state after setting up
- * the spans code.
+ /* Update Mesa state before calling _mesa_readpixels().
+ * XXX this may not be needed since ReadPixels no longer uses the
+ * span code.
*/
-
radeon_print(RADEON_FALLBACKS, RADEON_NORMAL,
"Falling back to sw for ReadPixels (format %s, type %s)\n",
- _mesa_lookup_enum_by_nr(format), _mesa_lookup_enum_by_nr(type));
+ _mesa_enum_to_string(format), _mesa_enum_to_string(type));
if (ctx->NewState)
_mesa_update_state(ctx);
- _swrast_ReadPixels(ctx, x, y, width, height, format, type, pack, pixels);
+ _mesa_readpixels(ctx, x, y, width, height, format, type, pack, pixels);
}