From 591e0dde2fb97f4d40db6e11b5fbfbe4c3c0efc8 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Wed, 25 Nov 2015 15:06:33 +0200 Subject: [PATCH] [core] Added modified, expires information to TileData --- src/mbgl/annotation/annotation_tile.cpp | 4 ++-- src/mbgl/annotation/annotation_tile.hpp | 4 ++-- src/mbgl/map/geometry_tile.hpp | 7 ++++++- src/mbgl/map/raster_tile_data.cpp | 5 ++++- src/mbgl/map/raster_tile_data.hpp | 4 +++- src/mbgl/map/source.cpp | 6 +++++- src/mbgl/map/tile_data.hpp | 3 +++ src/mbgl/map/vector_tile.cpp | 8 ++++---- src/mbgl/map/vector_tile.hpp | 2 +- src/mbgl/map/vector_tile_data.cpp | 8 +++++++- 10 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/mbgl/annotation/annotation_tile.cpp b/src/mbgl/annotation/annotation_tile.cpp index f9ab79e4f..f79d71cfd 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 AnnotationTileMonitor::monitorTile(std::function)> callback_) { +std::unique_ptr AnnotationTileMonitor::monitorTile(const GeometryTileMonitor::Callback& callback_) { callback = callback_; data.getAnnotationManager()->addTileMonitor(*this); return nullptr; } void AnnotationTileMonitor::update(std::unique_ptr 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 70c9f7265..a8bb2c567 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); - std::unique_ptr monitorTile(std::function)>) override; + std::unique_ptr monitorTile(const GeometryTileMonitor::Callback&) override; TileID tileID; private: MapData& data; - std::function)> callback; + GeometryTileMonitor::Callback callback; }; } diff --git a/src/mbgl/map/geometry_tile.hpp b/src/mbgl/map/geometry_tile.hpp index d6717ddc4..f6a4d3a53 100644 --- a/src/mbgl/map/geometry_tile.hpp +++ b/src/mbgl/map/geometry_tile.hpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -52,6 +53,10 @@ class GeometryTileMonitor : private util::noncopyable { public: virtual ~GeometryTileMonitor() = default; + using Callback = std::function, + 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 monitorTile(std::function)>) = 0; + virtual std::unique_ptr 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 6d0813ee3..7ef13301e 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& 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(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 f19747c44..6e7efa05f 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 request(float pixelRatio, - const std::function& callback); + const Callback& callback); void cancel() override; diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index 3237c544d..112d57115 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(normalized_id, texturePool, info, style.workers); + auto tileData = std::make_shared(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 2a5745142..ed3426cf8 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 +#include #include #include #include @@ -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; diff --git a/src/mbgl/map/vector_tile.cpp b/src/mbgl/map/vector_tile.cpp index 8b0693261..514491934 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 VectorTileMonitor::monitorTile(std::function)> callback) { +std::unique_ptr 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 VectorTileMonitor::monitorTile(std::functionreason == 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(data)); + callback(nullptr, std::make_unique(data), res.modified, res.expires); }); } diff --git a/src/mbgl/map/vector_tile.hpp b/src/mbgl/map/vector_tile.hpp index 7c7f96abb..e3290c27d 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 monitorTile(std::function)>) override; + std::unique_ptr 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 28be9627a..2ec008558 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 tile) { + tileRequest = monitor->monitorTile([callback, this](std::exception_ptr err, + std::unique_ptr 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.