diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index 19f297f318..f829ed19b4 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -144,6 +144,8 @@ bool Framework::CreateDrapeEngine(JNIEnv * env, jobject jSurface, int densityDpi void Framework::DeleteDrapeEngine() { SaveState(); + m_work.EnterBackground(); + m_work.DestroyDrapeEngine(); } @@ -160,7 +162,7 @@ void Framework::Resize(int w, int h) void Framework::DetachSurface() { - m_work.EnterBackground(); + m_work.SetRenderingEnabled(false); ASSERT(m_contextFactory != nullptr, ()); AndroidOGLContextFactory * factory = m_contextFactory->CastFactory(); @@ -173,7 +175,7 @@ void Framework::AttachSurface(JNIEnv * env, jobject jSurface) AndroidOGLContextFactory * factory = m_contextFactory->CastFactory(); factory->SetSurface(env, jSurface); - m_work.EnterForeground(); + m_work.SetRenderingEnabled(true); } void Framework::SetMapStyle(MapStyle mapStyle) diff --git a/map/framework.cpp b/map/framework.cpp index 2b2e1ed69d..2ee69f7fbf 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1047,8 +1047,7 @@ void Framework::MemoryWarning() void Framework::EnterBackground() { - if (m_drapeEngine) - m_drapeEngine->SetRenderingEnabled(false); + SetRenderingEnabled(false); ms::LatLon const ll = MercatorBounds::ToLatLon(GetViewportCenter()); alohalytics::Stats::Instance().LogEvent("Framework::EnterBackground", {{"zoom", strings::to_string(GetDrawScale())}, @@ -1068,8 +1067,11 @@ void Framework::EnterForeground() m_startForegroundTime = my::Timer::LocalTime(); // Drape can be not initialized here in case of the first launch - if (m_drapeEngine) - m_drapeEngine->SetRenderingEnabled(true); + // TODO(AlexZ): Why it can't be initialized here? Is it because we call EnterForeground in Android for every + // time when activity is created? If yes, then this code should be refactored: + // EnterForeground and EnterBackground should be called only when user opens the app and + // when user completely leaves the app (and is not just switching between app's activities). + SetRenderingEnabled(true); } bool Framework::GetCurrentPosition(double & lat, double & lon) const @@ -1495,6 +1497,12 @@ void Framework::DestroyDrapeEngine() m_drapeEngine.reset(); } +void Framework::SetRenderingEnabled(bool enable) +{ + if (m_drapeEngine) + m_drapeEngine->SetRenderingEnabled(enable); +} + void Framework::ConnectToGpsTracker() { m_connectToGpsTrack = true; diff --git a/map/framework.hpp b/map/framework.hpp index 2370f6ffa3..1a35fae676 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -327,6 +327,8 @@ public: void CreateDrapeEngine(ref_ptr contextFactory, DrapeCreationParams && params); ref_ptr GetDrapeEngine(); void DestroyDrapeEngine(); + /// Called when graphics engine should be temporarily paused and then resumed. + void SetRenderingEnabled(bool enable); void ConnectToGpsTracker(); void DisconnectFromGpsTracker();