[node] rendering interface changes

This commit is contained in:
Ivo van Dongen
2017-06-23 16:05:20 -07:00
committed by Ivo van Dongen
parent 3832f8d0d8
commit b97cc980e0
5 changed files with 125 additions and 10 deletions

View File

@@ -3,15 +3,18 @@
#include "node_feature.hpp"
#include "node_conversion.hpp"
#include "node_geojson.hpp"
#include "node_renderer_frontend.hpp"
#include <mbgl/gl/headless_display.hpp>
#include <mbgl/util/exception.hpp>
#include <mbgl/renderer/renderer.hpp>
#include <mbgl/style/conversion/source.hpp>
#include <mbgl/style/conversion/layer.hpp>
#include <mbgl/style/conversion/filter.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/style/image.hpp>
#include <mbgl/map/backend_scope.hpp>
#include <mbgl/map/map_observer.hpp>
#include <mbgl/util/premultiply.hpp>
#include <unistd.h>
@@ -396,7 +399,7 @@ void NodeMap::startRender(NodeMap::RenderOptions options) {
map->setDebug(options.debugOptions);
}
map->renderStill(*view, [this](const std::exception_ptr eptr) {
map->renderStill([this](const std::exception_ptr eptr) {
if (eptr) {
error = std::move(eptr);
uv_async_send(async);
@@ -501,7 +504,7 @@ void NodeMap::release() {
uv_close(reinterpret_cast<uv_handle_t *>(async), [] (uv_handle_t *h) {
delete reinterpret_cast<uv_async_t *>(h);
});
map.reset();
}
@@ -528,9 +531,14 @@ void NodeMap::Cancel(const Nan::FunctionCallbackInfo<v8::Value>& info) {
void NodeMap::cancel() {
auto style = map->getStyle().getJSON();
// Reset map explicitly as it resets the renderer frontend
map.reset();
map = std::make_unique<mbgl::Map>(backend, mapObserver, mbgl::Size{ 256, 256 },
pixelRatio, *this, threadpool, mbgl::MapMode::Still);
auto renderer = std::make_unique<mbgl::Renderer>(backend, pixelRatio, *this, threadpool);
rendererFrontend = std::make_unique<NodeRendererFrontend>(std::move(renderer), [this] { return view.get(); });
map = std::make_unique<mbgl::Map>(*rendererFrontend, mapObserver, mbgl::Size{ 256, 256 }, pixelRatio,
*this, threadpool, mbgl::MapMode::Still);
// FIXME: Reload the style after recreating the map. We need to find
// a better way of canceling an ongoing rendering on the core level
@@ -884,6 +892,11 @@ void NodeMap::DumpDebugLogs(const Nan::FunctionCallbackInfo<v8::Value>& info) {
if (!nodeMap->map) return Nan::ThrowError(releasedMessage());
nodeMap->map->dumpDebugLogs();
if (nodeMap->rendererFrontend) {
nodeMap->rendererFrontend->dumpDebugLogs();
}
info.GetReturnValue().SetUndefined();
}
@@ -945,7 +958,7 @@ void NodeMap::QueryRenderedFeatures(const Nan::FunctionCallbackInfo<v8::Value>&
auto pos0 = Nan::Get(posOrBox, 0).ToLocalChecked().As<v8::Array>();
auto pos1 = Nan::Get(posOrBox, 1).ToLocalChecked().As<v8::Array>();
optional = nodeMap->map->queryRenderedFeatures(mbgl::ScreenBox {
optional = nodeMap->rendererFrontend->queryRenderedFeatures(mbgl::ScreenBox {
{
Nan::Get(pos0, 0).ToLocalChecked()->NumberValue(),
Nan::Get(pos0, 1).ToLocalChecked()->NumberValue()
@@ -956,7 +969,7 @@ void NodeMap::QueryRenderedFeatures(const Nan::FunctionCallbackInfo<v8::Value>&
}, queryOptions);
} else {
optional = nodeMap->map->queryRenderedFeatures(mbgl::ScreenCoordinate {
optional = nodeMap->rendererFrontend->queryRenderedFeatures(mbgl::ScreenCoordinate {
Nan::Get(posOrBox, 0).ToLocalChecked()->NumberValue(),
Nan::Get(posOrBox, 1).ToLocalChecked()->NumberValue()
}, queryOptions);
@@ -980,11 +993,12 @@ NodeMap::NodeMap(v8::Local<v8::Object> options)
.ToLocalChecked()
->NumberValue()
: 1.0;
}()),
mapObserver(NodeMapObserver()),
map(std::make_unique<mbgl::Map>(backend,
}())
, mapObserver(NodeMapObserver())
, rendererFrontend(std::make_unique<NodeRendererFrontend>(std::make_unique<mbgl::Renderer>(backend, pixelRatio, *this, threadpool), [this] { return view.get(); }))
, map(std::make_unique<mbgl::Map>(*rendererFrontend,
mapObserver,
mbgl::Size{ 256, 256 },
mbgl::Size { 256, 256 },
pixelRatio,
*this,
threadpool,