From bc41d3cf6d0b5c635f856d95acd0d4941802f51f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 2 Jul 2015 13:00:20 +0200 Subject: [PATCH] don't restrict pixelRatio in SpriteStore this is required so that devices that aren't using 1x or 2x (like the iPhone 6 Plus with a pixelRatio of 3x) still show icons, albeit bilinearly scaled to the correct size in the SpriteAtlas --- src/mbgl/annotation/sprite_store.cpp | 10 ---------- src/mbgl/annotation/sprite_store.hpp | 5 ----- src/mbgl/geometry/sprite_atlas.cpp | 4 ++-- src/mbgl/geometry/sprite_atlas.hpp | 3 +-- src/mbgl/style/style.cpp | 4 ++-- test/annotations/sprite_store.cpp | 19 ++++++------------- 6 files changed, 11 insertions(+), 34 deletions(-) diff --git a/src/mbgl/annotation/sprite_store.cpp b/src/mbgl/annotation/sprite_store.cpp index 91aad471b..a6b536873 100644 --- a/src/mbgl/annotation/sprite_store.cpp +++ b/src/mbgl/annotation/sprite_store.cpp @@ -2,13 +2,8 @@ #include -#include - namespace mbgl { -SpriteStore::SpriteStore(const float pixelRatio_) : pixelRatio(pixelRatio_) { -} - void SpriteStore::setSprite(const std::string& name, std::shared_ptr sprite) { std::lock_guard lock(mutex); _setSprite(name, sprite); @@ -17,11 +12,6 @@ void SpriteStore::setSprite(const std::string& name, std::shared_ptr& sprite) { if (sprite) { - if (sprite->pixelRatio != pixelRatio) { - Log::Warning(Event::Sprite, "Sprite image has wrong pixel ratio"); - return; - } - auto it = sprites.find(name); if (it != sprites.end() && (it->second->width != sprite->width || it->second->height != sprite->height)) { diff --git a/src/mbgl/annotation/sprite_store.hpp b/src/mbgl/annotation/sprite_store.hpp index ffd795280..78e02ac69 100644 --- a/src/mbgl/annotation/sprite_store.hpp +++ b/src/mbgl/annotation/sprite_store.hpp @@ -20,8 +20,6 @@ class SpriteStore : private util::noncopyable { using Sprites = std::map>; public: - SpriteStore(const float ratio); - // Adds/replaces a Sprite image. void setSprite(const std::string&, std::shared_ptr = nullptr); @@ -37,9 +35,6 @@ public: // Returns Sprite images that changed since the last invocation of this function. Sprites getDirty(); - // Pixel ratio of all sprite images in this storage object. - const float pixelRatio; - private: void _setSprite(const std::string&, const std::shared_ptr& = nullptr); diff --git a/src/mbgl/geometry/sprite_atlas.cpp b/src/mbgl/geometry/sprite_atlas.cpp index dc42a97b9..c54646355 100644 --- a/src/mbgl/geometry/sprite_atlas.cpp +++ b/src/mbgl/geometry/sprite_atlas.cpp @@ -19,11 +19,11 @@ using namespace mbgl; -SpriteAtlas::SpriteAtlas(dimension width_, dimension height_, SpriteStore& store_) +SpriteAtlas::SpriteAtlas(dimension width_, dimension height_, float pixelRatio_, SpriteStore& store_) : width(width_), height(height_), store(store_), - pixelRatio(store.pixelRatio), + pixelRatio(pixelRatio_), bin(width_, height_), dirty(true) { } diff --git a/src/mbgl/geometry/sprite_atlas.hpp b/src/mbgl/geometry/sprite_atlas.hpp index d80b9cb94..237ff0c7a 100644 --- a/src/mbgl/geometry/sprite_atlas.hpp +++ b/src/mbgl/geometry/sprite_atlas.hpp @@ -38,8 +38,7 @@ class SpriteAtlas : public util::noncopyable { public: typedef uint16_t dimension; - // Add way to construct this from another SpriteAtlas (e.g. with another pixelRatio) - SpriteAtlas(dimension width, dimension height, SpriteStore& store); + SpriteAtlas(dimension width, dimension height, float pixelRatio, SpriteStore& store); ~SpriteAtlas(); // Returns the coordinates of an image that is sourced from the sprite image. diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 93235d2a1..4c05dac0b 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -27,8 +27,8 @@ Style::Style(const std::string& json, const std::string&, MapData& data_, : data(data_), glyphStore(std::make_unique(loop)), glyphAtlas(std::make_unique(1024, 1024)), - spriteStore(std::make_unique(data.pixelRatio)), - spriteAtlas(std::make_unique(512, 512, *spriteStore)), + spriteStore(std::make_unique()), + spriteAtlas(std::make_unique(512, 512, data.pixelRatio, *spriteStore)), lineAtlas(std::make_unique(512, 512)), mtx(std::make_unique()), workers(4) { diff --git a/test/annotations/sprite_store.cpp b/test/annotations/sprite_store.cpp index 58d27bd7c..ba5c213a7 100644 --- a/test/annotations/sprite_store.cpp +++ b/test/annotations/sprite_store.cpp @@ -11,7 +11,7 @@ TEST(Annotations, SpriteStore) { const auto sprite3 = std::make_shared(8, 8, 2, std::string(16 * 16 * 4, '\0')); using Sprites = std::map>; - SpriteStore store(2); + SpriteStore store; // Adding single store.setSprite("one", sprite1); @@ -53,24 +53,17 @@ TEST(Annotations, SpriteStore) { EXPECT_EQ(Sprites(), store.getDirty()); } -TEST(Annotations, SpriteStoreWrongPixelRatio) { +TEST(Annotations, SpriteStoreOtherPixelRatio) { FixtureLog log; const auto sprite1 = std::make_shared(8, 8, 1, std::string(8 * 8 * 4, '\0')); using Sprites = std::map>; - SpriteStore store(2); + SpriteStore store; // Adding mismatched sprite image store.setSprite("one", sprite1); - EXPECT_EQ(Sprites({}), store.getDirty()); - - EXPECT_EQ(1u, log.count({ - EventSeverity::Warning, - Event::Sprite, - int64_t(-1), - "Sprite image has wrong pixel ratio", - })); + EXPECT_EQ(Sprites({ { "one", sprite1 } }), store.getDirty()); } TEST(Annotations, SpriteStoreMultiple) { @@ -78,7 +71,7 @@ TEST(Annotations, SpriteStoreMultiple) { const auto sprite2 = std::make_shared(8, 8, 2, std::string(16 * 16 * 4, '\0')); using Sprites = std::map>; - SpriteStore store(2); + SpriteStore store; store.setSprites({ { "one", sprite1 }, { "two", sprite2 }, @@ -98,7 +91,7 @@ TEST(Annotations, SpriteStoreReplaceWithDifferentDimensions) { const auto sprite2 = std::make_shared(9, 9, 2, std::string(18 * 18 * 4, '\0')); using Sprites = std::map>; - SpriteStore store(2); + SpriteStore store; store.setSprite("sprite", sprite1); store.setSprite("sprite", sprite2);