From: Iago Toral Quiroga Date: Mon, 10 Nov 2014 10:25:20 +0000 (+0100) Subject: swrast: Use _mesa_format_convert to implement draw_rgba_pixels. X-Git-Tag: upstream/17.1.0~21559 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=84eb402c01962e3ff4b70c9948c85a61ed81678f;p=platform%2Fupstream%2Fmesa.git swrast: Use _mesa_format_convert to implement draw_rgba_pixels. This is the only place that uses _mesa_unpack_color_span_float so after this we should be able to remove that function. Reviewed-by: Jason Ekstrand --- diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c index 227faa2..b30e389 100644 --- a/src/mesa/swrast/s_drawpix.c +++ b/src/mesa/swrast/s_drawpix.c @@ -29,6 +29,8 @@ #include "main/condrender.h" #include "main/context.h" #include "main/format_pack.h" +#include "main/format_utils.h" +#include "main/glformats.h" #include "main/image.h" #include "main/imports.h" #include "main/macros.h" @@ -451,6 +453,28 @@ draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y, GLint skipPixels = 0; /* use span array for temp color storage */ GLfloat *rgba = (GLfloat *) span.array->attribs[VARYING_SLOT_COL0]; + void *tempImage = NULL; + + if (unpack->SwapBytes) { + /* We have to handle byte-swapping scenarios before calling + * _mesa_format_convert + */ + GLint swapSize = _mesa_sizeof_packed_type(type); + if (swapSize == 2 || swapSize == 4) { + int components = _mesa_components_in_format(format); + int elementCount = width * height * components; + tempImage = malloc(elementCount * swapSize); + if (!tempImage) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glDrawPixels"); + return; + } + if (swapSize == 2) + _mesa_swap2_copy(tempImage, (GLushort *) pixels, elementCount); + else + _mesa_swap4_copy(tempImage, (GLuint *) pixels, elementCount); + pixels = tempImage; + } + } /* if the span is wider than SWRAST_MAX_WIDTH we have to do it in chunks */ while (skipPixels < width) { @@ -461,11 +485,15 @@ draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y, type, 0, skipPixels); GLint row; + /* get image row as float/RGBA */ + uint32_t srcMesaFormat = _mesa_format_from_format_and_type(format, type); for (row = 0; row < height; row++) { - /* get image row as float/RGBA */ - _mesa_unpack_color_span_float(ctx, spanWidth, GL_RGBA, rgba, - format, type, source, unpack, - transferOps); + int dstRowStride = 4 * width * sizeof(float); + _mesa_format_convert(rgba, RGBA8888_FLOAT, dstRowStride, + (void*)source, srcMesaFormat, srcStride, + spanWidth, 1, NULL); + if (transferOps) + _mesa_apply_rgba_transfer_ops(ctx, transferOps, spanWidth, (GLfloat (*)[4])rgba); /* Set these for each row since the _swrast_write_* functions * may change them while clipping/rendering. */ @@ -490,6 +518,8 @@ draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y, /* XXX this is ugly/temporary, to undo above change */ span.array->ChanType = CHAN_TYPE; + + free(tempImage); } swrast_render_finish(ctx);