diff options
Diffstat (limited to 'drape')
-rw-r--r-- | drape/symbols_texture.cpp | 34 | ||||
-rw-r--r-- | drape/symbols_texture.hpp | 15 | ||||
-rw-r--r-- | drape/texture_manager.cpp | 49 | ||||
-rw-r--r-- | drape/texture_manager.hpp | 13 |
4 files changed, 80 insertions, 31 deletions
diff --git a/drape/symbols_texture.cpp b/drape/symbols_texture.cpp index 4bdad9334f..d66b2fd1f3 100644 --- a/drape/symbols_texture.cpp +++ b/drape/symbols_texture.cpp @@ -20,8 +20,6 @@ namespace dp namespace { -string const SymbolsTextureName = "symbols"; - using TDefinitionInserter = function<void(string const &, m2::RectF const &)>; using TSymbolsLoadingCompletion = function<void(unsigned char *, uint32_t, uint32_t)>; using TSymbolsLoadingFailure = function<void(string const &)>; @@ -114,8 +112,8 @@ private: m2::RectF m_rect; }; -void LoadSymbols(string const & skinPathName, bool convertToUV, - TDefinitionInserter const & definitionInserter, +void LoadSymbols(std::string const & skinPathName, std::string const & textureName, + bool convertToUV, TDefinitionInserter const & definitionInserter, TSymbolsLoadingCompletion const & completionHandler, TSymbolsLoadingFailure const & failureHandler) { @@ -131,7 +129,7 @@ void LoadSymbols(string const & skinPathName, bool convertToUV, DefinitionLoader loader(definitionInserter, convertToUV); { - ReaderPtr<Reader> reader = GetStyleReader().GetResourceReader(SymbolsTextureName + ".sdf", skinPathName); + ReaderPtr<Reader> reader = GetStyleReader().GetResourceReader(textureName + ".sdf", skinPathName); ReaderSource<ReaderPtr<Reader> > source(reader); if (!ParseXML(source, loader)) { @@ -144,7 +142,7 @@ void LoadSymbols(string const & skinPathName, bool convertToUV, } { - ReaderPtr<Reader> reader = GetStyleReader().GetResourceReader(SymbolsTextureName + ".png", skinPathName); + ReaderPtr<Reader> reader = GetStyleReader().GetResourceReader(textureName + ".png", skinPathName); size_t const size = static_cast<size_t>(reader.Size()); rawData.resize(size); reader.Read(0, &rawData[0], size); @@ -201,16 +199,18 @@ Texture::ResourceType SymbolsTexture::SymbolInfo::GetType() const return Symbol; } -SymbolsTexture::SymbolsTexture(string const & skinPathName, ref_ptr<HWTextureAllocator> allocator) +SymbolsTexture::SymbolsTexture(std::string const & skinPathName, std::string const & textureName, + ref_ptr<HWTextureAllocator> allocator) + : m_name(textureName) { Load(skinPathName, allocator); } -void SymbolsTexture::Load(string const & skinPathName, ref_ptr<HWTextureAllocator> allocator) +void SymbolsTexture::Load(std::string const & skinPathName, ref_ptr<HWTextureAllocator> allocator) { auto definitionInserter = [this](string const & name, m2::RectF const & rect) { - m_definition.insert(make_pair(name, SymbolsTexture::SymbolInfo(rect))); + m_definition.insert(std::make_pair(name, SymbolsTexture::SymbolInfo(rect))); }; auto completionHandler = [this, &allocator](unsigned char * data, uint32_t width, uint32_t height) @@ -230,7 +230,8 @@ void SymbolsTexture::Load(string const & skinPathName, ref_ptr<HWTextureAllocato Fail(); }; - LoadSymbols(skinPathName, true /* convertToUV */, definitionInserter, completionHandler, failureHandler); + LoadSymbols(skinPathName, m_name, true /* convertToUV */, definitionInserter, + completionHandler, failureHandler); } void SymbolsTexture::Invalidate(string const & skinPathName, ref_ptr<HWTextureAllocator> allocator) @@ -267,8 +268,14 @@ void SymbolsTexture::Fail() Create(p, make_ref(&alfaTexture)); } -bool SymbolsTexture::DecodeToMemory(string const & skinPathName, vector<uint8_t> & symbolsSkin, - map<string, m2::RectU> & symbolsIndex, +bool SymbolsTexture::IsSymbolContained(std::string const & symbolName) const +{ + return m_definition.find(symbolName) != m_definition.end(); +} + +bool SymbolsTexture::DecodeToMemory(std::string const & skinPathName, std::string const & textureName, + vector<uint8_t> & symbolsSkin, + std::map<string, m2::RectU> & symbolsIndex, uint32_t & skinWidth, uint32_t & skinHeight) { auto definitionInserter = [&symbolsIndex](string const & name, m2::RectF const & rect) @@ -294,7 +301,8 @@ bool SymbolsTexture::DecodeToMemory(string const & skinPathName, vector<uint8_t> result = false; }; - LoadSymbols(skinPathName, false /* convertToUV */, definitionInserter, completionHandler, failureHandler); + LoadSymbols(skinPathName, textureName, false /* convertToUV */, + definitionInserter, completionHandler, failureHandler); return result; } diff --git a/drape/symbols_texture.hpp b/drape/symbols_texture.hpp index 219f7f4e53..9d022d4d37 100644 --- a/drape/symbols_texture.hpp +++ b/drape/symbols_texture.hpp @@ -30,20 +30,25 @@ public: virtual ResourceType GetType() const; }; - explicit SymbolsTexture(string const & skinPathName, ref_ptr<HWTextureAllocator> allocator); + SymbolsTexture(std::string const & skinPathName, std::string const & textureName, + ref_ptr<HWTextureAllocator> allocator); ref_ptr<ResourceInfo> FindResource(Key const & key, bool & newResource) override; void Invalidate(string const & skinPathName, ref_ptr<HWTextureAllocator> allocator); - static bool DecodeToMemory(string const & skinPathName, vector<uint8_t> & symbolsSkin, - map<string, m2::RectU> & symbolsIndex, + bool IsSymbolContained(std::string const & symbolName) const; + + static bool DecodeToMemory(std::string const & skinPathName, std::string const & textureName, + vector<uint8_t> & symbolsSkin, + std::map<string, m2::RectU> & symbolsIndex, uint32_t & skinWidth, uint32_t & skinHeight); private: void Fail(); - void Load(string const & skinPathName, ref_ptr<HWTextureAllocator> allocator); + void Load(std::string const & skinPathName, ref_ptr<HWTextureAllocator> allocator); - typedef map<string, SymbolInfo> TSymDefinition; + using TSymDefinition = map<std::string, SymbolInfo>; + std::string m_name; mutable TSymDefinition m_definition; }; diff --git a/drape/texture_manager.cpp b/drape/texture_manager.cpp index 531e1215fc..30920845a7 100644 --- a/drape/texture_manager.cpp +++ b/drape/texture_manager.cpp @@ -37,6 +37,10 @@ size_t const kReservedColors = 20; float const kGlyphAreaMultiplier = 1.2f; float const kGlyphAreaCoverage = 0.9f; +std::string const kDefaultSymbolsTexture = "symbols"; +std::string const kSymbolTextures[] = { kDefaultSymbolsTexture, "symbols-ad" }; +uint32_t const kDefaultSymbolsIndex = 0; + namespace { @@ -145,7 +149,9 @@ void TextureManager::BaseRegion::SetTexture(ref_ptr<Texture> texture) m2::PointF TextureManager::BaseRegion::GetPixelSize() const { - ASSERT(IsValid(), ()); + if (!IsValid()) + return m2::PointF(0.0f, 0.0f); + m2::RectF const & texRect = m_info->GetTexRect(); return m2::PointF(texRect.SizeX() * m_texture->GetWidth(), texRect.SizeY() * m_texture->GetHeight()); @@ -153,11 +159,20 @@ m2::PointF TextureManager::BaseRegion::GetPixelSize() const float TextureManager::BaseRegion::GetPixelHeight() const { + if (!IsValid()) + return 0.0f; + return m_info->GetTexRect().SizeY() * m_texture->GetHeight(); } m2::RectF const & TextureManager::BaseRegion::GetTexRect() const { + if (!IsValid()) + { + static m2::RectF nilRect(0.0f, 0.0f, 0.0f, 0.0f); + return nilRect; + } + return m_info->GetTexRect(); } @@ -207,7 +222,7 @@ void TextureManager::Release() m_glyphGroups.clear(); m_hybridGlyphGroups.clear(); - m_symbolTexture.reset(); + m_symbolTextures.clear(); m_stipplePenTexture.reset(); m_colorTexture.reset(); @@ -380,7 +395,11 @@ void TextureManager::Init(Params const & params) GLFunctions::glPixelStore(gl_const::GLUnpackAlignment, 1); - m_symbolTexture = make_unique_dp<SymbolsTexture>(params.m_resPostfix, make_ref(m_textureAllocator)); + for (size_t i = 0; i < ARRAY_SIZE(kSymbolTextures); ++i) + { + m_symbolTextures.push_back(make_unique_dp<SymbolsTexture>(params.m_resPostfix, kSymbolTextures[i], + make_ref(m_textureAllocator))); + } m_trafficArrowTexture = make_unique_dp<StaticTexture>("traffic-arrow", params.m_resPostfix, make_ref(m_textureAllocator)); @@ -454,9 +473,12 @@ void TextureManager::Init(Params const & params) void TextureManager::Invalidate(string const & resPostfix) { - ASSERT(m_symbolTexture != nullptr, ()); - ref_ptr<SymbolsTexture> symbolsTexture = make_ref(m_symbolTexture); - symbolsTexture->Invalidate(resPostfix, make_ref(m_textureAllocator)); + for (size_t i = 0; i < m_symbolTextures.size(); ++i) + { + ASSERT(m_symbolTextures[i] != nullptr, ()); + ref_ptr<SymbolsTexture> symbolsTexture = make_ref(m_symbolTextures[i]); + symbolsTexture->Invalidate(resPostfix, make_ref(m_textureAllocator)); + } ASSERT(m_trafficArrowTexture != nullptr, ()); ref_ptr<StaticTexture> staticTexture = make_ref(m_trafficArrowTexture); @@ -465,7 +487,17 @@ void TextureManager::Invalidate(string const & resPostfix) void TextureManager::GetSymbolRegion(string const & symbolName, SymbolRegion & region) { - GetRegionBase(make_ref(m_symbolTexture), region, SymbolsTexture::SymbolKey(symbolName)); + for (size_t i = 0; i < m_symbolTextures.size(); ++i) + { + ASSERT(m_symbolTextures[i] != nullptr, ()); + ref_ptr<SymbolsTexture> symbolsTexture = make_ref(m_symbolTextures[i]); + if (symbolsTexture->IsSymbolContained(symbolName)) + { + GetRegionBase(symbolsTexture, region, SymbolsTexture::SymbolKey(symbolName)); + return; + } + } + LOG(LWARNING, ("Detected using of unknown symbol ", symbolName)); } void TextureManager::GetStippleRegion(TStipplePattern const & pen, StippleRegion & region) @@ -515,7 +547,8 @@ bool TextureManager::AreGlyphsReady(strings::UniString const & str, int fixedHei ref_ptr<Texture> TextureManager::GetSymbolsTexture() const { - return make_ref(m_symbolTexture); + ASSERT(!m_symbolTextures.empty(), ()); + return make_ref(m_symbolTextures[kDefaultSymbolsIndex]); } ref_ptr<Texture> TextureManager::GetTrafficArrowTexture() const diff --git a/drape/texture_manager.hpp b/drape/texture_manager.hpp index 60d18f18a7..15e1d684db 100644 --- a/drape/texture_manager.hpp +++ b/drape/texture_manager.hpp @@ -8,12 +8,15 @@ #include "base/string_utils.hpp" -#include "std/atomic.hpp" -#include "std/unordered_set.hpp" +#include <atomic> +#include <list> +#include <vector> namespace dp { +extern std::string const kDefaultSymbolsTexture; + class HWTextureAllocator; class TextureManager @@ -235,10 +238,10 @@ private: static constexpr size_t GetInvalidGlyphGroup(); private: - drape_ptr<Texture> m_symbolTexture; + std::vector<drape_ptr<Texture>> m_symbolTextures; drape_ptr<Texture> m_stipplePenTexture; drape_ptr<Texture> m_colorTexture; - list<drape_ptr<Texture>> m_glyphTextures; + std::list<drape_ptr<Texture>> m_glyphTextures; drape_ptr<Texture> m_trafficArrowTexture; @@ -248,7 +251,7 @@ private: buffer_vector<GlyphGroup, 64> m_glyphGroups; buffer_vector<HybridGlyphGroup, 4> m_hybridGlyphGroups; - atomic_flag m_nothingToUpload; + std::atomic_flag m_nothingToUpload; }; } // namespace dp |