[core] Use Actors for CustomTileLoader invocation from bindings.
This commit is contained in:
@@ -5,12 +5,13 @@
|
||||
#include <mbgl/util/geojson.hpp>
|
||||
#include <mbgl/util/range.hpp>
|
||||
#include <mbgl/util/constants.hpp>
|
||||
#include <mbgl/actor/mailbox.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class OverscaledTileID;
|
||||
class CanonicalTileID;
|
||||
template <class T>
|
||||
class Actor;
|
||||
|
||||
namespace style {
|
||||
|
||||
@@ -43,8 +44,7 @@ public:
|
||||
class Impl;
|
||||
const Impl& impl() const;
|
||||
private:
|
||||
std::shared_ptr<Mailbox> mailbox;
|
||||
std::unique_ptr<CustomTileLoader> loader;
|
||||
std::unique_ptr<Actor<CustomTileLoader>> loader;
|
||||
};
|
||||
|
||||
template <>
|
||||
|
||||
@@ -9,7 +9,6 @@ CustomTileLoader::CustomTileLoader(const TileFunction& fetchTileFn, const TileFu
|
||||
}
|
||||
|
||||
void CustomTileLoader::fetchTile(const OverscaledTileID& tileID, ActorRef<SetTileDataFunction> callbackRef) {
|
||||
std::lock_guard<std::mutex> lock(dataCacheMutex);
|
||||
auto cachedTileData = dataCache.find(tileID.canonical);
|
||||
if (cachedTileData != dataCache.end()) {
|
||||
callbackRef.invoke(&SetTileDataFunction::operator(), *(cachedTileData->second));
|
||||
@@ -49,14 +48,12 @@ void CustomTileLoader::removeTile(const OverscaledTileID& tileID) {
|
||||
}
|
||||
}
|
||||
if (tileCallbacks->second.size() == 0) {
|
||||
std::lock_guard<std::mutex> lock(dataCacheMutex);
|
||||
tileCallbackMap.erase(tileCallbacks);
|
||||
dataCache.erase(tileID.canonical);
|
||||
}
|
||||
}
|
||||
|
||||
void CustomTileLoader::setTileData(const CanonicalTileID& tileID, const GeoJSON& data) {
|
||||
std::lock_guard<std::mutex> lock(dataCacheMutex);
|
||||
|
||||
auto iter = tileCallbackMap.find(tileID);
|
||||
if (iter == tileCallbackMap.end()) return;
|
||||
@@ -76,10 +73,7 @@ void CustomTileLoader::invalidateTile(const CanonicalTileID& tileID) {
|
||||
invokeTileCancel(tileID);
|
||||
}
|
||||
tileCallbackMap.erase(tileCallbacks);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(dataCacheMutex);
|
||||
dataCache.erase(tileID);
|
||||
}
|
||||
dataCache.erase(tileID);
|
||||
}
|
||||
|
||||
void CustomTileLoader::invalidateRegion(const LatLngBounds& bounds, Range<uint8_t> ) {
|
||||
@@ -87,7 +81,6 @@ void CustomTileLoader::invalidateRegion(const LatLngBounds& bounds, Range<uint8_
|
||||
const LatLngBounds tileBounds(idtuple->first);
|
||||
if (tileBounds.intersects(bounds) || bounds.contains(tileBounds) || tileBounds.contains(bounds)) {
|
||||
for (auto iter = idtuple->second.begin(); iter != idtuple->second.end(); iter++) {
|
||||
std::lock_guard<std::mutex> lock(dataCacheMutex);
|
||||
auto actor = std::get<2>(*iter);
|
||||
actor.invoke(&SetTileDataFunction::operator(), mapbox::geojson::feature_collection());
|
||||
invokeTileCancel(idtuple->first);
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <mbgl/actor/actor_ref.hpp>
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
@@ -39,7 +38,6 @@ private:
|
||||
std::unordered_map<CanonicalTileID, std::vector<OverscaledIDFunctionTuple>> tileCallbackMap;
|
||||
// Keep around a cache of tile data to serve back for wrapped and over-zooomed tiles
|
||||
std::map<CanonicalTileID, std::unique_ptr<GeoJSON>> dataCache;
|
||||
std::mutex dataCacheMutex;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#include <mbgl/style/sources/custom_geometry_source.hpp>
|
||||
#include <mbgl/style/custom_tile_loader.hpp>
|
||||
#include <mbgl/style/sources/custom_geometry_source_impl.hpp>
|
||||
#include <mbgl/actor/actor.hpp>
|
||||
#include <mbgl/actor/scheduler.hpp>
|
||||
#include <mbgl/tile/tile_id.hpp>
|
||||
|
||||
#include <mbgl/util/shared_thread_pool.hpp>
|
||||
#include <tuple>
|
||||
#include <map>
|
||||
|
||||
@@ -13,8 +14,7 @@ namespace style {
|
||||
CustomGeometrySource::CustomGeometrySource(std::string id,
|
||||
const CustomGeometrySource::Options options)
|
||||
: Source(makeMutable<CustomGeometrySource::Impl>(std::move(id), options)),
|
||||
mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())),
|
||||
loader(std::make_unique<CustomTileLoader>(options.fetchTileFunction, options.cancelTileFunction)) {
|
||||
loader(std::make_unique<Actor<CustomTileLoader>>(*sharedThreadPool(), options.fetchTileFunction, options.cancelTileFunction)) {
|
||||
}
|
||||
|
||||
CustomGeometrySource::~CustomGeometrySource() = default;
|
||||
@@ -24,21 +24,21 @@ const CustomGeometrySource::Impl& CustomGeometrySource::impl() const {
|
||||
}
|
||||
|
||||
void CustomGeometrySource::loadDescription(FileSource&) {
|
||||
baseImpl = makeMutable<CustomGeometrySource::Impl>(impl(), ActorRef<CustomTileLoader>(*loader, mailbox));
|
||||
baseImpl = makeMutable<CustomGeometrySource::Impl>(impl(), loader->self());
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
void CustomGeometrySource::setTileData(const CanonicalTileID& tileID,
|
||||
const GeoJSON& data) {
|
||||
loader->setTileData(tileID, data);
|
||||
loader->invoke(&CustomTileLoader::setTileData, tileID, data);
|
||||
}
|
||||
|
||||
void CustomGeometrySource::invalidateTile(const CanonicalTileID& tileID) {
|
||||
loader->invalidateTile(tileID);
|
||||
loader->invoke(&CustomTileLoader::invalidateTile, tileID);
|
||||
}
|
||||
|
||||
void CustomGeometrySource::invalidateRegion(const LatLngBounds& bounds) {
|
||||
loader->invalidateRegion(bounds, impl().getZoomRange());
|
||||
loader->invoke(&CustomTileLoader::invalidateRegion, bounds, impl().getZoomRange());
|
||||
}
|
||||
|
||||
} // namespace style
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <mbgl/util/image.hpp>
|
||||
|
||||
#include <mbgl/util/tileset.hpp>
|
||||
#include <mbgl/util/default_thread_pool.hpp>
|
||||
#include <mbgl/util/shared_thread_pool.hpp>
|
||||
#include <mbgl/util/logging.hpp>
|
||||
#include <mbgl/util/optional.hpp>
|
||||
#include <mbgl/util/range.hpp>
|
||||
@@ -552,7 +552,7 @@ TEST(Source, ImageSourceImageUpdate) {
|
||||
|
||||
TEST(Source, CustomGeometrySourceSetTileData) {
|
||||
SourceTest test;
|
||||
|
||||
std::shared_ptr<ThreadPool> threadPool = sharedThreadPool();
|
||||
CustomGeometrySource source("source", CustomGeometrySource::Options());
|
||||
source.loadDescription(test.fileSource);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user