Privatize remaining MapContext members
This commit is contained in:
@@ -131,7 +131,6 @@ public:
|
||||
|
||||
// Memory
|
||||
void setSourceTileCacheSize(size_t);
|
||||
size_t getSourceTileCacheSize() const { return sourceCacheSize; }
|
||||
void onLowMemory();
|
||||
|
||||
// Debug
|
||||
@@ -149,7 +148,6 @@ private:
|
||||
void resize(uint16_t width, uint16_t height, float ratio = 1);
|
||||
void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight);
|
||||
|
||||
size_t sourceCacheSize;
|
||||
const std::unique_ptr<Environment> env;
|
||||
std::unique_ptr<EnvironmentScope> scope;
|
||||
View &view;
|
||||
|
||||
@@ -54,8 +54,6 @@ Map::~Map() {
|
||||
static_cast<uint8_t>(ThreadType::Map)),
|
||||
"MapandMain");
|
||||
|
||||
// Explicitly reset all pointers.
|
||||
context->style.reset();
|
||||
context.reset();
|
||||
|
||||
uv_run(env->loop, UV_RUN_DEFAULT);
|
||||
@@ -162,7 +160,7 @@ void Map::renderSync() {
|
||||
|
||||
context->triggerRender();
|
||||
|
||||
context->rendered.wait();
|
||||
data->rendered.wait();
|
||||
}
|
||||
|
||||
void Map::update() {
|
||||
@@ -383,9 +381,7 @@ void Map::setDefaultPointAnnotationSymbol(const std::string& symbol) {
|
||||
double Map::getTopOffsetPixelsForAnnotationSymbol(const std::string& symbol) {
|
||||
assert(Environment::currentlyOn(ThreadType::Main));
|
||||
return context->invokeSyncTask([&] {
|
||||
assert(context->sprite);
|
||||
const SpritePosition pos = context->sprite->getSpritePosition(symbol);
|
||||
return -pos.height / pos.pixelRatio / 2;
|
||||
return context->getTopOffsetPixelsForAnnotationSymbol(symbol);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -487,25 +483,14 @@ Duration Map::getDefaultTransitionDuration() {
|
||||
|
||||
|
||||
void Map::setSourceTileCacheSize(size_t size) {
|
||||
if (size != getSourceTileCacheSize()) {
|
||||
context->invokeTask([=] {
|
||||
sourceCacheSize = size;
|
||||
if (!context->style) return;
|
||||
for (const auto &source : context->style->sources) {
|
||||
source->setCacheSize(sourceCacheSize);
|
||||
}
|
||||
env->performCleanup();
|
||||
});
|
||||
}
|
||||
context->invokeTask([=] {
|
||||
context->setSourceTileCacheSize(size);
|
||||
});
|
||||
}
|
||||
|
||||
void Map::onLowMemory() {
|
||||
context->invokeTask([=] {
|
||||
if (!context->style) return;
|
||||
for (const auto &source : context->style->sources) {
|
||||
source->onLowMemory();
|
||||
}
|
||||
env->performCleanup();
|
||||
context->onLowMemory();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,11 @@ MapContext::MapContext(Environment& env_, View& view_, MapData& data_)
|
||||
painter(util::make_unique<Painter>(*spriteAtlas, *glyphAtlas, *lineAtlas)) {
|
||||
}
|
||||
|
||||
MapContext::~MapContext() {
|
||||
// TODO: does this need to happen first for some reason?
|
||||
style.reset();
|
||||
}
|
||||
|
||||
void MapContext::start() {
|
||||
// Setup async notifications
|
||||
assert(!asyncTerminate);
|
||||
@@ -85,7 +90,7 @@ void MapContext::start() {
|
||||
render();
|
||||
|
||||
// Finally, notify all listeners that we have finished rendering this frame.
|
||||
rendered.notify();
|
||||
data.rendered.notify();
|
||||
});
|
||||
|
||||
data.thread = std::thread([this]() {
|
||||
@@ -410,4 +415,32 @@ void MapContext::processTasks() {
|
||||
}
|
||||
}
|
||||
|
||||
double MapContext::getTopOffsetPixelsForAnnotationSymbol(const std::string& symbol) {
|
||||
assert(Environment::currentlyOn(ThreadType::Map));
|
||||
assert(sprite);
|
||||
const SpritePosition pos = sprite->getSpritePosition(symbol);
|
||||
return -pos.height / pos.pixelRatio / 2;
|
||||
}
|
||||
|
||||
void MapContext::setSourceTileCacheSize(size_t size) {
|
||||
assert(Environment::currentlyOn(ThreadType::Map));
|
||||
if (size != sourceCacheSize) {
|
||||
sourceCacheSize = size;
|
||||
if (!style) return;
|
||||
for (const auto &source : style->sources) {
|
||||
source->setCacheSize(sourceCacheSize);
|
||||
}
|
||||
env.performCleanup();
|
||||
}
|
||||
}
|
||||
|
||||
void MapContext::onLowMemory() {
|
||||
assert(Environment::currentlyOn(ThreadType::Map));
|
||||
if (!style) return;
|
||||
for (const auto &source : style->sources) {
|
||||
source->onLowMemory();
|
||||
}
|
||||
env.performCleanup();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <mbgl/map/tile_id.hpp>
|
||||
#include <mbgl/map/update.hpp>
|
||||
#include <mbgl/util/ptr.hpp>
|
||||
#include <mbgl/util/signal.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
@@ -33,6 +32,7 @@ class Worker;
|
||||
class MapContext {
|
||||
public:
|
||||
MapContext(Environment&, View&, MapData&);
|
||||
~MapContext();
|
||||
|
||||
// Starts the map thread.
|
||||
void start();
|
||||
@@ -57,6 +57,13 @@ public:
|
||||
return promise.get_future().get();
|
||||
}
|
||||
|
||||
double getTopOffsetPixelsForAnnotationSymbol(const std::string& symbol);
|
||||
void setSourceTileCacheSize(size_t size);
|
||||
void onLowMemory();
|
||||
|
||||
// TODO: Make this private
|
||||
public: void updateAnnotationTiles(const std::vector<TileID>& ids);
|
||||
|
||||
// These can only be called from the Map thread.
|
||||
private:
|
||||
// Checks if render thread needs to pause
|
||||
@@ -66,58 +73,52 @@ private:
|
||||
util::ptr<Sprite> getSprite();
|
||||
void updateTiles();
|
||||
|
||||
// TODO: Make these private
|
||||
public: void updateAnnotationTiles(const std::vector<TileID>& ids);
|
||||
|
||||
// Triggered by triggerUpdate();
|
||||
private: void update();
|
||||
void update();
|
||||
|
||||
// Prepares a map render by updating the tiles we need for the current view, as well as updating
|
||||
// the stylesheet.
|
||||
public: void prepare();
|
||||
void prepare();
|
||||
|
||||
// Unconditionally performs a render with the current map state.
|
||||
public: void render();
|
||||
void render();
|
||||
|
||||
// Runs the enqueued tasks.
|
||||
private: void processTasks();
|
||||
void processTasks();
|
||||
|
||||
private:
|
||||
// Loads the style set in the data object. Called by Update::StyleInfo
|
||||
private: void reloadStyle();
|
||||
void reloadStyle();
|
||||
|
||||
// Loads the actual JSON object an creates a new Style object.
|
||||
private: void loadStyleJSON(const std::string& json, const std::string& base);
|
||||
void loadStyleJSON(const std::string& json, const std::string& base);
|
||||
|
||||
// TODO: Make all of these private
|
||||
public:
|
||||
private: Environment& env;
|
||||
private: View& view;
|
||||
private: MapData& data;
|
||||
Environment& env;
|
||||
View& view;
|
||||
MapData& data;
|
||||
|
||||
private: std::atomic<UpdateType> updated { static_cast<UpdateType>(Update::Nothing) };
|
||||
std::atomic<UpdateType> updated { static_cast<UpdateType>(Update::Nothing) };
|
||||
|
||||
private: std::mutex mutexTask;
|
||||
private: std::queue<std::function<void()>> tasks;
|
||||
std::mutex mutexTask;
|
||||
std::queue<std::function<void()>> tasks;
|
||||
|
||||
|
||||
public: std::unique_ptr<uv::async> asyncUpdate;
|
||||
public: std::unique_ptr<uv::async> asyncRender;
|
||||
public: std::unique_ptr<uv::async> asyncInvoke;
|
||||
public: std::unique_ptr<uv::async> asyncTerminate;
|
||||
std::unique_ptr<uv::async> asyncUpdate;
|
||||
std::unique_ptr<uv::async> asyncRender;
|
||||
std::unique_ptr<uv::async> asyncInvoke;
|
||||
std::unique_ptr<uv::async> asyncTerminate;
|
||||
|
||||
public: std::unique_ptr<Worker> workers;
|
||||
private: const std::unique_ptr<GlyphStore> glyphStore;
|
||||
private: const std::unique_ptr<GlyphAtlas> glyphAtlas;
|
||||
private: const std::unique_ptr<SpriteAtlas> spriteAtlas;
|
||||
private: const std::unique_ptr<LineAtlas> lineAtlas;
|
||||
private: const std::unique_ptr<TexturePool> texturePool;
|
||||
public: const std::unique_ptr<Painter> painter;
|
||||
public: util::ptr<Sprite> sprite;
|
||||
public: util::ptr<Style> style;
|
||||
std::unique_ptr<Worker> workers;
|
||||
const std::unique_ptr<GlyphStore> glyphStore;
|
||||
const std::unique_ptr<GlyphAtlas> glyphAtlas;
|
||||
const std::unique_ptr<SpriteAtlas> spriteAtlas;
|
||||
const std::unique_ptr<LineAtlas> lineAtlas;
|
||||
const std::unique_ptr<TexturePool> texturePool;
|
||||
const std::unique_ptr<Painter> painter;
|
||||
|
||||
// Used to signal that rendering completed.
|
||||
public: util::Signal rendered;
|
||||
util::ptr<Sprite> sprite;
|
||||
util::ptr<Style> style;
|
||||
|
||||
size_t sourceCacheSize;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define MBGL_MAP_MAP_DATA
|
||||
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
#include <mbgl/util/signal.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
@@ -122,8 +123,12 @@ private:
|
||||
std::atomic<Duration> animationTime;
|
||||
std::atomic<Duration> defaultTransitionDuration;
|
||||
|
||||
// TODO: make private
|
||||
public:
|
||||
// TODO: make private
|
||||
// Used to signal that rendering completed.
|
||||
public: util::Signal rendered;
|
||||
|
||||
// TODO: document
|
||||
bool terminating = false;
|
||||
|
||||
std::thread thread;
|
||||
|
||||
Reference in New Issue
Block a user