From 041cd3e8aef8de0bad9cee6b090072775dbe0656 Mon Sep 17 00:00:00 2001 From: Daria Volvenkova Date: Tue, 3 Jul 2018 17:59:07 +0300 Subject: [PATCH] Fixed calculation of transit scheme state. --- drape_frontend/backend_renderer.cpp | 1 - drape_frontend/drape_engine.cpp | 6 +-- drape_frontend/drape_engine.hpp | 3 +- drape_frontend/frontend_renderer.cpp | 8 +-- drape_frontend/frontend_renderer.hpp | 1 + drape_frontend/message_subclasses.hpp | 7 +-- drape_frontend/transit_scheme_builder.cpp | 5 -- drape_frontend/transit_scheme_builder.hpp | 3 -- drape_frontend/transit_scheme_renderer.cpp | 16 ++++-- drape_frontend/transit_scheme_renderer.hpp | 7 +-- map/transit/transit_reader.cpp | 59 +++++++++++++--------- map/transit/transit_reader.hpp | 1 - 12 files changed, 59 insertions(+), 58 deletions(-) diff --git a/drape_frontend/backend_renderer.cpp b/drape_frontend/backend_renderer.cpp index d0da551c84..f4588b298e 100644 --- a/drape_frontend/backend_renderer.cpp +++ b/drape_frontend/backend_renderer.cpp @@ -436,7 +436,6 @@ void BackendRenderer::AcceptMessage(ref_ptr message) case Message::UpdateTransitScheme: { ref_ptr msg = message; - m_transitBuilder->SetVisibleMwms(msg->GetVisibleMwms()); m_transitBuilder->UpdateSchemes(msg->GetTransitDisplayInfos(), m_texMng); break; } diff --git a/drape_frontend/drape_engine.cpp b/drape_frontend/drape_engine.cpp index 98bc54e27f..ffc50bd433 100644 --- a/drape_frontend/drape_engine.cpp +++ b/drape_frontend/drape_engine.cpp @@ -749,12 +749,10 @@ void DrapeEngine::ClearTransitSchemeCache(MwmSet::MwmId const & mwmId) MessagePriority::Normal); } -void DrapeEngine::UpdateTransitScheme(TransitDisplayInfos && transitDisplayInfos, - std::vector const & visibleMwms) +void DrapeEngine::UpdateTransitScheme(TransitDisplayInfos && transitDisplayInfos) { m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread, - make_unique_dp(std::move(transitDisplayInfos), - visibleMwms), + make_unique_dp(std::move(transitDisplayInfos)), MessagePriority::Normal); } diff --git a/drape_frontend/drape_engine.hpp b/drape_frontend/drape_engine.hpp index b2f5c1844f..a3d6277a4d 100644 --- a/drape_frontend/drape_engine.hpp +++ b/drape_frontend/drape_engine.hpp @@ -203,8 +203,7 @@ public: void SetSimplifiedTrafficColors(bool simplified); void EnableTransitScheme(bool enable); - void UpdateTransitScheme(TransitDisplayInfos && transitDisplayInfos, - std::vector const & visibleMwms); + void UpdateTransitScheme(TransitDisplayInfos && transitDisplayInfos); void ClearTransitSchemeCache(MwmSet::MwmId const & mwmId); void SetFontScaleFactor(double scaleFactor); diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index 33b14be677..0c4a7360d1 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -753,6 +753,7 @@ void FrontendRenderer::AcceptMessage(ref_ptr message) case Message::EnableTransitScheme: { ref_ptr msg = message; + m_transitSchemeEnabled = msg->IsEnabled(); if (!msg->IsEnabled()) m_transitSchemeRenderer->ClearGLDependentResources(make_ref(m_overlayTree)); break; @@ -1360,11 +1361,10 @@ void FrontendRenderer::RenderTransitSchemeLayer(ScreenBase const & modelView) { GLFunctions::glClear(gl_const::GLDepthBit); GLFunctions::glEnable(gl_const::GLDepthTest); - if (m_transitSchemeRenderer->HasRenderData(m_currentZoomLevel)) + if (m_transitSchemeEnabled && m_transitSchemeRenderer->IsSchemeVisible(m_currentZoomLevel)) { RenderTransitBackground(); - GLFunctions::glEnable(gl_const::GLDepthTest); - m_transitSchemeRenderer->RenderTransit(modelView, m_currentZoomLevel, make_ref(m_gpuProgramManager), + m_transitSchemeRenderer->RenderTransit(modelView, make_ref(m_gpuProgramManager), make_ref(m_postprocessRenderer), m_generalUniforms); } GLFunctions::glDisable(gl_const::GLDepthTest); @@ -1463,7 +1463,7 @@ void FrontendRenderer::BuildOverlayTree(ScreenBase const & modelView) for (drape_ptr & group : overlay.m_renderGroups) UpdateOverlayTree(modelView, group); } - if (m_transitSchemeRenderer->HasRenderData(m_currentZoomLevel) && !HasTransitRouteData()) + if (m_transitSchemeRenderer->IsSchemeVisible(m_currentZoomLevel) && !HasTransitRouteData()) m_transitSchemeRenderer->CollectOverlays(make_ref(m_overlayTree), modelView); EndUpdateOverlayTree(); } diff --git a/drape_frontend/frontend_renderer.hpp b/drape_frontend/frontend_renderer.hpp index 3a9a998f63..4baba1fdfe 100755 --- a/drape_frontend/frontend_renderer.hpp +++ b/drape_frontend/frontend_renderer.hpp @@ -318,6 +318,7 @@ private: bool m_needRestoreSize; bool m_trafficEnabled; + bool m_transitSchemeEnabled = false; drape_ptr m_overlaysTracker; OverlaysShowStatsCallback m_overlaysShowStatsCallback; diff --git a/drape_frontend/message_subclasses.hpp b/drape_frontend/message_subclasses.hpp index 6466ff5d3e..3a5fcab0f1 100644 --- a/drape_frontend/message_subclasses.hpp +++ b/drape_frontend/message_subclasses.hpp @@ -1053,19 +1053,16 @@ private: class UpdateTransitSchemeMessage : public Message { public: - UpdateTransitSchemeMessage(TransitDisplayInfos && transitInfos, - std::vector const & visibleMwms) - : m_transitInfos(move(transitInfos)), m_visibleMwms(visibleMwms) + UpdateTransitSchemeMessage(TransitDisplayInfos && transitInfos) + : m_transitInfos(move(transitInfos)) {} Type GetType() const override { return Message::UpdateTransitScheme; } TransitDisplayInfos const & GetTransitDisplayInfos() { return m_transitInfos; } - std::vector const & GetVisibleMwms() const { return m_visibleMwms; } private: TransitDisplayInfos m_transitInfos; - std::vector m_visibleMwms; }; class RegenerateTransitMessage : public Message diff --git a/drape_frontend/transit_scheme_builder.cpp b/drape_frontend/transit_scheme_builder.cpp index e8f7e738ad..9fb1ba73e5 100644 --- a/drape_frontend/transit_scheme_builder.cpp +++ b/drape_frontend/transit_scheme_builder.cpp @@ -274,11 +274,6 @@ bool FindLongerPath(routing::transit::StopId stop1Id, routing::transit::StopId s } } // namespace -void TransitSchemeBuilder::SetVisibleMwms(std::vector const & visibleMwms) -{ - m_visibleMwms = visibleMwms; -} - void TransitSchemeBuilder::UpdateSchemes(TransitDisplayInfos const & transitDisplayInfos, ref_ptr textures) { diff --git a/drape_frontend/transit_scheme_builder.hpp b/drape_frontend/transit_scheme_builder.hpp index 7c8610942f..e5a85b37de 100644 --- a/drape_frontend/transit_scheme_builder.hpp +++ b/drape_frontend/transit_scheme_builder.hpp @@ -111,8 +111,6 @@ public: : m_flushRenderDataFn(flushFn) {} - void SetVisibleMwms(std::vector const & visibleMwms); - void UpdateSchemes(TransitDisplayInfos const & transitDisplayInfos, ref_ptr textures); void RebuildSchemes(ref_ptr textures); @@ -167,7 +165,6 @@ private: using TransitSchemes = std::map; TransitSchemes m_schemes; - std::vector m_visibleMwms; TFlushRenderDataFn m_flushRenderDataFn; diff --git a/drape_frontend/transit_scheme_renderer.cpp b/drape_frontend/transit_scheme_renderer.cpp index 88d598eefa..ae04735e45 100644 --- a/drape_frontend/transit_scheme_renderer.cpp +++ b/drape_frontend/transit_scheme_renderer.cpp @@ -27,9 +27,15 @@ float CalculateHalfWidth(ScreenBase const & screen) } } // namespace -bool TransitSchemeRenderer::HasRenderData(int zoomLevel) const +bool TransitSchemeRenderer::IsSchemeVisible(int zoomLevel) const { - return !m_linesRenderData.empty() && zoomLevel >= kTransitSchemeMinZoomLevel; + return zoomLevel >= kTransitSchemeMinZoomLevel; +} + +bool TransitSchemeRenderer::HasRenderData() const +{ + return !m_linesRenderData.empty() || !m_linesCapsRenderData.empty() || !m_markersRenderData.empty() || + !m_textRenderData.empty() || !m_colorSymbolRenderData.empty(); } void TransitSchemeRenderer::ClearGLDependentResources(ref_ptr tree) @@ -123,12 +129,12 @@ void TransitSchemeRenderer::PrepareRenderData(ref_ptr mng, currentRenderData.emplace_back(std::move(newRenderData)); } -void TransitSchemeRenderer::RenderTransit(ScreenBase const & screen, int zoomLevel, - ref_ptr mng, +void TransitSchemeRenderer::RenderTransit(ScreenBase const & screen, ref_ptr mng, ref_ptr postprocessRenderer, dp::UniformValuesStorage const & commonUniforms) { - if (!HasRenderData(zoomLevel)) + auto const zoomLevel = GetDrawTileScale(screen); + if (!IsSchemeVisible(zoomLevel) || !HasRenderData()) return; float const pixelHalfWidth = CalculateHalfWidth(screen); diff --git a/drape_frontend/transit_scheme_renderer.hpp b/drape_frontend/transit_scheme_renderer.hpp index b222841d29..c09b1bff72 100644 --- a/drape_frontend/transit_scheme_renderer.hpp +++ b/drape_frontend/transit_scheme_renderer.hpp @@ -21,10 +21,9 @@ class TransitSchemeRenderer public: void AddRenderData(ref_ptr mng, ref_ptr tree, TransitRenderData && renderData); - bool HasRenderData(int zoomLevel) const; + bool IsSchemeVisible(int zoomLevel) const; - void RenderTransit(ScreenBase const & screen, int zoomLevel, - ref_ptr mng, + void RenderTransit(ScreenBase const & screen, ref_ptr mng, ref_ptr postprocessRenderer, dp::UniformValuesStorage const & commonUniforms); @@ -61,6 +60,8 @@ private: void RenderStubs(ScreenBase const & screen, ref_ptr mng, dp::UniformValuesStorage const & commonUniforms); + bool HasRenderData() const; + uint32_t m_lastRecacheId = 0; std::vector m_linesRenderData; std::vector m_linesCapsRenderData; diff --git a/map/transit/transit_reader.cpp b/map/transit/transit_reader.cpp index 6a6ee0fe43..4bd5eb99be 100644 --- a/map/transit/transit_reader.cpp +++ b/map/transit/transit_reader.cpp @@ -181,7 +181,6 @@ void TransitReadManager::EnableTransitSchemeMode(bool enable) m_isSchemeMode = enable; if (!m_isSchemeMode) { - m_lastVisibleMwms.clear(); m_lastActiveMwms.clear(); m_mwmCache.clear(); m_cacheSize = 0; @@ -200,18 +199,18 @@ void TransitReadManager::UpdateViewport(ScreenBase const & screen) if (!m_isSchemeMode) return; - if (df::GetZoomLevel(screen.GetScale()) < kMinSchemeZoomLevel) + if (df::GetDrawTileScale(screen) < kMinSchemeZoomLevel) + { + ChangeState(TransitSchemeState::Enabled); return; + } auto mwms = m_getMwmsByRectFn(screen.ClipRect()); - if (m_lastVisibleMwms == mwms) - return; - m_lastVisibleMwms = mwms; m_lastActiveMwms.clear(); - auto const currentTime = steady_clock::now(); - TransitDisplayInfos displayInfos; + + TransitDisplayInfos newTransitData; for (auto const & mwmId : mwms) { if (!mwmId.IsAlive()) @@ -220,7 +219,7 @@ void TransitReadManager::UpdateViewport(ScreenBase const & screen) auto it = m_mwmCache.find(mwmId); if (it == m_mwmCache.end()) { - displayInfos[mwmId] = {}; + newTransitData[mwmId] = {}; m_mwmCache.insert(make_pair(mwmId, CacheEntry(currentTime))); } else @@ -228,25 +227,37 @@ void TransitReadManager::UpdateViewport(ScreenBase const & screen) it->second.m_lastActiveTime = currentTime; } } - GetTransitDisplayInfo(displayInfos); - if (!displayInfos.empty()) - { - for (auto const & transitInfo : displayInfos) - { - if (transitInfo.second != nullptr) - { - auto it = m_mwmCache.find(transitInfo.first); - it->second.m_isLoaded = true; - it->second.m_dataSize = CalculateCacheSize(*transitInfo.second); - m_cacheSize += it->second.m_dataSize; - } + if (!newTransitData.empty()) + { + GetTransitDisplayInfo(newTransitData); + + TransitDisplayInfos validTransitData; + for (auto & transitDataItem : newTransitData) + { + auto & transitInfo = transitDataItem.second; + if (!transitInfo || transitInfo->m_lines.empty()) + continue; + + auto it = m_mwmCache.find(transitDataItem.first); + + it->second.m_isLoaded = true; + + auto const dataSize = CalculateCacheSize(*transitInfo); + it->second.m_dataSize = dataSize; + m_cacheSize += dataSize; + + validTransitData[transitDataItem.first] = std::move(transitInfo); + } + + if (!validTransitData.empty()) + { + ShrinkCacheToAllowableSize(); + m_drapeEngine.SafeCall(&df::DrapeEngine::UpdateTransitScheme, std::move(validTransitData)); } - ShrinkCacheToAllowableSize(); - m_drapeEngine.SafeCall(&df::DrapeEngine::UpdateTransitScheme, std::move(displayInfos), mwms); } - bool hasData = false; + bool hasData = m_lastActiveMwms.empty(); for (auto const & mwmId : m_lastActiveMwms) { if (m_mwmCache.at(mwmId).m_isLoaded) @@ -279,8 +290,6 @@ void TransitReadManager::Invalidate() if (!m_isSchemeMode) return; - m_lastVisibleMwms.clear(); - if (m_currentModelView.second) UpdateViewport(m_currentModelView.first); } diff --git a/map/transit/transit_reader.hpp b/map/transit/transit_reader.hpp index 4b6a8c81b1..c3ef315bf0 100644 --- a/map/transit/transit_reader.hpp +++ b/map/transit/transit_reader.hpp @@ -141,7 +141,6 @@ private: }; GetMwmsByRectFn m_getMwmsByRectFn; - std::vector m_lastVisibleMwms; std::set m_lastActiveMwms; std::map m_mwmCache; size_t m_cacheSize = 0;