[core] separate Backend from View for headless rendering

This commit is contained in:
Konstantin Käfer
2016-10-06 13:23:50 +02:00
parent 45f4dc0166
commit 5cc390d694
54 changed files with 779 additions and 525 deletions

View File

@@ -5,7 +5,7 @@
#include <mbgl/annotation/annotation.hpp>
#include <mbgl/sprite/sprite_image.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/platform/default/headless_display.hpp>
#include <mbgl/platform/default/headless_backend.hpp>
#include <mbgl/platform/default/headless_view.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
@@ -23,11 +23,11 @@ std::shared_ptr<SpriteImage> namedMarker(const std::string &name) {
class AnnotationTest {
public:
util::RunLoop loop;
std::shared_ptr<HeadlessDisplay> display { std::make_shared<HeadlessDisplay>() };
HeadlessView view { display, 1 };
HeadlessBackend backend;
HeadlessView view;
StubFileSource fileSource;
ThreadPool threadPool { 4 };
Map map { view, fileSource, threadPool, MapMode::Still };
Map map { backend, view, view.getPixelRatio(), fileSource, threadPool, MapMode::Still };
void checkRendering(const char * name) {
test::checkImage(std::string("test/fixtures/annotations/") + name,

View File

@@ -3,7 +3,8 @@
#include <mbgl/test/fixture_log_observer.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/platform/default/headless_display.hpp>
#include <mbgl/platform/default/headless_backend.hpp>
#include <mbgl/platform/default/headless_view.hpp>
#include <mbgl/storage/online_file_source.hpp>
#include <mbgl/platform/default/thread_pool.hpp>
#include <mbgl/util/exception.hpp>
@@ -19,13 +20,14 @@ TEST(API, RenderWithoutCallback) {
util::RunLoop loop;
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1);
HeadlessBackend backend;
HeadlessView view;
view.resize(128, 512);
StubFileSource fileSource;
ThreadPool threadPool(4);
std::unique_ptr<Map> map = std::make_unique<Map>(view, fileSource, threadPool, MapMode::Still);
std::unique_ptr<Map> map = std::make_unique<Map>(backend, view, view.getPixelRatio(),
fileSource, threadPool, MapMode::Still);
map->renderStill(nullptr);
// Force Map thread to join.
@@ -44,13 +46,13 @@ TEST(API, RenderWithoutCallback) {
TEST(API, RenderWithoutStyle) {
util::RunLoop loop;
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1);
HeadlessBackend backend;
HeadlessView view;
view.resize(128, 512);
StubFileSource fileSource;
ThreadPool threadPool(4);
Map map(view, fileSource, threadPool, MapMode::Still);
Map map(backend, view, view.getPixelRatio(), fileSource, threadPool, MapMode::Still);
std::exception_ptr error;
map.renderStill([&](std::exception_ptr error_, PremultipliedImage&&) {

View File

@@ -2,7 +2,7 @@
#include <mbgl/gl/gl.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/platform/default/headless_display.hpp>
#include <mbgl/platform/default/headless_backend.hpp>
#include <mbgl/platform/default/headless_view.hpp>
#include <mbgl/platform/default/thread_pool.hpp>
#include <mbgl/storage/default_file_source.hpp>
@@ -85,8 +85,8 @@ public:
TEST(CustomLayer, Basic) {
util::RunLoop loop;
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1);
HeadlessBackend backend;
HeadlessView view;
#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(view, fileSource, threadPool, MapMode::Still);
Map map(backend, view, view.getPixelRatio(), 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>(

View File

@@ -1,5 +1,5 @@
#include <mbgl/map/map.hpp>
#include <mbgl/platform/default/headless_display.hpp>
#include <mbgl/platform/default/headless_backend.hpp>
#include <mbgl/platform/default/headless_view.hpp>
#include <mbgl/platform/default/thread_pool.hpp>
#include <mbgl/sprite/sprite_image.hpp>
@@ -26,11 +26,11 @@ public:
}
util::RunLoop loop;
std::shared_ptr<HeadlessDisplay> display { std::make_shared<HeadlessDisplay>() };
HeadlessView view { display, 1 };
HeadlessBackend backend;
HeadlessView view;
StubFileSource fileSource;
ThreadPool threadPool { 4 };
Map map { view, fileSource, threadPool, MapMode::Still };
Map map { backend, view, view.getPixelRatio(), fileSource, threadPool, MapMode::Still };
};
} // end namespace

View File

@@ -2,7 +2,7 @@
#include <mbgl/test/fixture_log_observer.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/platform/default/headless_display.hpp>
#include <mbgl/platform/default/headless_backend.hpp>
#include <mbgl/platform/default/headless_view.hpp>
#include <mbgl/platform/default/thread_pool.hpp>
#include <mbgl/storage/default_file_source.hpp>
@@ -25,8 +25,8 @@ TEST(API, TEST_REQUIRES_SERVER(RenderMissingTile)) {
const auto style = util::read_file("test/fixtures/api/water_missing_tiles.json");
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1, 256, 512);
HeadlessBackend backend;
HeadlessView view(1, 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,7 +38,7 @@ TEST(API, TEST_REQUIRES_SERVER(RenderMissingTile)) {
Log::setObserver(std::make_unique<FixtureLogObserver>());
Map map(view, fileSource, threadPool, MapMode::Still);
Map map(backend, view, view.getPixelRatio(), fileSource, threadPool, MapMode::Still);
std::string message;

View File

@@ -2,7 +2,7 @@
#include <mbgl/test/fixture_log_observer.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/platform/default/headless_display.hpp>
#include <mbgl/platform/default/headless_backend.hpp>
#include <mbgl/platform/default/headless_view.hpp>
#include <mbgl/platform/default/thread_pool.hpp>
#include <mbgl/storage/default_file_source.hpp>
@@ -19,9 +19,8 @@ TEST(API, RepeatedRender) {
const auto style = util::read_file("test/fixtures/api/water.json");
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1, 256, 512);
HeadlessBackend backend;
HeadlessView view(1, 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");
@@ -33,7 +32,7 @@ TEST(API, RepeatedRender) {
Log::setObserver(std::make_unique<FixtureLogObserver>());
Map map(view, fileSource, threadPool, MapMode::Still);
Map map(backend, view, view.getPixelRatio(), fileSource, threadPool, MapMode::Still);
{
map.setStyleJSON(style);