diff --git a/android/cpp/NativeMapView.cpp b/android/cpp/NativeMapView.cpp index a3b8c75d3..add3e3bdb 100644 --- a/android/cpp/NativeMapView.cpp +++ b/android/cpp/NativeMapView.cpp @@ -180,6 +180,8 @@ bool NativeMapView::initializeDisplay() { void NativeMapView::terminateDisplay() { LOG_VERBOSE("NativeMapView::terminateDisplay"); + map->terminate(); + if (display != EGL_NO_DISPLAY) { if (!eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) { @@ -281,6 +283,8 @@ bool NativeMapView::createSurface(ANativeWindow* window_) { void NativeMapView::destroySurface() { LOG_VERBOSE("NativeMapView::destroySurface"); + map->terminate(); + if (surface != EGL_NO_SURFACE) { if (!eglDestroySurface(display, surface)) { LOG_ERROR("eglDestroySurface() returned error %d", eglGetError()); @@ -444,7 +448,6 @@ void NativeMapView::stop() { LOG_VERBOSE("NativeMapView::stop"); if ((display != EGL_NO_DISPLAY) && (surface != EGL_NO_SURFACE) && (context != EGL_NO_CONTEXT)) { - // FIXME make_inactive before this so no valid context map->stop(); } } @@ -501,47 +504,32 @@ void MBGLView::make_active() { nativeView->surface, nativeView->context)) { LOG_ERROR("eglMakeCurrent() returned error %d", eglGetError()); } - - // TODO still can't fix the black screen problem :-( - EGLint width, height; - if (!(eglQuerySurface(nativeView->display, nativeView->surface, EGL_WIDTH, &width) - & eglQuerySurface(nativeView->display, nativeView->surface, EGL_HEIGHT, &height))) { - LOG_ERROR("eglQuerySurface() returned error %d", eglGetError()); - } - map->resize(width, height); - } else { LOG_DEBUG("Not activating as we are not ready"); } } void MBGLView::make_inactive() { - // FIXME for testing - /*LOG_VERBOSE("MBGLView::make_inactive"); + LOG_VERBOSE("MBGLView::make_inactive"); if (!eglMakeCurrent(nativeView->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) { LOG_ERROR("eglMakeCurrent(EGL_NO_CONTEXT) returned error %d", eglGetError()); - }*/ + } } void MBGLView::swap() { LOG_VERBOSE("MBGLView::swap"); - // FIXME bug workaround - make_active(); if (map->needsSwap() && (nativeView->display != EGL_NO_DISPLAY) && (nativeView->surface != EGL_NO_SURFACE)) { if (!eglSwapBuffers(nativeView->display, nativeView->surface)) { LOG_ERROR("eglSwapBuffers() returned error %d", eglGetError()); - LOG_ERROR("%u", reinterpret_cast(nativeView->surface)); // TODO remove } map->swapped(); } else { LOG_DEBUG("Not swapping as we are not ready"); } - // FIXME bug workaround - make_inactive(); } void MBGLView::notify() { diff --git a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java index 85b4ef726..3c1910758 100644 --- a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java +++ b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java @@ -361,10 +361,6 @@ public class MapView extends SurfaceView { public void onCreate(Bundle savedInstanceState) { Log.v(TAG, "onCreate"); if (savedInstanceState != null) { - lonlat = (LonLat) savedInstanceState - .getParcelable(STATE_CENTER_COORDINATE); - bearing = savedInstanceState.getDouble(STATE_CENTER_DIRECTION); - zoom = savedInstanceState.getDouble(STATE_ZOOM_LEVEL); setCenterCoordinate((LonLat) savedInstanceState .getParcelable(STATE_CENTER_COORDINATE)); setDirection(savedInstanceState.getDouble(STATE_CENTER_DIRECTION)); @@ -418,28 +414,15 @@ public class MapView extends SurfaceView { // Must be called from Activity onPause public void onPause() { Log.v(TAG, "onPause"); - lonlat = mNativeMapView.getLonLat(); - bearing = mNativeMapView.getBearing(); - zoom = mNativeMapView.getZoom(); mNativeMapView.stop(); } // Called when we need to start the render thread // Must be called from Activity onResume - // TODO need to fix this in Map C++ code - // Seems map state gets reset when we start() - private LonLat lonlat; - private double bearing, zoom; - public void onResume() { Log.v(TAG, "onResume"); mNativeMapView.start(); - if (lonlat != null) { - mNativeMapView.setLonLat(lonlat); - mNativeMapView.setBearing(bearing); - mNativeMapView.setZoom(zoom); - } } // This class handles SurfaceHolder callbacks @@ -460,11 +443,6 @@ public class MapView extends SurfaceView { public void surfaceCreated(SurfaceHolder holder) { Log.v(TAG, "surfaceCreated"); mNativeMapView.createSurface(holder.getSurface()); - if (lonlat != null) { - mNativeMapView.setLonLat(lonlat); - mNativeMapView.setBearing(bearing); - mNativeMapView.setZoom(zoom); - } } // Called when the native surface buffer has been destroyed @@ -484,7 +462,6 @@ public class MapView extends SurfaceView { Log.v(TAG, "surfaceChanged"); Log.i(TAG, "resize " + format + " " + width + " " + height); mNativeMapView.resize(width, height); - // TODO fix bug when rotating - sometimes 1/2 map black } } @@ -515,7 +492,7 @@ public class MapView extends SurfaceView { // Draw events // - // TODO: onDraw for editor? + // TODO: onDraw for UI editor mockup? // By default it just shows a gray screen with "MapView" // Not too important but perhaps we could put a static demo map image there diff --git a/src/map/map.cpp b/src/map/map.cpp index d0a279b64..ab16eff13 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -215,7 +215,9 @@ void Map::cleanup(uv_async_t *async) { } void Map::terminate() { + view.make_active(); painter.terminate(); + view.make_inactive(); } void Map::setReachability(bool reachable) { @@ -239,7 +241,9 @@ void Map::render(uv_async_t *async) { if (map->is_clean.test_and_set() == false) { map->render(); map->is_swapped.clear(); + map->view.make_active(); map->view.swap(); + map->view.make_inactive(); } else { // We set the rendered flag in the test above, so we have to reset it // now that we're not actually rendering because the map is clean. @@ -254,6 +258,9 @@ void Map::terminate(uv_async_t *async) { Map *map = static_cast(async->data); assert(uv_thread_self() == map->map_thread); + // Makre sure we have a GL context + map->view.make_active(); + // Remove all of these to make sure they are destructed in the correct thread. map->glyphStore.reset(); map->fileSource.reset(); @@ -261,6 +268,8 @@ void Map::terminate(uv_async_t *async) { map->workers.reset(); map->activeSources.clear(); + map->view.make_inactive(); + uv_close((uv_handle_t *)map->async_cleanup.get(), nullptr); uv_close((uv_handle_t *)map->async_render.get(), nullptr); uv_close((uv_handle_t *)map->async_terminate.get(), nullptr);