Commit 6491058e authored by Ulf Hermann's avatar Ulf Hermann

QmlProfiler: Clean up pixmap cache model

Change-Id: I28b32318fe66644b3fe16825efcf86a6d3f9c68a
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@theqtcompany.com>
parent c4079d6a
...@@ -90,19 +90,18 @@ QVariantList PixmapCacheModel::labels() const ...@@ -90,19 +90,18 @@ QVariantList PixmapCacheModel::labels() const
// Cache Size // Cache Size
QVariantMap element; QVariantMap element;
element.insert(QLatin1String("description"), QVariant(QLatin1String("Cache Size"))); element.insert(QLatin1String("description"), tr("Cache Size"));
element.insert(QLatin1String("id"), QVariant(0)); element.insert(QLatin1String("id"), 0);
result << element; result << element;
for (int i=0; i < m_pixmaps.count(); i++) { for (int i = 0; i < m_pixmaps.count(); ++i) {
// Loading // Loading
QVariantMap element; QVariantMap element;
element.insert(QLatin1String("displayName"), m_pixmaps[i].url); element.insert(QLatin1String("displayName"), m_pixmaps[i].url);
element.insert(QLatin1String("description"), element.insert(QLatin1String("description"), getFilenameOnly(m_pixmaps[i].url));
QVariant(getFilenameOnly(m_pixmaps[i].url)));
element.insert(QLatin1String("id"), QVariant(i+1)); element.insert(QLatin1String("id"), QVariant(i + 1));
result << element; result << element;
} }
...@@ -117,11 +116,9 @@ QVariantMap PixmapCacheModel::details(int index) const ...@@ -117,11 +116,9 @@ QVariantMap PixmapCacheModel::details(int index) const
if (ev->pixmapEventType == PixmapCacheCountChanged) { if (ev->pixmapEventType == PixmapCacheCountChanged) {
result.insert(QLatin1String("displayName"), tr("Image Cached")); result.insert(QLatin1String("displayName"), tr("Image Cached"));
} else { } else {
if (ev->pixmapEventType == PixmapLoadingStarted) { result.insert(QLatin1String("displayName"), tr("Image Loaded"));
result.insert(QLatin1String("displayName"), tr("Image Loaded")); if (m_pixmaps[ev->urlIndex].sizes[ev->sizeIndex].loadState != Finished)
if (m_pixmaps[ev->urlIndex].sizes[ev->sizeIndex].loadState != Finished) result.insert(tr("Result"), tr("Load Error"));
result.insert(tr("Result"), tr("Load Error"));
}
result.insert(tr("Duration"), QmlProfilerDataModel::formatTime(duration(index))); result.insert(tr("Duration"), QmlProfilerDataModel::formatTime(duration(index)));
} }
...@@ -170,9 +167,9 @@ void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type ...@@ -170,9 +167,9 @@ void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type
qint64 pixmapStartTime = event.timestamp(); qint64 pixmapStartTime = event.timestamp();
newEvent.urlIndex = -1; newEvent.urlIndex = -1;
for (QVector<Pixmap>::const_iterator it(m_pixmaps.cend()); it != m_pixmaps.cbegin();) { for (auto i = m_pixmaps.cend(), begin = m_pixmaps.cbegin(); i != begin;) {
if ((--it)->url == type.location.filename) { if ((--i)->url == type.location.filename) {
newEvent.urlIndex = it - m_pixmaps.cbegin(); newEvent.urlIndex = i - m_pixmaps.cbegin();
break; break;
} }
} }
...@@ -188,8 +185,7 @@ void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type ...@@ -188,8 +185,7 @@ void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type
case PixmapSizeKnown: {// pixmap size case PixmapSizeKnown: {// pixmap size
// Look for pixmaps for which we don't know the size, yet and which have actually been // Look for pixmaps for which we don't know the size, yet and which have actually been
// loaded. // loaded.
for (QVector<PixmapState>::iterator i(pixmap.sizes.begin()); for (auto i = pixmap.sizes.begin(), end = pixmap.sizes.end(); i != end; ++i) {
i != pixmap.sizes.end(); ++i) {
if (i->size.isValid() || i->cacheState == Uncacheable || i->cacheState == Corrupt) if (i->size.isValid() || i->cacheState == Uncacheable || i->cacheState == Corrupt)
continue; continue;
...@@ -225,8 +221,7 @@ void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type ...@@ -225,8 +221,7 @@ void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type
// First try to find a preferred pixmap, which either is Corrupt and will be uncached // First try to find a preferred pixmap, which either is Corrupt and will be uncached
// or is uncached and will be cached. // or is uncached and will be cached.
for (QVector<PixmapState>::iterator i(pixmap.sizes.begin()); for (auto i = pixmap.sizes.begin(), end = pixmap.sizes.end(); i != end; ++i) {
i != pixmap.sizes.end(); ++i) {
if (uncache && i->cacheState == Corrupt) { if (uncache && i->cacheState == Corrupt) {
newEvent.sizeIndex = i - pixmap.sizes.begin(); newEvent.sizeIndex = i - pixmap.sizes.begin();
i->cacheState = Uncacheable; i->cacheState = Uncacheable;
...@@ -247,16 +242,15 @@ void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type ...@@ -247,16 +242,15 @@ void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type
// Error pixmaps that become corrupt cache entries. We also accept Initial to be // Error pixmaps that become corrupt cache entries. We also accept Initial to be
// uncached as we may have missed the matching PixmapCacheCountChanged that cached it. // uncached as we may have missed the matching PixmapCacheCountChanged that cached it.
if (newEvent.sizeIndex == -1) { if (newEvent.sizeIndex == -1) {
for (QVector<PixmapState>::iterator i(pixmap.sizes.begin()); for (auto i = pixmap.sizes.begin(), end = pixmap.sizes.end(); i != end; ++i) {
i != pixmap.sizes.end(); ++i) { if (uncache && (i->cacheState == Cached || i->cacheState == ToBeCached)) {
if (uncache && (i->cacheState == Cached || i->cacheState == ToBeCached ||
i->cacheState == Uncached)) {
newEvent.sizeIndex = i - pixmap.sizes.begin(); newEvent.sizeIndex = i - pixmap.sizes.begin();
if (i->size.isValid()) if (i->size.isValid())
pixSize = -i->size.width() * i->size.height(); pixSize = -i->size.width() * i->size.height();
i->cacheState = Uncached; i->cacheState = Uncached;
break; break;
} else if (!uncache && i->cacheState == Uncacheable) { } else if (!uncache && i->cacheState == Uncacheable) {
// A pixmap can repeatedly be cached, become corrupt, and the be uncached again.
newEvent.sizeIndex = i - pixmap.sizes.begin(); newEvent.sizeIndex = i - pixmap.sizes.begin();
i->cacheState = Corrupt; i->cacheState = Corrupt;
break; break;
...@@ -268,17 +262,17 @@ void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type ...@@ -268,17 +262,17 @@ void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type
if (newEvent.sizeIndex == -1) { if (newEvent.sizeIndex == -1) {
newEvent.sizeIndex = pixmap.sizes.length(); newEvent.sizeIndex = pixmap.sizes.length();
pixmap.sizes << PixmapState(uncache ? Uncached : ToBeCached); pixmap.sizes << PixmapState(uncache ? Uncached : ToBeCached);
// now the size is 0. Thus, there is no point in updating the size row.
} else if (pixSize != 0) {
m_lastCacheSizeEvent = updateCacheCount(m_lastCacheSizeEvent, pixmapStartTime, pixSize,
newEvent, event.typeIndex());
} }
m_lastCacheSizeEvent = updateCacheCount(m_lastCacheSizeEvent, pixmapStartTime, pixSize,
newEvent, event.typeIndex());
break; break;
} }
case PixmapLoadingStarted: { // Load case PixmapLoadingStarted: { // Load
// Look for a pixmap that hasn't been started, yet. There may have been a refcount // Look for a pixmap that hasn't been started, yet. There may have been a refcount
// event, which we ignore. // event, which we ignore.
for (QVector<PixmapState>::const_iterator i(pixmap.sizes.cbegin()); for (auto i = pixmap.sizes.cbegin(), end = pixmap.sizes.cend(); i != end; ++i) {
i != pixmap.sizes.cend(); ++i) {
if (i->loadState == Initial) { if (i->loadState == Initial) {
newEvent.sizeIndex = i - pixmap.sizes.cbegin(); newEvent.sizeIndex = i - pixmap.sizes.cbegin();
break; break;
...@@ -299,8 +293,7 @@ void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type ...@@ -299,8 +293,7 @@ void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type
case PixmapLoadingFinished: case PixmapLoadingFinished:
case PixmapLoadingError: { case PixmapLoadingError: {
// First try to find one that has already started // First try to find one that has already started
for (QVector<PixmapState>::const_iterator i(pixmap.sizes.cbegin()); for (auto i = pixmap.sizes.cbegin(), end = pixmap.sizes.cend(); i != end; ++i) {
i != pixmap.sizes.cend(); ++i) {
if (i->loadState != Loading) if (i->loadState != Loading)
continue; continue;
// Pixmaps with known size cannot be errors and vice versa // Pixmaps with known size cannot be errors and vice versa
...@@ -313,8 +306,7 @@ void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type ...@@ -313,8 +306,7 @@ void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type
// If none was found use any other compatible one // If none was found use any other compatible one
if (newEvent.sizeIndex == -1) { if (newEvent.sizeIndex == -1) {
for (QVector<PixmapState>::const_iterator i(pixmap.sizes.cbegin()); for (auto i = pixmap.sizes.cbegin(), end = pixmap.sizes.cend(); i != end; ++i) {
i != pixmap.sizes.cend(); ++i) {
if (i->loadState != Initial) if (i->loadState != Initial)
continue; continue;
// Pixmaps with known size cannot be errors and vice versa // Pixmaps with known size cannot be errors and vice versa
...@@ -372,7 +364,7 @@ void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type ...@@ -372,7 +364,7 @@ void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type
// Cached cannot happen as size would have to be known and Corrupt or // Cached cannot happen as size would have to be known and Corrupt or
// Uncacheable cannot happen as we only accept one finish or error event per // Uncacheable cannot happen as we only accept one finish or error event per
// pixmap. // pixmap.
Q_ASSERT(false); Q_UNREACHABLE();
} }
} else { } else {
state.loadState = Finished; state.loadState = Finished;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment