[render] Add a RunLoop to render main thread
Also simplified the code making the logic more linear.
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/util/image.hpp>
|
||||
#include <mbgl/util/io.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
|
||||
#include <mbgl/platform/default/headless_view.hpp>
|
||||
#include <mbgl/platform/default/headless_display.hpp>
|
||||
#include <mbgl/platform/log.hpp>
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
#include <mbgl/storage/sqlite_cache.hpp>
|
||||
|
||||
@@ -17,18 +17,9 @@
|
||||
|
||||
namespace po = boost::program_options;
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
|
||||
#define UV_ASYNC_PARAMS(handle) uv_async_t *handle, int
|
||||
#else
|
||||
#define UV_ASYNC_PARAMS(handle) uv_async_t *handle
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
std::string style_path;
|
||||
double lat = 0, lon = 0;
|
||||
@@ -73,8 +64,9 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
using namespace mbgl;
|
||||
|
||||
mbgl::SQLiteCache cache(cache_file);
|
||||
mbgl::DefaultFileSource fileSource(&cache);
|
||||
util::RunLoop loop;
|
||||
SQLiteCache cache(cache_file);
|
||||
DefaultFileSource fileSource(&cache);
|
||||
|
||||
// Try to load the token from the environment.
|
||||
if (!token.size()) {
|
||||
@@ -102,16 +94,7 @@ int main(int argc, char *argv[]) {
|
||||
map.setDebug(debug ? mbgl::MapDebugOptions::TileBorders | mbgl::MapDebugOptions::ParseStatus : mbgl::MapDebugOptions::NoDebug);
|
||||
}
|
||||
|
||||
uv_async_t *async = new uv_async_t;
|
||||
uv_async_init(uv_default_loop(), async, [](UV_ASYNC_PARAMS(as)) {
|
||||
std::unique_ptr<PremultipliedImage> image(reinterpret_cast<PremultipliedImage*>(as->data));
|
||||
uv_close(reinterpret_cast<uv_handle_t *>(as), [](uv_handle_t *handle) {
|
||||
delete reinterpret_cast<uv_async_t *>(handle);
|
||||
});
|
||||
util::write_file(output, encodePNG(*image));
|
||||
});
|
||||
|
||||
map.renderStill([async](std::exception_ptr error, PremultipliedImage&& image) {
|
||||
map.renderStill([&](std::exception_ptr error, PremultipliedImage&& image) {
|
||||
try {
|
||||
if (error) {
|
||||
std::rethrow_exception(error);
|
||||
@@ -121,10 +104,11 @@ int main(int argc, char *argv[]) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
async->data = new PremultipliedImage(std::move(image));
|
||||
uv_async_send(async);
|
||||
util::write_file(output, encodePNG(image));
|
||||
loop.stop();
|
||||
});
|
||||
|
||||
// This loop will terminate once the async was fired.
|
||||
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
||||
loop.run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user