#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace mbgl { MapContext::MapContext(View& view_, FileSource& fileSource, MapData& data_) : view(view_), data(data_), asyncUpdate(std::make_unique(util::RunLoop::getLoop(), [this] { update(); })), asyncInvalidate(std::make_unique(util::RunLoop::getLoop(), [&view_] { view_.invalidate(); })), texturePool(std::make_unique()) { assert(util::ThreadContext::currentlyOn(util::ThreadType::Map)); util::ThreadContext::setFileSource(&fileSource); util::ThreadContext::setGLObjectStore(&glObjectStore); asyncUpdate->unref(); asyncInvalidate->unref(); view.activate(); } MapContext::~MapContext() { // Make sure we call cleanup() before deleting this object. assert(!style); } void MapContext::cleanup() { view.notify(); styleRequest = nullptr; // Explicit resets currently necessary because these abandon resources that need to be // cleaned up by glObjectStore.performCleanup(); style.reset(); painter.reset(); texturePool.reset(); glObjectStore.performCleanup(); view.deactivate(); } void MapContext::pause() { MBGL_CHECK_ERROR(glFinish()); view.deactivate(); std::unique_lock lockPause(data.mutexPause); data.paused = true; data.condPause.notify_all(); data.condPause.wait(lockPause, [&]{ return !data.paused; }); view.activate(); asyncInvalidate->send(); } void MapContext::triggerUpdate(const TransformState& state, const Update flags) { transformState = state; updateFlags |= flags; asyncUpdate->send(); } void MapContext::setStyleURL(const std::string& url) { if (styleURL == url) { return; } styleRequest = nullptr; styleURL = url; styleJSON.clear(); style = std::make_unique