summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2017-11-03 11:33:00 +0200
committerTobrun <tobrun.van.nuland@gmail.com>2017-11-03 03:18:01 -0700
commite552e0bf6d9bc7239d091cf3ff2362fd83456eaa (patch)
tree0c3393a0e6d005aa4ee60b8248b783d885292ca6
parent04ac36318c6f5a0942434168e84231e68e922d72 (diff)
downloadqtlocation-mapboxgl-upstream/tvn-cherry-pick-textureview.tar.gz
[android] TextureView - cleanup destruction codeupstream/tvn-cherry-pick-textureview
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java41
1 files changed, 29 insertions, 12 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java
index 3ed55b634a..c34833e9ce 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java
@@ -213,6 +213,12 @@ class TextureViewRenderThread extends Thread implements TextureView.SurfaceTextu
break;
}
+ // (re-)Initialize EGL Surface if needed
+ if (eglHolder.eglSurface == EGL10.EGL_NO_SURFACE) {
+ recreateSurface = true;
+ break;
+ }
+
// Check if the size has changed
if (sizeChanged) {
recreateSurface = true;
@@ -247,7 +253,14 @@ class TextureViewRenderThread extends Thread implements TextureView.SurfaceTextu
// Initialize EGL
if (initializeEGL) {
eglHolder.prepare();
- eglHolder.createSurface();
+ if (!eglHolder.createSurface()) {
+ synchronized (lock) {
+ // Cleanup the surface if one could not be created
+ // and wait for another to be ready.
+ destroySurface = true;
+ }
+ continue;
+ }
mapRenderer.onSurfaceCreated(gl, eglHolder.eglConfig);
mapRenderer.onSurfaceChanged(gl, w, h);
continue;
@@ -345,7 +358,7 @@ class TextureViewRenderThread extends Thread implements TextureView.SurfaceTextu
// No texture view present
eglConfig = null;
eglContext = EGL10.EGL_NO_CONTEXT;
- } else /*if (eglContext == EGL10.EGL_NO_CONTEXT)*/ {
+ } else if (eglContext == EGL10.EGL_NO_CONTEXT) {
eglConfig = new EGLConfigChooser().chooseConfig(egl, eglDisplay);
int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE};
eglContext = egl.eglCreateContext(eglDisplay, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
@@ -408,29 +421,33 @@ class TextureViewRenderThread extends Thread implements TextureView.SurfaceTextu
}
if (!egl.eglDestroySurface(eglDisplay, eglSurface)) {
- Timber.e("Could not destroy egl surface. Display %s, Surface %s", eglDisplay, eglSurface);
- throw new RuntimeException("eglDestroyContext: " + egl.eglGetError());
+ Timber.w("Could not destroy egl surface. Display %s, Surface %s", eglDisplay, eglSurface);
}
+
+ eglSurface = EGL10.EGL_NO_SURFACE;
}
private void destroyContext() {
- if (eglSurface == null || eglSurface == EGL10.EGL_NO_SURFACE) {
+ if (eglContext == EGL10.EGL_NO_CONTEXT) {
return;
}
if (!egl.eglDestroyContext(eglDisplay, eglContext)) {
- Timber.e("Could not destroy egl context. Display %s, Context %s", eglDisplay, eglContext);
- throw new RuntimeException("eglDestroyContext: " + egl.eglGetError());
+ Timber.w("Could not destroy egl context. Display %s, Context %s", eglDisplay, eglContext);
}
+
+ eglContext = EGL10.EGL_NO_CONTEXT;
}
private void terminate() {
- if (eglDisplay != EGL10.EGL_NO_DISPLAY) {
- if (!egl.eglTerminate(eglDisplay)) {
- Timber.w("Could not terminate egl. Display %s", eglDisplay);
- }
- eglDisplay = EGL10.EGL_NO_DISPLAY;
+ if (eglDisplay == EGL10.EGL_NO_DISPLAY) {
+ return;
+ }
+
+ if (!egl.eglTerminate(eglDisplay)) {
+ Timber.w("Could not terminate egl. Display %s", eglDisplay);
}
+ eglDisplay = EGL10.EGL_NO_DISPLAY;
}
void cleanup() {