10#include "StackedTileLoader.h"
12#include "MarbleDebug.h"
13#include "MarbleGlobal.h"
14#include "MergedLayerDecorator.h"
15#include "StackedTile.h"
16#include "TileLoader.h"
17#include "TileLoaderHelper.h"
22#include <QReadWriteLock>
27class StackedTileLoaderPrivate
30 explicit StackedTileLoaderPrivate(MergedLayerDecorator *mergedLayerDecorator)
31 : m_layerDecorator(mergedLayerDecorator)
33 m_tileCache.setMaxCost(20000 * 1024);
36 MergedLayerDecorator *
const m_layerDecorator;
44 , d(new StackedTileLoaderPrivate(mergedLayerDecorator))
48StackedTileLoader::~StackedTileLoader()
50 qDeleteAll(d->m_tilesOnDisplay);
54int StackedTileLoader::tileColumnCount(
int level)
const
56 return d->m_layerDecorator->tileColumnCount(level);
59int StackedTileLoader::tileRowCount(
int level)
const
61 return d->m_layerDecorator->tileRowCount(level);
64const GeoSceneAbstractTileProjection *StackedTileLoader::tileProjection()
const
66 return d->m_layerDecorator->tileProjection();
69QSize StackedTileLoader::tileSize()
const
71 return d->m_layerDecorator->tileSize();
78 for (; it != end; ++it) {
79 Q_ASSERT(it.value()->used() &&
"contained in m_tilesOnDisplay should imply used()");
80 it.value()->setUsed(
false);
92 if (!it.
value()->used()) {
96 d->m_tileCache.insert(it.
key(), it.
value(), it.
value()->byteCount());
97 d->m_tilesOnDisplay.remove(it.
key());
106 StackedTile *stackedTile = d->m_tilesOnDisplay.value(stackedTileId,
nullptr);
109 stackedTile->setUsed(
true);
117 stackedTile = d->m_tilesOnDisplay.value(stackedTileId,
nullptr);
119 Q_ASSERT(stackedTile->used() &&
"other thread should have marked tile as used");
125 stackedTile = d->m_tileCache.take(stackedTileId);
127 Q_ASSERT(!stackedTile->used() &&
"tiles in m_tileCache are invisible and should thus be marked as unused");
128 stackedTile->setUsed(
true);
129 d->m_tilesOnDisplay[stackedTileId] = stackedTile;
137 mDebug() <<
"load tile from disk:" << stackedTileId;
139 stackedTile = d->m_layerDecorator->loadTile(stackedTileId);
140 Q_ASSERT(stackedTile);
141 stackedTile->setUsed(
true);
143 d->m_tilesOnDisplay[stackedTileId] = stackedTile;
146 Q_EMIT tileLoaded(stackedTileId);
153 return d->m_tileCache.maxCost() / 1024;
158 return d->m_tilesOnDisplay.keys();
163 return d->m_tileCache.count() + d->m_tilesOnDisplay.count();
168 mDebug() << QStringLiteral(
"Setting tile cache to %1 kilobytes.").arg(kiloBytes);
169 d->m_tileCache.setMaxCost(kiloBytes * 1024);
172void StackedTileLoader::updateTile(TileId
const &tileId,
QImage const &tileImage)
174 const TileId stackedTileId(0, tileId.zoomLevel(), tileId.x(), tileId.y());
176 StackedTile *displayedTile = d->m_tilesOnDisplay.take(stackedTileId);
178 Q_ASSERT(!d->m_tileCache.contains(stackedTileId));
180 StackedTile *
const stackedTile = d->m_layerDecorator->updateTile(*displayedTile, tileId, tileImage);
181 stackedTile->setUsed(
true);
182 d->m_tilesOnDisplay.insert(stackedTileId, stackedTile);
184 delete displayedTile;
185 displayedTile =
nullptr;
187 Q_EMIT tileLoaded(stackedTileId);
189 d->m_tileCache.remove(stackedTileId);
193RenderState StackedTileLoader::renderState()
const
198 for (; it !=
end; ++it) {
199 renderState.addChild(d->m_layerDecorator->renderState(it.key()));
206 qDeleteAll(d->m_tilesOnDisplay);
207 d->m_tilesOnDisplay.clear();
208 d->m_tileCache.clear();
215#include "moc_StackedTileLoader.cpp"
void clear()
Effectively triggers a reload of all tiles that are currently in use and clears the tile cache in phy...
int tileCount() const
Return the number of tiles in the cache.
void cleanupTilehash()
Cleans up the internal tile hash.
void resetTilehash()
Resets the internal tile hash.
quint64 volatileCacheLimit() const
Returns the limit of the volatile (in RAM) cache.
StackedTileLoader(MergedLayerDecorator *mergedLayerDecorator, QObject *parent=nullptr)
Creates a new tile loader.
QList< TileId > visibleTiles() const
Reloads the tiles that are currently displayed.
const StackedTile * loadTile(TileId const &stackedTileId)
Loads a tile and returns it.
void setVolatileCacheLimit(quint64 kiloBytes)
Set the limit of the volatile (in RAM) cache.
A single tile that consists of a stack of Tile layers.
const QList< QKeySequence > & end()
Binds a QML item to a specific geodetic location in screen coordinates.
bool hasNext() const const
const Key & key() const const
const T & value() const const
QString fromLatin1(QByteArrayView str)