From 8671b834b4c36b766b19dded6b7c374e61a525a4 Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Tue, 31 Oct 2017 18:12:04 +0200 Subject: [android] bring back texture view --- .../java/com/mapbox/mapboxsdk/maps/MapView.java | 66 +++++++++++++++------- .../mapbox/mapboxsdk/maps/MapboxMapOptions.java | 37 +++++++++++- .../src/main/res-public/values/public.xml | 3 + .../src/main/res/values/attrs.xml | 3 + 4 files changed, 85 insertions(+), 24 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index 622cdd33a6..92153f7f0b 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -15,6 +15,7 @@ import android.util.AttributeSet; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.MotionEvent; +import android.view.TextureView; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; @@ -29,6 +30,7 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants; import com.mapbox.mapboxsdk.constants.Style; import com.mapbox.mapboxsdk.maps.renderer.glsurfaceview.GLSurfaceViewMapRenderer; import com.mapbox.mapboxsdk.maps.renderer.MapRenderer; +import com.mapbox.mapboxsdk.maps.renderer.textureview.TextureViewMapRenderer; import com.mapbox.mapboxsdk.maps.widgets.CompassView; import com.mapbox.mapboxsdk.maps.widgets.MyLocationView; import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings; @@ -137,7 +139,7 @@ public class MapView extends FrameLayout { } else { getViewTreeObserver().removeGlobalOnLayoutListener(this); } - initialiseDrawingSurface(); + initialiseDrawingSurface(options); } }); } @@ -284,31 +286,53 @@ public class MapView extends FrameLayout { } } - private void initialiseDrawingSurface() { - GLSurfaceView glSurfaceView = (GLSurfaceView) findViewById(R.id.surfaceView); - glSurfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop()); + private void initialiseDrawingSurface(MapboxMapOptions options) { + if (options.getTextureMode()) { + TextureView textureView = new TextureView(getContext()); + mapRenderer = new TextureViewMapRenderer(getContext(), textureView) { + @Override + protected void onSurfaceCreated(GL10 gl, EGLConfig config) { + MapView.this.post(new Runnable() { + @Override + public void run() { + // Initialise only once + if (mapboxMap == null) { + initialiseMap(); + mapboxMap.onStart(); + } + } + }); - GLSurfaceViewMapRenderer mapRenderer = new GLSurfaceViewMapRenderer(getContext(), glSurfaceView) { - @Override - public void onSurfaceCreated(GL10 gl, EGLConfig config) { - MapView.this.post(new Runnable() { - @Override - public void run() { - // Initialise only once - if (mapboxMap == null) { - initialiseMap(); - mapboxMap.onStart(); + super.onSurfaceCreated(gl, config); + } + }; + addView(textureView, 0); + } else { + GLSurfaceView glSurfaceView = (GLSurfaceView) findViewById(R.id.surfaceView); + glSurfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop()); + + mapRenderer = new GLSurfaceViewMapRenderer(getContext(), glSurfaceView) { + @Override + public void onSurfaceCreated(GL10 gl, EGLConfig config) { + MapView.this.post(new Runnable() { + @Override + public void run() { + // Initialise only once + if (mapboxMap == null) { + initialiseMap(); + mapboxMap.onStart(); + } } - } - }); + }); - super.onSurfaceCreated(gl, config); - } - }; + super.onSurfaceCreated(gl, config); + } + }; - glSurfaceView.setVisibility(View.VISIBLE); + glSurfaceView.setVisibility(View.VISIBLE); + + } - this.mapRenderer = mapRenderer; nativeMapView = new NativeMapView(this, mapRenderer); nativeMapView.resizeView(getMeasuredWidth(), getMeasuredHeight()); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java index 7b979f5563..f26e0b9d3b 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java @@ -85,6 +85,8 @@ public class MapboxMapOptions implements Parcelable { private String apiBaseUrl; + private boolean textureMode; + private String style; /** @@ -152,7 +154,7 @@ public class MapboxMapOptions implements Parcelable { style = in.readString(); apiBaseUrl = in.readString(); - + textureMode = in.readByte() != 0; prefetchesTiles = in.readByte() != 0; zMediaOverlay = in.readByte() != 0; } @@ -296,6 +298,8 @@ public class MapboxMapOptions implements Parcelable { ColorUtils.getPrimaryColor(context))); mapboxMapOptions.myLocationAccuracyThreshold( typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_myLocationAccuracyThreshold, 0)); + mapboxMapOptions.textureMode( + typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_renderTextureMode, false)); mapboxMapOptions.setPrefetchesTiles( typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_enableTilePrefetch, true)); mapboxMapOptions.renderSurfaceOnTop( @@ -698,13 +702,30 @@ public class MapboxMapOptions implements Parcelable { return this; } + /** + * Enable {@link android.view.TextureView} as rendered surface. + *

+ * Since the 5.2.0 release we replaced our TextureView with an {@link android.opengl.GLSurfaceView} + * implementation. Enabling this option will use the {@link android.view.TextureView} instead. + * {@link android.view.TextureView} can be useful in situations where you need to animate, scale + * or transform the view. This comes at a siginficant performance penalty and should not be considered + * unless absolutely needed. + *

+ * + * @param textureMode True to enable texture mode + * @return This + */ + public MapboxMapOptions textureMode(boolean textureMode) { + this.textureMode = textureMode; + return this; + } + /** * Enable tile pre-fetching. Loads tiles at a lower zoom-level to pre-render * a low resolution preview while more detailed tiles are loaded. * Enabled by default * * @param enable true to enable - * * @return This */ public MapboxMapOptions setPrefetchesTiles(boolean enable) { @@ -1049,6 +1070,15 @@ public class MapboxMapOptions implements Parcelable { return debugActive; } + /** + * Returns true if TextureView is being used the render view. + * + * @return True if TextureView is used. + */ + public boolean getTextureMode() { + return textureMode; + } + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { public MapboxMapOptions createFromParcel(Parcel in) { return new MapboxMapOptions(in); @@ -1112,7 +1142,7 @@ public class MapboxMapOptions implements Parcelable { dest.writeString(style); dest.writeString(apiBaseUrl); - + dest.writeByte((byte) (textureMode ? 1 : 0)); dest.writeByte((byte) (prefetchesTiles ? 1 : 0)); dest.writeByte((byte) (zMediaOverlay ? 1 : 0)); } @@ -1289,6 +1319,7 @@ public class MapboxMapOptions implements Parcelable { result = 31 * result + (myLocationAccuracyThreshold != +0.0f ? Float.floatToIntBits(myLocationAccuracyThreshold) : 0); result = 31 * result + (apiBaseUrl != null ? apiBaseUrl.hashCode() : 0); + result = 31 * result + (textureMode ? 1 : 0); result = 31 * result + (style != null ? style.hashCode() : 0); result = 31 * result + (prefetchesTiles ? 1 : 0); result = 31 * result + (zMediaOverlay ? 1 : 0); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml index 40045f851f..f406f4d042 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml @@ -72,6 +72,9 @@ + + + diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml index b673224094..2a4c2fe746 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml @@ -114,6 +114,9 @@ + + + -- cgit v1.2.1