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 /test | |
parent | 5cc390d694fc7510d445310d8eb9e32429a5e67b (diff) | |
download | qtlocation-mapboxgl-a4d259c33f9bb890bba97fd89552720e3e0ec09b.tar.gz |
[core] move gl::Context to Backend and refactor View
Diffstat (limited to 'test')
-rw-r--r-- | test/api/annotations.test.cpp | 40 | ||||
-rw-r--r-- | test/api/api_misuse.test.cpp | 18 | ||||
-rw-r--r-- | test/api/custom_layer.test.cpp | 8 | ||||
-rw-r--r-- | test/api/query.test.cpp | 8 | ||||
-rw-r--r-- | test/api/render_missing.test.cpp | 8 | ||||
-rw-r--r-- | test/api/repeated_render.test.cpp | 14 | ||||
-rw-r--r-- | test/gl/object.test.cpp | 14 | ||||
-rw-r--r-- | test/map/map.test.cpp | 70 | ||||
-rw-r--r-- | test/src/mbgl/test/util.cpp | 7 | ||||
-rw-r--r-- | test/src/mbgl/test/util.hpp | 3 | ||||
-rw-r--r-- | test/util/memory.test.cpp | 42 | ||||
-rw-r--r-- | test/util/offscreen_texture.test.cpp | 20 |
12 files changed, 111 insertions, 141 deletions
diff --git a/test/api/annotations.test.cpp b/test/api/annotations.test.cpp index 53c0182ee9..2c875796bd 100644 --- a/test/api/annotations.test.cpp +++ b/test/api/annotations.test.cpp @@ -6,7 +6,7 @@ #include <mbgl/sprite/sprite_image.hpp> #include <mbgl/map/map.hpp> #include <mbgl/platform/default/headless_backend.hpp> -#include <mbgl/platform/default/headless_view.hpp> +#include <mbgl/platform/default/offscreen_view.hpp> #include <mbgl/util/io.hpp> #include <mbgl/util/run_loop.hpp> #include <mbgl/util/color.hpp> @@ -24,14 +24,14 @@ class AnnotationTest { public: util::RunLoop loop; HeadlessBackend backend; - HeadlessView view; + OffscreenView view{ backend.getContext() }; StubFileSource fileSource; ThreadPool threadPool { 4 }; - Map map { backend, view, view.getPixelRatio(), fileSource, threadPool, MapMode::Still }; + Map map { backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still }; void checkRendering(const char * name) { test::checkImage(std::string("test/fixtures/annotations/") + name, - test::render(map), 0.0002, 0.1); + test::render(map, view), 0.0002, 0.1); } }; @@ -162,7 +162,7 @@ TEST(Annotations, AddMultiple) { test.map.addAnnotationIcon("default_marker", namedMarker("default_marker.png")); test.map.addAnnotation(SymbolAnnotation { Point<double> { -10, 0 }, "default_marker" }); - test::render(test.map); + test::render(test.map, test.view); test.map.addAnnotation(SymbolAnnotation { Point<double> { 10, 0 }, "default_marker" }); test.checkRendering("add_multiple"); @@ -172,7 +172,7 @@ TEST(Annotations, NonImmediateAdd) { AnnotationTest test; test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json")); - test::render(test.map); + test::render(test.map, test.view); Polygon<double> polygon = {{ {{ { 0, 0 }, { 0, 45 }, { 45, 45 }, { 45, 0 } }} }}; FillAnnotation annotation { polygon }; @@ -190,7 +190,7 @@ TEST(Annotations, UpdateSymbolAnnotationGeometry) { test.map.addAnnotationIcon("flipped_marker", namedMarker("flipped_marker.png")); AnnotationID point = test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" }); - test::render(test.map); + test::render(test.map, test.view); test.map.updateAnnotation(point, SymbolAnnotation { Point<double> { -10, 0 }, "default_marker" }); test.checkRendering("update_point"); @@ -204,7 +204,7 @@ TEST(Annotations, UpdateSymbolAnnotationIcon) { test.map.addAnnotationIcon("flipped_marker", namedMarker("flipped_marker.png")); AnnotationID point = test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" }); - test::render(test.map); + test::render(test.map, test.view); test.map.updateAnnotation(point, SymbolAnnotation { Point<double> { 0, 0 }, "flipped_marker" }); test.checkRendering("update_icon"); @@ -220,7 +220,7 @@ TEST(Annotations, UpdateLineAnnotationGeometry) { test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json")); AnnotationID line = test.map.addAnnotation(annotation); - test::render(test.map); + test::render(test.map, test.view); annotation.geometry = LineString<double> {{ { 0, 0 }, { -45, -45 } }}; test.map.updateAnnotation(line, annotation); @@ -237,7 +237,7 @@ TEST(Annotations, UpdateLineAnnotationStyle) { test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json")); AnnotationID line = test.map.addAnnotation(annotation); - test::render(test.map); + test::render(test.map, test.view); annotation.color = { { 0, 255, 0, 1 } }; annotation.width = { 2 }; @@ -254,7 +254,7 @@ TEST(Annotations, UpdateFillAnnotationGeometry) { test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json")); AnnotationID fill = test.map.addAnnotation(annotation); - test::render(test.map); + test::render(test.map, test.view); annotation.geometry = Polygon<double> {{ {{ { 0, 0 }, { 0, 45 }, { 45, 0 } }} }}; test.map.updateAnnotation(fill, annotation); @@ -271,7 +271,7 @@ TEST(Annotations, UpdateFillAnnotationStyle) { test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json")); AnnotationID fill = test.map.addAnnotation(annotation); - test::render(test.map); + test::render(test.map, test.view); annotation.color = { { 0, 255, 0, 1 } }; test.map.updateAnnotation(fill, annotation); @@ -285,7 +285,7 @@ TEST(Annotations, RemovePoint) { test.map.addAnnotationIcon("default_marker", namedMarker("default_marker.png")); AnnotationID point = test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" }); - test::render(test.map); + test::render(test.map, test.view); test.map.removeAnnotation(point); test.checkRendering("remove_point"); @@ -302,7 +302,7 @@ TEST(Annotations, RemoveShape) { test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json")); AnnotationID shape = test.map.addAnnotation(annotation); - test::render(test.map); + test::render(test.map, test.view); test.map.removeAnnotation(shape); test.checkRendering("remove_shape"); @@ -314,7 +314,7 @@ TEST(Annotations, ImmediateRemoveShape) { test.map.removeAnnotation(test.map.addAnnotation(LineAnnotation { LineString<double>() })); test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json")); - test::render(test.map); + test::render(test.map, test.view); } TEST(Annotations, SwitchStyle) { @@ -324,7 +324,7 @@ TEST(Annotations, SwitchStyle) { test.map.addAnnotationIcon("default_marker", namedMarker("default_marker.png")); test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" }); - test::render(test.map); + test::render(test.map, test.view); test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json")); test.checkRendering("switch_style"); @@ -338,7 +338,7 @@ TEST(Annotations, QueryRenderedFeatures) { test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" }); test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 50 }, "default_marker" }); - test::render(test.map); + test::render(test.map, test.view); auto features = test.map.queryRenderedFeatures(test.map.pixelForLatLng({ 0, 0 })); EXPECT_EQ(features.size(), 1u); @@ -370,7 +370,7 @@ TEST(Annotations, QueryFractionalZoomLevels) { test.map.setLatLngZoom({ 5, 5 }, 0); for (uint16_t zoomSteps = 10; zoomSteps <= 20; ++zoomSteps) { test.map.setZoom(zoomSteps / 10.0); - test::render(test.map); + test::render(test.map, test.view); auto features = test.map.queryRenderedFeatures(box); // Filter out repeated features. @@ -402,7 +402,7 @@ TEST(Annotations, VisibleFeatures) { // Change bearing *after* adding annotations causes them to be reordered. test.map.setBearing(45); - test::render(test.map); + test::render(test.map, test.view); auto features = test.map.queryRenderedFeatures(box); auto sortID = [](const Feature& lhs, const Feature& rhs) { return lhs.id < rhs.id; }; @@ -413,7 +413,7 @@ TEST(Annotations, VisibleFeatures) { test.map.setBearing(0); test.map.setZoom(4); - test::render(test.map); + test::render(test.map, test.view); features = test.map.queryRenderedFeatures(box); std::sort(features.begin(), features.end(), sortID); features.erase(std::unique(features.begin(), features.end(), sameID), features.end()); diff --git a/test/api/api_misuse.test.cpp b/test/api/api_misuse.test.cpp index f11363fa3c..eb271b0258 100644 --- a/test/api/api_misuse.test.cpp +++ b/test/api/api_misuse.test.cpp @@ -4,7 +4,7 @@ #include <mbgl/map/map.hpp> #include <mbgl/platform/default/headless_backend.hpp> -#include <mbgl/platform/default/headless_view.hpp> +#include <mbgl/platform/default/offscreen_view.hpp> #include <mbgl/storage/online_file_source.hpp> #include <mbgl/platform/default/thread_pool.hpp> #include <mbgl/util/exception.hpp> @@ -21,14 +21,13 @@ TEST(API, RenderWithoutCallback) { util::RunLoop loop; HeadlessBackend backend; - HeadlessView view; - view.resize(128, 512); + OffscreenView view(backend.getContext(), {{ 128, 512 }}); StubFileSource fileSource; ThreadPool threadPool(4); - std::unique_ptr<Map> map = std::make_unique<Map>(backend, view, view.getPixelRatio(), - fileSource, threadPool, MapMode::Still); - map->renderStill(nullptr); + std::unique_ptr<Map> map = + std::make_unique<Map>(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still); + map->renderStill(view, nullptr); // Force Map thread to join. map.reset(); @@ -47,15 +46,14 @@ TEST(API, RenderWithoutStyle) { util::RunLoop loop; HeadlessBackend backend; - HeadlessView view; - view.resize(128, 512); + OffscreenView view(backend.getContext(), {{ 128, 512 }}); StubFileSource fileSource; ThreadPool threadPool(4); - Map map(backend, view, view.getPixelRatio(), fileSource, threadPool, MapMode::Still); + Map map(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still); std::exception_ptr error; - map.renderStill([&](std::exception_ptr error_, PremultipliedImage&&) { + map.renderStill(view, [&](std::exception_ptr error_) { error = error_; loop.stop(); }); diff --git a/test/api/custom_layer.test.cpp b/test/api/custom_layer.test.cpp index 84ae780174..70de102b80 100644 --- a/test/api/custom_layer.test.cpp +++ b/test/api/custom_layer.test.cpp @@ -3,7 +3,7 @@ #include <mbgl/gl/gl.hpp> #include <mbgl/map/map.hpp> #include <mbgl/platform/default/headless_backend.hpp> -#include <mbgl/platform/default/headless_view.hpp> +#include <mbgl/platform/default/offscreen_view.hpp> #include <mbgl/platform/default/thread_pool.hpp> #include <mbgl/storage/default_file_source.hpp> #include <mbgl/style/layers/custom_layer.hpp> @@ -86,7 +86,7 @@ TEST(CustomLayer, Basic) { util::RunLoop loop; HeadlessBackend backend; - HeadlessView view; + OffscreenView view(backend.getContext()); #ifdef MBGL_ASSET_ZIP // Regenerate with `cd test/fixtures/api/ && zip -r assets.zip assets/` @@ -97,7 +97,7 @@ TEST(CustomLayer, Basic) { ThreadPool threadPool(4); - Map map(backend, view, view.getPixelRatio(), fileSource, threadPool, MapMode::Still); + Map map(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still); map.setStyleJSON(util::read_file("test/fixtures/api/water.json")); map.setLatLngZoom({ 37.8, -122.5 }, 10); map.addLayer(std::make_unique<CustomLayer>( @@ -117,5 +117,5 @@ TEST(CustomLayer, Basic) { layer->setFillColor(Color{ 1.0, 1.0, 0.0, 1.0 }); map.addLayer(std::move(layer)); - test::checkImage("test/fixtures/custom_layer/basic", test::render(map), 0.0006, 0.1); + test::checkImage("test/fixtures/custom_layer/basic", test::render(map, view), 0.0006, 0.1); } diff --git a/test/api/query.test.cpp b/test/api/query.test.cpp index d989d222c5..8e59c19afc 100644 --- a/test/api/query.test.cpp +++ b/test/api/query.test.cpp @@ -1,6 +1,6 @@ #include <mbgl/map/map.hpp> #include <mbgl/platform/default/headless_backend.hpp> -#include <mbgl/platform/default/headless_view.hpp> +#include <mbgl/platform/default/offscreen_view.hpp> #include <mbgl/platform/default/thread_pool.hpp> #include <mbgl/sprite/sprite_image.hpp> #include <mbgl/test/stub_file_source.hpp> @@ -22,15 +22,15 @@ public: map.setStyleJSON(util::read_file("test/fixtures/api/query_style.json")); map.addImage("test-icon", std::move(image)); - test::render(map); + test::render(map, view); } util::RunLoop loop; HeadlessBackend backend; - HeadlessView view; + OffscreenView view { backend.getContext() }; StubFileSource fileSource; ThreadPool threadPool { 4 }; - Map map { backend, view, view.getPixelRatio(), fileSource, threadPool, MapMode::Still }; + Map map { backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still }; }; } // end namespace diff --git a/test/api/render_missing.test.cpp b/test/api/render_missing.test.cpp index 8123070282..366d71e67d 100644 --- a/test/api/render_missing.test.cpp +++ b/test/api/render_missing.test.cpp @@ -3,7 +3,7 @@ #include <mbgl/map/map.hpp> #include <mbgl/platform/default/headless_backend.hpp> -#include <mbgl/platform/default/headless_view.hpp> +#include <mbgl/platform/default/offscreen_view.hpp> #include <mbgl/platform/default/thread_pool.hpp> #include <mbgl/storage/default_file_source.hpp> #include <mbgl/util/image.hpp> @@ -26,7 +26,7 @@ TEST(API, TEST_REQUIRES_SERVER(RenderMissingTile)) { const auto style = util::read_file("test/fixtures/api/water_missing_tiles.json"); HeadlessBackend backend; - HeadlessView view(1, 256, 512); + OffscreenView view(backend.getContext(), {{ 256, 512 }}); #ifdef MBGL_ASSET_ZIP // Regenerate with `cd test/fixtures/api/ && zip -r assets.zip assets/` DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets.zip"); @@ -38,14 +38,14 @@ TEST(API, TEST_REQUIRES_SERVER(RenderMissingTile)) { Log::setObserver(std::make_unique<FixtureLogObserver>()); - Map map(backend, view, view.getPixelRatio(), fileSource, threadPool, MapMode::Still); + Map map(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still); std::string message; // This host does not respond (== connection error). // Are you seeing this test fail? Make sure you don't have a server running on port 3001! map.setStyleJSON(style); - map.renderStill([&](std::exception_ptr err, PremultipliedImage&&) { + map.renderStill(view, [&](std::exception_ptr err) { ASSERT_TRUE(err.operator bool()); try { std::rethrow_exception(err); diff --git a/test/api/repeated_render.test.cpp b/test/api/repeated_render.test.cpp index 5bc57198bd..715b49b289 100644 --- a/test/api/repeated_render.test.cpp +++ b/test/api/repeated_render.test.cpp @@ -3,7 +3,7 @@ #include <mbgl/map/map.hpp> #include <mbgl/platform/default/headless_backend.hpp> -#include <mbgl/platform/default/headless_view.hpp> +#include <mbgl/platform/default/offscreen_view.hpp> #include <mbgl/platform/default/thread_pool.hpp> #include <mbgl/storage/default_file_source.hpp> #include <mbgl/util/image.hpp> @@ -20,7 +20,7 @@ TEST(API, RepeatedRender) { const auto style = util::read_file("test/fixtures/api/water.json"); HeadlessBackend backend; - HeadlessView view(1, 256, 512); + OffscreenView view(backend.getContext(), {{ 256, 512 }}); #ifdef MBGL_ASSET_ZIP // Regenerate with `cd test/fixtures/api/ && zip -r assets.zip assets/` DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets.zip"); @@ -32,13 +32,13 @@ TEST(API, RepeatedRender) { Log::setObserver(std::make_unique<FixtureLogObserver>()); - Map map(backend, view, view.getPixelRatio(), fileSource, threadPool, MapMode::Still); + Map map(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still); { map.setStyleJSON(style); PremultipliedImage result; - map.renderStill([&result](std::exception_ptr, PremultipliedImage&& image) { - result = std::move(image); + map.renderStill(view, [&](std::exception_ptr) { + result = view.readStillImage(); }); while (!result.size()) { @@ -55,8 +55,8 @@ TEST(API, RepeatedRender) { { map.setStyleJSON(style); PremultipliedImage result; - map.renderStill([&result](std::exception_ptr, PremultipliedImage&& image) { - result = std::move(image); + map.renderStill(view, [&](std::exception_ptr) { + result = view.readStillImage(); }); while (!result.size()) { diff --git a/test/gl/object.test.cpp b/test/gl/object.test.cpp index 1f9d48cff7..a3457d28c6 100644 --- a/test/gl/object.test.cpp +++ b/test/gl/object.test.cpp @@ -1,7 +1,7 @@ #include <mbgl/test/util.hpp> #include <mbgl/platform/default/headless_backend.hpp> -#include <mbgl/platform/default/headless_view.hpp> +#include <mbgl/platform/default/offscreen_view.hpp> #include <mbgl/gl/gl.hpp> #include <mbgl/gl/context.hpp> @@ -43,11 +43,8 @@ TEST(GLObject, Value) { auto object = std::make_unique<mbgl::gl::State<MockGLObject>>(); EXPECT_EQ(object->getCurrentValue(), false); - EXPECT_FALSE(object->isDirty()); - EXPECT_FALSE(setFlag); - - object->setDirty(); EXPECT_TRUE(object->isDirty()); + EXPECT_FALSE(setFlag); *object = false; EXPECT_EQ(object->getCurrentValue(), false); @@ -59,16 +56,11 @@ TEST(GLObject, Value) { EXPECT_EQ(object->getCurrentValue(), true); EXPECT_FALSE(object->isDirty()); EXPECT_TRUE(setFlag); - - object->reset(); - EXPECT_EQ(object->getCurrentValue(), false); - EXPECT_FALSE(object->isDirty()); - EXPECT_TRUE(setFlag); } TEST(GLObject, Store) { mbgl::HeadlessBackend backend; - mbgl::HeadlessView view; + mbgl::OffscreenView view(backend.getContext()); mbgl::gl::Context context; EXPECT_TRUE(context.empty()); diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index a5d634e77a..97a09e94a0 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -5,7 +5,7 @@ #include <mbgl/map/map.hpp> #include <mbgl/platform/default/headless_backend.hpp> -#include <mbgl/platform/default/headless_view.hpp> +#include <mbgl/platform/default/offscreen_view.hpp> #include <mbgl/platform/default/thread_pool.hpp> #include <mbgl/sprite/sprite_image.hpp> #include <mbgl/storage/network_status.hpp> @@ -23,15 +23,14 @@ using namespace std::literals::string_literals; struct MapTest { util::RunLoop runLoop; HeadlessBackend backend; - HeadlessView view; + OffscreenView view { backend.getContext() }; StubFileSource fileSource; ThreadPool threadPool { 4 }; }; TEST(Map, LatLngBehavior) { MapTest test; - Map map(test.backend, test.view, test.view.getPixelRatio(), test.fileSource, test.threadPool, - MapMode::Still); + Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); map.setStyleJSON(util::read_file("test/fixtures/api/empty.json")); @@ -65,12 +64,11 @@ TEST(Map, Offline) { fileSource.put(Resource::glyphs(prefix + "{fontstack}/{range}.pbf", {{"Helvetica"}}, {0, 255}), expiredItem("glyph.pbf")); NetworkStatus::Set(NetworkStatus::Status::Offline); - Map map(test.backend, test.view, test.view.getPixelRatio(), fileSource, test.threadPool, - MapMode::Still); + Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); map.setStyleURL(prefix + "style.json"); test::checkImage("test/fixtures/map/offline", - test::render(map), + test::render(map, test.view), 0.0015, 0.1); @@ -90,8 +88,8 @@ TEST(Map, SetStyleInvalidJSON) { }); { - Map map(test.backend, test.view, test.view.getPixelRatio(), test.fileSource, - test.threadPool, MapMode::Still); + Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, + MapMode::Still); map.setStyleJSON("invalid"); } @@ -122,8 +120,7 @@ TEST(Map, SetStyleInvalidURL) { } }); - Map map(test.backend, test.view, test.view.getPixelRatio(), test.fileSource, test.threadPool, - MapMode::Still); + Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); map.setStyleURL("mapbox://bar"); test.runLoop.run(); @@ -132,8 +129,7 @@ TEST(Map, SetStyleInvalidURL) { TEST(Map, DoubleStyleLoad) { MapTest test; - Map map(test.backend, test.view, test.view.getPixelRatio(), test.fileSource, test.threadPool, - MapMode::Still); + Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); map.setStyleJSON(""); map.setStyleJSON(""); } @@ -144,8 +140,7 @@ TEST(Map, StyleFresh) { MapTest test; FakeFileSource fileSource; - Map map(test.backend, test.view, test.view.getPixelRatio(), fileSource, test.threadPool, - MapMode::Still); + Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); map.setStyleURL("mapbox://styles/test"); EXPECT_EQ(1u, fileSource.requests.size()); @@ -165,8 +160,7 @@ TEST(Map, StyleExpired) { MapTest test; FakeFileSource fileSource; - Map map(test.backend, test.view, test.view.getPixelRatio(), fileSource, test.threadPool, - MapMode::Still); + Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); map.setStyleURL("mapbox://styles/test"); EXPECT_EQ(1u, fileSource.requests.size()); @@ -193,8 +187,7 @@ TEST(Map, StyleExpiredWithAnnotations) { MapTest test; FakeFileSource fileSource; - Map map(test.backend, test.view, test.view.getPixelRatio(), fileSource, test.threadPool, - MapMode::Still); + Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); map.setStyleURL("mapbox://styles/test"); EXPECT_EQ(1u, fileSource.requests.size()); @@ -218,8 +211,7 @@ TEST(Map, StyleEarlyMutation) { MapTest test; FakeFileSource fileSource; - Map map(test.backend, test.view, test.view.getPixelRatio(), fileSource, test.threadPool, - MapMode::Still); + Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); map.setStyleURL("mapbox://styles/test"); map.addLayer(std::make_unique<style::BackgroundLayer>("bg")); @@ -233,8 +225,7 @@ TEST(Map, StyleEarlyMutation) { TEST(Map, StyleLoadedSignal) { MapTest test; - Map map(test.backend, test.view, test.view.getPixelRatio(), test.fileSource, test.threadPool, - MapMode::Still); + Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); // The map should emit a signal on style loaded bool emitted = false; @@ -255,22 +246,20 @@ TEST(Map, StyleLoadedSignal) { TEST(Map, AddLayer) { MapTest test; - Map map(test.backend, test.view, test.view.getPixelRatio(), test.fileSource, test.threadPool, - MapMode::Still); + Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); map.setStyleJSON(util::read_file("test/fixtures/api/empty.json")); auto layer = std::make_unique<BackgroundLayer>("background"); - layer->setBackgroundColor({{ 1, 0, 0, 1 }}); + layer->setBackgroundColor({ { 1, 0, 0, 1 } }); map.addLayer(std::move(layer)); - test::checkImage("test/fixtures/map/add_layer", test::render(map)); + test::checkImage("test/fixtures/map/add_layer", test::render(map, test.view)); } TEST(Map, RemoveLayer) { MapTest test; - Map map(test.backend, test.view, test.view.getPixelRatio(), test.fileSource, test.threadPool, - MapMode::Still); + Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); map.setStyleJSON(util::read_file("test/fixtures/api/empty.json")); auto layer = std::make_unique<BackgroundLayer>("background"); @@ -278,7 +267,7 @@ TEST(Map, RemoveLayer) { map.addLayer(std::move(layer)); map.removeLayer("background"); - test::checkImage("test/fixtures/map/remove_layer", test::render(map)); + test::checkImage("test/fixtures/map/remove_layer", test::render(map, test.view)); } TEST(Map, DisabledSources) { @@ -295,8 +284,7 @@ TEST(Map, DisabledSources) { return {}; }; - Map map(test.backend, test.view, test.view.getPixelRatio(), test.fileSource, test.threadPool, - MapMode::Still); + Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); map.setZoom(1); // This stylesheet has two raster layers, one that starts at zoom 1, the other at zoom 0. @@ -338,16 +326,15 @@ TEST(Map, DisabledSources) { } )STYLE"); - test::checkImage("test/fixtures/map/disabled_layers/first", test::render(map)); + test::checkImage("test/fixtures/map/disabled_layers/first", test::render(map, test.view)); map.setZoom(0.5); - test::checkImage("test/fixtures/map/disabled_layers/second", test::render(map)); + test::checkImage("test/fixtures/map/disabled_layers/second", test::render(map, test.view)); } TEST(Map, Classes) { MapTest test; - Map map(test.backend, test.view, test.view.getPixelRatio(), test.fileSource, test.threadPool, - MapMode::Still); + Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); map.setStyleJSON(util::read_file("test/fixtures/api/empty.json")); EXPECT_FALSE(map.getTransitionOptions().duration); @@ -381,8 +368,7 @@ TEST(Map, Classes) { TEST(Map, AddImage) { MapTest test; - Map map(test.backend, test.view, test.view.getPixelRatio(), test.fileSource, test.threadPool, - MapMode::Still); + Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); auto decoded1 = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png")); auto decoded2 = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png")); auto image1 = std::make_unique<SpriteImage>(std::move(decoded1), 1.0); @@ -393,20 +379,18 @@ TEST(Map, AddImage) { map.setStyleJSON(util::read_file("test/fixtures/api/icon_style.json")); map.addImage("test-icon", std::move(image2)); - test::checkImage("test/fixtures/map/add_icon", test::render(map)); + test::checkImage("test/fixtures/map/add_icon", test::render(map, test.view)); } TEST(Map, RemoveImage) { MapTest test; - Map map(test.backend, test.view, test.view.getPixelRatio(), test.fileSource, test.threadPool, - MapMode::Still); + Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); auto decoded = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png")); auto image = std::make_unique<SpriteImage>(std::move(decoded), 1.0); map.setStyleJSON(util::read_file("test/fixtures/api/icon_style.json")); map.addImage("test-icon", std::move(image)); map.removeImage("test-icon"); - test::checkImage("test/fixtures/map/remove_icon", test::render(map)); + test::checkImage("test/fixtures/map/remove_icon", test::render(map, test.view)); } - diff --git a/test/src/mbgl/test/util.cpp b/test/src/mbgl/test/util.cpp index a674eafeb4..7f98c43dc9 100644 --- a/test/src/mbgl/test/util.cpp +++ b/test/src/mbgl/test/util.cpp @@ -1,6 +1,7 @@ #include <mbgl/test/util.hpp> #include <mbgl/map/map.hpp> +#include <mbgl/platform/default/offscreen_view.hpp> #include <mbgl/platform/log.hpp> #include <mbgl/util/image.hpp> #include <mbgl/util/io.hpp> @@ -97,10 +98,10 @@ Server::~Server() { } } -PremultipliedImage render(Map& map) { +PremultipliedImage render(Map& map, OffscreenView& view) { PremultipliedImage result; - map.renderStill([&result](std::exception_ptr, PremultipliedImage&& image) { - result = std::move(image); + map.renderStill(view, [&](std::exception_ptr) { + result = view.readStillImage(); }); while (!result.size()) { diff --git a/test/src/mbgl/test/util.hpp b/test/src/mbgl/test/util.hpp index ce0069131c..b8ecf175aa 100644 --- a/test/src/mbgl/test/util.hpp +++ b/test/src/mbgl/test/util.hpp @@ -52,6 +52,7 @@ namespace mbgl { class Map; +class OffscreenView; namespace test { @@ -64,7 +65,7 @@ private: int fd = -1; }; -PremultipliedImage render(Map&); +PremultipliedImage render(Map&, OffscreenView&); void checkImage(const std::string& base, const PremultipliedImage& actual, diff --git a/test/util/memory.test.cpp b/test/util/memory.test.cpp index 2ab3a03799..a1e47d6c2b 100644 --- a/test/util/memory.test.cpp +++ b/test/util/memory.test.cpp @@ -3,7 +3,7 @@ #include <mbgl/map/map.hpp> #include <mbgl/platform/default/headless_backend.hpp> -#include <mbgl/platform/default/headless_view.hpp> +#include <mbgl/platform/default/offscreen_view.hpp> #include <mbgl/platform/default/thread_pool.hpp> #include <mbgl/util/io.hpp> #include <mbgl/util/run_loop.hpp> @@ -57,7 +57,7 @@ public: util::RunLoop runLoop; HeadlessBackend backend; - HeadlessView view{ 2 }; + OffscreenView view{ backend.getContext(), {{ 512, 512 }} }; StubFileSource fileSource; ThreadPool threadPool { 4 }; @@ -93,22 +93,20 @@ private: TEST(Memory, Vector) { MemoryTest test; - Map map(test.backend, test.view, test.view.getPixelRatio(), test.fileSource, test.threadPool, - MapMode::Still); + Map map(test.backend, { { 256, 256 } }, 2, test.fileSource, test.threadPool, MapMode::Still); map.setZoom(16); // more map features map.setStyleURL("mapbox://streets"); - test::render(map); + test::render(map, test.view); } TEST(Memory, Raster) { MemoryTest test; - Map map(test.backend, test.view, test.view.getPixelRatio(), test.fileSource, test.threadPool, - MapMode::Still); + Map map(test.backend, { { 256, 256 } }, 2, test.fileSource, test.threadPool, MapMode::Still); map.setStyleURL("mapbox://satellite"); - test::render(map); + test::render(map, test.view); } // This test will measure the size of a Map object @@ -123,19 +121,17 @@ TEST(Memory, Footprint) { MemoryTest test; - auto renderMap = [](Map* map, const char* style){ - map->setZoom(16); - - map->setStyleURL(style); - test::render(*map); + auto renderMap = [&](Map& map, const char* style){ + map.setZoom(16); + map.setStyleURL(style); + test::render(map, test.view); }; // Warm up buffers and cache. for (unsigned i = 0; i < 10; ++i) { - Map map(test.backend, test.view, test.view.getPixelRatio(), test.fileSource, - test.threadPool, MapMode::Still); - renderMap(&map, "mapbox://streets"); - renderMap(&map, "mapbox://satellite"); + Map map(test.backend, {{ 256, 256 }}, 2, test.fileSource, test.threadPool, MapMode::Still); + renderMap(map, "mapbox://streets"); + renderMap(map, "mapbox://satellite"); }; // Process close callbacks, mostly needed by @@ -147,9 +143,9 @@ TEST(Memory, Footprint) { long vectorInitialRSS = getRSS(); for (unsigned i = 0; i < runs; ++i) { - auto vector = std::make_unique<Map>(test.backend, test.view, test.view.getPixelRatio(), - test.fileSource, test.threadPool, MapMode::Still); - renderMap(vector.get(), "mapbox://streets"); + auto vector = std::make_unique<Map>(test.backend, std::array<uint16_t, 2>{ { 256, 256 } }, + 2, test.fileSource, test.threadPool, MapMode::Still); + renderMap(*vector, "mapbox://streets"); maps.push_back(std::move(vector)); }; @@ -157,9 +153,9 @@ TEST(Memory, Footprint) { long rasterInitialRSS = getRSS(); for (unsigned i = 0; i < runs; ++i) { - auto raster = std::make_unique<Map>(test.backend, test.view, test.view.getPixelRatio(), - test.fileSource, test.threadPool, MapMode::Still); - renderMap(raster.get(), "mapbox://satellite"); + auto raster = std::make_unique<Map>(test.backend, std::array<uint16_t, 2>{ { 256, 256 } }, + 2, test.fileSource, test.threadPool, MapMode::Still); + renderMap(*raster, "mapbox://satellite"); maps.push_back(std::move(raster)); }; diff --git a/test/util/offscreen_texture.test.cpp b/test/util/offscreen_texture.test.cpp index e281a3d65b..bd4eab69a8 100644 --- a/test/util/offscreen_texture.test.cpp +++ b/test/util/offscreen_texture.test.cpp @@ -2,7 +2,7 @@ #include <mbgl/gl/context.hpp> #include <mbgl/platform/default/headless_backend.hpp> -#include <mbgl/platform/default/headless_view.hpp> +#include <mbgl/platform/default/offscreen_view.hpp> #include <mbgl/gl/gl.hpp> #include <mbgl/util/offscreen_texture.hpp> @@ -11,7 +11,7 @@ using namespace mbgl; TEST(OffscreenTexture, EmptyRed) { HeadlessBackend backend; - HeadlessView view(1.0f, 512, 256); + OffscreenView view(backend.getContext(), {{ 512, 256 }}); view.bind(); MBGL_CHECK_ERROR(glClearColor(1.0f, 0.0f, 0.0f, 1.0f)); @@ -68,10 +68,7 @@ struct Buffer { TEST(OffscreenTexture, RenderToTexture) { HeadlessBackend backend; - HeadlessView view(1.0f, 512, 256); - view.bind(); - gl::Context context; - context.viewport.setDefaultValue(gl::value::Viewport::Get()); + auto& context = backend.getContext(); MBGL_CHECK_ERROR(glEnable(GL_BLEND)); MBGL_CHECK_ERROR(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); @@ -109,14 +106,17 @@ void main() { // Make sure the texture gets destructed before we call context.reset(); { + OffscreenView view(context, {{ 512, 256 }}); + // First, draw red to the bound FBO. context.clearColor = { 1, 0, 0, 1 }; + view.bind(); MBGL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT)); // Then, create a texture, bind it, and render yellow to that texture. This should not // affect the originally bound FBO. - OffscreenTexture texture; - texture.bind(context, {{ 128, 128 }}); + OffscreenTexture texture(context, {{ 128, 128 }}); + texture.bind(); context.clearColor = { 0, 0, 0, 0 }; MBGL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT)); @@ -128,12 +128,10 @@ void main() { glVertexAttribPointer(paintShader.a_pos, 2, GL_FLOAT, GL_FALSE, 0, nullptr)); MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, 3)); - auto image = view.readStillImage(texture.getSize()); + auto image = texture.readStillImage(); test::checkImage("test/fixtures/offscreen_texture/render-to-texture", image, 0, 0); // Now reset the FBO back to normal and retrieve the original (restored) framebuffer. - context.resetState(); - context.bindFramebuffer.setDirty(); view.bind(); image = view.readStillImage(); |