diff options
-rw-r--r-- | platform/darwin/src/headless_backend_cgl.cpp | 2 | ||||
-rw-r--r-- | platform/default/mbgl/gl/headless_backend.cpp | 4 | ||||
-rw-r--r-- | platform/default/mbgl/gl/headless_backend.hpp | 1 | ||||
-rw-r--r-- | platform/default/mbgl/gl/headless_display.hpp | 16 | ||||
-rw-r--r-- | platform/linux/src/headless_backend_egl.cpp | 2 | ||||
-rw-r--r-- | platform/linux/src/headless_backend_glx.cpp | 2 | ||||
-rw-r--r-- | platform/node/src/node_map.cpp | 12 | ||||
-rw-r--r-- | test/api/annotations.test.cpp | 2 | ||||
-rw-r--r-- | test/api/api_misuse.test.cpp | 2 | ||||
-rw-r--r-- | test/api/custom_layer.test.cpp | 2 | ||||
-rw-r--r-- | test/api/query.test.cpp | 2 | ||||
-rw-r--r-- | test/api/render_missing.test.cpp | 2 | ||||
-rw-r--r-- | test/api/repeated_render.test.cpp | 4 | ||||
-rw-r--r-- | test/gl/object.test.cpp | 2 | ||||
-rw-r--r-- | test/map/map.test.cpp | 5 | ||||
-rw-r--r-- | test/map/prefetch.test.cpp | 2 | ||||
-rw-r--r-- | test/src/mbgl/test/util.cpp | 6 | ||||
-rw-r--r-- | test/src/mbgl/test/util.hpp | 2 | ||||
-rw-r--r-- | test/tile/annotation_tile.test.cpp | 2 | ||||
-rw-r--r-- | test/util/memory.test.cpp | 2 | ||||
-rw-r--r-- | test/util/offscreen_texture.test.cpp | 4 |
21 files changed, 35 insertions, 43 deletions
diff --git a/platform/darwin/src/headless_backend_cgl.cpp b/platform/darwin/src/headless_backend_cgl.cpp index 6ad98f4326..3b0c3aaf35 100644 --- a/platform/darwin/src/headless_backend_cgl.cpp +++ b/platform/darwin/src/headless_backend_cgl.cpp @@ -51,7 +51,7 @@ gl::ProcAddress HeadlessBackend::initializeExtension(const char* name) { bool HeadlessBackend::hasDisplay() { if (!display) { - display.reset(new HeadlessDisplay); + display = HeadlessDisplay::create(); } return bool(display); } diff --git a/platform/default/mbgl/gl/headless_backend.cpp b/platform/default/mbgl/gl/headless_backend.cpp index e17e8f5c11..9076be4cbb 100644 --- a/platform/default/mbgl/gl/headless_backend.cpp +++ b/platform/default/mbgl/gl/headless_backend.cpp @@ -11,10 +11,6 @@ namespace mbgl { HeadlessBackend::HeadlessBackend() = default; -HeadlessBackend::HeadlessBackend(std::shared_ptr<HeadlessDisplay> display_) - : display(std::move(display_)) { -} - HeadlessBackend::~HeadlessBackend() { BackendScope guard { *this, getScopeType() }; context.reset(); diff --git a/platform/default/mbgl/gl/headless_backend.hpp b/platform/default/mbgl/gl/headless_backend.hpp index 133c2096d9..5f39eb9f00 100644 --- a/platform/default/mbgl/gl/headless_backend.hpp +++ b/platform/default/mbgl/gl/headless_backend.hpp @@ -12,7 +12,6 @@ class HeadlessDisplay; class HeadlessBackend : public RendererBackend { public: HeadlessBackend(); - HeadlessBackend(std::shared_ptr<HeadlessDisplay>); ~HeadlessBackend() override; void updateAssumedState() override; diff --git a/platform/default/mbgl/gl/headless_display.hpp b/platform/default/mbgl/gl/headless_display.hpp index a5c95085b8..8c294655e5 100644 --- a/platform/default/mbgl/gl/headless_display.hpp +++ b/platform/default/mbgl/gl/headless_display.hpp @@ -6,13 +6,27 @@ namespace mbgl { class HeadlessDisplay { public: - HeadlessDisplay(); + static std::shared_ptr<HeadlessDisplay> create() { + static std::weak_ptr<HeadlessDisplay> instance; + + auto shared = instance.lock(); + + if (!shared) { + instance = shared = std::shared_ptr<HeadlessDisplay>(new HeadlessDisplay()); + } + + return shared; + } + + ~HeadlessDisplay(); template <typename DisplayAttribute> DisplayAttribute attribute() const; private: + HeadlessDisplay(); + class Impl; std::unique_ptr<Impl> impl; }; diff --git a/platform/linux/src/headless_backend_egl.cpp b/platform/linux/src/headless_backend_egl.cpp index d98b2edc03..0784173af7 100644 --- a/platform/linux/src/headless_backend_egl.cpp +++ b/platform/linux/src/headless_backend_egl.cpp @@ -67,7 +67,7 @@ gl::ProcAddress HeadlessBackend::initializeExtension(const char* name) { bool HeadlessBackend::hasDisplay() { if (!display) { - display.reset(new HeadlessDisplay); + display = HeadlessDisplay::create(); } return bool(display); }; diff --git a/platform/linux/src/headless_backend_glx.cpp b/platform/linux/src/headless_backend_glx.cpp index eec0e7656f..0ba7f08630 100644 --- a/platform/linux/src/headless_backend_glx.cpp +++ b/platform/linux/src/headless_backend_glx.cpp @@ -50,7 +50,7 @@ gl::ProcAddress HeadlessBackend::initializeExtension(const char* name) { bool HeadlessBackend::hasDisplay() { if (!display) { - display.reset(new HeadlessDisplay); + display = HeadlessDisplay::create(); } return bool(display); }; diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index b4e93455ea..079112b4c8 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -5,7 +5,6 @@ #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/renderer/backend_scope.hpp> @@ -35,17 +34,11 @@ struct NodeMap::RenderOptions { Nan::Persistent<v8::Function> NodeMap::constructor; -static std::shared_ptr<mbgl::HeadlessDisplay> sharedDisplay() { - static auto display = std::make_shared<mbgl::HeadlessDisplay>(); - return display; -} - static const char* releasedMessage() { return "Map resources have already been released"; } -NodeBackend::NodeBackend() - : HeadlessBackend(sharedDisplay()) {} +NodeBackend::NodeBackend(): HeadlessBackend() {} void NodeMapObserver::onDidFailLoadingMap(std::exception_ptr error) { std::rethrow_exception(error); @@ -81,9 +74,6 @@ void NodeMap::Init(v8::Local<v8::Object> target) { constructor.Reset(tpl->GetFunction()); Nan::Set(target, Nan::New("Map").ToLocalChecked(), tpl->GetFunction()); - - // Initialize display connection on module load. - sharedDisplay(); } /** diff --git a/test/api/annotations.test.cpp b/test/api/annotations.test.cpp index bc1ad54129..878ef90831 100644 --- a/test/api/annotations.test.cpp +++ b/test/api/annotations.test.cpp @@ -30,7 +30,7 @@ std::unique_ptr<style::Image> namedMarker(const std::string& name) { class AnnotationTest { public: util::RunLoop loop; - HeadlessBackend backend { test::sharedDisplay() }; + HeadlessBackend backend; BackendScope scope { backend }; OffscreenView view { backend.getContext() }; StubFileSource fileSource; diff --git a/test/api/api_misuse.test.cpp b/test/api/api_misuse.test.cpp index ed5cc41a49..9f53b763be 100644 --- a/test/api/api_misuse.test.cpp +++ b/test/api/api_misuse.test.cpp @@ -24,7 +24,7 @@ TEST(API, RenderWithoutCallback) { util::RunLoop loop; - HeadlessBackend backend { test::sharedDisplay() }; + HeadlessBackend backend; BackendScope scope { backend }; OffscreenView view { backend.getContext(), { 128, 512 } }; StubFileSource fileSource; diff --git a/test/api/custom_layer.test.cpp b/test/api/custom_layer.test.cpp index da5b535a86..972485338f 100644 --- a/test/api/custom_layer.test.cpp +++ b/test/api/custom_layer.test.cpp @@ -89,7 +89,7 @@ public: TEST(CustomLayer, Basic) { util::RunLoop loop; - HeadlessBackend backend { test::sharedDisplay() }; + HeadlessBackend backend; BackendScope scope { backend }; OffscreenView view { backend.getContext() }; DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets"); diff --git a/test/api/query.test.cpp b/test/api/query.test.cpp index 5135b51e8b..a5224222cb 100644 --- a/test/api/query.test.cpp +++ b/test/api/query.test.cpp @@ -30,7 +30,7 @@ public: } util::RunLoop loop; - HeadlessBackend backend { test::sharedDisplay() }; + HeadlessBackend backend; BackendScope scope { backend }; OffscreenView view { backend.getContext() }; StubFileSource fileSource; diff --git a/test/api/render_missing.test.cpp b/test/api/render_missing.test.cpp index 01a0e9293b..02c19d359b 100644 --- a/test/api/render_missing.test.cpp +++ b/test/api/render_missing.test.cpp @@ -30,7 +30,7 @@ TEST(API, TEST_REQUIRES_SERVER(RenderMissingTile)) { const auto style = util::read_file("test/fixtures/api/water_missing_tiles.json"); - HeadlessBackend backend { test::sharedDisplay() }; + HeadlessBackend backend; BackendScope scope { backend }; OffscreenView view { backend.getContext(), { 256, 512 } }; float pixelRatio { 1 }; diff --git a/test/api/repeated_render.test.cpp b/test/api/repeated_render.test.cpp index 7d61992769..0e8a2715b7 100644 --- a/test/api/repeated_render.test.cpp +++ b/test/api/repeated_render.test.cpp @@ -27,7 +27,7 @@ TEST(API, RepeatedRender) { const auto style = util::read_file("test/fixtures/api/water.json"); - HeadlessBackend backend { test::sharedDisplay() }; + HeadlessBackend backend; BackendScope scope { backend }; OffscreenView view { backend.getContext(), { 512, 512 } }; float pixelRatio { 1 }; @@ -84,7 +84,7 @@ TEST(API, ZoomHistory) { const auto style = util::read_file("test/fixtures/api/empty.json"); - HeadlessBackend backend { test::sharedDisplay() }; + HeadlessBackend backend; BackendScope scope { backend }; OffscreenView view { backend.getContext(), { 512, 512 } }; DefaultFileSource fileSource(":memory:", "."); diff --git a/test/gl/object.test.cpp b/test/gl/object.test.cpp index cf887dab40..30699718b3 100644 --- a/test/gl/object.test.cpp +++ b/test/gl/object.test.cpp @@ -47,7 +47,7 @@ TEST(GLObject, Value) { } TEST(GLObject, Store) { - HeadlessBackend backend { test::sharedDisplay() }; + HeadlessBackend backend; BackendScope scope { backend }; OffscreenView view(backend.getContext()); diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index 93890aa9f3..3e8f8696e1 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -6,6 +6,7 @@ #include <mbgl/map/map.hpp> #include <mbgl/renderer/backend_scope.hpp> #include <mbgl/gl/headless_backend.hpp> +#include <mbgl/gl/headless_display.hpp> #include <mbgl/gl/offscreen_view.hpp> #include <mbgl/gl/context.hpp> #include <mbgl/util/default_thread_pool.hpp> @@ -539,8 +540,8 @@ TEST(Map, DontLoadUnneededTiles) { TEST(Map, TEST_DISABLED_ON_CI(ContinuousRendering)) { util::RunLoop runLoop; - HeadlessBackend backend { test::sharedDisplay() }; - BackendScope scope(backend); + HeadlessBackend backend; + BackendScope scope { backend }; OffscreenView view { backend.getContext() }; ThreadPool threadPool { 4 }; DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets"); diff --git a/test/map/prefetch.test.cpp b/test/map/prefetch.test.cpp index c3ff04acfc..436bdc3b63 100644 --- a/test/map/prefetch.test.cpp +++ b/test/map/prefetch.test.cpp @@ -24,7 +24,7 @@ using namespace std::literals::string_literals; TEST(Map, PrefetchTiles) { util::RunLoop runLoop; - HeadlessBackend backend(test::sharedDisplay()); + HeadlessBackend backend; BackendScope scope(backend); OffscreenView view(backend.getContext(), { 512, 512 }); ThreadPool threadPool(4); diff --git a/test/src/mbgl/test/util.cpp b/test/src/mbgl/test/util.cpp index f3b0bbc96f..0b1034e315 100644 --- a/test/src/mbgl/test/util.cpp +++ b/test/src/mbgl/test/util.cpp @@ -2,7 +2,6 @@ #include <mbgl/map/map.hpp> #include <mbgl/gl/offscreen_view.hpp> -#include <mbgl/gl/headless_display.hpp> #include <mbgl/util/logging.hpp> #include <mbgl/util/image.hpp> #include <mbgl/util/io.hpp> @@ -99,11 +98,6 @@ Server::~Server() { } } -std::shared_ptr<HeadlessDisplay> sharedDisplay() { - static auto display = std::make_shared<HeadlessDisplay>(); - return display; -} - PremultipliedImage render(Map& map, OffscreenView& view) { PremultipliedImage result; map.renderStill([&](std::exception_ptr) { diff --git a/test/src/mbgl/test/util.hpp b/test/src/mbgl/test/util.hpp index 8673155fe4..9c015f1641 100644 --- a/test/src/mbgl/test/util.hpp +++ b/test/src/mbgl/test/util.hpp @@ -70,8 +70,6 @@ private: int fd = -1; }; -std::shared_ptr<HeadlessDisplay> sharedDisplay(); - PremultipliedImage render(Map&, OffscreenView&); void checkImage(const std::string& base, diff --git a/test/tile/annotation_tile.test.cpp b/test/tile/annotation_tile.test.cpp index 50f1facc10..c58b980ecd 100644 --- a/test/tile/annotation_tile.test.cpp +++ b/test/tile/annotation_tile.test.cpp @@ -29,7 +29,7 @@ public: ThreadPool threadPool { 1 }; style::Style style { loop, fileSource, 1 }; AnnotationManager annotationManager { style }; - HeadlessBackend backend { test::sharedDisplay() }; + HeadlessBackend backend; BackendScope scope { backend }; RenderStyle renderStyle { threadPool, fileSource }; ImageManager imageManager; diff --git a/test/util/memory.test.cpp b/test/util/memory.test.cpp index cb333129d8..ad7982ce57 100644 --- a/test/util/memory.test.cpp +++ b/test/util/memory.test.cpp @@ -38,7 +38,7 @@ public: } util::RunLoop runLoop; - HeadlessBackend backend { test::sharedDisplay() }; + HeadlessBackend backend; BackendScope scope { backend }; OffscreenView view { backend.getContext(), { 512, 512 } }; StubFileSource fileSource; diff --git a/test/util/offscreen_texture.test.cpp b/test/util/offscreen_texture.test.cpp index d8a409de36..d4efd75689 100644 --- a/test/util/offscreen_texture.test.cpp +++ b/test/util/offscreen_texture.test.cpp @@ -11,7 +11,7 @@ using namespace mbgl; TEST(OffscreenTexture, EmptyRed) { - HeadlessBackend backend { test::sharedDisplay() }; + HeadlessBackend backend; BackendScope scope { backend }; OffscreenView view(backend.getContext(), { 512, 256 }); @@ -74,7 +74,7 @@ struct Buffer { TEST(OffscreenTexture, RenderToTexture) { - HeadlessBackend backend { test::sharedDisplay() }; + HeadlessBackend backend; BackendScope scope { backend }; auto& context = backend.getContext(); |