From 56e9221b362129712e9e2900d6bba95b48ff4039 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 23 Nov 2016 18:07:52 +0100 Subject: [PATCH] Implement clip part of qt_alphamapblit_quint16 Adds handling of clipping in qt_alphamapblit_quint16, this is also preparing for a generic implementation of alphamapblit. Change-Id: I706f08179abefa74f8de138369a0dc8ce19510fc Reviewed-by: Laszlo Agocs --- src/gui/painting/qdrawhelper.cpp | 69 ++++++++++++++++-------- src/gui/painting/qdrawhelper_neon.cpp | 13 ++++- src/gui/painting/qpaintengine_raster.cpp | 2 +- 3 files changed, 60 insertions(+), 24 deletions(-) diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index 4ea3b37d5f..b7d3920599 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -5543,32 +5543,57 @@ inline static void qt_bitmapblit_quint16(QRasterBuffer *rasterBuffer, map, mapWidth, mapHeight, mapStride); } -static void qt_alphamapblit_quint16(QRasterBuffer *rasterBuffer, - int x, int y, const QRgba64 &color, - const uchar *map, - int mapWidth, int mapHeight, int mapStride, - const QClipData *, bool /*useGammaCorrection*/) +static inline void alphamapblend_quint16(int coverage, quint16 *dest, int x, const quint16 srcColor) +{ + if (coverage == 0) { + // nothing + } else if (coverage == 255) { + dest[x] = srcColor; + } else { + dest[x] = BYTE_MUL_RGB16(srcColor, coverage) + + BYTE_MUL_RGB16(dest[x], 255 - coverage); + } +} + +void qt_alphamapblit_quint16(QRasterBuffer *rasterBuffer, + int x, int y, const QRgba64 &color, + const uchar *map, + int mapWidth, int mapHeight, int mapStride, + const QClipData *clip, bool /*useGammaCorrection*/) { const quint16 c = color.toRgb16(); - quint16 *dest = reinterpret_cast(rasterBuffer->scanLine(y)) + x; - const int destStride = rasterBuffer->bytesPerLine() / sizeof(quint16); - while (mapHeight--) { - for (int i = 0; i < mapWidth; ++i) { - const int coverage = map[i]; - - if (coverage == 0) { - // nothing - } else if (coverage == 255) { - dest[i] = c; - } else { - int ialpha = 255 - coverage; - dest[i] = BYTE_MUL_RGB16(c, coverage) - + BYTE_MUL_RGB16(dest[i], ialpha); - } + if (!clip) { + quint16 *dest = reinterpret_cast(rasterBuffer->scanLine(y)) + x; + const int destStride = rasterBuffer->bytesPerLine() / sizeof(quint16); + while (mapHeight--) { + for (int i = 0; i < mapWidth; ++i) + alphamapblend_quint16(map[i], dest, i, c); + dest += destStride; + map += mapStride; } - dest += destStride; - map += mapStride; + } else { + int top = qMax(y, 0); + int bottom = qMin(y + mapHeight, rasterBuffer->height()); + map += (top - y) * mapStride; + + const_cast(clip)->initialize(); + for (int yp = top; ypm_clipLines[yp]; + + quint16 *dest = reinterpret_cast(rasterBuffer->scanLine(yp)); + + for (int i=0; i(x, clip.x); + int end = qMin(x + mapWidth, clip.x + clip.len); + + for (int xp=start; xp line.count) + map += mapStride; + } // for (yp -> bottom) } } diff --git a/src/gui/painting/qdrawhelper_neon.cpp b/src/gui/painting/qdrawhelper_neon.cpp index 643c570f65..4cbac009d8 100644 --- a/src/gui/painting/qdrawhelper_neon.cpp +++ b/src/gui/painting/qdrawhelper_neon.cpp @@ -535,12 +535,23 @@ void qt_blend_rgb32_on_rgb32_neon(uchar *destPixels, int dbpl, } #if defined(ENABLE_PIXMAN_DRAWHELPERS) +extern void qt_alphamapblit_quint16(QRasterBuffer *rasterBuffer, + int x, int y, const QRgba64 &color, + const uchar *map, + int mapWidth, int mapHeight, int mapStride, + const QClipData *clip, bool useGammaCorrection); + void qt_alphamapblit_quint16_neon(QRasterBuffer *rasterBuffer, int x, int y, const QRgba64 &color, const uchar *bitmap, int mapWidth, int mapHeight, int mapStride, - const QClipData *, bool /*useGammaCorrection*/) + const QClipData *clip, bool useGammaCorrection) { + if (clip || useGammaCorrection) { + qt_alphamapblit_quint16(rasterBuffer, x, y, color, bitmap, mapWidth, mapHeight, mapStride, clip, useGammaCorrection); + return; + } + quint16 *dest = reinterpret_cast(rasterBuffer->scanLine(y)) + x; const int destStride = rasterBuffer->bytesPerLine() / sizeof(quint16); diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index fc4f2a9944..eb43453ddb 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -2621,7 +2621,7 @@ void QRasterPaintEngine::alphaPenBlt(const void* src, int bpl, int depth, int rx return; } } - } else if (d->deviceDepth == 32 && ((depth == 8 && s->penData.alphamapBlit) || (depth == 32 && s->penData.alphaRGBBlit))) { + } else if ((depth == 8 && s->penData.alphamapBlit) || (depth == 32 && s->penData.alphaRGBBlit)) { // (A)RGB Alpha mask where the alpha component is not used. if (!clip) { int nx = qMax(0, rx);