Merge branch 'master' into image-readers
This commit is contained in:
@@ -126,7 +126,6 @@ public:
|
||||
|
||||
public:
|
||||
inline const TransformState &getState() const { return state; }
|
||||
inline util::ptr<FileSource> getFileSource() const { return fileSource; }
|
||||
inline util::ptr<Style> getStyle() const { return style; }
|
||||
inline GlyphAtlas & getGlyphAtlas() { return glyphAtlas; }
|
||||
inline util::ptr<GlyphStore> getGlyphStore() { return glyphStore; }
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
namespace mbgl {
|
||||
|
||||
class Map;
|
||||
class FileSource;
|
||||
class Painter;
|
||||
class StyleLayer;
|
||||
class TransformState;
|
||||
@@ -27,9 +28,9 @@ class Source : public std::enable_shared_from_this<Source>, private util::noncop
|
||||
public:
|
||||
Source(const util::ptr<SourceInfo>& info);
|
||||
|
||||
void load(Map &map);
|
||||
void load(Map&, FileSource&);
|
||||
bool update(Map&, FileSource&);
|
||||
|
||||
bool update(Map &map);
|
||||
void updateMatrices(const mat4 &projMatrix, const TransformState &transform);
|
||||
void drawClippingMasks(Painter &painter);
|
||||
size_t getTileCount() const;
|
||||
@@ -47,9 +48,9 @@ private:
|
||||
int32_t coveringZoomLevel(const TransformState&) const;
|
||||
std::forward_list<Tile::ID> coveringTiles(const TransformState&) const;
|
||||
|
||||
bool updateTiles(Map &map);
|
||||
bool updateTiles(Map&, FileSource&);
|
||||
|
||||
TileData::State addTile(Map &map, const Tile::ID& id);
|
||||
TileData::State addTile(Map&, FileSource&, const Tile::ID&);
|
||||
TileData::State hasTile(const Tile::ID& id);
|
||||
|
||||
double getZoom(const TransformState &state) const;
|
||||
|
||||
@@ -34,11 +34,11 @@ public:
|
||||
class Sprite : public std::enable_shared_from_this<Sprite>, private util::noncopyable {
|
||||
private:
|
||||
struct Key {};
|
||||
void load(const util::ptr<FileSource> &fileSource);
|
||||
void load(FileSource& fileSource);
|
||||
|
||||
public:
|
||||
Sprite(const Key &, const std::string& base_url, float pixelRatio);
|
||||
static util::ptr<Sprite> Create(const std::string& base_url, float pixelRatio, const util::ptr<FileSource> &fileSource);
|
||||
static util::ptr<Sprite> Create(const std::string& base_url, float pixelRatio, FileSource& fileSource);
|
||||
|
||||
const SpritePosition &getSpritePosition(const std::string& name) const;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
namespace mbgl {
|
||||
|
||||
class Map;
|
||||
class FileSource;
|
||||
class Painter;
|
||||
class SourceInfo;
|
||||
class StyleLayer;
|
||||
@@ -43,7 +44,7 @@ public:
|
||||
TileData(Tile::ID const& id, Map &map, const util::ptr<SourceInfo> &source);
|
||||
~TileData();
|
||||
|
||||
void request();
|
||||
void request(FileSource&);
|
||||
void cancel();
|
||||
void reparse();
|
||||
const std::string toString() const;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <mbgl/storage/resource_type.hpp>
|
||||
#include <mbgl/storage/request.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
@@ -16,18 +17,12 @@ namespace mbgl {
|
||||
class BaseRequest;
|
||||
class SQLiteStore;
|
||||
|
||||
class FileSource {
|
||||
class FileSource : public util::noncopyable {
|
||||
private:
|
||||
FileSource(const FileSource &) = delete;
|
||||
FileSource(FileSource &&) = delete;
|
||||
FileSource& operator=(const FileSource &) = delete;
|
||||
FileSource& operator=(FileSource &&) = delete;
|
||||
|
||||
public:
|
||||
FileSource(uv_loop_t *loop, const std::string &path);
|
||||
~FileSource();
|
||||
|
||||
public:
|
||||
// Stores and retrieves the base path/URL for relative requests
|
||||
void setBase(const std::string &value);
|
||||
const std::string &getBase() const;
|
||||
|
||||
@@ -48,7 +48,7 @@ private:
|
||||
|
||||
class GlyphPBF {
|
||||
public:
|
||||
GlyphPBF(const std::string &glyphURL, const std::string &fontStack, GlyphRange glyphRange, const util::ptr<FileSource> &fileSource);
|
||||
GlyphPBF(const std::string &glyphURL, const std::string &fontStack, GlyphRange glyphRange, FileSource& fileSource);
|
||||
|
||||
private:
|
||||
GlyphPBF(const GlyphPBF &) = delete;
|
||||
@@ -71,7 +71,7 @@ private:
|
||||
// Manages Glyphrange PBF loading.
|
||||
class GlyphStore {
|
||||
public:
|
||||
GlyphStore(const util::ptr<FileSource> &fileSource);
|
||||
GlyphStore(FileSource& fileSource);
|
||||
|
||||
// Block until all specified GlyphRanges of the specified font stack are loaded.
|
||||
void waitForGlyphRanges(const std::string &fontStack, const std::set<GlyphRange> &glyphRanges);
|
||||
@@ -86,11 +86,8 @@ private:
|
||||
|
||||
FontStack &createFontStack(const std::string &fontStack);
|
||||
|
||||
public:
|
||||
std::string glyphURL;
|
||||
|
||||
private:
|
||||
const util::ptr<FileSource> fileSource;
|
||||
FileSource& fileSource;
|
||||
std::unordered_map<std::string, std::map<GlyphRange, std::unique_ptr<GlyphPBF>>> ranges;
|
||||
std::unordered_map<std::string, std::unique_ptr<FontStack>> stacks;
|
||||
std::mutex mtx;
|
||||
|
||||
@@ -346,7 +346,7 @@ void Map::setStyleJSON(std::string newStyleJSON, const std::string &base) {
|
||||
style->loadJSON((const uint8_t *)styleJSON.c_str());
|
||||
if (!fileSource) {
|
||||
fileSource = std::make_shared<FileSource>(**loop, platform::defaultCacheDatabase());
|
||||
glyphStore = std::make_shared<GlyphStore>(fileSource);
|
||||
glyphStore = std::make_shared<GlyphStore>(*fileSource);
|
||||
}
|
||||
fileSource->setBase(base);
|
||||
glyphStore->setURL(util::mapbox::normalizeGlyphsURL(style->glyph_url, getAccessToken()));
|
||||
@@ -370,7 +370,7 @@ util::ptr<Sprite> Map::getSprite() {
|
||||
const float pixelRatio = state.getPixelRatio();
|
||||
const std::string &sprite_url = style->getSpriteURL();
|
||||
if (!sprite || sprite->pixelRatio != pixelRatio) {
|
||||
sprite = Sprite::Create(sprite_url, pixelRatio, fileSource);
|
||||
sprite = Sprite::Create(sprite_url, pixelRatio, *fileSource);
|
||||
}
|
||||
|
||||
return sprite;
|
||||
@@ -607,7 +607,7 @@ void Map::updateSources() {
|
||||
if (style_source->enabled) {
|
||||
if (!style_source->source) {
|
||||
style_source->source = std::make_shared<Source>(style_source->info);
|
||||
style_source->source->load(*this);
|
||||
style_source->source->load(*this, *fileSource);
|
||||
}
|
||||
} else {
|
||||
style_source->source.reset();
|
||||
@@ -642,14 +642,14 @@ void Map::updateSources(const util::ptr<StyleLayerGroup> &group) {
|
||||
|
||||
void Map::updateTiles() {
|
||||
for (const util::ptr<StyleSource> &source : getActiveSources()) {
|
||||
source->source->update(*this);
|
||||
source->source->update(*this, *fileSource);
|
||||
}
|
||||
}
|
||||
|
||||
void Map::prepare() {
|
||||
if (!fileSource) {
|
||||
fileSource = std::make_shared<FileSource>(**loop, platform::defaultCacheDatabase());
|
||||
glyphStore = std::make_shared<GlyphStore>(fileSource);
|
||||
glyphStore = std::make_shared<GlyphStore>(*fileSource);
|
||||
}
|
||||
|
||||
if (!style) {
|
||||
|
||||
@@ -30,7 +30,7 @@ Source::Source(const util::ptr<SourceInfo>& info_)
|
||||
// Note: This is a separate function that must be called exactly once after creation
|
||||
// The reason this isn't part of the constructor is that calling shared_from_this() in
|
||||
// the constructor fails.
|
||||
void Source::load(Map& map) {
|
||||
void Source::load(Map& map, FileSource& fileSource) {
|
||||
if (info->url.empty()) {
|
||||
loaded = true;
|
||||
return;
|
||||
@@ -39,7 +39,7 @@ void Source::load(Map& map) {
|
||||
std::string url = util::mapbox::normalizeSourceURL(info->url, map.getAccessToken());
|
||||
util::ptr<Source> source = shared_from_this();
|
||||
|
||||
map.getFileSource()->request(ResourceType::JSON, url)->onload([source, &map](const Response &res) {
|
||||
fileSource.request(ResourceType::JSON, url)->onload([source, &map](const Response &res) {
|
||||
if (res.code != 200) {
|
||||
Log::Warning(Event::General, "failed to load source TileJSON");
|
||||
return;
|
||||
@@ -61,9 +61,9 @@ void Source::load(Map& map) {
|
||||
});
|
||||
}
|
||||
|
||||
bool Source::update(Map &map) {
|
||||
bool Source::update(Map& map, FileSource& fileSource) {
|
||||
if (loaded && map.getTime() > updated) {
|
||||
return updateTiles(map);
|
||||
return updateTiles(map, fileSource);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -159,7 +159,7 @@ TileData::State Source::hasTile(const Tile::ID& id) {
|
||||
return TileData::State::invalid;
|
||||
}
|
||||
|
||||
TileData::State Source::addTile(Map &map, const Tile::ID& id) {
|
||||
TileData::State Source::addTile(Map& map, FileSource& fileSource, const Tile::ID& id) {
|
||||
const TileData::State state = hasTile(id);
|
||||
|
||||
if (state != TileData::State::invalid) {
|
||||
@@ -194,7 +194,7 @@ TileData::State Source::addTile(Map &map, const Tile::ID& id) {
|
||||
throw std::runtime_error("source type not implemented");
|
||||
}
|
||||
|
||||
new_tile.data->request();
|
||||
new_tile.data->request(fileSource);
|
||||
tile_data.emplace(new_tile.data->id, new_tile.data);
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ bool Source::findLoadedParent(const Tile::ID& id, int32_t minCoveringZoom, std::
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Source::updateTiles(Map &map) {
|
||||
bool Source::updateTiles(Map& map, FileSource& fileSource) {
|
||||
bool changed = false;
|
||||
|
||||
int32_t zoom = std::floor(getZoom(map.getState()));
|
||||
@@ -298,7 +298,7 @@ bool Source::updateTiles(Map &map) {
|
||||
|
||||
// Add existing child/parent tiles if the actual tile is not yet loaded
|
||||
for (const Tile::ID& id : required) {
|
||||
const TileData::State state = addTile(map, id);
|
||||
const TileData::State state = addTile(map, fileSource, id);
|
||||
|
||||
if (state != TileData::State::parsed) {
|
||||
// The tile we require is not yet loaded. Try to find a parent or
|
||||
|
||||
@@ -22,7 +22,7 @@ SpritePosition::SpritePosition(uint16_t x_, uint16_t y_, uint16_t width_, uint16
|
||||
sdf(sdf_) {
|
||||
}
|
||||
|
||||
util::ptr<Sprite> Sprite::Create(const std::string& base_url, float pixelRatio, const util::ptr<FileSource> &fileSource) {
|
||||
util::ptr<Sprite> Sprite::Create(const std::string& base_url, float pixelRatio, FileSource& fileSource) {
|
||||
util::ptr<Sprite> sprite(std::make_shared<Sprite>(Key(), base_url, pixelRatio));
|
||||
sprite->load(fileSource);
|
||||
return sprite;
|
||||
@@ -51,7 +51,7 @@ Sprite::operator bool() const {
|
||||
// Note: This is a separate function that must be called exactly once after creation
|
||||
// The reason this isn't part of the constructor is that calling shared_from_this() in
|
||||
// the constructor fails.
|
||||
void Sprite::load(const util::ptr<FileSource> &fileSource) {
|
||||
void Sprite::load(FileSource& fileSource) {
|
||||
if (!valid) {
|
||||
// Treat a non-existent sprite as a successfully loaded empty sprite.
|
||||
loadedImage = true;
|
||||
@@ -62,7 +62,7 @@ void Sprite::load(const util::ptr<FileSource> &fileSource) {
|
||||
|
||||
util::ptr<Sprite> sprite = shared_from_this();
|
||||
|
||||
fileSource->request(ResourceType::JSON, jsonURL)->onload([sprite](const Response &res) {
|
||||
fileSource.request(ResourceType::JSON, jsonURL)->onload([sprite](const Response &res) {
|
||||
if (res.code == 200) {
|
||||
sprite->body = res.data;
|
||||
sprite->parseJSON();
|
||||
@@ -75,7 +75,7 @@ void Sprite::load(const util::ptr<FileSource> &fileSource) {
|
||||
}
|
||||
});
|
||||
|
||||
fileSource->request(ResourceType::Image, spriteURL)->onload([sprite](const Response &res) {
|
||||
fileSource.request(ResourceType::Image, spriteURL)->onload([sprite](const Response &res) {
|
||||
if (res.code == 200) {
|
||||
sprite->image = res.data;
|
||||
sprite->parseImage();
|
||||
|
||||
@@ -28,7 +28,7 @@ const std::string TileData::toString() const {
|
||||
return util::sprintf<32>("[tile %d/%d/%d]", id.z, id.x, id.y);
|
||||
}
|
||||
|
||||
void TileData::request() {
|
||||
void TileData::request(FileSource& fileSource) {
|
||||
if (source->tiles.empty())
|
||||
return;
|
||||
|
||||
@@ -45,7 +45,7 @@ void TileData::request() {
|
||||
|
||||
// Note: Somehow this feels slower than the change to request_http()
|
||||
std::weak_ptr<TileData> weak_tile = shared_from_this();
|
||||
req = map.getFileSource()->request(ResourceType::Tile, url);
|
||||
req = fileSource.request(ResourceType::Tile, url);
|
||||
req->onload([weak_tile, url](const Response &res) {
|
||||
util::ptr<TileData> tile = weak_tile.lock();
|
||||
if (!tile || tile->state == State::obsolete) {
|
||||
|
||||
@@ -66,12 +66,6 @@ void Transform::_moveBy(const double dx, const double dy, const timestamp durati
|
||||
|
||||
constrain(final.scale, final.y);
|
||||
|
||||
// Un-rotate when rotated and panning far enough to show off-world in corners.
|
||||
double w = final.scale * util::tileSize / 2;
|
||||
double m = std::sqrt(std::pow((current.width / 2), 2) + pow((current.height / 2), 2));
|
||||
double x = std::abs(sqrt(std::pow(final.x, 2) + std::pow(final.y, 2)));
|
||||
if (current.angle && w - x < m) _setAngle(0);
|
||||
|
||||
if (duration == 0) {
|
||||
current.x = final.x;
|
||||
current.y = final.y;
|
||||
|
||||
@@ -137,7 +137,7 @@ void FontStack::lineWrap(Shaping &shaping, const float lineHeight, const float m
|
||||
align(shaping, justify, horizontalAlign, verticalAlign, maxLineLength, lineHeight, line);
|
||||
}
|
||||
|
||||
GlyphPBF::GlyphPBF(const std::string &glyphURL, const std::string &fontStack, GlyphRange glyphRange, const util::ptr<FileSource> &fileSource)
|
||||
GlyphPBF::GlyphPBF(const std::string &glyphURL, const std::string &fontStack, GlyphRange glyphRange, FileSource& fileSource)
|
||||
: future(promise.get_future().share())
|
||||
{
|
||||
// Load the glyph set URL
|
||||
@@ -148,8 +148,8 @@ GlyphPBF::GlyphPBF(const std::string &glyphURL, const std::string &fontStack, Gl
|
||||
});
|
||||
|
||||
// The prepare call jumps back to the main thread.
|
||||
fileSource->prepare([&, url, fileSource] {
|
||||
auto request = fileSource->request(ResourceType::Glyphs, url);
|
||||
fileSource.prepare([&, url] {
|
||||
auto request = fileSource.request(ResourceType::Glyphs, url);
|
||||
request->onload([&, url](const Response &res) {
|
||||
if (res.code != 200) {
|
||||
// Something went wrong with loading the glyph pbf. Pass on the error to the future listeners.
|
||||
@@ -228,7 +228,7 @@ void GlyphPBF::parse(FontStack &stack) {
|
||||
data.clear();
|
||||
}
|
||||
|
||||
GlyphStore::GlyphStore(const util::ptr<FileSource> &fileSource_) : fileSource(fileSource_) {}
|
||||
GlyphStore::GlyphStore(FileSource& fileSource_) : fileSource(fileSource_) {}
|
||||
|
||||
void GlyphStore::setURL(const std::string &url) {
|
||||
glyphURL = url;
|
||||
|
||||
Reference in New Issue
Block a user