summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-06-06 16:59:27 -0700
committerKonstantin Käfer <mail@kkaefer.com>2016-06-10 12:42:14 +0200
commitc3a8534a4308474a4b6cad09785d53ab43cb6f6a (patch)
tree3d18d2d72bfb216a49fe18dd17fe51b46e0da6db
parent908f3f083244dc264e8e6a6869c543d456b2b13c (diff)
downloadqtlocation-mapboxgl-c3a8534a4308474a4b6cad09785d53ab43cb6f6a.tar.gz
[core] Push conditional initialization into subclasses
-rw-r--r--src/mbgl/style/source.cpp50
-rw-r--r--src/mbgl/tile/annotation_tile_data.cpp15
-rw-r--r--src/mbgl/tile/annotation_tile_data.hpp8
-rw-r--r--src/mbgl/tile/geojson_tile_data.cpp17
-rw-r--r--src/mbgl/tile/geojson_tile_data.hpp15
-rw-r--r--src/mbgl/tile/raster_tile_data.cpp16
-rw-r--r--src/mbgl/tile/raster_tile_data.hpp6
-rw-r--r--src/mbgl/tile/vector_tile_data.cpp22
-rw-r--r--src/mbgl/tile/vector_tile_data.hpp11
9 files changed, 106 insertions, 54 deletions
diff --git a/src/mbgl/style/source.cpp b/src/mbgl/style/source.cpp
index d0a002dd70..7e012727dd 100644
--- a/src/mbgl/style/source.cpp
+++ b/src/mbgl/style/source.cpp
@@ -2,6 +2,7 @@
#include <mbgl/style/source_observer.hpp>
#include <mbgl/map/transform.hpp>
#include <mbgl/tile/tile.hpp>
+#include <mbgl/tile/tile_source.hpp>
#include <mbgl/renderer/painter.hpp>
#include <mbgl/util/exception.hpp>
#include <mbgl/util/constants.hpp>
@@ -19,11 +20,6 @@
#include <mbgl/util/string.hpp>
#include <mbgl/util/tile_cover.hpp>
-#include <mbgl/tile/vector_tile_source.hpp>
-#include <mbgl/tile/geojson_tile_source.hpp>
-#include <mbgl/tile/annotation_tile_source.hpp>
-#include <mbgl/tile/image_tile_source.hpp>
-
#include <mbgl/tile/raster_tile_data.hpp>
#include <mbgl/tile/annotation_tile_data.hpp>
#include <mbgl/tile/geojson_tile_data.hpp>
@@ -194,49 +190,13 @@ std::unique_ptr<TileData> Source::createTile(const OverscaledTileID& overscaledT
const UpdateParameters& parameters) {
// If we don't find working tile data, we're just going to load it.
if (type == SourceType::Raster) {
- assert(!tileset->tiles.empty());
- const auto resource = Resource::tile(
- tileset->tiles.at(0), parameters.pixelRatio, overscaledTileID.canonical.x,
- overscaledTileID.canonical.y, overscaledTileID.canonical.z);
- auto data = std::make_unique<RasterTileData>(overscaledTileID, parameters.texturePool,
- parameters.worker);
- data->setTileSource(
- std::make_unique<ImageTileSource>(*data, resource, parameters.fileSource));
-
- // Need a std::move here to create a std::unique_ptr<TileData> from
- // std::unique_ptr<GeometryTileData>.
- return std::move(data);
+ return std::make_unique<RasterTileData>(overscaledTileID, parameters, *tileset);
} else if (type == SourceType::Vector) {
- assert(!tileset->tiles.empty());
- const auto resource = Resource::tile(
- tileset->tiles.at(0), parameters.pixelRatio, overscaledTileID.canonical.x,
- overscaledTileID.canonical.y, overscaledTileID.canonical.z);
- auto data = std::make_unique<VectorTileData>(overscaledTileID, id, parameters.style,
- parameters.mode);
- data->setTileSource(
- std::make_unique<VectorTileSource>(*data, resource, parameters.fileSource));
-
- // Need a std::move here to create a std::unique_ptr<TileData> from
- // std::unique_ptr<GeometryTileData>.
- return std::move(data);
+ return std::make_unique<VectorTileData>(overscaledTileID, id, parameters, *tileset);
} else if (type == SourceType::Annotations) {
- auto data = std::make_unique<AnnotationTileData>(overscaledTileID, id, parameters.style,
- parameters.mode);
- data->setTileSource(std::make_unique<AnnotationTileSource>(
- *data, overscaledTileID, parameters.annotationManager));
-
- // Need a std::move here to create a std::unique_ptr<TileData> from
- // std::unique_ptr<GeometryTileData>.
- return std::move(data);
+ return std::make_unique<AnnotationTileData>(overscaledTileID, id, parameters);
} else if (type == SourceType::GeoJSON) {
- auto data = std::make_unique<GeoJSONTileData>(overscaledTileID, id, parameters.style,
- parameters.mode);
- data->setTileSource(
- std::make_unique<GeoJSONTileSource>(*data, geojsonvt.get(), overscaledTileID));
-
- // Need a std::move here to create a std::unique_ptr<TileData> from
- // std::unique_ptr<GeometryTileData>.
- return std::move(data);
+ return std::make_unique<GeoJSONTileData>(overscaledTileID, id, parameters, geojsonvt.get());
} else {
Log::Warning(Event::Style, "Source type '%s' is not implemented",
SourceTypeClass(type).c_str());
diff --git a/src/mbgl/tile/annotation_tile_data.cpp b/src/mbgl/tile/annotation_tile_data.cpp
new file mode 100644
index 0000000000..5d23a35b2f
--- /dev/null
+++ b/src/mbgl/tile/annotation_tile_data.cpp
@@ -0,0 +1,15 @@
+#include <mbgl/tile/annotation_tile_data.hpp>
+#include <mbgl/tile/annotation_tile_source.hpp>
+#include <mbgl/style/update_parameters.hpp>
+
+namespace mbgl {
+
+AnnotationTileData::AnnotationTileData(const OverscaledTileID& overscaledTileID,
+ std::string sourceID,
+ const style::UpdateParameters& parameters)
+ : GeometryTileData(overscaledTileID, sourceID, parameters.style, parameters.mode) {
+ setTileSource(std::make_unique<AnnotationTileSource>(
+ *this, overscaledTileID, parameters.annotationManager));
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/tile/annotation_tile_data.hpp b/src/mbgl/tile/annotation_tile_data.hpp
index fdd6dde6b0..4d8357eab9 100644
--- a/src/mbgl/tile/annotation_tile_data.hpp
+++ b/src/mbgl/tile/annotation_tile_data.hpp
@@ -4,9 +4,15 @@
namespace mbgl {
+namespace style {
+class UpdateParameters;
+}
+
class AnnotationTileData : public GeometryTileData {
public:
- using GeometryTileData::GeometryTileData;
+ AnnotationTileData(const OverscaledTileID&,
+ std::string sourceID,
+ const style::UpdateParameters&);
};
} // namespace mbgl
diff --git a/src/mbgl/tile/geojson_tile_data.cpp b/src/mbgl/tile/geojson_tile_data.cpp
new file mode 100644
index 0000000000..4464ae34b8
--- /dev/null
+++ b/src/mbgl/tile/geojson_tile_data.cpp
@@ -0,0 +1,17 @@
+#include <mbgl/tile/geojson_tile_data.hpp>
+#include <mbgl/tile/geojson_tile_source.hpp>
+#include <mbgl/style/update_parameters.hpp>
+
+namespace mbgl {
+
+GeoJSONTileData::GeoJSONTileData(const OverscaledTileID& overscaledTileID,
+ std::string sourceID,
+ const style::UpdateParameters& parameters,
+ mapbox::geojsonvt::GeoJSONVT* geojsonvt)
+ : GeometryTileData(overscaledTileID, sourceID, parameters.style, parameters.mode) {
+ setTileSource(
+ std::make_unique<GeoJSONTileSource>(*this, geojsonvt, overscaledTileID));
+}
+
+
+} // namespace mbgl
diff --git a/src/mbgl/tile/geojson_tile_data.hpp b/src/mbgl/tile/geojson_tile_data.hpp
index be1a38abe6..63a0b1b65d 100644
--- a/src/mbgl/tile/geojson_tile_data.hpp
+++ b/src/mbgl/tile/geojson_tile_data.hpp
@@ -2,11 +2,24 @@
#include <mbgl/tile/geometry_tile_data.hpp>
+namespace mapbox {
+namespace geojsonvt {
+class GeoJSONVT;
+} // namespace geojsonvt
+} // namespace mapbox
+
namespace mbgl {
+namespace style {
+class UpdateParameters;
+}
+
class GeoJSONTileData : public GeometryTileData {
public:
- using GeometryTileData::GeometryTileData;
+ GeoJSONTileData(const OverscaledTileID&,
+ std::string sourceID,
+ const style::UpdateParameters&,
+ mapbox::geojsonvt::GeoJSONVT*);
};
} // namespace mbgl
diff --git a/src/mbgl/tile/raster_tile_data.cpp b/src/mbgl/tile/raster_tile_data.cpp
index dade0357c1..0d388181c7 100644
--- a/src/mbgl/tile/raster_tile_data.cpp
+++ b/src/mbgl/tile/raster_tile_data.cpp
@@ -1,6 +1,8 @@
#include <mbgl/tile/raster_tile_data.hpp>
#include <mbgl/style/source.hpp>
+#include <mbgl/style/update_parameters.hpp>
#include <mbgl/tile/tile_data_observer.hpp>
+#include <mbgl/tile/image_tile_source.hpp>
#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/response.hpp>
#include <mbgl/storage/file_source.hpp>
@@ -10,11 +12,17 @@
using namespace mbgl;
RasterTileData::RasterTileData(const OverscaledTileID& id_,
- gl::TexturePool& texturePool_,
- Worker& worker_)
+ const style::UpdateParameters& parameters,
+ const Tileset& tileset)
: TileData(id_),
- texturePool(texturePool_),
- worker(worker_) {
+ texturePool(parameters.texturePool),
+ worker(parameters.worker) {
+ assert(!tileset.tiles.empty());
+ const auto resource = Resource::tile(
+ tileset.tiles.at(0), parameters.pixelRatio, id_.canonical.x,
+ id_.canonical.y, id_.canonical.z);
+ setTileSource(
+ std::make_unique<ImageTileSource>(*this, resource, parameters.fileSource));
}
void RasterTileData::setError(std::exception_ptr err) {
diff --git a/src/mbgl/tile/raster_tile_data.hpp b/src/mbgl/tile/raster_tile_data.hpp
index f5c82d4e0d..5f2478745b 100644
--- a/src/mbgl/tile/raster_tile_data.hpp
+++ b/src/mbgl/tile/raster_tile_data.hpp
@@ -7,18 +7,20 @@ namespace mbgl {
class RasterTileSource;
class AsyncRequest;
+class Tileset;
namespace gl { class TexturePool; }
namespace style {
class Layer;
+class UpdateParameters;
}
class RasterTileData : public TileData {
public:
RasterTileData(const OverscaledTileID&,
- gl::TexturePool&,
- Worker&);
+ const style::UpdateParameters&,
+ const Tileset&);
~RasterTileData();
void setError(std::exception_ptr err);
diff --git a/src/mbgl/tile/vector_tile_data.cpp b/src/mbgl/tile/vector_tile_data.cpp
new file mode 100644
index 0000000000..58d528a8f3
--- /dev/null
+++ b/src/mbgl/tile/vector_tile_data.cpp
@@ -0,0 +1,22 @@
+#include <mbgl/tile/vector_tile_data.hpp>
+#include <mbgl/tile/vector_tile_source.hpp>
+#include <mbgl/style/update_parameters.hpp>
+#include <mbgl/util/tileset.hpp>
+#include <mbgl/util/async_request.hpp>
+
+namespace mbgl {
+
+VectorTileData::VectorTileData(const OverscaledTileID& overscaledTileID,
+ std::string sourceID,
+ const style::UpdateParameters& parameters,
+ const Tileset& tileset)
+ : GeometryTileData(overscaledTileID, sourceID, parameters.style, parameters.mode) {
+ assert(!tileset.tiles.empty());
+ const auto resource = Resource::tile(
+ tileset.tiles.at(0), parameters.pixelRatio, overscaledTileID.canonical.x,
+ overscaledTileID.canonical.y, overscaledTileID.canonical.z);
+ setTileSource(
+ std::make_unique<VectorTileSource>(*this, resource, parameters.fileSource));
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/tile/vector_tile_data.hpp b/src/mbgl/tile/vector_tile_data.hpp
index 67aadb8a71..739d1b9e7f 100644
--- a/src/mbgl/tile/vector_tile_data.hpp
+++ b/src/mbgl/tile/vector_tile_data.hpp
@@ -4,9 +4,18 @@
namespace mbgl {
+class Tileset;
+
+namespace style {
+class UpdateParameters;
+}
+
class VectorTileData : public GeometryTileData {
public:
- using GeometryTileData::GeometryTileData;
+ VectorTileData(const OverscaledTileID&,
+ std::string sourceID,
+ const style::UpdateParameters&,
+ const Tileset&);
};
} // namespace mbgl