#include #include #include #include namespace mbgl { GlyphStore::GlyphStore(FileSource& fileSource_) : fileSource(fileSource_) { } GlyphStore::~GlyphStore() = default; void GlyphStore::requestGlyphRange(const std::string& fontStackName, const GlyphRange& range) { assert(util::ThreadContext::currentlyOn(util::ThreadType::Map)); std::lock_guard lock(rangesMutex); auto& rangeSets = ranges[fontStackName]; const auto& rangeSetsIt = rangeSets.find(range); if (rangeSetsIt != rangeSets.end()) { return; } rangeSets.emplace(range, std::make_unique(this, fontStackName, range, observer, fileSource)); } bool GlyphStore::hasGlyphRanges(const std::string& fontStackName, const std::set& glyphRanges) { if (glyphRanges.empty()) { return true; } std::lock_guard lock(rangesMutex); const auto& rangeSets = ranges[fontStackName]; bool hasRanges = true; for (const auto& range : glyphRanges) { const auto& rangeSetsIt = rangeSets.find(range); if (rangeSetsIt == rangeSets.end()) { // Push the request to the MapThread, so we can easly cancel // if it is still pending when we destroy this object. workQueue.push(std::bind(&GlyphStore::requestGlyphRange, this, fontStackName, range)); hasRanges = false; continue; } if (!rangeSetsIt->second->isParsed()) { hasRanges = false; } } return hasRanges; } util::exclusive GlyphStore::getFontStack(const std::string& fontStack) { auto lock = std::make_unique>(stacksMutex); auto it = stacks.find(fontStack); if (it == stacks.end()) { it = stacks.emplace(fontStack, std::make_unique()).first; } // FIXME: We lock all FontStacks, but what we should // really do is lock only the one we are returning. return { it->second.get(), std::move(lock) }; } void GlyphStore::setObserver(Observer* observer_) { observer = observer_; } } // namespace mbgl