summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-05-15 14:09:06 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-05-16 12:26:35 -0700
commitcc1ea759a681cadcfd06fd7bdda79ca6deb38c62 (patch)
tree97ece422b0516b11979c84b8136f95aeabb1aa91 /src
parentc0f6e5ccefc67dbdaa6ab7c7ea75a2a2d0c3f2ae (diff)
downloadqtlocation-mapboxgl-cc1ea759a681cadcfd06fd7bdda79ca6deb38c62.tar.gz
[core, node, darwin, android, qt] Make image ID part of Image
More like Source and Layer.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/annotation/annotation_manager.cpp6
-rw-r--r--src/mbgl/annotation/annotation_manager.hpp2
-rw-r--r--src/mbgl/map/map.cpp8
-rw-r--r--src/mbgl/sprite/sprite_atlas.cpp13
-rw-r--r--src/mbgl/sprite/sprite_atlas.hpp6
-rw-r--r--src/mbgl/sprite/sprite_image_collection.cpp4
-rw-r--r--src/mbgl/sprite/sprite_image_collection.hpp1
-rw-r--r--src/mbgl/sprite/sprite_loader.cpp5
-rw-r--r--src/mbgl/sprite/sprite_loader.hpp6
-rw-r--r--src/mbgl/sprite/sprite_loader_observer.hpp7
-rw-r--r--src/mbgl/sprite/sprite_parser.cpp25
-rw-r--r--src/mbgl/sprite/sprite_parser.hpp24
-rw-r--r--src/mbgl/style/image.cpp9
-rw-r--r--src/mbgl/style/image_impl.cpp10
-rw-r--r--src/mbgl/style/image_impl.hpp4
-rw-r--r--src/mbgl/style/style.cpp22
-rw-r--r--src/mbgl/style/style.hpp4
17 files changed, 69 insertions, 87 deletions
diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp
index 8e75f8e63f..a7f1c69f3b 100644
--- a/src/mbgl/annotation/annotation_manager.cpp
+++ b/src/mbgl/annotation/annotation_manager.cpp
@@ -191,9 +191,9 @@ void AnnotationManager::removeTile(AnnotationTile& tile) {
tiles.erase(&tile);
}
-void AnnotationManager::addImage(const std::string& id, std::unique_ptr<style::Image> image) {
- addSpriteImage(spriteImages, id, std::move(image), [&](style::Image& added) {
- spriteAtlas.addImage(id, added.impl);
+void AnnotationManager::addImage(std::unique_ptr<style::Image> image) {
+ addSpriteImage(spriteImages, std::move(image), [&](style::Image& added) {
+ spriteAtlas.addImage(added.impl);
});
}
diff --git a/src/mbgl/annotation/annotation_manager.hpp b/src/mbgl/annotation/annotation_manager.hpp
index 69232677f9..837827b75c 100644
--- a/src/mbgl/annotation/annotation_manager.hpp
+++ b/src/mbgl/annotation/annotation_manager.hpp
@@ -33,7 +33,7 @@ public:
Update updateAnnotation(const AnnotationID&, const Annotation&, const uint8_t maxZoom);
void removeAnnotation(const AnnotationID&);
- void addImage(const std::string&, std::unique_ptr<style::Image>);
+ void addImage(std::unique_ptr<style::Image>);
void removeImage(const std::string&);
double getTopOffsetPixelsForImage(const std::string&);
SpriteAtlas& getSpriteAtlas() { return spriteAtlas; }
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index c6d3ed9915..e994428bf1 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -788,8 +788,8 @@ LatLng Map::latLngForPixel(const ScreenCoordinate& pixel) const {
#pragma mark - Annotations
-void Map::addAnnotationImage(const std::string& id, std::unique_ptr<style::Image> image) {
- impl->annotationManager->addImage(id, std::move(image));
+void Map::addAnnotationImage(std::unique_ptr<style::Image> image) {
+ impl->annotationManager->addImage(std::move(image));
}
void Map::removeAnnotationImage(const std::string& id) {
@@ -936,13 +936,13 @@ std::unique_ptr<Layer> Map::removeLayer(const std::string& id) {
return removedLayer;
}
-void Map::addImage(const std::string& id, std::unique_ptr<style::Image> image) {
+void Map::addImage(std::unique_ptr<style::Image> image) {
if (!impl->style) {
return;
}
impl->styleMutated = true;
- impl->style->addImage(id, std::move(image));
+ impl->style->addImage(std::move(image));
}
void Map::removeImage(const std::string& id) {
diff --git a/src/mbgl/sprite/sprite_atlas.cpp b/src/mbgl/sprite/sprite_atlas.cpp
index f677f7bb60..0f4cde56ad 100644
--- a/src/mbgl/sprite/sprite_atlas.cpp
+++ b/src/mbgl/sprite/sprite_atlas.cpp
@@ -42,25 +42,20 @@ SpriteAtlas::SpriteAtlas(Size size_, float pixelRatio_)
SpriteAtlas::~SpriteAtlas() = default;
-void SpriteAtlas::onSpriteLoaded(Images&& result) {
+void SpriteAtlas::onSpriteLoaded() {
markAsLoaded();
-
- for (auto& pair : result) {
- addImage(pair.first, pair.second->impl);
- }
-
for (auto requestor : requestors) {
requestor->onIconsAvailable(buildIconMap());
}
requestors.clear();
}
-void SpriteAtlas::addImage(const std::string& id, Immutable<style::Image::Impl> image_) {
+void SpriteAtlas::addImage(Immutable<style::Image::Impl> image_) {
icons.clear();
- auto it = entries.find(id);
+ auto it = entries.find(image_->id);
if (it == entries.end()) {
- entries.emplace(id, Entry { std::move(image_), {}, {} });
+ entries.emplace(image_->id, Entry { image_, {}, {} });
return;
}
diff --git a/src/mbgl/sprite/sprite_atlas.hpp b/src/mbgl/sprite/sprite_atlas.hpp
index 4e03c32b30..bcec26b7ba 100644
--- a/src/mbgl/sprite/sprite_atlas.hpp
+++ b/src/mbgl/sprite/sprite_atlas.hpp
@@ -43,12 +43,10 @@ public:
class SpriteAtlas : public util::noncopyable {
public:
- using Images = std::unordered_map<std::string, std::unique_ptr<style::Image>>;
-
SpriteAtlas(Size, float pixelRatio);
~SpriteAtlas();
- void onSpriteLoaded(Images&&);
+ void onSpriteLoaded();
void markAsLoaded() {
loaded = true;
@@ -61,7 +59,7 @@ public:
void dumpDebugLogs() const;
const style::Image::Impl* getImage(const std::string&) const;
- void addImage(const std::string&, Immutable<style::Image::Impl>);
+ void addImage(Immutable<style::Image::Impl>);
void removeImage(const std::string&);
void getIcons(IconRequestor& requestor);
diff --git a/src/mbgl/sprite/sprite_image_collection.cpp b/src/mbgl/sprite/sprite_image_collection.cpp
index 787ba83db2..ae00a6b146 100644
--- a/src/mbgl/sprite/sprite_image_collection.cpp
+++ b/src/mbgl/sprite/sprite_image_collection.cpp
@@ -3,10 +3,10 @@
namespace mbgl {
-void addSpriteImage(Images& images, const std::string& id,
+void addSpriteImage(Images& images,
std::unique_ptr<style::Image> image_,
std::function<void (style::Image&)> onAdded) {
-
+ std::string id = image_->getID();
auto it = images.find(id);
if (it == images.end()) {
// Add new
diff --git a/src/mbgl/sprite/sprite_image_collection.hpp b/src/mbgl/sprite/sprite_image_collection.hpp
index 00e252f74f..44c7bcd411 100644
--- a/src/mbgl/sprite/sprite_image_collection.hpp
+++ b/src/mbgl/sprite/sprite_image_collection.hpp
@@ -12,7 +12,6 @@ namespace mbgl {
using Images = std::unordered_map<std::string, std::unique_ptr<style::Image>>;
void addSpriteImage(Images&,
- const std::string&,
std::unique_ptr<style::Image>,
std::function<void (style::Image&)> onAdded = [] (style::Image&){});
diff --git a/src/mbgl/sprite/sprite_loader.cpp b/src/mbgl/sprite/sprite_loader.cpp
index 86325bba35..7c5fe40e05 100644
--- a/src/mbgl/sprite/sprite_loader.cpp
+++ b/src/mbgl/sprite/sprite_loader.cpp
@@ -89,10 +89,7 @@ void SpriteLoader::emitSpriteLoadedIfComplete() {
loader->worker.invoke(&SpriteLoaderWorker::parse, loader->image, loader->json);
}
-void SpriteLoader::onParsed(Images&& result) {
-
-
-
+void SpriteLoader::onParsed(std::vector<std::unique_ptr<style::Image>>&& result) {
observer->onSpriteLoaded(std::move(result));
}
diff --git a/src/mbgl/sprite/sprite_loader.hpp b/src/mbgl/sprite/sprite_loader.hpp
index dbebede03b..0daf46be9c 100644
--- a/src/mbgl/sprite/sprite_loader.hpp
+++ b/src/mbgl/sprite/sprite_loader.hpp
@@ -6,7 +6,7 @@
#include <string>
#include <map>
#include <set>
-#include <unordered_map>
+#include <vector>
#include <array>
#include <memory>
@@ -18,8 +18,6 @@ class SpriteLoaderObserver;
class SpriteLoader : public util::noncopyable {
public:
- using Images = std::unordered_map<std::string, std::unique_ptr<style::Image>>;
-
SpriteLoader(float pixelRatio);
~SpriteLoader();
@@ -32,7 +30,7 @@ private:
// Invoked by SpriteAtlasWorker
friend class SpriteLoaderWorker;
- void onParsed(Images&& result);
+ void onParsed(std::vector<std::unique_ptr<style::Image>>&&);
void onError(std::exception_ptr);
const float pixelRatio;
diff --git a/src/mbgl/sprite/sprite_loader_observer.hpp b/src/mbgl/sprite/sprite_loader_observer.hpp
index 632c48ea56..c730549c2c 100644
--- a/src/mbgl/sprite/sprite_loader_observer.hpp
+++ b/src/mbgl/sprite/sprite_loader_observer.hpp
@@ -2,8 +2,7 @@
#include <exception>
#include <memory>
-#include <unordered_map>
-#include <string>
+#include <vector>
namespace mbgl {
@@ -13,11 +12,9 @@ class Image;
class SpriteLoaderObserver {
public:
- using Images = std::unordered_map<std::string, std::unique_ptr<style::Image>>;
-
virtual ~SpriteLoaderObserver() = default;
- virtual void onSpriteLoaded(Images&&) {}
+ virtual void onSpriteLoaded(std::vector<std::unique_ptr<style::Image>>&&) {}
virtual void onSpriteError(std::exception_ptr) {}
};
diff --git a/src/mbgl/sprite/sprite_parser.cpp b/src/mbgl/sprite/sprite_parser.cpp
index c3ed20d03f..1a36e3e990 100644
--- a/src/mbgl/sprite/sprite_parser.cpp
+++ b/src/mbgl/sprite/sprite_parser.cpp
@@ -13,13 +13,14 @@
namespace mbgl {
-std::unique_ptr<style::Image> createStyleImage(const PremultipliedImage& image,
- const uint32_t srcX,
- const uint32_t srcY,
- const uint32_t width,
- const uint32_t height,
- const double ratio,
- const bool sdf) {
+std::unique_ptr<style::Image> createStyleImage(const std::string& id,
+ const PremultipliedImage& image,
+ const uint32_t srcX,
+ const uint32_t srcY,
+ const uint32_t width,
+ const uint32_t height,
+ const double ratio,
+ const bool sdf) {
// Disallow invalid parameter configurations.
if (width <= 0 || height <= 0 || width > 1024 || height > 1024 ||
ratio <= 0 || ratio > 10 ||
@@ -37,7 +38,7 @@ std::unique_ptr<style::Image> createStyleImage(const PremultipliedImage& image,
// Copy from the source image into our individual sprite image
PremultipliedImage::copy(image, dstImage, { srcX, srcY }, { 0, 0 }, { width, height });
- return std::make_unique<style::Image>(std::move(dstImage), ratio, sdf);
+ return std::make_unique<style::Image>(id, std::move(dstImage), ratio, sdf);
}
namespace {
@@ -84,7 +85,7 @@ bool getBoolean(const JSValue& value, const char* name, const bool def = false)
} // namespace
-Images parseSprite(const std::string& encodedImage, const std::string& json) {
+std::vector<std::unique_ptr<style::Image>> parseSprite(const std::string& encodedImage, const std::string& json) {
const PremultipliedImage raster = decodeImage(encodedImage);
JSDocument doc;
@@ -96,7 +97,7 @@ Images parseSprite(const std::string& encodedImage, const std::string& json) {
} else if (!doc.IsObject()) {
throw std::runtime_error("Sprite JSON root must be an object");
} else {
- Images images;
+ std::vector<std::unique_ptr<style::Image>> images;
for (const auto& property : doc.GetObject()) {
const std::string name = { property.name.GetString(), property.name.GetStringLength() };
const JSValue& value = property.value;
@@ -109,9 +110,9 @@ Images parseSprite(const std::string& encodedImage, const std::string& json) {
const double pixelRatio = getDouble(value, "pixelRatio", 1);
const bool sdf = getBoolean(value, "sdf", false);
- auto image = createStyleImage(raster, x, y, width, height, pixelRatio, sdf);
+ auto image = createStyleImage(name, raster, x, y, width, height, pixelRatio, sdf);
if (image) {
- images.emplace(name, std::move(image));
+ images.push_back(std::move(image));
}
}
}
diff --git a/src/mbgl/sprite/sprite_parser.hpp b/src/mbgl/sprite/sprite_parser.hpp
index 175ec8a883..f602818d3b 100644
--- a/src/mbgl/sprite/sprite_parser.hpp
+++ b/src/mbgl/sprite/sprite_parser.hpp
@@ -1,13 +1,10 @@
#pragma once
#include <mbgl/util/image.hpp>
-#include <mbgl/util/noncopyable.hpp>
-#include <mbgl/util/variant.hpp>
-#include <mbgl/util/geo.hpp>
#include <string>
#include <memory>
-#include <unordered_map>
+#include <vector>
namespace mbgl {
@@ -16,17 +13,16 @@ class Image;
} // namespace style
// Extracts an individual image from a spritesheet from the given location.
-std::unique_ptr<style::Image> createStyleImage(const PremultipliedImage&,
- uint32_t srcX,
- uint32_t srcY,
- uint32_t srcWidth,
- uint32_t srcHeight,
- double ratio,
- bool sdf);
-
-using Images = std::unordered_map<std::string, std::unique_ptr<style::Image>>;
+std::unique_ptr<style::Image> createStyleImage(const std::string& id,
+ const PremultipliedImage&,
+ uint32_t srcX,
+ uint32_t srcY,
+ uint32_t srcWidth,
+ uint32_t srcHeight,
+ double ratio,
+ bool sdf);
// Parses an image and an associated JSON file and returns the sprite objects.
-Images parseSprite(const std::string& image, const std::string& json);
+std::vector<std::unique_ptr<style::Image>> parseSprite(const std::string& image, const std::string& json);
} // namespace mbgl
diff --git a/src/mbgl/style/image.cpp b/src/mbgl/style/image.cpp
index 606d9907a4..3b35fa76f1 100644
--- a/src/mbgl/style/image.cpp
+++ b/src/mbgl/style/image.cpp
@@ -5,10 +5,15 @@
namespace mbgl {
namespace style {
-Image::Image(PremultipliedImage &&image,
+Image::Image(std::string id,
+ PremultipliedImage &&image,
const float pixelRatio,
bool sdf)
- : impl(makeMutable<Impl>(std::move(image), pixelRatio, sdf)) {
+ : impl(makeMutable<Impl>(std::move(id), std::move(image), pixelRatio, sdf)) {
+}
+
+std::string Image::getID() const {
+ return impl->id;
}
const PremultipliedImage& Image::getImage() const {
diff --git a/src/mbgl/style/image_impl.cpp b/src/mbgl/style/image_impl.cpp
index 910bffa905..ce327262e8 100644
--- a/src/mbgl/style/image_impl.cpp
+++ b/src/mbgl/style/image_impl.cpp
@@ -4,10 +4,12 @@
namespace mbgl {
namespace style {
-Image::Impl::Impl(PremultipliedImage&& image_,
- const float pixelRatio_,
- bool sdf_)
- : image(std::move(image_)),
+Image::Impl::Impl(std::string id_,
+ PremultipliedImage&& image_,
+ const float pixelRatio_,
+ bool sdf_)
+ : id(std::move(id_)),
+ image(std::move(image_)),
pixelRatio(pixelRatio_),
sdf(sdf_) {
diff --git a/src/mbgl/style/image_impl.hpp b/src/mbgl/style/image_impl.hpp
index dce4a6e4c0..b088a23261 100644
--- a/src/mbgl/style/image_impl.hpp
+++ b/src/mbgl/style/image_impl.hpp
@@ -7,7 +7,9 @@ namespace style {
class Image::Impl {
public:
- Impl(PremultipliedImage&&, float pixelRatio, bool sdf = false);
+ Impl(std::string id, PremultipliedImage&&, float pixelRatio, bool sdf = false);
+
+ const std::string id;
PremultipliedImage image;
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index f601c4126c..84ee841c06 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -505,9 +505,9 @@ bool Style::isLoaded() const {
return true;
}
-void Style::addImage(const std::string& id, std::unique_ptr<style::Image> image) {
- addSpriteImage(spriteImages, id, std::move(image), [&](style::Image& added) {
- spriteAtlas->addImage(id, added.impl);
+void Style::addImage(std::unique_ptr<style::Image> image) {
+ addSpriteImage(spriteImages, std::move(image), [&](style::Image& added) {
+ spriteAtlas->addImage(added.impl);
observer->onUpdate(Update::Repaint);
});
}
@@ -735,19 +735,11 @@ void Style::onTileError(RenderSource& source, const OverscaledTileID& tileID, st
observer->onResourceError(error);
}
-void Style::onSpriteLoaded(SpriteLoader::Images&& images) {
- // Add images to collection
- Images addedImages;
- for (auto& entry : images) {
- addSpriteImage(spriteImages, entry.first, std::move(entry.second), [&] (style::Image& added) {
- addedImages.emplace(entry.first, std::make_unique<Image>(added));
- });
+void Style::onSpriteLoaded(std::vector<std::unique_ptr<Image>>&& images) {
+ for (auto& image : images) {
+ addImage(std::move(image));
}
-
- // Update render sprite atlas
- spriteAtlas->onSpriteLoaded(std::move(addedImages));
-
- // Update observer
+ spriteAtlas->onSpriteLoaded();
observer->onUpdate(Update::Repaint); // For *-pattern properties.
}
diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp
index b4ff4f9ac4..bc1d52eed8 100644
--- a/src/mbgl/style/style.hpp
+++ b/src/mbgl/style/style.hpp
@@ -101,7 +101,7 @@ public:
const RenderLight& getRenderLight() const;
const style::Image* getImage(const std::string&) const;
- void addImage(const std::string&, std::unique_ptr<style::Image>);
+ void addImage(std::unique_ptr<style::Image>);
void removeImage(const std::string&);
RenderData getRenderData(MapDebugOptions, float angle) const;
@@ -151,7 +151,7 @@ private:
// SpriteLoaderObserver implementation.
std::unordered_map<std::string, std::unique_ptr<style::Image>> spriteImages;
- void onSpriteLoaded(SpriteLoaderObserver::Images&&) override;
+ void onSpriteLoaded(std::vector<std::unique_ptr<Image>>&&) override;
void onSpriteError(std::exception_ptr) override;
// SourceObserver implementation.