From 9725169aa314aa2b0499d3fe2a97c7a06f703f7b Mon Sep 17 00:00:00 2001 From: "r.kuznetsov" Date: Tue, 31 Jul 2018 16:20:08 +0300 Subject: [PATCH] [Android] Added surface rendering pause/resume --- android/jni/com/mapswithme/maps/Framework.cpp | 18 ++++++++++++++++++ android/jni/com/mapswithme/maps/Framework.hpp | 4 ++-- .../jni/com/mapswithme/maps/MapFragment.cpp | 12 ++++++++++++ .../src/com/mapswithme/maps/MapFragment.java | 10 ++++++++++ drape_frontend/frontend_renderer.cpp | 8 +------- 5 files changed, 43 insertions(+), 9 deletions(-) diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index 791353ee15..a2c660d9c3 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -247,6 +247,24 @@ bool Framework::AttachSurface(JNIEnv * env, jobject jSurface) return true; } +void Framework::PauseSurfaceRendering() +{ + if (m_contextFactory == nullptr) + return; + LOG(LINFO, ("Pause surface rendering.")); + m_contextFactory->setPresentAvailable(false); +} + +void Framework::ResumeSurfaceRendering() +{ + if (m_contextFactory == nullptr) + return; + LOG(LINFO, ("Resume surface rendering.")); + AndroidOGLContextFactory * factory = m_contextFactory->CastFactory(); + if (factory->IsValid()) + m_contextFactory->setPresentAvailable(true); +} + void Framework::SetMapStyle(MapStyle mapStyle) { m_work.SetMapStyle(mapStyle); diff --git a/android/jni/com/mapswithme/maps/Framework.hpp b/android/jni/com/mapswithme/maps/Framework.hpp index 76d35025b2..6ad976771b 100644 --- a/android/jni/com/mapswithme/maps/Framework.hpp +++ b/android/jni/com/mapswithme/maps/Framework.hpp @@ -92,14 +92,14 @@ namespace android void OnCompassUpdated(location::CompassInfo const & info, bool forceRedraw); void UpdateCompassSensor(int ind, float * arr); - void Invalidate(); - bool CreateDrapeEngine(JNIEnv * env, jobject jSurface, int densityDpi, bool firstLaunch, bool launchByDeepLink); bool IsDrapeEngineCreated(); void DetachSurface(bool destroyContext); bool AttachSurface(JNIEnv * env, jobject jSurface); + void PauseSurfaceRendering(); + void ResumeSurfaceRendering(); void SetMapStyle(MapStyle mapStyle); void MarkMapStyle(MapStyle mapStyle); diff --git a/android/jni/com/mapswithme/maps/MapFragment.cpp b/android/jni/com/mapswithme/maps/MapFragment.cpp index 1447644032..9e9fd9c641 100644 --- a/android/jni/com/mapswithme/maps/MapFragment.cpp +++ b/android/jni/com/mapswithme/maps/MapFragment.cpp @@ -84,6 +84,18 @@ Java_com_mapswithme_maps_MapFragment_nativeDetachSurface(JNIEnv * env, jclass cl g_framework->DetachSurface(destroyContext); } +JNIEXPORT void JNICALL +Java_com_mapswithme_maps_MapFragment_nativePauseSurfaceRendering(JNIEnv *, jclass) +{ + g_framework->PauseSurfaceRendering(); +} + +JNIEXPORT void JNICALL +Java_com_mapswithme_maps_MapFragment_nativeResumeSurfaceRendering(JNIEnv *, jclass) +{ + g_framework->ResumeSurfaceRendering(); +} + JNIEXPORT void JNICALL Java_com_mapswithme_maps_MapFragment_nativeSurfaceChanged(JNIEnv * env, jclass clazz, jint w, jint h) { diff --git a/android/src/com/mapswithme/maps/MapFragment.java b/android/src/com/mapswithme/maps/MapFragment.java index 0d63b99fb2..40c188be96 100644 --- a/android/src/com/mapswithme/maps/MapFragment.java +++ b/android/src/com/mapswithme/maps/MapFragment.java @@ -285,9 +285,17 @@ public class MapFragment extends BaseMwmFragment public void onPause() { mUiThemeOnPause = Config.getCurrentUiTheme(); + nativePauseSurfaceRendering(); super.onPause(); } + @Override + public void onResume() + { + super.onResume(); + nativeResumeSurfaceRendering(); + } + @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -360,6 +368,8 @@ public class MapFragment extends BaseMwmFragment boolean isLaunchByDeepLink); private static native boolean nativeAttachSurface(Surface surface); private static native void nativeDetachSurface(boolean destroyContext); + private static native void nativePauseSurfaceRendering(); + private static native void nativeResumeSurfaceRendering(); private static native void nativeSurfaceChanged(int w, int h); private static native void nativeOnTouch(int actionType, int id1, float x1, float y1, int id2, float x2, float y2, int maskedPointer); private static native void nativeSetupWidget(int widget, float x, float y, int anchor); diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index d10dddf7f8..9941bdff48 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -2026,7 +2026,6 @@ void FrontendRenderer::Routine::Do() double frameTime = 0.0; bool modelViewChanged = true; bool viewportChanged = true; - bool invalidContext = false; uint32_t inactiveFramesCounter = 0; bool forceFullRedrawNextFrame = false; uint32_t constexpr kMaxInactiveFrames = 2; @@ -2055,7 +2054,6 @@ void FrontendRenderer::Routine::Do() { if (context->validate()) { - invalidContext = false; timer.Reset(); ScreenBase modelView = m_renderer.ProcessEvents(modelViewChanged, viewportChanged); @@ -2152,12 +2150,8 @@ void FrontendRenderer::Routine::Do() } else { + forceFullRedrawNextFrame = true; inactiveFramesCounter = 0; - if (!invalidContext) - { - LOG(LINFO, ("Invalid context. Rendering is stopped.")); - invalidContext = true; - } } m_renderer.CheckRenderingEnabled(); }