diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-05-22 13:28:09 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-05-26 11:21:56 -0700 |
commit | aa216d00254c18f7b5903026ab1a489ae7797dd8 (patch) | |
tree | 7decb42cb0f8a8a5ae0e9d3bdcfdf69e76949e15 /src/mbgl/sprite | |
parent | 6cf9d5cfbfe8120121d8d53cbbf8915cea8f4879 (diff) | |
download | qtlocation-mapboxgl-aa216d00254c18f7b5903026ab1a489ae7797dd8.tar.gz |
[core] Don't use a separate SpriteAtlas for annotation images
Instead, just add them to the Style as needed. Includes changes from #8905 and takes care to avoid regressing #3817.
Diffstat (limited to 'src/mbgl/sprite')
-rw-r--r-- | src/mbgl/sprite/sprite_atlas.cpp | 18 | ||||
-rw-r--r-- | src/mbgl/sprite/sprite_atlas.hpp | 8 | ||||
-rw-r--r-- | src/mbgl/sprite/sprite_image_collection.cpp | 40 | ||||
-rw-r--r-- | src/mbgl/sprite/sprite_image_collection.hpp | 24 |
4 files changed, 17 insertions, 73 deletions
diff --git a/src/mbgl/sprite/sprite_atlas.cpp b/src/mbgl/sprite/sprite_atlas.cpp index d3f0072b20..97bf9edcf9 100644 --- a/src/mbgl/sprite/sprite_atlas.cpp +++ b/src/mbgl/sprite/sprite_atlas.cpp @@ -44,7 +44,7 @@ SpriteAtlas::SpriteAtlas() SpriteAtlas::~SpriteAtlas() = default; void SpriteAtlas::onSpriteLoaded() { - markAsLoaded(); + loaded = true; for (auto requestor : requestors) { requestor->onIconsAvailable(buildIconMap()); } @@ -106,8 +106,20 @@ const style::Image::Impl* SpriteAtlas::getImage(const std::string& id) const { return nullptr; } -void SpriteAtlas::getIcons(IconRequestor& requestor) { - if (isLoaded()) { +void SpriteAtlas::getIcons(IconRequestor& requestor, IconDependencies dependencies) { + // If the sprite has been loaded, or if all the icon dependencies are already present + // (i.e. if they've been addeded via runtime styling), then notify the requestor immediately. + // Otherwise, delay notification until the sprite is loaded. At that point, if any of the + // dependencies are still unavailable, we'll just assume they are permanently missing. + bool hasAllDependencies = true; + if (!isLoaded()) { + for (const auto& dependency : dependencies) { + if (entries.find(dependency) == entries.end()) { + hasAllDependencies = false; + } + } + } + if (isLoaded() || hasAllDependencies) { requestor.onIconsAvailable(buildIconMap()); } else { requestors.insert(&requestor); diff --git a/src/mbgl/sprite/sprite_atlas.hpp b/src/mbgl/sprite/sprite_atlas.hpp index f5c7fd114a..807c871731 100644 --- a/src/mbgl/sprite/sprite_atlas.hpp +++ b/src/mbgl/sprite/sprite_atlas.hpp @@ -66,10 +66,6 @@ public: void onSpriteLoaded(); - void markAsLoaded() { - loaded = true; - } - bool isLoaded() const { return loaded; } @@ -80,8 +76,8 @@ public: void addImage(Immutable<style::Image::Impl>); void removeImage(const std::string&); - void getIcons(IconRequestor& requestor); - void removeRequestor(IconRequestor& requestor); + void getIcons(IconRequestor&, IconDependencies); + void removeRequestor(IconRequestor&); // Ensure that the atlas contains the named image suitable for rendering as an icon, and // return its metrics. The image will be padded on each side with a one pixel wide transparent diff --git a/src/mbgl/sprite/sprite_image_collection.cpp b/src/mbgl/sprite/sprite_image_collection.cpp deleted file mode 100644 index ae00a6b146..0000000000 --- a/src/mbgl/sprite/sprite_image_collection.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include <mbgl/sprite/sprite_image_collection.hpp> -#include <mbgl/util/logging.hpp> - -namespace mbgl { - -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 - it = images.emplace(id, std::move(image_)).first; - onAdded(*it->second.get()); - return; - } - - std::unique_ptr<style::Image>& image = it->second; - - // There is already a sprite with that name in our store. - if (image->getImage().size != image_->getImage().size) { - Log::Warning(Event::Sprite, "Can't change sprite dimensions for '%s'", id.c_str()); - } - - // Update existing - image = std::move(image_); - onAdded(*it->second.get()); -} - -void removeSpriteImage(Images& images, - const std::string& id, - std::function<void ()> onRemoved) { - if (images.erase(id) > 0) { - onRemoved(); - } -} - - - -} // namespace mbgl diff --git a/src/mbgl/sprite/sprite_image_collection.hpp b/src/mbgl/sprite/sprite_image_collection.hpp deleted file mode 100644 index 44c7bcd411..0000000000 --- a/src/mbgl/sprite/sprite_image_collection.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include <mbgl/style/image.hpp> - -#include <functional> -#include <memory> -#include <string> -#include <unordered_map> - -namespace mbgl { - -using Images = std::unordered_map<std::string, std::unique_ptr<style::Image>>; - -void addSpriteImage(Images&, - std::unique_ptr<style::Image>, - std::function<void (style::Image&)> onAdded = [] (style::Image&){}); - -void removeSpriteImage(Images&, - const std::string&, - std::function<void ()> onRemoved = [] (){}); - - - -} // namespace mbgl |