1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-18 11:52:08 +01:00

Improved tile loading parallelism

This commit is contained in:
Martin Tůma 2024-12-01 10:25:10 +01:00
parent f620bbc383
commit c014526bd9
2 changed files with 49 additions and 22 deletions

View File

@ -120,15 +120,15 @@ void VectorTile::clear()
void VectorTile::polys(QFile *file, const RectC &rect, const Zoom &zoom, void VectorTile::polys(QFile *file, const RectC &rect, const Zoom &zoom,
QList<MapData::Poly> *polygons, QList<MapData::Poly> *lines, QList<MapData::Poly> *polygons, QList<MapData::Poly> *lines,
MapData::PolyCache *cache, QMutex *lock) MapData::PolyCache *cache, QMutex *cacheLock)
{ {
SubFile::Handle *rgnHdl = 0, *lblHdl = 0, *netHdl = 0, *nodHdl = 0, SubFile::Handle *rgnHdl = 0, *lblHdl = 0, *netHdl = 0, *nodHdl = 0,
*nodHdl2 = 0; *nodHdl2 = 0;
lock->lock(); _lock.lock();
if (_loaded < 0) { if (_loaded < 0) {
lock->unlock(); _lock.unlock();
return; return;
} }
@ -139,18 +139,23 @@ void VectorTile::polys(QFile *file, const RectC &rect, const Zoom &zoom,
nodHdl = new SubFile::Handle(file, _nod); nodHdl = new SubFile::Handle(file, _nod);
if (!load(*rgnHdl, *lblHdl, *netHdl, *nodHdl)) { if (!load(*rgnHdl, *lblHdl, *netHdl, *nodHdl)) {
lock->unlock(); _lock.unlock();
delete rgnHdl; delete lblHdl; delete netHdl; delete nodHdl; delete rgnHdl; delete lblHdl; delete netHdl; delete nodHdl;
return; return;
} }
} }
QList<SubDiv*> subdivs = _tre->subdivs(file, rect, zoom); QList<SubDiv*> subdivs = _tre->subdivs(file, rect, zoom);
cacheLock->lock();
for (int i = 0; i < subdivs.size(); i++) { for (int i = 0; i < subdivs.size(); i++) {
SubDiv *subdiv = subdivs.at(i); SubDiv *subdiv = subdivs.at(i);
MapData::Polys *polys = cache->object(subdiv); MapData::Polys *polys = cache->object(subdiv);
if (!polys) { if (!polys) {
cacheLock->unlock();
quint32 shift = _tre->shift(subdiv->bits()); quint32 shift = _tre->shift(subdiv->bits());
if (!rgnHdl) { if (!rgnHdl) {
@ -159,8 +164,10 @@ void VectorTile::polys(QFile *file, const RectC &rect, const Zoom &zoom,
netHdl = new SubFile::Handle(file, _net); netHdl = new SubFile::Handle(file, _net);
} }
if (!subdiv->initialized() && !_rgn->subdivInit(*rgnHdl, subdiv)) if (!subdiv->initialized() && !_rgn->subdivInit(*rgnHdl, subdiv)) {
cacheLock->lock();
continue; continue;
}
polys = new MapData::Polys(); polys = new MapData::Polys();
@ -186,6 +193,7 @@ void VectorTile::polys(QFile *file, const RectC &rect, const Zoom &zoom,
if (lines) if (lines)
copyPolys(rect, &polys->lines, lines); copyPolys(rect, &polys->lines, lines);
cacheLock->lock();
cache->insert(subdiv, polys); cache->insert(subdiv, polys);
} else { } else {
copyPolys(rect, &polys->polygons, polygons); copyPolys(rect, &polys->polygons, polygons);
@ -194,20 +202,21 @@ void VectorTile::polys(QFile *file, const RectC &rect, const Zoom &zoom,
} }
} }
lock->unlock(); cacheLock->unlock();
_lock.unlock();
delete rgnHdl; delete lblHdl; delete netHdl; delete nodHdl; delete nodHdl2; delete rgnHdl; delete lblHdl; delete netHdl; delete nodHdl; delete nodHdl2;
} }
void VectorTile::points(QFile *file, const RectC &rect, const Zoom &zoom, void VectorTile::points(QFile *file, const RectC &rect, const Zoom &zoom,
QList<MapData::Point> *points, MapData::PointCache *cache, QMutex *lock) QList<MapData::Point> *points, MapData::PointCache *cache, QMutex *cacheLock)
{ {
SubFile::Handle *rgnHdl = 0, *lblHdl = 0; SubFile::Handle *rgnHdl = 0, *lblHdl = 0;
lock->lock(); _lock.lock();
if (_loaded < 0) { if (_loaded < 0) {
lock->unlock(); _lock.unlock();
return; return;
} }
@ -218,25 +227,32 @@ void VectorTile::points(QFile *file, const RectC &rect, const Zoom &zoom,
SubFile::Handle netHdl(file, _net); SubFile::Handle netHdl(file, _net);
if (!load(*rgnHdl, *lblHdl, netHdl, nodHdl)) { if (!load(*rgnHdl, *lblHdl, netHdl, nodHdl)) {
lock->unlock(); _lock.unlock();
delete rgnHdl; delete lblHdl; delete rgnHdl; delete lblHdl;
return; return;
} }
} }
QList<SubDiv*> subdivs = _tre->subdivs(file, rect, zoom); QList<SubDiv*> subdivs = _tre->subdivs(file, rect, zoom);
cacheLock->lock();
for (int i = 0; i < subdivs.size(); i++) { for (int i = 0; i < subdivs.size(); i++) {
SubDiv *subdiv = subdivs.at(i); SubDiv *subdiv = subdivs.at(i);
QList<MapData::Point> *pl = cache->object(subdiv); QList<MapData::Point> *pl = cache->object(subdiv);
if (!pl) { if (!pl) {
cacheLock->unlock();
if (!rgnHdl) { if (!rgnHdl) {
rgnHdl = new SubFile::Handle(file, _rgn); rgnHdl = new SubFile::Handle(file, _rgn);
lblHdl = new SubFile::Handle(file, _lbl); lblHdl = new SubFile::Handle(file, _lbl);
} }
if (!subdiv->initialized() && !_rgn->subdivInit(*rgnHdl, subdiv)) if (!subdiv->initialized() && !_rgn->subdivInit(*rgnHdl, subdiv)) {
cacheLock->lock();
continue; continue;
}
pl = new QList<MapData::Point>; pl = new QList<MapData::Point>;
@ -248,26 +264,28 @@ void VectorTile::points(QFile *file, const RectC &rect, const Zoom &zoom,
copyPoints(rect, pl, points); copyPoints(rect, pl, points);
cacheLock->lock();
cache->insert(subdiv, pl); cache->insert(subdiv, pl);
} else } else
copyPoints(rect, pl, points); copyPoints(rect, pl, points);
} }
lock->unlock(); cacheLock->unlock();
_lock.unlock();
delete rgnHdl; delete lblHdl; delete rgnHdl; delete lblHdl;
} }
void VectorTile::elevations(QFile *file, const RectC &rect, const Zoom &zoom, void VectorTile::elevations(QFile *file, const RectC &rect, const Zoom &zoom,
QList<MapData::Elevation> *elevations, MapData::ElevationCache *cache, QList<MapData::Elevation> *elevations, MapData::ElevationCache *cache,
QMutex *lock) QMutex *cacheLock)
{ {
SubFile::Handle *hdl = 0; SubFile::Handle *hdl = 0;
lock->lock(); _demLock.lock();
if (_demLoaded < 0) { if (_demLoaded < 0) {
lock->unlock(); _demLock.unlock();
return; return;
} }
@ -275,7 +293,7 @@ void VectorTile::elevations(QFile *file, const RectC &rect, const Zoom &zoom,
hdl = new SubFile::Handle(file, _dem); hdl = new SubFile::Handle(file, _dem);
if (!loadDem(*hdl)) { if (!loadDem(*hdl)) {
lock->unlock(); _demLock.unlock();
delete hdl; delete hdl;
return; return;
} }
@ -285,19 +303,25 @@ void VectorTile::elevations(QFile *file, const RectC &rect, const Zoom &zoom,
// the given zoom (we prefer rendering quality rather than speed). For // the given zoom (we prefer rendering quality rather than speed). For
// maps with a single level this has no effect. // maps with a single level this has no effect.
int level = qMax(0, _dem->level(zoom) - 1); int level = qMax(0, _dem->level(zoom) - 1);
QList<const DEMTile*> tiles(_dem->tiles(rect, level)); QList<const DEMTile*> tiles(_dem->tiles(rect, level));
cacheLock->lock();
for (int i = 0; i < tiles.size(); i++) { for (int i = 0; i < tiles.size(); i++) {
const DEMTile *tile = tiles.at(i); const DEMTile *tile = tiles.at(i);
MapData::Elevation *el = cache->object(tile);
MapData::Elevation *el = cache->object(tile);
if (!el) { if (!el) {
cacheLock->unlock();
if (!hdl) if (!hdl)
hdl = new SubFile::Handle(file, _dem); hdl = new SubFile::Handle(file, _dem);
el = _dem->elevations(*hdl, level, tile); el = _dem->elevations(*hdl, level, tile);
if (!el->m.isNull()) if (!el->m.isNull())
elevations->append(*el); elevations->append(*el);
cacheLock->lock();
cache->insert(tile, el); cache->insert(tile, el);
} else { } else {
if (!el->m.isNull()) if (!el->m.isNull())
@ -305,7 +329,8 @@ void VectorTile::elevations(QFile *file, const RectC &rect, const Zoom &zoom,
} }
} }
lock->unlock(); cacheLock->unlock();
_demLock.unlock();
delete hdl; delete hdl;
} }

View File

@ -32,12 +32,13 @@ public:
void polys(QFile *file, const RectC &rect, const Zoom &zoom, void polys(QFile *file, const RectC &rect, const Zoom &zoom,
QList<MapData::Poly> *polygons, QList<MapData::Poly> *lines, QList<MapData::Poly> *polygons, QList<MapData::Poly> *lines,
MapData::PolyCache *cache, QMutex *lock); MapData::PolyCache *cache, QMutex *cacheLock);
void points(QFile *file, const RectC &rect, const Zoom &zoom, void points(QFile *file, const RectC &rect, const Zoom &zoom,
QList<MapData::Point> *points, MapData::PointCache *cache, QMutex *lock); QList<MapData::Point> *points, MapData::PointCache *cache,
QMutex *cacheLock);
void elevations(QFile *file, const RectC &rect, const Zoom &zoom, void elevations(QFile *file, const RectC &rect, const Zoom &zoom,
QList<MapData::Elevation> *elevations, MapData::ElevationCache *cache, QList<MapData::Elevation> *elevations, MapData::ElevationCache *cache,
QMutex *lock); QMutex *cacheLock);
static bool isTileFile(SubFile::Type type) static bool isTileFile(SubFile::Type type)
{ {
@ -92,6 +93,7 @@ private:
SubFile *_gmp; SubFile *_gmp;
int _loaded, _demLoaded; int _loaded, _demLoaded;
QMutex _lock, _demLock;
}; };
} }