Get rid of Environment et al.
mbgl::Environment is not used anymore and can removed.
This commit is contained in:
@@ -1,77 +0,0 @@
|
||||
#ifndef MBGL_MAP_MAP_ENVIRONMENT
|
||||
#define MBGL_MAP_MAP_ENVIRONMENT
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/util.hpp>
|
||||
|
||||
#include <thread>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
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(const Response&)>);
|
||||
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<uint32_t> abandonedVAOs;
|
||||
std::vector<uint32_t> abandonedBuffers;
|
||||
std::vector<uint32_t> abandonedTextures;
|
||||
};
|
||||
|
||||
class EnvironmentScope final {
|
||||
public:
|
||||
EnvironmentScope(Environment&, ThreadType, const std::string& name);
|
||||
~EnvironmentScope();
|
||||
|
||||
private:
|
||||
std::thread::id id;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
namespace mbgl {
|
||||
|
||||
class MapData;
|
||||
class Environment;
|
||||
class GlyphAtlas;
|
||||
class GlyphStore;
|
||||
class SpriteAtlas;
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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)),
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "mock_file_source.hpp"
|
||||
#include "mock_view.hpp"
|
||||
|
||||
#include <mbgl/map/environment.hpp>
|
||||
#include <mbgl/map/map_data.hpp>
|
||||
#include <mbgl/map/transform_state.hpp>
|
||||
#include <mbgl/style/style.hpp>
|
||||
@@ -25,9 +24,7 @@ public:
|
||||
View& view,
|
||||
FileSource& fileSource,
|
||||
const std::function<void(std::exception_ptr error)>& callback)
|
||||
: env_(fileSource),
|
||||
envScope_(env_, ThreadType::Map, "Map"),
|
||||
data_(view, MapMode::Still),
|
||||
: data_(view, MapMode::Still),
|
||||
callback_(callback) {
|
||||
util::ThreadContext::setFileSource(&fileSource);
|
||||
|
||||
@@ -35,7 +32,7 @@ public:
|
||||
data_.transform.setLatLngZoom({0, 0}, 16);
|
||||
|
||||
const std::string style = util::read_file("test/fixtures/resources/style.json");
|
||||
style_ = std::make_unique<Style>(style, "", loop, env_),
|
||||
style_ = std::make_unique<Style>(style, "", loop),
|
||||
style_->setObserver(this);
|
||||
}
|
||||
|
||||
@@ -67,9 +64,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
Environment env_;
|
||||
EnvironmentScope envScope_;
|
||||
|
||||
MapData data_;
|
||||
TransformState transformState_;
|
||||
TexturePool texturePool_;
|
||||
|
||||
Reference in New Issue
Block a user