[Mesa-dev] [PATCH v3 15/28] swrast: Use _mesa_format_convert to implement draw_rgba_pixels.
Jason Ekstrand
jason at jlekstrand.net
Fri Dec 12 11:50:36 PST 2014
On Tue, Dec 9, 2014 at 4:07 AM, Iago Toral Quiroga <itoral at igalia.com>
wrote:
>
> This is the only place that uses _mesa_unpack_color_span_float so after
> this we should be able to remove that function.
> ---
> src/mesa/swrast/s_drawpix.c | 39 +++++++++++++++++++++++++++++++++++----
> 1 file changed, 35 insertions(+), 4 deletions(-)
>
> diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c
> index 227faa2..dcf5581 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,9 @@ 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;
> +
> + if (tempImage)
> + free(tempImage);
>
You don't need the if. Otherwise, It looks fine.
> }
>
> swrast_render_finish(ctx);
> --
> 1.9.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20141212/7d7755a1/attachment.html>
More information about the mesa-dev
mailing list