summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-06-13 12:23:21 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-06-14 11:25:45 -0700
commiteecf9e7d231f282ec4ecf989360106aa91263800 (patch)
treecb593325edfd7aafab93aa724b8e03598c9d60db
parent55abb76f6840642c9734f19cb493d9efaf5329e3 (diff)
downloadqtlocation-mapboxgl-eecf9e7d231f282ec4ecf989360106aa91263800.tar.gz
[core] Virtualize Source::createTile
-rw-r--r--src/mbgl/annotation/annotation_source.cpp6
-rw-r--r--src/mbgl/annotation/annotation_source.hpp3
-rw-r--r--src/mbgl/style/source.cpp21
-rw-r--r--src/mbgl/style/source.hpp6
-rw-r--r--src/mbgl/style/sources/geojson_source.cpp6
-rw-r--r--src/mbgl/style/sources/geojson_source.hpp3
-rw-r--r--src/mbgl/style/sources/raster_source.cpp6
-rw-r--r--src/mbgl/style/sources/raster_source.hpp3
-rw-r--r--src/mbgl/style/sources/vector_source.cpp6
-rw-r--r--src/mbgl/style/sources/vector_source.hpp3
-rw-r--r--src/mbgl/tile/raster_tile.cpp2
-rw-r--r--src/mbgl/tile/raster_tile.hpp1
-rw-r--r--src/mbgl/tile/tile_loader.hpp1
-rw-r--r--src/mbgl/tile/tile_loader_impl.hpp3
14 files changed, 45 insertions, 25 deletions
diff --git a/src/mbgl/annotation/annotation_source.cpp b/src/mbgl/annotation/annotation_source.cpp
index 1589370f09..50fa7a2c09 100644
--- a/src/mbgl/annotation/annotation_source.cpp
+++ b/src/mbgl/annotation/annotation_source.cpp
@@ -1,5 +1,6 @@
#include <mbgl/annotation/annotation_source.hpp>
#include <mbgl/annotation/annotation_manager.hpp>
+#include <mbgl/annotation/annotation_tile.hpp>
namespace mbgl {
@@ -7,4 +8,9 @@ AnnotationSource::AnnotationSource()
: Source(SourceType::Annotations, AnnotationManager::SourceID, "", util::tileSize, std::make_unique<Tileset>()) {
}
+std::unique_ptr<Tile> AnnotationSource::createTile(const OverscaledTileID& tileID,
+ const style::UpdateParameters& parameters) {
+ return std::make_unique<AnnotationTile>(tileID, id, parameters);
+}
+
} // namespace mbgl
diff --git a/src/mbgl/annotation/annotation_source.hpp b/src/mbgl/annotation/annotation_source.hpp
index befff2de85..033580b645 100644
--- a/src/mbgl/annotation/annotation_source.hpp
+++ b/src/mbgl/annotation/annotation_source.hpp
@@ -7,6 +7,9 @@ namespace mbgl {
class AnnotationSource : public style::Source {
public:
AnnotationSource();
+
+private:
+ std::unique_ptr<Tile> createTile(const OverscaledTileID&, const style::UpdateParameters&) final;
};
} // namespace mbgl
diff --git a/src/mbgl/style/source.cpp b/src/mbgl/style/source.cpp
index d806e3140e..35acf3dd51 100644
--- a/src/mbgl/style/source.cpp
+++ b/src/mbgl/style/source.cpp
@@ -20,10 +20,6 @@
#include <mbgl/util/tile_cover.hpp>
#include <mbgl/util/enum.hpp>
-#include <mbgl/tile/raster_tile.hpp>
-#include <mbgl/tile/geojson_tile.hpp>
-#include <mbgl/tile/vector_tile.hpp>
-#include <mbgl/annotation/annotation_tile.hpp>
#include <mbgl/style/parser.hpp>
#include <mbgl/gl/debugging.hpp>
@@ -184,23 +180,6 @@ const std::map<UnwrappedTileID, RenderTile>& Source::getRenderTiles() const {
return renderTiles;
}
-std::unique_ptr<Tile> Source::createTile(const OverscaledTileID& overscaledTileID,
- const UpdateParameters& parameters) {
- // If we don't find working tile data, we're just going to load it.
- if (type == SourceType::Raster) {
- return std::make_unique<RasterTile>(overscaledTileID, parameters, *tileset);
- } else if (type == SourceType::Vector) {
- return std::make_unique<VectorTile>(overscaledTileID, id, parameters, *tileset);
- } else if (type == SourceType::Annotations) {
- return std::make_unique<AnnotationTile>(overscaledTileID, id, parameters);
- } else if (type == SourceType::GeoJSON) {
- return std::make_unique<GeoJSONTile>(overscaledTileID, id, parameters, geojsonvt.get());
- } else {
- Log::Warning(Event::Style, "Source type '%s' is not implemented", Enum<SourceType>::toString(type));
- return nullptr;
- }
-}
-
Tile* Source::getTile(const OverscaledTileID& overscaledTileID) const {
auto it = tiles.find(overscaledTileID);
if (it != tiles.end()) {
diff --git a/src/mbgl/style/source.hpp b/src/mbgl/style/source.hpp
index 45feadf2fe..51a9ba5c71 100644
--- a/src/mbgl/style/source.hpp
+++ b/src/mbgl/style/source.hpp
@@ -93,12 +93,10 @@ private:
void onTileError(Tile&, std::exception_ptr) override;
void onNeedsRepaint() override;
- std::unique_ptr<Tile> createTile(const OverscaledTileID&, const UpdateParameters&);
-
-private:
- std::unique_ptr<const Tileset> tileset;
+ virtual std::unique_ptr<Tile> createTile(const OverscaledTileID&, const UpdateParameters&) = 0;
protected:
+ std::unique_ptr<const Tileset> tileset;
std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> geojsonvt;
private:
diff --git a/src/mbgl/style/sources/geojson_source.cpp b/src/mbgl/style/sources/geojson_source.cpp
index 8a573becfe..caedcffcd5 100644
--- a/src/mbgl/style/sources/geojson_source.cpp
+++ b/src/mbgl/style/sources/geojson_source.cpp
@@ -1,4 +1,5 @@
#include <mbgl/style/sources/geojson_source.hpp>
+#include <mbgl/tile/geojson_tile.hpp>
#include <mapbox/geojsonvt.hpp>
@@ -14,5 +15,10 @@ GeoJSONSource::GeoJSONSource(std::string id_,
geojsonvt = std::move(geojsonvt_);
}
+std::unique_ptr<Tile> GeoJSONSource::createTile(const OverscaledTileID& tileID,
+ const UpdateParameters& parameters) {
+ return std::make_unique<GeoJSONTile>(tileID, id, parameters, geojsonvt.get());
+}
+
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/sources/geojson_source.hpp b/src/mbgl/style/sources/geojson_source.hpp
index d9f8cb4c62..c9262f22b7 100644
--- a/src/mbgl/style/sources/geojson_source.hpp
+++ b/src/mbgl/style/sources/geojson_source.hpp
@@ -12,6 +12,9 @@ public:
uint16_t tileSize,
std::unique_ptr<Tileset>&&,
std::unique_ptr<mapbox::geojsonvt::GeoJSONVT>&&);
+
+private:
+ std::unique_ptr<Tile> createTile(const OverscaledTileID&, const UpdateParameters&) final;
};
} // namespace style
diff --git a/src/mbgl/style/sources/raster_source.cpp b/src/mbgl/style/sources/raster_source.cpp
index 868d3f7f88..de8b248421 100644
--- a/src/mbgl/style/sources/raster_source.cpp
+++ b/src/mbgl/style/sources/raster_source.cpp
@@ -1,4 +1,5 @@
#include <mbgl/style/sources/raster_source.hpp>
+#include <mbgl/tile/raster_tile.hpp>
namespace mbgl {
namespace style {
@@ -10,5 +11,10 @@ RasterSource::RasterSource(std::string id_,
: Source(SourceType::Raster, std::move(id_), std::move(url_), tileSize_, std::move(tileset_)) {
}
+std::unique_ptr<Tile> RasterSource::createTile(const OverscaledTileID& tileID,
+ const UpdateParameters& parameters) {
+ return std::make_unique<RasterTile>(tileID, parameters, *tileset);
+}
+
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/sources/raster_source.hpp b/src/mbgl/style/sources/raster_source.hpp
index 0e062c14f8..abc203e3cb 100644
--- a/src/mbgl/style/sources/raster_source.hpp
+++ b/src/mbgl/style/sources/raster_source.hpp
@@ -11,6 +11,9 @@ public:
std::string url,
uint16_t tileSize,
std::unique_ptr<Tileset>&&);
+
+private:
+ std::unique_ptr<Tile> createTile(const OverscaledTileID&, const UpdateParameters&) final;
};
} // namespace style
diff --git a/src/mbgl/style/sources/vector_source.cpp b/src/mbgl/style/sources/vector_source.cpp
index e6adb9bb9f..5cf0a1e182 100644
--- a/src/mbgl/style/sources/vector_source.cpp
+++ b/src/mbgl/style/sources/vector_source.cpp
@@ -1,4 +1,5 @@
#include <mbgl/style/sources/vector_source.hpp>
+#include <mbgl/tile/vector_tile.hpp>
namespace mbgl {
namespace style {
@@ -9,5 +10,10 @@ VectorSource::VectorSource(std::string id_,
: Source(SourceType::Vector, std::move(id_), std::move(url_), util::tileSize, std::move(tileset_)) {
}
+std::unique_ptr<Tile> VectorSource::createTile(const OverscaledTileID& tileID,
+ const UpdateParameters& parameters) {
+ return std::make_unique<VectorTile>(tileID, id, parameters, *tileset);
+}
+
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/sources/vector_source.hpp b/src/mbgl/style/sources/vector_source.hpp
index 08ab9a461e..e98c17ddc1 100644
--- a/src/mbgl/style/sources/vector_source.hpp
+++ b/src/mbgl/style/sources/vector_source.hpp
@@ -10,6 +10,9 @@ public:
VectorSource(std::string id,
std::string url,
std::unique_ptr<Tileset>&&);
+
+private:
+ std::unique_ptr<Tile> createTile(const OverscaledTileID&, const UpdateParameters&) final;
};
} // namespace style
diff --git a/src/mbgl/tile/raster_tile.cpp b/src/mbgl/tile/raster_tile.cpp
index 5cfd41a164..f23d01a59a 100644
--- a/src/mbgl/tile/raster_tile.cpp
+++ b/src/mbgl/tile/raster_tile.cpp
@@ -20,6 +20,8 @@ RasterTile::RasterTile(const OverscaledTileID& id_,
loader(*this, id_, parameters, tileset) {
}
+RasterTile::~RasterTile() = default;
+
void RasterTile::setError(std::exception_ptr err) {
observer->onTileError(*this, err);
}
diff --git a/src/mbgl/tile/raster_tile.hpp b/src/mbgl/tile/raster_tile.hpp
index 8c0923e7ef..32231f7b03 100644
--- a/src/mbgl/tile/raster_tile.hpp
+++ b/src/mbgl/tile/raster_tile.hpp
@@ -21,6 +21,7 @@ public:
RasterTile(const OverscaledTileID&,
const style::UpdateParameters&,
const Tileset&);
+ ~RasterTile() final;
void setNecessity(Necessity) final;
diff --git a/src/mbgl/tile/tile_loader.hpp b/src/mbgl/tile/tile_loader.hpp
index 1086f4ed33..0d64f647d7 100644
--- a/src/mbgl/tile/tile_loader.hpp
+++ b/src/mbgl/tile/tile_loader.hpp
@@ -22,6 +22,7 @@ public:
const OverscaledTileID&,
const style::UpdateParameters&,
const Tileset&);
+ ~TileLoader();
using Necessity = Resource::Necessity;
diff --git a/src/mbgl/tile/tile_loader_impl.hpp b/src/mbgl/tile/tile_loader_impl.hpp
index 2e57f2f6f3..b987d6ec65 100644
--- a/src/mbgl/tile/tile_loader_impl.hpp
+++ b/src/mbgl/tile/tile_loader_impl.hpp
@@ -44,6 +44,9 @@ TileLoader<T>::TileLoader(T& tile_,
}
template <typename T>
+TileLoader<T>::~TileLoader() = default;
+
+template <typename T>
void TileLoader<T>::loadOptional() {
assert(!request);