summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun <tobrun.van.nuland@gmail.com>2016-11-16 18:08:48 +0100
committerTobrun <tobrun.van.nuland@gmail.com>2016-11-16 18:08:48 +0100
commit568eaaa108ed9e6e55d306ef2ea670c215c8d0ac (patch)
tree7e1d009e7b7f926a3bc80368005c4080d70c44fb
parent5479b75c9fa971332aadfede6b380267eebbd566 (diff)
downloadqtlocation-mapboxgl-upstream/5766-gl-surfaceview.tar.gz
[android] - migrate to GLSurfaceViewupstream/5766-gl-surfaceview
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapSurfaceView.java89
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java28
-rwxr-xr-xplatform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java4
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java69
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_marker_bulk.xml2
-rwxr-xr-xplatform/android/src/native_map_view.cpp382
-rwxr-xr-xplatform/android/src/native_map_view.hpp15
7 files changed, 154 insertions, 435 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapSurfaceView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapSurfaceView.java
new file mode 100644
index 0000000000..4ce921d656
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapSurfaceView.java
@@ -0,0 +1,89 @@
+package com.mapbox.mapboxsdk.maps;
+
+import android.content.Context;
+import android.opengl.GLSurfaceView;
+import android.os.Handler;
+import android.util.AttributeSet;
+import android.util.Log;
+
+import com.mapbox.mapboxsdk.constants.Style;
+import com.mapbox.mapboxsdk.geometry.LatLng;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+import static com.mapbox.mapboxsdk.constants.MapboxConstants.TAG;
+
+public class MapSurfaceView extends GLSurfaceView {
+
+ private MapRenderer renderer;
+ private NativeMapView nativeMapView;
+
+ public MapSurfaceView(Context context) {
+ super(context);
+ init(context, null);
+ }
+
+ public MapSurfaceView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init(context, attrs);
+ }
+
+ private void init(Context context, AttributeSet attrs) {
+ setDebugFlags(DEBUG_CHECK_GL_ERROR | DEBUG_LOG_GL_CALLS);
+ setEGLContextClientVersion(2);
+ nativeMapView = new NativeMapView(this);
+ nativeMapView.setAccessToken("pk.eyJ1IjoidG9icnVuIiwiYSI6ImNpajVlajR0cjAwNjN2NmtyY204eWw2eG0ifQ.x3_WEoExNW5Qyv9T3Vj7Mw");
+ nativeMapView.setStyleUrl(Style.LIGHT);
+ renderer = new MapRenderer();
+ setRenderer(renderer);
+ setRenderMode(RENDERMODE_WHEN_DIRTY);
+ new Handler().postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ nativeMapView.flyTo(90, new LatLng(22, 22), 3000, 2, 11);
+ }
+ }, 3000);
+ }
+
+ @Override
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ super.onSizeChanged(w, h, oldw, oldh);
+ }
+
+ public void onInvalidate() {
+ throw new RuntimeException("OnInvalidate");
+ }
+
+ public void onMapChanged(int rawChange) {
+ throw new RuntimeException("OnMapChanged " + rawChange);
+ }
+
+ public void onFpsChanged(double fps) {
+ throw new RuntimeException("OnFpsChanged " + fps);
+ }
+
+ public void onSnapshotReady(byte[] bytes) {
+ throw new RuntimeException("OnSnapshotReady");
+ }
+
+ private class MapRenderer implements GLSurfaceView.Renderer {
+ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ Log.d(TAG, "onSurfaceCreated");
+ nativeMapView.createSurface(getHolder().getSurface());
+ }
+
+ public void onSurfaceChanged(GL10 gl, final int w, final int h) {
+ Log.d(TAG, "onSurfaceChanged " + w + " " + h);
+ gl.glViewport(0, 0, w, h);
+ nativeMapView.resizeView(w, h);
+ nativeMapView.resizeFramebuffer(w, h);
+ nativeMapView.update();
+ }
+
+ public void onDrawFrame(GL10 gl) {
+ Log.d(TAG, "onDrawFrame render");
+ nativeMapView.render();
+ }
+ }
+}
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 e5848f5090..3f6bd31471 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
@@ -45,7 +45,6 @@ import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.Surface;
import android.view.SurfaceHolder;
-import android.view.SurfaceView;
import android.view.TextureView;
import android.view.View;
import android.view.ViewConfiguration;
@@ -124,6 +123,8 @@ public class MapView extends FrameLayout {
private MyLocationView myLocationView;
private LocationListener myLocationListener;
+ private MapSurfaceView mapSurfaceView;
+
private Projection projection;
private CopyOnWriteArrayList<OnMapChangedListener> onMapChangedListener;
@@ -202,12 +203,11 @@ public class MapView extends FrameLayout {
textureView.setSurfaceTextureListener(new SurfaceTextureListener());
addView(textureView, 0);
} else {
- SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surfaceView);
- surfaceView.getHolder().addCallback(new SurfaceCallback());
- surfaceView.setVisibility(View.VISIBLE);
+ mapSurfaceView = (MapSurfaceView) findViewById(R.id.surfaceView);
+ //surfaceView.getHolder().addCallback(new SurfaceCallback());
+ mapSurfaceView.setVisibility(View.VISIBLE);
}
- nativeMapView = new NativeMapView(this);
iconManager = new IconManager(nativeMapView);
mapboxMap = new MapboxMap(this, iconManager);
annotationManager = mapboxMap.getAnnotationManager();
@@ -576,6 +576,8 @@ public class MapView extends FrameLayout {
public void onStart() {
onStartCalled = true;
+ mapSurfaceView.onResume();
+
// Register for connectivity changes
connectivityReceiver = new ConnectivityReceiver();
getContext().registerReceiver(connectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
@@ -616,6 +618,8 @@ public class MapView extends FrameLayout {
public void onStop() {
onStopCalled = true;
+ mapSurfaceView.onPause();
+
// Unregister for connectivity changes
if (connectivityReceiver != null) {
getContext().unregisterReceiver(connectivityReceiver);
@@ -705,11 +709,11 @@ public class MapView extends FrameLayout {
// Center coordinate
//
- LatLng getCenterCoordinate(){
+ LatLng getCenterCoordinate() {
return nativeMapView.getLatLng();
}
- void setCenterCoordinate(LatLng centerCoordinate){
+ void setCenterCoordinate(LatLng centerCoordinate) {
nativeMapView.setLatLng(centerCoordinate);
}
@@ -1071,7 +1075,7 @@ public class MapView extends FrameLayout {
// Mapbox Core GL Camera
//
- private void cancelTransitions(){
+ private void cancelTransitions() {
if (cameraCancelableCallback != null) {
cameraCancelableCallback.onCancel();
cameraCancelableCallback = null;
@@ -1522,10 +1526,6 @@ public class MapView extends FrameLayout {
// Called for double taps
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
- if (destroyed || !mapboxMap.getUiSettings().isZoomGesturesEnabled()) {
- return false;
- }
-
switch (e.getAction()) {
case MotionEvent.ACTION_DOWN:
break;
@@ -2656,7 +2656,7 @@ public class MapView extends FrameLayout {
}
}
- private static class ZoomInvalidator implements Runnable {
+ public static class ZoomInvalidator implements Runnable {
private MapboxMap mapboxMap;
@@ -2667,7 +2667,7 @@ public class MapView extends FrameLayout {
@Override
public void run() {
// invalidate camera position
- mapboxMap.getCameraPosition();
+ // mapboxMap.getCameraPosition();
}
}
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 e7e3e647af..ff64a56beb 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
@@ -40,7 +40,7 @@ final class NativeMapView {
private long nativeMapViewPtr = 0;
// Used for callbacks
- private MapView mapView;
+ private MapSurfaceView mapView;
private final float pixelRatio;
@@ -56,7 +56,7 @@ final class NativeMapView {
// Constructors
//
- public NativeMapView(MapView mapView) {
+ public NativeMapView(MapSurfaceView mapView) {
Context context = mapView.getContext();
String dataPath = OfflineManager.getDatabasePath(context);
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java
index 2b84763dcd..8429145223 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java
@@ -27,6 +27,7 @@ import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.MarkerViewOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.maps.MapSurfaceView;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
@@ -44,7 +45,7 @@ import java.util.Random;
public class BulkMarkerActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
private MapboxMap mapboxMap;
- private MapView mapView;
+ private MapSurfaceView mapView;
private boolean customMarkerView;
private List<LatLng> locations;
@@ -63,23 +64,23 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
actionBar.setDisplayShowHomeEnabled(true);
}
- mapView = (MapView) findViewById(R.id.mapView);
- mapView.onCreate(savedInstanceState);
- mapView.getMapAsync(new OnMapReadyCallback() {
- @Override
- public void onMapReady(@NonNull MapboxMap mapboxMap) {
- BulkMarkerActivity.this.mapboxMap = mapboxMap;
-
- if (actionBar != null) {
- ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(
- actionBar.getThemedContext(), R.array.bulk_marker_list, android.R.layout.simple_spinner_item);
- spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- Spinner spinner = (Spinner) findViewById(R.id.spinner);
- spinner.setAdapter(spinnerAdapter);
- spinner.setOnItemSelectedListener(BulkMarkerActivity.this);
- }
- }
- });
+ mapView = (MapSurfaceView) findViewById(R.id.mapView);
+// mapView.onCreate(savedInstanceState);
+// mapView.getMapAsync(new OnMapReadyCallback() {
+// @Override
+// public void onMapReady(@NonNull MapboxMap mapboxMap) {
+// BulkMarkerActivity.this.mapboxMap = mapboxMap;
+//
+// if (actionBar != null) {
+// ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(
+// actionBar.getThemedContext(), R.array.bulk_marker_list, android.R.layout.simple_spinner_item);
+// spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+// Spinner spinner = (Spinner) findViewById(R.id.spinner);
+// spinner.setAdapter(spinnerAdapter);
+// spinner.setOnItemSelectedListener(BulkMarkerActivity.this);
+// }
+// }
+// });
final View fab = findViewById(R.id.fab);
if (fab != null) {
@@ -166,7 +167,7 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
@Override
protected void onStart() {
super.onStart();
- mapView.onStart();
+ // mapView.onStart();
}
@Override
@@ -184,25 +185,25 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
@Override
protected void onStop() {
super.onStop();
- mapView.onStop();
+ // mapView.onStop();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
- mapView.onSaveInstanceState(outState);
+ // mapView.onSaveInstanceState(outState);
}
@Override
protected void onDestroy() {
super.onDestroy();
- mapView.onDestroy();
+ // mapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
- mapView.onLowMemory();
+ // mapView.onLowMemory();
}
@Override
@@ -239,17 +240,17 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
showMarkers(amount);
}
- mapView.addOnMapChangedListener(new MapView.OnMapChangedListener() {
- @Override
- public void onMapChanged(@MapView.MapChange int change) {
- if (change == MapView.REGION_IS_CHANGING || change == MapView.REGION_DID_CHANGE) {
- if (!mapboxMap.getMarkerViewManager().getMarkerViewAdapters().isEmpty()) {
- TextView viewCountView = (TextView) findViewById(R.id.countView);
- viewCountView.setText("ViewCache size " + (mapView.getChildCount() - 5));
- }
- }
- }
- });
+// mapView.addOnMapChangedListener(new MapView.OnMapChangedListener() {
+// @Override
+// public void onMapChanged(@MapView.MapChange int change) {
+// if (change == MapView.REGION_IS_CHANGING || change == MapView.REGION_DID_CHANGE) {
+// if (!mapboxMap.getMarkerViewManager().getMarkerViewAdapters().isEmpty()) {
+// TextView viewCountView = (TextView) findViewById(R.id.countView);
+// viewCountView.setText("ViewCache size " + (mapView.getChildCount() - 5));
+// }
+// }
+// }
+// });
mapboxMap.getMarkerViewManager().setOnMarkerViewClickListener(
new MapboxMap.OnMarkerViewClickListener() {
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_marker_bulk.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_marker_bulk.xml
index 229d8e87c1..950ded9fd8 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_marker_bulk.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_marker_bulk.xml
@@ -18,7 +18,7 @@
</android.support.v7.widget.Toolbar>
- <com.mapbox.mapboxsdk.maps.MapView
+ <com.mapbox.mapboxsdk.maps.MapSurfaceView
android:id="@id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp
index 984fe9d382..e9701185c7 100755
--- a/platform/android/src/native_map_view.cpp
+++ b/platform/android/src/native_map_view.cpp
@@ -79,9 +79,6 @@ NativeMapView::NativeMapView(JNIEnv *env_, jobject obj_, float pixelRatio, int a
NativeMapView::~NativeMapView() {
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::~NativeMapView");
- terminateContext();
- destroySurface();
- terminateDisplay();
assert(vm != nullptr);
assert(obj != nullptr);
@@ -100,122 +97,36 @@ mbgl::Size NativeMapView::getFramebufferSize() const {
return { static_cast<uint32_t>(fbWidth), static_cast<uint32_t>(fbHeight) };
}
-void NativeMapView::updateViewBinding() {
- getContext().bindFramebuffer.setCurrentValue(0);
- assert(mbgl::gl::value::BindFramebuffer::Get() == getContext().bindFramebuffer.getCurrentValue());
- getContext().viewport.setCurrentValue({ 0, 0, getFramebufferSize() });
- assert(mbgl::gl::value::Viewport::Get() == getContext().viewport.getCurrentValue());
-}
-
void NativeMapView::bind() {
getContext().bindFramebuffer = 0;
getContext().viewport = { 0, 0, getFramebufferSize() };
}
void NativeMapView::activate() {
- if (active++) {
- return;
- }
-
- oldDisplay = eglGetCurrentDisplay();
- oldReadSurface = eglGetCurrentSurface(EGL_READ);
- oldDrawSurface = eglGetCurrentSurface(EGL_DRAW);
- oldContext = eglGetCurrentContext();
-
- assert(vm != nullptr);
-
- if ((display != EGL_NO_DISPLAY) && (surface != EGL_NO_SURFACE) && (context != EGL_NO_CONTEXT)) {
- if (!eglMakeCurrent(display, surface, surface, context)) {
- mbgl::Log::Error(mbgl::Event::OpenGL, "eglMakeCurrent() returned error %d",
- eglGetError());
- throw std::runtime_error("eglMakeCurrent() failed");
- }
-
- if (!eglSwapInterval(display, 0)) {
- mbgl::Log::Error(mbgl::Event::OpenGL, "eglSwapInterval() returned error %d", eglGetError());
- throw std::runtime_error("eglSwapInterval() failed");
- }
- } else {
- mbgl::Log::Info(mbgl::Event::Android, "Not activating as we are not ready");
- }
+ return;
}
void NativeMapView::deactivate() {
- if (--active) {
- return;
- }
-
- assert(vm != nullptr);
-
- if (oldContext != context && oldContext != EGL_NO_CONTEXT) {
- if (!eglMakeCurrent(oldDisplay, oldDrawSurface, oldReadSurface, oldContext)) {
- mbgl::Log::Error(mbgl::Event::OpenGL, "eglMakeCurrent() returned error %d",
- eglGetError());
- throw std::runtime_error("eglMakeCurrent() failed");
- }
- } else if (display != EGL_NO_DISPLAY) {
- if (!eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) {
- mbgl::Log::Error(mbgl::Event::OpenGL, "eglMakeCurrent(EGL_NO_CONTEXT) returned error %d",
- eglGetError());
- throw std::runtime_error("eglMakeCurrent() failed");
- }
- } else {
- mbgl::Log::Info(mbgl::Event::Android, "Not deactivating as we are not ready");
- }
+ return;
}
void NativeMapView::invalidate() {
assert(vm != nullptr);
assert(obj != nullptr);
- env->CallVoidMethod(obj, onInvalidateId);
- if (env->ExceptionCheck()) {
- env->ExceptionDescribe();
- }
+ //env->CallVoidMethod(obj, onInvalidateId);
+ //if (env->ExceptionCheck()) {
+ // env->ExceptionDescribe();
+ //}
}
void NativeMapView::render() {
- activate();
-
if (framebufferSizeChanged) {
getContext().viewport = { 0, 0, getFramebufferSize() };
framebufferSizeChanged = false;
}
- updateViewBinding();
map->render(*this);
-
- if(snapshot){
- snapshot = false;
-
- // take snapshot
- auto image = getContext().readFramebuffer<mbgl::PremultipliedImage>(getFramebufferSize());
-
- // encode and convert to jbytes
- std::string string = encodePNG(image);
- jbyteArray arr = env->NewByteArray(string.length());
- env->SetByteArrayRegion(arr,0,string.length(),(jbyte*)string.c_str());
-
- // invoke Mapview#OnSnapshotReady
- env->CallVoidMethod(obj, onSnapshotReadyId, arr);
- if (env->ExceptionCheck()) {
- env->ExceptionDescribe();
- }
- }
-
- if ((display != EGL_NO_DISPLAY) && (surface != EGL_NO_SURFACE)) {
- if (!eglSwapBuffers(display, surface)) {
- mbgl::Log::Error(mbgl::Event::OpenGL, "eglSwapBuffers() returned error %d",
- eglGetError());
- throw std::runtime_error("eglSwapBuffers() failed");
- }
-
- updateFps();
- } else {
- mbgl::Log::Info(mbgl::Event::Android, "Not swapping as we are not ready");
- }
-
- deactivate();
}
mbgl::Map &NativeMapView::getMap() { return *map; }
@@ -224,165 +135,18 @@ mbgl::DefaultFileSource &NativeMapView::getFileSource() { return *fileSource; }
void NativeMapView::initializeDisplay() {
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::initializeDisplay");
-
- assert(display == EGL_NO_DISPLAY);
- assert(config == nullptr);
- assert(format < 0);
-
- display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
- if (display == EGL_NO_DISPLAY) {
- mbgl::Log::Error(mbgl::Event::OpenGL, "eglGetDisplay() returned error %d", eglGetError());
- throw std::runtime_error("eglGetDisplay() failed");
- }
-
- EGLint major, minor;
- if (!eglInitialize(display, &major, &minor)) {
- mbgl::Log::Error(mbgl::Event::OpenGL, "eglInitialize() returned error %d", eglGetError());
- throw std::runtime_error("eglInitialize() failed");
- }
- if ((major <= 1) && (minor < 3)) {
- mbgl::Log::Error(mbgl::Event::OpenGL, "EGL version is too low, need 1.3, got %d.%d", major,
- minor);
- throw std::runtime_error("EGL version is too low");
- }
-
- log_egl_string(display, EGL_VENDOR, "Vendor");
- log_egl_string(display, EGL_VERSION, "Version");
- log_egl_string(display, EGL_CLIENT_APIS, "Client APIs");
- log_egl_string(display, EGL_EXTENSIONS, "Client Extensions");
-
- // Detect if we are in emulator.
- const bool inEmulator = []() {
- char prop[PROP_VALUE_MAX];
- __system_property_get("ro.kernel.qemu", prop);
- return strtol(prop, nullptr, 0) == 1;
- }();
-
- if (inEmulator) {
- // XXX https://code.google.com/p/android/issues/detail?id=78977
- mbgl::Log::Warning(mbgl::Event::Android, "In emulator! Enabling hacks :-(");
- }
-
- if (!eglBindAPI(EGL_OPENGL_ES_API)) {
- mbgl::Log::Error(mbgl::Event::OpenGL, "eglBindAPI(EGL_OPENGL_ES_API) returned error %d", eglGetError());
- throw std::runtime_error("eglBindAPI() failed");
- }
-
- // Get all configs at least RGB 565 with 16 depth and 8 stencil
- EGLint configAttribs[] = {
- EGL_CONFIG_CAVEAT, EGL_NONE,
- EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
- EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
- EGL_BUFFER_SIZE, 16,
- EGL_RED_SIZE, 5,
- EGL_GREEN_SIZE, 6,
- EGL_BLUE_SIZE, 5,
- EGL_DEPTH_SIZE, 16,
- EGL_STENCIL_SIZE, 8,
- (inEmulator ? EGL_NONE : EGL_CONFORMANT), EGL_OPENGL_ES2_BIT,
- (inEmulator ? EGL_NONE : EGL_COLOR_BUFFER_TYPE), EGL_RGB_BUFFER,
- EGL_NONE
- };
-
- EGLint numConfigs;
- if (!eglChooseConfig(display, configAttribs, nullptr, 0, &numConfigs)) {
- mbgl::Log::Error(mbgl::Event::OpenGL, "eglChooseConfig(NULL) returned error %d",
- eglGetError());
- throw std::runtime_error("eglChooseConfig() failed");
- }
- if (numConfigs < 1) {
- mbgl::Log::Error(mbgl::Event::OpenGL, "eglChooseConfig() returned no configs.");
- throw std::runtime_error("eglChooseConfig() failed");
- }
-
- const auto configs = std::make_unique<EGLConfig[]>(numConfigs);
- if (!eglChooseConfig(display, configAttribs, configs.get(), numConfigs, &numConfigs)) {
- mbgl::Log::Error(mbgl::Event::OpenGL, "eglChooseConfig() returned error %d", eglGetError());
- throw std::runtime_error("eglChooseConfig() failed");
- }
-
- config = chooseConfig(configs.get(), numConfigs);
- if (config == nullptr) {
- mbgl::Log::Error(mbgl::Event::OpenGL, "No config chosen");
- throw std::runtime_error("No config chosen");
- }
-
- if (!eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format)) {
- mbgl::Log::Error(mbgl::Event::OpenGL, "eglGetConfigAttrib() returned error %d",
- eglGetError());
- throw std::runtime_error("eglGetConfigAttrib() failed");
- }
- mbgl::Log::Info(mbgl::Event::OpenGL, "Chosen window format is %d", format);
}
void NativeMapView::terminateDisplay() {
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::terminateDisplay");
-
- if (display != EGL_NO_DISPLAY) {
- // Destroy the surface first, if it still exists. This call needs a valid surface.
- if (surface != EGL_NO_SURFACE) {
- if (!eglDestroySurface(display, surface)) {
- mbgl::Log::Error(mbgl::Event::OpenGL, "eglDestroySurface() returned error %d",
- eglGetError());
- throw std::runtime_error("eglDestroySurface() failed");
- }
- surface = EGL_NO_SURFACE;
- }
-
- if (!eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) {
- mbgl::Log::Error(mbgl::Event::OpenGL,
- "eglMakeCurrent(EGL_NO_CONTEXT) returned error %d", eglGetError());
- throw std::runtime_error("eglMakeCurrent() failed");
- }
-
- if (!eglTerminate(display)) {
- mbgl::Log::Error(mbgl::Event::OpenGL, "eglTerminate() returned error %d",
- eglGetError());
- throw std::runtime_error("eglTerminate() failed");
- }
- }
-
- display = EGL_NO_DISPLAY;
- config = nullptr;
- format = -1;
}
void NativeMapView::initializeContext() {
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::initializeContext");
-
- assert(display != EGL_NO_DISPLAY);
- assert(context == EGL_NO_CONTEXT);
- assert(config != nullptr);
-
- const EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
- context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs);
- if (context == EGL_NO_CONTEXT) {
- mbgl::Log::Error(mbgl::Event::OpenGL, "eglCreateContext() returned error %d",
- eglGetError());
- throw std::runtime_error("eglCreateContext() failed");
- }
}
void NativeMapView::terminateContext() {
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::terminateContext");
- if (display != EGL_NO_DISPLAY) {
-
- if (!eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) {
- mbgl::Log::Error(mbgl::Event::OpenGL,
- "eglMakeCurrent(EGL_NO_CONTEXT) returned error %d", eglGetError());
- throw std::runtime_error("eglMakeCurrent() failed");
- }
-
- if (context != EGL_NO_CONTEXT) {
- if (!eglDestroyContext(display, context)) {
- mbgl::Log::Error(mbgl::Event::OpenGL, "eglDestroyContext() returned error %d",
- eglGetError());
- throw std::runtime_error("eglDestroyContext() failed");
- }
- }
- }
-
- context = EGL_NO_CONTEXT;
}
void NativeMapView::createSurface(ANativeWindow *window_) {
@@ -391,54 +155,11 @@ void NativeMapView::createSurface(ANativeWindow *window_) {
assert(window == nullptr);
assert(window_ != nullptr);
window = window_;
-
- assert(display != EGL_NO_DISPLAY);
- assert(surface == EGL_NO_SURFACE);
- assert(config != nullptr);
- assert(format >= 0);
-
- ANativeWindow_setBuffersGeometry(window, 0, 0, format);
-
- const EGLint surfaceAttribs[] = {EGL_NONE};
- surface = eglCreateWindowSurface(display, config, window, surfaceAttribs);
- if (surface == EGL_NO_SURFACE) {
- mbgl::Log::Error(mbgl::Event::OpenGL, "eglCreateWindowSurface() returned error %d",
- eglGetError());
- throw std::runtime_error("eglCreateWindowSurface() failed");
- }
-
- if (!firstTime) {
- firstTime = true;
-
- activate();
-
- if (!eglMakeCurrent(display, surface, surface, context)) {
- mbgl::Log::Error(mbgl::Event::OpenGL, "eglMakeCurrent() returned error %d",
- eglGetError());
- throw std::runtime_error("eglMakeCurrent() failed");
- }
-
- mbgl::gl::InitializeExtensions([] (const char * name) {
- return reinterpret_cast<mbgl::gl::glProc>(eglGetProcAddress(name));
- });
-
- deactivate();
- }
}
void NativeMapView::destroySurface() {
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::destroySurface");
- if (surface != EGL_NO_SURFACE) {
- if (!eglDestroySurface(display, surface)) {
- mbgl::Log::Error(mbgl::Event::OpenGL, "eglDestroySurface() returned error %d",
- eglGetError());
- throw std::runtime_error("eglDestroySurface() failed");
- }
- }
-
- surface = EGL_NO_SURFACE;
-
if (window != nullptr) {
ANativeWindow_release(window);
window = nullptr;
@@ -494,83 +215,6 @@ EGLConfig NativeMapView::chooseConfig(const EGLConfig configs[], EGLint numConfi
EGLint caveat, conformant, bits, red, green, blue, alpha, alphaMask, depth, stencil,
sampleBuffers, samples;
- if (!eglGetConfigAttrib(display, configs[i], EGL_CONFIG_CAVEAT, &caveat)) {
- mbgl::Log::Error(mbgl::Event::OpenGL,
- "eglGetConfigAttrib(EGL_CONFIG_CAVEAT) returned error %d",
- eglGetError());
- throw std::runtime_error("eglGetConfigAttrib() failed");
- }
-
- if (!eglGetConfigAttrib(display, configs[i], EGL_CONFORMANT, &conformant)) {
- mbgl::Log::Error(mbgl::Event::OpenGL,
- "eglGetConfigAttrib(EGL_CONFORMANT) returned error %d", eglGetError());
- throw std::runtime_error("eglGetConfigAttrib() failed");
- }
-
- if (!eglGetConfigAttrib(display, configs[i], EGL_BUFFER_SIZE, &bits)) {
- mbgl::Log::Error(mbgl::Event::OpenGL,
- "eglGetConfigAttrib(EGL_BUFFER_SIZE) returned error %d",
- eglGetError());
- throw std::runtime_error("eglGetConfigAttrib() failed");
- }
-
- if (!eglGetConfigAttrib(display, configs[i], EGL_RED_SIZE, &red)) {
- mbgl::Log::Error(mbgl::Event::OpenGL,
- "eglGetConfigAttrib(EGL_RED_SIZE) returned error %d", eglGetError());
- throw std::runtime_error("eglGetConfigAttrib() failed");
- }
-
- if (!eglGetConfigAttrib(display, configs[i], EGL_GREEN_SIZE, &green)) {
- mbgl::Log::Error(mbgl::Event::OpenGL,
- "eglGetConfigAttrib(EGL_GREEN_SIZE) returned error %d", eglGetError());
- throw std::runtime_error("eglGetConfigAttrib() failed");
- }
-
- if (!eglGetConfigAttrib(display, configs[i], EGL_BLUE_SIZE, &blue)) {
- mbgl::Log::Error(mbgl::Event::OpenGL,
- "eglGetConfigAttrib(EGL_BLUE_SIZE) returned error %d", eglGetError());
- throw std::runtime_error("eglGetConfigAttrib() failed");
- }
-
- if (!eglGetConfigAttrib(display, configs[i], EGL_ALPHA_SIZE, &alpha)) {
- mbgl::Log::Error(mbgl::Event::OpenGL,
- "eglGetConfigAttrib(EGL_ALPHA_SIZE) returned error %d", eglGetError());
- throw std::runtime_error("eglGetConfigAttrib() failed");
- }
-
- if (!eglGetConfigAttrib(display, configs[i], EGL_ALPHA_MASK_SIZE, &alphaMask)) {
- mbgl::Log::Error(mbgl::Event::OpenGL,
- "eglGetConfigAttrib(EGL_ALPHA_MASK_SIZE) returned error %d",
- eglGetError());
- throw std::runtime_error("eglGetConfigAttrib() failed");
- }
-
- if (!eglGetConfigAttrib(display, configs[i], EGL_DEPTH_SIZE, &depth)) {
- mbgl::Log::Error(mbgl::Event::OpenGL,
- "eglGetConfigAttrib(EGL_DEPTH_SIZE) returned error %d", eglGetError());
- throw std::runtime_error("eglGetConfigAttrib() failed");
- }
-
- if (!eglGetConfigAttrib(display, configs[i], EGL_STENCIL_SIZE, &stencil)) {
- mbgl::Log::Error(mbgl::Event::OpenGL,
- "eglGetConfigAttrib(EGL_STENCIL_SIZE) returned error %d",
- eglGetError());
- throw std::runtime_error("eglGetConfigAttrib() failed");
- }
-
- if (!eglGetConfigAttrib(display, configs[i], EGL_SAMPLE_BUFFERS, &sampleBuffers)) {
- mbgl::Log::Error(mbgl::Event::OpenGL,
- "eglGetConfigAttrib(EGL_SAMPLE_BUFFERS) returned error %d",
- eglGetError());
- throw std::runtime_error("eglGetConfigAttrib() failed");
- }
-
- if (!eglGetConfigAttrib(display, configs[i], EGL_SAMPLES, &samples)) {
- mbgl::Log::Error(mbgl::Event::OpenGL,
- "eglGetConfigAttrib(EGL_SAMPLES) returned error %d", eglGetError());
- throw std::runtime_error("eglGetConfigAttrib() failed");
- }
-
mbgl::Log::Info(mbgl::Event::OpenGL, "...Caveat: %d", caveat);
mbgl::Log::Info(mbgl::Event::OpenGL, "...Conformant: %d", conformant);
mbgl::Log::Info(mbgl::Event::OpenGL, "...Color: %d", bits);
@@ -649,14 +293,14 @@ EGLConfig NativeMapView::chooseConfig(const EGLConfig configs[], EGLint numConfi
return configId;
}
-void NativeMapView::notifyMapChange(mbgl::MapChange change) {
- assert(vm != nullptr);
- assert(obj != nullptr);
+void NativeMapView::notifyMapChange(__attribute__((unused)) mbgl::MapChange change) {
+ //assert(change != 99);
+ //assert(obj != nullptr);
- env->CallVoidMethod(obj, onMapChangedId, change);
- if (env->ExceptionCheck()) {
- env->ExceptionDescribe();
- }
+ //env->CallVoidMethod(obj, onMapChangedId, change);
+ //if (env->ExceptionCheck()) {
+ // env->ExceptionDescribe();
+ //}
}
void NativeMapView::enableFps(bool enable) {
diff --git a/platform/android/src/native_map_view.hpp b/platform/android/src/native_map_view.hpp
index 14b9842c72..f5296e9d9c 100755
--- a/platform/android/src/native_map_view.hpp
+++ b/platform/android/src/native_map_view.hpp
@@ -21,7 +21,6 @@ public:
virtual ~NativeMapView();
mbgl::Size getFramebufferSize() const;
- void updateViewBinding();
void bind() override;
void activate() override;
@@ -64,22 +63,9 @@ private:
ANativeWindow *window = nullptr;
- EGLDisplay oldDisplay = EGL_NO_DISPLAY;
- EGLSurface oldReadSurface = EGL_NO_SURFACE;
- EGLSurface oldDrawSurface = EGL_NO_SURFACE;
- EGLContext oldContext = EGL_NO_CONTEXT;
-
- EGLDisplay display = EGL_NO_DISPLAY;
- EGLSurface surface = EGL_NO_SURFACE;
- EGLContext context = EGL_NO_CONTEXT;
-
- EGLConfig config = nullptr;
- EGLint format = -1;
-
std::string styleUrl;
std::string apiKey;
- bool firstTime = false;
bool fpsEnabled = false;
bool snapshot = false;
double fps = 0.0;
@@ -99,7 +85,6 @@ private:
std::unique_ptr<mbgl::Map> map;
mbgl::EdgeInsets insets;
- unsigned active = 0;
};
}
}