From 58de1e15c5e3f4983f445eacefb2fcc931371788 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 13 Feb 2017 15:53:51 -0800 Subject: [PATCH] [core] Inline SpriteAtlas::allocateImage --- src/mbgl/sprite/sprite_atlas.cpp | 33 +++++++++++--------------------- 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 606ad4f9b..1ca40f6c2 100644 --- a/src/mbgl/sprite/sprite_atlas.cpp +++ b/src/mbgl/sprite/sprite_atlas.cpp @@ -174,27 +174,6 @@ std::shared_ptr SpriteAtlas::getSprite(const std::string& nam } } -Rect 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 rect = bin.allocate(pack_width, pack_height); - if (rect.w == 0) { - return rect; - } - - return rect; -} - optional SpriteAtlas::getImage(const std::string& name, const SpritePatternMode mode) { std::lock_guard lock(mutex); @@ -225,7 +204,17 @@ optional SpriteAtlas::getImage(const std::string& name, }; } - Rect 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 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 a17f35267..d839109a2 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& = nullptr); void emitSpriteLoadedIfComplete(); - Rect allocateImage(const SpriteImage&); void copy(const PremultipliedImage&, Rect, SpritePatternMode); const Size size;