[core] Render from the main thread
Do not create a thread for the MapContext anymore.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <mbgl/platform/default/headless_view.hpp>
|
||||
#include <mbgl/storage/online_file_source.hpp>
|
||||
#include <mbgl/util/io.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
|
||||
#include <future>
|
||||
#include <vector>
|
||||
@@ -29,6 +30,8 @@ void checkRendering(Map& map, const char * name) {
|
||||
} // end namespace
|
||||
|
||||
TEST(Annotations, PointAnnotation) {
|
||||
util::RunLoop loop;
|
||||
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
HeadlessView view(display, 1);
|
||||
OnlineFileSource fileSource;
|
||||
@@ -42,6 +45,8 @@ TEST(Annotations, PointAnnotation) {
|
||||
}
|
||||
|
||||
TEST(Annotations, LineAnnotation) {
|
||||
util::RunLoop loop;
|
||||
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
HeadlessView view(display, 1);
|
||||
OnlineFileSource fileSource;
|
||||
@@ -61,6 +66,8 @@ TEST(Annotations, LineAnnotation) {
|
||||
}
|
||||
|
||||
TEST(Annotations, FillAnnotation) {
|
||||
util::RunLoop loop;
|
||||
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
HeadlessView view(display, 1);
|
||||
OnlineFileSource fileSource;
|
||||
@@ -79,6 +86,8 @@ TEST(Annotations, FillAnnotation) {
|
||||
}
|
||||
|
||||
TEST(Annotations, StyleSourcedShapeAnnotation) {
|
||||
util::RunLoop loop;
|
||||
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
HeadlessView view(display, 1);
|
||||
OnlineFileSource fileSource;
|
||||
@@ -94,6 +103,8 @@ TEST(Annotations, StyleSourcedShapeAnnotation) {
|
||||
}
|
||||
|
||||
TEST(Annotations, AddMultiple) {
|
||||
util::RunLoop loop;
|
||||
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
HeadlessView view(display, 1);
|
||||
OnlineFileSource fileSource;
|
||||
@@ -111,6 +122,8 @@ TEST(Annotations, AddMultiple) {
|
||||
}
|
||||
|
||||
TEST(Annotations, NonImmediateAdd) {
|
||||
util::RunLoop loop;
|
||||
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
HeadlessView view(display, 1);
|
||||
OnlineFileSource fileSource;
|
||||
@@ -131,6 +144,8 @@ TEST(Annotations, NonImmediateAdd) {
|
||||
}
|
||||
|
||||
TEST(Annotations, UpdateIcon) {
|
||||
util::RunLoop loop;
|
||||
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
HeadlessView view(display, 1);
|
||||
OnlineFileSource fileSource;
|
||||
@@ -150,6 +165,8 @@ TEST(Annotations, UpdateIcon) {
|
||||
}
|
||||
|
||||
TEST(Annotations, UpdatePoint) {
|
||||
util::RunLoop loop;
|
||||
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
HeadlessView view(display, 1);
|
||||
OnlineFileSource fileSource;
|
||||
@@ -168,6 +185,8 @@ TEST(Annotations, UpdatePoint) {
|
||||
}
|
||||
|
||||
TEST(Annotations, RemovePoint) {
|
||||
util::RunLoop loop;
|
||||
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
HeadlessView view(display, 1);
|
||||
OnlineFileSource fileSource;
|
||||
@@ -185,6 +204,8 @@ TEST(Annotations, RemovePoint) {
|
||||
}
|
||||
|
||||
TEST(Annotations, RemoveShape) {
|
||||
util::RunLoop loop;
|
||||
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
HeadlessView view(display, 1);
|
||||
OnlineFileSource fileSource;
|
||||
@@ -207,6 +228,8 @@ TEST(Annotations, RemoveShape) {
|
||||
}
|
||||
|
||||
TEST(Annotations, ImmediateRemoveShape) {
|
||||
util::RunLoop loop;
|
||||
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
HeadlessView view(display, 1);
|
||||
OnlineFileSource fileSource;
|
||||
@@ -219,6 +242,8 @@ TEST(Annotations, ImmediateRemoveShape) {
|
||||
}
|
||||
|
||||
TEST(Annotations, SwitchStyle) {
|
||||
util::RunLoop loop;
|
||||
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
HeadlessView view(display, 1);
|
||||
OnlineFileSource fileSource;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <mbgl/platform/default/headless_view.hpp>
|
||||
#include <mbgl/storage/online_file_source.hpp>
|
||||
#include <mbgl/util/exception.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
|
||||
#include <future>
|
||||
|
||||
@@ -15,6 +16,8 @@ TEST(API, RenderWithoutCallback) {
|
||||
FixtureLogObserver* log = new FixtureLogObserver();
|
||||
Log::setObserver(std::unique_ptr<Log::Observer>(log));
|
||||
|
||||
util::RunLoop loop;
|
||||
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
HeadlessView view(display, 1);
|
||||
view.resize(128, 512);
|
||||
@@ -37,6 +40,8 @@ TEST(API, RenderWithoutCallback) {
|
||||
}
|
||||
|
||||
TEST(API, RenderWithoutStyle) {
|
||||
util::RunLoop loop;
|
||||
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
HeadlessView view(display, 1);
|
||||
view.resize(128, 512);
|
||||
@@ -44,13 +49,16 @@ TEST(API, RenderWithoutStyle) {
|
||||
|
||||
Map map(view, fileSource, MapMode::Still);
|
||||
|
||||
std::promise<std::exception_ptr> promise;
|
||||
map.renderStill([&promise](std::exception_ptr error, PremultipliedImage&&) {
|
||||
promise.set_value(error);
|
||||
std::exception_ptr error;
|
||||
map.renderStill([&](std::exception_ptr error_, PremultipliedImage&&) {
|
||||
error = error_;
|
||||
loop.stop();
|
||||
});
|
||||
|
||||
loop.run();
|
||||
|
||||
try {
|
||||
std::rethrow_exception(promise.get_future().get());
|
||||
std::rethrow_exception(error);
|
||||
} catch (const util::MisuseException& ex) {
|
||||
EXPECT_EQ(std::string(ex.what()), "Map doesn't have a style");
|
||||
} catch (const std::exception&) {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <mbgl/layer/custom_layer.hpp>
|
||||
#include <mbgl/util/io.hpp>
|
||||
#include <mbgl/util/mat4.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
|
||||
@@ -68,6 +69,8 @@ public:
|
||||
};
|
||||
|
||||
TEST(CustomLayer, Basic) {
|
||||
util::RunLoop loop;
|
||||
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
HeadlessView view(display, 1);
|
||||
OnlineFileSource fileSource;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
#include <mbgl/util/image.hpp>
|
||||
#include <mbgl/util/io.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
|
||||
#include <future>
|
||||
|
||||
@@ -19,6 +20,8 @@
|
||||
TEST(API, TEST_REQUIRES_SERVER(RenderMissingTile)) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
|
||||
const auto style = util::read_file("test/fixtures/api/water_missing_tiles.json");
|
||||
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
@@ -38,8 +41,7 @@ TEST(API, TEST_REQUIRES_SERVER(RenderMissingTile)) {
|
||||
|
||||
// This host does not respond (== connection error).
|
||||
map.setStyleJSON(style, "");
|
||||
std::promise<void> promise;
|
||||
map.renderStill([&promise, &message](std::exception_ptr err, PremultipliedImage&&) {
|
||||
map.renderStill([&](std::exception_ptr err, PremultipliedImage&&) {
|
||||
ASSERT_TRUE(err.operator bool());
|
||||
try {
|
||||
std::rethrow_exception(err);
|
||||
@@ -47,9 +49,10 @@ TEST(API, TEST_REQUIRES_SERVER(RenderMissingTile)) {
|
||||
message = ex.what();
|
||||
EXPECT_TRUE(message.find("connect") != std::string::npos);
|
||||
}
|
||||
promise.set_value();
|
||||
loop.stop();
|
||||
});
|
||||
promise.get_future().get();
|
||||
|
||||
loop.run();
|
||||
|
||||
auto observer = Log::removeObserver();
|
||||
auto flo = dynamic_cast<FixtureLogObserver*>(observer.get());
|
||||
|
||||
@@ -7,12 +7,15 @@
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
#include <mbgl/util/image.hpp>
|
||||
#include <mbgl/util/io.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
|
||||
#include <future>
|
||||
|
||||
TEST(API, RepeatedRender) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
|
||||
const auto style = util::read_file("test/fixtures/api/water.json");
|
||||
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
@@ -30,11 +33,15 @@ TEST(API, RepeatedRender) {
|
||||
|
||||
{
|
||||
map.setStyleJSON(style, "");
|
||||
std::promise<PremultipliedImage> promise;
|
||||
map.renderStill([&promise](std::exception_ptr, PremultipliedImage&& image) {
|
||||
promise.set_value(std::move(image));
|
||||
PremultipliedImage result;
|
||||
map.renderStill([&result](std::exception_ptr, PremultipliedImage&& image) {
|
||||
result = std::move(image);
|
||||
});
|
||||
auto result = promise.get_future().get();
|
||||
|
||||
while (!result.size()) {
|
||||
loop.runOnce();
|
||||
}
|
||||
|
||||
ASSERT_EQ(256, result.width);
|
||||
ASSERT_EQ(512, result.height);
|
||||
#if !TEST_READ_ONLY
|
||||
@@ -44,11 +51,15 @@ TEST(API, RepeatedRender) {
|
||||
|
||||
{
|
||||
map.setStyleJSON(style, "");
|
||||
std::promise<PremultipliedImage> promise;
|
||||
map.renderStill([&promise](std::exception_ptr, PremultipliedImage&& image) {
|
||||
promise.set_value(std::move(image));
|
||||
PremultipliedImage result;
|
||||
map.renderStill([&result](std::exception_ptr, PremultipliedImage&& image) {
|
||||
result = std::move(image);
|
||||
});
|
||||
auto result = promise.get_future().get();
|
||||
|
||||
while (!result.size()) {
|
||||
loop.runOnce();
|
||||
}
|
||||
|
||||
ASSERT_EQ(256, result.width);
|
||||
ASSERT_EQ(512, result.height);
|
||||
#if !TEST_READ_ONLY
|
||||
|
||||
@@ -5,11 +5,14 @@
|
||||
#include <mbgl/platform/default/headless_view.hpp>
|
||||
#include <mbgl/platform/default/headless_display.hpp>
|
||||
#include <mbgl/storage/online_file_source.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
|
||||
|
||||
TEST(API, SetStyle) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
HeadlessView view(display, 1);
|
||||
OnlineFileSource fileSource;
|
||||
|
||||
Reference in New Issue
Block a user