summaryrefslogtreecommitdiff
path: root/src/map/map.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/map.cpp')
-rw-r--r--src/map/map.cpp54
1 files changed, 28 insertions, 26 deletions
diff --git a/src/map/map.cpp b/src/map/map.cpp
index f255c3ff65..2f0dceb427 100644
--- a/src/map/map.cpp
+++ b/src/map/map.cpp
@@ -30,17 +30,17 @@
using namespace mbgl;
-Map::Map(View& view)
+Map::Map(View& view_)
: loop(std::make_shared<uv::loop>()),
thread(std::make_unique<uv::thread>()),
async_terminate(new uv_async_t()),
async_render(new uv_async_t()),
async_cleanup(new uv_async_t()),
- view(view),
+ view(view_),
#ifndef NDEBUG
main_thread(uv_thread_self()),
#endif
- transform(view),
+ transform(view_),
glyphAtlas(std::make_shared<GlyphAtlas>(1024, 1024)),
spriteAtlas(std::make_shared<SpriteAtlas>(512, 512)),
texturepool(std::make_shared<Texturepool>()),
@@ -91,15 +91,28 @@ void Map::start() {
is_stopped = false;
// Setup async notifications
- uv_async_init(**loop, async_terminate.get(), terminate);
+
+// Iron out the differences between libuv 0.10 and 0.11
+#ifdef UV_ASYNC_CALLBACK
+#error Cannot overwrite UV_ASYNC_CALLBACK
+#endif
+#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
+#define UV_ASYNC_CALLBACK(name) [](uv_async_t *a, int) { return Map::name(a); }
+#else
+#define UV_ASYNC_CALLBACK(name) name
+#endif
+
+ uv_async_init(**loop, async_terminate.get(), UV_ASYNC_CALLBACK(terminate));
async_terminate->data = this;
- uv_async_init(**loop, async_render.get(), render);
+ uv_async_init(**loop, async_render.get(), UV_ASYNC_CALLBACK(render));
async_render->data = this;
- uv_async_init(**loop, async_cleanup.get(), cleanup);
+ uv_async_init(**loop, async_cleanup.get(), UV_ASYNC_CALLBACK(cleanup));
async_cleanup->data = this;
+#undef UV_ASYNC_CALLBACK
+
uv_thread_create(*thread, [](void *arg) {
Map *map = static_cast<Map *>(arg);
#ifndef NDEBUG
@@ -163,7 +176,6 @@ void Map::run() {
// If the map rendering wasn't started asynchronously, we perform one render
// *after* all events have been processed.
if (!async) {
- prepare();
render();
#ifndef NDEBUG
map_thread = -1;
@@ -199,17 +211,16 @@ void Map::cleanup() {
}
}
-#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
-void Map::cleanup(uv_async_t *async, int) {
-#else
void Map::cleanup(uv_async_t *async) {
-#endif
Map *map = static_cast<Map *>(async->data);
- map->view.make_active();
map->painter.cleanup();
}
+void Map::terminate() {
+ painter.terminate();
+}
+
void Map::setReachability(bool reachable) {
// Note: This function may be called from *any* thread.
if (reachable) {
@@ -221,11 +232,7 @@ void Map::setReachability(bool reachable) {
}
}
-#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
-void Map::render(uv_async_t *async, int) {
-#else
void Map::render(uv_async_t *async) {
-#endif
Map *map = static_cast<Map *>(async->data);
assert(uv_thread_self() == map->map_thread);
@@ -245,11 +252,7 @@ void Map::render(uv_async_t *async) {
}
}
-#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
-void Map::terminate(uv_async_t *async, int) {
-#else
void Map::terminate(uv_async_t *async) {
-#endif
// Closes all open handles on the loop. This means that the loop will automatically terminate.
Map *map = static_cast<Map *>(async->data);
assert(uv_thread_self() == map->map_thread);
@@ -271,8 +274,8 @@ void Map::terminate(uv_async_t *async) {
void Map::setup() {
assert(uv_thread_self() == map_thread);
view.make_active();
-
painter.setup();
+ view.make_inactive();
}
void Map::setStyleURL(const std::string &url) {
@@ -605,8 +608,6 @@ void Map::updateRenderState() {
}
void Map::prepare() {
- view.make_active();
-
if (!fileSource) {
fileSource = std::make_shared<FileSource>(**loop, platform::defaultCacheDatabase());
glyphStore = std::make_shared<GlyphStore>(fileSource);
@@ -651,9 +652,8 @@ void Map::prepare() {
}
void Map::render() {
-#if defined(DEBUG)
- std::vector<std::string> debug;
-#endif
+ view.make_active();
+
painter.clear();
painter.resize();
@@ -685,6 +685,8 @@ void Map::render() {
}
glFlush();
+
+ view.make_inactive();
}
void Map::renderLayers(util::ptr<StyleLayerGroup> group) {