From 07086981fe18aebb04eb55c24286b06eb2bf4c6f Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Thu, 25 Jun 2015 01:17:55 +0300 Subject: [PATCH] Get rid of Environment et al. mbgl::Environment is not used anymore and can removed. --- include/mbgl/map/environment.hpp | 77 -------------- src/mbgl/map/environment.cpp | 174 ------------------------------- src/mbgl/map/map_context.cpp | 5 +- src/mbgl/map/map_context.hpp | 4 - src/mbgl/map/map_data.hpp | 1 - src/mbgl/map/source.hpp | 1 - src/mbgl/storage/request.cpp | 2 - src/mbgl/style/style.cpp | 4 +- src/mbgl/style/style.hpp | 3 +- src/mbgl/text/glyph_store.cpp | 5 +- src/mbgl/text/glyph_store.hpp | 4 +- test/style/resource_loading.cpp | 10 +- 12 files changed, 9 insertions(+), 281 deletions(-) delete mode 100644 include/mbgl/map/environment.hpp delete mode 100644 src/mbgl/map/environment.cpp diff --git a/include/mbgl/map/environment.hpp b/include/mbgl/map/environment.hpp deleted file mode 100644 index d8068187e..000000000 --- a/include/mbgl/map/environment.hpp +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef MBGL_MAP_MAP_ENVIRONMENT -#define MBGL_MAP_MAP_ENVIRONMENT - -#include -#include - -#include -#include -#include - -typedef struct uv_loop_s uv_loop_t; - -namespace mbgl { - -class FileSource; -class Request; -class Response; -struct Resource; - -enum class ThreadType : uint8_t { - Unknown = 0, - Main = 1 << 0, - Map = 1 << 1, - TileWorker = 1 << 2, -}; - -class Environment final : private util::noncopyable { -public: - Environment(FileSource&); - ~Environment(); - - static Environment& Get(); - static bool inScope(); - static bool currentlyOn(ThreadType); - static std::string threadName(); - - unsigned getID() const; - - // ############################################################################################# - - // File request APIs - Request* request(const Resource&, std::function); - void cancelRequest(Request*); - - // ############################################################################################# - - // Mark OpenGL objects for deletion - void abandonVAO(uint32_t vao); - void abandonBuffer(uint32_t buffer); - void abandonTexture(uint32_t texture); - - // Actually remove the objects we marked as abandoned with the above methods. - // Only call this while the OpenGL context is exclusive to this thread. - void performCleanup(); - -private: - unsigned id; - FileSource& fileSource; - - // Stores OpenGL objects that we marked for deletion - std::vector abandonedVAOs; - std::vector abandonedBuffers; - std::vector abandonedTextures; -}; - -class EnvironmentScope final { -public: - EnvironmentScope(Environment&, ThreadType, const std::string& name); - ~EnvironmentScope(); - -private: - std::thread::id id; -}; - -} - -#endif diff --git a/src/mbgl/map/environment.cpp b/src/mbgl/map/environment.cpp deleted file mode 100644 index f2112c61b..000000000 --- a/src/mbgl/map/environment.cpp +++ /dev/null @@ -1,174 +0,0 @@ -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -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 lock(mtx); - - threadSet.emplace(std::this_thread::get_id(), ThreadInfo{ env, type, name }); - } - - void unregisterThread() { - std::lock_guard 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 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 ThreadSet; - ThreadSet threadSet; - - mutable std::mutex mtx; -}; - -unsigned makeEnvironmentID() { - static std::atomic 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(threadInfoStore.getThreadInfo().type) & static_cast(type); -} - -std::string Environment::threadName() { - return threadInfoStore.getThreadInfo().name; -} - -unsigned Environment::getID() const { - return id; -} - -Request* Environment::request(const Resource& resource, - std::function 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(abandonedVAOs.size()), - abandonedVAOs.data())); - abandonedVAOs.clear(); - } - - if (!abandonedTextures.empty()) { - MBGL_CHECK_ERROR(glDeleteTextures(static_cast(abandonedTextures.size()), - abandonedTextures.data())); - abandonedTextures.clear(); - } - - if (!abandonedBuffers.empty()) { - MBGL_CHECK_ERROR(glDeleteBuffers(static_cast(abandonedBuffers.size()), - abandonedBuffers.data())); - abandonedBuffers.clear(); - } -} - -} diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index ec1031e5a..bc4dc8c72 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include #include @@ -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(Update::Nothing)), asyncUpdate(std::make_unique(loop, [this] { update(); })), texturePool(std::make_unique()) { @@ -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