From ee387dcb715ebc21f63b524bb87a8ffaf198f8aa Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 13 Dec 2011 12:02:32 +0100 Subject: [blitter] Work on tst_QPixmap::clear() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default QPixmap may not hasAlphaChannel(), only if setMask() or fill() with a transparent color is called a QPixmap will hasAlphaChannel(). Make the QBlittablePlatformPixmap remember if there is an alpha channel, pass this as parameter in createBlittable to make it clear that this is required and not optional. Update the DirectFB plugin to handle this parameter to create a RGB32 or ARGB Surface depending on the alpha value, also only use PreMultiplied alpha when using ARGB. Separate the two constructors for the QDirectFbBlitter to either adopt a DirectFB Surface or to create one. Cherry-picked-from: qtbase:ab50b60f5cc237d5620f3ff3b2eb44c857f8f60b Change-Id: I8abf82408ecd2d075fc6f241ace8be2a34ac56e7 Reviewed-by: Jørgen Lind Merge-request: 1492 Reviewed-by: Jørgen Lind --- src/gui/image/qpixmap_blitter.cpp | 15 ++++++++-- src/gui/image/qpixmap_blitter_p.h | 3 +- .../platforms/directfb/qdirectfbblitter.cpp | 33 ++++++++++++++-------- src/plugins/platforms/directfb/qdirectfbblitter.h | 10 +++++-- 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/src/gui/image/qpixmap_blitter.cpp b/src/gui/image/qpixmap_blitter.cpp index f8fb538..c73e6a9 100644 --- a/src/gui/image/qpixmap_blitter.cpp +++ b/src/gui/image/qpixmap_blitter.cpp @@ -58,6 +58,7 @@ static int global_ser_no = 0; QBlittablePixmapData::QBlittablePixmapData() : QPixmapData(QPixmapData::PixmapType,BlitterClass) + , m_alpha(false) #ifdef QT_BLITTER_RASTEROVERLAY ,m_rasterOverlay(0), m_unmergedCopy(0) #endif //QT_BLITTER_RASTEROVERLAY @@ -77,7 +78,7 @@ QBlittable *QBlittablePixmapData::blittable() const { if (!m_blittable) { QBlittablePixmapData *that = const_cast(this); - that->m_blittable.reset(this->createBlittable(QSize(w,h))); + that->m_blittable.reset(this->createBlittable(QSize(w,h), m_alpha)); } return m_blittable.data(); @@ -136,7 +137,16 @@ void QBlittablePixmapData::fill(const QColor &color) if (color.alpha() == 255 && blittable()->capabilities() & QBlittable::SolidRectCapability) { blittable()->unlock(); blittable()->fillRect(QRectF(0,0,w,h),color); - }else { + } else { + // Need to be backed with an alpha channel now. It would be nice + // if we could just change the format, e.g. when going from + // RGB32 -> ARGB8888. + if (color.alpha() != 255 && !hasAlphaChannel()) { + m_blittable.reset(0); + m_engine.reset(0); + m_alpha = true; + } + uint pixel; switch (blittable()->lock()->format()) { case QImage::Format_ARGB32_Premultiplied: @@ -182,6 +192,7 @@ bool QBlittablePixmapData::hasAlphaChannel() const void QBlittablePixmapData::fromImage(const QImage &image, Qt::ImageConversionFlags flags) { + m_alpha = image.hasAlphaChannel(); resize(image.width(),image.height()); markRasterOverlay(QRect(0,0,w,h)); QImage *thisImg = buffer(); diff --git a/src/gui/image/qpixmap_blitter_p.h b/src/gui/image/qpixmap_blitter_p.h index 9b809ca..4742a83 100644 --- a/src/gui/image/qpixmap_blitter_p.h +++ b/src/gui/image/qpixmap_blitter_p.h @@ -55,7 +55,7 @@ public: QBlittablePixmapData(); ~QBlittablePixmapData(); - virtual QBlittable *createBlittable(const QSize &size) const = 0; + virtual QBlittable *createBlittable(const QSize &size, bool alpha) const = 0; QBlittable *blittable() const; void setBlittable(QBlittable *blittable); @@ -85,6 +85,7 @@ public: protected: QScopedPointer m_engine; QScopedPointer m_blittable; + bool m_alpha; #ifdef QT_BLITTER_RASTEROVERLAY QImage *m_rasterOverlay; diff --git a/src/plugins/platforms/directfb/qdirectfbblitter.cpp b/src/plugins/platforms/directfb/qdirectfbblitter.cpp index 86a8bf7..83c27d1 100644 --- a/src/plugins/platforms/directfb/qdirectfbblitter.cpp +++ b/src/plugins/platforms/directfb/qdirectfbblitter.cpp @@ -54,22 +54,33 @@ QDirectFbBlitter::QDirectFbBlitter(const QSize &rect, IDirectFBSurface *surface) |QBlittable::SourceOverPixmapCapability |QBlittable::SourceOverScaledPixmapCapability)) { - if (surface) { - m_surface = surface; - } else { - DFBSurfaceDescription surfaceDesc; - memset(&surfaceDesc,0,sizeof(DFBSurfaceDescription)); - surfaceDesc.width = rect.width(); - surfaceDesc.height = rect.height(); + m_surface = surface; +} + +QDirectFbBlitter::QDirectFbBlitter(const QSize &rect, bool alpha) + : QBlittable(rect, QBlittable::Capabilities(QBlittable::SolidRectCapability + |QBlittable::SourcePixmapCapability + |QBlittable::SourceOverPixmapCapability + |QBlittable::SourceOverScaledPixmapCapability)) +{ + DFBSurfaceDescription surfaceDesc; + memset(&surfaceDesc,0,sizeof(DFBSurfaceDescription)); + surfaceDesc.width = rect.width(); + surfaceDesc.height = rect.height(); + + if (alpha) { surfaceDesc.caps = DSCAPS_PREMULTIPLIED; surfaceDesc.pixelformat = DSPF_ARGB; surfaceDesc.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_CAPS | DSDESC_PIXELFORMAT); - - IDirectFB *dfb = QDirectFbConvenience::dfbInterface(); - dfb->CreateSurface(dfb,&surfaceDesc, &m_surface); - m_surface->Clear(m_surface,0,0,0,0); + } else { + surfaceDesc.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT); + surfaceDesc.pixelformat = DSPF_RGB32; } + + IDirectFB *dfb = QDirectFbConvenience::dfbInterface(); + dfb->CreateSurface(dfb , &surfaceDesc, &m_surface); + m_surface->Clear(m_surface, 0, 0, 0, 0); } QDirectFbBlitter::~QDirectFbBlitter() diff --git a/src/plugins/platforms/directfb/qdirectfbblitter.h b/src/plugins/platforms/directfb/qdirectfbblitter.h index 16d7599..5a2b77f 100644 --- a/src/plugins/platforms/directfb/qdirectfbblitter.h +++ b/src/plugins/platforms/directfb/qdirectfbblitter.h @@ -51,7 +51,8 @@ class QDirectFbBlitter : public QBlittable { public: - QDirectFbBlitter(const QSize &size, IDirectFBSurface *surface = 0); + QDirectFbBlitter(const QSize &size, IDirectFBSurface *surface); + QDirectFbBlitter(const QSize &size, bool alpha); virtual ~QDirectFbBlitter(); virtual void fillRect(const QRectF &rect, const QColor &color); @@ -70,7 +71,12 @@ protected: class QDirectFbBlitterPixmapData : public QBlittablePixmapData { public: - QBlittable *createBlittable(const QSize &size) const { return new QDirectFbBlitter(size); } + QBlittable *createBlittable(const QSize &size, bool alpha) const; }; +inline QBlittable *QDirectFbBlitterPixmapData::createBlittable(const QSize& size, bool alpha) const +{ + return new QDirectFbBlitter(size, alpha); +} + #endif // QDIRECTFBBLITTER_H -- cgit v0.12