diff options
author | Paul Olav Tvete <paul.tvete@nokia.com> | 2010-06-18 11:10:26 (GMT) |
---|---|---|
committer | Paul Olav Tvete <paul.tvete@nokia.com> | 2010-06-18 11:10:26 (GMT) |
commit | a3fd00796dafe52d4ff138b271564daf70d1adee (patch) | |
tree | 77ca481c06c1b2c3c7822a4cd5864702e341b680 /src/gui/image | |
parent | 793d1ed8d3a03eefdd487facdacf66ba575e1a07 (diff) | |
parent | 6aa50af000f85cc4497749fcf0860c8ed244a60e (diff) | |
download | Qt-a3fd00796dafe52d4ff138b271564daf70d1adee.zip Qt-a3fd00796dafe52d4ff138b271564daf70d1adee.tar.gz Qt-a3fd00796dafe52d4ff138b271564daf70d1adee.tar.bz2 |
Merge remote branch 'qt/4.7' into lighthouse
Conflicts:
configure
mkspecs/common/qws.conf
src/corelib/io/qresource.cpp
src/gui/image/qpixmapdata_p.h
src/gui/kernel/qapplication.cpp
src/gui/kernel/qapplication_p.h
src/gui/painting/qpaintengine_raster.cpp
src/gui/text/qfontdatabase.cpp
src/opengl/qgl_p.h
src/plugins/mediaservices/gstreamer/gstreamer.pro
Diffstat (limited to 'src/gui/image')
-rw-r--r-- | src/gui/image/image.pri | 14 | ||||
-rw-r--r-- | src/gui/image/qbmphandler.cpp | 10 | ||||
-rw-r--r-- | src/gui/image/qicon.cpp | 26 | ||||
-rw-r--r-- | src/gui/image/qiconloader.cpp | 16 | ||||
-rw-r--r-- | src/gui/image/qimage.cpp | 19 | ||||
-rw-r--r-- | src/gui/image/qpixmap.cpp | 58 | ||||
-rw-r--r-- | src/gui/image/qpixmap.h | 2 | ||||
-rw-r--r-- | src/gui/image/qpixmap_x11.cpp | 6 | ||||
-rw-r--r-- | src/gui/image/qpixmapcache.cpp | 64 | ||||
-rw-r--r-- | src/gui/image/qpixmapcache.h | 10 | ||||
-rw-r--r-- | src/gui/image/qpixmapcache_p.h | 7 | ||||
-rw-r--r-- | src/gui/image/qpixmapdata_p.h | 6 | ||||
-rw-r--r-- | src/gui/image/qpnghandler.cpp | 10 | ||||
-rw-r--r-- | src/gui/image/qppmhandler.cpp | 10 | ||||
-rw-r--r-- | src/gui/image/qxbmhandler.cpp | 10 | ||||
-rw-r--r-- | src/gui/image/qxpmhandler.cpp | 8 |
16 files changed, 196 insertions, 80 deletions
diff --git a/src/gui/image/image.pri b/src/gui/image/image.pri index 1aee4f0..1df66a0 100644 --- a/src/gui/image/image.pri +++ b/src/gui/image/image.pri @@ -98,12 +98,12 @@ SOURCES += \ SOURCES += image/qpnghandler.cpp contains(QT_CONFIG, system-png) { - unix:LIBS_PRIVATE += -lpng - win32:LIBS += libpng.lib + unix|win32-g++*:LIBS_PRIVATE += -lpng + win32:!win32-g++*:LIBS += libpng.lib } else { DEFINES *= QT_USE_BUNDLED_LIBPNG !isEqual(QT_ARCH, i386):!isEqual(QT_ARCH, x86_64):DEFINES += PNG_NO_ASSEMBLER_CODE - INCLUDEPATH += ../3rdparty/libpng ../3rdparty/zlib + INCLUDEPATH += ../3rdparty/libpng SOURCES += ../3rdparty/libpng/png.c \ ../3rdparty/libpng/pngerror.c \ ../3rdparty/libpng/pngget.c \ @@ -119,6 +119,14 @@ SOURCES += \ ../3rdparty/libpng/pngwrite.c \ ../3rdparty/libpng/pngwtran.c \ ../3rdparty/libpng/pngwutil.c + + contains(QT_CONFIG, system-zlib) { + symbian:LIBS_PRIVATE += -llibz + else:if(unix|win32-g++*):LIBS_PRIVATE += -lz + else:LIBS += zdll.lib + } else { + INCLUDEPATH += ../3rdparty/zlib + } } } else { DEFINES *= QT_NO_IMAGEFORMAT_PNG diff --git a/src/gui/image/qbmphandler.cpp b/src/gui/image/qbmphandler.cpp index 42e19b8..074b8f0 100644 --- a/src/gui/image/qbmphandler.cpp +++ b/src/gui/image/qbmphandler.cpp @@ -674,13 +674,15 @@ bool QBmpHandler::readHeader() bool QBmpHandler::canRead() const { - if (state == Ready) { - if (!canRead(device())) - return false; + if (state == Ready && !canRead(device())) + return false; + + if (state != Error) { setFormat("bmp"); return true; } - return state != Error; + + return false; } bool QBmpHandler::canRead(QIODevice *device) diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 891b1db..a2f429a 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -66,6 +66,8 @@ #include "private/qkde_p.h" #endif +#include "private/qstylehelper_p.h" + #ifndef QT_NO_ICON QT_BEGIN_NAMESPACE @@ -261,21 +263,17 @@ QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::St if (!actualSize.isNull() && (actualSize.width() > size.width() || actualSize.height() > size.height())) actualSize.scale(size, Qt::KeepAspectRatio); - QString key = QLatin1String("$qt_icon_") - + QString::number(pm.cacheKey()) - + QString::number(pe->mode) - + QString::number(QApplication::palette().cacheKey()) - + QLatin1Char('_') - + QString::number(actualSize.width()) - + QLatin1Char('_') - + QString::number(actualSize.height()) - + QLatin1Char('_'); - + QString key = QLatin1Literal("qt_") + % HexString<quint64>(pm.cacheKey()) + % HexString<uint>(pe->mode) + % HexString<quint64>(QApplication::palette().cacheKey()) + % HexString<uint>(actualSize.width()) + % HexString<uint>(actualSize.height()); if (mode == QIcon::Active) { - if (QPixmapCache::find(key + QString::number(mode), pm)) + if (QPixmapCache::find(key % HexString<uint>(mode), pm)) return pm; // horray - if (QPixmapCache::find(key + QString::number(QIcon::Normal), pm)) { + if (QPixmapCache::find(key % HexString<uint>(QIcon::Normal), pm)) { QStyleOption opt(0); opt.palette = QApplication::palette(); QPixmap active = QApplication::style()->generatedIconPixmap(QIcon::Active, pm, &opt); @@ -284,7 +282,7 @@ QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::St } } - if (!QPixmapCache::find(key + QString::number(mode), pm)) { + if (!QPixmapCache::find(key % HexString<uint>(mode), pm)) { if (pm.size() != actualSize) pm = pm.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); if (pe->mode != mode && mode != QIcon::Normal) { @@ -294,7 +292,7 @@ QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::St if (!generated.isNull()) pm = generated; } - QPixmapCache::insert(key + QString::number(mode), pm); + QPixmapCache::insert(key % HexString<uint>(mode), pm); } return pm; } diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp index a515ef8..34f40a9 100644 --- a/src/gui/image/qiconloader.cpp +++ b/src/gui/image/qiconloader.cpp @@ -63,6 +63,8 @@ #include <private/qt_x11_p.h> #endif +#include <private/qstylehelper_p.h> + QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QIconLoader, iconLoaderInstance) @@ -488,14 +490,12 @@ QPixmap PixmapEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State st basePixmap.load(filename); int actualSize = qMin(size.width(), size.height()); - QString key = QLatin1String("$qt_theme_") - + QString::number(basePixmap.cacheKey(), 16) - + QLatin1Char('_') - + QString::number(mode) - + QLatin1Char('_') - + QString::number(qApp->palette().cacheKey(), 16) - + QLatin1Char('_') - + QString::number(actualSize); + + QString key = QLatin1Literal("$qt_theme_") + % HexString<qint64>(basePixmap.cacheKey()) + % HexString<int>(mode) + % HexString<qint64>(qApp->palette().cacheKey()) + % HexString<int>(actualSize); QPixmap cachedPixmap; if (QPixmapCache::find(key, &cachedPixmap)) { diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 85be5b1..adc2632 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -272,6 +272,8 @@ bool QImageData::checkForAlphaPixels() const switch (format) { + case QImage::Format_Mono: + case QImage::Format_MonoLSB: case QImage::Format_Indexed8: has_alpha_pixels = has_alpha_clut; break; @@ -4208,6 +4210,7 @@ QImage QImage::createHeuristicMask(bool clipTight) const int w = width(); int h = height(); QImage m(w, h, Format_MonoLSB); + QIMAGE_SANITYCHECK_MEMORY(m); m.setColorCount(2); m.setColor(0, QColor(Qt::color0).rgba()); m.setColor(1, QColor(Qt::color1).rgba()); @@ -4300,6 +4303,7 @@ QImage QImage::createMaskFromColor(QRgb color, Qt::MaskMode mode) const if (!d) return QImage(); QImage maskImage(size(), QImage::Format_MonoLSB); + QIMAGE_SANITYCHECK_MEMORY(maskImage); maskImage.fill(0); uchar *s = maskImage.bits(); @@ -4360,6 +4364,7 @@ QImage QImage::mirrored(bool horizontal, bool vertical) const int h = d->height; // Create result image, copy colormap QImage result(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(result); // check if we ran out of of memory.. if (!result.d) @@ -4497,6 +4502,7 @@ QImage QImage::rgbSwapped() const case Format_ARGB32: case Format_ARGB32_Premultiplied: res = QImage(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(res); for (int i = 0; i < d->height; i++) { uint *q = (uint*)res.scanLine(i); uint *p = (uint*)scanLine(i); @@ -4510,6 +4516,7 @@ QImage QImage::rgbSwapped() const break; case Format_RGB16: res = QImage(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(res); for (int i = 0; i < d->height; i++) { ushort *q = (ushort*)res.scanLine(i); const ushort *p = (const ushort*)scanLine(i); @@ -4523,6 +4530,7 @@ QImage QImage::rgbSwapped() const break; case Format_ARGB8565_Premultiplied: res = QImage(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(res); for (int i = 0; i < d->height; i++) { quint8 *p = (quint8*)scanLine(i); const quint8 *end = p + d->width * sizeof(qargb8565); @@ -4535,6 +4543,7 @@ QImage QImage::rgbSwapped() const break; case Format_RGB666: res = QImage(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(res); for (int i = 0; i < d->height; i++) { qrgb666 *q = reinterpret_cast<qrgb666*>(res.scanLine(i)); const qrgb666 *p = reinterpret_cast<const qrgb666*>(scanLine(i)); @@ -4547,6 +4556,7 @@ QImage QImage::rgbSwapped() const break; case Format_ARGB6666_Premultiplied: res = QImage(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(res); for (int i = 0; i < d->height; i++) { qargb6666 *q = reinterpret_cast<qargb6666*>(res.scanLine(i)); const qargb6666 *p = reinterpret_cast<const qargb6666*>(scanLine(i)); @@ -4559,6 +4569,7 @@ QImage QImage::rgbSwapped() const break; case Format_RGB555: res = QImage(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(res); for (int i = 0; i < d->height; i++) { ushort *q = (ushort*)res.scanLine(i); const ushort *p = (const ushort*)scanLine(i); @@ -4572,6 +4583,7 @@ QImage QImage::rgbSwapped() const break; case Format_ARGB8555_Premultiplied: res = QImage(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(res); for (int i = 0; i < d->height; i++) { quint8 *p = (quint8*)scanLine(i); const quint8 *end = p + d->width * sizeof(qargb8555); @@ -4584,6 +4596,7 @@ QImage QImage::rgbSwapped() const break; case Format_RGB888: res = QImage(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(res); for (int i = 0; i < d->height; i++) { quint8 *q = reinterpret_cast<quint8*>(res.scanLine(i)); const quint8 *p = reinterpret_cast<const quint8*>(scanLine(i)); @@ -4599,6 +4612,7 @@ QImage QImage::rgbSwapped() const break; case Format_RGB444: res = QImage(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(res); for (int i = 0; i < d->height; i++) { quint8 *q = reinterpret_cast<quint8*>(res.scanLine(i)); const quint8 *p = reinterpret_cast<const quint8*>(scanLine(i)); @@ -4613,6 +4627,7 @@ QImage QImage::rgbSwapped() const break; case Format_ARGB4444_Premultiplied: res = QImage(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(res); for (int i = 0; i < d->height; i++) { quint8 *q = reinterpret_cast<quint8*>(res.scanLine(i)); const quint8 *p = reinterpret_cast<const quint8*>(scanLine(i)); @@ -4812,7 +4827,7 @@ bool QImageData::doImageIO(const QImage *image, QImageWriter *writer, int qualit or as a BMP image if the stream's version is 1. Note that writing the stream to a file will not produce a valid image file. - \sa QImage::save(), {Format of the QDataStream Operators} + \sa QImage::save(), {Serializing Qt Data Types} */ QDataStream &operator<<(QDataStream &s, const QImage &image) @@ -4838,7 +4853,7 @@ QDataStream &operator<<(QDataStream &s, const QImage &image) Reads an image from the given \a stream and stores it in the given \a image. - \sa QImage::load(), {Format of the QDataStream Operators} + \sa QImage::load(), {Serializing Qt Data Types} */ QDataStream &operator>>(QDataStream &s, QImage &image) diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index 8be4bab..ec640fc 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -82,6 +82,7 @@ #endif #include "qpixmap_raster_p.h" +#include "private/qstylehelper_p.h" QT_BEGIN_NAMESPACE @@ -635,17 +636,21 @@ void QPixmap::resize_helper(const QSize &s) if (size() == s) return; + // QPixmap.data member may be QRuntimePixmapData so use pixmapData() function to get + // the actual underlaying runtime pixmap data. + QPixmapData *pd = pixmapData(); + // Create new pixmap - QPixmap pm(QSize(w, h), data ? data->type : QPixmapData::PixmapType); + QPixmap pm(QSize(w, h), pd ? pd->type : QPixmapData::PixmapType); bool uninit = false; #if defined(Q_WS_X11) - QX11PixmapData *x11Data = data && data->classId() == QPixmapData::X11Class ? static_cast<QX11PixmapData*>(data.data()) : 0; + QX11PixmapData *x11Data = pd && pd->classId() == QPixmapData::X11Class ? static_cast<QX11PixmapData*>(pd) : 0; if (x11Data) { pm.x11SetScreen(x11Data->xinfo.screen()); uninit = x11Data->flags & QX11PixmapData::Uninitialized; } #elif defined(Q_WS_MAC) - QMacPixmapData *macData = data && data->classId() == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data.data()) : 0; + QMacPixmapData *macData = pd && pd->classId() == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(pd) : 0; if (macData) uninit = macData->uninit; #endif @@ -659,7 +664,7 @@ void QPixmap::resize_helper(const QSize &s) #if defined(Q_WS_X11) if (x11Data && x11Data->x11_mask) { - QX11PixmapData *pmData = static_cast<QX11PixmapData*>(pm.data.data()); + QX11PixmapData *pmData = static_cast<QX11PixmapData*>(pd); pmData->x11_mask = (Qt::HANDLE)XCreatePixmap(X11->display, RootWindow(x11Data->xinfo.display(), x11Data->xinfo.screen()), @@ -825,8 +830,14 @@ bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConvers return false; QFileInfo info(fileName); - QString key = QLatin1String("qt_pixmap_") + info.absoluteFilePath() + QLatin1Char('_') + QString::number(info.lastModified().toTime_t()) + QLatin1Char('_') + - QString::number(info.size()) + QLatin1Char('_') + QString::number(data ? data->pixelType() : QPixmapData::PixmapType); + if (!info.exists()) + return false; + + QString key = QLatin1Literal("qt_pixmap") + % info.absoluteFilePath() + % HexString<uint>(info.lastModified().toTime_t()) + % HexString<quint64>(info.size()) + % HexString<uint>(data ? data->pixelType() : QPixmapData::PixmapType); if (QPixmapCache::find(key, *this)) return true; @@ -1163,8 +1174,9 @@ QPixmap QPixmap::grabWidget(QWidget * widget, const QRect &rect) Qt::HANDLE QPixmap::handle() const { #if defined(Q_WS_X11) - if (data && data->classId() == QPixmapData::X11Class) - return static_cast<const QX11PixmapData*>(data.constData())->handle(); + const QPixmapData *pd = pixmapData(); + if (pd && pd->classId() == QPixmapData::X11Class) + return static_cast<const QX11PixmapData*>(pd)->handle(); #endif return 0; } @@ -1281,7 +1293,7 @@ bool QPixmap::convertFromImage(const QImage &image, ColorMode mode) image. Note that writing the stream to a file will not produce a valid image file. - \sa QPixmap::save(), {Format of the QDataStream Operators} + \sa QPixmap::save(), {Serializing Qt Data Types} */ QDataStream &operator<<(QDataStream &stream, const QPixmap &pixmap) @@ -1294,7 +1306,7 @@ QDataStream &operator<<(QDataStream &stream, const QPixmap &pixmap) Reads an image from the given \a stream into the given \a pixmap. - \sa QPixmap::load(), {Format of the QDataStream Operators} + \sa QPixmap::load(), {Serializing Qt Data Types} */ QDataStream &operator>>(QDataStream &stream, QPixmap &pixmap) @@ -1754,6 +1766,9 @@ QPixmap QPixmap::transformed(const QMatrix &matrix, Qt::TransformationMode mode) function returns the actual matrix used for transforming the pixmap. + \note When using the native X11 graphics system, the pixmap + becomes invalid when the QApplication instance is destroyed. + \sa QBitmap, QImage, QImageReader, QImageWriter */ @@ -1946,17 +1961,20 @@ void QPixmap::detach() if (!data) return; - QPixmapData::ClassId id = data->classId(); + // QPixmap.data member may be QRuntimePixmapData so use pixmapData() function to get + // the actual underlaying runtime pixmap data. + QPixmapData *pd = pixmapData(); + QPixmapData::ClassId id = pd->classId(); if (id == QPixmapData::RasterClass) { - QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(data.data()); + QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(pd); rasterData->image.detach(); } if (data->is_cached && data->ref == 1) - QImagePixmapCleanupHooks::executePixmapDataModificationHooks(data.data()); + QImagePixmapCleanupHooks::executePixmapDataModificationHooks(pd); #if defined(Q_WS_MAC) - QMacPixmapData *macData = id == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data.data()) : 0; + QMacPixmapData *macData = id == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(pd) : 0; if (macData) { if (macData->cg_mask) { CGImageRelease(macData->cg_mask); @@ -1971,8 +1989,8 @@ void QPixmap::detach() ++data->detach_no; #if defined(Q_WS_X11) - if (data->classId() == QPixmapData::X11Class) { - QX11PixmapData *d = static_cast<QX11PixmapData*>(data.data()); + if (pd->classId() == QPixmapData::X11Class) { + QX11PixmapData *d = static_cast<QX11PixmapData*>(pd); d->flags &= ~QX11PixmapData::Uninitialized; // reset the cache data @@ -2062,9 +2080,15 @@ QPixmap QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags) */ QPixmapData* QPixmap::pixmapData() const { - return data.data(); + if (data) { + QPixmapData* pm = data.data(); + return pm->runtimeData() ? pm->runtimeData() : pm; + } + + return 0; } + /*! \enum QPixmap::HBitmapFormat diff --git a/src/gui/image/qpixmap.h b/src/gui/image/qpixmap.h index 180af3b..82546da 100644 --- a/src/gui/image/qpixmap.h +++ b/src/gui/image/qpixmap.h @@ -271,9 +271,7 @@ private: friend class QX11PaintEngine; friend class QCoreGraphicsPaintEngine; friend class QWidgetPrivate; - friend class QRasterPaintEngine; friend class QRasterBuffer; - friend class QPixmapCacheEntry; #if !defined(QT_NO_DATASTREAM) friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &); #endif diff --git a/src/gui/image/qpixmap_x11.cpp b/src/gui/image/qpixmap_x11.cpp index 6bebefc..e8dc5ae 100644 --- a/src/gui/image/qpixmap_x11.cpp +++ b/src/gui/image/qpixmap_x11.cpp @@ -1250,10 +1250,8 @@ void QX11PixmapData::release() pengine = 0; if (!X11) { -#ifndef QT_NO_DEBUG - qWarning("~QX11PixmapData(): QPixmap objects must be destroyed before the QApplication" - " object, otherwise the native pixmap object will be leaked."); -#endif + // At this point, the X server will already have freed our resources, + // so there is nothing to do. return; } diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp index 5fc605a..ca21a0c 100644 --- a/src/gui/image/qpixmapcache.cpp +++ b/src/gui/image/qpixmapcache.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ +#define Q_TEST_QPIXMAPCACHE #include "qpixmapcache.h" #include "qobject.h" #include "qdebug.h" @@ -194,7 +195,11 @@ public: static QPixmapCache::KeyData* getKeyData(QPixmapCache::Key *key); + QList< QPair<QString,QPixmap> > allPixmaps() const; + bool flushDetachedPixmaps(bool nt); + private: + enum { soon_time = 10000, flush_time = 30000 }; int *keyArray; int theid; int ps; @@ -232,37 +237,49 @@ QPMCache::~QPMCache() cleaning-up, and to not cut down the size of the cache while the cache is in active use. - When the last pixmap has been deleted from the cache, kill the - timer so Qt won't keep the CPU from going into sleep mode. + When the last detached pixmap has been deleted from the cache, kill the + timer so Qt won't keep the CPU from going into sleep mode. Currently + the timer is not restarted when the pixmap becomes unused, but it does + restart once something else is added (i.e. the cache space is actually needed). + + Returns true if any were removed. */ -void QPMCache::timerEvent(QTimerEvent *) +bool QPMCache::flushDetachedPixmaps(bool nt) { int mc = maxCost(); - bool nt = totalCost() == ps; setMaxCost(nt ? totalCost() * 3 / 4 : totalCost() -1); setMaxCost(mc); ps = totalCost(); + bool any = false; QHash<QString, QPixmapCache::Key>::iterator it = cacheKeys.begin(); while (it != cacheKeys.end()) { if (!contains(it.value())) { releaseKey(it.value()); it = cacheKeys.erase(it); + any = true; } else { ++it; } } - if (!size()) { + return any; +} + +void QPMCache::timerEvent(QTimerEvent *) +{ + bool nt = totalCost() == ps; + if (!flushDetachedPixmaps(nt)) { killTimer(theid); theid = 0; } else if (nt != t) { killTimer(theid); - theid = startTimer(nt ? 10000 : 30000); + theid = startTimer(nt ? soon_time : flush_time); t = nt; } } + QPixmap *QPMCache::object(const QString &key) const { QPixmapCache::Key cacheKey = cacheKeys.value(key); @@ -305,7 +322,7 @@ bool QPMCache::insert(const QString& key, const QPixmap &pixmap, int cost) if (success) { cacheKeys.insert(key, cacheKey); if (!theid) { - theid = startTimer(30000); + theid = startTimer(flush_time); t = false; } } else { @@ -321,7 +338,7 @@ QPixmapCache::Key QPMCache::insert(const QPixmap &pixmap, int cost) bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost); if (success) { if (!theid) { - theid = startTimer(30000); + theid = startTimer(flush_time); t = false; } } else { @@ -342,7 +359,7 @@ bool QPMCache::replace(const QPixmapCache::Key &key, const QPixmap &pixmap, int bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost); if (success) { if(!theid) { - theid = startTimer(30000); + theid = startTimer(flush_time); t = false; } const_cast<QPixmapCache::Key&>(key) = cacheKey; @@ -422,6 +439,20 @@ QPixmapCache::KeyData* QPMCache::getKeyData(QPixmapCache::Key *key) return key->d; } +QList< QPair<QString,QPixmap> > QPMCache::allPixmaps() const +{ + QList< QPair<QString,QPixmap> > r; + QHash<QString, QPixmapCache::Key>::const_iterator it = cacheKeys.begin(); + while (it != cacheKeys.end()) { + QPixmap *ptr = QCache<QPixmapCache::Key, QPixmapCacheEntry>::object(it.value()); + if (ptr) + r.append(QPair<QString,QPixmap>(it.key(),*ptr)); + ++it; + } + return r; +} + + Q_GLOBAL_STATIC(QPMCache, pm_cache) int Q_AUTOTEST_EXPORT q_QPixmapCache_keyHashSize() @@ -633,4 +664,19 @@ void QPixmapCache::clear() } } +void QPixmapCache::flushDetachedPixmaps() +{ + pm_cache()->flushDetachedPixmaps(true); +} + +int QPixmapCache::totalUsed() +{ + return (pm_cache()->totalCost()+1023) / 1024; +} + +QList< QPair<QString,QPixmap> > QPixmapCache::allPixmaps() +{ + return pm_cache()->allPixmaps(); +} + QT_END_NAMESPACE diff --git a/src/gui/image/qpixmapcache.h b/src/gui/image/qpixmapcache.h index 50a9369..e9c8c15 100644 --- a/src/gui/image/qpixmapcache.h +++ b/src/gui/image/qpixmapcache.h @@ -44,6 +44,10 @@ #include <QtGui/qpixmap.h> +#ifdef Q_TEST_QPIXMAPCACHE +#include <QtCore/qpair.h> +#endif + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -83,6 +87,12 @@ public: static void remove(const QString &key); static void remove(const Key &key); static void clear(); + +#ifdef Q_TEST_QPIXMAPCACHE + static void flushDetachedPixmaps(); + static int totalUsed(); + static QList< QPair<QString,QPixmap> > allPixmaps(); +#endif }; QT_END_NAMESPACE diff --git a/src/gui/image/qpixmapcache_p.h b/src/gui/image/qpixmapcache_p.h index 86a1b78..6db3b20 100644 --- a/src/gui/image/qpixmapcache_p.h +++ b/src/gui/image/qpixmapcache_p.h @@ -81,8 +81,9 @@ class QPixmapCacheEntry : public QPixmap public: QPixmapCacheEntry(const QPixmapCache::Key &key, const QPixmap &pix) : QPixmap(pix), key(key) { - if (data && data->classId() == QPixmapData::RasterClass) { - QRasterPixmapData *d = static_cast<QRasterPixmapData*>(data.data()); + QPixmapData *pd = pixmapData(); + if (pd && pd->classId() == QPixmapData::RasterClass) { + QRasterPixmapData *d = static_cast<QRasterPixmapData*>(pd); if (!d->image.isNull() && d->image.d->paintEngine && !d->image.d->paintEngine->isActive()) { @@ -95,6 +96,8 @@ public: QPixmapCache::Key key; }; +inline bool qIsDetached(QPixmapCacheEntry &t) { return t.isDetached(); } + QT_END_NAMESPACE #endif // QPIXMAPCACHE_P_H diff --git a/src/gui/image/qpixmapdata_p.h b/src/gui/image/qpixmapdata_p.h index 8323b61..6d2a827 100644 --- a/src/gui/image/qpixmapdata_p.h +++ b/src/gui/image/qpixmapdata_p.h @@ -73,7 +73,8 @@ public: }; #endif enum ClassId { RasterClass, X11Class, MacClass, DirectFBClass, - OpenGLClass, OpenVGClass, BlitterClass, CustomClass = 1024 }; + OpenGLClass, OpenVGClass, RuntimeClass, BlitterClass, + CustomClass = 1024 }; QPixmapData(PixelType pixelType, int classId); virtual ~QPixmapData(); @@ -133,7 +134,10 @@ public: static QPixmapData *create(int w, int h, PixelType type); + virtual QPixmapData *runtimeData() const { return 0; } + protected: + void setSerialNumber(int serNo); int w; int h; diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp index dd31834..2cf8222 100644 --- a/src/gui/image/qpnghandler.cpp +++ b/src/gui/image/qpnghandler.cpp @@ -892,13 +892,15 @@ QPngHandler::~QPngHandler() bool QPngHandler::canRead() const { - if (d->state == QPngHandlerPrivate::Ready) { - if (!canRead(device())) - return false; + if (d->state == QPngHandlerPrivate::Ready && !canRead(device())) + return false; + + if (d->state != QPngHandlerPrivate::Error) { setFormat("png"); return true; } - return d->state != QPngHandlerPrivate::Error; + + return false; } bool QPngHandler::canRead(QIODevice *device) diff --git a/src/gui/image/qppmhandler.cpp b/src/gui/image/qppmhandler.cpp index cbbbef4..a9e796c 100644 --- a/src/gui/image/qppmhandler.cpp +++ b/src/gui/image/qppmhandler.cpp @@ -409,13 +409,15 @@ bool QPpmHandler::readHeader() bool QPpmHandler::canRead() const { - if (state == Ready) { - if (!canRead(device(), &subType)) - return false; + if (state == Ready && !canRead(device(), &subType)) + return false; + + if (state != Error) { setFormat(subType); return true; } - return state != Error; + + return false; } bool QPpmHandler::canRead(QIODevice *device, QByteArray *subType) diff --git a/src/gui/image/qxbmhandler.cpp b/src/gui/image/qxbmhandler.cpp index 385340a..0dd4e99 100644 --- a/src/gui/image/qxbmhandler.cpp +++ b/src/gui/image/qxbmhandler.cpp @@ -261,13 +261,15 @@ bool QXbmHandler::readHeader() bool QXbmHandler::canRead() const { - if (state == Ready) { - if (!canRead(device())) - return false; + if (state == Ready && !canRead(device())) + return false; + + if (state != Error) { setFormat("xbm"); return true; } - return state != Error; + + return false; } bool QXbmHandler::canRead(QIODevice *device) diff --git a/src/gui/image/qxpmhandler.cpp b/src/gui/image/qxpmhandler.cpp index a475cd0..b97afd3 100644 --- a/src/gui/image/qxpmhandler.cpp +++ b/src/gui/image/qxpmhandler.cpp @@ -1225,11 +1225,15 @@ bool QXpmHandler::readImage(QImage *image) bool QXpmHandler::canRead() const { - if (state == Ready && canRead(device())) { + if (state == Ready && !canRead(device())) + return false; + + if (state != Error) { setFormat("xpm"); return true; } - return state != Error; + + return false; } bool QXpmHandler::canRead(QIODevice *device) |