[core] [node] pass thread pool impl to Map constructor
Updates mbgl::Map constructor usage everywhere Adds NodeThreadPool implementation using AsyncQueue to call Nan::AsyncQueueWorker from main thread
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/platform/default/headless_display.hpp>
|
||||
#include <mbgl/platform/default/headless_view.hpp>
|
||||
#include <mbgl/platform/default/thread_pool.hpp>
|
||||
#include <mbgl/sprite/sprite_image.hpp>
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
#include <mbgl/storage/network_status.hpp>
|
||||
@@ -37,7 +38,8 @@ public:
|
||||
std::shared_ptr<HeadlessDisplay> display{ std::make_shared<HeadlessDisplay>() };
|
||||
HeadlessView view{ display, 1 };
|
||||
DefaultFileSource fileSource{ "benchmark/fixtures/api/cache.db", "." };
|
||||
Map map{ view, fileSource, MapMode::Still };
|
||||
ThreadPool threadPool{ 4 };
|
||||
Map map{ view, fileSource, threadPool, MapMode::Still };
|
||||
ScreenBox box{{ 0, 0 }, { 1000, 1000 }};
|
||||
};
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <mbgl/platform/platform.hpp>
|
||||
#include <mbgl/platform/default/settings_json.hpp>
|
||||
#include <mbgl/platform/default/glfw_view.hpp>
|
||||
#include <mbgl/platform/default/thread_pool.hpp>
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
|
||||
#include <signal.h>
|
||||
@@ -115,7 +116,9 @@ int main(int argc, char *argv[]) {
|
||||
fileSource.setAccessToken(std::string(token));
|
||||
}
|
||||
|
||||
mbgl::Map map(*view, fileSource);
|
||||
mbgl::ThreadPool threadPool(4);
|
||||
|
||||
mbgl::Map map(*view, fileSource, threadPool);
|
||||
|
||||
// Load settings
|
||||
mbgl::Settings_JSON settings;
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
#include <mbgl/util/io.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
|
||||
#include <mbgl/platform/default/headless_view.hpp>
|
||||
#include <mbgl/platform/default/headless_display.hpp>
|
||||
#include <mbgl/platform/default/headless_view.hpp>
|
||||
#include <mbgl/platform/default/thread_pool.hpp>
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
@@ -84,7 +85,8 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
HeadlessView view(pixelRatio, width, height);
|
||||
Map map(view, fileSource, MapMode::Still);
|
||||
ThreadPool threadPool(4);
|
||||
Map map(view, fileSource, threadPool, MapMode::Still);
|
||||
|
||||
map.setStyleJSON(style);
|
||||
map.setClasses(classes);
|
||||
|
||||
@@ -8,8 +8,6 @@ set(MBGL_CORE_FILES
|
||||
src/mbgl/actor/mailbox.hpp
|
||||
src/mbgl/actor/message.hpp
|
||||
src/mbgl/actor/scheduler.hpp
|
||||
src/mbgl/actor/thread_pool.cpp
|
||||
src/mbgl/actor/thread_pool.hpp
|
||||
|
||||
# algorithm
|
||||
src/mbgl/algorithm/covered_by_children.hpp
|
||||
|
||||
@@ -11,6 +11,8 @@ target_sources(mbgl-node
|
||||
PRIVATE platform/node/src/node_request.cpp
|
||||
PRIVATE platform/node/src/node_feature.hpp
|
||||
PRIVATE platform/node/src/node_feature.cpp
|
||||
PRIVATE platform/node/src/node_thread_pool.hpp
|
||||
PRIVATE platform/node/src/node_thread_pool.cpp
|
||||
PRIVATE platform/node/src/util/async_queue.hpp
|
||||
|
||||
# We are compiling with the uv loop, but since this target already has the headers for libuv,
|
||||
|
||||
@@ -89,9 +89,9 @@ set(MBGL_TEST_FILES
|
||||
# tile
|
||||
test/tile/geometry_tile_data.test.cpp
|
||||
test/tile/raster_tile.test.cpp
|
||||
test/tile/tile_coordinate.test.cpp
|
||||
test/tile/tile_id.test.cpp
|
||||
test/tile/vector_tile.test.cpp
|
||||
test/tile/tile_coordinate.test.cpp
|
||||
|
||||
# util
|
||||
test/util/async_task.test.cpp
|
||||
|
||||
@@ -19,8 +19,9 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class FileSource;
|
||||
class View;
|
||||
class FileSource;
|
||||
class Scheduler;
|
||||
class SpriteImage;
|
||||
struct CameraOptions;
|
||||
struct AnimationOptions;
|
||||
@@ -32,7 +33,7 @@ class Layer;
|
||||
|
||||
class Map : private util::noncopyable {
|
||||
public:
|
||||
explicit Map(View&, FileSource&,
|
||||
explicit Map(View&, FileSource&, Scheduler&,
|
||||
MapMode mapMode = MapMode::Continuous,
|
||||
GLContextMode contextMode = GLContextMode::Unique,
|
||||
ConstrainMode constrainMode = ConstrainMode::HeightOnly,
|
||||
|
||||
@@ -48,6 +48,9 @@ macro(mbgl_platform_core)
|
||||
|
||||
# Headless view
|
||||
# TODO
|
||||
|
||||
# Thread pool
|
||||
PRIVATE platform/default/thread_pool.cpp
|
||||
)
|
||||
|
||||
target_include_directories(mbgl-core
|
||||
|
||||
@@ -60,7 +60,8 @@ NativeMapView::NativeMapView(JNIEnv *env_, jobject obj_, float pixelRatio_, int
|
||||
env(env_),
|
||||
pixelRatio(pixelRatio_),
|
||||
availableProcessors(availableProcessors_),
|
||||
totalMemory(totalMemory_) {
|
||||
totalMemory(totalMemory_),
|
||||
threadPool(4) {
|
||||
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::NativeMapView");
|
||||
|
||||
assert(env_ != nullptr);
|
||||
@@ -81,7 +82,7 @@ NativeMapView::NativeMapView(JNIEnv *env_, jobject obj_, float pixelRatio_, int
|
||||
mbgl::android::cachePath + "/mbgl-offline.db",
|
||||
mbgl::android::apkPath);
|
||||
|
||||
map = std::make_unique<mbgl::Map>(*this, *fileSource, MapMode::Continuous);
|
||||
map = std::make_unique<mbgl::Map>(*this, *fileSource, threadPool, MapMode::Continuous);
|
||||
|
||||
float zoomFactor = map->getMaxZoom() - map->getMinZoom() + 1;
|
||||
float cpuFactor = availableProcessors;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/map/view.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/platform/default/thread_pool.hpp>
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
|
||||
#include <string>
|
||||
@@ -95,6 +96,7 @@ private:
|
||||
|
||||
// Ensure these are initialised last
|
||||
std::unique_ptr<mbgl::DefaultFileSource> fileSource;
|
||||
mbgl::ThreadPool threadPool;
|
||||
std::unique_ptr<mbgl::Map> map;
|
||||
mbgl::EdgeInsets insets;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <mbgl/actor/thread_pool.hpp>
|
||||
#include <mbgl/platform/default/thread_pool.hpp>
|
||||
#include <mbgl/actor/mailbox.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
@@ -40,6 +40,9 @@ macro(mbgl_platform_core)
|
||||
PRIVATE platform/darwin/src/headless_view_eagl.mm
|
||||
PRIVATE platform/default/headless_display.cpp
|
||||
PRIVATE platform/default/headless_view.cpp
|
||||
|
||||
# Thread pool
|
||||
PRIVATE platform/default/thread_pool.cpp
|
||||
)
|
||||
|
||||
target_add_mason_package(mbgl-core PUBLIC geojson)
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <mbgl/map/mode.hpp>
|
||||
#include <mbgl/platform/platform.hpp>
|
||||
#include <mbgl/platform/darwin/reachability.h>
|
||||
#include <mbgl/platform/default/thread_pool.hpp>
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
#include <mbgl/storage/network_status.hpp>
|
||||
#include <mbgl/style/transition_options.hpp>
|
||||
@@ -258,6 +259,7 @@ public:
|
||||
{
|
||||
mbgl::Map *_mbglMap;
|
||||
MBGLView *_mbglView;
|
||||
mbgl::ThreadPool *_mbglThreadPool;
|
||||
|
||||
BOOL _opaque;
|
||||
|
||||
@@ -397,7 +399,8 @@ public:
|
||||
|
||||
// setup mbgl map
|
||||
mbgl::DefaultFileSource *mbglFileSource = [MGLOfflineStorage sharedOfflineStorage].mbglFileSource;
|
||||
_mbglMap = new mbgl::Map(*_mbglView, *mbglFileSource, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None, mbgl::ViewportMode::Default);
|
||||
_mbglThreadPool = new mbgl::ThreadPool(4);
|
||||
_mbglMap = new mbgl::Map(*_mbglView, *mbglFileSource, *_mbglThreadPool, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None, mbgl::ViewportMode::Default);
|
||||
[self validateTileCacheSize];
|
||||
|
||||
// start paused if in IB
|
||||
@@ -650,6 +653,12 @@ public:
|
||||
_mbglView = nullptr;
|
||||
}
|
||||
|
||||
if (_mbglThreadPool)
|
||||
{
|
||||
delete _mbglThreadPool;
|
||||
_mbglThreadPool = nullptr;
|
||||
}
|
||||
|
||||
if ([[EAGLContext currentContext] isEqual:_context])
|
||||
{
|
||||
[EAGLContext setCurrentContext:nil];
|
||||
|
||||
@@ -44,6 +44,9 @@ macro(mbgl_platform_core)
|
||||
PRIVATE platform/default/headless_display.cpp
|
||||
PRIVATE platform/default/headless_view.cpp
|
||||
PRIVATE platform/default/headless_view_glx.cpp
|
||||
|
||||
# Thread pool
|
||||
PRIVATE platform/default/thread_pool.cpp
|
||||
)
|
||||
|
||||
target_include_directories(mbgl-core
|
||||
|
||||
@@ -38,6 +38,9 @@ macro(mbgl_platform_core)
|
||||
PRIVATE platform/darwin/src/headless_view_cgl.cpp
|
||||
PRIVATE platform/default/headless_display.cpp
|
||||
PRIVATE platform/default/headless_view.cpp
|
||||
|
||||
# Thread pool
|
||||
PRIVATE platform/default/thread_pool.cpp
|
||||
)
|
||||
|
||||
target_add_mason_package(mbgl-core PUBLIC geojson)
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#import <mbgl/annotation/annotation.hpp>
|
||||
#import <mbgl/map/camera.hpp>
|
||||
#import <mbgl/platform/darwin/reachability.h>
|
||||
#import <mbgl/platform/default/thread_pool.hpp>
|
||||
#import <mbgl/gl/extension.hpp>
|
||||
#import <mbgl/gl/gl.hpp>
|
||||
#import <mbgl/sprite/sprite_image.hpp>
|
||||
@@ -158,6 +159,7 @@ public:
|
||||
/// Cross-platform map view controller.
|
||||
mbgl::Map *_mbglMap;
|
||||
MGLMapViewImpl *_mbglView;
|
||||
mbgl::ThreadPool *_mbglThreadPool;
|
||||
|
||||
NSPanGestureRecognizer *_panGestureRecognizer;
|
||||
NSMagnificationGestureRecognizer *_magnificationGestureRecognizer;
|
||||
@@ -261,7 +263,8 @@ public:
|
||||
[[NSFileManager defaultManager] removeItemAtURL:legacyCacheURL error:NULL];
|
||||
|
||||
mbgl::DefaultFileSource *mbglFileSource = [MGLOfflineStorage sharedOfflineStorage].mbglFileSource;
|
||||
_mbglMap = new mbgl::Map(*_mbglView, *mbglFileSource, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None, mbgl::ViewportMode::Default);
|
||||
_mbglThreadPool = new mbgl::ThreadPool(4);
|
||||
_mbglMap = new mbgl::Map(*_mbglView, *mbglFileSource, *_mbglThreadPool, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None, mbgl::ViewportMode::Default);
|
||||
[self validateTileCacheSize];
|
||||
|
||||
// Install the OpenGL layer. Interface Builder’s synchronous drawing means
|
||||
@@ -466,6 +469,10 @@ public:
|
||||
delete _mbglView;
|
||||
_mbglView = nullptr;
|
||||
}
|
||||
if (_mbglThreadPool) {
|
||||
delete _mbglThreadPool;
|
||||
_mbglThreadPool = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(__unused NSDictionary *)change context:(void *)context {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "node_log.hpp"
|
||||
#include "util/async_queue.hpp"
|
||||
|
||||
#include <mbgl/util/enum.hpp>
|
||||
|
||||
@@ -19,7 +18,7 @@ struct NodeLogObserver::LogMessage {
|
||||
};
|
||||
|
||||
NodeLogObserver::NodeLogObserver(v8::Local<v8::Object> target)
|
||||
: queue(new Queue(uv_default_loop(), [this](LogMessage &message) {
|
||||
: queue(new util::AsyncQueue<LogMessage>(uv_default_loop(), [this](LogMessage &message) {
|
||||
Nan::HandleScope scope;
|
||||
|
||||
auto msg = Nan::New<v8::Object>();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "util/async_queue.hpp"
|
||||
|
||||
#include <mbgl/platform/log.hpp>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
@@ -24,8 +26,7 @@ private:
|
||||
Nan::Persistent<v8::Object> module;
|
||||
|
||||
struct LogMessage;
|
||||
using Queue = util::AsyncQueue<LogMessage>;
|
||||
Queue *queue = nullptr;
|
||||
util::AsyncQueue<LogMessage>* queue;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -777,7 +777,8 @@ NodeMap::NodeMap(v8::Local<v8::Object> options) :
|
||||
Nan::HandleScope scope;
|
||||
return Nan::Has(options, Nan::New("ratio").ToLocalChecked()).FromJust() ? Nan::Get(options, Nan::New("ratio").ToLocalChecked()).ToLocalChecked()->NumberValue() : 1.0;
|
||||
}()),
|
||||
map(std::make_unique<mbgl::Map>(view, *this, mbgl::MapMode::Still)),
|
||||
threadpool(),
|
||||
map(std::make_unique<mbgl::Map>(view, *this, threadpool, mbgl::MapMode::Still)),
|
||||
async(new uv_async_t) {
|
||||
|
||||
view.setMapChangeCallback([&](mbgl::MapChange change) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "node_thread_pool.hpp"
|
||||
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/storage/file_source.hpp>
|
||||
#include <mbgl/platform/default/headless_view.hpp>
|
||||
@@ -52,6 +54,7 @@ public:
|
||||
std::unique_ptr<mbgl::AsyncRequest> request(const mbgl::Resource&, mbgl::FileSource::Callback);
|
||||
|
||||
mbgl::HeadlessView view;
|
||||
NodeThreadPool threadpool;
|
||||
std::unique_ptr<mbgl::Map> map;
|
||||
|
||||
std::exception_ptr error;
|
||||
|
||||
39
platform/node/src/node_thread_pool.cpp
Normal file
39
platform/node/src/node_thread_pool.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "node_thread_pool.hpp"
|
||||
#include "util/async_queue.hpp"
|
||||
|
||||
#include <mbgl/actor/mailbox.hpp>
|
||||
|
||||
namespace node_mbgl {
|
||||
|
||||
NodeThreadPool::NodeThreadPool()
|
||||
: queue(new util::AsyncQueue<std::weak_ptr<mbgl::Mailbox>>(uv_default_loop(), [this](std::weak_ptr<mbgl::Mailbox> mailbox) {
|
||||
Worker* worker = new Worker(mailbox);
|
||||
Nan::AsyncQueueWorker(worker);
|
||||
})) {
|
||||
// Don't keep the event loop alive.
|
||||
queue->unref();
|
||||
}
|
||||
|
||||
NodeThreadPool::~NodeThreadPool() {
|
||||
queue->stop();
|
||||
}
|
||||
|
||||
void NodeThreadPool::schedule(std::weak_ptr<mbgl::Mailbox> mailbox) {
|
||||
queue->send(std::move(mailbox));
|
||||
}
|
||||
|
||||
NodeThreadPool::Worker::Worker(std::weak_ptr<mbgl::Mailbox> mailbox_)
|
||||
: AsyncWorker(nullptr),
|
||||
mailbox(std::move(mailbox_)) {};
|
||||
|
||||
void NodeThreadPool::Worker::Execute() {
|
||||
if (auto locked = mailbox.lock()) {
|
||||
locked->receive();
|
||||
}
|
||||
}
|
||||
|
||||
void NodeThreadPool::Worker::WorkComplete() {
|
||||
// no-op to avoid calling nullptr callback
|
||||
}
|
||||
|
||||
} // namespace node_mbgl
|
||||
37
platform/node/src/node_thread_pool.hpp
Normal file
37
platform/node/src/node_thread_pool.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/actor/scheduler.hpp>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
#pragma GCC diagnostic ignored "-Wshadow"
|
||||
#include <nan.h>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
namespace node_mbgl {
|
||||
|
||||
namespace util { template <typename T> class AsyncQueue; }
|
||||
|
||||
class NodeThreadPool : public mbgl::Scheduler {
|
||||
public:
|
||||
NodeThreadPool();
|
||||
~NodeThreadPool();
|
||||
|
||||
void schedule(std::weak_ptr<mbgl::Mailbox>) override;
|
||||
|
||||
private:
|
||||
util::AsyncQueue<std::weak_ptr<mbgl::Mailbox>>* queue;
|
||||
|
||||
class Worker : public Nan::AsyncWorker {
|
||||
public:
|
||||
Worker(std::weak_ptr<mbgl::Mailbox>);
|
||||
|
||||
void Execute();
|
||||
void WorkComplete();
|
||||
|
||||
private:
|
||||
std::weak_ptr<mbgl::Mailbox> mailbox;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace node_mbgl
|
||||
@@ -28,6 +28,7 @@ public:
|
||||
q->process();
|
||||
});
|
||||
}
|
||||
~AsyncQueue() {}
|
||||
|
||||
void send(T &&data) {
|
||||
{
|
||||
@@ -60,9 +61,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
~AsyncQueue() {
|
||||
}
|
||||
|
||||
void process() {
|
||||
std::unique_ptr<T> item;
|
||||
while (true) {
|
||||
|
||||
@@ -30,6 +30,9 @@ set(MBGL_QT_FILES
|
||||
# Misc
|
||||
PRIVATE platform/default/log_stderr.cpp
|
||||
|
||||
# Thread pool
|
||||
PRIVATE platform/default/thread_pool.cpp
|
||||
|
||||
# Platform integration
|
||||
PRIVATE platform/qt/src/async_task.cpp
|
||||
PRIVATE platform/qt/src/async_task_impl.hpp
|
||||
|
||||
@@ -811,8 +811,9 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin
|
||||
settings.cacheDatabasePath().toStdString(),
|
||||
settings.assetPath().toStdString(),
|
||||
settings.cacheDatabaseMaximumSize()))
|
||||
, threadPool(4)
|
||||
, mapObj(std::make_unique<mbgl::Map>(
|
||||
*this, *fileSourceObj,
|
||||
*this, *fileSourceObj, threadPool,
|
||||
static_cast<mbgl::MapMode>(settings.mapMode()),
|
||||
static_cast<mbgl::GLContextMode>(settings.contextMode()),
|
||||
static_cast<mbgl::ConstrainMode>(settings.constrainMode()),
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/map/view.hpp>
|
||||
#include <mbgl/platform/default/thread_pool.hpp>
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
#include <mbgl/util/geo.hpp>
|
||||
|
||||
@@ -34,6 +35,7 @@ public:
|
||||
QMapboxGL *q_ptr { nullptr };
|
||||
|
||||
std::unique_ptr<mbgl::DefaultFileSource> fileSourceObj;
|
||||
mbgl::ThreadPool threadPool;
|
||||
std::unique_ptr<mbgl::Map> mapObj;
|
||||
|
||||
bool dirty { false };
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <mbgl/util/async_task.hpp>
|
||||
#include <mbgl/util/mapbox.hpp>
|
||||
#include <mbgl/util/tile_coordinate.hpp>
|
||||
#include <mbgl/actor/thread_pool.hpp>
|
||||
#include <mbgl/actor/scheduler.hpp>
|
||||
#include <mbgl/platform/log.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
@@ -36,7 +36,7 @@ enum class RenderState : uint8_t {
|
||||
|
||||
class Map::Impl : public style::Observer {
|
||||
public:
|
||||
Impl(View&, FileSource&, MapMode, GLContextMode, ConstrainMode, ViewportMode);
|
||||
Impl(View&, FileSource&, Scheduler&, MapMode, GLContextMode, ConstrainMode, ViewportMode);
|
||||
|
||||
void onSourceAttributionChanged(style::Source&, const std::string&) override;
|
||||
void onUpdate(Update) override;
|
||||
@@ -51,6 +51,7 @@ public:
|
||||
|
||||
View& view;
|
||||
FileSource& fileSource;
|
||||
Scheduler& scheduler;
|
||||
|
||||
RenderState renderState = RenderState::Never;
|
||||
Transform transform;
|
||||
@@ -63,7 +64,6 @@ public:
|
||||
|
||||
Update updateFlags = Update::Nothing;
|
||||
util::AsyncTask asyncUpdate;
|
||||
ThreadPool workerThreadPool;
|
||||
|
||||
std::unique_ptr<AnnotationManager> annotationManager;
|
||||
std::unique_ptr<Painter> painter;
|
||||
@@ -81,20 +81,22 @@ public:
|
||||
bool loading = false;
|
||||
};
|
||||
|
||||
Map::Map(View& view, FileSource& fileSource, MapMode mapMode, GLContextMode contextMode, ConstrainMode constrainMode, ViewportMode viewportMode)
|
||||
: impl(std::make_unique<Impl>(view, fileSource, mapMode, contextMode, constrainMode, viewportMode)) {
|
||||
Map::Map(View& view, FileSource& fileSource, Scheduler& scheduler, MapMode mapMode, GLContextMode contextMode, ConstrainMode constrainMode, ViewportMode viewportMode)
|
||||
: impl(std::make_unique<Impl>(view, fileSource, scheduler, mapMode, contextMode, constrainMode, viewportMode)) {
|
||||
view.initialize(this);
|
||||
update(Update::Dimensions);
|
||||
}
|
||||
|
||||
Map::Impl::Impl(View& view_,
|
||||
FileSource& fileSource_,
|
||||
Scheduler& scheduler_,
|
||||
MapMode mode_,
|
||||
GLContextMode contextMode_,
|
||||
ConstrainMode constrainMode_,
|
||||
ViewportMode viewportMode_)
|
||||
: view(view_),
|
||||
fileSource(fileSource_),
|
||||
scheduler(scheduler_),
|
||||
transform([this](MapChange change) { view.notifyMapChange(change); },
|
||||
constrainMode_,
|
||||
viewportMode_),
|
||||
@@ -102,7 +104,6 @@ Map::Impl::Impl(View& view_,
|
||||
contextMode(contextMode_),
|
||||
pixelRatio(view.getPixelRatio()),
|
||||
asyncUpdate([this] { update(); }),
|
||||
workerThreadPool(4),
|
||||
annotationManager(std::make_unique<AnnotationManager>(pixelRatio)) {
|
||||
}
|
||||
|
||||
@@ -230,7 +231,7 @@ void Map::Impl::update() {
|
||||
style::UpdateParameters parameters(pixelRatio,
|
||||
debugOptions,
|
||||
transform.getState(),
|
||||
workerThreadPool,
|
||||
scheduler,
|
||||
fileSource,
|
||||
mode,
|
||||
*annotationManager,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <mbgl/actor/actor.hpp>
|
||||
#include <mbgl/actor/thread_pool.hpp>
|
||||
#include <mbgl/platform/default/thread_pool.hpp>
|
||||
|
||||
#include <mbgl/test/util.hpp>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <mbgl/actor/actor.hpp>
|
||||
#include <mbgl/actor/thread_pool.hpp>
|
||||
#include <mbgl/platform/default/thread_pool.hpp>
|
||||
|
||||
#include <mbgl/test/util.hpp>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <mbgl/test/util.hpp>
|
||||
#include <mbgl/test/stub_file_source.hpp>
|
||||
|
||||
#include <mbgl/platform/default/thread_pool.hpp>
|
||||
#include <mbgl/annotation/annotation.hpp>
|
||||
#include <mbgl/sprite/sprite_image.hpp>
|
||||
#include <mbgl/map/map.hpp>
|
||||
@@ -25,7 +26,8 @@ public:
|
||||
std::shared_ptr<HeadlessDisplay> display { std::make_shared<HeadlessDisplay>() };
|
||||
HeadlessView view { display, 1 };
|
||||
StubFileSource fileSource;
|
||||
Map map { view, fileSource, MapMode::Still };
|
||||
ThreadPool threadPool { 4 };
|
||||
Map map { view, fileSource, threadPool, MapMode::Still };
|
||||
|
||||
void checkRendering(const char * name) {
|
||||
test::checkImage(std::string("test/fixtures/annotations/") + name,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/platform/default/headless_display.hpp>
|
||||
#include <mbgl/storage/online_file_source.hpp>
|
||||
#include <mbgl/platform/default/thread_pool.hpp>
|
||||
#include <mbgl/util/exception.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
|
||||
@@ -22,8 +23,9 @@ TEST(API, RenderWithoutCallback) {
|
||||
HeadlessView view(display, 1);
|
||||
view.resize(128, 512);
|
||||
StubFileSource fileSource;
|
||||
ThreadPool threadPool(4);
|
||||
|
||||
std::unique_ptr<Map> map = std::make_unique<Map>(view, fileSource, MapMode::Still);
|
||||
std::unique_ptr<Map> map = std::make_unique<Map>(view, fileSource, threadPool, MapMode::Still);
|
||||
map->renderStill(nullptr);
|
||||
|
||||
// Force Map thread to join.
|
||||
@@ -46,8 +48,9 @@ TEST(API, RenderWithoutStyle) {
|
||||
HeadlessView view(display, 1);
|
||||
view.resize(128, 512);
|
||||
StubFileSource fileSource;
|
||||
ThreadPool threadPool(4);
|
||||
|
||||
Map map(view, fileSource, MapMode::Still);
|
||||
Map map(view, fileSource, threadPool, MapMode::Still);
|
||||
|
||||
std::exception_ptr error;
|
||||
map.renderStill([&](std::exception_ptr error_, PremultipliedImage&&) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/platform/default/headless_display.hpp>
|
||||
#include <mbgl/platform/default/headless_view.hpp>
|
||||
#include <mbgl/platform/default/thread_pool.hpp>
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
#include <mbgl/style/layers/custom_layer.hpp>
|
||||
#include <mbgl/style/layers/fill_layer.hpp>
|
||||
@@ -94,7 +95,9 @@ TEST(CustomLayer, Basic) {
|
||||
DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets");
|
||||
#endif
|
||||
|
||||
Map map(view, fileSource, MapMode::Still);
|
||||
ThreadPool threadPool(4);
|
||||
|
||||
Map map(view, fileSource, threadPool, MapMode::Still);
|
||||
map.setStyleJSON(util::read_file("test/fixtures/api/water.json"));
|
||||
map.setLatLngZoom({ 37.8, -122.5 }, 10);
|
||||
map.addLayer(std::make_unique<CustomLayer>(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/platform/default/headless_display.hpp>
|
||||
#include <mbgl/platform/default/headless_view.hpp>
|
||||
#include <mbgl/platform/default/thread_pool.hpp>
|
||||
#include <mbgl/sprite/sprite_image.hpp>
|
||||
#include <mbgl/test/stub_file_source.hpp>
|
||||
#include <mbgl/test/util.hpp>
|
||||
@@ -28,7 +29,8 @@ public:
|
||||
std::shared_ptr<HeadlessDisplay> display { std::make_shared<HeadlessDisplay>() };
|
||||
HeadlessView view { display, 1 };
|
||||
StubFileSource fileSource;
|
||||
Map map { view, fileSource, MapMode::Still };
|
||||
ThreadPool threadPool { 4 };
|
||||
Map map { view, fileSource, threadPool, MapMode::Still };
|
||||
};
|
||||
|
||||
} // end namespace
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
#include <mbgl/test/fixture_log_observer.hpp>
|
||||
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/platform/default/headless_view.hpp>
|
||||
#include <mbgl/platform/default/headless_display.hpp>
|
||||
#include <mbgl/platform/default/headless_view.hpp>
|
||||
#include <mbgl/platform/default/thread_pool.hpp>
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
#include <mbgl/util/image.hpp>
|
||||
#include <mbgl/util/io.hpp>
|
||||
@@ -33,9 +34,11 @@ TEST(API, TEST_REQUIRES_SERVER(RenderMissingTile)) {
|
||||
DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets");
|
||||
#endif
|
||||
|
||||
ThreadPool threadPool(4);
|
||||
|
||||
Log::setObserver(std::make_unique<FixtureLogObserver>());
|
||||
|
||||
Map map(view, fileSource, MapMode::Still);
|
||||
Map map(view, fileSource, threadPool, MapMode::Still);
|
||||
|
||||
std::string message;
|
||||
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
#include <mbgl/test/fixture_log_observer.hpp>
|
||||
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/platform/default/headless_view.hpp>
|
||||
#include <mbgl/platform/default/headless_display.hpp>
|
||||
#include <mbgl/platform/default/headless_view.hpp>
|
||||
#include <mbgl/platform/default/thread_pool.hpp>
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
#include <mbgl/util/image.hpp>
|
||||
#include <mbgl/util/io.hpp>
|
||||
@@ -20,6 +21,7 @@ TEST(API, RepeatedRender) {
|
||||
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
HeadlessView view(display, 1, 256, 512);
|
||||
|
||||
#ifdef MBGL_ASSET_ZIP
|
||||
// Regenerate with `cd test/fixtures/api/ && zip -r assets.zip assets/`
|
||||
DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets.zip");
|
||||
@@ -27,9 +29,11 @@ TEST(API, RepeatedRender) {
|
||||
DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets");
|
||||
#endif
|
||||
|
||||
ThreadPool threadPool(4);
|
||||
|
||||
Log::setObserver(std::make_unique<FixtureLogObserver>());
|
||||
|
||||
Map map(view, fileSource, MapMode::Still);
|
||||
Map map(view, fileSource, threadPool, MapMode::Still);
|
||||
|
||||
{
|
||||
map.setStyleJSON(style);
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
#include <mbgl/test/fixture_log_observer.hpp>
|
||||
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/platform/default/headless_view.hpp>
|
||||
#include <mbgl/platform/default/headless_display.hpp>
|
||||
#include <mbgl/platform/default/headless_view.hpp>
|
||||
#include <mbgl/platform/default/thread_pool.hpp>
|
||||
#include <mbgl/sprite/sprite_image.hpp>
|
||||
#include <mbgl/storage/network_status.hpp>
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
@@ -24,11 +25,12 @@ struct MapTest {
|
||||
std::shared_ptr<HeadlessDisplay> display { std::make_shared<mbgl::HeadlessDisplay>() };
|
||||
HeadlessView view { display, 1 };
|
||||
StubFileSource fileSource;
|
||||
ThreadPool threadPool { 4 };
|
||||
};
|
||||
|
||||
TEST(Map, LatLngBehavior) {
|
||||
MapTest test;
|
||||
Map map(test.view, test.fileSource, MapMode::Still);
|
||||
Map map(test.view, test.fileSource, test.threadPool, MapMode::Still);
|
||||
|
||||
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
|
||||
@@ -62,7 +64,7 @@ TEST(Map, Offline) {
|
||||
fileSource.put(Resource::glyphs(prefix + "{fontstack}/{range}.pbf", {{"Helvetica"}}, {0, 255}), expiredItem("glyph.pbf"));
|
||||
NetworkStatus::Set(NetworkStatus::Status::Offline);
|
||||
|
||||
Map map(test.view, fileSource, MapMode::Still);
|
||||
Map map(test.view, fileSource, test.threadPool, MapMode::Still);
|
||||
map.setStyleURL(prefix + "style.json");
|
||||
|
||||
test::checkImage("test/fixtures/map/offline",
|
||||
@@ -86,7 +88,7 @@ TEST(Map, SetStyleInvalidJSON) {
|
||||
});
|
||||
|
||||
{
|
||||
Map map(test.view, test.fileSource, MapMode::Still);
|
||||
Map map(test.view, test.fileSource, test.threadPool, MapMode::Still);
|
||||
map.setStyleJSON("invalid");
|
||||
}
|
||||
|
||||
@@ -117,7 +119,7 @@ TEST(Map, SetStyleInvalidURL) {
|
||||
}
|
||||
});
|
||||
|
||||
Map map(test.view, test.fileSource, MapMode::Still);
|
||||
Map map(test.view, test.fileSource, test.threadPool, MapMode::Still);
|
||||
map.setStyleURL("mapbox://bar");
|
||||
|
||||
test.runLoop.run();
|
||||
@@ -126,7 +128,7 @@ TEST(Map, SetStyleInvalidURL) {
|
||||
TEST(Map, DoubleStyleLoad) {
|
||||
MapTest test;
|
||||
|
||||
Map map(test.view, test.fileSource, MapMode::Still);
|
||||
Map map(test.view, test.fileSource, test.threadPool, MapMode::Still);
|
||||
map.setStyleJSON("");
|
||||
map.setStyleJSON("");
|
||||
}
|
||||
@@ -137,7 +139,7 @@ TEST(Map, StyleFresh) {
|
||||
MapTest test;
|
||||
FakeFileSource fileSource;
|
||||
|
||||
Map map(test.view, fileSource, MapMode::Still);
|
||||
Map map(test.view, fileSource, test.threadPool, MapMode::Still);
|
||||
map.setStyleURL("mapbox://styles/test");
|
||||
EXPECT_EQ(1u, fileSource.requests.size());
|
||||
|
||||
@@ -157,7 +159,7 @@ TEST(Map, StyleExpired) {
|
||||
MapTest test;
|
||||
FakeFileSource fileSource;
|
||||
|
||||
Map map(test.view, fileSource, MapMode::Still);
|
||||
Map map(test.view, fileSource, test.threadPool, MapMode::Still);
|
||||
map.setStyleURL("mapbox://styles/test");
|
||||
EXPECT_EQ(1u, fileSource.requests.size());
|
||||
|
||||
@@ -184,7 +186,7 @@ TEST(Map, StyleExpiredWithAnnotations) {
|
||||
MapTest test;
|
||||
FakeFileSource fileSource;
|
||||
|
||||
Map map(test.view, fileSource, MapMode::Still);
|
||||
Map map(test.view, fileSource, test.threadPool, MapMode::Still);
|
||||
map.setStyleURL("mapbox://styles/test");
|
||||
EXPECT_EQ(1u, fileSource.requests.size());
|
||||
|
||||
@@ -208,7 +210,7 @@ TEST(Map, StyleEarlyMutation) {
|
||||
MapTest test;
|
||||
FakeFileSource fileSource;
|
||||
|
||||
Map map(test.view, fileSource, MapMode::Still);
|
||||
Map map(test.view, fileSource, test.threadPool, MapMode::Still);
|
||||
map.setStyleURL("mapbox://styles/test");
|
||||
map.addLayer(std::make_unique<style::BackgroundLayer>("bg"));
|
||||
|
||||
@@ -222,7 +224,7 @@ TEST(Map, StyleEarlyMutation) {
|
||||
|
||||
TEST(Map, StyleLoadedSignal) {
|
||||
MapTest test;
|
||||
Map map(test.view, test.fileSource, MapMode::Still);
|
||||
Map map(test.view, test.fileSource, test.threadPool, MapMode::Still);
|
||||
|
||||
// The map should emit a signal on style loaded
|
||||
bool emitted = false;
|
||||
@@ -243,7 +245,7 @@ TEST(Map, StyleLoadedSignal) {
|
||||
TEST(Map, AddLayer) {
|
||||
MapTest test;
|
||||
|
||||
Map map(test.view, test.fileSource, MapMode::Still);
|
||||
Map map(test.view, test.fileSource, test.threadPool, MapMode::Still);
|
||||
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
|
||||
auto layer = std::make_unique<BackgroundLayer>("background");
|
||||
@@ -256,7 +258,7 @@ TEST(Map, AddLayer) {
|
||||
TEST(Map, RemoveLayer) {
|
||||
MapTest test;
|
||||
|
||||
Map map(test.view, test.fileSource, MapMode::Still);
|
||||
Map map(test.view, test.fileSource, test.threadPool, MapMode::Still);
|
||||
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
|
||||
auto layer = std::make_unique<BackgroundLayer>("background");
|
||||
@@ -281,7 +283,7 @@ TEST(Map, DisabledSources) {
|
||||
return {};
|
||||
};
|
||||
|
||||
Map map(test.view, test.fileSource, MapMode::Still);
|
||||
Map map(test.view, test.fileSource, test.threadPool, MapMode::Still);
|
||||
map.setZoom(1);
|
||||
|
||||
// This stylesheet has two raster layers, one that starts at zoom 1, the other at zoom 0.
|
||||
@@ -331,7 +333,7 @@ TEST(Map, DisabledSources) {
|
||||
TEST(Map, Classes) {
|
||||
MapTest test;
|
||||
|
||||
Map map(test.view, test.fileSource, MapMode::Still);
|
||||
Map map(test.view, test.fileSource, test.threadPool, MapMode::Still);
|
||||
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
|
||||
EXPECT_FALSE(map.getTransitionOptions().duration);
|
||||
@@ -365,7 +367,7 @@ TEST(Map, Classes) {
|
||||
TEST(Map, AddImage) {
|
||||
MapTest test;
|
||||
|
||||
Map map(test.view, test.fileSource, MapMode::Still);
|
||||
Map map(test.view, test.fileSource, test.threadPool, MapMode::Still);
|
||||
auto decoded1 = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png"));
|
||||
auto decoded2 = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png"));
|
||||
auto image1 = std::make_unique<SpriteImage>(std::move(decoded1), 1.0);
|
||||
@@ -382,7 +384,7 @@ TEST(Map, AddImage) {
|
||||
TEST(Map, RemoveImage) {
|
||||
MapTest test;
|
||||
|
||||
Map map(test.view, test.fileSource, MapMode::Still);
|
||||
Map map(test.view, test.fileSource, test.threadPool, MapMode::Still);
|
||||
auto decoded = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png"));
|
||||
auto image = std::make_unique<SpriteImage>(std::move(decoded), 1.0);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <mbgl/util/string.hpp>
|
||||
#include <mbgl/util/io.hpp>
|
||||
#include <mbgl/util/tileset.hpp>
|
||||
#include <mbgl/actor/thread_pool.hpp>
|
||||
#include <mbgl/platform/default/thread_pool.hpp>
|
||||
#include <mbgl/platform/log.hpp>
|
||||
|
||||
#include <mbgl/map/transform.hpp>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <mbgl/tile/raster_tile.hpp>
|
||||
#include <mbgl/tile/tile_loader_impl.hpp>
|
||||
|
||||
#include <mbgl/actor/thread_pool.hpp>
|
||||
#include <mbgl/platform/default/thread_pool.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
#include <mbgl/map/transform.hpp>
|
||||
#include <mbgl/style/style.hpp>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <mbgl/tile/vector_tile.hpp>
|
||||
#include <mbgl/tile/tile_loader_impl.hpp>
|
||||
|
||||
#include <mbgl/actor/thread_pool.hpp>
|
||||
#include <mbgl/platform/default/thread_pool.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
#include <mbgl/map/transform.hpp>
|
||||
#include <mbgl/style/style.hpp>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/platform/default/headless_display.hpp>
|
||||
#include <mbgl/platform/default/headless_view.hpp>
|
||||
#include <mbgl/platform/default/thread_pool.hpp>
|
||||
#include <mbgl/util/io.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
|
||||
@@ -58,6 +59,7 @@ public:
|
||||
std::shared_ptr<HeadlessDisplay> display { std::make_shared<mbgl::HeadlessDisplay>() };
|
||||
HeadlessView view { display, 2 };
|
||||
StubFileSource fileSource;
|
||||
ThreadPool threadPool { 4 };
|
||||
|
||||
private:
|
||||
Response response(const std::string& path) {
|
||||
@@ -91,7 +93,7 @@ private:
|
||||
TEST(Memory, Vector) {
|
||||
MemoryTest test;
|
||||
|
||||
Map map(test.view, test.fileSource, MapMode::Still);
|
||||
Map map(test.view, test.fileSource, test.threadPool, MapMode::Still);
|
||||
map.setZoom(16); // more map features
|
||||
map.setStyleURL("mapbox://streets");
|
||||
|
||||
@@ -101,7 +103,7 @@ TEST(Memory, Vector) {
|
||||
TEST(Memory, Raster) {
|
||||
MemoryTest test;
|
||||
|
||||
Map map(test.view, test.fileSource, MapMode::Still);
|
||||
Map map(test.view, test.fileSource, test.threadPool, MapMode::Still);
|
||||
map.setStyleURL("mapbox://satellite");
|
||||
|
||||
test::render(map);
|
||||
@@ -128,7 +130,7 @@ TEST(Memory, Footprint) {
|
||||
|
||||
// Warm up buffers and cache.
|
||||
for (unsigned i = 0; i < 10; ++i) {
|
||||
Map map(test.view, test.fileSource, MapMode::Still);
|
||||
Map map(test.view, test.fileSource,test.threadPool, MapMode::Still);
|
||||
renderMap(&map, "mapbox://streets");
|
||||
renderMap(&map, "mapbox://satellite");
|
||||
};
|
||||
@@ -142,7 +144,7 @@ TEST(Memory, Footprint) {
|
||||
|
||||
long vectorInitialRSS = getRSS();
|
||||
for (unsigned i = 0; i < runs; ++i) {
|
||||
auto vector = std::make_unique<Map>(test.view, test.fileSource, MapMode::Still);
|
||||
auto vector = std::make_unique<Map>(test.view, test.fileSource, test.threadPool, MapMode::Still);
|
||||
renderMap(vector.get(), "mapbox://streets");
|
||||
maps.push_back(std::move(vector));
|
||||
};
|
||||
@@ -151,7 +153,7 @@ TEST(Memory, Footprint) {
|
||||
|
||||
long rasterInitialRSS = getRSS();
|
||||
for (unsigned i = 0; i < runs; ++i) {
|
||||
auto raster = std::make_unique<Map>(test.view, test.fileSource, MapMode::Still);
|
||||
auto raster = std::make_unique<Map>(test.view, test.fileSource, test.threadPool, MapMode::Still);
|
||||
renderMap(raster.get(), "mapbox://satellite");
|
||||
maps.push_back(std::move(raster));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user