From 762e4bdfbede24ed2acf5f3547d32a0317165495 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 12 Mar 2015 17:02:39 -0700 Subject: Clean up GlyphAtlas --- src/mbgl/geometry/glyph_atlas.cpp | 48 +++++++++++++++++++-------------------- src/mbgl/geometry/glyph_atlas.hpp | 32 +++++++++++++------------- 2 files changed, 40 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/mbgl/geometry/glyph_atlas.cpp b/src/mbgl/geometry/glyph_atlas.cpp index 67e6303200..6fcb4ecf87 100644 --- a/src/mbgl/geometry/glyph_atlas.cpp +++ b/src/mbgl/geometry/glyph_atlas.cpp @@ -18,26 +18,43 @@ GlyphAtlas::GlyphAtlas(uint16_t width_, uint16_t height_) dirty(true) { } -Rect GlyphAtlas::addGlyph(uint64_t tile_id, const std::string& face_name, - const SDFGlyph& glyph) +void GlyphAtlas::addGlyphs(uint64_t tileID, + const std::u32string& text, + const std::string& stackName, + const FontStack& fontStack, + GlyphPositions& face) { std::lock_guard lock(mtx); - return addGlyph_impl(tile_id, face_name, glyph); + + const std::map& sdfs = fontStack.getSDFs(); + + for (uint32_t chr : text) + { + auto sdf_it = sdfs.find(chr); + if (sdf_it == sdfs.end()) { + continue; + } + + const SDFGlyph& sdf = sdf_it->second; + Rect rect = addGlyph(tileID, stackName, sdf); + face.emplace(chr, Glyph{rect, sdf.metrics}); + } } -Rect GlyphAtlas::addGlyph_impl(uint64_t tile_id, const std::string& face_name, +Rect GlyphAtlas::addGlyph(uint64_t tileID, + const std::string& stackName, const SDFGlyph& glyph) { // Use constant value for now. const uint8_t buffer = 3; - std::map& face = index[face_name]; + std::map& face = index[stackName]; std::map::iterator it = face.find(glyph.id); // The glyph is already in this texture. if (it != face.end()) { GlyphValue& value = it->second; - value.ids.insert(tile_id); + value.ids.insert(tileID); return value.rect; } @@ -68,7 +85,7 @@ Rect GlyphAtlas::addGlyph_impl(uint64_t tile_id, const std::string& fa assert(rect.x + rect.w <= width); assert(rect.y + rect.h <= height); - face.emplace(glyph.id, GlyphValue { rect, tile_id }); + face.emplace(glyph.id, GlyphValue { rect, tileID }); // Copy the bitmap char *target = data.get(); @@ -86,23 +103,6 @@ Rect GlyphAtlas::addGlyph_impl(uint64_t tile_id, const std::string& fa return rect; } -void GlyphAtlas::addGlyphs(uint64_t tileid, std::u32string const& text, std::string const& stackname, FontStack const& fontStack, GlyphPositions & face) -{ - std::lock_guard lock(mtx); - - std::map const& sdfs = fontStack.getSDFs(); - for (uint32_t chr : text) - { - auto sdf_it = sdfs.find(chr); - if (sdf_it != sdfs.end()) - { - SDFGlyph const& sdf = sdf_it->second; - Rect rect = addGlyph_impl(tileid, stackname, sdf); - face.emplace(chr, Glyph{rect, sdf.metrics}); - } - } -} - void GlyphAtlas::removeGlyphs(uint64_t tile_id) { std::lock_guard lock(mtx); diff --git a/src/mbgl/geometry/glyph_atlas.hpp b/src/mbgl/geometry/glyph_atlas.hpp index 7b3c223fe5..19550ea4df 100644 --- a/src/mbgl/geometry/glyph_atlas.hpp +++ b/src/mbgl/geometry/glyph_atlas.hpp @@ -15,6 +15,19 @@ namespace mbgl { class GlyphAtlas : public util::noncopyable { public: + GlyphAtlas(uint16_t width, uint16_t height); + + void addGlyphs(uint64_t tileID, + const std::u32string& text, + const std::string& stackName, + const FontStack&, + GlyphPositions&); + void removeGlyphs(uint64_t tile_id); + + void bind(); + + const uint16_t width = 0; + const uint16_t height = 0; private: struct GlyphValue { @@ -24,23 +37,10 @@ private: std::set ids; }; - Rect addGlyph_impl(uint64_t tile_id, const std::string& face_name, - const SDFGlyph& glyph); -public: - GlyphAtlas(uint16_t width, uint16_t height); - - Rect addGlyph(uint64_t tile_id, const std::string& face_name, - const SDFGlyph& glyph); - void addGlyphs(uint64_t tileid, std::u32string const& text, std::string const& stackname, - FontStack const& fontStack, GlyphPositions & face); - void removeGlyphs(uint64_t tile_id); - void bind(); + Rect addGlyph(uint64_t tileID, + const std::string& stackName, + const SDFGlyph&); -public: - const uint16_t width = 0; - const uint16_t height = 0; - -private: std::mutex mtx; BinPack bin; std::map> index; -- cgit v1.2.1