move getSprite to MapContext
This commit is contained in:
committed by
John Firebaugh
parent
9580ec7b08
commit
f8600d8d97
@@ -173,8 +173,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);
|
||||
|
||||
util::ptr<Sprite> getSprite();
|
||||
|
||||
// Checks if render thread needs to pause
|
||||
void checkForPause();
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ Map::Map(View& view_, FileSource& fileSource_)
|
||||
scope(util::make_unique<EnvironmentScope>(*env, ThreadType::Main, "Main")),
|
||||
view(view_),
|
||||
data(util::make_unique<MapData>(view_)),
|
||||
context(util::make_unique<MapContext>(*env)),
|
||||
context(util::make_unique<MapContext>(*env, *data)),
|
||||
updated(static_cast<UpdateType>(Update::Nothing))
|
||||
{
|
||||
view.initialize(this);
|
||||
@@ -430,17 +430,6 @@ std::string Map::getStyleJSON() const {
|
||||
return data->getStyleInfo().json;
|
||||
}
|
||||
|
||||
util::ptr<Sprite> Map::getSprite() {
|
||||
assert(Environment::currentlyOn(ThreadType::Map));
|
||||
const float pixelRatio = data->getTransformState().getPixelRatio();
|
||||
const std::string &sprite_url = context->style->getSpriteURL();
|
||||
if (!context->sprite || !context->sprite->hasPixelRatio(pixelRatio)) {
|
||||
context->sprite = Sprite::Create(sprite_url, pixelRatio, *env);
|
||||
}
|
||||
|
||||
return context->sprite;
|
||||
}
|
||||
|
||||
#pragma mark - Size
|
||||
|
||||
void Map::resize(uint16_t width, uint16_t height, float ratio) {
|
||||
@@ -739,7 +728,7 @@ void Map::updateTiles() {
|
||||
if (!context->style) return;
|
||||
for (const auto& source : context->style->sources) {
|
||||
source->update(*data, context->getWorker(), context->style, *context->glyphAtlas, *context->glyphStore,
|
||||
*context->spriteAtlas, getSprite(), *context->texturePool, [this]() {
|
||||
*context->spriteAtlas, context->getSprite(), *context->texturePool, [this]() {
|
||||
assert(Environment::currentlyOn(ThreadType::Map));
|
||||
triggerUpdate();
|
||||
});
|
||||
@@ -854,7 +843,7 @@ void Map::prepare() {
|
||||
|
||||
// Allow the sprite atlas to potentially pull new sprite images if needed.
|
||||
context->spriteAtlas->resize(data->getTransformState().getPixelRatio());
|
||||
context->spriteAtlas->setSprite(getSprite());
|
||||
context->spriteAtlas->setSprite(context->getSprite());
|
||||
|
||||
updateTiles();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include <mbgl/map/map_context.hpp>
|
||||
#include <mbgl/map/map_data.hpp>
|
||||
#include <mbgl/map/environment.hpp>
|
||||
#include <mbgl/map/sprite.hpp>
|
||||
|
||||
#include <mbgl/renderer/painter.hpp>
|
||||
|
||||
@@ -9,6 +11,8 @@
|
||||
#include <mbgl/geometry/sprite_atlas.hpp>
|
||||
#include <mbgl/geometry/line_atlas.hpp>
|
||||
|
||||
#include <mbgl/style/style.hpp>
|
||||
|
||||
#include <mbgl/util/std.hpp>
|
||||
#include <mbgl/util/uv_detail.hpp>
|
||||
#include <mbgl/util/worker.hpp>
|
||||
@@ -16,8 +20,10 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
MapContext::MapContext(Environment& env)
|
||||
: glyphStore(util::make_unique<GlyphStore>(env)),
|
||||
MapContext::MapContext(Environment& env_, MapData& data_)
|
||||
: env(env_),
|
||||
data(data_),
|
||||
glyphStore(util::make_unique<GlyphStore>(env)),
|
||||
glyphAtlas(util::make_unique<GlyphAtlas>(1024, 1024)),
|
||||
spriteAtlas(util::make_unique<SpriteAtlas>(512, 512)),
|
||||
lineAtlas(util::make_unique<LineAtlas>(512, 512)),
|
||||
@@ -30,4 +36,15 @@ Worker& MapContext::getWorker() {
|
||||
return *workers;
|
||||
}
|
||||
|
||||
}
|
||||
util::ptr<Sprite> MapContext::getSprite() {
|
||||
assert(Environment::currentlyOn(ThreadType::Map));
|
||||
const float pixelRatio = data.getTransformState().getPixelRatio();
|
||||
const std::string &sprite_url = style->getSpriteURL();
|
||||
if (!sprite || !sprite->hasPixelRatio(pixelRatio)) {
|
||||
sprite = Sprite::Create(sprite_url, pixelRatio, env);
|
||||
}
|
||||
|
||||
return sprite;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
namespace mbgl {
|
||||
|
||||
class Environment;
|
||||
class MapData;
|
||||
class GlyphStore;
|
||||
class GlyphAtlas;
|
||||
class SpriteAtlas;
|
||||
@@ -20,12 +21,17 @@ class Worker;
|
||||
|
||||
class MapContext {
|
||||
public:
|
||||
MapContext(Environment&);
|
||||
MapContext(Environment&, MapData&);
|
||||
|
||||
Worker& getWorker();
|
||||
util::ptr<Sprite> getSprite();
|
||||
|
||||
public:
|
||||
std::unique_ptr<Worker> workers;
|
||||
|
||||
public:
|
||||
Environment& env;
|
||||
MapData& data;
|
||||
const std::unique_ptr<GlyphStore> glyphStore;
|
||||
const std::unique_ptr<GlyphAtlas> glyphAtlas;
|
||||
const std::unique_ptr<SpriteAtlas> spriteAtlas;
|
||||
|
||||
Reference in New Issue
Block a user