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 /test/map | |
parent | 11933f6ab81248a884db3b1f69be714a60b6a86c (diff) | |
download | qtlocation-mapboxgl-32bd1d54fa777035920b58e653905e4592ef187c.tar.gz |
[node, tests] Consolidate headless rendering logic in HeadlessFrontend
Diffstat (limited to 'test/map')
-rw-r--r-- | test/map/map.test.cpp | 94 | ||||
-rw-r--r-- | test/map/prefetch.test.cpp | 16 |
2 files changed, 42 insertions, 68 deletions
diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index 3e8f8696e1..95d652f2af 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -4,16 +4,12 @@ #include <mbgl/test/fixture_log_observer.hpp> #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/gl/headless_frontend.hpp> #include <mbgl/util/default_thread_pool.hpp> #include <mbgl/storage/network_status.hpp> #include <mbgl/storage/default_file_source.hpp> #include <mbgl/storage/online_file_source.hpp> -#include <mbgl/renderer/renderer.hpp> #include <mbgl/util/image.hpp> #include <mbgl/util/io.hpp> #include <mbgl/util/run_loop.hpp> @@ -21,7 +17,6 @@ #include <mbgl/style/style.hpp> #include <mbgl/style/image.hpp> #include <mbgl/style/layers/background_layer.hpp> -#include <mbgl/test/stub_renderer_frontend.hpp> #include <mbgl/util/color.hpp> using namespace mbgl; @@ -53,30 +48,33 @@ public: didFinishLoadingStyleCallback(); } } - + + void onDidFinishRenderingFrame(RenderMode mode) final { + if (didFinishRenderingFrame) { + didFinishRenderingFrame(mode); + } + } + std::function<void()> onWillStartLoadingMapCallback; std::function<void()> onDidFinishLoadingMapCallback; std::function<void()> didFailLoadingMapCallback; std::function<void()> didFinishLoadingStyleCallback; + std::function<void(RenderMode)> didFinishRenderingFrame; }; template <class FileSource = StubFileSource> class MapTest { public: util::RunLoop runLoop; - HeadlessBackend backend; - BackendScope scope { backend }; - OffscreenView view { backend.getContext() }; FileSource fileSource; ThreadPool threadPool { 4 }; StubMapObserver observer; - StubRendererFrontend rendererFrontend; + HeadlessFrontend frontend; Map map; MapTest(float pixelRatio = 1, MapMode mode = MapMode::Still) - : rendererFrontend( - std::make_unique<Renderer>(backend, pixelRatio, fileSource, threadPool), view) - , map(rendererFrontend, observer, view.getSize(), pixelRatio, fileSource, threadPool, mode) { + : frontend(pixelRatio, fileSource, threadPool) + , map(frontend, observer, frontend.getSize(), pixelRatio, fileSource, threadPool, mode) { } template <typename T = FileSource> @@ -84,10 +82,8 @@ public: float pixelRatio = 1, MapMode mode = MapMode::Still, typename std::enable_if<std::is_same<T, DefaultFileSource>::value>::type* = 0) : fileSource { cachePath, assetRoot } - , rendererFrontend( - std::make_unique<Renderer>(backend, pixelRatio, fileSource, threadPool), - view) - , map(rendererFrontend, observer, view.getSize(), pixelRatio, fileSource, threadPool, mode) { + , frontend(pixelRatio, fileSource, threadPool) + , map(frontend, observer, frontend.getSize(), pixelRatio, fileSource, threadPool, mode) { } }; @@ -157,7 +153,7 @@ TEST(Map, Offline) { test.map.getStyle().loadURL(prefix + "style.json"); test::checkImage("test/fixtures/map/offline", - test::render(test.map, test.view), + test.frontend.render(test.map), 0.0015, 0.1); @@ -296,7 +292,7 @@ TEST(Map, StyleExpiredWithRender) { test.fileSource.respond(Resource::Style, response); EXPECT_EQ(1u, test.fileSource.requests.size()); - test::render(test.map, test.view); + test.frontend.render(test.map); EXPECT_EQ(1u, test.fileSource.requests.size()); test.fileSource.respond(Resource::Style, response); @@ -406,16 +402,18 @@ TEST(Map, AddLayer) { layer->setBackgroundColor({ { 1, 0, 0, 1 } }); test.map.getStyle().addLayer(std::move(layer)); - test::checkImage("test/fixtures/map/add_layer", test::render(test.map, test.view)); + test::checkImage("test/fixtures/map/add_layer", test.frontend.render(test.map)); } TEST(Map, WithoutVAOExtension) { MapTest<DefaultFileSource> test { ":memory:", "test/fixtures/api/assets" }; - test.backend.getContext().disableVAOExtension = true; + + BackendScope scope { *test.frontend.getBackend() }; + test.frontend.getBackend()->getContext().disableVAOExtension = true; test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json")); - test::checkImage("test/fixtures/map/no_vao", test::render(test.map, test.view), 0.002); + test::checkImage("test/fixtures/map/no_vao", test.frontend.render(test.map), 0.002); } TEST(Map, RemoveLayer) { @@ -428,7 +426,7 @@ TEST(Map, RemoveLayer) { test.map.getStyle().addLayer(std::move(layer)); test.map.getStyle().removeLayer("background"); - test::checkImage("test/fixtures/map/remove_layer", test::render(test.map, test.view)); + test::checkImage("test/fixtures/map/remove_layer", test.frontend.render(test.map)); } TEST(Map, DisabledSources) { @@ -486,9 +484,9 @@ TEST(Map, DisabledSources) { } )STYLE"); - test::checkImage("test/fixtures/map/disabled_layers/first", test::render(test.map, test.view)); + test::checkImage("test/fixtures/map/disabled_layers/first", test.frontend.render(test.map)); test.map.setZoom(0.5); - test::checkImage("test/fixtures/map/disabled_layers/second", test::render(test.map, test.view)); + test::checkImage("test/fixtures/map/disabled_layers/second", test.frontend.render(test.map)); } TEST(Map, DontLoadUnneededTiles) { @@ -533,16 +531,13 @@ TEST(Map, DontLoadUnneededTiles) { const double z = double(zoom) / 10; tiles.clear(); test.map.setZoom(z); - test::render(test.map, test.view); + test.frontend.render(test.map); EXPECT_EQ(referenceTiles[z], tiles) << "zoom level " << z; } } TEST(Map, TEST_DISABLED_ON_CI(ContinuousRendering)) { util::RunLoop runLoop; - HeadlessBackend backend; - BackendScope scope { backend }; - OffscreenView view { backend.getContext() }; ThreadPool threadPool { 4 }; DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets"); float pixelRatio { 1 }; @@ -551,39 +546,26 @@ TEST(Map, TEST_DISABLED_ON_CI(ContinuousRendering)) { util::Timer emergencyShutoff; emergencyShutoff.start(10s, 0s, [&] { - util::RunLoop::Get()->stop(); + runLoop.stop(); FAIL() << "Did not stop rendering"; }); util::Timer timer; - std::function<bool()> isLoaded; - - StubRendererFrontend rendererFrontend { - std::make_unique<Renderer>(backend, pixelRatio, fileSource, threadPool), - [&](StubRendererFrontend& bridge) { - if (isLoaded()) { - // Abort the test after 1 second after the map loading fully. Note that a "fully loaded - // map" doesn't mean that we won't render anymore: we could still render fade in/fade - // out or other animations. - // If we are continuing to render indefinitely, the emergency shutoff above will trigger - // and the test will fail since the regular time will be constantly reset. - timer.start(1s, 0s, [&] { - util::RunLoop::Get()->stop(); - }); - } - - bridge.render(view); - } - }; - - Map map(rendererFrontend, MapObserver::nullObserver(), view.getSize(), pixelRatio, fileSource, - threadPool, MapMode::Continuous); + HeadlessFrontend frontend(pixelRatio, fileSource, threadPool); - isLoaded = [&] { - return map.isFullyLoaded(); + StubMapObserver observer; + observer.didFinishRenderingFrame = [&] (MapObserver::RenderMode) { + // Start a timer that ends the test one second from now. If we are continuing to render + // indefinitely, the timer will be constantly restarted and never trigger. Instead, the + // emergency shutoff above will trigger, failing the test. + timer.start(1s, 0s, [&] { + runLoop.stop(); + }); }; + Map map(frontend, observer, frontend.getSize(), pixelRatio, fileSource, threadPool, MapMode::Continuous); map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json")); - util::RunLoop::Get()->run(); + + runLoop.run(); } diff --git a/test/map/prefetch.test.cpp b/test/map/prefetch.test.cpp index 436bdc3b63..5c9a22d1bf 100644 --- a/test/map/prefetch.test.cpp +++ b/test/map/prefetch.test.cpp @@ -1,18 +1,14 @@ #include <mbgl/test/util.hpp> #include <mbgl/test/stub_file_source.hpp> -#include <mbgl/gl/headless_backend.hpp> -#include <mbgl/gl/offscreen_view.hpp> #include <mbgl/map/map.hpp> -#include <mbgl/renderer/renderer.hpp> -#include <mbgl/renderer/backend_scope.hpp> +#include <mbgl/gl/headless_frontend.hpp> #include <mbgl/storage/default_file_source.hpp> #include <mbgl/style/style.hpp> #include <mbgl/util/default_thread_pool.hpp> #include <mbgl/util/image.hpp> #include <mbgl/util/io.hpp> #include <mbgl/util/run_loop.hpp> -#include <mbgl/test/stub_renderer_frontend.hpp> #include <algorithm> #include <string> @@ -24,14 +20,10 @@ using namespace std::literals::string_literals; TEST(Map, PrefetchTiles) { util::RunLoop runLoop; - HeadlessBackend backend; - BackendScope scope(backend); - OffscreenView view(backend.getContext(), { 512, 512 }); ThreadPool threadPool(4); StubFileSource fileSource; - StubRendererFrontend rendererFrontend { - std::make_unique<Renderer>(backend, 1, fileSource, threadPool), view }; - Map map(rendererFrontend, MapObserver::nullObserver(), view.getSize(), 1, fileSource, threadPool, MapMode::Still); + HeadlessFrontend frontend { { 512, 512 }, 1, fileSource, threadPool }; + Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), 1, fileSource, threadPool, MapMode::Still); std::vector<int> tiles; @@ -65,7 +57,7 @@ TEST(Map, PrefetchTiles) { map.setLatLngZoom({ 40.726989, -73.992857 }, zoom); // Manhattan // Should always render the ideal tiles (i.e. a green map) - test::checkImage("test/fixtures/map/prefetch", test::render(map, view)); + test::checkImage("test/fixtures/map/prefetch", frontend.render(map)); ASSERT_TRUE(std::is_permutation(tiles.begin(), tiles.end(), expected.begin())); ASSERT_FALSE(tiles.empty()); |