diff options
author | Julien Brianceau <jbrianceau@nds.com> | 2012-09-11 14:30:11 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-09-12 05:42:25 (GMT) |
commit | 3dc047a4e11d2b18259d3ee383e81147c9098cb7 (patch) | |
tree | c1ad99346019a1c1baf844f0f50e03251729798f /src/gui | |
parent | 6c564607770479173967b9a74926cbe1c4bc109e (diff) | |
download | Qt-3dc047a4e11d2b18259d3ee383e81147c9098cb7.zip Qt-3dc047a4e11d2b18259d3ee383e81147c9098cb7.tar.gz Qt-3dc047a4e11d2b18259d3ee383e81147c9098cb7.tar.bz2 |
qpa: add non-opaque fill support
Add non-opaque fill support for qpa through new QBlittable flag
"AlphaFillRectCapability" and add related implementation in DirectFB
qpa platform.
cherry-picked from qt5/qtbase aab15782e21bf0aaea7f2211278e9aa9fc78c6d7
Change-Id: Ia1c74c2926d2e244290dcb62cbd3b6848ba95707
Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/image/qpixmap_blitter.cpp | 6 | ||||
-rw-r--r-- | src/gui/painting/qblittable_p.h | 7 | ||||
-rw-r--r-- | src/gui/painting/qpaintengine_blitter.cpp | 66 |
3 files changed, 66 insertions, 13 deletions
diff --git a/src/gui/image/qpixmap_blitter.cpp b/src/gui/image/qpixmap_blitter.cpp index fd1742c..76a1a7d 100644 --- a/src/gui/image/qpixmap_blitter.cpp +++ b/src/gui/image/qpixmap_blitter.cpp @@ -133,8 +133,10 @@ int QBlittablePixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const void QBlittablePixmapData::fill(const QColor &color) { - //jlind: todo: change when blittables can support non opaque fillRects - if (color.alpha() == 255 && blittable()->capabilities() & QBlittable::SolidRectCapability) { + if (blittable()->capabilities() & QBlittable::AlphaFillRectCapability) { + blittable()->unlock(); + blittable()->alphaFillRect(QRectF(0,0,w,h),color,QPainter::CompositionMode_Source); + } else if (color.alpha() == 255 && blittable()->capabilities() & QBlittable::SolidRectCapability) { blittable()->unlock(); blittable()->fillRect(QRectF(0,0,w,h),color); } else { diff --git a/src/gui/painting/qblittable_p.h b/src/gui/painting/qblittable_p.h index 53793bd..d89fd22 100644 --- a/src/gui/painting/qblittable_p.h +++ b/src/gui/painting/qblittable_p.h @@ -62,6 +62,7 @@ public: SourcePixmapCapability = 0x0002, SourceOverPixmapCapability = 0x0004, SourceOverScaledPixmapCapability = 0x0008, + AlphaFillRectCapability = 0x0010, // Internal ones OutlineCapability = 0x0001000, @@ -76,6 +77,12 @@ public: virtual void fillRect(const QRectF &rect, const QColor &color) = 0; virtual void drawPixmap(const QRectF &rect, const QPixmap &pixmap, const QRectF &subrect) = 0; + virtual void alphaFillRect(const QRectF &rect, const QColor &color, QPainter::CompositionMode cmode) { + Q_UNUSED(rect); + Q_UNUSED(color); + Q_UNUSED(cmode); + qWarning("Please implement alphaFillRect function in your platform or remove AlphaFillRectCapability from it"); + } bool isLocked() const; diff --git a/src/gui/painting/qpaintengine_blitter.cpp b/src/gui/painting/qpaintengine_blitter.cpp index d4eb619..679e21b 100644 --- a/src/gui/painting/qpaintengine_blitter.cpp +++ b/src/gui/painting/qpaintengine_blitter.cpp @@ -74,6 +74,7 @@ public: , fillRectMask(0) , drawRectMask(0) , drawPixmapMask(0) + , alphaFillRectMask(0) , capabillitiesState(0) { if (capabilities & QBlittable::SolidRectCapability) @@ -84,6 +85,8 @@ public: setSourceOverPixmapMask(); if (capabilities & QBlittable::SourceOverScaledPixmapCapability) setSourceOverScaledPixmapMask(); + if (capabilities & QBlittable::AlphaFillRectCapability) + setAlphaFillRectMask(); } inline bool canBlitterFillRect() const @@ -91,6 +94,11 @@ public: return checkStateAgainstMask(capabillitiesState, fillRectMask); } + inline bool canBlitterAlphaFillRect() const + { + return checkStateAgainstMask(capabillitiesState, alphaFillRectMask); + } + inline bool canBlitterDrawRectMask() const { return checkStateAgainstMask(capabillitiesState, drawRectMask); @@ -148,6 +156,24 @@ private: updateStateBits(&fillRectMask, STATE_CLIP_COMPLEX, false); } + void setAlphaFillRectMask() { + updateStateBits(&alphaFillRectMask, STATE_XFORM_SCALE, false); + updateStateBits(&alphaFillRectMask, STATE_XFORM_COMPLEX, false); + + updateStateBits(&alphaFillRectMask, STATE_BRUSH_PATTERN, false); + updateStateBits(&alphaFillRectMask, STATE_BRUSH_ALPHA, true); + + updateStateBits(&alphaFillRectMask, STATE_PEN_ENABLED, true); + + //Sub-pixel aliasing should not be sent to the blitter + updateStateBits(&alphaFillRectMask, STATE_ANTIALIASING, true); + updateStateBits(&alphaFillRectMask, STATE_ALPHA, false); + updateStateBits(&alphaFillRectMask, STATE_BLENDING_COMPLEX, false); + + updateStateBits(&alphaFillRectMask, STATE_CLIPSYS_COMPLEX, false); + updateStateBits(&alphaFillRectMask, STATE_CLIP_COMPLEX, false); + } + void setSourcePixmapMask() { updateStateBits(&drawPixmapMask, STATE_XFORM_SCALE, true); updateStateBits(&drawPixmapMask, STATE_XFORM_COMPLEX, false); @@ -178,6 +204,7 @@ private: uint fillRectMask; uint drawRectMask; uint drawPixmapMask; + uint alphaFillRectMask; uint capabillitiesState; }; @@ -195,7 +222,7 @@ public: void lock(); void unlock(); - void fillRect(const QRectF& rect, const QColor&); + void fillRect(const QRectF& rect, const QColor&, bool alpha); void clipAndDrawPixmap(const QRectF &clip, const QRectF &target, const QPixmap &pm, const QRectF &sr); @@ -287,7 +314,7 @@ void QBlitterPaintEnginePrivate::updateClipState(QPainterState *) caps.updateState(STATE_CLIP_COMPLEX, complexClip); } -void QBlitterPaintEnginePrivate::fillRect(const QRectF &rect, const QColor &color) +void QBlitterPaintEnginePrivate::fillRect(const QRectF &rect, const QColor &color, bool alpha) { Q_Q(QBlitterPaintEngine); pmData->unmarkRasterOverlay(rect); @@ -298,14 +325,20 @@ void QBlitterPaintEnginePrivate::fillRect(const QRectF &rect, const QColor &colo if (clipData) { if (clipData->hasRectClip) { unlock(); - pmData->blittable()->fillRect(targetRect & clipData->clipRect, color); + if (alpha) + pmData->blittable()->alphaFillRect(targetRect & clipData->clipRect, color, q->state()->compositionMode()); + else + pmData->blittable()->fillRect(targetRect & clipData->clipRect, color); } else if (clipData->hasRegionClip) { QVector<QRect> rects = clipData->clipRegion.rects(); for (int i = 0; i < rects.size(); ++i) { QRect intersectRect = rects.at(i).intersected(targetRect.toRect()); if (!intersectRect.isEmpty()) { unlock(); - pmData->blittable()->fillRect(intersectRect, color); + if (alpha) + pmData->blittable()->alphaFillRect(intersectRect, color, q->state()->compositionMode()); + else + pmData->blittable()->fillRect(intersectRect, color); } } } @@ -314,11 +347,17 @@ void QBlitterPaintEnginePrivate::fillRect(const QRectF &rect, const QColor &colo && targetRect.width() <= q->paintDevice()->width() && targetRect.height() <= q->paintDevice()->height()) { unlock(); - pmData->blittable()->fillRect(targetRect, color); + if (alpha) + pmData->blittable()->alphaFillRect(targetRect, color, q->state()->compositionMode()); + else + pmData->blittable()->fillRect(targetRect, color); } else { QRectF deviceRect(0, 0, q->paintDevice()->width(), q->paintDevice()->height()); unlock(); - pmData->blittable()->fillRect(deviceRect & targetRect, color); + if (alpha) + pmData->blittable()->alphaFillRect(deviceRect & targetRect, color, q->state()->compositionMode()); + else + pmData->blittable()->fillRect(deviceRect & targetRect, color); } } } @@ -457,8 +496,10 @@ void QBlitterPaintEngine::fill(const QVectorPath &path, const QBrush &brush) void QBlitterPaintEngine::fillRect(const QRectF &rect, const QColor &color) { Q_D(QBlitterPaintEngine); - if (d->caps.canBlitterFillRect() && color.alpha() == 0xff) { - d->fillRect(rect, color); + if (d->caps.canBlitterAlphaFillRect()) { + d->fillRect(rect, color, true); + } else if (d->caps.canBlitterFillRect() && color.alpha() == 0xff) { + d->fillRect(rect, color, false); } else { d->lock(); d->pmData->markRasterOverlay(rect); @@ -474,9 +515,12 @@ void QBlitterPaintEngine::fillRect(const QRectF &rect, const QBrush &brush) Q_D(QBlitterPaintEngine); if (qbrush_style(brush) == Qt::SolidPattern + && d->caps.canBlitterAlphaFillRect()) { + d->fillRect(rect, qbrush_color(brush), true); + } else if (qbrush_style(brush) == Qt::SolidPattern && qbrush_color(brush).alpha() == 0xff && d->caps.canBlitterFillRect()) { - d->fillRect(rect, qbrush_color(brush)); + d->fillRect(rect, qbrush_color(brush), false); } else if (brush.style() == Qt::TexturePattern && d->caps.canBlitterDrawPixmap(rect, brush.texture(), rect)) { bool rectIsFilled = false; @@ -547,7 +591,7 @@ void QBlitterPaintEngine::drawRects(const QRect *rects, int rectCount) Q_D(QBlitterPaintEngine); if (d->caps.canBlitterDrawRectMask()) { for (int i=0; i<rectCount; ++i) - d->fillRect(rects[i], qbrush_color(state()->brush)); + d->fillRect(rects[i], qbrush_color(state()->brush), false); } else { d->pmData->markRasterOverlay(rects, rectCount); QRasterPaintEngine::drawRects(rects, rectCount); @@ -559,7 +603,7 @@ void QBlitterPaintEngine::drawRects(const QRectF *rects, int rectCount) Q_D(QBlitterPaintEngine); if (d->caps.canBlitterDrawRectMask()) { for (int i = 0; i < rectCount; ++i) - d->fillRect(rects[i], qbrush_color(state()->brush)); + d->fillRect(rects[i], qbrush_color(state()->brush), false); } else { d->pmData->markRasterOverlay(rects, rectCount); QRasterPaintEngine::drawRects(rects, rectCount); |