diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-09-14 21:23:07 +0300 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2017-09-22 23:33:56 +0300 |
commit | 5d12503302dff168137d6f3b1444e4dc32ad44dd (patch) | |
tree | 98128bdddb287c30b2c1445eb88d44e9a97d57ab /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java | |
parent | 15a47d116a0fc15d249b37574fcd932ce88909df (diff) | |
download | qtlocation-mapboxgl-5d12503302dff168137d6f3b1444e4dc32ad44dd.tar.gz |
[android] self-contained map renderer
- Isolates the GL thread in a MapRenderer class with a native peer
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java')
-rwxr-xr-x | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java | 137 |
1 files changed, 16 insertions, 121 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java index 240e68bf13..62fe2be0c3 100755 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java @@ -4,7 +4,6 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.PointF; import android.graphics.RectF; -import android.opengl.GLSurfaceView; import android.support.annotation.IntRange; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -20,7 +19,8 @@ import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLngBounds; import com.mapbox.mapboxsdk.geometry.ProjectedMeters; -import com.mapbox.mapboxsdk.maps.renderer.RenderThread; +import com.mapbox.mapboxsdk.maps.renderer.MapRenderer; +import com.mapbox.mapboxsdk.maps.renderer.MapRendererScheduler; import com.mapbox.mapboxsdk.storage.FileSource; import com.mapbox.mapboxsdk.style.layers.CannotAddLayerException; import com.mapbox.mapboxsdk.style.layers.Filter; @@ -36,13 +36,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import javax.microedition.khronos.egl.EGLConfig; -import javax.microedition.khronos.opengles.GL10; - import timber.log.Timber; // Class that wraps the native methods for convenience -final class NativeMapView implements GLSurfaceView.Renderer { +final class NativeMapView { // Flag to indicating destroy was called private boolean destroyed = false; @@ -53,12 +50,12 @@ final class NativeMapView implements GLSurfaceView.Renderer { // Used for callbacks private MapView mapView; - // Used to schedule work on the render thread - private RenderThread renderThread; - //Hold a reference to prevent it from being GC'd as long as it's used on the native side private final FileSource fileSource; + // Used to schedule work on the MapRenderer Thread + private MapRendererScheduler scheduler; + // Device density private final float pixelRatio; @@ -73,25 +70,21 @@ final class NativeMapView implements GLSurfaceView.Renderer { // Constructors // - public NativeMapView(final MapView mapView) { + public NativeMapView(final MapView mapView, MapRenderer mapRenderer) { + this.scheduler = mapRenderer; + this.mapView = mapView; + Context context = mapView.getContext(); fileSource = FileSource.getInstance(context); - pixelRatio = context.getResources().getDisplayMetrics().density; - this.mapView = mapView; - String programCacheDir = context.getCacheDir().getAbsolutePath(); - nativeInitialize(this, fileSource, pixelRatio, programCacheDir); + nativeInitialize(this, fileSource, mapRenderer, pixelRatio); } // // Methods // - public void setRenderThread(RenderThread renderThread) { - this.renderThread = renderThread; - } - private boolean isDestroyedOn(String callingMethod) { if (destroyed && !TextUtils.isEmpty(callingMethod)) { Timber.e( @@ -113,14 +106,7 @@ final class NativeMapView implements GLSurfaceView.Renderer { return; } - requestRender(); - } - - public void render() { - if (isDestroyedOn("render")) { - return; - } - nativeRender(); + scheduler.requestRender(); } public void resizeView(int width, int height) { @@ -151,31 +137,8 @@ final class NativeMapView implements GLSurfaceView.Renderer { + "capping value at 65535 instead of %s", height); height = 65535; } - nativeResizeView(width, height); - } - - private void resizeFramebuffer(int fbWidth, int fbHeight) { - if (isDestroyedOn("resizeFramebuffer")) { - return; - } - if (fbWidth < 0) { - throw new IllegalArgumentException("fbWidth cannot be negative."); - } - if (fbHeight < 0) { - throw new IllegalArgumentException("fbHeight cannot be negative."); - } - - if (fbWidth > 65535) { - throw new IllegalArgumentException( - "fbWidth cannot be greater than 65535."); - } - - if (fbHeight > 65535) { - throw new IllegalArgumentException( - "fbHeight cannot be greater than 65535."); - } - nativeResizeFramebuffer(fbWidth, fbHeight); + nativeResizeView(width, height); } public void setStyleUrl(String url) { @@ -873,31 +836,6 @@ final class NativeMapView implements GLSurfaceView.Renderer { // Callbacks // - /** - * Called from JNI whenever the native map - * needs rendering. - */ - protected void requestRender() { - if (renderThread != null) { - renderThread.requestRender(); - } - } - - /** - * Called from JNI when work needs to be processed on - * the Renderer Thread. - */ - protected void requestProcessing() { - if (renderThread != null) { - renderThread.queueEvent(new Runnable() { - @Override - public void run() { - nativeProcess(); - } - }); - } - } - protected void onMapChanged(int rawChange) { if (mapView != null) { mapView.onMapChange(rawChange); @@ -928,33 +866,13 @@ final class NativeMapView implements GLSurfaceView.Renderer { private native void nativeInitialize(NativeMapView nativeMapView, FileSource fileSource, - float pixelRatio, - String programCacheDir); + MapRenderer mapRenderer, + float pixelRatio); private native void nativeDestroy(); - private native void nativeProcess(); - - private native void nativeInitializeDisplay(); - - private native void nativeTerminateDisplay(); - - private native void nativeInitializeContext(); - - private native void nativeTerminateContext(); - - private native void nativeCreateSurface(Object surface); - - private native void nativeDestroySurface(); - - private native void nativeUpdate(); - - private native void nativeRender(); - private native void nativeResizeView(int width, int height); - private native void nativeResizeFramebuffer(int fbWidth, int fbHeight); - private native void nativeSetStyleUrl(String url); private native String nativeGetStyleUrl(); @@ -1160,30 +1078,7 @@ final class NativeMapView implements GLSurfaceView.Renderer { void addSnapshotCallback(@NonNull MapboxMap.SnapshotReadyCallback callback) { snapshotReadyCallback = callback; scheduleTakeSnapshot(); - renderThread.requestRender(); - } - - // - // GLSurfaceView.Renderer - // - - @Override - public void onSurfaceCreated(GL10 gl, EGLConfig config) { - Timber.i("[%s] onSurfaceCreated", Thread.currentThread().getName()); - //TODO: callback to map to re-create renderer? + scheduler.requestRender(); } - @Override - public void onSurfaceChanged(GL10 gl, int width, int height) { - Timber.i("[%s] onSurfaceChanged %sx%s", Thread.currentThread().getName(), width, height); - // Sets the current view port to the new size. - gl.glViewport(0, 0, width, height); - resizeFramebuffer(width, height); - // resizeView(width, height); Done from MapView#onSizeChanged - } - - @Override - public void onDrawFrame(GL10 gl) { - nativeRender(); - } } |