summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2019-03-12 15:22:48 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2019-03-12 15:24:49 +0200
commit6c6997846c343aa93deac043ba2d24a6bdeb819e (patch)
treef5bfddb6e52acdf508a8a33ee15a5430fe37bbfd
parent2a4b67f4ae2665d9166b1ceb6d37fa44afa67400 (diff)
downloadqtlocation-mapboxgl-upstream/node-filesource-composition.tar.gz
[node] Change Map/FileSource relationship to compositionupstream/node-filesource-composition
-rw-r--r--platform/node/src/node_map.cpp20
-rw-r--r--platform/node/src/node_map.hpp19
2 files changed, 27 insertions, 12 deletions
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp
index b12d3552a4..6b583f71ea 100644
--- a/platform/node/src/node_map.cpp
+++ b/platform/node/src/node_map.cpp
@@ -615,14 +615,15 @@ void NodeMap::cancel() {
reinterpret_cast<NodeMap *>(h->data)->renderFinished();
});
- frontend = std::make_unique<mbgl::HeadlessFrontend>(mbgl::Size{ 256, 256 }, pixelRatio, *this, threadpool);
+ fileSource = std::make_unique<NodeFileSource>(this);
+ frontend = std::make_unique<mbgl::HeadlessFrontend>(mbgl::Size{ 256, 256 }, pixelRatio, *fileSource, threadpool);
mbgl::MapOptions options;
options.withMapMode(mode)
.withConstrainMode(mbgl::ConstrainMode::HeightOnly)
.withViewportMode(mbgl::ViewportMode::Default)
.withCrossSourceCollisions(crossSourceCollisions);
map = std::make_unique<mbgl::Map>(*frontend, mapObserver, frontend->getSize(), pixelRatio,
- *this, threadpool, options);
+ *fileSource, threadpool, options);
// FIXME: Reload the style after recreating the map. We need to find
// a better way of canceling an ongoing rendering on the core level
@@ -1200,12 +1201,13 @@ NodeMap::NodeMap(v8::Local<v8::Object> options)
: true;
}())
, mapObserver(NodeMapObserver())
- , frontend(std::make_unique<mbgl::HeadlessFrontend>(mbgl::Size { 256, 256 }, pixelRatio, *this, threadpool))
+ , fileSource(std::make_unique<NodeFileSource>(this))
+ , frontend(std::make_unique<mbgl::HeadlessFrontend>(mbgl::Size { 256, 256 }, pixelRatio, *fileSource, threadpool))
, map(std::make_unique<mbgl::Map>(*frontend,
mapObserver,
frontend->getSize(),
pixelRatio,
- *this,
+ *fileSource,
threadpool,
mbgl::MapOptions().withMapMode(mode)
.withConstrainMode(mbgl::ConstrainMode::HeightOnly)
@@ -1226,15 +1228,19 @@ NodeMap::~NodeMap() {
if (map) release();
}
-std::unique_ptr<mbgl::AsyncRequest> NodeMap::request(const mbgl::Resource& resource, mbgl::FileSource::Callback callback_) {
+NodeFileSource::NodeFileSource(NodeMap* nodeMap_) : nodeMap(nodeMap_) {}
+
+std::unique_ptr<mbgl::AsyncRequest> NodeFileSource::request(const mbgl::Resource& resource, mbgl::FileSource::Callback callback_) {
+ assert(nodeMap);
+
Nan::HandleScope scope;
// Because this method may be called while this NodeMap is already eligible for garbage collection,
// we need to explicitly hold onto our own handle here so that GC during a v8 call doesn't destroy
// *this while we're still executing code.
- handle();
+ nodeMap->handle();
v8::Local<v8::Value> argv[] = {
- Nan::New<v8::External>(this),
+ Nan::New<v8::External>(nodeMap),
Nan::New<v8::External>(&callback_)
};
diff --git a/platform/node/src/node_map.hpp b/platform/node/src/node_map.hpp
index b83a238681..1ac8ea7ed0 100644
--- a/platform/node/src/node_map.hpp
+++ b/platform/node/src/node_map.hpp
@@ -26,9 +26,9 @@ class NodeMapObserver : public mbgl::MapObserver {
};
class RenderRequest;
+class NodeFileSource;
-class NodeMap : public Nan::ObjectWrap,
- public mbgl::FileSource {
+class NodeMap : public Nan::ObjectWrap {
public:
struct RenderOptions;
class RenderWorker;
@@ -78,13 +78,12 @@ public:
static RenderOptions ParseOptions(v8::Local<v8::Object>);
- std::unique_ptr<mbgl::AsyncRequest> request(const mbgl::Resource&, mbgl::FileSource::Callback);
-
const float pixelRatio;
mbgl::MapMode mode;
bool crossSourceCollisions;
NodeThreadPool threadpool;
NodeMapObserver mapObserver;
+ std::unique_ptr<NodeFileSource> fileSource;
std::unique_ptr<mbgl::HeadlessFrontend> frontend;
std::unique_ptr<mbgl::Map> map;
@@ -98,4 +97,14 @@ public:
bool loaded = false;
};
-}
+class NodeFileSource : public mbgl::FileSource {
+public:
+ NodeFileSource(NodeMap*);
+
+ std::unique_ptr<mbgl::AsyncRequest> request(const mbgl::Resource&, mbgl::FileSource::Callback) final;
+
+private:
+ NodeMap* nodeMap;
+};
+
+} // namespace node_mbgl \ No newline at end of file