summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2015-11-25 15:06:33 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2015-11-27 17:47:02 +0200
commit591e0dde2fb97f4d40db6e11b5fbfbe4c3c0efc8 (patch)
tree98d5968f05ecc71cc5797901b34009526ae31ad3 /src
parent31fd2822f516337f084f85db7e369d0633113b73 (diff)
downloadqtlocation-mapboxgl-591e0dde2fb97f4d40db6e11b5fbfbe4c3c0efc8.tar.gz
[core] Added modified, expires information to TileData
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/annotation/annotation_tile.cpp4
-rw-r--r--src/mbgl/annotation/annotation_tile.hpp4
-rw-r--r--src/mbgl/map/geometry_tile.hpp7
-rw-r--r--src/mbgl/map/raster_tile_data.cpp5
-rw-r--r--src/mbgl/map/raster_tile_data.hpp4
-rw-r--r--src/mbgl/map/source.cpp6
-rw-r--r--src/mbgl/map/tile_data.hpp3
-rw-r--r--src/mbgl/map/vector_tile.cpp8
-rw-r--r--src/mbgl/map/vector_tile.hpp2
-rw-r--r--src/mbgl/map/vector_tile_data.cpp8
10 files changed, 37 insertions, 14 deletions
diff --git a/src/mbgl/annotation/annotation_tile.cpp b/src/mbgl/annotation/annotation_tile.cpp
index f9ab79e4f4..f79d71cfde 100644
--- a/src/mbgl/annotation/annotation_tile.cpp
+++ b/src/mbgl/annotation/annotation_tile.cpp
@@ -36,14 +36,14 @@ AnnotationTileMonitor::~AnnotationTileMonitor() {
data.getAnnotationManager()->removeTileMonitor(*this);
}
-std::unique_ptr<FileRequest> AnnotationTileMonitor::monitorTile(std::function<void (std::exception_ptr, std::unique_ptr<GeometryTile>)> callback_) {
+std::unique_ptr<FileRequest> AnnotationTileMonitor::monitorTile(const GeometryTileMonitor::Callback& callback_) {
callback = callback_;
data.getAnnotationManager()->addTileMonitor(*this);
return nullptr;
}
void AnnotationTileMonitor::update(std::unique_ptr<GeometryTile> tile) {
- callback(nullptr, std::move(tile));
+ callback(nullptr, std::move(tile), Seconds::zero(), Seconds::zero());
}
}
diff --git a/src/mbgl/annotation/annotation_tile.hpp b/src/mbgl/annotation/annotation_tile.hpp
index 70c9f7265f..a8bb2c5677 100644
--- a/src/mbgl/annotation/annotation_tile.hpp
+++ b/src/mbgl/annotation/annotation_tile.hpp
@@ -46,13 +46,13 @@ public:
~AnnotationTileMonitor();
void update(std::unique_ptr<GeometryTile>);
- std::unique_ptr<FileRequest> monitorTile(std::function<void (std::exception_ptr, std::unique_ptr<GeometryTile>)>) override;
+ std::unique_ptr<FileRequest> monitorTile(const GeometryTileMonitor::Callback&) override;
TileID tileID;
private:
MapData& data;
- std::function<void (std::exception_ptr, std::unique_ptr<GeometryTile>)> callback;
+ GeometryTileMonitor::Callback callback;
};
}
diff --git a/src/mbgl/map/geometry_tile.hpp b/src/mbgl/map/geometry_tile.hpp
index d6717ddc47..f6a4d3a536 100644
--- a/src/mbgl/map/geometry_tile.hpp
+++ b/src/mbgl/map/geometry_tile.hpp
@@ -5,6 +5,7 @@
#include <mapbox/optional.hpp>
#include <mbgl/style/value.hpp>
+#include <mbgl/util/chrono.hpp>
#include <mbgl/util/ptr.hpp>
#include <mbgl/util/vec.hpp>
#include <mbgl/util/noncopyable.hpp>
@@ -52,6 +53,10 @@ class GeometryTileMonitor : private util::noncopyable {
public:
virtual ~GeometryTileMonitor() = default;
+ using Callback = std::function<void (std::exception_ptr,
+ std::unique_ptr<GeometryTile>,
+ Seconds modified,
+ Seconds expires)>;
/*
* 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.
@@ -60,7 +65,7 @@ public:
*
* To cease monitoring, release the returned Request.
*/
- virtual std::unique_ptr<FileRequest> monitorTile(std::function<void (std::exception_ptr, std::unique_ptr<GeometryTile>)>) = 0;
+ virtual std::unique_ptr<FileRequest> monitorTile(const Callback&) = 0;
};
class GeometryTileFeatureExtractor {
diff --git a/src/mbgl/map/raster_tile_data.cpp b/src/mbgl/map/raster_tile_data.cpp
index 6d0813ee32..7ef13301e8 100644
--- a/src/mbgl/map/raster_tile_data.cpp
+++ b/src/mbgl/map/raster_tile_data.cpp
@@ -25,7 +25,7 @@ RasterTileData::~RasterTileData() {
}
void RasterTileData::request(float pixelRatio,
- const std::function<void()>& callback) {
+ const RasterTileData::Callback& callback) {
std::string url = source.tileURL(id, pixelRatio);
state = State::loading;
@@ -55,6 +55,9 @@ void RasterTileData::request(float pixelRatio,
state = State::loaded;
}
+ modified = res.modified;
+ expires = res.expires;
+
workRequest = worker.parseRasterTile(std::make_unique<RasterBucket>(texturePool), res.data, [this, callback] (RasterTileParseResult result) {
workRequest.reset();
if (state != State::loaded) {
diff --git a/src/mbgl/map/raster_tile_data.hpp b/src/mbgl/map/raster_tile_data.hpp
index f19747c441..6e7efa05f7 100644
--- a/src/mbgl/map/raster_tile_data.hpp
+++ b/src/mbgl/map/raster_tile_data.hpp
@@ -17,8 +17,10 @@ public:
RasterTileData(const TileID&, TexturePool&, const SourceInfo&, Worker&);
~RasterTileData();
+ using Callback = std::function<void()>;
+
void request(float pixelRatio,
- const std::function<void()>& callback);
+ const Callback& callback);
void cancel() override;
diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp
index 3237c544da..112d57115a 100644
--- a/src/mbgl/map/source.cpp
+++ b/src/mbgl/map/source.cpp
@@ -285,7 +285,11 @@ TileData::State Source::addTile(MapData& data,
// If we don't find working tile data, we're just going to load it.
if (info.type == SourceType::Raster) {
- auto tileData = std::make_shared<RasterTileData>(normalized_id, texturePool, info, style.workers);
+ auto tileData = std::make_shared<RasterTileData>(normalized_id,
+ texturePool,
+ info,
+ style.workers);
+
tileData->request(data.pixelRatio, callback);
new_tile.data = tileData;
} else {
diff --git a/src/mbgl/map/tile_data.hpp b/src/mbgl/map/tile_data.hpp
index 2a5745142d..ed3426cf80 100644
--- a/src/mbgl/map/tile_data.hpp
+++ b/src/mbgl/map/tile_data.hpp
@@ -2,6 +2,7 @@
#define MBGL_MAP_TILE_DATA
#include <mbgl/util/noncopyable.hpp>
+#include <mbgl/util/chrono.hpp>
#include <mbgl/map/tile_id.hpp>
#include <mbgl/renderer/bucket.hpp>
#include <mbgl/text/placement_config.hpp>
@@ -94,6 +95,8 @@ public:
void dumpDebugLogs() const;
const TileID id;
+ Seconds modified = Seconds::zero();
+ Seconds expires = Seconds::zero();
// Contains the tile ID string for painting debug information.
std::unique_ptr<DebugBucket> debugBucket;
diff --git a/src/mbgl/map/vector_tile.cpp b/src/mbgl/map/vector_tile.cpp
index 8b06932615..5144919348 100644
--- a/src/mbgl/map/vector_tile.cpp
+++ b/src/mbgl/map/vector_tile.cpp
@@ -181,7 +181,7 @@ VectorTileMonitor::VectorTileMonitor(const SourceInfo& source, const TileID& id,
: url(source.tileURL(id, pixelRatio)) {
}
-std::unique_ptr<FileRequest> VectorTileMonitor::monitorTile(std::function<void (std::exception_ptr, std::unique_ptr<GeometryTile>)> callback) {
+std::unique_ptr<FileRequest> VectorTileMonitor::monitorTile(const GeometryTileMonitor::Callback& callback) {
return util::ThreadContext::getFileSource()->request({ Resource::Kind::Tile, url }, [callback, this](Response res) {
if (res.data && data == res.data) {
// We got the same data again. Abort early.
@@ -190,18 +190,18 @@ std::unique_ptr<FileRequest> VectorTileMonitor::monitorTile(std::function<void (
if (res.error) {
if (res.error->reason == Response::Error::Reason::NotFound) {
- callback(nullptr, nullptr);
+ callback(nullptr, nullptr, res.modified, res.expires);
return;
} else {
std::stringstream message;
message << "Failed to load [" << url << "]: " << res.error->message;
- callback(std::make_exception_ptr(std::runtime_error(message.str())), nullptr);
+ callback(std::make_exception_ptr(std::runtime_error(message.str())), nullptr, res.modified, res.expires);
return;
}
}
data = res.data;
- callback(nullptr, std::make_unique<VectorTile>(data));
+ callback(nullptr, std::make_unique<VectorTile>(data), res.modified, res.expires);
});
}
diff --git a/src/mbgl/map/vector_tile.hpp b/src/mbgl/map/vector_tile.hpp
index 7c7f96abbd..e3290c27de 100644
--- a/src/mbgl/map/vector_tile.hpp
+++ b/src/mbgl/map/vector_tile.hpp
@@ -63,7 +63,7 @@ class VectorTileMonitor : public GeometryTileMonitor {
public:
VectorTileMonitor(const SourceInfo&, const TileID&, float pixelRatio);
- std::unique_ptr<FileRequest> monitorTile(std::function<void (std::exception_ptr, std::unique_ptr<GeometryTile>)>) override;
+ std::unique_ptr<FileRequest> monitorTile(const GeometryTileMonitor::Callback&) override;
private:
std::string url;
diff --git a/src/mbgl/map/vector_tile_data.cpp b/src/mbgl/map/vector_tile_data.cpp
index 28be9627ae..2ec0085585 100644
--- a/src/mbgl/map/vector_tile_data.cpp
+++ b/src/mbgl/map/vector_tile_data.cpp
@@ -25,7 +25,10 @@ VectorTileData::VectorTileData(const TileID& id_,
monitor(std::move(monitor_))
{
state = State::loading;
- tileRequest = monitor->monitorTile([callback, this](std::exception_ptr err, std::unique_ptr<GeometryTile> tile) {
+ tileRequest = monitor->monitorTile([callback, this](std::exception_ptr err,
+ std::unique_ptr<GeometryTile> tile,
+ Seconds modified_,
+ Seconds expires_) {
if (err) {
try {
std::rethrow_exception(err);
@@ -50,6 +53,9 @@ VectorTileData::VectorTileData(const TileID& id_,
state = State::partial;
}
+ modified = modified_;
+ expires = expires_;
+
// Kick off a fresh parse of this tile. This happens when the tile is new, or
// when tile data changed. Replacing the workdRequest will cancel a pending work
// request in case there is one.