From c542bd114090753f5fc6f55e68605e1fd3bbd070 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Mon, 10 Nov 2014 15:06:56 -0500 Subject: [PATCH 01/14] repair undef None GLX wrapper, pass 0 instead of None to GLX functions --- include/mbgl/platform/default/headless_view.hpp | 2 +- platform/default/headless_display.cpp | 2 +- platform/default/headless_view.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/mbgl/platform/default/headless_view.hpp b/include/mbgl/platform/default/headless_view.hpp index f599dde27..9d8acf70f 100644 --- a/include/mbgl/platform/default/headless_view.hpp +++ b/include/mbgl/platform/default/headless_view.hpp @@ -5,7 +5,7 @@ #define MBGL_USE_CGL 1 #else #define GL_GLEXT_PROTOTYPES -#include +#include #define MBGL_USE_GLX 1 #endif diff --git a/platform/default/headless_display.cpp b/platform/default/headless_display.cpp index 409fcbf05..ada48b864 100644 --- a/platform/default/headless_display.cpp +++ b/platform/default/headless_display.cpp @@ -48,7 +48,7 @@ HeadlessDisplay::HeadlessDisplay() { // We're creating a dummy pbuffer anyway that we're not using. static int pixelFormat[] = { GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, - None + 0 }; int configs = 0; diff --git a/platform/default/headless_view.cpp b/platform/default/headless_view.cpp index 687f3ecf7..1f5a0ec98 100644 --- a/platform/default/headless_view.cpp +++ b/platform/default/headless_view.cpp @@ -107,7 +107,7 @@ GLXContext createCoreProfile(Display *dpy, GLXFBConfig fbconfig) { const int context_flags[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, core_profile_versions[i].major, GLX_CONTEXT_MINOR_VERSION_ARB, core_profile_versions[i].minor, - None + 0 }; ctx = glXCreateContextAttribsARB(dpy, fbconfig, 0, True, context_flags); if (context_creation_failed) { @@ -172,7 +172,7 @@ void HeadlessView::createContext() { int pbuffer_attributes[] = { GLX_PBUFFER_WIDTH, 8, GLX_PBUFFER_HEIGHT, 8, - None + 0 }; glx_pbuffer = glXCreatePbuffer(x_display, fb_configs[0], pbuffer_attributes); #endif From 6109102923469ab9db6374b270f0b07a2c6f1615 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Tue, 11 Nov 2014 22:30:55 +1100 Subject: [PATCH 02/14] Remove left over test logs --- src/map/map.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/map/map.cpp b/src/map/map.cpp index 483ae276e..5a18ac7e7 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -319,7 +319,6 @@ void Map::render(uv_async_t *async) { } void Map::terminate(uv_async_t *async) { - Log::Info(Event::General, "Map::terminate() start"); // Closes all open handles on the loop. This means that the loop will automatically terminate. Map *map = static_cast(async->data); assert(uv_thread_self() == map->map_thread); @@ -334,13 +333,10 @@ void Map::terminate(uv_async_t *async) { map->view.make_inactive(); map->terminating = true; - Log::Info(Event::General, "Map::terminate() set terminating = true"); 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); - - Log::Info(Event::General, "Map::terminate() done"); } #pragma mark - Setup From 6ee24f07d780fe1c16fb41a9e1de67c0a41b2420 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Tue, 11 Nov 2014 22:31:25 +1100 Subject: [PATCH 03/14] Be sure to terminate everything --- android/cpp/NativeMapView.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/android/cpp/NativeMapView.cpp b/android/cpp/NativeMapView.cpp index 3d9a3b89e..00fb11b2b 100644 --- a/android/cpp/NativeMapView.cpp +++ b/android/cpp/NativeMapView.cpp @@ -59,6 +59,8 @@ NativeMapView::NativeMapView(JNIEnv* env, jobject obj_) { NativeMapView::~NativeMapView() { LOG_VERBOSE("NativeMapView::~NativeMapView"); terminateContext(); + terminateSurface(); + terminateDisplay(); delete map; map = nullptr; From 682e9404c43ece4d38f35e199429f63a8c3c6c99 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Tue, 11 Nov 2014 22:32:43 +1100 Subject: [PATCH 04/14] We no longer need to call Map::terminate9 --- android/cpp/NativeMapView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/cpp/NativeMapView.cpp b/android/cpp/NativeMapView.cpp index 00fb11b2b..eadf40c3e 100644 --- a/android/cpp/NativeMapView.cpp +++ b/android/cpp/NativeMapView.cpp @@ -243,7 +243,7 @@ bool NativeMapView::initializeContext() { void NativeMapView::terminateContext() { LOG_VERBOSE("NativeMapView::terminateContext"); - map->terminate(); + //map->terminate(); if (display != EGL_NO_DISPLAY) { if (!eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, From e8139cbcfdef09e735a7f1931537930499aa01b7 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Tue, 11 Nov 2014 22:35:46 +1100 Subject: [PATCH 05/14] Fix function name --- android/cpp/NativeMapView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/cpp/NativeMapView.cpp b/android/cpp/NativeMapView.cpp index eadf40c3e..6e6b4d6c1 100644 --- a/android/cpp/NativeMapView.cpp +++ b/android/cpp/NativeMapView.cpp @@ -59,7 +59,7 @@ NativeMapView::NativeMapView(JNIEnv* env, jobject obj_) { NativeMapView::~NativeMapView() { LOG_VERBOSE("NativeMapView::~NativeMapView"); terminateContext(); - terminateSurface(); + destroySurface(); terminateDisplay(); delete map; From de1f37fa9ee77f1dd7ee535415f1c6876ffe99d9 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Tue, 11 Nov 2014 22:50:37 +1100 Subject: [PATCH 06/14] Change Assetbridge extraction dir to data dir Only extract needed files --- android/cpp/JNI.cpp | 6 ++++-- android/cpp/NativeMapView.hpp | 1 + .../arieslabs/assetbridge/Assetbridge.java | 20 +++++++++++++++---- .../java/com/mapbox/mapboxgl/lib/MapView.java | 7 ++++--- .../mapbox/mapboxgl/lib/NativeMapView.java | 6 +++--- platform/default/http_request_baton_curl.cpp | 2 +- 6 files changed, 29 insertions(+), 13 deletions(-) diff --git a/android/cpp/JNI.cpp b/android/cpp/JNI.cpp index 3b1801c4c..708063f24 100644 --- a/android/cpp/JNI.cpp +++ b/android/cpp/JNI.cpp @@ -21,6 +21,7 @@ namespace mbgl { namespace android { std::string cache_path; +std::string data_path; jmethodID on_map_changed_id = nullptr; @@ -139,9 +140,10 @@ using namespace mbgl::android; // TODO: wrap C++ exceptions? // TODO: wrap other sorts of exceptions? eg coffee catch -jlong JNICALL nativeCreate(JNIEnv* env, jobject obj, jstring cache_path_) { +jlong JNICALL nativeCreate(JNIEnv* env, jobject obj, jstring cache_path_, jstring data_path_) { LOG_VERBOSE("nativeCreate"); cache_path = std_string_from_jstring(env, cache_path_); + data_path = std_string_from_jstring(env, data_path_); NativeMapView* native_map_view = new NativeMapView(env, obj); if (native_map_view == nullptr) { throw_error(env, "Unable to create NativeMapView."); @@ -754,7 +756,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { // NOTE: if you get java.lang.UnsatisfiedLinkError you likely forgot to set the size of the array correctly (too large) std::array methods = {{ // Can remove the extra brace in C++14 - { "nativeCreate", "(Ljava/lang/String;)J", reinterpret_cast(&nativeCreate) }, + { "nativeCreate", "(Ljava/lang/String;Ljava/lang/String;)J", reinterpret_cast(&nativeCreate) }, { "nativeDestroy", "(J)V", reinterpret_cast(&nativeDestroy) }, { "nativeInitializeDisplay", "(J)V", reinterpret_cast(&nativeInitializeDisplay) }, { "nativeTerminateDisplay", "(J)V", reinterpret_cast(&nativeTerminateDisplay) }, diff --git a/android/cpp/NativeMapView.hpp b/android/cpp/NativeMapView.hpp index 5e12084b3..75aba6985 100644 --- a/android/cpp/NativeMapView.hpp +++ b/android/cpp/NativeMapView.hpp @@ -15,6 +15,7 @@ namespace mbgl { namespace android { extern std::string cache_path; +extern std::string data_path; extern jmethodID on_map_changed_id; diff --git a/android/java/lib/src/main/java/com/arieslabs/assetbridge/Assetbridge.java b/android/java/lib/src/main/java/com/arieslabs/assetbridge/Assetbridge.java index 8730cf4ca..f12468dce 100644 --- a/android/java/lib/src/main/java/com/arieslabs/assetbridge/Assetbridge.java +++ b/android/java/lib/src/main/java/com/arieslabs/assetbridge/Assetbridge.java @@ -9,8 +9,12 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; public class Assetbridge { + + private static final String TAG = "Assetbridge"; + /*static { System.loadLibrary("assetbridge"); }*/ @@ -19,16 +23,21 @@ public class Assetbridge { public static void unpack(Context c) { try { - // first let's get the temp directory - String tmpdir = c.getCacheDir().getPath(); + // first let's get the data directory + String datadir = c.getFilesDir().getAbsolutePath(); + Log.v(TAG, "Extracting assets to " + datadir); // now we need the assetmanager AssetManager am = c.getAssets(); - String[] assets = am.list(""); + + // only extract what we need + ArrayList assets = new ArrayList(); + assets.add("ca-bundle.crt"); + assets.add("styles"); // iterate on the files... for(String asset : assets) { - copyAssetFolder(am, asset, tmpdir + "/" + asset); + copyAssetFolder(am, asset, datadir + "/" + asset); } // last, set the ASSETDIR environment variable for the C @@ -44,6 +53,7 @@ public class Assetbridge { public static void copyAssetFolder(AssetManager am, String src, String dest) throws IOException { + Log.v(TAG, "Copying " + src); InputStream srcIS = null; File destfh; @@ -58,6 +68,8 @@ public class Assetbridge { isDir = true; } + Log.v(TAG, src + " was " + (isDir ? "a dir" : "a file")); + // either way, we'll use the dest as a File destfh = new File(dest); 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 ebec3db83..37db7d55f 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 @@ -116,18 +116,19 @@ public class MapView extends SurfaceView { } // Get the cache path - String cachePath = context.getCacheDir().getPath(); + String cachePath = context.getCacheDir().getAbsolutePath(); + String dataPath = context.getFilesDir().getAbsolutePath(); // Extract the asset files Assetbridge.unpack(context); // Load the map style and API key //mStyleUrl = "https://mapbox.github.io/mapbox-gl-styles/styles/bright-v6.json"; - mStyleUrl = "file://" + cachePath + "/styles/styles/bright-v6.json"; + mStyleUrl = "file://" + dataPath + "/styles/styles/bright-v6.json"; mAccessToken = "pk.eyJ1IjoibGpiYWRlIiwiYSI6IlJSQ0FEZ2MifQ.7mE4aOegldh3595AG9dxpQ"; // Create the NativeMapView - mNativeMapView = new NativeMapView(this, cachePath); + mNativeMapView = new NativeMapView(this, cachePath, dataPath); mNativeMapView.setStyleURL(mStyleUrl); mNativeMapView.setAccessToken(mAccessToken); mNativeMapView.setDebug(true); diff --git a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java index 974c408b6..e0e005f66 100644 --- a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java +++ b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java @@ -37,11 +37,11 @@ class NativeMapView { // Constructors // - public NativeMapView(MapView mapView, String cachePath) { + public NativeMapView(MapView mapView, String cachePath, String dataPath) { mMapView = mapView; // Create the NativeMapView - mNativeMapViewPtr = nativeCreate(cachePath); + mNativeMapViewPtr = nativeCreate(cachePath, dataPath); } // @@ -407,7 +407,7 @@ class NativeMapView { super.finalize(); } - private native long nativeCreate(String cachePath); + private native long nativeCreate(String cachePath, String dataPath); private native void nativeDestroy(long nativeMapViewPtr); diff --git a/platform/default/http_request_baton_curl.cpp b/platform/default/http_request_baton_curl.cpp index db057bc1b..5238283fd 100644 --- a/platform/default/http_request_baton_curl.cpp +++ b/platform/default/http_request_baton_curl.cpp @@ -423,7 +423,7 @@ void start_request(void *const ptr) { #ifndef __ANDROID__ std::string ca_path = "ca-bundle.crt"; #else - std::string ca_path = mbgl::android::cache_path + "/ca-bundle.crt"; + std::string ca_path = mbgl::android::data_path + "/ca-bundle.crt"; #endif // Carry on the shared pointer in the private information of the CURL handle. From beb12bada213bda24e183224ad8f115b3548fc03 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Tue, 11 Nov 2014 23:05:30 +1100 Subject: [PATCH 07/14] Missed other Map::terminate() call --- android/cpp/NativeMapView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/cpp/NativeMapView.cpp b/android/cpp/NativeMapView.cpp index 6e6b4d6c1..5644b284d 100644 --- a/android/cpp/NativeMapView.cpp +++ b/android/cpp/NativeMapView.cpp @@ -197,7 +197,7 @@ bool NativeMapView::initializeDisplay() { void NativeMapView::terminateDisplay() { LOG_VERBOSE("NativeMapView::terminateDisplay"); - map->terminate(); + //map->terminate(); if (display != EGL_NO_DISPLAY) { if (!eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, From a1274fbc800e96048baf71225ae2c8e23ffdbf32 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Wed, 12 Nov 2014 08:13:06 +1100 Subject: [PATCH 08/14] Lets no get ahead of ourselves --- android/java/app/src/main/AndroidManifest.xml | 2 +- android/java/lib/src/main/AndroidManifest.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/android/java/app/src/main/AndroidManifest.xml b/android/java/app/src/main/AndroidManifest.xml index b3e55dd97..a227b81f5 100644 --- a/android/java/app/src/main/AndroidManifest.xml +++ b/android/java/app/src/main/AndroidManifest.xml @@ -2,7 +2,7 @@ + android:versionName="0.1" > diff --git a/android/java/lib/src/main/AndroidManifest.xml b/android/java/lib/src/main/AndroidManifest.xml index 4a8844179..16dabf837 100644 --- a/android/java/lib/src/main/AndroidManifest.xml +++ b/android/java/lib/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ + android:versionName="0.1" > From 6b9e3c60ef34c4fed15d8c74c9c8688d54961286 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Wed, 12 Nov 2014 21:17:24 +1100 Subject: [PATCH 09/14] Renamed source files using mapbox style Move headers to mbgl/android Tidy up headers and includes --- android/cpp/{JNI.cpp => jni.cpp} | 7 ++-- ...{NativeMapView.cpp => native_map_view.cpp} | 9 +++-- android/mapboxgl-app.gyp | 4 +- include/mbgl/android/jni.hpp | 37 +++++++++++++++++ .../cpp/log.h => include/mbgl/android/log.hpp | 6 +-- .../mbgl/android/native_map_view.hpp | 40 +++---------------- platform/android/cache_database_data.cpp | 2 +- platform/default/http_request_baton_curl.cpp | 4 +- 8 files changed, 61 insertions(+), 48 deletions(-) rename android/cpp/{JNI.cpp => jni.cpp} (99%) rename android/cpp/{NativeMapView.cpp => native_map_view.cpp} (99%) create mode 100644 include/mbgl/android/jni.hpp rename android/cpp/log.h => include/mbgl/android/log.hpp (94%) rename android/cpp/NativeMapView.hpp => include/mbgl/android/native_map_view.hpp (68%) diff --git a/android/cpp/JNI.cpp b/android/cpp/jni.cpp similarity index 99% rename from android/cpp/JNI.cpp rename to android/cpp/jni.cpp index 708063f24..45b8f7fd2 100644 --- a/android/cpp/JNI.cpp +++ b/android/cpp/jni.cpp @@ -11,9 +11,10 @@ #include -#include "log.h" - -#include "NativeMapView.hpp" +#include +#include +#include +#include #pragma clang diagnostic ignored "-Wunused-parameter" diff --git a/android/cpp/NativeMapView.cpp b/android/cpp/native_map_view.cpp similarity index 99% rename from android/cpp/NativeMapView.cpp rename to android/cpp/native_map_view.cpp index 5644b284d..ab06275f0 100644 --- a/android/cpp/NativeMapView.cpp +++ b/android/cpp/native_map_view.cpp @@ -5,12 +5,13 @@ #include +#include +#include + +#include #include #include - -#include "log.h" - -#include "NativeMapView.hpp" +#include namespace mbgl { namespace android { diff --git a/android/mapboxgl-app.gyp b/android/mapboxgl-app.gyp index ac8937fb3..118669542 100644 --- a/android/mapboxgl-app.gyp +++ b/android/mapboxgl-app.gyp @@ -8,8 +8,8 @@ 'product_name': 'mapbox-gl', 'type': 'shared_library', 'sources': [ - './cpp/NativeMapView.cpp', - './cpp/JNI.cpp', + './cpp/native_map_view.cpp', + './cpp/jni.cpp', ], 'cflags_cc': [ '-I<(boost_root)/include', diff --git a/include/mbgl/android/jni.hpp b/include/mbgl/android/jni.hpp new file mode 100644 index 000000000..c1af07c64 --- /dev/null +++ b/include/mbgl/android/jni.hpp @@ -0,0 +1,37 @@ +#ifndef MBGL_ANDROID_JNI +#define MBGL_ANDROID_JNI + +#include +#include + +namespace mbgl { +namespace android { + +extern std::string cache_path; +extern std::string data_path; + +extern jmethodID on_map_changed_id; + +extern jclass lon_lat_class; +extern jmethodID lon_lat_constructor_id; +extern jfieldID lon_lat_lon_id; +extern jfieldID lon_lat_lat_id; + +extern jclass lon_lat_zoom_class; +extern jmethodID lon_lat_zoom_constructor_id; +extern jfieldID lon_lat_zoom_lon_id; +extern jfieldID lon_lat_zoom_lat_id; +extern jfieldID lon_lat_zoom_zoom_id; + +extern jclass runtime_exception_class; + +extern jmethodID list_to_array_id; + +extern jclass array_list_class; +extern jmethodID array_list_constructor_id; +extern jmethodID array_list_add_id; + +} +} + +#endif diff --git a/android/cpp/log.h b/include/mbgl/android/log.hpp similarity index 94% rename from android/cpp/log.h rename to include/mbgl/android/log.hpp index 3cf203853..50b6bec1e 100644 --- a/android/cpp/log.h +++ b/include/mbgl/android/log.hpp @@ -1,5 +1,5 @@ -#ifndef LOG_H -#define LOG_H +#ifndef MBGL_ANDROID_LOG +#define MBGL_ANDROID_LOG #include @@ -22,4 +22,4 @@ #define LOG_WARN(fmt, args...) __android_log_print(ANDROID_LOG_WARN, __FILE__ ":" S__LINE__, fmt, ##args) #define LOG_ERROR(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, __FILE__ ":" S__LINE__, fmt, ##args) -#endif // LOG_H +#endif diff --git a/android/cpp/NativeMapView.hpp b/include/mbgl/android/native_map_view.hpp similarity index 68% rename from android/cpp/NativeMapView.hpp rename to include/mbgl/android/native_map_view.hpp index 75aba6985..04949abe1 100644 --- a/android/cpp/NativeMapView.hpp +++ b/include/mbgl/android/native_map_view.hpp @@ -1,43 +1,15 @@ -#ifndef MAP_VIEW_HPP -#define MAP_VIEW_HPP +#ifndef MBGL_ANDROID_NATIVE_MAP_VIEW +#define MBGL_ANDROID_NATIVE_MAP_VIEW +#include #include - #include - #include - #include -#include - namespace mbgl { namespace android { -extern std::string cache_path; -extern std::string data_path; - -extern jmethodID on_map_changed_id; - -extern jclass lon_lat_class; -extern jmethodID lon_lat_constructor_id; -extern jfieldID lon_lat_lon_id; -extern jfieldID lon_lat_lat_id; - -extern jclass lon_lat_zoom_class; -extern jmethodID lon_lat_zoom_constructor_id; -extern jfieldID lon_lat_zoom_lon_id; -extern jfieldID lon_lat_zoom_lat_id; -extern jfieldID lon_lat_zoom_zoom_id; - -extern jclass runtime_exception_class; - -extern jmethodID list_to_array_id; - -extern jclass array_list_class; -extern jmethodID array_list_constructor_id; -extern jmethodID array_list_add_id; - class MBGLView; class NativeMapView { @@ -116,7 +88,7 @@ private: NativeMapView* nativeView = nullptr; }; -} // namespace android -} // namespace mbgl +} +} -#endif // MAP_VIEW_HPP +#endif diff --git a/platform/android/cache_database_data.cpp b/platform/android/cache_database_data.cpp index 61c4efc15..5f13a44f6 100644 --- a/platform/android/cache_database_data.cpp +++ b/platform/android/cache_database_data.cpp @@ -1,5 +1,5 @@ #include -#include "../../android/cpp/NativeMapView.hpp" +#include namespace mbgl { namespace platform { diff --git a/platform/default/http_request_baton_curl.cpp b/platform/default/http_request_baton_curl.cpp index 5238283fd..a88b949e0 100644 --- a/platform/default/http_request_baton_curl.cpp +++ b/platform/default/http_request_baton_curl.cpp @@ -1,8 +1,10 @@ +#include #include #include #include + #ifdef __ANDROID__ - #include "../../android/cpp/NativeMapView.hpp" + #include #endif #include From 49da2c2fa5e6419df383b3358e63f2efcc939119 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Wed, 12 Nov 2014 22:00:44 +1100 Subject: [PATCH 10/14] Tidy code up more --- android/cpp/jni.cpp | 99 +++++++++--------- android/cpp/native_map_view.cpp | 127 ++++++++++------------- include/mbgl/android/native_map_view.hpp | 50 ++++----- 3 files changed, 131 insertions(+), 145 deletions(-) diff --git a/android/cpp/jni.cpp b/android/cpp/jni.cpp index 45b8f7fd2..8b3780811 100644 --- a/android/cpp/jni.cpp +++ b/android/cpp/jni.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #pragma clang diagnostic ignored "-Wunused-parameter" @@ -242,49 +243,49 @@ void JNICALL nativeRun(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeRun"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->run(); + native_map_view->getMap().run(); } void JNICALL nativeRerender(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeRerender"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->rerender(); + native_map_view->getMap().rerender(); } void JNICALL nativeUpdate(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeUpdate"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->update(); + native_map_view->getMap().update(); } void JNICALL nativeCleanup(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeCleanup"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->cleanup(); + native_map_view->getMap().cleanup(); } void JNICALL nativeTerminate(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeTerminate"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->terminate(); + native_map_view->getMap().terminate(); } jboolean JNICALL nativeNeedsSwap(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeNeedsSwap"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - return native_map_view->getMap()->needsSwap(); + return native_map_view->getMap().needsSwap(); } void JNICALL nativeSwapped(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeSwapped"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->swapped(); + native_map_view->getMap().swapped(); } void JNICALL nativeResize(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jint width, jint height, jfloat ratio) { @@ -295,7 +296,7 @@ void JNICALL nativeResize(JNIEnv* env, jobject obj, jlong native_map_view_ptr, j LOG_ASSERT(width <= UINT16_MAX); LOG_ASSERT(height <= UINT16_MAX); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->resize(width, height, ratio); + native_map_view->getMap().resize(width, height, ratio); } void JNICALL nativeResize(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jint width, jint height, jfloat ratio, jint fb_width, jint fb_height) { @@ -310,21 +311,21 @@ void JNICALL nativeResize(JNIEnv* env, jobject obj, jlong native_map_view_ptr, j LOG_ASSERT(fb_width <= UINT16_MAX); LOG_ASSERT(fb_height <= UINT16_MAX); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->resize(width, height, ratio, fb_width, fb_height); + native_map_view->getMap().resize(width, height, ratio, fb_width, fb_height); } void JNICALL nativeSetAppliedClasses(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jobject classes) { LOG_VERBOSE("nativeSetAppliedClasses"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->setAppliedClasses(std_vector_string_from_jobject(env, classes)); + native_map_view->getMap().setAppliedClasses(std_vector_string_from_jobject(env, classes)); } jobject JNICALL nativeGetAppliedClasses(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeGetAppliedClasses"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - return std_vector_string_to_jobject(env, native_map_view->getMap()->getAppliedClasses()); + return std_vector_string_to_jobject(env, native_map_view->getMap().getAppliedClasses()); } void JNICALL nativeSetDefaultTransitionDuration(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jlong duration_milliseconds) { @@ -333,56 +334,56 @@ void JNICALL nativeSetDefaultTransitionDuration(JNIEnv* env, jobject obj, jlong LOG_ASSERT(duration_milliseconds >= 0); //LOG_ASSERT(duration_milliseconds <= UINT64_MAX); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->setDefaultTransitionDuration(duration_milliseconds); + native_map_view->getMap().setDefaultTransitionDuration(duration_milliseconds); } void JNICALL nativeSetStyleURL(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jstring url) { LOG_VERBOSE("nativeSetStyleURL"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->setStyleURL(std_string_from_jstring(env, url)); + native_map_view->getMap().setStyleURL(std_string_from_jstring(env, url)); } void JNICALL nativeSetStyleJSON(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jstring new_style_json, jstring base) { LOG_VERBOSE("nativeSetStyleJSON"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->setStyleJSON(std_string_from_jstring(env, new_style_json), std_string_from_jstring(env, base)); + native_map_view->getMap().setStyleJSON(std_string_from_jstring(env, new_style_json), std_string_from_jstring(env, base)); } jstring JNICALL nativeGetStyleJSON(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeGetStyleJSON"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - return std_string_to_jstring(env, native_map_view->getMap()->getStyleJSON()); + return std_string_to_jstring(env, native_map_view->getMap().getStyleJSON()); } void JNICALL nativeSetAccessToken(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jstring access_token) { LOG_VERBOSE("nativeSetAccessToken"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->setAccessToken(std_string_from_jstring(env, access_token)); + native_map_view->getMap().setAccessToken(std_string_from_jstring(env, access_token)); } jstring JNICALL nativeGetAccessToken(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeGetAccessToken"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - return std_string_to_jstring(env, native_map_view->getMap()->getAccessToken()); + return std_string_to_jstring(env, native_map_view->getMap().getAccessToken()); } void JNICALL nativeCancelTransitions(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeCancelTransitions"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->cancelTransitions(); + native_map_view->getMap().cancelTransitions(); } void JNICALL nativeMoveBy(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jdouble dx, jdouble dy, jdouble duration) { LOG_VERBOSE("nativeMoveBy"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->moveBy(dx, dy, duration); + native_map_view->getMap().moveBy(dx, dy, duration); } void JNICALL nativeSetLonLat(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jobject lon_lat, jdouble duration) { @@ -404,7 +405,7 @@ void JNICALL nativeSetLonLat(JNIEnv* env, jobject obj, jlong native_map_view_ptr // TODO remove when fixed LOG_DEBUG("lon lat %f %f", lon, lat); - native_map_view->getMap()->setLonLat(lon, lat, duration); + native_map_view->getMap().setLonLat(lon, lat, duration); } jobject JNICALL nativeGetLonLat(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { @@ -412,7 +413,7 @@ jobject JNICALL nativeGetLonLat(JNIEnv* env, jobject obj, jlong native_map_view_ LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); double lon, lat; - native_map_view->getMap()->getLonLat(lon, lat); + native_map_view->getMap().getLonLat(lon, lat); jobject ret = env->NewObject(lon_lat_class, lon_lat_constructor_id, lon, lat); if (ret == nullptr) { @@ -427,56 +428,56 @@ void JNICALL nativeStartPanning(JNIEnv* env, jobject obj, jlong native_map_view_ LOG_VERBOSE("nativeStartPanning"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->startPanning(); + native_map_view->getMap().startPanning(); } void JNICALL nativeStopPanning(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeStopPanning"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->stopPanning(); + native_map_view->getMap().stopPanning(); } void JNICALL nativeResetPosition(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeResetPosition"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->resetPosition(); + native_map_view->getMap().resetPosition(); } void JNICALL nativeScaleBy(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jdouble ds, jdouble cx, jdouble cy, jdouble duration) { LOG_VERBOSE("nativeScaleBy"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->scaleBy(ds, cx, cy, duration); + native_map_view->getMap().scaleBy(ds, cx, cy, duration); } void JNICALL nativeSetScale(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jdouble scale, jdouble cx, jdouble cy, jdouble duration) { LOG_VERBOSE("nativeSetScale"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->setScale(scale, cx, cy, duration); + native_map_view->getMap().setScale(scale, cx, cy, duration); } jdouble JNICALL nativeGetScale(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeGetScale"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - return native_map_view->getMap()->getScale(); + return native_map_view->getMap().getScale(); } void JNICALL nativeSetZoom(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jdouble zoom, jdouble duration) { LOG_VERBOSE("nativeSetZoom"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->setZoom(zoom, duration); + native_map_view->getMap().setZoom(zoom, duration); } jdouble JNICALL nativeGetZoom(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeGetZoom"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - return native_map_view->getMap()->getZoom(); + return native_map_view->getMap().getZoom(); } void JNICALL nativeSetLonLatZoom(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jobject lon_lat_zoom, jdouble duration) { @@ -502,7 +503,7 @@ void JNICALL nativeSetLonLatZoom(JNIEnv* env, jobject obj, jlong native_map_view return; } - native_map_view->getMap()->setLonLatZoom(lon, lat, zoom, duration); + native_map_view->getMap().setLonLatZoom(lon, lat, zoom, duration); } jobject JNICALL nativeGetLonLatZoom(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { @@ -510,7 +511,7 @@ jobject JNICALL nativeGetLonLatZoom(JNIEnv* env, jobject obj, jlong native_map_v LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); double lon, lat, zoom; - native_map_view->getMap()->getLonLatZoom(lon, lat, zoom); + native_map_view->getMap().getLonLatZoom(lon, lat, zoom); jobject ret = env->NewObject(lon_lat_zoom_class, lon_lat_zoom_constructor_id, lon, lat, zoom); if (ret == nullptr) { @@ -525,119 +526,119 @@ void JNICALL nativeResetZoom(JNIEnv* env, jobject obj, jlong native_map_view_ptr LOG_VERBOSE("nativeResetZoom"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->resetZoom(); + native_map_view->getMap().resetZoom(); } void JNICALL nativeStartScaling(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeStartScaling"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->startScaling(); + native_map_view->getMap().startScaling(); } void JNICALL nativeStopScaling(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeStopScaling"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->stopScaling(); + native_map_view->getMap().stopScaling(); } jdouble JNICALL nativeGetMinZoom(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeGetMinZoom"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - return native_map_view->getMap()->getMinZoom(); + return native_map_view->getMap().getMinZoom(); } jdouble JNICALL nativeGetMaxZoom(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeGetMaxZoom"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - return native_map_view->getMap()->getMaxZoom(); + return native_map_view->getMap().getMaxZoom(); } void JNICALL nativeRotateBy(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jdouble sx, jdouble sy, jdouble ex, jdouble ey, jdouble duration) { LOG_VERBOSE("nativeRotateBy"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->rotateBy(sx, sy, ex, ey, duration); + native_map_view->getMap().rotateBy(sx, sy, ex, ey, duration); } void JNICALL nativeSetBearing(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jdouble degrees, jdouble duration) { LOG_VERBOSE("nativeSetBearing"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->setBearing(degrees, duration); + native_map_view->getMap().setBearing(degrees, duration); } void JNICALL nativeSetBearing(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jdouble degrees, jdouble cx, jdouble cy) { LOG_VERBOSE("nativeSetBearing"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->setBearing(degrees, cx, cy); + native_map_view->getMap().setBearing(degrees, cx, cy); } jdouble JNICALL nativeGetBearing(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeGetBearing"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - return native_map_view->getMap()->getBearing(); + return native_map_view->getMap().getBearing(); } void JNICALL nativeResetNorth(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeResetNorth"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->resetNorth(); + native_map_view->getMap().resetNorth(); } void JNICALL nativeStartRotating(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeStartRotating"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->startRotating(); + native_map_view->getMap().startRotating(); } void JNICALL nativeStopRotating(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeStopRotating"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->stopRotating(); + native_map_view->getMap().stopRotating(); } jboolean JNICALL nativeCanRotate(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeCanRotate"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - return native_map_view->getMap()->canRotate(); + return native_map_view->getMap().canRotate(); } void JNICALL nativeSetDebug(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jboolean debug) { LOG_VERBOSE("nativeSetDebug"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->setDebug(debug); + native_map_view->getMap().setDebug(debug); } void JNICALL nativeToggleDebug(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeToggleDebug"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->toggleDebug(); + native_map_view->getMap().toggleDebug(); } jboolean JNICALL nativeGetDebug(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeGetDebug"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - return native_map_view->getMap()->getDebug(); + return native_map_view->getMap().getDebug(); } void JNICALL nativeSetReachability(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jboolean status) { LOG_VERBOSE("nativeSetReachability"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - native_map_view->getMap()->setReachability(status); + native_map_view->getMap().setReachability(status); } } // namespace @@ -645,6 +646,8 @@ void JNICALL nativeSetReachability(JNIEnv* env, jobject obj, jlong native_map_vi extern "C" { extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { + mbgl::Log::Set(); + LOG_VERBOSE("JNI_OnLoad"); JNIEnv* env = nullptr; diff --git a/android/cpp/native_map_view.cpp b/android/cpp/native_map_view.cpp index ab06275f0..f976d7d96 100644 --- a/android/cpp/native_map_view.cpp +++ b/android/cpp/native_map_view.cpp @@ -8,9 +8,7 @@ #include #include -#include #include -#include #include namespace mbgl { @@ -34,7 +32,55 @@ void log_gl_string(GLenum name, const char* label) { } } -NativeMapView::NativeMapView(JNIEnv* env, jobject obj_) { + +void MBGLView::make_active() { + LOG_VERBOSE("MBGLView::make_active"); + if ((nativeView.display != EGL_NO_DISPLAY) + && (nativeView.surface != EGL_NO_SURFACE) + && (nativeView.context != EGL_NO_CONTEXT)) { + if (!eglMakeCurrent(nativeView.display, nativeView.surface, + nativeView.surface, nativeView.context)) { + LOG_ERROR("eglMakeCurrent() returned error %d", eglGetError()); + } + } else { + LOG_DEBUG("Not activating as we are not ready"); + } +} + +void 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"); + + 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()); + } + map->swapped(); + } else { + LOG_DEBUG("Not swapping as we are not ready"); + } +} + +void MBGLView::notify() { + LOG_VERBOSE("MBGLView::notify()"); + // noop +} + +void MBGLView::notify_map_change(mbgl::MapChange /* change */, mbgl::timestamp /* delay */) { + LOG_VERBOSE("MBGLView::notify_map_change()"); + nativeView.notifyMapChange(); +} + +NativeMapView::NativeMapView(JNIEnv* env, jobject obj_) : map(view), view(*this) { LOG_VERBOSE("NativeMapView::NativeMapView"); LOG_ASSERT(env != nullptr); @@ -50,11 +96,6 @@ NativeMapView::NativeMapView(JNIEnv* env, jobject obj_) { env->ExceptionDescribe(); return; } - - mbgl::Log::Set(); - - view = new MBGLView(this); - map = new mbgl::Map(*view); } NativeMapView::~NativeMapView() { @@ -63,12 +104,6 @@ NativeMapView::~NativeMapView() { destroySurface(); terminateDisplay(); - delete map; - map = nullptr; - - delete view; - view = nullptr; - LOG_ASSERT(vm != nullptr); LOG_ASSERT(obj != nullptr); @@ -168,8 +203,8 @@ bool NativeMapView::initializeDisplay() { } } - // TODO make_unique missing in Android NDK? -// const std::unique_ptr configs = std::make_unique(new EGLConfig[num_configs]); + // TODO: make_unique is missing in Android NDK? + // const std::unique_ptr configs = std::make_unique(new EGLConfig[num_configs]); const std::unique_ptr configs(new EGLConfig[num_configs]); if (!eglChooseConfig(display, config_attribs, configs.get(), num_configs, &num_configs)) { @@ -198,8 +233,6 @@ 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)) { @@ -244,8 +277,6 @@ bool NativeMapView::initializeContext() { void NativeMapView::terminateContext() { LOG_VERBOSE("NativeMapView::terminateContext"); - //map->terminate(); - if (display != EGL_NO_DISPLAY) { if (!eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) { @@ -480,7 +511,7 @@ void NativeMapView::start() { LOG_ASSERT(display != EGL_NO_DISPLAY); LOG_ASSERT(context != EGL_NO_CONTEXT); - map->start(true); + map.start(true); } void NativeMapView::loadExtensions() { @@ -515,7 +546,7 @@ void NativeMapView::stop() { LOG_ASSERT(display != EGL_NO_DISPLAY); LOG_ASSERT(context != EGL_NO_CONTEXT); - map->stop(); + map.stop(); } @@ -525,7 +556,7 @@ void NativeMapView::pause(bool wait_for_pause) { LOG_ASSERT(display != EGL_NO_DISPLAY); LOG_ASSERT(context != EGL_NO_CONTEXT); - map->pause(wait_for_pause); + map.pause(wait_for_pause); } void NativeMapView::resume() { @@ -535,7 +566,7 @@ void NativeMapView::resume() { LOG_ASSERT(context != EGL_NO_CONTEXT); if (surface != EGL_NO_SURFACE) { - map->resume(); + map.resume(); } else { LOG_DEBUG("Not resuming because we are not ready"); } @@ -553,7 +584,6 @@ void NativeMapView::notifyMapChange() { NULL }; - // TODO do this only once per thread? jint ret; JNIEnv* env = nullptr; bool detach = false; @@ -584,52 +614,5 @@ void NativeMapView::notifyMapChange() { env = nullptr; } -void MBGLView::make_active() { - LOG_VERBOSE("MBGLView::make_active"); - if ((nativeView->display != EGL_NO_DISPLAY) - && (nativeView->surface != EGL_NO_SURFACE) - && (nativeView->context != EGL_NO_CONTEXT)) { - if (!eglMakeCurrent(nativeView->display, nativeView->surface, - nativeView->surface, nativeView->context)) { - LOG_ERROR("eglMakeCurrent() returned error %d", eglGetError()); - } - } else { - LOG_DEBUG("Not activating as we are not ready"); - } } - -void 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"); - - 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()); - } - map->swapped(); - } else { - LOG_DEBUG("Not swapping as we are not ready"); - } -} - -void MBGLView::notify() { - LOG_VERBOSE("MBGLView::notify()"); - // noop -} - -void MBGLView::notify_map_change(mbgl::MapChange /* change */, mbgl::timestamp /* delay */) { - LOG_VERBOSE("MBGLView::notify_map_change()"); - nativeView->notifyMapChange(); -} - -} // namespace android -} // namespace mbgl diff --git a/include/mbgl/android/native_map_view.hpp b/include/mbgl/android/native_map_view.hpp index 04949abe1..e2daab939 100644 --- a/include/mbgl/android/native_map_view.hpp +++ b/include/mbgl/android/native_map_view.hpp @@ -1,7 +1,9 @@ #ifndef MBGL_ANDROID_NATIVE_MAP_VIEW #define MBGL_ANDROID_NATIVE_MAP_VIEW +#include #include +#include #include #include #include @@ -10,16 +12,34 @@ namespace mbgl { namespace android { -class MBGLView; +class NativeMapView; -class NativeMapView { +class MBGLView: public mbgl::View, private mbgl::util::noncopyable { +public: + explicit MBGLView(NativeMapView& nativeView_) : + nativeView(nativeView_) { + } + + void make_active() override; + void make_inactive() override; + + void swap() override; + + void notify() override; + void notify_map_change(mbgl::MapChange change, mbgl::timestamp delay = 0) override; + +private: + NativeMapView& nativeView; +}; + +class NativeMapView : private mbgl::util::noncopyable { friend class MBGLView; public: NativeMapView(JNIEnv* env, jobject obj); ~NativeMapView(); - mbgl::Map* getMap() const { + mbgl::Map& getMap() { return map; } @@ -52,8 +72,8 @@ private: ANativeWindow* window = nullptr; - mbgl::Map* map = nullptr; - MBGLView* view = nullptr; + mbgl::Map map; + MBGLView view; EGLDisplay display = EGL_NO_DISPLAY; EGLSurface surface = EGL_NO_SURFACE; @@ -68,26 +88,6 @@ private: bool first_time = false; }; -class MBGLView: public mbgl::View { -public: - MBGLView(NativeMapView* nativeView_) : - nativeView(nativeView_) { - } - virtual ~MBGLView() { - } - - void make_active() override; - void make_inactive() override; - - void swap() override; - - void notify() override; - void notify_map_change(mbgl::MapChange change, mbgl::timestamp delay = 0) override; - -private: - NativeMapView* nativeView = nullptr; -}; - } } From 11061ee5da02650e36abbc4f558446db793d3df2 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Wed, 12 Nov 2014 22:01:32 +1100 Subject: [PATCH 11/14] Add noncopyable --- include/mbgl/platform/default/glfw_view.hpp | 3 ++- include/mbgl/platform/default/headless_display.hpp | 3 ++- include/mbgl/platform/default/headless_view.hpp | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/mbgl/platform/default/glfw_view.hpp b/include/mbgl/platform/default/glfw_view.hpp index 6e91c1125..c63b205a4 100644 --- a/include/mbgl/platform/default/glfw_view.hpp +++ b/include/mbgl/platform/default/glfw_view.hpp @@ -3,13 +3,14 @@ #include #include +#include #ifdef NVIDIA #define GLFW_INCLUDE_ES2 #endif #include -class GLFWView : public mbgl::View { +class GLFWView : public mbgl::View, private mbgl::util::noncopyable { public: GLFWView(bool fullscreen = false); ~GLFWView(); diff --git a/include/mbgl/platform/default/headless_display.hpp b/include/mbgl/platform/default/headless_display.hpp index 5b33fd699..cd6cb4f75 100644 --- a/include/mbgl/platform/default/headless_display.hpp +++ b/include/mbgl/platform/default/headless_display.hpp @@ -1,11 +1,12 @@ #ifndef MBGL_COMMON_HEADLESS_DISPLAY #define MBGL_COMMON_HEADLESS_DISPLAY +#include #include "headless_view.hpp" namespace mbgl { -class HeadlessDisplay { +class HeadlessDisplay, private mbgl::util::noncopyable { public: HeadlessDisplay(); ~HeadlessDisplay(); diff --git a/include/mbgl/platform/default/headless_view.hpp b/include/mbgl/platform/default/headless_view.hpp index f599dde27..0a058552e 100644 --- a/include/mbgl/platform/default/headless_view.hpp +++ b/include/mbgl/platform/default/headless_view.hpp @@ -9,6 +9,7 @@ #define MBGL_USE_GLX 1 #endif +#include #include #include @@ -18,7 +19,7 @@ namespace mbgl { class HeadlessDisplay; -class HeadlessView : public View { +class HeadlessView : public View, private util::noncopyable { public: HeadlessView(); HeadlessView(std::shared_ptr display); From 82908c99f779c4d5771b4eb315b2283db4c1f046 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Wed, 12 Nov 2014 22:03:27 +1100 Subject: [PATCH 12/14] More tidy up --- android/cpp/jni.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/android/cpp/jni.cpp b/android/cpp/jni.cpp index 8b3780811..82b78f817 100644 --- a/android/cpp/jni.cpp +++ b/android/cpp/jni.cpp @@ -132,16 +132,13 @@ jobject std_vector_string_to_jobject(JNIEnv* env, std::vector vecto return jlist; } -} // namespace android -} // namespace mbgl +} +} namespace { using namespace mbgl::android; -// TODO: wrap C++ exceptions? -// TODO: wrap other sorts of exceptions? eg coffee catch - jlong JNICALL nativeCreate(JNIEnv* env, jobject obj, jstring cache_path_, jstring data_path_) { LOG_VERBOSE("nativeCreate"); cache_path = std_string_from_jstring(env, cache_path_); @@ -332,7 +329,6 @@ void JNICALL nativeSetDefaultTransitionDuration(JNIEnv* env, jobject obj, jlong LOG_VERBOSE("nativeSetDefaultTransitionDuration"); LOG_ASSERT(native_map_view_ptr != 0); LOG_ASSERT(duration_milliseconds >= 0); - //LOG_ASSERT(duration_milliseconds <= UINT64_MAX); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); native_map_view->getMap().setDefaultTransitionDuration(duration_milliseconds); } @@ -403,8 +399,6 @@ void JNICALL nativeSetLonLat(JNIEnv* env, jobject obj, jlong native_map_view_ptr return; } - // TODO remove when fixed - LOG_DEBUG("lon lat %f %f", lon, lat); native_map_view->getMap().setLonLat(lon, lat, duration); } @@ -641,7 +635,7 @@ void JNICALL nativeSetReachability(JNIEnv* env, jobject obj, jlong native_map_vi native_map_view->getMap().setReachability(status); } -} // namespace +} extern "C" { @@ -895,4 +889,4 @@ extern "C" JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) { array_list_add_id = nullptr; } -} // extern "C" +} From 27cf24171a014b63e139e7fc77422753beac44e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Wed, 12 Nov 2014 12:12:01 +0100 Subject: [PATCH 13/14] check library versions against header symbols in static initialization function fixes #580 --- platform/default/http_request_baton_curl.cpp | 15 ++++++ platform/default/image.cpp | 14 +++++ src/map/map.cpp | 55 ++++++++++++++++++++ 3 files changed, 84 insertions(+) diff --git a/platform/default/http_request_baton_curl.cpp b/platform/default/http_request_baton_curl.cpp index b8b4bac5f..02e9497c9 100644 --- a/platform/default/http_request_baton_curl.cpp +++ b/platform/default/http_request_baton_curl.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -9,6 +10,20 @@ #include #include + +// Check curl library version. +const static bool curl_version_check = []() { + const auto version = curl_version_info(CURLVERSION_NOW); + if (version->version_num != LIBCURL_VERSION_NUM) { + throw std::runtime_error(mbgl::util::sprintf<96>( + "libcurl version mismatch: headers report %d.%d.%d, but library reports %d.%d.%d", + (LIBCURL_VERSION_NUM >> 16) & 0xFF, (LIBCURL_VERSION_NUM >> 8) & 0xFF, LIBCURL_VERSION_NUM & 0xFF, + (version->version_num >> 16) & 0xFF, (version->version_num >> 8) & 0xFF, version->version_num & 0xFF)); + } + return true; +}(); + + // This file contains code from http://curl.haxx.se/libcurl/c/multi-uv.html: /*************************************************************************** diff --git a/platform/default/image.cpp b/platform/default/image.cpp index 68d178691..bf119fee0 100644 --- a/platform/default/image.cpp +++ b/platform/default/image.cpp @@ -1,4 +1,5 @@ #include +#include #include @@ -8,6 +9,19 @@ #include +// Check png library version. +const static bool png_version_check = []() { + const png_uint_32 version = png_access_version_number(); + if (version != PNG_LIBPNG_VER) { + throw std::runtime_error(mbgl::util::sprintf<96>( + "libpng version mismatch: headers report %d.%d.%d, but library reports %d.%d.%d", + PNG_LIBPNG_VER / 10000, (PNG_LIBPNG_VER / 100) % 100, PNG_LIBPNG_VER % 100, + version / 10000, (version / 100) % 100, version % 100)); + } + return true; +}(); + + namespace mbgl { namespace util { diff --git a/src/map/map.cpp b/src/map/map.cpp index d0a279b64..6e9e47fd5 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -28,6 +29,60 @@ #define _USE_MATH_DEFINES #include +#include + +// Check libuv library version. +const static bool uv_version_check = []() { + const unsigned int version = uv_version(); + const unsigned int major = (version >> 16) & 0xFF; + const unsigned int minor = (version >> 8) & 0xFF; + const unsigned int patch = version & 0xFF; + +#ifndef UV_VERSION_PATCH + // 0.10 doesn't have UV_VERSION_PATCH defined, so we "fake" it by using the library patch level. + const unsigned int UV_VERSION_PATCH = version & 0xFF; +#endif + + if (major != UV_VERSION_MAJOR || minor != UV_VERSION_MINOR || patch != UV_VERSION_PATCH) { + throw std::runtime_error(mbgl::util::sprintf<96>( + "libuv version mismatch: headers report %d.%d.%d, but library reports %d.%d.%d", UV_VERSION_MAJOR, + UV_VERSION_MINOR, UV_VERSION_PATCH, major, minor, patch)); + } + return true; +}(); + + +#include +// Check zlib library version. +const static bool zlib_version_check = []() { + const char *const version = zlibVersion(); + if (version[0] != ZLIB_VERSION[0]) { + throw std::runtime_error(mbgl::util::sprintf<96>( + "zlib version mismatch: headers report %s, but library reports %s", ZLIB_VERSION, version)); + } + + return true; +}(); + + +#include +// Check sqlite3 library version. +const static bool sqlite_version_check = []() { + if (sqlite3_libversion_number() != SQLITE_VERSION_NUMBER) { + throw std::runtime_error(mbgl::util::sprintf<96>( + "sqlite3 libversion mismatch: headers report %d, but library reports %d", + SQLITE_VERSION_NUMBER, sqlite3_libversion_number())); + } + if (strcmp(sqlite3_sourceid(), SQLITE_SOURCE_ID) != 0) { + throw std::runtime_error(mbgl::util::sprintf<256>( + "sqlite3 sourceid mismatch: headers report \"%s\", but library reports \"%s\"", + SQLITE_SOURCE_ID, sqlite3_sourceid())); + } + + return true; +}(); + + using namespace mbgl; Map::Map(View& view_) From 7877d0505e25dd4d2f636b3dba8605a8519c9e9e Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Wed, 12 Nov 2014 23:17:07 +1100 Subject: [PATCH 14/14] Fix crash --- android/cpp/native_map_view.cpp | 2 +- include/mbgl/android/native_map_view.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/android/cpp/native_map_view.cpp b/android/cpp/native_map_view.cpp index f976d7d96..ab3034a18 100644 --- a/android/cpp/native_map_view.cpp +++ b/android/cpp/native_map_view.cpp @@ -80,7 +80,7 @@ void MBGLView::notify_map_change(mbgl::MapChange /* change */, mbgl::timestamp / nativeView.notifyMapChange(); } -NativeMapView::NativeMapView(JNIEnv* env, jobject obj_) : map(view), view(*this) { +NativeMapView::NativeMapView(JNIEnv* env, jobject obj_) : view(*this), map(view) { LOG_VERBOSE("NativeMapView::NativeMapView"); LOG_ASSERT(env != nullptr); diff --git a/include/mbgl/android/native_map_view.hpp b/include/mbgl/android/native_map_view.hpp index e2daab939..dee6a2226 100644 --- a/include/mbgl/android/native_map_view.hpp +++ b/include/mbgl/android/native_map_view.hpp @@ -72,8 +72,8 @@ private: ANativeWindow* window = nullptr; + MBGLView view; // Must be before map mbgl::Map map; - MBGLView view; EGLDisplay display = EGL_NO_DISPLAY; EGLSurface surface = EGL_NO_SURFACE;