diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-07-21 16:36:31 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-07-26 09:50:38 -0700 |
commit | 32bd1d54fa777035920b58e653905e4592ef187c (patch) | |
tree | 3f6fa84d6c9369bdd312ba630538a0c7504fce3a /platform | |
parent | 11933f6ab81248a884db3b1f69be714a60b6a86c (diff) | |
download | qtlocation-mapboxgl-32bd1d54fa777035920b58e653905e4592ef187c.tar.gz |
[node, tests] Consolidate headless rendering logic in HeadlessFrontend
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/config.cmake | 4 | ||||
-rw-r--r-- | platform/default/mbgl/gl/headless_backend.cpp | 39 | ||||
-rw-r--r-- | platform/default/mbgl/gl/headless_backend.hpp | 14 | ||||
-rw-r--r-- | platform/default/mbgl/gl/headless_frontend.cpp | 86 | ||||
-rw-r--r-- | platform/default/mbgl/gl/headless_frontend.hpp | 47 | ||||
-rw-r--r-- | platform/default/mbgl/gl/offscreen_view.cpp | 65 | ||||
-rw-r--r-- | platform/default/mbgl/gl/offscreen_view.hpp | 28 | ||||
-rw-r--r-- | platform/default/mbgl/renderer/async_renderer_frontend.cpp | 41 | ||||
-rw-r--r-- | platform/default/mbgl/renderer/async_renderer_frontend.hpp | 36 | ||||
-rw-r--r-- | platform/ios/config.cmake | 4 | ||||
-rw-r--r-- | platform/linux/config.cmake | 4 | ||||
-rw-r--r-- | platform/macos/config.cmake | 4 | ||||
-rw-r--r-- | platform/node/src/node_map.cpp | 47 | ||||
-rw-r--r-- | platform/node/src/node_map.hpp | 19 | ||||
-rw-r--r-- | platform/node/src/node_renderer_frontend.cpp | 53 | ||||
-rw-r--r-- | platform/node/src/node_renderer_frontend.hpp | 47 | ||||
-rw-r--r-- | platform/qt/config.cmake | 4 |
17 files changed, 216 insertions, 326 deletions
diff --git a/platform/android/config.cmake b/platform/android/config.cmake index 7b0c8d60f2..390e4842f4 100644 --- a/platform/android/config.cmake +++ b/platform/android/config.cmake @@ -308,10 +308,10 @@ macro(mbgl_platform_test) platform/android/src/test/main.jni.cpp # Headless view + platform/default/mbgl/gl/headless_frontend.cpp + platform/default/mbgl/gl/headless_frontend.hpp platform/default/mbgl/gl/headless_backend.cpp platform/default/mbgl/gl/headless_backend.hpp - platform/default/mbgl/gl/offscreen_view.cpp - platform/default/mbgl/gl/offscreen_view.hpp platform/linux/src/headless_backend_egl.cpp platform/linux/src/headless_display_egl.cpp diff --git a/platform/default/mbgl/gl/headless_backend.cpp b/platform/default/mbgl/gl/headless_backend.cpp index 82660331fa..a854fe9731 100644 --- a/platform/default/mbgl/gl/headless_backend.cpp +++ b/platform/default/mbgl/gl/headless_backend.cpp @@ -9,10 +9,26 @@ namespace mbgl { -HeadlessBackend::HeadlessBackend() = default; +class HeadlessBackend::View { +public: + View(gl::Context& context, Size size) + : color(context.createRenderbuffer<gl::RenderbufferType::RGBA>(size)), + depthStencil(context.createRenderbuffer<gl::RenderbufferType::DepthStencil>(size)), + framebuffer(context.createFramebuffer(color, depthStencil)) { + } + + gl::Renderbuffer<gl::RenderbufferType::RGBA> color; + gl::Renderbuffer<gl::RenderbufferType::DepthStencil> depthStencil; + gl::Framebuffer framebuffer; +}; + +HeadlessBackend::HeadlessBackend(Size size_) + : size(size_) { +} HeadlessBackend::~HeadlessBackend() { BackendScope guard { *this }; + view.reset(); context.reset(); } @@ -36,8 +52,29 @@ void HeadlessBackend::deactivate() { active = false; } +void HeadlessBackend::bind() { + gl::Context& context_ = getContext(); + + if (!view) { + view = std::make_unique<View>(context_, size); + } + + context_.bindFramebuffer = view->framebuffer.framebuffer; + context_.scissorTest = false; + context_.viewport = { 0, 0, size }; +} + void HeadlessBackend::updateAssumedState() { // no-op } +void HeadlessBackend::setSize(Size size_) { + size = size_; + view.reset(); +} + +PremultipliedImage HeadlessBackend::readStillImage() { + return getContext().readFramebuffer<PremultipliedImage>(size); +} + } // namespace mbgl diff --git a/platform/default/mbgl/gl/headless_backend.hpp b/platform/default/mbgl/gl/headless_backend.hpp index 5f39eb9f00..d845e9930c 100644 --- a/platform/default/mbgl/gl/headless_backend.hpp +++ b/platform/default/mbgl/gl/headless_backend.hpp @@ -1,5 +1,6 @@ #pragma once +#include <mbgl/map/view.hpp> #include <mbgl/renderer/renderer_backend.hpp> #include <memory> @@ -9,13 +10,17 @@ namespace mbgl { class HeadlessDisplay; -class HeadlessBackend : public RendererBackend { +class HeadlessBackend : public View, public RendererBackend { public: - HeadlessBackend(); + HeadlessBackend(Size = { 256, 256 }); ~HeadlessBackend() override; + void bind() override; void updateAssumedState() override; + void setSize(Size); + PremultipliedImage readStillImage(); + struct Impl { virtual ~Impl() = default; virtual void activateContext() = 0; @@ -37,7 +42,12 @@ private: std::shared_ptr<HeadlessDisplay> display; std::unique_ptr<Impl> impl; + Size size; + float pixelRatio; bool active = false; + + class View; + std::unique_ptr<View> view; }; } // namespace mbgl diff --git a/platform/default/mbgl/gl/headless_frontend.cpp b/platform/default/mbgl/gl/headless_frontend.cpp new file mode 100644 index 0000000000..3f34d8eeba --- /dev/null +++ b/platform/default/mbgl/gl/headless_frontend.cpp @@ -0,0 +1,86 @@ +#include <mbgl/gl/headless_frontend.hpp> +#include <mbgl/renderer/renderer.hpp> +#include <mbgl/map/map.hpp> +#include <mbgl/util/run_loop.hpp> + +namespace mbgl { + +HeadlessFrontend::HeadlessFrontend(float pixelRatio_, FileSource& fileSource, Scheduler& scheduler) + : HeadlessFrontend({ 256, 256 }, pixelRatio_, fileSource, scheduler) { +} + +HeadlessFrontend::HeadlessFrontend(Size size_, float pixelRatio_, FileSource& fileSource, Scheduler& scheduler) + : size(size_), + pixelRatio(pixelRatio_), + backend({ static_cast<uint32_t>(size.width * pixelRatio), + static_cast<uint32_t>(size.height * pixelRatio) }), + asyncInvalidate([this] { + if (renderer && updateParameters) { + mbgl::BackendScope guard { backend }; + renderer->render(backend, *updateParameters); + } + }), + renderer(std::make_unique<Renderer>(backend, pixelRatio, fileSource, scheduler)) { +} + +HeadlessFrontend::~HeadlessFrontend() = default; + +void HeadlessFrontend::reset() { + assert(renderer); + renderer.reset(); +} + +void HeadlessFrontend::update(std::shared_ptr<UpdateParameters> updateParameters_) { + updateParameters = updateParameters_; + asyncInvalidate.send(); +} + +void HeadlessFrontend::setObserver(RendererObserver& observer_) { + assert(renderer); + renderer->setObserver(&observer_); +} + +Size HeadlessFrontend::getSize() const { + return size; +} + +Renderer* HeadlessFrontend::getRenderer() { + assert(renderer); + return renderer.get(); +} + +RendererBackend* HeadlessFrontend::getBackend() { + return &backend; +} + +void HeadlessFrontend::setSize(Size size_) { + if (size != size_) { + size = size_; + backend.setSize({ static_cast<uint32_t>(size_.width * pixelRatio), + static_cast<uint32_t>(size_.height * pixelRatio) }); + } +} + +PremultipliedImage HeadlessFrontend::readStillImage() { + return backend.readStillImage(); +} + +PremultipliedImage HeadlessFrontend::render(Map& map) { + PremultipliedImage result; + + map.renderStill([&](std::exception_ptr error) { + if (error) { + std::rethrow_exception(error); + } else { + result = backend.readStillImage(); + } + }); + + while (!result.valid()) { + util::RunLoop::Get()->runOnce(); + } + + return result; +} + +} // namespace mbgl diff --git a/platform/default/mbgl/gl/headless_frontend.hpp b/platform/default/mbgl/gl/headless_frontend.hpp new file mode 100644 index 0000000000..18d0d2527b --- /dev/null +++ b/platform/default/mbgl/gl/headless_frontend.hpp @@ -0,0 +1,47 @@ +#pragma once + +#include <mbgl/renderer/renderer_frontend.hpp> +#include <mbgl/gl/headless_backend.hpp> +#include <mbgl/util/async_task.hpp> + +#include <memory> + +namespace mbgl { + +class FileSource; +class Scheduler; +class Renderer; +class RendererBackend; +class Map; + +class HeadlessFrontend : public RendererFrontend { +public: + HeadlessFrontend(float pixelRatio_, FileSource&, Scheduler&); + HeadlessFrontend(Size, float pixelRatio_, FileSource&, Scheduler&); + ~HeadlessFrontend() override; + + void reset() override; + void update(std::shared_ptr<UpdateParameters>) override; + void setObserver(RendererObserver&) override; + + Size getSize() const; + void setSize(Size); + + Renderer* getRenderer(); + RendererBackend* getBackend(); + + PremultipliedImage readStillImage(); + PremultipliedImage render(Map&); + +private: + Size size; + float pixelRatio; + + HeadlessBackend backend; + util::AsyncTask asyncInvalidate; + + std::unique_ptr<Renderer> renderer; + std::shared_ptr<UpdateParameters> updateParameters; +}; + +} // namespace mbgl diff --git a/platform/default/mbgl/gl/offscreen_view.cpp b/platform/default/mbgl/gl/offscreen_view.cpp deleted file mode 100644 index e7cf7cffe5..0000000000 --- a/platform/default/mbgl/gl/offscreen_view.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include <mbgl/gl/offscreen_view.hpp> -#include <mbgl/gl/context.hpp> -#include <mbgl/gl/framebuffer.hpp> -#include <mbgl/gl/renderbuffer.hpp> -#include <mbgl/util/optional.hpp> - -#include <cstring> -#include <cassert> - -namespace mbgl { - -class OffscreenView::Impl { -public: - Impl(gl::Context& context_, const Size size_) : context(context_), size(std::move(size_)) { - assert(!size.isEmpty()); - } - - void bind() { - if (!framebuffer) { - color = context.createRenderbuffer<gl::RenderbufferType::RGBA>(size); - depthStencil = context.createRenderbuffer<gl::RenderbufferType::DepthStencil>(size); - framebuffer = context.createFramebuffer(*color, *depthStencil); - } else { - context.bindFramebuffer = framebuffer->framebuffer; - } - - context.scissorTest = false; - context.viewport = { 0, 0, size }; - } - - PremultipliedImage readStillImage() { - return context.readFramebuffer<PremultipliedImage>(size); - } - - const Size& getSize() const { - return size; - } - -private: - gl::Context& context; - const Size size; - optional<gl::Framebuffer> framebuffer; - optional<gl::Renderbuffer<gl::RenderbufferType::RGBA>> color; - optional<gl::Renderbuffer<gl::RenderbufferType::DepthStencil>> depthStencil; -}; - -OffscreenView::OffscreenView(gl::Context& context, const Size size) - : impl(std::make_unique<Impl>(context, std::move(size))) { -} - -OffscreenView::~OffscreenView() = default; - -void OffscreenView::bind() { - impl->bind(); -} - -PremultipliedImage OffscreenView::readStillImage() { - return impl->readStillImage(); -} - -const Size& OffscreenView::getSize() const { - return impl->getSize(); -} - -} // namespace mbgl diff --git a/platform/default/mbgl/gl/offscreen_view.hpp b/platform/default/mbgl/gl/offscreen_view.hpp deleted file mode 100644 index eb888272e5..0000000000 --- a/platform/default/mbgl/gl/offscreen_view.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include <mbgl/map/view.hpp> -#include <mbgl/util/image.hpp> - -namespace mbgl { - -namespace gl { -class Context; -} // namespace gl - -class OffscreenView : public View { -public: - OffscreenView(gl::Context&, Size size = { 256, 256 }); - ~OffscreenView() override; - - void bind() override; - - PremultipliedImage readStillImage(); - - const Size& getSize() const; - -private: - class Impl; - const std::unique_ptr<Impl> impl; -}; - -} // namespace mbgl diff --git a/platform/default/mbgl/renderer/async_renderer_frontend.cpp b/platform/default/mbgl/renderer/async_renderer_frontend.cpp deleted file mode 100644 index 230d0bb820..0000000000 --- a/platform/default/mbgl/renderer/async_renderer_frontend.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "async_renderer_frontend.hpp" - -#include <mbgl/renderer/backend_scope.hpp> -#include <mbgl/renderer/renderer.hpp> - -namespace mbgl { - -AsyncRendererFrontend::AsyncRendererFrontend(std::unique_ptr<Renderer> renderer_, RendererBackend& backend, View& view_) - : renderer(std::move(renderer_)) - , view(view_) - , asyncInvalidate([&] { - if (renderer && updateParameters) { - BackendScope guard { backend }; - renderer->render(view, *updateParameters); - } - }) { -} - -AsyncRendererFrontend::~AsyncRendererFrontend() = default; - -void AsyncRendererFrontend::reset() { - assert(renderer); - renderer.reset(); -} - -void AsyncRendererFrontend::update(std::shared_ptr<UpdateParameters> updateParameters_) { - updateParameters = updateParameters_; - asyncInvalidate.send(); -} - -void AsyncRendererFrontend::setObserver(RendererObserver& observer_) { - assert(renderer); - renderer->setObserver(&observer_); -} - -Renderer* AsyncRendererFrontend::getRenderer() { - assert(renderer); - return renderer.get(); -} - -} // namespace mbgl diff --git a/platform/default/mbgl/renderer/async_renderer_frontend.hpp b/platform/default/mbgl/renderer/async_renderer_frontend.hpp deleted file mode 100644 index e1b2f780cd..0000000000 --- a/platform/default/mbgl/renderer/async_renderer_frontend.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include <mbgl/map/view.hpp> -#include <mbgl/renderer/renderer_frontend.hpp> -#include <mbgl/util/async_task.hpp> - -#include <memory> -#include <vector> - -namespace mbgl { - -class Renderer; -class RendererBackend; - -// Default implementation for RendererFrontend -class AsyncRendererFrontend : public mbgl::RendererFrontend { -public: - AsyncRendererFrontend(std::unique_ptr<Renderer>, RendererBackend&, View&); - ~AsyncRendererFrontend() override; - - void reset() override; - - void update(std::shared_ptr<UpdateParameters> updateParameters_) override; - - void setObserver(RendererObserver& observer_) override; - - Renderer* getRenderer(); - -private: - std::unique_ptr<Renderer> renderer; - View& view; - std::shared_ptr<UpdateParameters> updateParameters; - util::AsyncTask asyncInvalidate; -}; - -} // namespace mbgl diff --git a/platform/ios/config.cmake b/platform/ios/config.cmake index efb31d2e00..7ea1dddef7 100644 --- a/platform/ios/config.cmake +++ b/platform/ios/config.cmake @@ -49,13 +49,13 @@ macro(mbgl_platform_core) PRIVATE platform/default/png_writer.cpp # Headless view + PRIVATE platform/default/mbgl/gl/headless_frontend.cpp + PRIVATE platform/default/mbgl/gl/headless_frontend.hpp PRIVATE platform/default/mbgl/gl/headless_backend.cpp PRIVATE platform/default/mbgl/gl/headless_backend.hpp PRIVATE platform/darwin/src/headless_backend_eagl.mm PRIVATE platform/default/mbgl/gl/headless_display.cpp PRIVATE platform/default/mbgl/gl/headless_display.hpp - PRIVATE platform/default/mbgl/gl/offscreen_view.cpp - PRIVATE platform/default/mbgl/gl/offscreen_view.hpp # Thread pool PRIVATE platform/default/mbgl/util/shared_thread_pool.cpp diff --git a/platform/linux/config.cmake b/platform/linux/config.cmake index 8fbfafb417..3aa1fdbbfc 100644 --- a/platform/linux/config.cmake +++ b/platform/linux/config.cmake @@ -80,11 +80,11 @@ macro(mbgl_platform_core) PRIVATE platform/default/webp_reader.cpp # Headless view + PRIVATE platform/default/mbgl/gl/headless_frontend.cpp + PRIVATE platform/default/mbgl/gl/headless_frontend.hpp PRIVATE platform/default/mbgl/gl/headless_backend.cpp PRIVATE platform/default/mbgl/gl/headless_backend.hpp PRIVATE platform/default/mbgl/gl/headless_display.hpp - PRIVATE platform/default/mbgl/gl/offscreen_view.cpp - PRIVATE platform/default/mbgl/gl/offscreen_view.hpp # Thread pool PRIVATE platform/default/mbgl/util/default_thread_pool.cpp diff --git a/platform/macos/config.cmake b/platform/macos/config.cmake index d037469bd0..86c54b612c 100644 --- a/platform/macos/config.cmake +++ b/platform/macos/config.cmake @@ -45,13 +45,13 @@ macro(mbgl_platform_core) PRIVATE platform/default/png_writer.cpp # Headless view + PRIVATE platform/default/mbgl/gl/headless_frontend.cpp + PRIVATE platform/default/mbgl/gl/headless_frontend.hpp PRIVATE platform/default/mbgl/gl/headless_backend.cpp PRIVATE platform/default/mbgl/gl/headless_backend.hpp PRIVATE platform/darwin/src/headless_backend_cgl.cpp PRIVATE platform/default/mbgl/gl/headless_display.hpp PRIVATE platform/darwin/src/headless_display_cgl.cpp - PRIVATE platform/default/mbgl/gl/offscreen_view.cpp - PRIVATE platform/default/mbgl/gl/offscreen_view.hpp # Thread pool PRIVATE platform/default/mbgl/util/shared_thread_pool.cpp diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index 0b87a86210..7c7082bd09 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -3,11 +3,10 @@ #include "node_feature.hpp" #include "node_conversion.hpp" #include "node_geojson.hpp" -#include "node_renderer_frontend.hpp" #include <mbgl/util/exception.hpp> #include <mbgl/renderer/renderer.hpp> -#include <mbgl/renderer/backend_scope.hpp> +#include <mbgl/gl/headless_frontend.hpp> #include <mbgl/style/conversion/source.hpp> #include <mbgl/style/conversion/layer.hpp> #include <mbgl/style/conversion/filter.hpp> @@ -26,8 +25,7 @@ struct NodeMap::RenderOptions { double pitch = 0; double latitude = 0; double longitude = 0; - unsigned int width = 512; - unsigned int height = 512; + mbgl::Size size = { 512, 512 }; std::vector<std::string> classes; mbgl::MapDebugOptions debugOptions = mbgl::MapDebugOptions::NoDebug; }; @@ -38,8 +36,6 @@ static const char* releasedMessage() { return "Map resources have already been released"; } -NodeBackend::NodeBackend(): HeadlessBackend() {} - void NodeMapObserver::onDidFailLoadingMap(std::exception_ptr error) { std::rethrow_exception(error); } @@ -258,11 +254,11 @@ NodeMap::RenderOptions NodeMap::ParseOptions(v8::Local<v8::Object> obj) { } if (Nan::Has(obj, Nan::New("width").ToLocalChecked()).FromJust()) { - options.width = Nan::Get(obj, Nan::New("width").ToLocalChecked()).ToLocalChecked()->IntegerValue(); + options.size.width = Nan::Get(obj, Nan::New("width").ToLocalChecked()).ToLocalChecked()->IntegerValue(); } if (Nan::Has(obj, Nan::New("height").ToLocalChecked()).FromJust()) { - options.height = Nan::Get(obj, Nan::New("height").ToLocalChecked()).ToLocalChecked()->IntegerValue(); + options.size.height = Nan::Get(obj, Nan::New("height").ToLocalChecked()).ToLocalChecked()->IntegerValue(); } if (Nan::Has(obj, Nan::New("classes").ToLocalChecked()).FromJust()) { @@ -358,15 +354,8 @@ void NodeMap::Render(const Nan::FunctionCallbackInfo<v8::Value>& info) { } void NodeMap::startRender(NodeMap::RenderOptions options) { - map->setSize({ options.width, options.height }); - - const mbgl::Size fbSize{ static_cast<uint32_t>(options.width * pixelRatio), - static_cast<uint32_t>(options.height * pixelRatio) }; - if (!view || view->getSize() != fbSize) { - view.reset(); - mbgl::BackendScope scope { backend }; - view = std::make_unique<mbgl::OffscreenView>(backend.getContext(), fbSize); - } + frontend->setSize(options.size); + map->setSize(options.size); if (map->getZoom() != options.zoom) { map->setZoom(options.zoom); @@ -395,7 +384,7 @@ void NodeMap::startRender(NodeMap::RenderOptions options) { uv_async_send(async); } else { assert(!image.data); - image = view->readStillImage(); + image = frontend->readStillImage(); uv_async_send(async); } }); @@ -525,9 +514,8 @@ void NodeMap::cancel() { // Reset map explicitly as it resets the renderer frontend map.reset(); - auto renderer = std::make_unique<mbgl::Renderer>(backend, pixelRatio, *this, threadpool); - rendererFrontend = std::make_unique<NodeRendererFrontend>(std::move(renderer), backend, [this] { return view.get(); }); - map = std::make_unique<mbgl::Map>(*rendererFrontend, mapObserver, mbgl::Size{ 256, 256 }, pixelRatio, + frontend = std::make_unique<mbgl::HeadlessFrontend>(mbgl::Size{ 256, 256 }, pixelRatio, *this, threadpool); + map = std::make_unique<mbgl::Map>(*frontend, mapObserver, frontend->getSize(), pixelRatio, *this, threadpool, mbgl::MapMode::Still); // FIXME: Reload the style after recreating the map. We need to find @@ -882,11 +870,8 @@ 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(); - } - + nodeMap->frontend->getRenderer()->dumpDebugLogs(); + info.GetReturnValue().SetUndefined(); } @@ -948,7 +933,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->rendererFrontend->queryRenderedFeatures(mbgl::ScreenBox { + optional = nodeMap->frontend->getRenderer()->queryRenderedFeatures(mbgl::ScreenBox { { Nan::Get(pos0, 0).ToLocalChecked()->NumberValue(), Nan::Get(pos0, 1).ToLocalChecked()->NumberValue() @@ -959,7 +944,7 @@ void NodeMap::QueryRenderedFeatures(const Nan::FunctionCallbackInfo<v8::Value>& }, queryOptions); } else { - optional = nodeMap->rendererFrontend->queryRenderedFeatures(mbgl::ScreenCoordinate { + optional = nodeMap->frontend->getRenderer()->queryRenderedFeatures(mbgl::ScreenCoordinate { Nan::Get(posOrBox, 0).ToLocalChecked()->NumberValue(), Nan::Get(posOrBox, 1).ToLocalChecked()->NumberValue() }, queryOptions); @@ -985,10 +970,10 @@ NodeMap::NodeMap(v8::Local<v8::Object> options) : 1.0; }()) , mapObserver(NodeMapObserver()) - , rendererFrontend(std::make_unique<NodeRendererFrontend>(std::make_unique<mbgl::Renderer>(backend, pixelRatio, *this, threadpool), backend, [this] { return view.get(); })) - , map(std::make_unique<mbgl::Map>(*rendererFrontend, + , frontend(std::make_unique<mbgl::HeadlessFrontend>(mbgl::Size { 256, 256 }, pixelRatio, *this, threadpool)) + , map(std::make_unique<mbgl::Map>(*frontend, mapObserver, - mbgl::Size { 256, 256 }, + frontend->getSize(), pixelRatio, *this, threadpool, diff --git a/platform/node/src/node_map.hpp b/platform/node/src/node_map.hpp index 08a3dcaa79..7bd3b99bea 100644 --- a/platform/node/src/node_map.hpp +++ b/platform/node/src/node_map.hpp @@ -4,8 +4,7 @@ #include <mbgl/map/map.hpp> #include <mbgl/storage/file_source.hpp> -#include <mbgl/gl/headless_backend.hpp> -#include <mbgl/gl/offscreen_view.hpp> +#include <mbgl/util/image.hpp> #include <exception> @@ -15,15 +14,13 @@ #include <nan.h> #pragma GCC diagnostic pop +namespace mbgl { +class Map; +class HeadlessFrontend; +} // namespace mbgl + namespace node_mbgl { - -class NodeRendererFrontend; -class NodeBackend : public mbgl::HeadlessBackend { -public: - NodeBackend(); -}; - class NodeMapObserver : public mbgl::MapObserver { void onDidFailLoadingMap(std::exception_ptr) override; }; @@ -73,11 +70,9 @@ public: std::unique_ptr<mbgl::AsyncRequest> request(const mbgl::Resource&, mbgl::FileSource::Callback); const float pixelRatio; - NodeBackend backend; - std::unique_ptr<mbgl::OffscreenView> view; NodeThreadPool threadpool; NodeMapObserver mapObserver; - std::unique_ptr<NodeRendererFrontend> rendererFrontend; + std::unique_ptr<mbgl::HeadlessFrontend> frontend; std::unique_ptr<mbgl::Map> map; std::exception_ptr error; diff --git a/platform/node/src/node_renderer_frontend.cpp b/platform/node/src/node_renderer_frontend.cpp deleted file mode 100644 index 5ebb92717b..0000000000 --- a/platform/node/src/node_renderer_frontend.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include "node_renderer_frontend.hpp" - -#include <mbgl/renderer/renderer.hpp> -#include <mbgl/renderer/renderer_backend.hpp> -#include <mbgl/renderer/backend_scope.hpp> - -namespace node_mbgl { - -NodeRendererFrontend::NodeRendererFrontend(std::unique_ptr<mbgl::Renderer> renderer_, mbgl::RendererBackend& backend_, ViewAccessorFunction getView) - : renderer(std::move(renderer_)) - , asyncInvalidate([&, getView] { - if (renderer && updateParameters) { - mbgl::BackendScope guard { backend_ }; - renderer->render(*getView(), *updateParameters); - } - }) { -} - -NodeRendererFrontend::~NodeRendererFrontend() = default; - -void NodeRendererFrontend::reset() { - assert(renderer); - renderer.reset(); -} - -void NodeRendererFrontend::setObserver(mbgl::RendererObserver& observer_) { - assert(renderer); - renderer->setObserver(&observer_); -} - -void NodeRendererFrontend::update(std::shared_ptr<mbgl::UpdateParameters> updateParameters_) { - updateParameters = updateParameters_; - asyncInvalidate.send(); -} - -std::vector<mbgl::Feature> NodeRendererFrontend::queryRenderedFeatures(const mbgl::ScreenBox& box, - const mbgl::RenderedQueryOptions& options) const { - assert(renderer); - return renderer->queryRenderedFeatures(box, options); -} - -std::vector<mbgl::Feature> NodeRendererFrontend::queryRenderedFeatures(const mbgl::ScreenCoordinate& point, - const mbgl::RenderedQueryOptions& options) const { - assert(renderer); - return renderer->queryRenderedFeatures(point, options); -} - -void NodeRendererFrontend::dumpDebugLogs() { - assert(renderer); - return renderer->dumpDebugLogs(); -} - -} // namespace node_mbgl diff --git a/platform/node/src/node_renderer_frontend.hpp b/platform/node/src/node_renderer_frontend.hpp deleted file mode 100644 index c70291317b..0000000000 --- a/platform/node/src/node_renderer_frontend.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include <mbgl/renderer/renderer_frontend.hpp> -#include <mbgl/renderer/query.hpp> -#include <mbgl/util/async_task.hpp> -#include <mbgl/util/feature.hpp> -#include <mbgl/util/geo.hpp> - -#include <functional> -#include <memory> - -namespace mbgl { - class Renderer; - class RendererBackend; - class View; -} // namespace mbgl - -namespace node_mbgl { - -class NodeRendererFrontend : public mbgl::RendererFrontend { -public: - using ViewAccessorFunction = std::function<mbgl::View* ()>; - NodeRendererFrontend(std::unique_ptr<mbgl::Renderer>, mbgl::RendererBackend&, ViewAccessorFunction); - - ~NodeRendererFrontend(); - - void reset() override; - - void setObserver(mbgl::RendererObserver&) override; - - void update(std::shared_ptr<mbgl::UpdateParameters>) override; - - // Feature querying - std::vector<mbgl::Feature> queryRenderedFeatures(const mbgl::ScreenCoordinate&, - const mbgl::RenderedQueryOptions& options = {}) const; - std::vector<mbgl::Feature> queryRenderedFeatures(const mbgl::ScreenBox&, - const mbgl::RenderedQueryOptions& = {}) const; - - void dumpDebugLogs(); - -private: - std::unique_ptr<mbgl::Renderer> renderer; - std::shared_ptr<mbgl::UpdateParameters> updateParameters; - mbgl::util::AsyncTask asyncInvalidate; -}; - -} // namespace node_mbgl diff --git a/platform/qt/config.cmake b/platform/qt/config.cmake index 0f2bab0516..732fb1de28 100644 --- a/platform/qt/config.cmake +++ b/platform/qt/config.cmake @@ -52,12 +52,12 @@ endmacro() macro(mbgl_platform_test) target_sources(mbgl-test + PRIVATE platform/default/mbgl/gl/headless_frontend.cpp + PRIVATE platform/default/mbgl/gl/headless_frontend.hpp PRIVATE platform/default/mbgl/gl/headless_backend.cpp PRIVATE platform/default/mbgl/gl/headless_backend.hpp PRIVATE platform/default/mbgl/gl/headless_display.cpp PRIVATE platform/default/mbgl/gl/headless_display.hpp - PRIVATE platform/default/mbgl/gl/offscreen_view.cpp - PRIVATE platform/default/mbgl/gl/offscreen_view.hpp PRIVATE platform/qt/test/headless_backend_qt.cpp PRIVATE platform/qt/test/main.cpp PRIVATE platform/qt/test/qmapboxgl.cpp |