From b1a882f178d71d1462b5ee7e7ffde142928b5086 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 7 Feb 2014 16:52:00 +0100 Subject: Fix drawCachedGlyphs on RGBA8888 drawCachedGlyphs draws with the wrong color on RGBA8888. The issue is that the draw routines bitmapblit_quint32 and alphamapblit_quint32 while safe to use on rgba formats, needs to have the input color converted. This patch adds small wrapper functions for bitmapblit and alphamapblit that converts the formats. Two tests are extended to ensure we have test coverage. Change-Id: I5f99f3795eba46a69d4df5b167e6099024e9a060 Reviewed-by: Gunnar Sletta --- src/gui/painting/qdrawhelper.cpp | 89 ++++++++++++++++++++--------------- src/gui/painting/qdrawhelper_avx.cpp | 1 + src/gui/painting/qdrawhelper_sse2.cpp | 7 +++ src/gui/painting/qdrawhelper_x86_p.h | 6 +++ 4 files changed, 66 insertions(+), 37 deletions(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index c71d75cf94..865dab6597 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -5605,7 +5605,7 @@ static void qt_gradient_quint16(int count, const QSpan *spans, void *userData) } } -inline static void qt_bitmapblit_quint32(QRasterBuffer *rasterBuffer, +inline static void qt_bitmapblit_argb32(QRasterBuffer *rasterBuffer, int x, int y, quint32 color, const uchar *map, int mapWidth, int mapHeight, int mapStride) @@ -5614,6 +5614,15 @@ inline static void qt_bitmapblit_quint32(QRasterBuffer *rasterBuffer, map, mapWidth, mapHeight, mapStride); } +inline static void qt_bitmapblit_rgba8888(QRasterBuffer *rasterBuffer, + int x, int y, quint32 color, + const uchar *map, + int mapWidth, int mapHeight, int mapStride) +{ + qt_bitmapblit_template(rasterBuffer, x, y, ARGB2RGBA(color), + map, mapWidth, mapHeight, mapStride); +} + inline static void qt_bitmapblit_quint16(QRasterBuffer *rasterBuffer, int x, int y, quint32 color, const uchar *map, @@ -5725,11 +5734,11 @@ static inline void grayBlendPixel(quint32 *dst, int coverage, int sr, int sg, in } #endif -static void qt_alphamapblit_quint32(QRasterBuffer *rasterBuffer, - int x, int y, quint32 color, - const uchar *map, - int mapWidth, int mapHeight, int mapStride, - const QClipData *clip) +static void qt_alphamapblit_argb32(QRasterBuffer *rasterBuffer, + int x, int y, quint32 color, + const uchar *map, + int mapWidth, int mapHeight, int mapStride, + const QClipData *clip) { const quint32 c = color; const int destStride = rasterBuffer->bytesPerLine() / sizeof(quint32); @@ -5820,10 +5829,19 @@ static void qt_alphamapblit_quint32(QRasterBuffer *rasterBuffer, } } -static void qt_alphargbblit_quint32(QRasterBuffer *rasterBuffer, - int x, int y, quint32 color, - const uint *src, int mapWidth, int mapHeight, int srcStride, - const QClipData *clip) +static void qt_alphamapblit_rgba8888(QRasterBuffer *rasterBuffer, + int x, int y, quint32 color, + const uchar *map, + int mapWidth, int mapHeight, int mapStride, + const QClipData *clip) +{ + qt_alphamapblit_argb32(rasterBuffer, x, y, ARGB2RGBA(color), map, mapWidth, mapHeight, mapStride, clip); +} + +static void qt_alphargbblit_argb32(QRasterBuffer *rasterBuffer, + int x, int y, quint32 color, + const uint *src, int mapWidth, int mapHeight, int srcStride, + const QClipData *clip) { const quint32 c = color; @@ -5965,27 +5983,27 @@ DrawHelper qDrawHelper[QImage::NImageFormats] = { blend_color_argb, qt_gradient_argb32, - qt_bitmapblit_quint32, - qt_alphamapblit_quint32, - qt_alphargbblit_quint32, + qt_bitmapblit_argb32, + qt_alphamapblit_argb32, + qt_alphargbblit_argb32, qt_rectfill_argb32 }, // Format_ARGB32, { blend_color_generic, qt_gradient_argb32, - qt_bitmapblit_quint32, - qt_alphamapblit_quint32, - qt_alphargbblit_quint32, + qt_bitmapblit_argb32, + qt_alphamapblit_argb32, + qt_alphargbblit_argb32, qt_rectfill_nonpremul_argb32 }, // Format_ARGB32_Premultiplied { blend_color_argb, qt_gradient_argb32, - qt_bitmapblit_quint32, - qt_alphamapblit_quint32, - qt_alphargbblit_quint32, + qt_bitmapblit_argb32, + qt_alphamapblit_argb32, + qt_alphargbblit_argb32, qt_rectfill_argb32 }, // Format_RGB16 @@ -6049,42 +6067,39 @@ DrawHelper qDrawHelper[QImage::NImageFormats] = { blend_color_generic, blend_src_generic, - qt_bitmapblit_quint32, + qt_bitmapblit_rgba8888, #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN - qt_alphamapblit_quint32, - qt_alphargbblit_quint32, + qt_alphamapblit_rgba8888, #else 0, - 0, #endif + 0, qt_rectfill_rgba }, // Format_RGBA8888 { blend_color_generic, blend_src_generic, - qt_bitmapblit_quint32, + qt_bitmapblit_rgba8888, #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN - qt_alphamapblit_quint32, - qt_alphargbblit_quint32, + qt_alphamapblit_rgba8888, #else 0, - 0, #endif + 0, qt_rectfill_nonpremul_rgba }, // Format_RGB8888_Premultiplied { blend_color_generic, blend_src_generic, - qt_bitmapblit_quint32, + qt_bitmapblit_rgba8888, #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN - qt_alphamapblit_quint32, - qt_alphargbblit_quint32, + qt_alphamapblit_rgba8888, #else 0, - 0, #endif + 0, qt_rectfill_rgba } }; @@ -6173,9 +6188,9 @@ void qInitDrawhelperAsm() qDrawHelper[QImage::Format_ARGB32].bitmapBlit = qt_bitmapblit32_avx; qDrawHelper[QImage::Format_ARGB32_Premultiplied].bitmapBlit = qt_bitmapblit32_avx; qDrawHelper[QImage::Format_RGB16].bitmapBlit = qt_bitmapblit16_avx; - qDrawHelper[QImage::Format_RGBX8888].bitmapBlit = qt_bitmapblit32_avx; - qDrawHelper[QImage::Format_RGBA8888].bitmapBlit = qt_bitmapblit32_avx; - qDrawHelper[QImage::Format_RGBA8888_Premultiplied].bitmapBlit = qt_bitmapblit32_avx; + qDrawHelper[QImage::Format_RGBX8888].bitmapBlit = qt_bitmapblit8888_avx; + qDrawHelper[QImage::Format_RGBA8888].bitmapBlit = qt_bitmapblit8888_avx; + qDrawHelper[QImage::Format_RGBA8888_Premultiplied].bitmapBlit = qt_bitmapblit8888_avx; extern void qt_scale_image_argb32_on_argb32_avx(uchar *destPixels, int dbpl, const uchar *srcPixels, int sbpl, @@ -6198,9 +6213,9 @@ void qInitDrawhelperAsm() qDrawHelper[QImage::Format_ARGB32].bitmapBlit = qt_bitmapblit32_sse2; qDrawHelper[QImage::Format_ARGB32_Premultiplied].bitmapBlit = qt_bitmapblit32_sse2; qDrawHelper[QImage::Format_RGB16].bitmapBlit = qt_bitmapblit16_sse2; - qDrawHelper[QImage::Format_RGBX8888].bitmapBlit = qt_bitmapblit32_sse2; - qDrawHelper[QImage::Format_RGBA8888].bitmapBlit = qt_bitmapblit32_sse2; - qDrawHelper[QImage::Format_RGBA8888_Premultiplied].bitmapBlit = qt_bitmapblit32_sse2; + qDrawHelper[QImage::Format_RGBX8888].bitmapBlit = qt_bitmapblit8888_sse2; + qDrawHelper[QImage::Format_RGBA8888].bitmapBlit = qt_bitmapblit8888_sse2; + qDrawHelper[QImage::Format_RGBA8888_Premultiplied].bitmapBlit = qt_bitmapblit8888_sse2; extern void qt_scale_image_argb32_on_argb32_sse2(uchar *destPixels, int dbpl, const uchar *srcPixels, int sbpl, diff --git a/src/gui/painting/qdrawhelper_avx.cpp b/src/gui/painting/qdrawhelper_avx.cpp index 7da6ce6a20..7d42525150 100644 --- a/src/gui/painting/qdrawhelper_avx.cpp +++ b/src/gui/painting/qdrawhelper_avx.cpp @@ -60,6 +60,7 @@ #define qt_memfill32_sse2 qt_memfill32_avx #define qt_memfill16_sse2 qt_memfill16_avx #define qt_bitmapblit32_sse2 qt_bitmapblit32_avx +#define qt_bitmapblit8888_sse2 qt_bitmapblit8888_avx #define qt_bitmapblit16_sse2 qt_bitmapblit16_avx #define QSimdSse2 QSimdAvx #define qt_fetch_radial_gradient_sse2 qt_fetch_radial_gradient_avx diff --git a/src/gui/painting/qdrawhelper_sse2.cpp b/src/gui/painting/qdrawhelper_sse2.cpp index a9dc5a7fb7..ea191c2ec5 100644 --- a/src/gui/painting/qdrawhelper_sse2.cpp +++ b/src/gui/painting/qdrawhelper_sse2.cpp @@ -470,6 +470,13 @@ void qt_bitmapblit32_sse2(QRasterBuffer *rasterBuffer, int x, int y, } } +void qt_bitmapblit8888_sse2(QRasterBuffer *rasterBuffer, int x, int y, + quint32 color, + const uchar *src, int width, int height, int stride) +{ + qt_bitmapblit32_sse2(rasterBuffer, x, y, ARGB2RGBA(color), src, width, height, stride); +} + void qt_bitmapblit16_sse2(QRasterBuffer *rasterBuffer, int x, int y, quint32 color, const uchar *src, int width, int height, int stride) diff --git a/src/gui/painting/qdrawhelper_x86_p.h b/src/gui/painting/qdrawhelper_x86_p.h index d64b9cec39..aee508f641 100644 --- a/src/gui/painting/qdrawhelper_x86_p.h +++ b/src/gui/painting/qdrawhelper_x86_p.h @@ -63,6 +63,9 @@ void qt_memfill16_sse2(quint16 *dest, quint16 value, int count); void qt_bitmapblit32_sse2(QRasterBuffer *rasterBuffer, int x, int y, quint32 color, const uchar *src, int width, int height, int stride); +void qt_bitmapblit8888_sse2(QRasterBuffer *rasterBuffer, int x, int y, + quint32 color, + const uchar *src, int width, int height, int stride); void qt_bitmapblit16_sse2(QRasterBuffer *rasterBuffer, int x, int y, quint32 color, const uchar *src, int width, int height, int stride); @@ -85,6 +88,9 @@ void qt_memfill16_avx(quint16 *dest, quint16 value, int count); void qt_bitmapblit32_avx(QRasterBuffer *rasterBuffer, int x, int y, quint32 color, const uchar *src, int width, int height, int stride); +void qt_bitmapblit8888_avx(QRasterBuffer *rasterBuffer, int x, int y, + quint32 color, + const uchar *src, int width, int height, int stride); void qt_bitmapblit16_avx(QRasterBuffer *rasterBuffer, int x, int y, quint32 color, const uchar *src, int width, int height, int stride); -- cgit v1.2.3