summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
diff options
context:
space:
mode:
authorJulien Brianceau <jbrianceau@nds.com>2012-09-12 12:46:21 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-09-12 17:45:30 (GMT)
commitbdbfc1d1824c32b00506b2a3b8d1b176c3c9a8a0 (patch)
tree50f457d701695cbd7ef3553e1206ae1721a71bd5 /src/plugins/platforms
parent5032ca8cde5ed6fa39acfde650d373fcb4ea7807 (diff)
downloadQt-bdbfc1d1824c32b00506b2a3b8d1b176c3c9a8a0.zip
Qt-bdbfc1d1824c32b00506b2a3b8d1b176c3c9a8a0.tar.gz
Qt-bdbfc1d1824c32b00506b2a3b8d1b176c3c9a8a0.tar.bz2
qpa: extend drawPixmap capabilities
Extend drawPixmap capabilities for qpa through new OpacityPixmapCapability QBlittable flag and add related implementation in DirectFB platform. cherry-picked from qt5/qtbase 4ae829c1dbd0e8a72b82ab4c6cddb0a4ffe009f6 Change-Id: I8abdb0fa72bc030d769190d7cba40561007e7b46 Reviewed-by: Jørgen Lind <jorgen.lind@gmail.com>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r--src/plugins/platforms/directfb/qdirectfbblitter.cpp80
-rw-r--r--src/plugins/platforms/directfb/qdirectfbblitter.h1
2 files changed, 48 insertions, 33 deletions
diff --git a/src/plugins/platforms/directfb/qdirectfbblitter.cpp b/src/plugins/platforms/directfb/qdirectfbblitter.cpp
index efbfc77..3932f0c 100644
--- a/src/plugins/platforms/directfb/qdirectfbblitter.cpp
+++ b/src/plugins/platforms/directfb/qdirectfbblitter.cpp
@@ -57,7 +57,8 @@ static QBlittable::Capabilities dfb_blitter_capabilities()
|QBlittable::SourcePixmapCapability
|QBlittable::SourceOverPixmapCapability
|QBlittable::SourceOverScaledPixmapCapability
- |QBlittable::AlphaFillRectCapability);
+ |QBlittable::AlphaFillRectCapability
+ |QBlittable::OpacityPixmapCapability);
}
QDirectFbBlitter::QDirectFbBlitter(const QSize &rect, IDirectFBSurface *surface)
@@ -79,7 +80,7 @@ QDirectFbBlitter::QDirectFbBlitter(const QSize &rect, bool alpha)
surfaceDesc.width = rect.width();
surfaceDesc.height = rect.height();
- // force alpha format to get AlphaFillRectCapability support
+ // force alpha format to get AlphaFillRectCapability and ExtendedPixmapCapability support
alpha = true;
if (alpha) {
@@ -124,37 +125,7 @@ void QDirectFbBlitter::fillRect(const QRectF &rect, const QColor &color)
void QDirectFbBlitter::drawPixmap(const QRectF &rect, const QPixmap &pixmap, const QRectF &srcRect)
{
- QPixmapData *data = pixmap.pixmapData();
- Q_ASSERT(data->width() && data->height());
- Q_ASSERT(data->classId() == QPixmapData::BlitterClass);
- QBlittablePixmapData *blitPm = static_cast<QBlittablePixmapData*>(data);
- QDirectFbBlitter *dfbBlitter = static_cast<QDirectFbBlitter *>(blitPm->blittable());
- dfbBlitter->unlock();
-
- IDirectFBSurface *s = dfbBlitter->m_surface.data();
-
- DFBSurfaceBlittingFlags blittingFlags = DSBLIT_NOFX;
- DFBSurfacePorterDuffRule porterDuff = DSPD_SRC;
- if (pixmap.hasAlpha()) {
- blittingFlags = DSBLIT_BLEND_ALPHACHANNEL;
- porterDuff = DSPD_SRC_OVER;
- }
-
- m_surface->SetBlittingFlags(m_surface.data(), DFBSurfaceBlittingFlags(blittingFlags));
- m_surface->SetPorterDuff(m_surface.data(), porterDuff);
- m_surface->SetDstBlendFunction(m_surface.data(), DSBF_INVSRCALPHA);
-
- const DFBRectangle sRect = { srcRect.x(), srcRect.y(), srcRect.width(), srcRect.height() };
-
- DFBResult result;
- if (rect.width() == srcRect.width() && rect.height() == srcRect.height())
- result = m_surface->Blit(m_surface.data(), s, &sRect, rect.x(), rect.y());
- else {
- const DFBRectangle dRect = { rect.x(), rect.y(), rect.width(), rect.height() };
- result = m_surface->StretchBlit(m_surface.data(), s, &sRect, &dRect);
- }
- if (result != DFB_OK)
- DirectFBError("QDirectFBBlitter::drawPixmap()", result);
+ drawPixmapOpacity(rect, pixmap, srcRect, QPainter::CompositionMode_SourceOver, 1.0);
}
void QDirectFbBlitter::alphaFillRect(const QRectF &rect, const QColor &color, QPainter::CompositionMode cmode)
@@ -194,6 +165,49 @@ void QDirectFbBlitter::alphaFillRect(const QRectF &rect, const QColor &color, QP
DirectFBError("QDirectFBBlitter::alphaFillRect()", result);
}
+void QDirectFbBlitter::drawPixmapOpacity(const QRectF &rect, const QPixmap &pixmap, const QRectF &subrect, QPainter::CompositionMode cmode, qreal opacity)
+{
+ QRect sQRect = subrect.toRect();
+ QRect dQRect = rect.toRect();
+ DFBRectangle sRect = { sQRect.x(), sQRect.y(), sQRect.width(), sQRect.height() };
+ DFBRectangle dRect = { dQRect.x(), dQRect.y(), dQRect.width(), dQRect.height() };
+ DFBResult result;
+
+ // skip if dst too small
+ if ((dRect.w <= 0) || (dRect.h <= 0)) return;
+
+ // correct roundings if needed
+ if (sRect.w <= 0) sRect.w = 1;
+ if (sRect.h <= 0) sRect.h = 1;
+
+ QBlittablePixmapData *blitPm = static_cast<QBlittablePixmapData*>(pixmap.pixmapData());
+ QDirectFbBlitter *dfbBlitter = static_cast<QDirectFbBlitter *>(blitPm->blittable());
+ dfbBlitter->unlock();
+
+ IDirectFBSurface *s = dfbBlitter->m_surface.data();
+
+ DFBSurfaceBlittingFlags blittingFlags = DFBSurfaceBlittingFlags(DSBLIT_BLEND_ALPHACHANNEL);
+ DFBSurfacePorterDuffRule porterDuff = (cmode == QPainter::CompositionMode_SourceOver) ? DSPD_SRC_OVER : DSPD_SRC;
+
+ if (opacity != 1.0)
+ {
+ blittingFlags = DFBSurfaceBlittingFlags(blittingFlags | DSBLIT_BLEND_COLORALPHA | (m_premult ? DSBLIT_SRC_PREMULTCOLOR : 0));
+ m_surface->SetColor(m_surface.data(), 0xff, 0xff, 0xff, (u8) (opacity * 255.0));
+ }
+
+ m_surface->SetBlittingFlags(m_surface.data(), DFBSurfaceBlittingFlags(blittingFlags));
+ m_surface->SetPorterDuff(m_surface.data(), porterDuff);
+ m_surface->SetDstBlendFunction(m_surface.data(), DSBF_INVSRCALPHA);
+
+ if ((sRect.w == dRect.w) && (sRect.h == dRect.h))
+ result = m_surface->Blit(m_surface.data(), s, &sRect, dRect.x, dRect.y);
+ else
+ result = m_surface->StretchBlit(m_surface.data(), s, &sRect, &dRect);
+
+ if (result != DFB_OK)
+ DirectFBError("QDirectFBBlitter::drawPixmapExtended()", result);
+}
+
QImage *QDirectFbBlitter::doLock()
{
Q_ASSERT(m_surface);
diff --git a/src/plugins/platforms/directfb/qdirectfbblitter.h b/src/plugins/platforms/directfb/qdirectfbblitter.h
index 77c23d5..70f67e0 100644
--- a/src/plugins/platforms/directfb/qdirectfbblitter.h
+++ b/src/plugins/platforms/directfb/qdirectfbblitter.h
@@ -60,6 +60,7 @@ public:
virtual void fillRect(const QRectF &rect, const QColor &color);
virtual void drawPixmap(const QRectF &rect, const QPixmap &pixmap, const QRectF &subrect);
void alphaFillRect(const QRectF &rect, const QColor &color, QPainter::CompositionMode cmode);
+ void drawPixmapOpacity(const QRectF &rect, const QPixmap &pixmap, const QRectF &subrect, QPainter::CompositionMode cmode, qreal opacity);
IDirectFBSurface *dfbSurface() const;