[core] split backend from mapobserver
This commit is contained in:
committed by
Ivo van Dongen
parent
e35cbbae55
commit
57351c068b
@@ -38,7 +38,7 @@ public:
|
||||
OffscreenView view{ backend.getContext(), { 1000, 1000 } };
|
||||
DefaultFileSource fileSource{ "benchmark/fixtures/api/cache.db", "." };
|
||||
ThreadPool threadPool{ 4 };
|
||||
Map map{ backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still };
|
||||
Map map{ backend, MapObserver::nullObserver(), view.getSize(), 1, fileSource, threadPool, MapMode::Still };
|
||||
ScreenBox box{{ 0, 0 }, { 1000, 1000 }};
|
||||
};
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <mbgl/benchmark/util.hpp>
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/map/map_observer.hpp>
|
||||
#include <mbgl/map/backend_scope.hpp>
|
||||
#include <mbgl/gl/headless_backend.hpp>
|
||||
#include <mbgl/gl/offscreen_view.hpp>
|
||||
@@ -44,7 +45,7 @@ static void prepare(Map& map, optional<std::string> json = {}) {
|
||||
|
||||
static void API_renderStill_reuse_map(::benchmark::State& state) {
|
||||
RenderBenchmark bench;
|
||||
Map map { bench.backend, bench.view.getSize(), 1, bench.fileSource, bench.threadPool, MapMode::Still };
|
||||
Map map { bench.backend, MapObserver::nullObserver(), bench.view.getSize(), 1, bench.fileSource, bench.threadPool, MapMode::Still };
|
||||
prepare(map);
|
||||
|
||||
while (state.KeepRunning()) {
|
||||
@@ -54,7 +55,7 @@ static void API_renderStill_reuse_map(::benchmark::State& state) {
|
||||
|
||||
static void API_renderStill_reuse_map_switch_styles(::benchmark::State& state) {
|
||||
RenderBenchmark bench;
|
||||
Map map { bench.backend, bench.view.getSize(), 1, bench.fileSource, bench.threadPool, MapMode::Still };
|
||||
Map map { bench.backend, MapObserver::nullObserver(), bench.view.getSize(), 1, bench.fileSource, bench.threadPool, MapMode::Still };
|
||||
|
||||
while (state.KeepRunning()) {
|
||||
prepare(map, { "{}" });
|
||||
@@ -68,7 +69,7 @@ static void API_renderStill_recreate_map(::benchmark::State& state) {
|
||||
RenderBenchmark bench;
|
||||
|
||||
while (state.KeepRunning()) {
|
||||
Map map { bench.backend, bench.view.getSize(), 1, bench.fileSource, bench.threadPool, MapMode::Still };
|
||||
Map map { bench.backend, MapObserver::nullObserver(), bench.view.getSize(), 1, bench.fileSource, bench.threadPool, MapMode::Still };
|
||||
prepare(map);
|
||||
mbgl::benchmark::render(map, bench.view);
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ int main(int argc, char *argv[]) {
|
||||
OffscreenView view(backend.getContext(), { static_cast<uint32_t>(width * pixelRatio),
|
||||
static_cast<uint32_t>(height * pixelRatio) });
|
||||
ThreadPool threadPool(4);
|
||||
Map map(backend, mbgl::Size { width, height }, pixelRatio, fileSource, threadPool, MapMode::Still);
|
||||
Map map(backend, MapObserver::nullObserver(), mbgl::Size { width, height }, pixelRatio, fileSource, threadPool, MapMode::Still);
|
||||
|
||||
if (style_path.find("://") == std::string::npos) {
|
||||
style_path = std::string("file://") + style_path;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/map/map_observer.hpp>
|
||||
#include <mbgl/map/view.hpp>
|
||||
#include <mbgl/util/image.hpp>
|
||||
#include <mbgl/util/size.hpp>
|
||||
|
||||
@@ -17,7 +17,7 @@ using FramebufferID = uint32_t;
|
||||
|
||||
class BackendScope;
|
||||
|
||||
class Backend : public MapObserver {
|
||||
class Backend {
|
||||
public:
|
||||
Backend();
|
||||
virtual ~Backend();
|
||||
|
||||
@@ -33,6 +33,7 @@ class Style;
|
||||
class Map : private util::noncopyable {
|
||||
public:
|
||||
explicit Map(Backend&,
|
||||
MapObserver&,
|
||||
Size size,
|
||||
float pixelRatio,
|
||||
FileSource&,
|
||||
|
||||
@@ -49,6 +49,7 @@ class Map::Impl : public style::Observer,
|
||||
public:
|
||||
Impl(Map&,
|
||||
Backend&,
|
||||
MapObserver&,
|
||||
float pixelRatio,
|
||||
FileSource&,
|
||||
Scheduler&,
|
||||
@@ -104,6 +105,7 @@ public:
|
||||
};
|
||||
|
||||
Map::Map(Backend& backend,
|
||||
MapObserver& mapObserver,
|
||||
const Size size,
|
||||
const float pixelRatio,
|
||||
FileSource& fileSource,
|
||||
@@ -115,6 +117,7 @@ Map::Map(Backend& backend,
|
||||
optional<std::string> programCacheDir)
|
||||
: impl(std::make_unique<Impl>(*this,
|
||||
backend,
|
||||
mapObserver,
|
||||
pixelRatio,
|
||||
fileSource,
|
||||
scheduler,
|
||||
@@ -128,6 +131,7 @@ Map::Map(Backend& backend,
|
||||
|
||||
Map::Impl::Impl(Map& map_,
|
||||
Backend& backend_,
|
||||
MapObserver& mapObserver,
|
||||
float pixelRatio_,
|
||||
FileSource& fileSource_,
|
||||
Scheduler& scheduler_,
|
||||
@@ -137,7 +141,7 @@ Map::Impl::Impl(Map& map_,
|
||||
ViewportMode viewportMode_,
|
||||
optional<std::string> programCacheDir_)
|
||||
: map(map_),
|
||||
observer(backend_),
|
||||
observer(mapObserver),
|
||||
backend(backend_),
|
||||
fileSource(fileSource_),
|
||||
scheduler(scheduler_),
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
OffscreenView view { backend.getContext() };
|
||||
StubFileSource fileSource;
|
||||
ThreadPool threadPool { 4 };
|
||||
Map map { backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still };
|
||||
Map map { backend, MapObserver::nullObserver(), view.getSize(), 1, fileSource, threadPool, MapMode::Still };
|
||||
|
||||
void checkRendering(const char * name) {
|
||||
test::checkImage(std::string("test/fixtures/annotations/") + name,
|
||||
|
||||
@@ -29,7 +29,7 @@ TEST(API, RenderWithoutCallback) {
|
||||
ThreadPool threadPool(4);
|
||||
|
||||
std::unique_ptr<Map> map =
|
||||
std::make_unique<Map>(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still);
|
||||
std::make_unique<Map>(backend, MapObserver::nullObserver(), view.getSize(), 1, fileSource, threadPool, MapMode::Still);
|
||||
map->renderStill(view, nullptr);
|
||||
|
||||
// Force Map thread to join.
|
||||
|
||||
@@ -93,7 +93,7 @@ TEST(CustomLayer, Basic) {
|
||||
DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets");
|
||||
ThreadPool threadPool(4);
|
||||
|
||||
Map map(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still);
|
||||
Map map(backend, MapObserver::nullObserver(), view.getSize(), 1, fileSource, threadPool, MapMode::Still);
|
||||
map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
|
||||
map.setLatLngZoom({ 37.8, -122.5 }, 10);
|
||||
map.getStyle().addLayer(std::make_unique<CustomLayer>(
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
OffscreenView view { backend.getContext() };
|
||||
StubFileSource fileSource;
|
||||
ThreadPool threadPool { 4 };
|
||||
Map map { backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still };
|
||||
Map map { backend, MapObserver::nullObserver(), view.getSize(), 1, fileSource, threadPool, MapMode::Still };
|
||||
};
|
||||
|
||||
} // end namespace
|
||||
|
||||
@@ -35,7 +35,7 @@ TEST(API, TEST_REQUIRES_SERVER(RenderMissingTile)) {
|
||||
|
||||
Log::setObserver(std::make_unique<FixtureLogObserver>());
|
||||
|
||||
Map map(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still);
|
||||
Map map(backend, MapObserver::nullObserver(), view.getSize(), 1, fileSource, threadPool, MapMode::Still);
|
||||
|
||||
std::string message;
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ TEST(API, RepeatedRender) {
|
||||
|
||||
Log::setObserver(std::make_unique<FixtureLogObserver>());
|
||||
|
||||
Map map(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still);
|
||||
Map map(backend, MapObserver::nullObserver(), view.getSize(), 1, fileSource, threadPool, MapMode::Still);
|
||||
|
||||
{
|
||||
map.getStyle().loadJSON(style);
|
||||
@@ -86,7 +86,7 @@ TEST(API, ZoomHistory) {
|
||||
|
||||
Log::setObserver(std::make_unique<FixtureLogObserver>());
|
||||
|
||||
Map map(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still);
|
||||
Map map(backend, MapObserver::nullObserver(), view.getSize(), 1, fileSource, threadPool, MapMode::Still);
|
||||
map.getStyle().loadJSON(style);
|
||||
|
||||
auto geojson = mapbox::geojson::parse(R"t({ "type": "FeatureCollection", "features": [{ "type": "Feature", "properties": {}, "geometry": { "type": "LineString", "coordinates": [ [ -150, -75 ], [ 150, 75 ] ] } } ] })t");
|
||||
|
||||
@@ -25,42 +25,46 @@ using namespace mbgl;
|
||||
using namespace mbgl::style;
|
||||
using namespace std::literals::string_literals;
|
||||
|
||||
class BackendTest : public HeadlessBackend {
|
||||
class MockBackend : public HeadlessBackend {
|
||||
public:
|
||||
BackendTest() : HeadlessBackend(test::sharedDisplay()) {}
|
||||
|
||||
void invalidate() {
|
||||
if (invalidateCallback) {
|
||||
invalidateCallback();
|
||||
}
|
||||
MockBackend()
|
||||
: HeadlessBackend(test::sharedDisplay() ) {
|
||||
}
|
||||
|
||||
std::function<void()> invalidateCallback;
|
||||
std::function<void()> callback;
|
||||
void invalidate() override {
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class StubMapObserver : public MapObserver {
|
||||
public:
|
||||
void onWillStartLoadingMap() final {
|
||||
if (onWillStartLoadingMapCallback) {
|
||||
onWillStartLoadingMapCallback();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void onDidFinishLoadingMap() final {
|
||||
if (onDidFinishLoadingMapCallback) {
|
||||
onDidFinishLoadingMapCallback();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void onDidFailLoadingMap(std::exception_ptr) final {
|
||||
if (didFailLoadingMapCallback) {
|
||||
didFailLoadingMapCallback();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void onDidFinishLoadingStyle() final {
|
||||
if (didFinishLoadingStyleCallback) {
|
||||
didFinishLoadingStyleCallback();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::function<void()> onWillStartLoadingMapCallback;
|
||||
std::function<void()> onDidFinishLoadingMapCallback;
|
||||
std::function<void()> didFailLoadingMapCallback;
|
||||
@@ -69,7 +73,8 @@ public:
|
||||
|
||||
struct MapTest {
|
||||
util::RunLoop runLoop;
|
||||
BackendTest backend;
|
||||
MockBackend backend;
|
||||
StubMapObserver observer;
|
||||
BackendScope scope { backend };
|
||||
OffscreenView view { backend.getContext() };
|
||||
StubFileSource fileSource;
|
||||
@@ -78,7 +83,7 @@ struct MapTest {
|
||||
|
||||
TEST(Map, LatLngBehavior) {
|
||||
MapTest test;
|
||||
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
|
||||
|
||||
map.setLatLngZoom({ 1, 1 }, 0);
|
||||
auto latLng1 = map.getLatLng();
|
||||
@@ -92,7 +97,7 @@ TEST(Map, LatLngBehavior) {
|
||||
|
||||
TEST(Map, LatLngBoundsToCamera) {
|
||||
MapTest test;
|
||||
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
|
||||
|
||||
map.setLatLngZoom({ 40.712730, -74.005953 }, 16.0);
|
||||
|
||||
@@ -104,7 +109,7 @@ TEST(Map, LatLngBoundsToCamera) {
|
||||
|
||||
TEST(Map, CameraToLatLngBounds) {
|
||||
MapTest test;
|
||||
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
|
||||
|
||||
map.setLatLngZoom({ 45, 90 }, 16);
|
||||
|
||||
@@ -143,7 +148,7 @@ 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.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, test.observer, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
|
||||
map.getStyle().loadURL(prefix + "style.json");
|
||||
|
||||
test::checkImage("test/fixtures/map/offline",
|
||||
@@ -160,12 +165,12 @@ TEST(Map, SetStyleInvalidJSON) {
|
||||
Log::setObserver(std::make_unique<FixtureLogObserver>());
|
||||
|
||||
bool fail = false;
|
||||
test.backend.didFailLoadingMapCallback = [&]() {
|
||||
test.observer.didFailLoadingMapCallback = [&]() {
|
||||
fail = true;
|
||||
};
|
||||
|
||||
{
|
||||
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool,
|
||||
Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool,
|
||||
MapMode::Still);
|
||||
map.getStyle().loadJSON("invalid");
|
||||
}
|
||||
@@ -191,11 +196,11 @@ TEST(Map, SetStyleInvalidURL) {
|
||||
return response;
|
||||
};
|
||||
|
||||
test.backend.didFailLoadingMapCallback = [&]() {
|
||||
test.observer.didFailLoadingMapCallback = [&]() {
|
||||
test.runLoop.stop();
|
||||
};
|
||||
|
||||
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
|
||||
map.getStyle().loadURL("mapbox://bar");
|
||||
|
||||
test.runLoop.run();
|
||||
@@ -204,7 +209,7 @@ TEST(Map, SetStyleInvalidURL) {
|
||||
TEST(Map, DoubleStyleLoad) {
|
||||
MapTest test;
|
||||
|
||||
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
|
||||
map.getStyle().loadJSON("");
|
||||
map.getStyle().loadJSON("");
|
||||
}
|
||||
@@ -215,7 +220,7 @@ TEST(Map, StyleFresh) {
|
||||
MapTest test;
|
||||
FakeFileSource fileSource;
|
||||
|
||||
Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, test.observer, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
|
||||
map.getStyle().loadURL("mapbox://styles/test");
|
||||
EXPECT_EQ(1u, fileSource.requests.size());
|
||||
|
||||
@@ -235,7 +240,7 @@ TEST(Map, StyleExpired) {
|
||||
MapTest test;
|
||||
FakeFileSource fileSource;
|
||||
|
||||
Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, test.observer, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
|
||||
map.getStyle().loadURL("mapbox://styles/test");
|
||||
EXPECT_EQ(1u, fileSource.requests.size());
|
||||
|
||||
@@ -262,7 +267,7 @@ TEST(Map, StyleExpiredWithAnnotations) {
|
||||
MapTest test;
|
||||
FakeFileSource fileSource;
|
||||
|
||||
Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, test.observer, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
|
||||
map.getStyle().loadURL("mapbox://styles/test");
|
||||
EXPECT_EQ(1u, fileSource.requests.size());
|
||||
|
||||
@@ -288,7 +293,7 @@ TEST(Map, StyleExpiredWithRender) {
|
||||
MapTest test;
|
||||
FakeFileSource fileSource;
|
||||
|
||||
Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, test.observer, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
|
||||
map.getStyle().loadURL("mapbox://styles/test");
|
||||
EXPECT_EQ(1u, fileSource.requests.size());
|
||||
|
||||
@@ -312,7 +317,7 @@ TEST(Map, StyleEarlyMutation) {
|
||||
MapTest test;
|
||||
FakeFileSource fileSource;
|
||||
|
||||
Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, test.observer, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
|
||||
map.getStyle().loadURL("mapbox://styles/test");
|
||||
map.getStyle().addLayer(std::make_unique<style::BackgroundLayer>("bg"));
|
||||
|
||||
@@ -326,10 +331,10 @@ TEST(Map, StyleEarlyMutation) {
|
||||
|
||||
TEST(Map, MapLoadingSignal) {
|
||||
MapTest test;
|
||||
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
|
||||
|
||||
bool emitted = false;
|
||||
test.backend.onWillStartLoadingMapCallback = [&]() {
|
||||
test.observer.onWillStartLoadingMapCallback = [&]() {
|
||||
emitted = true;
|
||||
};
|
||||
map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
@@ -338,13 +343,13 @@ TEST(Map, MapLoadingSignal) {
|
||||
|
||||
TEST(Map, MapLoadedSignal) {
|
||||
MapTest test;
|
||||
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Continuous);
|
||||
Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Continuous);
|
||||
|
||||
test.backend.onDidFinishLoadingMapCallback = [&]() {
|
||||
test.observer.onDidFinishLoadingMapCallback = [&]() {
|
||||
test.runLoop.stop();
|
||||
};
|
||||
|
||||
test.backend.invalidateCallback = [&]() {
|
||||
test.backend.callback = [&]() {
|
||||
map.render(test.view);
|
||||
};
|
||||
|
||||
@@ -354,11 +359,11 @@ TEST(Map, MapLoadedSignal) {
|
||||
|
||||
TEST(Map, StyleLoadedSignal) {
|
||||
MapTest test;
|
||||
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
|
||||
|
||||
// The map should emit a signal on style loaded
|
||||
bool emitted = false;
|
||||
test.backend.didFinishLoadingStyleCallback = [&]() {
|
||||
test.observer.didFinishLoadingStyleCallback = [&]() {
|
||||
emitted = true;
|
||||
};
|
||||
map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
@@ -375,10 +380,10 @@ TEST(Map, TEST_REQUIRES_SERVER(StyleNetworkErrorRetry)) {
|
||||
MapTest test;
|
||||
OnlineFileSource fileSource;
|
||||
|
||||
Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, test.observer, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
|
||||
map.getStyle().loadURL("http://127.0.0.1:3000/style-fail-once-500");
|
||||
|
||||
test.backend.didFinishLoadingStyleCallback = [&]() {
|
||||
test.observer.didFinishLoadingStyleCallback = [&]() {
|
||||
test.runLoop.stop();
|
||||
};
|
||||
|
||||
@@ -389,18 +394,18 @@ TEST(Map, TEST_REQUIRES_SERVER(StyleNotFound)) {
|
||||
MapTest test;
|
||||
OnlineFileSource fileSource;
|
||||
|
||||
Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, test.observer, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
|
||||
map.getStyle().loadURL("http://127.0.0.1:3000/style-fail-once-404");
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
util::Timer timer;
|
||||
|
||||
// Not found errors should not trigger a retry like other errors.
|
||||
test.backend.didFinishLoadingStyleCallback = [&]() {
|
||||
test.observer.didFinishLoadingStyleCallback = [&]() {
|
||||
FAIL() << "Should not retry on not found!";
|
||||
};
|
||||
|
||||
test.backend.didFailLoadingMapCallback = [&]() {
|
||||
test.observer.didFailLoadingMapCallback = [&]() {
|
||||
timer.start(Milliseconds(1100), 0s, [&] {
|
||||
test.runLoop.stop();
|
||||
});
|
||||
@@ -416,7 +421,7 @@ TEST(Map, TEST_REQUIRES_SERVER(StyleNotFound)) {
|
||||
TEST(Map, AddLayer) {
|
||||
MapTest test;
|
||||
|
||||
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
|
||||
map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
|
||||
auto layer = std::make_unique<BackgroundLayer>("background");
|
||||
@@ -433,7 +438,7 @@ TEST(Map, WithoutVAOExtension) {
|
||||
|
||||
DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets");
|
||||
|
||||
Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, test.observer, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
|
||||
map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
|
||||
|
||||
test::checkImage("test/fixtures/map/no_vao", test::render(map, test.view), 0.002);
|
||||
@@ -442,7 +447,7 @@ TEST(Map, WithoutVAOExtension) {
|
||||
TEST(Map, RemoveLayer) {
|
||||
MapTest test;
|
||||
|
||||
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
|
||||
map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
|
||||
auto layer = std::make_unique<BackgroundLayer>("background");
|
||||
@@ -467,7 +472,7 @@ TEST(Map, DisabledSources) {
|
||||
return {};
|
||||
};
|
||||
|
||||
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, test.observer, 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.
|
||||
@@ -517,7 +522,7 @@ TEST(Map, DisabledSources) {
|
||||
TEST(Map, DontLoadUnneededTiles) {
|
||||
MapTest test;
|
||||
|
||||
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
|
||||
map.getStyle().loadJSON(R"STYLE({
|
||||
"sources": {
|
||||
"a": { "type": "vector", "tiles": [ "a/{z}/{x}/{y}" ] }
|
||||
@@ -562,29 +567,14 @@ TEST(Map, DontLoadUnneededTiles) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class MockBackend : public HeadlessBackend {
|
||||
public:
|
||||
MockBackend(std::shared_ptr<HeadlessDisplay> display_)
|
||||
: HeadlessBackend(display_) {
|
||||
}
|
||||
|
||||
std::function<void()> callback;
|
||||
void invalidate() override {
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TEST(Map, TEST_DISABLED_ON_CI(ContinuousRendering)) {
|
||||
util::RunLoop runLoop;
|
||||
MockBackend backend { test::sharedDisplay() };
|
||||
MockBackend backend;
|
||||
BackendScope scope { backend };
|
||||
OffscreenView view { backend.getContext() };
|
||||
ThreadPool threadPool { 4 };
|
||||
DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets");
|
||||
Map map(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Continuous);
|
||||
Map map(backend, MapObserver::nullObserver(), view.getSize(), 1, fileSource, threadPool, MapMode::Continuous);
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ TEST(Map, PrefetchTiles) {
|
||||
OffscreenView view(backend.getContext(), { 512, 512 });
|
||||
ThreadPool threadPool(4);
|
||||
StubFileSource fileSource;
|
||||
Map map(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still);
|
||||
Map map(backend, MapObserver::nullObserver(), view.getSize(), 1, fileSource, threadPool, MapMode::Still);
|
||||
|
||||
std::vector<int> tiles;
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ private:
|
||||
TEST(Memory, Vector) {
|
||||
MemoryTest test;
|
||||
|
||||
Map map(test.backend, { 256, 256 }, 2, test.fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, MapObserver::nullObserver(), { 256, 256 }, 2, test.fileSource, test.threadPool, MapMode::Still);
|
||||
map.setZoom(16); // more map features
|
||||
map.getStyle().loadURL("mapbox://streets");
|
||||
|
||||
@@ -84,7 +84,7 @@ TEST(Memory, Vector) {
|
||||
TEST(Memory, Raster) {
|
||||
MemoryTest test;
|
||||
|
||||
Map map(test.backend, { 256, 256 }, 2, test.fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, MapObserver::nullObserver(), { 256, 256 }, 2, test.fileSource, test.threadPool, MapMode::Still);
|
||||
map.getStyle().loadURL("mapbox://satellite");
|
||||
|
||||
test::render(map, test.view);
|
||||
@@ -125,7 +125,7 @@ TEST(Memory, Footprint) {
|
||||
|
||||
// Warm up buffers and cache.
|
||||
for (unsigned i = 0; i < 10; ++i) {
|
||||
Map map(test.backend, { 256, 256 }, 2, test.fileSource, test.threadPool, MapMode::Still);
|
||||
Map map(test.backend, MapObserver::nullObserver(), { 256, 256 }, 2, test.fileSource, test.threadPool, MapMode::Still);
|
||||
renderMap(map, "mapbox://streets");
|
||||
renderMap(map, "mapbox://satellite");
|
||||
};
|
||||
@@ -139,8 +139,9 @@ TEST(Memory, Footprint) {
|
||||
|
||||
long vectorInitialRSS = mbgl::test::getCurrentRSS();
|
||||
for (unsigned i = 0; i < runs; ++i) {
|
||||
auto vector = std::make_unique<Map>(test.backend, Size{ 256, 256 }, 2, test.fileSource,
|
||||
test.threadPool, MapMode::Still);
|
||||
auto vector = std::make_unique<Map>(test.backend, MapObserver::nullObserver(),
|
||||
Size{ 256, 256 }, 2, test.fileSource, test.threadPool,
|
||||
MapMode::Still);
|
||||
renderMap(*vector, "mapbox://streets");
|
||||
maps.push_back(std::move(vector));
|
||||
};
|
||||
@@ -149,8 +150,9 @@ TEST(Memory, Footprint) {
|
||||
|
||||
long rasterInitialRSS = mbgl::test::getCurrentRSS();
|
||||
for (unsigned i = 0; i < runs; ++i) {
|
||||
auto raster = std::make_unique<Map>(test.backend, Size{ 256, 256 }, 2, test.fileSource,
|
||||
test.threadPool, MapMode::Still);
|
||||
auto raster = std::make_unique<Map>(test.backend, MapObserver::nullObserver(),
|
||||
Size{ 256, 256 }, 2, test.fileSource, test.threadPool,
|
||||
MapMode::Still);
|
||||
renderMap(*raster, "mapbox://satellite");
|
||||
maps.push_back(std::move(raster));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user