diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-04-16 10:34:30 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-04-17 13:40:42 +0200 |
commit | 46bf2269107b21d20fc84ef46a9ce5c2bfeea519 (patch) | |
tree | 5afa856c246a8c99db7cfeab55adcdc59ca50a9f /test | |
parent | cd496645d435a192af3060f06fbe9f2baca76d1a (diff) | |
download | qtlocation-mapboxgl-46bf2269107b21d20fc84ef46a9ce5c2bfeea519.tar.gz |
align static render mode and still image render mode
- static rendering now also runs in a separate thread; you have to start it with map.start(Map::Mode::Static) and join the thread with map.stop() before destructing the Map object
- map.renderStill() takes a callback with will be invoked on the *map* thread, so you'll have to figure out your own method of dispatching back to the main thread.
Diffstat (limited to 'test')
-rw-r--r-- | test/headless/headless.cpp | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/test/headless/headless.cpp b/test/headless/headless.cpp index f4c8accf61..4ce9b668f1 100644 --- a/test/headless/headless.cpp +++ b/test/headless/headless.cpp @@ -2,6 +2,7 @@ #include "../fixtures/fixture_log_observer.hpp" #include <mbgl/map/map.hpp> +#include <mbgl/map/still_image.hpp> #include <mbgl/util/image.hpp> #include <mbgl/util/std.hpp> @@ -15,6 +16,8 @@ #include <mbgl/platform/default/headless_display.hpp> #include <mbgl/storage/default_file_source.hpp> +#include <uv.h> + #include <dirent.h> void rewriteLocalScheme(rapidjson::Value &value, rapidjson::Document::AllocatorType &allocator) { @@ -142,6 +145,8 @@ TEST_P(HeadlessTest, render) { DefaultFileSource fileSource(nullptr); Map map(view, fileSource); + map.start(Map::Mode::Static); + map.setClasses(classes); map.setStyleJSON(style, "test/suite"); @@ -149,16 +154,34 @@ TEST_P(HeadlessTest, render) { map.setLatLngZoom(mbgl::LatLng(latitude, longitude), zoom); map.setBearing(bearing); - // Run the loop. It will terminate when we don't have any further listeners. - map.run(); - - const unsigned int w = width * pixelRatio; - const unsigned int h = height * pixelRatio; - - auto pixels = view.readPixels(); + struct Data { + std::string path; + std::unique_ptr<const StillImage> image; + }; - const std::string image = util::compress_png(w, h, pixels.get()); - util::write_file(actual_image, image); + uv_async_t *async = new uv_async_t; + async->data = new Data { "test/suite/tests/" + base + "/" + name + "/actual.png", nullptr }; + uv_async_init(uv_default_loop(), async, [](uv_async_t *as, int) { + auto data = std::unique_ptr<Data>(reinterpret_cast<Data *>(as->data)); + as->data = nullptr; + uv_close(reinterpret_cast<uv_handle_t *>(as), [](uv_handle_t *handle) { + delete reinterpret_cast<uv_async_t *>(handle); + }); + + assert(data); + const std::string png = util::compress_png(data->image->width, data->image->height, data->image->pixels.get()); + util::write_file(data->path, png); + }); + + map.renderStill([async](std::unique_ptr<const StillImage> image) { + reinterpret_cast<Data *>(async->data)->image = std::move(image); + uv_async_send(async); + }); + + // This loop will terminate once the async was fired. + uv_run(uv_default_loop(), UV_RUN_DEFAULT); + + map.stop(); } } |