From 1c4266c0200dac2939faa8baa35422609d6c0881 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 17 Aug 2018 16:25:27 -0700 Subject: Revert "[core] Evict unused font stacks from GlyphManager" This reverts commit 8ca419fb2ebbba427f2f27ba3d794fb3d6cc5797. --- include/mbgl/util/font_stack.hpp | 7 ----- src/mbgl/renderer/renderer_impl.cpp | 4 --- src/mbgl/style/parser.cpp | 28 +++++++++++++++--- src/mbgl/text/glyph_manager.cpp | 7 ----- src/mbgl/text/glyph_manager.hpp | 3 -- src/mbgl/util/font_stack.cpp | 40 -------------------------- test/fixtures/style_parser/text-font.info.json | 16 +++++------ 7 files changed, 32 insertions(+), 73 deletions(-) diff --git a/include/mbgl/util/font_stack.hpp b/include/mbgl/util/font_stack.hpp index ace60a4ba6..d0b431e9ea 100644 --- a/include/mbgl/util/font_stack.hpp +++ b/include/mbgl/util/font_stack.hpp @@ -1,11 +1,7 @@ #pragma once -#include -#include - #include #include -#include namespace mbgl { @@ -18,7 +14,4 @@ struct FontStackHash { std::size_t operator()(const FontStack&) const; }; -// Statically evaluate layer properties to determine what font stacks are used. -std::set fontStacks(const std::vector>&); - } // namespace mbgl diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp index d3f72b89b9..fea27403c9 100644 --- a/src/mbgl/renderer/renderer_impl.cpp +++ b/src/mbgl/renderer/renderer_impl.cpp @@ -173,10 +173,6 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) { renderLayers.at(entry.first)->setImpl(entry.second.after); } - if (!layerDiff.removed.empty() || !layerDiff.added.empty() || !layerDiff.changed.empty()) { - glyphManager->evict(fontStacks(*updateParameters.layers)); - } - // Update layers for class and zoom changes. for (const auto& entry : renderLayers) { RenderLayer& layer = *entry.second; diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp index 0a90919f0b..8d14d7972c 100644 --- a/src/mbgl/style/parser.cpp +++ b/src/mbgl/style/parser.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -273,12 +274,31 @@ void Parser::parseLayer(const std::string& id, const JSValue& value, std::unique } std::vector Parser::fontStacks() const { - std::vector> impls; - impls.reserve(layers.size()); + std::set result; + for (const auto& layer : layers) { - impls.emplace_back(layer->baseImpl); + if (layer->is() && !layer->as()->getTextField().isUndefined()) { + layer->as()->getTextFont().match( + [&] (Undefined) { + result.insert({"Open Sans Regular", "Arial Unicode MS Regular"}); + }, + [&] (const FontStack& constant) { + result.insert(constant); + }, + [&] (const auto& function) { + for (const auto& value : function.possibleOutputs()) { + if (value) { + result.insert(*value); + } else { + Log::Warning(Event::ParseStyle, "Layer '%s' has an invalid value for text-font and will not work offline. Output values must be contained as literals within the expression.", layer->getID().c_str()); + break; + } + } + } + ); + } } - std::set result = mbgl::fontStacks(impls); + return std::vector(result.begin(), result.end()); } diff --git a/src/mbgl/text/glyph_manager.cpp b/src/mbgl/text/glyph_manager.cpp index 8e7cfe5ba7..3130418908 100644 --- a/src/mbgl/text/glyph_manager.cpp +++ b/src/mbgl/text/glyph_manager.cpp @@ -5,7 +5,6 @@ #include #include #include -#include namespace mbgl { @@ -154,10 +153,4 @@ void GlyphManager::removeRequestor(GlyphRequestor& requestor) { } } -void GlyphManager::evict(const std::set& keep) { - util::erase_if(entries, [&] (const auto& entry) { - return keep.count(entry.first) == 0; - }); -} - } // namespace mbgl diff --git a/src/mbgl/text/glyph_manager.hpp b/src/mbgl/text/glyph_manager.hpp index 642471bbf2..84db2c4be5 100644 --- a/src/mbgl/text/glyph_manager.hpp +++ b/src/mbgl/text/glyph_manager.hpp @@ -42,9 +42,6 @@ public: void setObserver(GlyphManagerObserver*); - // Remove glyphs for all but the supplied font stacks. - void evict(const std::set&); - private: Glyph generateLocalSDF(const FontStack& fontStack, GlyphID glyphID); diff --git a/src/mbgl/util/font_stack.cpp b/src/mbgl/util/font_stack.cpp index 177d5e6f31..fb3b1b60a2 100644 --- a/src/mbgl/util/font_stack.cpp +++ b/src/mbgl/util/font_stack.cpp @@ -1,14 +1,10 @@ #include -#include -#include #include #include namespace mbgl { -using namespace style; - std::string fontStackToString(const FontStack& fontStack) { return boost::algorithm::join(fontStack, ","); } @@ -17,40 +13,4 @@ std::size_t FontStackHash::operator()(const FontStack& fontStack) const { return boost::hash_range(fontStack.begin(), fontStack.end()); } -std::set fontStacks(const std::vector>& layers) { - std::set result; - - for (const auto& layer : layers) { - if (layer->type != LayerType::Symbol) { - continue; - } - - const SymbolLayer::Impl& impl = dynamic_cast(*layer); - if (impl.layout.get().isUndefined()) { - continue; - } - - impl.layout.get().match( - [&] (Undefined) { - result.insert({"Open Sans Regular", "Arial Unicode MS Regular"}); - }, - [&] (const FontStack& constant) { - result.insert(constant); - }, - [&] (const auto& function) { - for (const auto& value : function.possibleOutputs()) { - if (value) { - result.insert(*value); - } else { - Log::Warning(Event::ParseStyle, "Layer '%s' has an invalid value for text-font and will not render text. Output values must be contained as literals within the expression.", impl.id.c_str()); - break; - } - } - } - ); - } - - return result; -} - } // namespace mbgl diff --git a/test/fixtures/style_parser/text-font.info.json b/test/fixtures/style_parser/text-font.info.json index dba9c707df..0fb9658269 100644 --- a/test/fixtures/style_parser/text-font.info.json +++ b/test/fixtures/style_parser/text-font.info.json @@ -1,14 +1,14 @@ { "default": { "log": [ - [1, "WARNING", "ParseStyle", "Layer 'invalid expression - get' has an invalid value for text-font and will not render text. Output values must be contained as literals within the expression."], - [1, "WARNING", "ParseStyle", "Layer 'invalid expression - case' has an invalid value for text-font and will not render text. Output values must be contained as literals within the expression."], - [1, "WARNING", "ParseStyle", "Layer 'invalid expression - match' has an invalid value for text-font and will not render text. Output values must be contained as literals within the expression."], - [1, "WARNING", "ParseStyle", "Layer 'invalid expression - at' has an invalid value for text-font and will not render text. Output values must be contained as literals within the expression."], - [1, "WARNING", "ParseStyle", "Layer 'invalid expression - coalesce' has an invalid value for text-font and will not render text. Output values must be contained as literals within the expression."], - [1, "WARNING", "ParseStyle", "Layer 'invalid expression - step' has an invalid value for text-font and will not render text. Output values must be contained as literals within the expression."], - [1, "WARNING", "ParseStyle", "Layer 'invalid expression - let/var' has an invalid value for text-font and will not render text. Output values must be contained as literals within the expression."], - [1, "WARNING", "ParseStyle", "Layer 'invalid expression - identity function' has an invalid value for text-font and will not render text. Output values must be contained as literals within the expression."] + [1, "WARNING", "ParseStyle", "Layer 'invalid expression - get' has an invalid value for text-font and will not work offline. Output values must be contained as literals within the expression."], + [1, "WARNING", "ParseStyle", "Layer 'invalid expression - case' has an invalid value for text-font and will not work offline. Output values must be contained as literals within the expression."], + [1, "WARNING", "ParseStyle", "Layer 'invalid expression - match' has an invalid value for text-font and will not work offline. Output values must be contained as literals within the expression."], + [1, "WARNING", "ParseStyle", "Layer 'invalid expression - at' has an invalid value for text-font and will not work offline. Output values must be contained as literals within the expression."], + [1, "WARNING", "ParseStyle", "Layer 'invalid expression - coalesce' has an invalid value for text-font and will not work offline. Output values must be contained as literals within the expression."], + [1, "WARNING", "ParseStyle", "Layer 'invalid expression - step' has an invalid value for text-font and will not work offline. Output values must be contained as literals within the expression."], + [1, "WARNING", "ParseStyle", "Layer 'invalid expression - let/var' has an invalid value for text-font and will not work offline. Output values must be contained as literals within the expression."], + [1, "WARNING", "ParseStyle", "Layer 'invalid expression - identity function' has an invalid value for text-font and will not work offline. Output values must be contained as literals within the expression."] ] } } -- cgit v1.2.1