[core] Render from the main thread

Do not create a thread for the MapContext anymore.
This commit is contained in:
John Firebaugh
2015-09-01 15:07:17 +03:00
parent 18d8e80f52
commit 204c7fee03
35 changed files with 268 additions and 525 deletions

View File

@@ -1,10 +1,8 @@
#include "node_map.hpp"
#include "node_request.hpp"
#include "node_mapbox_gl_native.hpp"
#include <mbgl/platform/default/headless_display.hpp>
#include <mbgl/util/exception.hpp>
#include <mbgl/util/work_request.hpp>
#include <unistd.h>
@@ -474,18 +472,16 @@ NodeMap::~NodeMap() {
if (valid) release();
}
std::unique_ptr<mbgl::AsyncRequest> NodeMap::request(const mbgl::Resource& resource, Callback cb1) {
// This function can be called from any thread. Make sure we're executing the
// JS implementation in the node event loop.
return NodeRunLoop().invokeWithCallback([this] (mbgl::Resource res, Callback cb2) {
Nan::HandleScope scope;
std::unique_ptr<mbgl::AsyncRequest> NodeMap::request(const mbgl::Resource& resource, Callback callback_) {
Nan::HandleScope scope;
auto requestHandle = NodeRequest::Create(res, cb2)->ToObject();
auto callbackHandle = Nan::New<v8::Function>(NodeRequest::Respond, requestHandle);
auto requestHandle = NodeRequest::Create(resource, callback_)->ToObject();
auto callbackHandle = Nan::New<v8::Function>(NodeRequest::Respond, requestHandle);
v8::Local<v8::Value> argv[] = { requestHandle, callbackHandle };
Nan::MakeCallback(handle()->GetInternalField(1)->ToObject(), "request", 2, argv);
}, cb1, resource);
v8::Local<v8::Value> argv[] = { requestHandle, callbackHandle };
Nan::MakeCallback(handle()->GetInternalField(1)->ToObject(), "request", 2, argv);
return std::make_unique<mbgl::AsyncRequest>();
}
}

View File

@@ -5,25 +5,18 @@
#include <nan.h>
#pragma GCC diagnostic pop
#include "node_mapbox_gl_native.hpp"
#include <mbgl/util/run_loop.hpp>
#include "node_map.hpp"
#include "node_log.hpp"
#include "node_request.hpp"
namespace node_mbgl {
mbgl::util::RunLoop& NodeRunLoop() {
static mbgl::util::RunLoop nodeRunLoop;
return nodeRunLoop;
}
}
void RegisterModule(v8::Local<v8::Object> target, v8::Local<v8::Object> module) {
// This has the effect of:
// a) Ensuring that the static local variable is initialized before any thread contention.
// b) unreffing an async handle, which otherwise would keep the default loop running.
node_mbgl::NodeRunLoop().stop();
static mbgl::util::RunLoop nodeRunLoop;
nodeRunLoop.stop();
node_mbgl::NodeMap::Init(target);
node_mbgl::NodeRequest::Init(target);

View File

@@ -1,9 +0,0 @@
#pragma once
#include <mbgl/util/run_loop.hpp>
namespace node_mbgl {
mbgl::util::RunLoop& NodeRunLoop();
}