diff options
author | Anders Bakken <anders.bakken@nokia.com> | 2009-08-25 18:18:31 (GMT) |
---|---|---|
committer | Anders Bakken <anders.bakken@nokia.com> | 2009-08-25 18:23:35 (GMT) |
commit | 3d885b2c75d4854266e6552d2659505f132acd00 (patch) | |
tree | a70eaeff24a56506a725c742661b90848837d20f | |
parent | 7aefaa2d4c4f192e033ec3323e2e2368af833248 (diff) | |
download | Qt-3d885b2c75d4854266e6552d2659505f132acd00.zip Qt-3d885b2c75d4854266e6552d2659505f132acd00.tar.gz Qt-3d885b2c75d4854266e6552d2659505f132acd00.tar.bz2 |
Refactor QDirectFBPaintDevice/QDirectFBPixmapData
Move format into QDirectFBPaintDevice.
Reviewed-by: Donald Carr <donald.carr@nokia.com>
8 files changed, 70 insertions, 31 deletions
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.cpp index 3979a8c..f45f256 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.cpp @@ -47,7 +47,8 @@ QDirectFBPaintDevice::QDirectFBPaintDevice(QDirectFBScreen *scr) : QCustomRasterPaintDevice(0), dfbSurface(0), lockedImage(0), screen(scr), - bpl(-1), lockFlgs(DFBSurfaceLockFlags(0)), mem(0), engine(0) + bpl(-1), lockFlgs(DFBSurfaceLockFlags(0)), mem(0), engine(0), + imageFormat(QImage::Format_Invalid) {} QDirectFBPaintDevice::~QDirectFBPaintDevice() @@ -56,13 +57,11 @@ QDirectFBPaintDevice::~QDirectFBPaintDevice() delete engine; } - IDirectFBSurface *QDirectFBPaintDevice::directFBSurface() const { return dfbSurface; } - void QDirectFBPaintDevice::lockDirectFB(DFBSurfaceLockFlags flags) { if (!(lockFlgs & flags)) { @@ -77,7 +76,6 @@ void QDirectFBPaintDevice::lockDirectFB(DFBSurfaceLockFlags flags) } } - void QDirectFBPaintDevice::unlockDirectFB() { if (!lockedImage || !QDirectFBScreen::instance()) @@ -90,19 +88,16 @@ void QDirectFBPaintDevice::unlockDirectFB() lockFlgs = DFBSurfaceLockFlags(0); } - void *QDirectFBPaintDevice::memory() const { return mem; } - QImage::Format QDirectFBPaintDevice::format() const { - return QDirectFBScreen::getImageFormat(dfbSurface); + return imageFormat; } - int QDirectFBPaintDevice::bytesPerLine() const { if (bpl == -1) { @@ -143,11 +138,9 @@ int QDirectFBPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const case QPaintDevice::PdmDpiY: return (dotsPerMeterY() * 254) / 10000; // 0.0254 meters-per-inch case QPaintDevice::PdmDepth: - DFBSurfacePixelFormat format; - dfbSurface->GetPixelFormat(dfbSurface, &format); - return QDirectFBScreen::depth(format); + return QDirectFBScreen::depth(imageFormat); case QPaintDevice::PdmNumColors: { - if (lockedImage) + if (lockedImage) return lockedImage->numColors(); DFBResult result; diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.h b/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.h index 688fd7b..48761b2 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.h +++ b/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.h @@ -89,6 +89,7 @@ protected: DFBSurfaceLockFlags lockFlgs; uchar *mem; QDirectFBPaintEngine *engine; + QImage::Format imageFormat; private: Q_DISABLE_COPY(QDirectFBPaintDevice); }; diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp index 7cacdd9..7231dd5 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp @@ -51,7 +51,7 @@ static int global_ser_no = 0; QDirectFBPixmapData::QDirectFBPixmapData(QDirectFBScreen *screen, PixelType pixelType) : QPixmapData(pixelType, DirectFBClass), QDirectFBPaintDevice(screen), - format(QImage::Format_Invalid), alpha(false) + alpha(false) { setSerialNumber(0); } @@ -70,11 +70,11 @@ void QDirectFBPixmapData::resize(int width, int height) return; } - format = screen->pixelFormat(); + imageFormat = screen->pixelFormat(); dfbSurface = screen->createDFBSurface(QSize(width, height), - format, + imageFormat, QDirectFBScreen::TrackSurface); - d = screen->depth(); + d = QDirectFBScreen::depth(imageFormat); alpha = false; if (!dfbSurface) { invalidate(); @@ -85,7 +85,6 @@ void QDirectFBPixmapData::resize(int width, int height) w = width; h = height; is_null = (w <= 0 || h <= 0); - d = metric(QPaintDevice::PdmDepth); setSerialNumber(++global_ser_no); } @@ -183,13 +182,13 @@ void QDirectFBPixmapData::fromImage(const QImage &image, #endif ) { alpha = true; - format = screen->alphaPixmapFormat(); + imageFormat = screen->alphaPixmapFormat(); } else { alpha = false; - format = screen->pixelFormat(); + imageFormat = screen->pixelFormat(); } - dfbSurface = screen->createDFBSurface(image, format, QDirectFBScreen::TrackSurface|QDirectFBScreen::NoPreallocated); + dfbSurface = screen->createDFBSurface(image, imageFormat, QDirectFBScreen::TrackSurface|QDirectFBScreen::NoPreallocated); if (!dfbSurface) { qWarning("QDirectFBPixmapData::fromImage()"); invalidate(); @@ -198,7 +197,7 @@ void QDirectFBPixmapData::fromImage(const QImage &image, w = image.width(); h = image.height(); is_null = (w <= 0 || h <= 0); - d = metric(QPaintDevice::PdmDepth); + d = QDirectFBScreen::depth(imageFormat); setSerialNumber(++global_ser_no); #ifdef QT_NO_DIRECTFB_OPAQUE_DETECTION Q_UNUSED(flags); @@ -216,12 +215,12 @@ void QDirectFBPixmapData::copy(const QPixmapData *data, const QRect &rect) const QDirectFBPixmapData *otherData = static_cast<const QDirectFBPixmapData*>(data); IDirectFBSurface *src = otherData->directFBSurface(); alpha = data->hasAlphaChannel(); - format = (alpha - ? QDirectFBScreen::instance()->alphaPixmapFormat() - : QDirectFBScreen::instance()->pixelFormat()); + imageFormat = (alpha + ? QDirectFBScreen::instance()->alphaPixmapFormat() + : QDirectFBScreen::instance()->pixelFormat()); - dfbSurface = screen->createDFBSurface(rect.size(), format, + dfbSurface = screen->createDFBSurface(rect.size(), imageFormat, QDirectFBScreen::TrackSurface); if (!dfbSurface) { qWarning("QDirectFBPixmapData::copy()"); @@ -279,11 +278,12 @@ void QDirectFBPixmapData::fill(const QColor &color) alpha = (color.alpha() < 255); - if (alpha && ::isOpaqueFormat(format)) { + if (alpha && ::isOpaqueFormat(imageFormat)) { QSize size; dfbSurface->GetSize(dfbSurface, &size.rwidth(), &size.rheight()); screen->releaseDFBSurface(dfbSurface); - format = screen->alphaPixmapFormat(); + imageFormat = screen->alphaPixmapFormat(); + d = QDirectFBScreen::depth(imageFormat); dfbSurface = screen->createDFBSurface(size, screen->alphaPixmapFormat(), QDirectFBScreen::TrackSurface); setSerialNumber(++global_ser_no); if (!dfbSurface) { @@ -324,7 +324,7 @@ QPixmap QDirectFBPixmapData::transformed(const QTransform &transform, flags = DSBLIT_BLEND_ALPHACHANNEL; } data->dfbSurface = screen->createDFBSurface(size, - format, + imageFormat, QDirectFBScreen::TrackSurface); if (flags & DSBLIT_BLEND_ALPHACHANNEL) { data->dfbSurface->Clear(data->dfbSurface, 0, 0, 0, 0); @@ -411,6 +411,6 @@ void QDirectFBPixmapData::invalidate() alpha = false; d = w = h = 0; is_null = true; - format = QImage::Format_Invalid; + imageFormat = QImage::Format_Invalid; } diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.h b/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.h index 2300174..c8dda0c 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.h +++ b/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.h @@ -74,12 +74,11 @@ public: QImage *buffer(DFBSurfaceLockFlags lockFlags); // Pure virtual in QPixmapData, so re-implement here and delegate to QDirectFBPaintDevice - inline QImage::Format pixelFormat() const { return format; } + inline QImage::Format pixelFormat() const { return imageFormat; } static bool hasAlphaChannel(const QImage &img); inline bool hasAlphaChannel() const { return alpha; } private: void invalidate(); - QImage::Format format; bool alpha; }; diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp index bb614a2..ecd4aba 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp @@ -658,6 +658,42 @@ int QDirectFBScreen::depth(DFBSurfacePixelFormat format) return 0; } +int QDirectFBScreen::depth(QImage::Format format) +{ + int depth = 0; + switch(format) { + case QImage::Format_Invalid: + case QImage::NImageFormats: + Q_ASSERT(false); + case QImage::Format_Mono: + case QImage::Format_MonoLSB: + depth = 1; + break; + case QImage::Format_Indexed8: + depth = 8; + break; + case QImage::Format_RGB32: + case QImage::Format_ARGB32: + case QImage::Format_ARGB32_Premultiplied: + depth = 32; + break; + case QImage::Format_RGB555: + case QImage::Format_RGB16: + case QImage::Format_RGB444: + case QImage::Format_ARGB4444_Premultiplied: + depth = 16; + break; + case QImage::Format_RGB666: + case QImage::Format_ARGB6666_Premultiplied: + case QImage::Format_ARGB8565_Premultiplied: + case QImage::Format_ARGB8555_Premultiplied: + case QImage::Format_RGB888: + depth = 24; + break; + } + return depth; +} + void QDirectFBScreenPrivate::setFlipFlags(const QStringList &args) { QRegExp flipRegexp(QLatin1String("^flip=([\\w,]*)$")); diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h index 4cae076..e8da283 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h @@ -169,6 +169,7 @@ public: using QScreen::depth; static int depth(DFBSurfacePixelFormat format); + static int depth(QImage::Format format); static DFBSurfacePixelFormat getSurfacePixelFormat(QImage::Format format); static DFBSurfaceDescription getSurfaceDescription(const uint *buffer, diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.cpp index 7569a18..83affa7 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.cpp @@ -144,6 +144,7 @@ void QDirectFBWindowSurface::createWindow() dfbSurface->Release(dfbSurface); dfbWindow->GetSurface(dfbWindow, &dfbSurface); + updateFormat(); } #endif // QT_NO_DIRECTFB_WM @@ -179,6 +180,7 @@ static DFBResult setGeometry(IDirectFBWindow *dfbWindow, const QRect &old, const void QDirectFBWindowSurface::setGeometry(const QRect &rect) { + IDirectFBSurface *oldSurface = dfbSurface; #ifdef QT_NO_DIRECTFB_WM IDirectFBSurface *primarySurface = screen->primarySurface(); Q_ASSERT(primarySurface); @@ -236,6 +238,8 @@ void QDirectFBWindowSurface::setGeometry(const QRect &rect) if (result != DFB_OK) DirectFBErrorFatal("QDirectFBWindowSurface::setGeometry()", result); } + if (oldSurface != dfbSurface) + updateFormat(); QWSWindowSurface::setGeometry(rect); } @@ -462,3 +466,7 @@ QImage *QDirectFBWindowSurface::buffer(const QWidget *widget) return img; } +void QDirectFBWindowSurface::updateFormat() +{ + imageFormat = dfbSurface ? QDirectFBScreen::getImageFormat(dfbSurface) : QImage::Format_Invalid; +} diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.h b/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.h index 2c4bcdf..0da3a98 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.h +++ b/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.h @@ -90,6 +90,7 @@ public: QImage *buffer(const QWidget *widget); private: + void updateFormat(); #ifdef QT_DIRECTFB_WM void createWindow(); IDirectFBWindow *dfbWindow; |