From fa16431221f74c834611694a8e3c5cb192b783fd Mon Sep 17 00:00:00 2001 From: tobrun Date: Tue, 19 Feb 2019 09:48:57 +0100 Subject: wip refactor --- .../maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java | 8 +++++++- platform/android/src/map_renderer.cpp | 10 +++++++++- platform/android/src/map_renderer.hpp | 8 +++++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java index e757907ab8..06539ae21d 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java @@ -1,5 +1,6 @@ package com.mapbox.mapboxsdk.maps.renderer.glsurfaceview; +import android.annotation.SuppressLint; import android.content.Context; import android.opengl.GLSurfaceView; @@ -43,6 +44,11 @@ public class GLSurfaceViewMapRenderer extends MapRenderer implements GLSurfaceVi GLSurfaceViewMapRenderer.this.onSurfaceDestroyed(); } + @Override + public void surfaceCreated(SurfaceHolder holder) { + GLSurfaceViewMapRenderer.super.onSurfaceCreated(null, null); + } + }); } @@ -58,7 +64,7 @@ public class GLSurfaceViewMapRenderer extends MapRenderer implements GLSurfaceVi @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { - super.onSurfaceCreated(gl, config); + //super.onSurfaceCreated(gl, config); } @Override diff --git a/platform/android/src/map_renderer.cpp b/platform/android/src/map_renderer.cpp index cff021afd2..135905c277 100644 --- a/platform/android/src/map_renderer.cpp +++ b/platform/android/src/map_renderer.cpp @@ -125,7 +125,9 @@ void MapRenderer::scheduleSnapshot(std::unique_ptr callback) { } void MapRenderer::render(JNIEnv&) { - assert (renderer); + if (!renderer) { + return; + } std::shared_ptr params; { @@ -159,6 +161,12 @@ void MapRenderer::render(JNIEnv&) { } void MapRenderer::onSurfaceCreated(JNIEnv&) { + // Make sure to create the surface of the renderer on the GL Thread + auto self = ActorRef(*this, mailbox); + self.ask(&MapRenderer::createRenderer).wait(); +} + +void MapRenderer::createRenderer() { // Lock as the initialization can come from the main thread or the GL thread first std::lock_guard lock(initialisationMutex); diff --git a/platform/android/src/map_renderer.hpp b/platform/android/src/map_renderer.hpp index 8c2f28a4df..0c3c01b93e 100644 --- a/platform/android/src/map_renderer.hpp +++ b/platform/android/src/map_renderer.hpp @@ -90,11 +90,13 @@ private: // Renders a frame. void render(JNIEnv&); - void onSurfaceCreated(JNIEnv&); - void onSurfaceChanged(JNIEnv&, jint width, jint height); - // Called on Main thread + void createRenderer(); + + // Called from the Main thread // + void onSurfaceCreated(JNIEnv&); + void onSurfaceDestroyed(JNIEnv&); private: -- cgit v1.2.1