diff options
author | Thiago Marcos P. Santos <thiago@mapbox.com> | 2015-06-25 01:17:55 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2015-06-25 16:26:22 +0300 |
commit | 07086981fe18aebb04eb55c24286b06eb2bf4c6f (patch) | |
tree | 5a1da73b7f546e3c714d70959a7bf45602898e9a /src | |
parent | e32b0b7e20179c24ffa12325b4d5e184941acbb8 (diff) | |
download | qtlocation-mapboxgl-07086981fe18aebb04eb55c24286b06eb2bf4c6f.tar.gz |
Get rid of Environment et al.
mbgl::Environment is not used anymore and can
removed.
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/map/environment.cpp | 174 | ||||
-rw-r--r-- | src/mbgl/map/map_context.cpp | 5 | ||||
-rw-r--r-- | src/mbgl/map/map_context.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/map/map_data.hpp | 1 | ||||
-rw-r--r-- | src/mbgl/map/source.hpp | 1 | ||||
-rw-r--r-- | src/mbgl/storage/request.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/style/style.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/style/style.hpp | 3 | ||||
-rw-r--r-- | src/mbgl/text/glyph_store.cpp | 5 | ||||
-rw-r--r-- | src/mbgl/text/glyph_store.hpp | 4 |
10 files changed, 7 insertions, 196 deletions
diff --git a/src/mbgl/map/environment.cpp b/src/mbgl/map/environment.cpp deleted file mode 100644 index f2112c61b2..0000000000 --- a/src/mbgl/map/environment.cpp +++ /dev/null @@ -1,174 +0,0 @@ -#include <mbgl/map/environment.hpp> -#include <mbgl/storage/file_source.hpp> -#include <mbgl/platform/gl.hpp> -#include <mbgl/util/run_loop.hpp> -#include <mbgl/geometry/vao.hpp> - -#include <uv.h> - -#include <atomic> -#include <cassert> -#include <mutex> -#include <unordered_map> - -namespace mbgl { - -namespace { - -class ThreadInfoStore { -private: - struct ThreadInfo { - Environment* env; - ThreadType type; - std::string name; - }; - -public: - ThreadInfoStore() { - registerThread(nullptr, ThreadType::Main, "Main"); - } - - ~ThreadInfoStore() { - unregisterThread(); - assert(threadSet.size() == 0); - } - - void registerThread(Environment* env, ThreadType type, const std::string& name) { - std::lock_guard<std::mutex> lock(mtx); - - threadSet.emplace(std::this_thread::get_id(), ThreadInfo{ env, type, name }); - } - - void unregisterThread() { - std::lock_guard<std::mutex> lock(mtx); - - ThreadSet::iterator it = threadSet.find(std::this_thread::get_id()); - if (it != threadSet.end()) { - threadSet.erase(it); - } - } - - const ThreadInfo& getThreadInfo() const { - static ThreadInfo emptyInfo; - std::lock_guard<std::mutex> lock(mtx); - - ThreadSet::const_iterator it = threadSet.find(std::this_thread::get_id()); - if (it != threadSet.end()) { - return it->second; - } else { - return emptyInfo; - } - } - -private: - typedef std::unordered_map<std::thread::id, ThreadInfo> ThreadSet; - ThreadSet threadSet; - - mutable std::mutex mtx; -}; - -unsigned makeEnvironmentID() { - static std::atomic<unsigned> id(0); - return id++; -} - -ThreadInfoStore threadInfoStore; - -} // namespace - -EnvironmentScope::EnvironmentScope(Environment& env, ThreadType type, const std::string& name) - : id(std::this_thread::get_id()) { - threadInfoStore.registerThread(&env, type, name); -} - -EnvironmentScope::~EnvironmentScope() { - assert(id == std::this_thread::get_id()); - threadInfoStore.unregisterThread(); -} - -Environment::Environment(FileSource& fs) - : id(makeEnvironmentID()), fileSource(fs) { -} - -Environment::~Environment() { - assert(abandonedVAOs.empty()); - assert(abandonedTextures.empty()); - assert(abandonedBuffers.empty()); -} - -Environment& Environment::Get() { - Environment* env = threadInfoStore.getThreadInfo().env; - assert(env); - - return *env; -} - -bool Environment::inScope() { - return threadInfoStore.getThreadInfo().env; -} - -bool Environment::currentlyOn(ThreadType type) { - return static_cast<uint8_t>(threadInfoStore.getThreadInfo().type) & static_cast<uint8_t>(type); -} - -std::string Environment::threadName() { - return threadInfoStore.getThreadInfo().name; -} - -unsigned Environment::getID() const { - return id; -} - -Request* Environment::request(const Resource& resource, - std::function<void(const Response&)> callback) { - return fileSource.request(resource, util::RunLoop::current.get()->get(), std::move(callback)); -} - -void Environment::cancelRequest(Request* req) { - assert(currentlyOn(ThreadType::Map)); - fileSource.cancel(req); -} - -// ############################################################################################# - -#pragma mark - OpenGL cleanup - -void Environment::abandonVAO(uint32_t vao) { - assert(currentlyOn(ThreadType::Map)); - abandonedVAOs.emplace_back(vao); -} - -void Environment::abandonBuffer(uint32_t buffer) { - assert(currentlyOn(ThreadType::Map)); - abandonedBuffers.emplace_back(buffer); -} - -void Environment::abandonTexture(uint32_t texture) { - assert(currentlyOn(ThreadType::Map)); - abandonedTextures.emplace_back(texture); -} - -// Actually remove the objects we marked as abandoned with the above methods. -void Environment::performCleanup() { - assert(currentlyOn(ThreadType::Map)); - - if (!abandonedVAOs.empty()) { - MBGL_CHECK_ERROR(VertexArrayObject::Delete(static_cast<GLsizei>(abandonedVAOs.size()), - abandonedVAOs.data())); - abandonedVAOs.clear(); - } - - if (!abandonedTextures.empty()) { - MBGL_CHECK_ERROR(glDeleteTextures(static_cast<GLsizei>(abandonedTextures.size()), - abandonedTextures.data())); - abandonedTextures.clear(); - } - - if (!abandonedBuffers.empty()) { - MBGL_CHECK_ERROR(glDeleteBuffers(static_cast<GLsizei>(abandonedBuffers.size()), - abandonedBuffers.data())); - abandonedBuffers.clear(); - } -} - -} diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index ec1031e5ac..bc4dc8c723 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -1,7 +1,6 @@ #include <mbgl/map/map_context.hpp> #include <mbgl/map/map_data.hpp> #include <mbgl/map/view.hpp> -#include <mbgl/map/environment.hpp> #include <mbgl/map/still_image.hpp> #include <mbgl/map/annotation.hpp> @@ -30,8 +29,6 @@ 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<UpdateType>(Update::Nothing)), asyncUpdate(std::make_unique<uv::async>(loop, [this] { update(); })), texturePool(std::make_unique<TexturePool>()) { @@ -117,7 +114,7 @@ void MapContext::loadStyleJSON(const std::string& json, const std::string& base) assert(util::ThreadContext::currentlyOn(util::ThreadType::Map)); style.reset(); - style = std::make_unique<Style>(json, base, asyncUpdate->get()->loop, env); + style = std::make_unique<Style>(json, base, asyncUpdate->get()->loop); style->cascade(data.getClasses()); style->setDefaultTransitionDuration(data.getDefaultTransitionDuration()); style->setObserver(this); diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp index 87e748d878..6185db4a55 100644 --- a/src/mbgl/map/map_context.hpp +++ b/src/mbgl/map/map_context.hpp @@ -3,7 +3,6 @@ #include <mbgl/map/tile_id.hpp> #include <mbgl/map/update.hpp> -#include <mbgl/map/environment.hpp> #include <mbgl/map/transform_state.hpp> #include <mbgl/style/style.hpp> #include <mbgl/util/gl_object_store.hpp> @@ -79,9 +78,6 @@ private: util::GLObjectStore glObjectStore; - Environment env; - EnvironmentScope envScope; - UpdateType updated { static_cast<UpdateType>(Update::Nothing) }; std::unique_ptr<uv::async> asyncUpdate; diff --git a/src/mbgl/map/map_data.hpp b/src/mbgl/map/map_data.hpp index 32722d07e8..2d22a00689 100644 --- a/src/mbgl/map/map_data.hpp +++ b/src/mbgl/map/map_data.hpp @@ -11,7 +11,6 @@ #include <condition_variable> #include <mbgl/map/mode.hpp> -#include <mbgl/map/environment.hpp> #include <mbgl/map/transform.hpp> #include <mbgl/map/transform_state.hpp> #include <mbgl/map/annotation.hpp> diff --git a/src/mbgl/map/source.hpp b/src/mbgl/map/source.hpp index dbc1272d71..6b0b23f266 100644 --- a/src/mbgl/map/source.hpp +++ b/src/mbgl/map/source.hpp @@ -22,7 +22,6 @@ namespace mbgl { class MapData; -class Environment; class GlyphAtlas; class GlyphStore; class SpriteAtlas; diff --git a/src/mbgl/storage/request.cpp b/src/mbgl/storage/request.cpp index b653a41e71..79d441442d 100644 --- a/src/mbgl/storage/request.cpp +++ b/src/mbgl/storage/request.cpp @@ -1,8 +1,6 @@ #include <mbgl/storage/request.hpp> -#include <mbgl/map/environment.hpp> #include <mbgl/storage/response.hpp> - #include <mbgl/util/util.hpp> #include <mbgl/util/uv_detail.hpp> diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 24771e1859..15dffd113b 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -20,8 +20,8 @@ namespace mbgl { Style::Style(const std::string& data, const std::string&, - uv_loop_t* loop, Environment& env) - : glyphStore(std::make_unique<GlyphStore>(loop, env)), + uv_loop_t* loop) + : glyphStore(std::make_unique<GlyphStore>(loop)), glyphAtlas(std::make_unique<GlyphAtlas>(1024, 1024)), spriteAtlas(std::make_unique<SpriteAtlas>(512, 512)), lineAtlas(std::make_unique<LineAtlas>(512, 512)), diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index 7e83a3e700..003183e3c2 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -20,7 +20,6 @@ namespace mbgl { -class Environment; class GlyphAtlas; class GlyphStore; class SpriteAtlas; @@ -34,7 +33,7 @@ class Style : public GlyphStore::Observer, public: Style(const std::string& data, const std::string& base, - uv_loop_t*, Environment&); + uv_loop_t*); ~Style(); class Observer { diff --git a/src/mbgl/text/glyph_store.cpp b/src/mbgl/text/glyph_store.cpp index 9afa765424..0f507deb44 100644 --- a/src/mbgl/text/glyph_store.cpp +++ b/src/mbgl/text/glyph_store.cpp @@ -7,9 +7,8 @@ namespace mbgl { -GlyphStore::GlyphStore(uv_loop_t* loop, Environment& env_) - : env(env_), - asyncEmitGlyphRangeLoaded(std::make_unique<uv::async>(loop, [this] { emitGlyphRangeLoaded(); })), +GlyphStore::GlyphStore(uv_loop_t* loop) + : asyncEmitGlyphRangeLoaded(std::make_unique<uv::async>(loop, [this] { emitGlyphRangeLoaded(); })), asyncEmitGlyphRangeLoadedingFailed(std::make_unique<uv::async>(loop, [this] { emitGlyphRangeLoadingFailed(); })), observer(nullptr) { asyncEmitGlyphRangeLoaded->unref(); diff --git a/src/mbgl/text/glyph_store.hpp b/src/mbgl/text/glyph_store.hpp index 746bcd1338..a1f69b9943 100644 --- a/src/mbgl/text/glyph_store.hpp +++ b/src/mbgl/text/glyph_store.hpp @@ -18,7 +18,6 @@ class async; namespace mbgl { -class Environment; class FontStack; class GlyphPBF; @@ -33,7 +32,7 @@ public: virtual void onGlyphRangeLoadingFailed(std::exception_ptr error) = 0; }; - GlyphStore(uv_loop_t* loop, Environment &); + GlyphStore(uv_loop_t* loop); ~GlyphStore(); // Asynchronously request for GlyphRanges and when it gets loaded, notifies the @@ -55,7 +54,6 @@ private: util::exclusive<FontStack> createFontStack(const std::string &fontStack); std::string glyphURL; - Environment &env; std::unordered_map<std::string, std::map<GlyphRange, std::unique_ptr<GlyphPBF>>> ranges; std::mutex rangesMutex; |