diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-02-13 15:53:51 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-02-14 16:28:12 -0600 |
commit | 58de1e15c5e3f4983f445eacefb2fcc931371788 (patch) | |
tree | 8510ea78a42b98efa904caf8157102b5afb85849 /src/mbgl/sprite | |
parent | 5524506abd7194456e187532201260b075ea4d93 (diff) | |
download | qtlocation-mapboxgl-58de1e15c5e3f4983f445eacefb2fcc931371788.tar.gz |
[core] Inline SpriteAtlas::allocateImage
Diffstat (limited to 'src/mbgl/sprite')
-rw-r--r-- | src/mbgl/sprite/sprite_atlas.cpp | 33 | ||||
-rw-r--r-- | src/mbgl/sprite/sprite_atlas.hpp | 1 |
2 files changed, 11 insertions, 23 deletions
diff --git a/src/mbgl/sprite/sprite_atlas.cpp b/src/mbgl/sprite/sprite_atlas.cpp index 606ad4f9b8..1ca40f6c2d 100644 --- a/src/mbgl/sprite/sprite_atlas.cpp +++ b/src/mbgl/sprite/sprite_atlas.cpp @@ -174,27 +174,6 @@ std::shared_ptr<const SpriteImage> SpriteAtlas::getSprite(const std::string& nam } } -Rect<uint16_t> SpriteAtlas::allocateImage(const SpriteImage& spriteImage) { - - const uint16_t pixel_width = std::ceil(spriteImage.image.size.width / pixelRatio); - const uint16_t pixel_height = std::ceil(spriteImage.image.size.height / pixelRatio); - - // Increase to next number divisible by 4, but at least 1. - // This is so we can scale down the texture coordinates and pack them - // into 2 bytes rather than 4 bytes. - const uint16_t pack_width = (pixel_width + 1) + (4 - (pixel_width + 1) % 4); - const uint16_t pack_height = (pixel_height + 1) + (4 - (pixel_height + 1) % 4); - - // We have to allocate a new area in the bin, and store an empty image in it. - // Add a 1px border around every image. - Rect<uint16_t> rect = bin.allocate(pack_width, pack_height); - if (rect.w == 0) { - return rect; - } - - return rect; -} - optional<SpriteAtlasElement> SpriteAtlas::getImage(const std::string& name, const SpritePatternMode mode) { std::lock_guard<std::recursive_mutex> lock(mutex); @@ -225,7 +204,17 @@ optional<SpriteAtlasElement> SpriteAtlas::getImage(const std::string& name, }; } - Rect<uint16_t> rect = allocateImage(*entry.spriteImage); + const uint16_t pixelWidth = std::ceil(entry.spriteImage->image.size.width / pixelRatio); + const uint16_t pixelHeight = std::ceil(entry.spriteImage->image.size.height / pixelRatio); + + // Increase to next number divisible by 4, but at least 1. + // This is so we can scale down the texture coordinates and pack them + // into 2 bytes rather than 4 bytes. + const uint16_t packWidth = (pixelWidth + 1) + (4 - (pixelWidth + 1) % 4); + const uint16_t packHeight = (pixelHeight + 1) + (4 - (pixelHeight + 1) % 4); + + // We have to allocate a new area in the bin, and store an empty image in it. + Rect<uint16_t> rect = bin.allocate(packWidth, packHeight); if (rect.w == 0) { if (debug::spriteWarnings) { Log::Warning(Event::Sprite, "sprite atlas bitmap overflow"); diff --git a/src/mbgl/sprite/sprite_atlas.hpp b/src/mbgl/sprite/sprite_atlas.hpp index a17f35267b..d839109a24 100644 --- a/src/mbgl/sprite/sprite_atlas.hpp +++ b/src/mbgl/sprite/sprite_atlas.hpp @@ -101,7 +101,6 @@ private: void _setSprite(const std::string&, const std::shared_ptr<const SpriteImage>& = nullptr); void emitSpriteLoadedIfComplete(); - Rect<uint16_t> allocateImage(const SpriteImage&); void copy(const PremultipliedImage&, Rect<uint16_t>, SpritePatternMode); const Size size; |