summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSamuel Rødal <sroedal@trolltech.com>2009-09-04 11:20:04 (GMT)
committerSamuel Rødal <sroedal@trolltech.com>2009-09-04 14:29:01 (GMT)
commit57447242994a16e30d3cb199eefaf625f0088f9f (patch)
tree7d18fcd98aecc491b708788ca617681f70411b33 /src
parent5323b15f50df99722d304c04d1758bb9410ef041 (diff)
downloadQt-57447242994a16e30d3cb199eefaf625f0088f9f.zip
Qt-57447242994a16e30d3cb199eefaf625f0088f9f.tar.gz
Qt-57447242994a16e30d3cb199eefaf625f0088f9f.tar.bz2
Avoided streaming multiple copies of images/pixmaps in QPaintBuffer.
This reduces the size of the trace files significantly in certain cases. Reviewed-by: Trond
Diffstat (limited to 'src')
-rw-r--r--src/gui/painting/qpaintbuffer.cpp75
1 files changed, 74 insertions, 1 deletions
diff --git a/src/gui/painting/qpaintbuffer.cpp b/src/gui/painting/qpaintbuffer.cpp
index 04ddd7d..7de9063 100644
--- a/src/gui/painting/qpaintbuffer.cpp
+++ b/src/gui/painting/qpaintbuffer.cpp
@@ -1721,11 +1721,66 @@ QDataStream &operator>>(QDataStream &stream, QPaintBufferCommand &command)
return stream;
}
+struct QPaintBufferCacheEntry
+{
+ QVariant::Type type;
+ quint64 cacheKey;
+};
+
+QDataStream &operator<<(QDataStream &stream, const QPaintBufferCacheEntry &entry)
+{
+ return stream << entry.type << entry.cacheKey;
+}
+
+QDataStream &operator>>(QDataStream &stream, QPaintBufferCacheEntry &entry)
+{
+ return stream >> entry.type >> entry.cacheKey;
+}
+
+static int qRegisterPaintBufferMetaTypes()
+{
+ qRegisterMetaType<QPaintBufferCacheEntry>();
+ qRegisterMetaTypeStreamOperators<QPaintBufferCacheEntry>("QPaintBufferCacheEntry");
+
+ return 0; // something
+}
+
+Q_DECLARE_METATYPE(QPaintBufferCacheEntry);
+Q_CONSTRUCTOR_FUNCTION(qRegisterPaintBufferMetaTypes)
+
QDataStream &operator<<(QDataStream &stream, const QPaintBuffer &buffer)
{
+ QHash<qint64, QPixmap> pixmaps;
+ QHash<qint64, QImage> images;
+
+ QVector<QVariant> variants = buffer.d_ptr->variants;
+ for (int i = 0; i < variants.size(); ++i) {
+ const QVariant &v = variants.at(i);
+ if (v.type() == QVariant::Image) {
+ const QImage image(v.value<QImage>());
+ images[image.cacheKey()] = image;
+
+ QPaintBufferCacheEntry entry;
+ entry.type = QVariant::Image;
+ entry.cacheKey = image.cacheKey();
+ variants[i] = QVariant::fromValue(entry);
+ } else if (v.type() == QVariant::Pixmap) {
+ const QPixmap pixmap(v.value<QPixmap>());
+ pixmaps[pixmap.cacheKey()] = pixmap;
+
+ QPaintBufferCacheEntry entry;
+ entry.type = QVariant::Pixmap;
+ entry.cacheKey = pixmap.cacheKey();
+ variants[i] = QVariant::fromValue(entry);
+ }
+ }
+
+ stream << pixmaps;
+ stream << images;
+
stream << buffer.d_ptr->ints;
stream << buffer.d_ptr->floats;
- stream << buffer.d_ptr->variants;
+ stream << variants;
stream << buffer.d_ptr->commands;
stream << buffer.d_ptr->boundingRect;
@@ -1734,12 +1789,30 @@ QDataStream &operator<<(QDataStream &stream, const QPaintBuffer &buffer)
QDataStream &operator>>(QDataStream &stream, QPaintBuffer &buffer)
{
+ QHash<qint64, QPixmap> pixmaps;
+ QHash<qint64, QImage> images;
+
+ stream >> pixmaps;
+ stream >> images;
+
stream >> buffer.d_ptr->ints;
stream >> buffer.d_ptr->floats;
stream >> buffer.d_ptr->variants;
stream >> buffer.d_ptr->commands;
stream >> buffer.d_ptr->boundingRect;
+ QVector<QVariant> &variants = buffer.d_ptr->variants;
+ for (int i = 0; i < variants.size(); ++i) {
+ const QVariant &v = variants.at(i);
+ if (v.canConvert<QPaintBufferCacheEntry>()) {
+ QPaintBufferCacheEntry entry = v.value<QPaintBufferCacheEntry>();
+ if (entry.type == QVariant::Image)
+ variants[i] = QVariant(images.value(entry.cacheKey));
+ else
+ variants[i] = QVariant(pixmaps.value(entry.cacheKey));
+ }
+ }
+
return stream;
}