diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-07-31 18:14:26 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-07-31 18:14:26 +0200 |
commit | 75c079adb16a24cbd8b8111993a67313fd52718a (patch) | |
tree | 400207782ad718fa605414a6132dcfa20a09415d /include | |
parent | fa3a41136ca6345f34b53a1f211926cc1bd8649c (diff) | |
download | qtlocation-mapboxgl-75c079adb16a24cbd8b8111993a67313fd52718a.tar.gz |
move sprite to a use future loading
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/geometry/sprite_atlas.hpp | 17 | ||||
-rw-r--r-- | include/mbgl/map/map.hpp | 5 | ||||
-rw-r--r-- | include/mbgl/map/sprite.hpp | 32 | ||||
-rw-r--r-- | include/mbgl/map/tile_parser.hpp | 5 | ||||
-rw-r--r-- | include/mbgl/renderer/symbol_bucket.hpp | 5 | ||||
-rw-r--r-- | include/mbgl/style/style.hpp | 6 |
6 files changed, 45 insertions, 25 deletions
diff --git a/include/mbgl/geometry/sprite_atlas.hpp b/include/mbgl/geometry/sprite_atlas.hpp index 4b55540cc8..dc2378c2fb 100644 --- a/include/mbgl/geometry/sprite_atlas.hpp +++ b/include/mbgl/geometry/sprite_atlas.hpp @@ -26,18 +26,21 @@ public: // Changes the pixel ratio. bool resize(float newRatio); - // Update uninitialized sprites in this atlas from the given sprite. + // Update uninitialized (= outdated) sprites in this atlas from the given sprite. void update(const Sprite &sprite); - // Returns the coordinates of a square icon. The getter also *creates* new square icons in the - // atlas if they don't exist, but they'll be default-initialized with a a black circle. - Rect<dimension> getIcon(int size, const std::string &name); - // Returns the coordinates of an image that is sourced from the sprite image. - // This getter does not create images, as the dimension of the texture us unknown if the - // sprite is not yet loaded. Instead, it returns a 0/0/0/0 rect. + // This getter attempts to read the image from the sprite if it is already loaded. + // In that case, it copies it into the sprite atlas and returns the dimensions. + // Otherwise, it returns a 0/0/0/0 rect. Rect<dimension> getImage(const std::string &name, const Sprite &sprite); + // Returns the coordinates of an image that is sourced from the sprite image. + // This getter waits until the sprite image was loaded, copies it into the sprite + // image and returns the dimensions. + // NEVER CALL THIS FUNCTION FROM THE RENDER THREAD! it is blocking. + Rect<dimension> waitForImage(const std::string &name, const Sprite &sprite); + // Binds the image buffer of this sprite atlas to the GPU, and uploads data if it is out // of date. void bind(bool linear = false); diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 81d55b217f..0a94fc7ed2 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -21,6 +21,7 @@ class GlyphAtlas; class GlyphStore; class LayerDescription; class SpriteAtlas; +class Sprite; class Style; class StyleLayer; class StyleLayerGroup; @@ -110,10 +111,11 @@ public: public: inline const TransformState &getState() const { return state; } - inline std::shared_ptr<const Style> getStyle() const { return style; } + inline std::shared_ptr<Style> getStyle() const { return style; } inline std::shared_ptr<GlyphAtlas> getGlyphAtlas() { return glyphAtlas; } inline std::shared_ptr<GlyphStore> getGlyphStore() { return glyphStore; } inline std::shared_ptr<SpriteAtlas> getSpriteAtlas() { return spriteAtlas; } + std::shared_ptr<Sprite> getSprite(); inline std::shared_ptr<Texturepool> getTexturepool() { return texturepool; } inline std::shared_ptr<uv::loop> getLoop() { return loop; } inline timestamp getAnimationTime() const { return animationTime; } @@ -172,6 +174,7 @@ private: std::shared_ptr<GlyphAtlas> glyphAtlas; std::shared_ptr<GlyphStore> glyphStore; std::shared_ptr<SpriteAtlas> spriteAtlas; + std::shared_ptr<Sprite> sprite; std::shared_ptr<Texturepool> texturepool; Painter painter; diff --git a/include/mbgl/map/sprite.hpp b/include/mbgl/map/sprite.hpp index 3f8d5611a4..40d37d5da1 100644 --- a/include/mbgl/map/sprite.hpp +++ b/include/mbgl/map/sprite.hpp @@ -2,6 +2,7 @@ #define MBGL_STYLE_SPRITE #include <mbgl/util/image.hpp> +#include <mbgl/util/noncopyable.hpp> #include <cstdint> #include <atomic> @@ -9,6 +10,7 @@ #include <memory> #include <string> #include <unordered_map> +#include <future> namespace mbgl { @@ -28,37 +30,43 @@ public: uint8_t pixelRatio = 1; }; -class Sprite : public std::enable_shared_from_this<Sprite> { -public: - Sprite(Map &map, float pixelRatio = 1); +class Sprite : public std::enable_shared_from_this<Sprite>, private util::noncopyable { +private: + struct Key {}; + void load(); - void load(const std::string& base_url); +public: + Sprite(const Key &, const std::string& base_url, float pixelRatio); + static std::shared_ptr<Sprite> Create(const std::string& base_url, float pixelRatio); const SpritePosition &getSpritePosition(const std::string& name) const; + void waitUntilLoaded() const; bool isLoaded() const; + operator bool() const; + public: const float pixelRatio; + const std::string url; std::unique_ptr<util::Image> raster; private: - void asyncParseJSON(); - void asyncParseImage(); - - static void parseJSON(std::shared_ptr<Sprite> &sprite); - static void parseImage(std::shared_ptr<Sprite> &sprite); - static void complete(std::shared_ptr<Sprite> &sprite); + void parseJSON(); + void parseImage(); + void complete(); private: - Map ↦ - std::string url; std::string body; std::string image; std::atomic<bool> loadedImage; std::atomic<bool> loadedJSON; std::unordered_map<std::string, SpritePosition> pos; const SpritePosition empty; + + std::promise<void> promise; + std::future<void> future; + }; } diff --git a/include/mbgl/map/tile_parser.hpp b/include/mbgl/map/tile_parser.hpp index 84505c1e05..b407502434 100644 --- a/include/mbgl/map/tile_parser.hpp +++ b/include/mbgl/map/tile_parser.hpp @@ -18,6 +18,7 @@ class FontStack; class GlyphAtlas; class GlyphStore; class SpriteAtlas; +class Sprite; class Style; class StyleBucket; class StyleBucketFill; @@ -32,7 +33,8 @@ public: const std::shared_ptr<const Style> &style, const std::shared_ptr<GlyphAtlas> &glyphAtlas, const std::shared_ptr<GlyphStore> &glyphStore, - const std::shared_ptr<SpriteAtlas> &spriteAtlas); + const std::shared_ptr<SpriteAtlas> &spriteAtlas, + const std::shared_ptr<Sprite> &sprite); public: void parse(); @@ -57,6 +59,7 @@ private: std::shared_ptr<GlyphAtlas> glyphAtlas; std::shared_ptr<GlyphStore> glyphStore; std::shared_ptr<SpriteAtlas> spriteAtlas; + std::shared_ptr<Sprite> sprite; Placement placement; }; diff --git a/include/mbgl/renderer/symbol_bucket.hpp b/include/mbgl/renderer/symbol_bucket.hpp index a073856d2b..b1917a93b2 100644 --- a/include/mbgl/renderer/symbol_bucket.hpp +++ b/include/mbgl/renderer/symbol_bucket.hpp @@ -24,6 +24,7 @@ class IconShader; class DotShader; class Placement; class SpriteAtlas; +class Sprite; class GlyphAtlas; class GlyphStore; class FontStack; @@ -44,8 +45,8 @@ public: virtual bool hasIconData() const; void addFeatures(const VectorTileLayer &layer, const FilterExpression &filter, - const Tile::ID &id, SpriteAtlas &spriteAtlas, GlyphAtlas &glyphAtlas, - GlyphStore &glyphStore); + const Tile::ID &id, SpriteAtlas &spriteAtlas, Sprite &sprite, + GlyphAtlas &glyphAtlas, GlyphStore &glyphStore); void addGlyphs(const PlacedGlyphs &glyphs, float placementZoom, PlacementRange placementRange, float zoom); diff --git a/include/mbgl/style/style.hpp b/include/mbgl/style/style.hpp index 6aab71a4c6..3df58ab42b 100644 --- a/include/mbgl/style/style.hpp +++ b/include/mbgl/style/style.hpp @@ -48,13 +48,15 @@ public: const BackgroundProperties &getBackgroundProperties() const; + const std::string &getSpriteURL() const; + public: - std::shared_ptr<Sprite> sprite; std::shared_ptr<StyleLayerGroup> layers; std::vector<std::string> appliedClasses; - std::string sprite_url; std::string glyph_url; +private: + std::string sprite_url; private: PropertyTransition defaultTransition; |