From 7669e02062ccab9e3d908a9eab04f5d13a7b89c0 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 29 Oct 2015 12:00:59 -0700 Subject: [PATCH] [core] Monitor annotation tiles, rather than completely invalidating them Fixes #1688 --- src/mbgl/annotation/annotation_manager.cpp | 14 +++++++++++++- src/mbgl/annotation/annotation_manager.hpp | 9 ++++++++- src/mbgl/annotation/annotation_tile.cpp | 18 ++++++++++++++---- src/mbgl/annotation/annotation_tile.hpp | 7 ++++++- src/mbgl/map/geometry_tile.hpp | 5 +++++ src/mbgl/map/source.cpp | 7 ------- src/mbgl/map/source.hpp | 2 -- 7 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp index e5c55c90d..7169d5162 100644 --- a/src/mbgl/annotation/annotation_manager.cpp +++ b/src/mbgl/annotation/annotation_manager.cpp @@ -138,7 +138,19 @@ void AnnotationManager::updateStyle(Style& style) { } obsoleteShapeAnnotationLayers.clear(); - style.getSource(SourceID)->invalidateTiles(); + + for (auto& monitor : monitors) { + monitor->update(getTile(monitor->tileID)); + } +} + +void AnnotationManager::addTileMonitor(AnnotationTileMonitor& monitor) { + monitors.insert(&monitor); + monitor.update(getTile(monitor.tileID)); +} + +void AnnotationManager::removeTileMonitor(AnnotationTileMonitor& monitor) { + monitors.erase(&monitor); } } diff --git a/src/mbgl/annotation/annotation_manager.hpp b/src/mbgl/annotation/annotation_manager.hpp index 42acbb998..f1b41c9cc 100644 --- a/src/mbgl/annotation/annotation_manager.hpp +++ b/src/mbgl/annotation/annotation_manager.hpp @@ -9,12 +9,14 @@ #include #include +#include namespace mbgl { class PointAnnotation; class ShapeAnnotation; class AnnotationTile; +class AnnotationTileMonitor; class Style; class AnnotationManager : private util::noncopyable { @@ -30,17 +32,22 @@ public: LatLngBounds getBoundsForAnnotations(const AnnotationIDs&) const; void updateStyle(Style&); - std::unique_ptr getTile(const TileID&); + + void addTileMonitor(AnnotationTileMonitor&); + void removeTileMonitor(AnnotationTileMonitor&); static const std::string SourceID; static const std::string PointLayerID; private: + std::unique_ptr getTile(const TileID&); + AnnotationID nextID = 0; PointAnnotationImpl::Tree pointTree; PointAnnotationImpl::Map pointAnnotations; ShapeAnnotationImpl::Map shapeAnnotations; std::vector obsoleteShapeAnnotationLayers; + std::set monitors; }; } diff --git a/src/mbgl/annotation/annotation_tile.cpp b/src/mbgl/annotation/annotation_tile.cpp index 81f7662b4..4b0f2a92e 100644 --- a/src/mbgl/annotation/annotation_tile.cpp +++ b/src/mbgl/annotation/annotation_tile.cpp @@ -26,13 +26,23 @@ util::ptr AnnotationTile::getLayer(const std::string& name) c return nullptr; } -AnnotationTileMonitor::AnnotationTileMonitor(const TileID& id, MapData& data) - : tile(data.getAnnotationManager()->getTile(id)) { +AnnotationTileMonitor::AnnotationTileMonitor(const TileID& tileID_, MapData& data_) + : tileID(tileID_), + data(data_) { } -Request* AnnotationTileMonitor::monitorTile(std::function)> callback) { - callback(nullptr, std::move(tile)); +AnnotationTileMonitor::~AnnotationTileMonitor() { + data.getAnnotationManager()->removeTileMonitor(*this); +} + +Request* AnnotationTileMonitor::monitorTile(std::function)> callback_) { + callback = callback_; + data.getAnnotationManager()->addTileMonitor(*this); return nullptr; } +void AnnotationTileMonitor::update(std::unique_ptr tile) { + callback(nullptr, std::move(tile)); +} + } diff --git a/src/mbgl/annotation/annotation_tile.hpp b/src/mbgl/annotation/annotation_tile.hpp index 52955da33..dcd843ed0 100644 --- a/src/mbgl/annotation/annotation_tile.hpp +++ b/src/mbgl/annotation/annotation_tile.hpp @@ -43,11 +43,16 @@ class MapData; class AnnotationTileMonitor : public GeometryTileMonitor { public: AnnotationTileMonitor(const TileID&, MapData&); + ~AnnotationTileMonitor(); + void update(std::unique_ptr); Request* monitorTile(std::function)>) override; + TileID tileID; + private: - std::unique_ptr tile; + MapData& data; + std::function)> callback; }; } diff --git a/src/mbgl/map/geometry_tile.hpp b/src/mbgl/map/geometry_tile.hpp index 242476da6..93312bcf4 100644 --- a/src/mbgl/map/geometry_tile.hpp +++ b/src/mbgl/map/geometry_tile.hpp @@ -27,6 +27,7 @@ typedef std::vector> GeometryCollection; class GeometryTileFeature : private util::noncopyable { public: + virtual ~GeometryTileFeature() = default; virtual FeatureType getType() const = 0; virtual mapbox::util::optional getValue(const std::string& key) const = 0; virtual GeometryCollection getGeometries() const = 0; @@ -34,12 +35,14 @@ public: class GeometryTileLayer : private util::noncopyable { public: + virtual ~GeometryTileLayer() = default; virtual std::size_t featureCount() const = 0; virtual util::ptr getFeature(std::size_t) const = 0; }; class GeometryTile : private util::noncopyable { public: + virtual ~GeometryTile() = default; virtual util::ptr getLayer(const std::string&) const = 0; }; @@ -47,6 +50,8 @@ class Request; class GeometryTileMonitor : private util::noncopyable { public: + virtual ~GeometryTileMonitor() = default; + /* * Monitor the tile held by this object for changes. When the tile is loaded for the first time, * or updates, the callback is executed. If an error occurs, the first parameter will be set. diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index 3cd73734f..9a916537a 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -526,13 +526,6 @@ bool Source::update(MapData& data, return allTilesUpdated; } -void Source::invalidateTiles() { - cache.clear(); - tiles.clear(); - tile_data.clear(); - updateTilePtrs(); -} - void Source::updateTilePtrs() { tilePtrs.clear(); for (const auto& pair : tiles) { diff --git a/src/mbgl/map/source.hpp b/src/mbgl/map/source.hpp index 4aab4a8b4..9120bbfa7 100644 --- a/src/mbgl/map/source.hpp +++ b/src/mbgl/map/source.hpp @@ -78,8 +78,6 @@ public: TexturePool&, bool shouldReparsePartialTiles); - void invalidateTiles(); - void updateMatrices(const mat4 &projMatrix, const TransformState &transform); void drawClippingMasks(Painter &painter); void finishRender(Painter &painter);