diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-10-10 17:16:37 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-10-25 13:52:36 -0700 |
commit | a4d259c33f9bb890bba97fd89552720e3e0ec09b (patch) | |
tree | 342ecc27a6993c48f3a2e1d739fce890350bc44d /platform/node | |
parent | 5cc390d694fc7510d445310d8eb9e32429a5e67b (diff) | |
download | qtlocation-mapboxgl-a4d259c33f9bb890bba97fd89552720e3e0ec09b.tar.gz |
[core] move gl::Context to Backend and refactor View
Diffstat (limited to 'platform/node')
-rw-r--r-- | platform/node/src/node_map.cpp | 41 | ||||
-rw-r--r-- | platform/node/src/node_map.hpp | 5 |
2 files changed, 31 insertions, 15 deletions
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index ebdf8d62c3..671bf3e0fd 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -356,21 +356,28 @@ void NodeMap::Render(const Nan::FunctionCallbackInfo<v8::Value>& info) { } void NodeMap::startRender(NodeMap::RenderOptions options) { - view.resize(options.width, options.height); - map->update(mbgl::Update::Dimensions); + map->setSize(std::array<uint16_t, 2>{{ static_cast<uint16_t>(options.width), + static_cast<uint16_t>(options.height) }}); + + const std::array<uint16_t, 2> fbSize{{ static_cast<uint16_t>(options.width * pixelRatio), + static_cast<uint16_t>(options.height * pixelRatio) }}; + if (!view || view->getSize() != fbSize) { + view.reset(); + view = std::make_unique<mbgl::OffscreenView>(backend.getContext(), fbSize); + } map->setClasses(options.classes); map->setLatLngZoom(mbgl::LatLng(options.latitude, options.longitude), options.zoom); map->setBearing(options.bearing); map->setPitch(options.pitch); map->setDebug(options.debugOptions); - map->renderStill([this](const std::exception_ptr eptr, mbgl::PremultipliedImage&& result) { + map->renderStill(*view, [this](const std::exception_ptr eptr) { if (eptr) { error = std::move(eptr); uv_async_send(async); } else { assert(!image.data); - image = std::move(result); + image = view->readStillImage(); uv_async_send(async); } }); @@ -772,15 +779,23 @@ void NodeMap::QueryRenderedFeatures(const Nan::FunctionCallbackInfo<v8::Value>& } } -NodeMap::NodeMap(v8::Local<v8::Object> options) : - backend(sharedDisplay()), - view([&] { - Nan::HandleScope scope; - return Nan::Has(options, Nan::New("ratio").ToLocalChecked()).FromJust() ? Nan::Get(options, Nan::New("ratio").ToLocalChecked()).ToLocalChecked()->NumberValue() : 1.0; - }()), - threadpool(), - map(std::make_unique<mbgl::Map>(backend, view, view.getPixelRatio(), *this, threadpool, mbgl::MapMode::Still)), - async(new uv_async_t) { +NodeMap::NodeMap(v8::Local<v8::Object> options) + : pixelRatio([&] { + Nan::HandleScope scope; + return Nan::Has(options, Nan::New("ratio").ToLocalChecked()).FromJust() + ? Nan::Get(options, Nan::New("ratio").ToLocalChecked()) + .ToLocalChecked() + ->NumberValue() + : 1.0; + }()), + backend(sharedDisplay()), + map(std::make_unique<mbgl::Map>(backend, + std::array<uint16_t, 2>{{ 256, 256 }}, + pixelRatio, + *this, + threadpool, + mbgl::MapMode::Still)), + async(new uv_async_t) { backend.setMapChangeCallback([&](mbgl::MapChange change) { if (change == mbgl::MapChangeDidFailLoadingMap) { diff --git a/platform/node/src/node_map.hpp b/platform/node/src/node_map.hpp index 48ff2caab1..45de2733cc 100644 --- a/platform/node/src/node_map.hpp +++ b/platform/node/src/node_map.hpp @@ -5,7 +5,7 @@ #include <mbgl/map/map.hpp> #include <mbgl/storage/file_source.hpp> #include <mbgl/platform/default/headless_backend.hpp> -#include <mbgl/platform/default/headless_view.hpp> +#include <mbgl/platform/default/offscreen_view.hpp> #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" @@ -54,8 +54,9 @@ public: std::unique_ptr<mbgl::AsyncRequest> request(const mbgl::Resource&, mbgl::FileSource::Callback); + const float pixelRatio; mbgl::HeadlessBackend backend; - mbgl::HeadlessView view; + std::unique_ptr<mbgl::OffscreenView> view; NodeThreadPool threadpool; std::unique_ptr<mbgl::Map> map; |