diff options
author | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2015-07-08 15:50:43 +0300 |
---|---|---|
committer | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2015-11-30 16:09:31 +0300 |
commit | 99d172530c1077924bbeb002afbf4a34d26c9243 (patch) | |
tree | 83deefbd7053040b80936c5011256f57cef4fcc6 | |
parent | 7b95adff42ca55aaac61d6f00bad8ffb233da975 (diff) |
Added symbols reloading on changing map style
-rw-r--r-- | drape/symbols_texture.cpp | 8 | ||||
-rw-r--r-- | drape/symbols_texture.hpp | 2 | ||||
-rw-r--r-- | drape/texture.cpp | 20 | ||||
-rw-r--r-- | drape/texture.hpp | 4 | ||||
-rw-r--r-- | drape/texture_manager.cpp | 14 | ||||
-rw-r--r-- | drape/texture_manager.hpp | 6 | ||||
-rw-r--r-- | drape_frontend/backend_renderer.cpp | 11 | ||||
-rw-r--r-- | drape_frontend/backend_renderer.hpp | 5 | ||||
-rw-r--r-- | drape_frontend/drape_engine.cpp | 9 | ||||
-rw-r--r-- | drape_frontend/drape_engine.hpp | 9 | ||||
-rwxr-xr-x | drape_frontend/frontend_renderer.cpp | 36 | ||||
-rw-r--r-- | drape_frontend/message.hpp | 4 | ||||
-rw-r--r-- | drape_frontend/message_subclasses.hpp | 30 | ||||
-rw-r--r-- | drape_head/testing_engine.cpp | 2 | ||||
-rw-r--r-- | indexer/map_style_reader.cpp | 5 | ||||
-rw-r--r-- | indexer/map_style_reader.hpp | 2 | ||||
-rw-r--r-- | map/framework.cpp | 13 |
17 files changed, 157 insertions, 23 deletions
diff --git a/drape/symbols_texture.cpp b/drape/symbols_texture.cpp index 9e7761ad37..9a01c33c71 100644 --- a/drape/symbols_texture.cpp +++ b/drape/symbols_texture.cpp @@ -166,6 +166,14 @@ void SymbolsTexture::Load(string const & skinPathName) stbi_image_free(data); } +void SymbolsTexture::Invalidate(string const & skinPathName) +{ + Destroy(); + m_definition.clear(); + + Load(skinPathName); +} + ref_ptr<Texture::ResourceInfo> SymbolsTexture::FindResource(Texture::Key const & key, bool & newResource) { newResource = false; diff --git a/drape/symbols_texture.hpp b/drape/symbols_texture.hpp index c165faf453..27e88f63ef 100644 --- a/drape/symbols_texture.hpp +++ b/drape/symbols_texture.hpp @@ -33,6 +33,8 @@ public: ref_ptr<ResourceInfo> FindResource(Key const & key, bool & newResource); + void Invalidate(string const & skinPathName); + private: void Fail(); void Load(string const & skinPathName); diff --git a/drape/texture.cpp b/drape/texture.cpp index db646439a3..f02870edd2 100644 --- a/drape/texture.cpp +++ b/drape/texture.cpp @@ -31,13 +31,7 @@ Texture::Texture() Texture::~Texture() { - if (m_textureID != -1) - { - GLFunctions::glDeleteTexture(m_textureID); -#if defined(TRACK_GPU_MEM) - dp::GPUMemTracker::Inst().RemoveDeallocated("Texture", m_textureID); -#endif - } + Destroy(); } void Texture::Create(uint32_t width, uint32_t height, TextureFormat format) @@ -86,6 +80,18 @@ void Texture::Create(uint32_t width, uint32_t height, TextureFormat format, ref_ #endif } +void Texture::Destroy() +{ + if (m_textureID != -1) + { + GLFunctions::glDeleteTexture(m_textureID); + m_textureID = -1; +#if defined(TRACK_GPU_MEM) + dp::GPUMemTracker::Inst().RemoveDeallocated("Texture", m_textureID); +#endif + } +} + void Texture::SetFilterParams(glConst minFilter, glConst magFilter) { ASSERT_ID; diff --git a/drape/texture.hpp b/drape/texture.hpp index 405c5373c6..705bfcc96e 100644 --- a/drape/texture.hpp +++ b/drape/texture.hpp @@ -49,6 +49,7 @@ public: void Create(uint32_t width, uint32_t height, TextureFormat format); void Create(uint32_t width, uint32_t height, TextureFormat format, ref_ptr<void> data); + void SetFilterParams(glConst minFilter, glConst magFilter); void SetWrapMode(glConst sMode, glConst tMode); @@ -69,6 +70,9 @@ public: static uint32_t GetMaxTextureSize(); +protected: + void Destroy(); + private: void UnpackFormat(TextureFormat format, glConst & layout, glConst & pixelType); int32_t GetID() const; diff --git a/drape/texture_manager.cpp b/drape/texture_manager.cpp index 36c8d286d6..3908221999 100644 --- a/drape/texture_manager.cpp +++ b/drape/texture_manager.cpp @@ -287,8 +287,8 @@ size_t TextureManager::FindHybridGlyphsGroup(TMultilineText const & text) void TextureManager::Init(Params const & params) { GLFunctions::glPixelStore(gl_const::GLUnpackAlignment, 1); - m_symbolTexture = make_unique_dp<SymbolsTexture>(my::JoinFoldersToPath(string("resources-") + params.m_resPrefix, "symbols")); + m_symbolTexture = make_unique_dp<SymbolsTexture>(GetSymbolsTexturePath(params.m_resPostfix)); m_stipplePenTexture = make_unique_dp<StipplePenTexture>(m2::PointU(STIPPLE_TEXTURE_SIZE, STIPPLE_TEXTURE_SIZE)); m_colorTexture = make_unique_dp<ColorTexture>(m2::PointU(COLOR_TEXTURE_SIZE, COLOR_TEXTURE_SIZE)); @@ -319,6 +319,13 @@ void TextureManager::Init(Params const & params) }); } +void TextureManager::Invalidate(string const & postfix) +{ + ASSERT(m_symbolTexture != nullptr, ()); + ref_ptr<SymbolsTexture> symbolsTexture = make_ref(m_symbolTexture); + symbolsTexture->Invalidate(GetSymbolsTexturePath(postfix)); +} + void TextureManager::GetSymbolRegion(string const & symbolName, SymbolRegion & region) { GetRegionBase(make_ref(m_symbolTexture), region, SymbolsTexture::SymbolKey(symbolName)); @@ -349,4 +356,9 @@ constexpr size_t TextureManager::GetInvalidGlyphGroup() return INVALID_GLYPH_GROUP; } +string TextureManager::GetSymbolsTexturePath(string const & postfix) const +{ + return my::JoinFoldersToPath(string("resources-") + postfix, "symbols"); +} + } // namespace dp diff --git a/drape/texture_manager.hpp b/drape/texture_manager.hpp index e3ccaf4a68..e0feac940d 100644 --- a/drape/texture_manager.hpp +++ b/drape/texture_manager.hpp @@ -65,7 +65,7 @@ public: struct Params { - string m_resPrefix; + string m_resPostfix; GlyphManager::Params m_glyphMngParams; }; @@ -73,6 +73,8 @@ public: void Release(); void Init(Params const & params); + void Invalidate(string const & postfix); + void GetSymbolRegion(string const & symbolName, SymbolRegion & region); typedef buffer_vector<uint8_t, 8> TStipplePattern; @@ -209,6 +211,8 @@ private: static constexpr size_t GetInvalidGlyphGroup(); private: + string GetSymbolsTexturePath(string const & postfix) const; + drape_ptr<Texture> m_symbolTexture; drape_ptr<Texture> m_stipplePenTexture; drape_ptr<Texture> m_colorTexture; diff --git a/drape_frontend/backend_renderer.cpp b/drape_frontend/backend_renderer.cpp index 2a549ed95b..ee38ec4f5e 100644 --- a/drape_frontend/backend_renderer.cpp +++ b/drape_frontend/backend_renderer.cpp @@ -26,6 +26,7 @@ BackendRenderer::BackendRenderer(Params const & params) : BaseRenderer(ThreadsCommutator::ResourceUploadThread, params) , m_model(params.m_model) , m_readManager(make_unique_dp<ReadManager>(params.m_commutator, m_model)) + , m_resourcesSuffix(params.m_resourcesSuffix) { gui::DrapeGui::Instance().SetRecacheCountryStatusSlot([this]() { @@ -202,6 +203,14 @@ void BackendRenderer::AcceptMessage(ref_ptr<Message> message) MessagePriority::Normal); break; } + case Message::InvalidateTextures: + { + ref_ptr<InvalidateTexturesMessage> msg = message; + m_resourcesSuffix = msg->GetMapStyleSuffix(); + + m_texMng->Invalidate(VisualParams::Instance().GetResourcePostfix() + m_resourcesSuffix); + break; + } case Message::StopRendering: { ProcessStopRenderingMessage(); @@ -251,7 +260,7 @@ void BackendRenderer::InitGLDependentResource() m_batchersPool = make_unique_dp<BatchersPool>(ReadManager::ReadCount(), bind(&BackendRenderer::FlushGeometry, this, _1)); dp::TextureManager::Params params; - params.m_resPrefix = VisualParams::Instance().GetResourcePostfix(); + params.m_resPostfix = VisualParams::Instance().GetResourcePostfix() + m_resourcesSuffix; params.m_glyphMngParams.m_uniBlocks = "unicode_blocks.txt"; params.m_glyphMngParams.m_whitelist = "fonts_whitelist.txt"; params.m_glyphMngParams.m_blacklist = "fonts_blacklist.txt"; diff --git a/drape_frontend/backend_renderer.hpp b/drape_frontend/backend_renderer.hpp index bc408a5c7e..28d6bd8758 100644 --- a/drape_frontend/backend_renderer.hpp +++ b/drape_frontend/backend_renderer.hpp @@ -30,13 +30,15 @@ public: struct Params : BaseRenderer::Params { Params(ref_ptr<ThreadsCommutator> commutator, ref_ptr<dp::OGLContextFactory> factory, - ref_ptr<dp::TextureManager> texMng, MapDataProvider const & model) + ref_ptr<dp::TextureManager> texMng, MapDataProvider const & model, string const & resourcesSuffix) : BaseRenderer::Params(commutator, factory, texMng) , m_model(model) + , m_resourcesSuffix(resourcesSuffix) { } MapDataProvider const & m_model; + string m_resourcesSuffix; }; BackendRenderer(Params const & params); @@ -56,6 +58,7 @@ private: drape_ptr<ReadManager> m_readManager; drape_ptr<RouteBuilder> m_routeBuilder; gui::LayerCacher m_guiCacher; + string m_resourcesSuffix; ///////////////////////////////////////// // MessageAcceptor // diff --git a/drape_frontend/drape_engine.cpp b/drape_frontend/drape_engine.cpp index 675133c36f..e5fe2c802a 100644 --- a/drape_frontend/drape_engine.cpp +++ b/drape_frontend/drape_engine.cpp @@ -66,7 +66,7 @@ DrapeEngine::DrapeEngine(Params && params) m_frontend = make_unique_dp<FrontendRenderer>(frParams); BackendRenderer::Params brParams(frParams.m_commutator, frParams.m_oglContextFactory, - frParams.m_texMng, params.m_model); + frParams.m_texMng, params.m_model, params.m_resourcesSuffix); m_backend = make_unique_dp<BackendRenderer>(brParams); GuiRecacheMessage::Blocker blocker; @@ -167,6 +167,13 @@ void DrapeEngine::InvalidateRect(m2::RectD const & rect) MessagePriority::High); } +void DrapeEngine::UpdateMapStyle(string const & mapStyleSuffix) +{ + m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread, + make_unique_dp<UpdateMapStyleMessage>(mapStyleSuffix), + MessagePriority::High); +} + void DrapeEngine::AddUserEvent(UserEvent const & e) { m_frontend->AddUserEvent(e); diff --git a/drape_frontend/drape_engine.hpp b/drape_frontend/drape_engine.hpp index 647274728d..eb2514abd1 100644 --- a/drape_frontend/drape_engine.hpp +++ b/drape_frontend/drape_engine.hpp @@ -38,15 +38,16 @@ public: Viewport const & viewport, MapDataProvider const & model, double vs, - gui::TWidgetsInitInfo && info) + gui::TWidgetsInitInfo && info, + string const & resourcesSuffix) : m_factory(factory) , m_stringsBundle(stringBundle) , m_viewport(viewport) , m_model(model) , m_vs(vs) , m_info(move(info)) - { - } + , m_resourcesSuffix(resourcesSuffix) + {} ref_ptr<dp::OGLContextFactory> m_factory; ref_ptr<StringsBundle> m_stringsBundle; @@ -54,6 +55,7 @@ public: MapDataProvider m_model; double m_vs; gui::TWidgetsInitInfo m_info; + string m_resourcesSuffix; }; DrapeEngine(Params && params); @@ -79,6 +81,7 @@ public: void SetRenderingEnabled(bool const isEnabled); void InvalidateRect(m2::RectD const & rect); + void UpdateMapStyle(string const & mapStyleSuffix); void SetCountryInfo(gui::CountryInfo const & info, bool isCurrentCountry, bool isCountryLoaded); void SetCompassInfo(location::CompassInfo const & info); diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index 56d488b848..0aff685606 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -167,8 +167,6 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message) m_commutator->PostMessage(ThreadsCommutator::ResourceUploadThread, make_unique_dp<UpdateReadManagerMessage>(screen, move(tiles)), MessagePriority::Normal); - - RefreshBgColor(); } break; } @@ -318,6 +316,7 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message) m_myPositionController->ActivateRouting(); break; } + case Message::RemoveRoute: { ref_ptr<RemoveRouteMessage> msg = message; @@ -326,6 +325,39 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message) m_myPositionController->DeactivateRouting(); break; } + + case Message::UpdateMapStyle: + { + ref_ptr<UpdateMapStyleMessage> msg = message; + + m_tileTree->Invalidate(); + + TTilesCollection tiles; + ScreenBase screen = m_userEventStream.GetCurrentScreen(); + ResolveTileKeys(screen.ClipRect(), tiles); + + m_renderGroups.clear(); + m_deferredRenderGroups.clear(); + + m_commutator->PostMessage(ThreadsCommutator::ResourceUploadThread, + make_unique_dp<InvalidateReadManagerRectMessage>(tiles), + MessagePriority::Normal); + + BaseBlockingMessage::Blocker blocker; + m_commutator->PostMessage(ThreadsCommutator::ResourceUploadThread, + make_unique_dp<InvalidateTexturesMessage>(blocker, msg->GetMapStyleSuffix()), + MessagePriority::Normal); + blocker.Wait(); + + m_commutator->PostMessage(ThreadsCommutator::ResourceUploadThread, + make_unique_dp<UpdateReadManagerMessage>(screen, move(tiles)), + MessagePriority::Normal); + + RefreshBgColor(); + + break; + } + default: ASSERT(false, ()); } diff --git a/drape_frontend/message.hpp b/drape_frontend/message.hpp index edd5de8c28..67830c57ba 100644 --- a/drape_frontend/message.hpp +++ b/drape_frontend/message.hpp @@ -35,7 +35,9 @@ public: GetMyPosition, AddRoute, RemoveRoute, - FlushRoute + FlushRoute, + UpdateMapStyle, + InvalidateTextures }; virtual ~Message() {} diff --git a/drape_frontend/message_subclasses.hpp b/drape_frontend/message_subclasses.hpp index 946bfc8bac..8ab484dcb0 100644 --- a/drape_frontend/message_subclasses.hpp +++ b/drape_frontend/message_subclasses.hpp @@ -560,5 +560,35 @@ private: drape_ptr<dp::RenderBucket> m_endOfRouteBuffer; }; +class UpdateMapStyleMessage : public Message +{ +public: + UpdateMapStyleMessage(string const & mapStyleSuffix) + : m_mapStyleSuffix(mapStyleSuffix) + {} + + Type GetType() const override { return Message::UpdateMapStyle; } + + string const & GetMapStyleSuffix() const { return m_mapStyleSuffix; } + +private: + string m_mapStyleSuffix; +}; + +class InvalidateTexturesMessage : public BaseBlockingMessage +{ +public: + InvalidateTexturesMessage(Blocker & blocker, string const & mapStyleSuffix) + : BaseBlockingMessage(blocker) + , m_mapStyleSuffix(mapStyleSuffix) + {} + + Type GetType() const override { return Message::InvalidateTextures; } + + string const & GetMapStyleSuffix() const { return m_mapStyleSuffix; } + +private: + string m_mapStyleSuffix; +}; } // namespace df diff --git a/drape_head/testing_engine.cpp b/drape_head/testing_engine.cpp index 68159b1842..dcb0fa00f4 100644 --- a/drape_head/testing_engine.cpp +++ b/drape_head/testing_engine.cpp @@ -334,7 +334,7 @@ TestingEngine::TestingEngine(Viewport const & viewport, double vs) GLFunctions::Init(); dp::TextureManager::Params params; - params.m_resPrefix = VisualParams::Instance().GetResourcePostfix(); + params.m_resPostfix = VisualParams::Instance().GetResourcePostfix(); params.m_glyphMngParams.m_uniBlocks = "unicode_blocks.txt"; params.m_glyphMngParams.m_whitelist = "fonts_whitelist.txt"; params.m_glyphMngParams.m_blacklist = "fonts_blacklist.txt"; diff --git a/indexer/map_style_reader.cpp b/indexer/map_style_reader.cpp index 0d3fc7fe13..299a631315 100644 --- a/indexer/map_style_reader.cpp +++ b/indexer/map_style_reader.cpp @@ -50,6 +50,11 @@ MapStyle StyleReader::GetCurrentStyle() return m_mapStyle; } +string StyleReader::GetCurrentStyleSuffix() +{ + return GetStyleSuffix(GetCurrentStyle()); +} + ReaderPtr<Reader> StyleReader::GetDrawingRulesReader() { string const rulesFile = string("drules_proto") + GetStyleSuffix(GetCurrentStyle()) + ".bin"; diff --git a/indexer/map_style_reader.hpp b/indexer/map_style_reader.hpp index 63ff46a47a..d866e21c49 100644 --- a/indexer/map_style_reader.hpp +++ b/indexer/map_style_reader.hpp @@ -12,6 +12,8 @@ public: void SetCurrentStyle(MapStyle mapStyle); MapStyle GetCurrentStyle(); + string GetCurrentStyleSuffix(); + ReaderPtr<Reader> GetDrawingRulesReader(); ReaderPtr<Reader> GetResourceReader(string const & file, string const & density); diff --git a/map/framework.cpp b/map/framework.cpp index 16ef7984af..e8a7df5adc 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -812,8 +812,12 @@ void Framework::UpdateUserViewportChanged() void Framework::UpdateSearchResults(search::Results const & results) { - FillSearchResultsMarks(results); - Invalidate(); + if (!results.IsEndMarker() && results.GetCount() > 0) + { + // Got here from search thread. Need to switch into GUI thread to modify search mark container. + // Do copy the results structure to pass into GUI thread. + GetPlatform().RunOnGuiThread(bind(&Framework::OnSearchResultsCallbackUI, this, results)); + } } void Framework::OnSearchResultsCallbackUI(search::Results const & results) @@ -1254,7 +1258,8 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::OGLContextFactory> contextFactory, df::MapDataProvider(idReadFn, featureReadFn, updateCountryIndex, isCountryLoadedFn, downloadMapFn, downloadMapRoutingFn, downloadRetryFn), params.m_visualScale, - move(params.m_widgetsInitInfo)); + move(params.m_widgetsInitInfo), + GetStyleReader().GetCurrentStyleSuffix()); m_drapeEngine = make_unique_dp<df::DrapeEngine>(move(p)); AddViewportListener([this](ScreenBase const & screen) @@ -1284,7 +1289,7 @@ void Framework::SetMapStyle(MapStyle mapStyle) classificator::Load(); drule::LoadRules(); - InvalidateRect(m_currentMovelView.ClipRect()); + CallDrapeFunction(bind(&df::DrapeEngine::UpdateMapStyle, _1, GetStyleReader().GetCurrentStyleSuffix())); alohalytics::TStringMap details {{"mapStyle", strings::to_string(static_cast<int>(mapStyle))}}; alohalytics::Stats::Instance().LogEvent("MapStyle_Changed", details); |