summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2015-04-16 10:34:30 +0200
committerKonstantin Käfer <mail@kkaefer.com>2015-04-17 13:40:42 +0200
commit46bf2269107b21d20fc84ef46a9ce5c2bfeea519 (patch)
tree5afa856c246a8c99db7cfeab55adcdc59ca50a9f /bin
parentcd496645d435a192af3060f06fbe9f2baca76d1a (diff)
downloadqtlocation-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 'bin')
-rw-r--r--bin/render.cpp34
-rw-r--r--bin/render.gyp3
2 files changed, 27 insertions, 10 deletions
diff --git a/bin/render.cpp b/bin/render.cpp
index 440256b38c..78cb5b59f5 100644
--- a/bin/render.cpp
+++ b/bin/render.cpp
@@ -1,4 +1,5 @@
#include <mbgl/map/map.hpp>
+#include <mbgl/map/still_image.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/std.hpp>
#include <mbgl/util/io.hpp>
@@ -19,12 +20,13 @@
namespace po = boost::program_options;
+#include <uv.h>
+
#include <cassert>
#include <cstdlib>
#include <iostream>
int main(int argc, char *argv[]) {
-
std::string style_path;
double lat = 0, lon = 0;
double zoom = 0;
@@ -33,7 +35,7 @@ int main(int argc, char *argv[]) {
int width = 512;
int height = 512;
double pixelRatio = 1.0;
- std::string output = "out.png";
+ static std::string output = "out.png";
std::string cache_file = "cache.sqlite";
std::vector<std::string> classes;
std::string token;
@@ -81,6 +83,8 @@ int main(int argc, char *argv[]) {
HeadlessView view;
Map map(view, fileSource);
+ map.start(Map::Mode::Static);
+
// Set access token if present
if (token.size()) {
map.setAccessToken(std::string(token));
@@ -93,14 +97,24 @@ int main(int argc, char *argv[]) {
map.setLatLngZoom({ lat, lon }, zoom);
map.setBearing(bearing);
- // Run the loop. It will terminate when we don't have any further listeners.
- map.run();
+ uv_async_t *async = new uv_async_t;
+ uv_async_init(uv_default_loop(), async, [](uv_async_t *as, int) {
+ std::unique_ptr<const StillImage> image(reinterpret_cast<const StillImage *>(as->data));
+ uv_close(reinterpret_cast<uv_handle_t *>(as), [](uv_handle_t *handle) {
+ delete reinterpret_cast<uv_async_t *>(handle);
+ });
+
+ const std::string png = util::compress_png(image->width, image->height, image->pixels.get());
+ util::write_file(output, png);
+ });
+
+ map.renderStill([async](std::unique_ptr<const StillImage> image) {
+ async->data = const_cast<StillImage *>(image.release());
+ uv_async_send(async);
+ });
- // Get the data from the GPU.
- auto pixels = view.readPixels();
+ // This loop will terminate once the async was fired.
+ uv_run(uv_default_loop(), UV_RUN_DEFAULT);
- const unsigned int w = width * pixelRatio;
- const unsigned int h = height * pixelRatio;
- const std::string image = util::compress_png(w, h, pixels.get());
- util::write_file(output, image);
+ map.stop();
}
diff --git a/bin/render.gyp b/bin/render.gyp
index 316a7f3ed0..b205e7a959 100644
--- a/bin/render.gyp
+++ b/bin/render.gyp
@@ -28,15 +28,18 @@
'variables' : {
'cflags_cc': [
'<@(glfw3_cflags)',
+ '<@(uv_cflags)',
'<@(boost_cflags)',
],
'ldflags': [
'<@(glfw3_ldflags)',
+ '<@(uv_ldflags)',
'<@(boost_ldflags)',
'-lboost_program_options'
],
'libraries': [
'<@(glfw3_static_libs)',
+ '<@(uv_static_libs)',
],
},