#include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace mbgl { MapContext::MapContext(uv_loop_t* loop, View& view_, FileSource& fileSource, MapData& data_) : view(view_), data(data_), env(fileSource), envScope(env, ThreadType::Map, "Map"), updated(static_cast(Update::Nothing)), asyncUpdate(std::make_unique(loop, [this] { update(); })), texturePool(std::make_unique()) { assert(Environment::currentlyOn(ThreadType::Map)); asyncUpdate->unref(); view.activate(); } MapContext::~MapContext() { // Make sure we call cleanup() before deleting this object. assert(!style); } void MapContext::cleanup() { view.notify(); // Explicit resets currently necessary because these abandon resources that need to be // cleaned up by env.performCleanup(); style.reset(); painter.reset(); texturePool.reset(); env.performCleanup(); view.deactivate(); } void MapContext::pause() { MBGL_CHECK_ERROR(glFinish()); view.deactivate(); std::unique_lock lockPause(data.mutexPause); data.condPaused.notify_all(); data.condResume.wait(lockPause); view.activate(); } void MapContext::resize(uint16_t width, uint16_t height, float ratio) { view.resize(width, height, ratio); triggerUpdate(); } void MapContext::triggerUpdate(const Update u) { updated |= static_cast(u); asyncUpdate->send(); } void MapContext::setStyleURL(const std::string& url) { styleURL = url; styleJSON.clear(); const size_t pos = styleURL.rfind('/'); std::string base = ""; if (pos != std::string::npos) { base = styleURL.substr(0, pos + 1); } env.request({ Resource::Kind::Style, styleURL }, [this, base](const Response &res) { if (res.status == Response::Successful) { loadStyleJSON(res.data, base); } else { Log::Error(Event::Setup, "loading style failed: %s", res.message.c_str()); } }); } void MapContext::setStyleJSON(const std::string& json, const std::string& base) { styleURL.clear(); styleJSON = json; loadStyleJSON(json, base); } void MapContext::loadStyleJSON(const std::string& json, const std::string& base) { assert(Environment::currentlyOn(ThreadType::Map)); style.reset(); style = std::make_unique