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 --- bin/render.cpp | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) (limited to 'bin') diff --git a/bin/render.cpp b/bin/render.cpp index 0214d3310c..444921ff2b 100644 --- a/bin/render.cpp +++ b/bin/render.cpp @@ -2,14 +2,10 @@ #include #include -#include -#include +#include #include #include #include -#include -#include -#include #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunknown-pragmas" @@ -85,13 +81,9 @@ int main(int argc, char *argv[]) { fileSource.setAccessToken(std::string(token)); } - HeadlessBackend backend; - BackendScope scope { backend }; - OffscreenView view(backend.getContext(), { static_cast(width * pixelRatio), - static_cast(height * pixelRatio) }); ThreadPool threadPool(4); - AsyncRendererFrontend rendererFrontend(std::make_unique(backend, pixelRatio, fileSource, threadPool), backend, view); - Map map(rendererFrontend, MapObserver::nullObserver(), mbgl::Size { width, height }, pixelRatio, fileSource, threadPool, MapMode::Still); + HeadlessFrontend frontend({ width, height }, pixelRatio, fileSource, threadPool); + Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource, threadPool, MapMode::Still); if (style_path.find("://") == std::string::npos) { style_path = std::string("file://") + style_path; @@ -106,23 +98,14 @@ int main(int argc, char *argv[]) { map.setDebug(debug ? mbgl::MapDebugOptions::TileBorders | mbgl::MapDebugOptions::ParseStatus : mbgl::MapDebugOptions::NoDebug); } - map.renderStill([&](std::exception_ptr error) { - try { - if (error) { - std::rethrow_exception(error); - } - } catch(std::exception& e) { - std::cout << "Error: " << e.what() << std::endl; - exit(1); - } - + try { std::ofstream out(output, std::ios::binary); - out << encodePNG(view.readStillImage()); + out << encodePNG(frontend.render(map)); out.close(); - loop.stop(); - }); - - loop.run(); + } catch(std::exception& e) { + std::cout << "Error: " << e.what() << std::endl; + exit(1); + } return 0; } -- cgit v1.2.1