diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index c3f6c07832..fdd6bf0a09 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -183,6 +183,11 @@ void Framework::SetMapStyle(MapStyle mapStyle) m_work.SetMapStyle(mapStyle); } +void Framework::MarkMapStyle(MapStyle mapStyle) +{ + m_work.MarkMapStyle(mapStyle); +} + MapStyle Framework::GetMapStyle() const { return m_work.GetMapStyle(); @@ -1281,6 +1286,14 @@ extern "C" g_framework->SetMapStyle(val); } + JNIEXPORT void JNICALL + Java_com_mapswithme_maps_Framework_nativeMarkMapStyle(JNIEnv * env, jclass thiz, jint mapStyle) + { + MapStyle const val = static_cast(mapStyle); + if (val != g_framework->GetMapStyle()) + g_framework->MarkMapStyle(val); + } + JNIEXPORT void JNICALL Java_com_mapswithme_maps_Framework_nativeSetRouter(JNIEnv * env, jclass thiz, jint routerType) { diff --git a/android/jni/com/mapswithme/maps/Framework.hpp b/android/jni/com/mapswithme/maps/Framework.hpp index 154da0cf6d..2061456f9a 100644 --- a/android/jni/com/mapswithme/maps/Framework.hpp +++ b/android/jni/com/mapswithme/maps/Framework.hpp @@ -80,6 +80,7 @@ namespace android void AttachSurface(JNIEnv * env, jobject jSurface); void SetMapStyle(MapStyle mapStyle); + void MarkMapStyle(MapStyle mapStyle); MapStyle GetMapStyle() const; void SetupMeasurementSystem(); diff --git a/android/src/com/mapswithme/maps/Framework.java b/android/src/com/mapswithme/maps/Framework.java index 1dd14be0de..525af6a545 100644 --- a/android/src/com/mapswithme/maps/Framework.java +++ b/android/src/com/mapswithme/maps/Framework.java @@ -161,6 +161,13 @@ public class Framework public native static void nativeSetMapStyle(int mapStyle); + /** + * This method allows to set new map style without immediate applying. It can be used before + * engine recreation instead of nativeSetMapStyle to avoid huge flow of OpenGL invocations. + * @param mapStyle style index + */ + public native static void nativeMarkMapStyle(int mapStyle); + public native static void nativeSetRouter(int routerType); public native static int nativeGetRouter(); diff --git a/android/src/com/mapswithme/maps/MapFragment.java b/android/src/com/mapswithme/maps/MapFragment.java index 3b4ba705ed..a13ddae749 100644 --- a/android/src/com/mapswithme/maps/MapFragment.java +++ b/android/src/com/mapswithme/maps/MapFragment.java @@ -180,16 +180,23 @@ public class MapFragment extends BaseMwmFragment return; if (getActivity() == null || !getActivity().isChangingConfigurations()) - { - // We're in the main thread here. So nothing from the queue will be run between these two calls. - // Destroy engine first, then clear the queue that theoretically can be filled by nativeDestroyEngine(). - nativeDestroyEngine(); - MwmApplication.get().clearFunctorsOnUiThread(); - } + destroyEngine(); else nativeDetachSurface(); } + public void destroyEngine() + { + if (!mEngineCreated) + return; + + // We're in the main thread here. So nothing from the queue will be run between these two calls. + // Destroy engine first, then clear the queue that theoretically can be filled by nativeDestroyEngine(). + nativeDestroyEngine(); + MwmApplication.get().clearFunctorsOnUiThread(); + mEngineCreated = false; + } + @Override public void onCreate(Bundle b) { diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java index eb6287033c..d2e2143c47 100644 --- a/android/src/com/mapswithme/maps/MwmActivity.java +++ b/android/src/com/mapswithme/maps/MwmActivity.java @@ -750,6 +750,14 @@ public class MwmActivity extends BaseMwmFragmentActivity mMainMenu.onResume(); } + @Override + public void recreate() + { + // Explicitly destroy engine before activity recreation. + mMapFragment.destroyEngine(); + super.recreate(); + } + private void initShowcase() { NativeAppwallAd.AppwallAdListener listener = new NativeAppwallAd.AppwallAdListener() diff --git a/android/src/com/mapswithme/util/ThemeSwitcher.java b/android/src/com/mapswithme/util/ThemeSwitcher.java index e5f447f078..d2173c2260 100644 --- a/android/src/com/mapswithme/util/ThemeSwitcher.java +++ b/android/src/com/mapswithme/util/ThemeSwitcher.java @@ -88,7 +88,9 @@ public final class ThemeSwitcher if (ThemeUtils.isNightTheme(theme)) style = Framework.MAP_STYLE_DARK; - Framework.nativeSetMapStyle(style); + // Activity and drape engine will be recreated so we have to mark new map style. + // Changes will be applied in process of recreation. + Framework.nativeMarkMapStyle(style); Activity a = MwmApplication.backgroundTracker().getTopActivity(); if (a != null && !a.isFinishing()) diff --git a/map/framework.cpp b/map/framework.cpp index 6aecf4af74..6c7d2fd9f8 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1392,20 +1392,23 @@ void Framework::OnUpdateGpsTrackPointsCallback(vectorUpdateGpsTrackPoints(move(pointsAdd), move(indicesRemove)); } -void Framework::SetMapStyle(MapStyle mapStyle) +void Framework::MarkMapStyle(MapStyle mapStyle) { // Store current map style before classificator reloading Settings::Set(kMapStyleKey, static_cast(mapStyle)); GetStyleReader().SetCurrentStyle(mapStyle); - CallDrapeFunction(bind(&df::DrapeEngine::UpdateMapStyle, _1)); - - InvalidateUserMarks(); - alohalytics::TStringMap details {{"mapStyle", strings::to_string(static_cast(mapStyle))}}; alohalytics::Stats::Instance().LogEvent("MapStyle_Changed", details); } +void Framework::SetMapStyle(MapStyle mapStyle) +{ + MarkMapStyle(mapStyle); + CallDrapeFunction(bind(&df::DrapeEngine::UpdateMapStyle, _1)); + InvalidateUserMarks(); +} + MapStyle Framework::GetMapStyle() const { return GetStyleReader().GetCurrentStyle(); diff --git a/map/framework.hpp b/map/framework.hpp index 5bb45a988d..859c5a5a4a 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -318,6 +318,7 @@ public: void DisconnectFromGpsTracker(); void SetMapStyle(MapStyle mapStyle); + void MarkMapStyle(MapStyle mapStyle); MapStyle GetMapStyle() const; void SetupMeasurementSystem();