[Marble-commits] KDE/kdeedu/marble/src/lib

Jens-Michael Hoffmann jensmh at gmx.de
Tue Mar 23 16:16:25 CET 2010


SVN commit 1106665 by jmhoffmann:

Fix (or rather improve) cost calculation for tile cache.

This is a fix for a regression introduced with the tile loader refactoring.
Since then, StackedTile is used which includes a set of tiles and the
composed result tile. This was not taken into account.

However, the cost calculation is still not correct, as in some cases
because of QImage's implicitly shared data, the calculated value is too high.
Maybe this is better than if a value too low is reported.

 M  +14 -1     StackedTile.cpp  
 M  +2 -0      StackedTile_p.h  
 M  +0 -1      TextureTile.cpp  
 M  +8 -0      TextureTile.h  


--- trunk/KDE/kdeedu/marble/src/lib/StackedTile.cpp #1106664:1106665
@@ -60,6 +60,7 @@
       jumpTable8(0),
       jumpTable32(0),
       m_resultTile(),
+      m_byteCount(0),
       m_depth(0),
       m_isGrayscale( false ),
       m_forMergedLayerDecorator( false )
@@ -233,6 +234,17 @@
     }
 }
 
+void StackedTilePrivate::calcByteCount()
+{
+    int byteCount = m_resultTile.numBytes();
+    QVector<QSharedPointer<TextureTile> >::const_iterator pos = m_tiles.constBegin();
+    QVector<QSharedPointer<TextureTile> >::const_iterator const end = m_tiles.constEnd();
+    for (; pos != end; ++pos )
+        byteCount += (*pos)->byteCount();
+    m_byteCount = byteCount;
+}
+
+
 StackedTile::StackedTile( TileId const& id, QObject * parent )
     : AbstractTile( *new StackedTilePrivate( id ), parent ), d(0)
 {
@@ -349,7 +361,7 @@
 
 int StackedTile::numBytes() const
 {
-    return d->m_resultTile.numBytes();
+    return d->m_byteCount;
 }
 
 QImage const * StackedTile::resultTile() const
@@ -388,6 +400,7 @@
     // for now, this seems to be the best place for initializing this stuff
     d->m_depth = d->m_resultTile.depth();
     d->m_isGrayscale = d->m_resultTile.isGrayscale();
+    d->calcByteCount();
 }
 
 #include "StackedTile.moc"
--- trunk/KDE/kdeedu/marble/src/lib/StackedTile_p.h #1106664:1106665
@@ -38,6 +38,7 @@
 
     QVector<QSharedPointer<TextureTile> > m_tiles;
     QImage    m_resultTile;
+    int m_byteCount;
 
     int       m_depth;
     bool      m_isGrayscale;
@@ -50,6 +51,7 @@
     inline uint pixelF( qreal x, qreal y, const QRgb& pixel ) const;
     void mergeCopyToResult( QSharedPointer<TextureTile> const & tile );
     void mergeMultiplyToResult( QSharedPointer<TextureTile> const & tile );
+    void calcByteCount();
 };
 
 }
--- trunk/KDE/kdeedu/marble/src/lib/TextureTile.cpp #1106664:1106665
@@ -18,7 +18,6 @@
 #include <limits>
 
 #include <QtCore/QString>
-#include <QtGui/QImage>
 
 namespace Marble
 {
--- trunk/KDE/kdeedu/marble/src/lib/TextureTile.h #1106664:1106665
@@ -17,6 +17,7 @@
 #define MARBLE_TEXTURE_TILE_H
 
 #include <QtCore/QDateTime>
+#include <QtGui/QImage>
 
 #include "TileId.h"
 
@@ -58,6 +59,7 @@
     QImage * image();
     State state() const;
     MergeRule mergeRule() const;
+    int byteCount() const;
 
  private:
     Q_DISABLE_COPY( TextureTile )
@@ -122,6 +124,12 @@
     return m_mergeRule;
 }
 
+inline int TextureTile::byteCount() const
+{
+    // FIXME: once Qt 4.6 is required for Marble, use QImage::byteCount()
+    return m_image ? m_image->numBytes() : 0;
+}
+
 inline void TextureTile::setState( State const state )
 {
     m_state = state;


More information about the Marble-commits mailing list