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
This commit is contained in:
Konstantin Käfer
2015-07-02 13:00:20 +02:00
parent 4f48874ef0
commit bc41d3cf6d
6 changed files with 11 additions and 34 deletions

View File

@@ -2,13 +2,8 @@
#include <mbgl/platform/log.hpp>
#include <mbgl/util/exception.hpp>
namespace mbgl {
SpriteStore::SpriteStore(const float pixelRatio_) : pixelRatio(pixelRatio_) {
}
void SpriteStore::setSprite(const std::string& name, std::shared_ptr<const SpriteImage> sprite) {
std::lock_guard<std::mutex> lock(mutex);
_setSprite(name, sprite);
@@ -17,11 +12,6 @@ void SpriteStore::setSprite(const std::string& name, std::shared_ptr<const Sprit
void SpriteStore::_setSprite(const std::string& name,
const std::shared_ptr<const SpriteImage>& 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)) {

View File

@@ -20,8 +20,6 @@ class SpriteStore : private util::noncopyable {
using Sprites = std::map<std::string, std::shared_ptr<const SpriteImage>>;
public:
SpriteStore(const float ratio);
// Adds/replaces a Sprite image.
void setSprite(const std::string&, std::shared_ptr<const SpriteImage> = 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<const SpriteImage>& = nullptr);

View File

@@ -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) {
}

View File

@@ -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.

View File

@@ -27,8 +27,8 @@ Style::Style(const std::string& json, const std::string&, MapData& data_,
: data(data_),
glyphStore(std::make_unique<GlyphStore>(loop)),
glyphAtlas(std::make_unique<GlyphAtlas>(1024, 1024)),
spriteStore(std::make_unique<SpriteStore>(data.pixelRatio)),
spriteAtlas(std::make_unique<SpriteAtlas>(512, 512, *spriteStore)),
spriteStore(std::make_unique<SpriteStore>()),
spriteAtlas(std::make_unique<SpriteAtlas>(512, 512, data.pixelRatio, *spriteStore)),
lineAtlas(std::make_unique<LineAtlas>(512, 512)),
mtx(std::make_unique<uv::rwlock>()),
workers(4) {

View File

@@ -11,7 +11,7 @@ TEST(Annotations, SpriteStore) {
const auto sprite3 = std::make_shared<SpriteImage>(8, 8, 2, std::string(16 * 16 * 4, '\0'));
using Sprites = std::map<std::string, std::shared_ptr<const SpriteImage>>;
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<SpriteImage>(8, 8, 1, std::string(8 * 8 * 4, '\0'));
using Sprites = std::map<std::string, std::shared_ptr<const SpriteImage>>;
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<SpriteImage>(8, 8, 2, std::string(16 * 16 * 4, '\0'));
using Sprites = std::map<std::string, std::shared_ptr<const SpriteImage>>;
SpriteStore store(2);
SpriteStore store;
store.setSprites({
{ "one", sprite1 }, { "two", sprite2 },
@@ -98,7 +91,7 @@ TEST(Annotations, SpriteStoreReplaceWithDifferentDimensions) {
const auto sprite2 = std::make_shared<SpriteImage>(9, 9, 2, std::string(18 * 18 * 4, '\0'));
using Sprites = std::map<std::string, std::shared_ptr<const SpriteImage>>;
SpriteStore store(2);
SpriteStore store;
store.setSprite("sprite", sprite1);
store.setSprite("sprite", sprite2);