From 32bd1d54fa777035920b58e653905e4592ef187c Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 21 Jul 2017 16:36:31 -0700 Subject: [node, tests] Consolidate headless rendering logic in HeadlessFrontend --- test/util/memory.test.cpp | 78 +++++++++++++----------------------- test/util/offscreen_texture.test.cpp | 21 +++++----- 2 files changed, 37 insertions(+), 62 deletions(-) (limited to 'test/util') diff --git a/test/util/memory.test.cpp b/test/util/memory.test.cpp index ad7982ce57..54763cd9db 100644 --- a/test/util/memory.test.cpp +++ b/test/util/memory.test.cpp @@ -3,15 +3,11 @@ #include #include -#include -#include -#include +#include #include #include #include #include -#include -#include #include #include @@ -38,9 +34,6 @@ public: } util::RunLoop runLoop; - HeadlessBackend backend; - BackendScope scope { backend }; - OffscreenView view { backend.getContext(), { 512, 512 } }; StubFileSource fileSource; ThreadPool threadPool { 4 }; @@ -77,30 +70,25 @@ TEST(Memory, Vector) { MemoryTest test; float ratio { 2 }; - StubRendererFrontend rendererFrontend { - std::make_unique(test.backend, ratio, test.fileSource, test.threadPool), - test.view }; - Map map(rendererFrontend, MapObserver::nullObserver(), { 256, 256 }, ratio, test.fileSource, + HeadlessFrontend frontend { { 256, 256 }, ratio, test.fileSource, test.threadPool }; + Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), ratio, test.fileSource, test.threadPool, MapMode::Still); map.setZoom(16); // more map features map.getStyle().loadURL("mapbox://streets"); - test::render(map, test.view); + frontend.render(map); } TEST(Memory, Raster) { MemoryTest test; float ratio { 2 }; - StubRendererFrontend rendererFrontend { - std::make_unique(test.backend, ratio, test.fileSource, test.threadPool), - test.view }; - - Map map(rendererFrontend, MapObserver::nullObserver(), { 256, 256 }, ratio, test.fileSource, + HeadlessFrontend frontend { { 256, 256 }, ratio, test.fileSource, test.threadPool }; + Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), ratio, test.fileSource, test.threadPool, MapMode::Still); map.getStyle().loadURL("mapbox://satellite"); - test::render(map, test.view); + frontend.render(map); } /** @@ -127,57 +115,47 @@ TEST(Memory, Footprint) { if (!shouldRunFootprint()) { return; } - + MemoryTest test; - float ratio { 2 }; - auto renderMap = [&](Map& map, const char* style){ - map.setZoom(16); - map.getStyle().loadURL(style); - test::render(map, test.view); + class FrontendAndMap { + public: + FrontendAndMap(MemoryTest& test_, const char* style) + : frontend(Size{ 256, 256 }, 2, test_.fileSource, test_.threadPool) + , map(frontend, MapObserver::nullObserver(), frontend.getSize(), 2, test_.fileSource, test_.threadPool, MapMode::Still) { + map.setZoom(16); + map.getStyle().loadURL(style); + frontend.render(map); + } + + HeadlessFrontend frontend; + Map map; }; // Warm up buffers and cache. for (unsigned i = 0; i < 10; ++i) { - StubRendererFrontend rendererFrontend { - std::make_unique(test.backend, ratio, test.fileSource, test.threadPool), - test.view }; - Map map(rendererFrontend, MapObserver::nullObserver(), { 256, 256 }, ratio, test.fileSource, - test.threadPool, MapMode::Still); - renderMap(map, "mapbox://streets"); - renderMap(map, "mapbox://satellite"); - }; + FrontendAndMap(test, "mapbox://streets"); + FrontendAndMap(test, "mapbox://satellite"); + } // Process close callbacks, mostly needed by // libuv runloop. test.runLoop.runOnce(); - std::vector, std::unique_ptr>> maps; + std::vector> maps; unsigned runs = 15; long vectorInitialRSS = mbgl::test::getCurrentRSS(); for (unsigned i = 0; i < runs; ++i) { - auto frontend = std::make_unique( - std::make_unique(test.backend, ratio, test.fileSource, test.threadPool), test.view); - auto vector = std::make_unique(*frontend, MapObserver::nullObserver(), - Size{ 256, 256 }, ratio, test.fileSource, - test.threadPool, MapMode::Still); - renderMap(*vector, "mapbox://streets"); - maps.push_back({std::move(vector), std::move(frontend)}); - }; + maps.emplace_back(std::make_unique(test, "mapbox://streets")); + } double vectorFootprint = (mbgl::test::getCurrentRSS() - vectorInitialRSS) / double(runs); long rasterInitialRSS = mbgl::test::getCurrentRSS(); for (unsigned i = 0; i < runs; ++i) { - auto frontend = std::make_unique( - std::make_unique(test.backend, ratio, test.fileSource, test.threadPool), test.view); - auto raster = std::make_unique(*frontend, MapObserver::nullObserver(), - Size{ 256, 256 }, ratio, test.fileSource, - test.threadPool, MapMode::Still); - renderMap(*raster, "mapbox://satellite"); - maps.push_back({std::move(raster), std::move(frontend)}); - }; + maps.emplace_back(std::make_unique(test, "mapbox://satellite")); + } double rasterFootprint = (mbgl::test::getCurrentRSS() - rasterInitialRSS) / double(runs); diff --git a/test/util/offscreen_texture.test.cpp b/test/util/offscreen_texture.test.cpp index d4efd75689..09c940c4c3 100644 --- a/test/util/offscreen_texture.test.cpp +++ b/test/util/offscreen_texture.test.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include @@ -11,20 +10,19 @@ using namespace mbgl; TEST(OffscreenTexture, EmptyRed) { - HeadlessBackend backend; + HeadlessBackend backend({ 512, 256 }); BackendScope scope { backend }; - OffscreenView view(backend.getContext(), { 512, 256 }); - // Scissor test shouldn't leak after OffscreenView::bind(). + // Scissor test shouldn't leak after HeadlessBackend::bind(). MBGL_CHECK_ERROR(glScissor(64, 64, 128, 128)); backend.getContext().scissorTest.setCurrentValue(true); - view.bind(); + backend.bind(); MBGL_CHECK_ERROR(glClearColor(1.0f, 0.0f, 0.0f, 1.0f)); MBGL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT)); - auto image = view.readStillImage(); + auto image = backend.readStillImage(); test::checkImage("test/fixtures/offscreen_texture/empty-red", image, 0, 0); } @@ -74,7 +72,7 @@ struct Buffer { TEST(OffscreenTexture, RenderToTexture) { - HeadlessBackend backend; + HeadlessBackend backend({ 512, 256 }); BackendScope scope { backend }; auto& context = backend.getContext(); @@ -124,8 +122,7 @@ void main() { Buffer triangleBuffer({ 0, 0.5, 0.5, -0.5, -0.5, -0.5 }); Buffer viewportBuffer({ -1, -1, 1, -1, -1, 1, 1, 1 }); - OffscreenView view(context, { 512, 256 }); - view.bind(); + backend.bind(); // First, draw red to the bound FBO. context.clear(Color::red(), {}, {}); @@ -153,9 +150,9 @@ void main() { 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. - view.bind(); + backend.bind(); - image = view.readStillImage(); + image = backend.readStillImage(); test::checkImage("test/fixtures/offscreen_texture/render-to-fbo", image, 0, 0); // Now, composite the Framebuffer texture we've rendered to onto the main FBO. @@ -168,6 +165,6 @@ void main() { glVertexAttribPointer(compositeShader.a_pos, 2, GL_FLOAT, GL_FALSE, 0, nullptr)); MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); - image = view.readStillImage(); + image = backend.readStillImage(); test::checkImage("test/fixtures/offscreen_texture/render-to-fbo-composited", image, 0, 0.1); } -- cgit v1.2.1