summaryrefslogtreecommitdiff
path: root/src/mbgl/text/glyph_atlas.cpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-02-23 12:42:48 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-02-27 16:19:35 -0800
commite3500c1f791be82d64b50c7fa80b29b4e3c8a031 (patch)
treecba8edaf48b5de2aaf80443a397beaa6ceccc1a7 /src/mbgl/text/glyph_atlas.cpp
parent47dcfe7d441933c8d75c5efca14fb4683cf7099e (diff)
downloadqtlocation-mapboxgl-e3500c1f791be82d64b50c7fa80b29b4e3c8a031.tar.gz
[core] Replace three maps/mutexes in GlyphAtlas with a single map and mutex
Diffstat (limited to 'src/mbgl/text/glyph_atlas.cpp')
-rw-r--r--src/mbgl/text/glyph_atlas.cpp43
1 files changed, 16 insertions, 27 deletions
diff --git a/src/mbgl/text/glyph_atlas.cpp b/src/mbgl/text/glyph_atlas.cpp
index 88b319366d..1b3f7518b5 100644
--- a/src/mbgl/text/glyph_atlas.cpp
+++ b/src/mbgl/text/glyph_atlas.cpp
@@ -23,16 +23,17 @@ GlyphAtlas::GlyphAtlas(const Size size, FileSource& fileSource_)
GlyphAtlas::~GlyphAtlas() = default;
void GlyphAtlas::requestGlyphRange(const FontStack& fontStack, const GlyphRange& range) {
- std::lock_guard<std::mutex> lock(rangesMutex);
- auto& rangeSets = ranges[fontStack];
+ std::lock_guard<std::mutex> lock(mutex);
+ auto& rangeSets = entries[fontStack].ranges;
const auto& rangeSetsIt = rangeSets.find(range);
if (rangeSetsIt != rangeSets.end()) {
return;
}
- rangeSets.emplace(range,
- std::make_unique<GlyphPBF>(this, fontStack, range, observer, fileSource));
+ rangeSets.emplace(std::piecewise_construct,
+ std::forward_as_tuple(range),
+ std::forward_as_tuple(this, fontStack, range, observer, fileSource));
}
bool GlyphAtlas::hasGlyphRanges(const FontStack& fontStack, const GlyphRangeSet& glyphRanges) {
@@ -40,8 +41,8 @@ bool GlyphAtlas::hasGlyphRanges(const FontStack& fontStack, const GlyphRangeSet&
return true;
}
- std::lock_guard<std::mutex> lock(rangesMutex);
- const auto& rangeSets = ranges[fontStack];
+ std::lock_guard<std::mutex> lock(mutex);
+ const auto& rangeSets = entries[fontStack].ranges;
bool hasRanges = true;
for (const auto& range : glyphRanges) {
@@ -55,7 +56,7 @@ bool GlyphAtlas::hasGlyphRanges(const FontStack& fontStack, const GlyphRangeSet&
continue;
}
- if (!rangeSetsIt->second->isParsed()) {
+ if (!rangeSetsIt->second.isParsed()) {
hasRanges = false;
}
}
@@ -64,16 +65,8 @@ bool GlyphAtlas::hasGlyphRanges(const FontStack& fontStack, const GlyphRangeSet&
}
util::exclusive<GlyphSet> GlyphAtlas::getGlyphSet(const FontStack& fontStack) {
- auto lock = std::make_unique<std::lock_guard<std::mutex>>(glyphSetsMutex);
-
- auto it = glyphSets.find(fontStack);
- if (it == glyphSets.end()) {
- it = glyphSets.emplace(fontStack, std::make_unique<GlyphSet>()).first;
- }
-
- // FIXME: We lock all GlyphSets, but what we should
- // really do is lock only the one we are returning.
- return { it->second.get(), std::move(lock) };
+ auto lock = std::make_unique<std::lock_guard<std::mutex>>(mutex);
+ return { &entries[fontStack].glyphSet, std::move(lock) };
}
void GlyphAtlas::setObserver(GlyphAtlasObserver* observer_) {
@@ -83,12 +76,10 @@ void GlyphAtlas::setObserver(GlyphAtlasObserver* observer_) {
void GlyphAtlas::addGlyphs(uintptr_t tileUID,
const std::u16string& text,
const FontStack& fontStack,
- const GlyphSet& glyphSet,
+ const util::exclusive<GlyphSet>& glyphSet,
GlyphPositions& face)
{
- std::lock_guard<std::mutex> lock(mtx);
-
- const std::map<uint32_t, SDFGlyph>& sdfs = glyphSet.getSDFs();
+ const std::map<uint32_t, SDFGlyph>& sdfs = glyphSet->getSDFs();
for (char16_t chr : text)
{
@@ -107,7 +98,7 @@ Rect<uint16_t> GlyphAtlas::addGlyph(uintptr_t tileUID,
const FontStack& fontStack,
const SDFGlyph& glyph)
{
- std::map<uint32_t, GlyphValue>& face = index[fontStack];
+ std::map<uint32_t, GlyphValue>& face = entries[fontStack].glyphValues;
auto it = face.find(glyph.id);
// The glyph is already in this texture.
@@ -151,10 +142,10 @@ Rect<uint16_t> GlyphAtlas::addGlyph(uintptr_t tileUID,
}
void GlyphAtlas::removeGlyphs(uintptr_t tileUID) {
- std::lock_guard<std::mutex> lock(mtx);
+ std::lock_guard<std::mutex> lock(mutex);
- for (auto& faces : index) {
- std::map<uint32_t, GlyphValue>& face = faces.second;
+ for (auto& entry : entries) {
+ std::map<uint32_t, GlyphValue>& face = entry.second.glyphValues;
for (auto it = face.begin(); it != face.end(); /* we advance in the body */) {
GlyphValue& value = it->second;
value.ids.erase(tileUID);
@@ -190,8 +181,6 @@ Size GlyphAtlas::getSize() const {
}
void GlyphAtlas::upload(gl::Context& context, gl::TextureUnit unit) {
- std::lock_guard<std::mutex> lock(mtx);
-
if (!texture) {
texture = context.createTexture(image, unit);
} else if (dirty) {