diff --git a/android/cpp/jni.cpp b/android/cpp/jni.cpp index fd92ba8f4..d62621ae6 100644 --- a/android/cpp/jni.cpp +++ b/android/cpp/jni.cpp @@ -23,16 +23,16 @@ #pragma clang diagnostic ignored "-Wunused-parameter" -#define CPP_TRY_JNI(ENV, CODE) \ - try { \ - CODE; \ - } catch(std::exception e) { \ - std::string msg("Unhandled C++ exception: "); \ - msg.append(e.what()); \ - throw_error(ENV, msg.c_str()); \ +#define CPP_TRY_JNI(ENV, CODE) \ + try { \ + CODE; \ + } \ + catch (std::exception e) { \ + std::string msg("Unhandled C++ exception: "); \ + msg.append(e.what()); \ + throw_error(ENV, msg.c_str()); \ } - namespace mbgl { namespace android { @@ -64,7 +64,7 @@ jclass arrayListClass = nullptr; jmethodID arrayListConstructorId = nullptr; jmethodID arrayListAddId = nullptr; -bool throw_error(JNIEnv* env, const char* msg) { +bool throw_error(JNIEnv *env, const char *msg) { if (env->ThrowNew(runtimeExceptionClass, msg) < 0) { env->ExceptionDescribe(); return false; @@ -73,7 +73,7 @@ bool throw_error(JNIEnv* env, const char* msg) { return true; } -std::string std_string_from_jstring(JNIEnv* env, jstring jstr) { +std::string std_string_from_jstring(JNIEnv *env, jstring jstr) { std::string str; if (jstr == nullptr) { @@ -91,23 +91,24 @@ std::string std_string_from_jstring(JNIEnv* env, jstring jstr) { return str; } - const jchar* chars = env->GetStringChars(jstr, nullptr); + const jchar *chars = env->GetStringChars(jstr, nullptr); if (chars == nullptr) { env->ExceptionDescribe(); return str; } - std::u16string ustr(reinterpret_cast(chars), len); + std::u16string ustr(reinterpret_cast(chars), len); env->ReleaseStringChars(jstr, chars); chars = nullptr; - str = std::wstring_convert,char16_t>().to_bytes(ustr); + str = std::wstring_convert, char16_t>().to_bytes(ustr); return str; } -jstring std_string_to_jstring(JNIEnv* env, std::string str) { - std::u16string ustr = std::wstring_convert,char16_t>().from_bytes(str); +jstring std_string_to_jstring(JNIEnv *env, std::string str) { + std::u16string ustr = + std::wstring_convert, char16_t>().from_bytes(str); - jstring jstr = env->NewString(reinterpret_cast(ustr.c_str()), ustr.size()); + jstring jstr = env->NewString(reinterpret_cast(ustr.c_str()), ustr.size()); if (jstr == nullptr) { env->ExceptionDescribe(); return nullptr; @@ -116,7 +117,7 @@ jstring std_string_to_jstring(JNIEnv* env, std::string str) { return jstr; } -std::vector std_vector_string_from_jobject(JNIEnv* env, jobject jlist) { +std::vector std_vector_string_from_jobject(JNIEnv *env, jobject jlist) { std::vector vector; if (jlist == nullptr) { @@ -128,7 +129,8 @@ std::vector std_vector_string_from_jobject(JNIEnv* env, jobject jli return vector; } - jobjectArray array = reinterpret_cast(env->CallObjectMethod(jlist, listToArrayId)); + jobjectArray array = + reinterpret_cast(env->CallObjectMethod(jlist, listToArrayId)); if (env->ExceptionCheck() || (array == nullptr)) { env->ExceptionDescribe(); return vector; @@ -153,7 +155,7 @@ std::vector std_vector_string_from_jobject(JNIEnv* env, jobject jli return vector; } -jobject std_vector_string_to_jobject(JNIEnv* env, std::vector vector) { +jobject std_vector_string_to_jobject(JNIEnv *env, std::vector vector) { jobject jlist = env->NewObject(arrayListClass, arrayListConstructorId); if (jlist == nullptr) { env->ExceptionDescribe(); @@ -170,7 +172,6 @@ jobject std_vector_string_to_jobject(JNIEnv* env, std::vector vecto return jlist; } - } } @@ -178,12 +179,13 @@ namespace { using namespace mbgl::android; -jlong JNICALL nativeCreate(JNIEnv* env, jobject obj, jstring cachePath_, jstring dataPath_, jstring apkPath_) { +jlong JNICALL +nativeCreate(JNIEnv *env, jobject obj, jstring cachePath_, jstring dataPath_, jstring apkPath_) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeCreate"); cachePath = std_string_from_jstring(env, cachePath_); dataPath = std_string_from_jstring(env, dataPath_); apkPath = std_string_from_jstring(env, apkPath_); - NativeMapView* nativeMapView = nullptr; + NativeMapView *nativeMapView = nullptr; COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView = new NativeMapView(env, obj))); if (nativeMapView == nullptr) { throw_error(env, "Unable to create NativeMapView."); @@ -193,18 +195,18 @@ jlong JNICALL nativeCreate(JNIEnv* env, jobject obj, jstring cachePath_, jstring return mapViewPtr; } -void JNICALL nativeDestroy(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeDestroy(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeDestroy"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); delete nativeMapView; nativeMapView = nullptr; } -void JNICALL nativeInitializeDisplay(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeInitializeDisplay(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeInitializeDisplay"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); bool ret = false; COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->initializeDisplay())); if (!ret) { @@ -212,17 +214,17 @@ void JNICALL nativeInitializeDisplay(JNIEnv* env, jobject obj, jlong nativeMapVi } } -void JNICALL nativeTerminateDisplay(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeTerminateDisplay(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeTerminateDisplay"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->terminateDisplay())); } -void JNICALL nativeInitializeContext(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeInitializeContext(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeInitializeContext"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); bool ret = false; COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->initializeContext())); if (!ret) { @@ -230,115 +232,119 @@ void JNICALL nativeInitializeContext(JNIEnv* env, jobject obj, jlong nativeMapVi } } -void JNICALL nativeTerminateContext(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeTerminateContext(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeTerminateContext"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->terminateContext())); } -void JNICALL nativeCreateSurface(JNIEnv* env, jobject obj, jlong nativeMapViewPtr, jobject surface) { +void JNICALL +nativeCreateSurface(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject surface) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeCreateSurface"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); bool ret = false; - COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->createSurface(ANativeWindow_fromSurface(env, surface)))); + COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->createSurface( + ANativeWindow_fromSurface(env, surface)))); if (!ret) { throw_error(env, "Unable to create GL surface."); } } -void JNICALL nativeDestroySurface(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeDestroySurface(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeDestroySurface"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->destroySurface())); } -void JNICALL nativeStart(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeStart(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeStart"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->start())); } -void JNICALL nativeStop(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeStop(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeStop"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->stop())); } -void JNICALL nativePause(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativePause(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativePause"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->pause())); } -void JNICALL nativeResume(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeResume(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeResume"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->resume())); } -void JNICALL nativeRun(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeRun(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeRun"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().run())); } -void JNICALL nativeRerender(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeRerender(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeRerender"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().rerender())); } -void JNICALL nativeUpdate(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeUpdate(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeUpdate"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().update())); } -void JNICALL nativeTerminate(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeTerminate(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeTerminate"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().terminate())); } -jboolean JNICALL nativeNeedsSwap(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +jboolean JNICALL nativeNeedsSwap(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeNeedsSwap"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); jboolean ret = false; COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->getMap().needsSwap())); return ret; } -void JNICALL nativeSwapped(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeSwapped(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSwapped"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, (nativeMapView->getMap().swapped()))); } -void JNICALL nativeResize(JNIEnv* env, jobject obj, jlong nativeMapViewPtr, jint width, jint height, jfloat ratio) { +void JNICALL nativeResize(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jint width, jint height, + jfloat ratio) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeResize"); assert(nativeMapViewPtr != 0); assert(width >= 0); assert(height >= 0); assert(width <= UINT16_MAX); assert(height <= UINT16_MAX); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().resize(width, height, ratio))); } -void JNICALL nativeResize(JNIEnv* env, jobject obj, jlong nativeMapViewPtr, jint width, jint height, jfloat ratio, jint fbWidth, jint fbHeight) { +void JNICALL nativeResize(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jint width, jint height, + jfloat ratio, jint fbWidth, jint fbHeight) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeResize"); assert(nativeMapViewPtr != 0); assert(width >= 0); @@ -349,100 +355,118 @@ void JNICALL nativeResize(JNIEnv* env, jobject obj, jlong nativeMapViewPtr, jint assert(fbHeight >= 0); assert(fbWidth <= UINT16_MAX); assert(fbHeight <= UINT16_MAX); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); - COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().resize(width, height, ratio, fbWidth, fbHeight))); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().resize(width, height, ratio, + fbWidth, fbHeight))); } -void JNICALL nativeSetAppliedClasses(JNIEnv* env, jobject obj, jlong nativeMapViewPtr, jobject classes) { +void JNICALL +nativeSetAppliedClasses(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject classes) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetAppliedClasses"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); - COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setAppliedClasses(std_vector_string_from_jobject(env, classes)))); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setAppliedClasses( + std_vector_string_from_jobject(env, classes)))); } -jobject JNICALL nativeGetAppliedClasses(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +jobject JNICALL nativeGetAppliedClasses(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetAppliedClasses"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); jobject ret = nullptr; - COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = std_vector_string_to_jobject(env, nativeMapView->getMap().getAppliedClasses()))); + COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = std_vector_string_to_jobject( + env, nativeMapView->getMap().getAppliedClasses()))); return ret; } -void JNICALL nativeSetDefaultTransitionDuration(JNIEnv* env, jobject obj, jlong nativeMapViewPtr, jlong milliseconds) { +void JNICALL nativeSetDefaultTransitionDuration(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, + jlong milliseconds) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetDefaultTransitionDuration"); assert(nativeMapViewPtr != 0); assert(milliseconds >= 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); - COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setDefaultTransitionDuration(milliseconds))); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + COFFEE_TRY_JNI( + env, CPP_TRY_JNI(env, nativeMapView->getMap().setDefaultTransitionDuration(milliseconds))); } -jlong JNICALL nativeGetDefaultTransitionDuration(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +jlong JNICALL nativeGetDefaultTransitionDuration(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetDefaultTransitionDuration"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); jlong ret = 0; - COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->getMap().getDefaultTransitionDuration())); + COFFEE_TRY_JNI(env, + CPP_TRY_JNI(env, ret = nativeMapView->getMap().getDefaultTransitionDuration())); return ret; } -void JNICALL nativeSetStyleURL(JNIEnv* env, jobject obj, jlong nativeMapViewPtr, jstring url) { +void JNICALL nativeSetStyleURL(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jstring url) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetStyleURL"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); - COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setStyleURL(std_string_from_jstring(env, url)))); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setStyleURL( + std_string_from_jstring(env, url)))); } -void JNICALL nativeSetStyleJSON(JNIEnv* env, jobject obj, jlong nativeMapViewPtr, jstring newStyleJson, jstring base) { +void JNICALL nativeSetStyleJSON(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, + jstring newStyleJson, jstring base) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetStyleJSON"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); - COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setStyleJSON(std_string_from_jstring(env, newStyleJson), std_string_from_jstring(env, base)))); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setStyleJSON( + std_string_from_jstring(env, newStyleJson), + std_string_from_jstring(env, base)))); } -jstring JNICALL nativeGetStyleJSON(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +jstring JNICALL nativeGetStyleJSON(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetStyleJSON"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); jstring ret = nullptr; - COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = std_string_to_jstring(env, nativeMapView->getMap().getStyleJSON()))); + COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = std_string_to_jstring( + env, nativeMapView->getMap().getStyleJSON()))); return ret; } -void JNICALL nativeSetAccessToken(JNIEnv* env, jobject obj, jlong nativeMapViewPtr, jstring accessToken) { +void JNICALL +nativeSetAccessToken(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jstring accessToken) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetAccessToken"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); - COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getFileSource().setAccessToken(std_string_from_jstring(env, accessToken)))); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getFileSource().setAccessToken( + std_string_from_jstring(env, accessToken)))); } -jstring JNICALL nativeGetAccessToken(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +jstring JNICALL nativeGetAccessToken(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetAccessToken"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); jstring ret = nullptr; - COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = std_string_to_jstring(env, nativeMapView->getFileSource().getAccessToken()))); + COFFEE_TRY_JNI(env, + CPP_TRY_JNI(env, ret = std_string_to_jstring( + env, nativeMapView->getFileSource().getAccessToken()))); return ret; } -void JNICALL nativeCancelTransitions(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeCancelTransitions(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeCancelTransitions"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().cancelTransitions())); } -void JNICALL nativeMoveBy(JNIEnv* env, jobject obj, jlong nativeMapViewPtr, jdouble dx, jdouble dy, jdouble duration) { +void JNICALL nativeMoveBy(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble dx, jdouble dy, + jdouble duration) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeMoveBy"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().moveBy(dx, dy, duration))); } -void JNICALL nativeSetLonLat(JNIEnv* env, jobject obj, jlong nativeMapViewPtr, jobject lonLat, jdouble duration) { +void JNICALL nativeSetLonLat(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject lonLat, + jdouble duration) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetLonLat"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); double lon = env->GetDoubleField(lonLat, lonLatLonId); if (env->ExceptionCheck()) { @@ -459,10 +483,10 @@ void JNICALL nativeSetLonLat(JNIEnv* env, jobject obj, jlong nativeMapViewPtr, j COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setLonLat(lon, lat, duration))); } -jobject JNICALL nativeGetLonLat(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +jobject JNICALL nativeGetLonLat(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetLonLat"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); double lon = 0.0, lat = 0.0; COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().getLonLat(lon, lat))); @@ -475,70 +499,75 @@ jobject JNICALL nativeGetLonLat(JNIEnv* env, jobject obj, jlong nativeMapViewPtr return ret; } -void JNICALL nativeStartPanning(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeStartPanning(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeStartPanning"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().startPanning())); } -void JNICALL nativeStopPanning(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeStopPanning(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeStopPanning"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().stopPanning())); } -void JNICALL nativeResetPosition(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeResetPosition(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeResetPosition"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().resetPosition())); } -void JNICALL nativeScaleBy(JNIEnv* env, jobject obj, jlong nativeMapViewPtr, jdouble ds, jdouble cx, jdouble cy, jdouble duration) { +void JNICALL nativeScaleBy(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble ds, jdouble cx, + jdouble cy, jdouble duration) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeScaleBy"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().scaleBy(ds, cx, cy, duration))); } -void JNICALL nativeSetScale(JNIEnv* env, jobject obj, jlong nativeMapViewPtr, jdouble scale, jdouble cx, jdouble cy, jdouble duration) { +void JNICALL nativeSetScale(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble scale, + jdouble cx, jdouble cy, jdouble duration) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetScale"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); - COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setScale(scale, cx, cy, duration))); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + COFFEE_TRY_JNI(env, + CPP_TRY_JNI(env, nativeMapView->getMap().setScale(scale, cx, cy, duration))); } -jdouble JNICALL nativeGetScale(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +jdouble JNICALL nativeGetScale(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetScale"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); jdouble ret = 0.0; COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->getMap().getScale())); return ret; } -void JNICALL nativeSetZoom(JNIEnv* env, jobject obj, jlong nativeMapViewPtr, jdouble zoom, jdouble duration) { +void JNICALL +nativeSetZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble zoom, jdouble duration) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetZoom"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setZoom(zoom, duration))); } -jdouble JNICALL nativeGetZoom(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +jdouble JNICALL nativeGetZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetZoom"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); jdouble ret = 0.0; COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->getMap().getZoom())); return ret; } -void JNICALL nativeSetLonLatZoom(JNIEnv* env, jobject obj, jlong nativeMapViewPtr, jobject lonLatZoom, jdouble duration) { +void JNICALL nativeSetLonLatZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, + jobject lonLatZoom, jdouble duration) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetLonLatZoom"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); double lon = env->GetDoubleField(lonLatZoom, lonLatZoomLonId); if (env->ExceptionCheck()) { @@ -558,13 +587,14 @@ void JNICALL nativeSetLonLatZoom(JNIEnv* env, jobject obj, jlong nativeMapViewPt return; } - COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setLonLatZoom(lon, lat, zoom, duration))); + COFFEE_TRY_JNI( + env, CPP_TRY_JNI(env, nativeMapView->getMap().setLonLatZoom(lon, lat, zoom, duration))); } -jobject JNICALL nativeGetLonLatZoom(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +jobject JNICALL nativeGetLonLatZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetLonLatZoom"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); double lon = 0.0, lat = 0.0, zoom = 0.0; COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().getLonLatZoom(lon, lat, zoom))); @@ -577,126 +607,132 @@ jobject JNICALL nativeGetLonLatZoom(JNIEnv* env, jobject obj, jlong nativeMapVie return ret; } -void JNICALL nativeResetZoom(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeResetZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeResetZoom"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().resetZoom())); } -void JNICALL nativeStartScaling(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeStartScaling(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeStartScaling"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().startScaling())); } -void JNICALL nativeStopScaling(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeStopScaling(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeStopScaling"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().stopScaling())); } -jdouble JNICALL nativeGetMinZoom(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +jdouble JNICALL nativeGetMinZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetMinZoom"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); jdouble ret = 0.0; COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->getMap().getMinZoom())); return ret; } -jdouble JNICALL nativeGetMaxZoom(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +jdouble JNICALL nativeGetMaxZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetMaxZoom"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); jdouble ret = 0.0; COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->getMap().getMaxZoom())); return ret; } -void JNICALL nativeRotateBy(JNIEnv* env, jobject obj, jlong nativeMapViewPtr, jdouble sx, jdouble sy, jdouble ex, jdouble ey, jdouble duration) { +void JNICALL nativeRotateBy(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble sx, + jdouble sy, jdouble ex, jdouble ey, jdouble duration) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeRotateBy"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); - COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().rotateBy(sx, sy, ex, ey, duration))); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + COFFEE_TRY_JNI(env, + CPP_TRY_JNI(env, nativeMapView->getMap().rotateBy(sx, sy, ex, ey, duration))); } -void JNICALL nativeSetBearing(JNIEnv* env, jobject obj, jlong nativeMapViewPtr, jdouble degrees, jdouble duration) { +void JNICALL nativeSetBearing(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble degrees, + jdouble duration) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetBearing"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setBearing(degrees, duration))); } -void JNICALL nativeSetBearing(JNIEnv* env, jobject obj, jlong nativeMapViewPtr, jdouble degrees, jdouble cx, jdouble cy) { +void JNICALL nativeSetBearing(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble degrees, + jdouble cx, jdouble cy) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetBearing"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setBearing(degrees, cx, cy))); } -jdouble JNICALL nativeGetBearing(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +jdouble JNICALL nativeGetBearing(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetBearing"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); jdouble ret = 0.0; COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->getMap().getBearing())); return ret; } -void JNICALL nativeResetNorth(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeResetNorth(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeResetNorth"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().resetNorth())); } -void JNICALL nativeStartRotating(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeStartRotating(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeStartRotating"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().startRotating())); } -void JNICALL nativeStopRotating(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeStopRotating(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeStopRotating"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().stopRotating())); } -void JNICALL nativeSetDebug(JNIEnv* env, jobject obj, jlong nativeMapViewPtr, jboolean debug) { +void JNICALL nativeSetDebug(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jboolean debug) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetDebug"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); - COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setDebug(debug); nativeMapView->enableFps(debug))); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setDebug(debug); + nativeMapView->enableFps(debug))); } -void JNICALL nativeToggleDebug(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +void JNICALL nativeToggleDebug(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeToggleDebug"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); - COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().toggleDebug(); nativeMapView->enableFps(nativeMapView->getMap().getDebug()))); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().toggleDebug(); + nativeMapView->enableFps(nativeMapView->getMap().getDebug()))); } -jboolean JNICALL nativeGetDebug(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) { +jboolean JNICALL nativeGetDebug(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetDebug"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); jboolean ret = false; COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->getMap().getDebug())); return ret; } -void JNICALL nativeSetReachability(JNIEnv* env, jobject obj, jlong nativeMapViewPtr, jboolean status) { +void JNICALL +nativeSetReachability(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jboolean status) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetReachability"); assert(nativeMapViewPtr != 0); - NativeMapView* nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getFileSource().setReachability(status))); } - } extern "C" { @@ -706,8 +742,8 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { mbgl::Log::Debug(mbgl::Event::JNI, "JNI_OnLoad"); - JNIEnv* env = nullptr; - jint ret = vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6); + JNIEnv *env = nullptr; + jint ret = vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6); if (ret != JNI_OK) { mbgl::Log::Error(mbgl::Event::JNI, "GetEnv() failed with %i", ret); return JNI_ERR; @@ -827,68 +863,94 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { return JNI_ERR; } - // NOTE: if you get java.lang.UnsatisfiedLinkError you likely forgot to set the size of the array correctly (too large) + // 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;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) }, - { "nativeInitializeContext", "(J)V", reinterpret_cast(&nativeInitializeContext) }, - { "nativeTerminateContext", "(J)V", reinterpret_cast(&nativeTerminateContext) }, - { "nativeCreateSurface", "(JLandroid/view/Surface;)V", reinterpret_cast(&nativeCreateSurface) }, - { "nativeDestroySurface", "(J)V", reinterpret_cast(&nativeDestroySurface) }, - { "nativeStart", "(J)V", reinterpret_cast(&nativeStart) }, - { "nativeStop", "(J)V", reinterpret_cast(&nativeStop) }, - { "nativePause", "(J)V", reinterpret_cast(&nativePause) }, - { "nativeResume", "(J)V", reinterpret_cast(&nativeResume) }, - { "nativeRun", "(J)V", reinterpret_cast(&nativeRun) }, - { "nativeRerender", "(J)V", reinterpret_cast(&nativeRerender) }, - { "nativeUpdate", "(J)V", reinterpret_cast(&nativeUpdate) }, - { "nativeTerminate", "(J)V", reinterpret_cast(&nativeTerminate) }, - { "nativeNeedsSwap", "(J)Z", reinterpret_cast(&nativeNeedsSwap) }, - { "nativeSwapped", "(J)V", reinterpret_cast(&nativeSwapped) }, - { "nativeResize", "(JIIF)V", reinterpret_cast(static_cast(&nativeResize)) }, - { "nativeResize", "(JIIFII)V", reinterpret_cast(static_cast(&nativeResize)) }, - { "nativeSetAppliedClasses", "(JLjava/util/List;)V", reinterpret_cast(&nativeSetAppliedClasses) }, - { "nativeGetAppliedClasses", "(J)Ljava/util/List;", reinterpret_cast(&nativeGetAppliedClasses) }, - { "nativeSetDefaultTransitionDuration", "(JJ)V", reinterpret_cast(&nativeSetDefaultTransitionDuration) }, - { "nativeGetDefaultTransitionDuration", "(J)J", reinterpret_cast(&nativeGetDefaultTransitionDuration) }, - { "nativeSetStyleUrl", "(JLjava/lang/String;)V", reinterpret_cast(&nativeSetStyleURL) }, - { "nativeSetStyleJson", "(JLjava/lang/String;Ljava/lang/String;)V", reinterpret_cast(&nativeSetStyleJSON) }, - { "nativeGetStyleJson", "(J)Ljava/lang/String;", reinterpret_cast(&nativeGetStyleJSON) }, - { "nativeSetAccessToken", "(JLjava/lang/String;)V", reinterpret_cast(&nativeSetAccessToken) }, - { "nativeGetAccessToken", "(J)Ljava/lang/String;", reinterpret_cast(&nativeGetAccessToken) }, - { "nativeCancelTransitions", "(J)V", reinterpret_cast(&nativeCancelTransitions) }, - { "nativeMoveBy", "(JDDD)V", reinterpret_cast(&nativeMoveBy) }, - { "nativeSetLonLat", "(JLcom/mapbox/mapboxgl/lib/LonLat;D)V", reinterpret_cast(&nativeSetLonLat) }, - { "nativeGetLonLat", "(J)Lcom/mapbox/mapboxgl/lib/LonLat;", reinterpret_cast(&nativeGetLonLat) }, - { "nativeStartPanning", "(J)V", reinterpret_cast(&nativeStartPanning) }, - { "nativeStopPanning", "(J)V", reinterpret_cast(&nativeStopPanning) }, - { "nativeResetPosition", "(J)V", reinterpret_cast(&nativeResetPosition) }, - { "nativeScaleBy", "(JDDDD)V", reinterpret_cast(&nativeScaleBy) }, - { "nativeSetScale", "(JDDDD)V", reinterpret_cast(&nativeSetScale) }, - { "nativeGetScale", "(J)D", reinterpret_cast(&nativeGetScale) }, - { "nativeSetZoom", "(JDD)V", reinterpret_cast(&nativeSetZoom) }, - { "nativeGetZoom", "(J)D", reinterpret_cast(&nativeGetZoom) }, - { "nativeSetLonLatZoom", "(JLcom/mapbox/mapboxgl/lib/LonLatZoom;D)V", reinterpret_cast(&nativeSetLonLatZoom) }, - { "nativeGetLonLatZoom", "(J)Lcom/mapbox/mapboxgl/lib/LonLatZoom;", reinterpret_cast(&nativeGetLonLatZoom) }, - { "nativeResetZoom", "(J)V", reinterpret_cast(&nativeResetZoom) }, - { "nativeStartPanning", "(J)V", reinterpret_cast(&nativeStartScaling) }, - { "nativeStopPanning", "(J)V", reinterpret_cast(&nativeStopScaling) }, - { "nativeGetMinZoom", "(J)D", reinterpret_cast(&nativeGetMinZoom) }, - { "nativeGetMaxZoom", "(J)D", reinterpret_cast(&nativeGetMaxZoom) }, - { "nativeRotateBy", "(JDDDDD)V", reinterpret_cast(&nativeRotateBy) }, - { "nativeSetBearing", "(JDD)V", reinterpret_cast(static_cast(&nativeSetBearing)) }, - { "nativeSetBearing", "(JDDD)V", reinterpret_cast(static_cast(&nativeSetBearing)) }, - { "nativeGetBearing", "(J)D", reinterpret_cast(&nativeGetBearing) }, - { "nativeResetNorth", "(J)V", reinterpret_cast(&nativeResetNorth) }, - { "nativeStartRotating", "(J)V", reinterpret_cast(&nativeStartRotating) }, - { "nativeStopRotating", "(J)V", reinterpret_cast(&nativeStopRotating) }, - { "nativeSetDebug", "(JZ)V", reinterpret_cast(&nativeSetDebug) }, - { "nativeToggleDebug", "(J)V", reinterpret_cast(&nativeToggleDebug) }, - { "nativeGetDebug", "(J)Z", reinterpret_cast(&nativeGetDebug) }, - { "nativeSetReachability", "(JZ)V", reinterpret_cast(&nativeSetReachability) } - }}; + {"nativeCreate", "(Ljava/lang/String;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)}, + {"nativeInitializeContext", "(J)V", reinterpret_cast(&nativeInitializeContext)}, + {"nativeTerminateContext", "(J)V", reinterpret_cast(&nativeTerminateContext)}, + {"nativeCreateSurface", "(JLandroid/view/Surface;)V", + reinterpret_cast(&nativeCreateSurface)}, + {"nativeDestroySurface", "(J)V", reinterpret_cast(&nativeDestroySurface)}, + {"nativeStart", "(J)V", reinterpret_cast(&nativeStart)}, + {"nativeStop", "(J)V", reinterpret_cast(&nativeStop)}, + {"nativePause", "(J)V", reinterpret_cast(&nativePause)}, + {"nativeResume", "(J)V", reinterpret_cast(&nativeResume)}, + {"nativeRun", "(J)V", reinterpret_cast(&nativeRun)}, + {"nativeRerender", "(J)V", reinterpret_cast(&nativeRerender)}, + {"nativeUpdate", "(J)V", reinterpret_cast(&nativeUpdate)}, + {"nativeTerminate", "(J)V", reinterpret_cast(&nativeTerminate)}, + {"nativeNeedsSwap", "(J)Z", reinterpret_cast(&nativeNeedsSwap)}, + {"nativeSwapped", "(J)V", reinterpret_cast(&nativeSwapped)}, + {"nativeResize", "(JIIF)V", + reinterpret_cast( + static_cast( + &nativeResize))}, + {"nativeResize", "(JIIFII)V", + reinterpret_cast(static_cast(&nativeResize))}, + {"nativeSetAppliedClasses", "(JLjava/util/List;)V", + reinterpret_cast(&nativeSetAppliedClasses)}, + {"nativeGetAppliedClasses", "(J)Ljava/util/List;", + reinterpret_cast(&nativeGetAppliedClasses)}, + {"nativeSetDefaultTransitionDuration", "(JJ)V", + reinterpret_cast(&nativeSetDefaultTransitionDuration)}, + {"nativeGetDefaultTransitionDuration", "(J)J", + reinterpret_cast(&nativeGetDefaultTransitionDuration)}, + {"nativeSetStyleUrl", "(JLjava/lang/String;)V", + reinterpret_cast(&nativeSetStyleURL)}, + {"nativeSetStyleJson", "(JLjava/lang/String;Ljava/lang/String;)V", + reinterpret_cast(&nativeSetStyleJSON)}, + {"nativeGetStyleJson", "(J)Ljava/lang/String;", + reinterpret_cast(&nativeGetStyleJSON)}, + {"nativeSetAccessToken", "(JLjava/lang/String;)V", + reinterpret_cast(&nativeSetAccessToken)}, + {"nativeGetAccessToken", "(J)Ljava/lang/String;", + reinterpret_cast(&nativeGetAccessToken)}, + {"nativeCancelTransitions", "(J)V", reinterpret_cast(&nativeCancelTransitions)}, + {"nativeMoveBy", "(JDDD)V", reinterpret_cast(&nativeMoveBy)}, + {"nativeSetLonLat", "(JLcom/mapbox/mapboxgl/lib/LonLat;D)V", + reinterpret_cast(&nativeSetLonLat)}, + {"nativeGetLonLat", "(J)Lcom/mapbox/mapboxgl/lib/LonLat;", + reinterpret_cast(&nativeGetLonLat)}, + {"nativeStartPanning", "(J)V", reinterpret_cast(&nativeStartPanning)}, + {"nativeStopPanning", "(J)V", reinterpret_cast(&nativeStopPanning)}, + {"nativeResetPosition", "(J)V", reinterpret_cast(&nativeResetPosition)}, + {"nativeScaleBy", "(JDDDD)V", reinterpret_cast(&nativeScaleBy)}, + {"nativeSetScale", "(JDDDD)V", reinterpret_cast(&nativeSetScale)}, + {"nativeGetScale", "(J)D", reinterpret_cast(&nativeGetScale)}, + {"nativeSetZoom", "(JDD)V", reinterpret_cast(&nativeSetZoom)}, + {"nativeGetZoom", "(J)D", reinterpret_cast(&nativeGetZoom)}, + {"nativeSetLonLatZoom", "(JLcom/mapbox/mapboxgl/lib/LonLatZoom;D)V", + reinterpret_cast(&nativeSetLonLatZoom)}, + {"nativeGetLonLatZoom", "(J)Lcom/mapbox/mapboxgl/lib/LonLatZoom;", + reinterpret_cast(&nativeGetLonLatZoom)}, + {"nativeResetZoom", "(J)V", reinterpret_cast(&nativeResetZoom)}, + {"nativeStartPanning", "(J)V", reinterpret_cast(&nativeStartScaling)}, + {"nativeStopPanning", "(J)V", reinterpret_cast(&nativeStopScaling)}, + {"nativeGetMinZoom", "(J)D", reinterpret_cast(&nativeGetMinZoom)}, + {"nativeGetMaxZoom", "(J)D", reinterpret_cast(&nativeGetMaxZoom)}, + {"nativeRotateBy", "(JDDDDD)V", reinterpret_cast(&nativeRotateBy)}, + {"nativeSetBearing", "(JDD)V", + reinterpret_cast( + static_cast( + &nativeSetBearing))}, + {"nativeSetBearing", "(JDDD)V", + reinterpret_cast( + static_cast( + &nativeSetBearing))}, + {"nativeGetBearing", "(J)D", reinterpret_cast(&nativeGetBearing)}, + {"nativeResetNorth", "(J)V", reinterpret_cast(&nativeResetNorth)}, + {"nativeStartRotating", "(J)V", reinterpret_cast(&nativeStartRotating)}, + {"nativeStopRotating", "(J)V", reinterpret_cast(&nativeStopRotating)}, + {"nativeSetDebug", "(JZ)V", reinterpret_cast(&nativeSetDebug)}, + {"nativeToggleDebug", "(J)V", reinterpret_cast(&nativeToggleDebug)}, + {"nativeGetDebug", "(J)Z", reinterpret_cast(&nativeGetDebug)}, + {"nativeSetReachability", "(JZ)V", reinterpret_cast(&nativeSetReachability)}}}; if (env->RegisterNatives(nativeMapViewClass, methods.data(), methods.size()) < 0) { env->ExceptionDescribe(); @@ -916,7 +978,8 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { return JNI_ERR; } - nullPointerExceptionClass = reinterpret_cast(env->NewGlobalRef(nullPointerExceptionClass)); + nullPointerExceptionClass = + reinterpret_cast(env->NewGlobalRef(nullPointerExceptionClass)); if (nullPointerExceptionClass == nullptr) { env->ExceptionDescribe(); env->DeleteGlobalRef(lonLatClass); @@ -935,7 +998,6 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { return JNI_ERR; } - char release[PROP_VALUE_MAX] = ""; __system_property_get("ro.build.version.release", release); androidRelease = std::string(release); @@ -946,8 +1008,8 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { extern "C" JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) { mbgl::Log::Debug(mbgl::Event::JNI, "JNI_OnUnload"); - JNIEnv* env = nullptr; - jint ret = vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6); + JNIEnv *env = nullptr; + jint ret = vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6); if (ret != JNI_OK) { mbgl::Log::Error(mbgl::Event::JNI, "GetEnv() failed with %i", ret); return; @@ -982,5 +1044,4 @@ extern "C" JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) { arrayListConstructorId = nullptr; arrayListAddId = nullptr; } - } diff --git a/android/cpp/native_map_view.cpp b/android/cpp/native_map_view.cpp index 7b91af0fd..986d33902 100644 --- a/android/cpp/native_map_view.cpp +++ b/android/cpp/native_map_view.cpp @@ -19,10 +19,11 @@ namespace mbgl { namespace android { -void log_egl_string(EGLDisplay display, EGLint name, const char* label) { - const char* str = eglQueryString(display, name); +void log_egl_string(EGLDisplay display, EGLint name, const char *label) { + const char *str = eglQueryString(display, name); if (str == nullptr) { - mbgl::Log::Error(mbgl::Event::OpenGL, "eglQueryString(%d) returned error %d", name, eglGetError()); + mbgl::Log::Error(mbgl::Event::OpenGL, "eglQueryString(%d) returned error %d", name, + eglGetError()); } else { char buf[513]; for (int len = std::strlen(str), pos = 0; len > 0; len -= 512, pos += 512) { @@ -33,13 +34,15 @@ void log_egl_string(EGLDisplay display, EGLint name, const char* label) { } } -void log_gl_string(GLenum name, const char* label) { - const GLubyte* str = glGetString(name); +void log_gl_string(GLenum name, const char *label) { + const GLubyte *str = glGetString(name); if (str == nullptr) { - mbgl::Log::Error(mbgl::Event::OpenGL, "glGetString(%d) returned error %d", name, glGetError()); + mbgl::Log::Error(mbgl::Event::OpenGL, "glGetString(%d) returned error %d", name, + glGetError()); } else { char buf[513]; - for (int len = std::strlen(reinterpret_cast(str)), pos = 0; len > 0; len -= 512, pos += 512) { + for (int len = std::strlen(reinterpret_cast(str)), pos = 0; len > 0; + len -= 512, pos += 512) { strncpy(buf, reinterpret_cast(str) + pos, 512); buf[512] = 0; mbgl::Log::Info(mbgl::Event::OpenGL, "GL %s: %s", label, buf); @@ -47,7 +50,10 @@ void log_gl_string(GLenum name, const char* label) { } } -NativeMapView::NativeMapView(JNIEnv* env, jobject obj_) : mbgl::View(*this), fileSource(mbgl::platform::defaultCacheDatabase()), map(*this, fileSource) { +NativeMapView::NativeMapView(JNIEnv *env, jobject obj_) + : mbgl::View(*this), + fileSource(mbgl::platform::defaultCacheDatabase()), + map(*this, fileSource) { mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::NativeMapView"); assert(env != nullptr); @@ -75,8 +81,8 @@ NativeMapView::~NativeMapView() { assert(obj != nullptr); jint ret; - JNIEnv* env = nullptr; - ret = vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6); + JNIEnv *env = nullptr; + ret = vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6); if (ret == JNI_OK) { env->DeleteGlobalRef(obj); } else { @@ -90,7 +96,8 @@ void NativeMapView::activate() { mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::activate"); 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()); + mbgl::Log::Error(mbgl::Event::OpenGL, "eglMakeCurrent() returned error %d", + eglGetError()); } } else { mbgl::Log::Info(mbgl::Event::Android, "Not activating as we are not ready"); @@ -100,7 +107,8 @@ void NativeMapView::activate() { void NativeMapView::deactivate() { mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::deactivate"); 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()); + mbgl::Log::Error(mbgl::Event::OpenGL, "eglMakeCurrent(EGL_NO_CONTEXT) returned error %d", + eglGetError()); } } @@ -109,7 +117,8 @@ void NativeMapView::swap() { if (map.needsSwap() && (display != EGL_NO_DISPLAY) && (surface != EGL_NO_SURFACE)) { if (!eglSwapBuffers(display, surface)) { - mbgl::Log::Error(mbgl::Event::OpenGL, "eglSwapBuffers() returned error %d", eglGetError()); + mbgl::Log::Error(mbgl::Event::OpenGL, "eglSwapBuffers() returned error %d", + eglGetError()); } map.swapped(); updateFps(); @@ -123,13 +132,9 @@ void NativeMapView::notify() { // noop } -mbgl::Map& NativeMapView::getMap() { - return map; -} +mbgl::Map &NativeMapView::getMap() { return map; } -mbgl::CachingHTTPFileSource& NativeMapView::getFileSource() { - return fileSource; -} +mbgl::CachingHTTPFileSource &NativeMapView::getFileSource() { return fileSource; } bool NativeMapView::initializeDisplay() { mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::initializeDisplay"); @@ -152,7 +157,8 @@ bool NativeMapView::initializeDisplay() { return false; } if ((major <= 1) && (minor < 3)) { - mbgl::Log::Error(mbgl::Event::OpenGL, "EGL version is too low, need 1.3, got %d.%d", major, minor); + mbgl::Log::Error(mbgl::Event::OpenGL, "EGL version is too low, need 1.3, got %d.%d", major, + minor); terminateDisplay(); return false; } @@ -172,22 +178,19 @@ bool NativeMapView::initializeDisplay() { // 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, // Ugly hack - (inEmulator ? EGL_NONE : EGL_COLOR_BUFFER_TYPE), EGL_RGB_BUFFER, // Ugly hack - EGL_NONE - }; + 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, // Ugly hack + (inEmulator ? EGL_NONE : EGL_COLOR_BUFFER_TYPE), EGL_RGB_BUFFER, // Ugly hack + EGL_NONE}; EGLint numConfigs; if (!eglChooseConfig(display, configAttribs, nullptr, 0, &numConfigs)) { - mbgl::Log::Error(mbgl::Event::OpenGL, "eglChooseConfig(NULL) returned error %d", eglGetError()); + mbgl::Log::Error(mbgl::Event::OpenGL, "eglChooseConfig(NULL) returned error %d", + eglGetError()); terminateDisplay(); return false; } @@ -212,7 +215,8 @@ bool NativeMapView::initializeDisplay() { } if (!eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format)) { - mbgl::Log::Error(mbgl::Event::OpenGL, "eglGetConfigAttrib() returned error %d", eglGetError()); + mbgl::Log::Error(mbgl::Event::OpenGL, "eglGetConfigAttrib() returned error %d", + eglGetError()); terminateDisplay(); return false; } @@ -228,18 +232,20 @@ void NativeMapView::terminateDisplay() { // 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()); + mbgl::Log::Error(mbgl::Event::OpenGL, "eglDestroySurface() returned error %d", + eglGetError()); } 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()); + mbgl::Log::Error(mbgl::Event::OpenGL, + "eglMakeCurrent(EGL_NO_CONTEXT) returned error %d", eglGetError()); } if (!eglTerminate(display)) { - mbgl::Log::Error(mbgl::Event::OpenGL, "eglTerminate() returned error %d", eglGetError()); + mbgl::Log::Error(mbgl::Event::OpenGL, "eglTerminate() returned error %d", + eglGetError()); } } @@ -255,13 +261,11 @@ bool NativeMapView::initializeContext() { assert(context == EGL_NO_CONTEXT); assert(config != nullptr); - const EGLint contextAttribs[] = { - EGL_CONTEXT_CLIENT_VERSION, 2, - EGL_NONE - }; + 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()); + mbgl::Log::Error(mbgl::Event::OpenGL, "eglCreateContext() returned error %d", + eglGetError()); terminateContext(); return false; } @@ -274,13 +278,14 @@ void 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()); + mbgl::Log::Error(mbgl::Event::OpenGL, + "eglMakeCurrent(EGL_NO_CONTEXT) returned error %d", eglGetError()); } if (context != EGL_NO_CONTEXT) { if (!eglDestroyContext(display, context)) { - mbgl::Log::Error(mbgl::Event::OpenGL, "eglDestroyContext() returned error %d", eglGetError()); + mbgl::Log::Error(mbgl::Event::OpenGL, "eglDestroyContext() returned error %d", + eglGetError()); } } } @@ -288,7 +293,7 @@ void NativeMapView::terminateContext() { context = EGL_NO_CONTEXT; } -bool NativeMapView::createSurface(ANativeWindow* window_) { +bool NativeMapView::createSurface(ANativeWindow *window_) { mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::createSurface"); assert(window == nullptr); @@ -302,12 +307,11 @@ bool NativeMapView::createSurface(ANativeWindow* window_) { ANativeWindow_setBuffersGeometry(window, 0, 0, format); - const EGLint surfaceAttribs[] = { - EGL_NONE - }; + 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()); + mbgl::Log::Error(mbgl::Event::OpenGL, "eglCreateWindowSurface() returned error %d", + eglGetError()); destroySurface(); return false; } @@ -316,19 +320,23 @@ bool NativeMapView::createSurface(ANativeWindow* window_) { firstTime = true; if (!eglMakeCurrent(display, surface, surface, context)) { - mbgl::Log::Error(mbgl::Event::OpenGL, "eglMakeCurrent() returned error %d", eglGetError()); + mbgl::Log::Error(mbgl::Event::OpenGL, "eglMakeCurrent() returned error %d", + eglGetError()); } log_gl_string(GL_VENDOR, "Vendor"); log_gl_string(GL_RENDERER, "Renderer"); log_gl_string(GL_VERSION, "Version"); - log_gl_string(GL_SHADING_LANGUAGE_VERSION, "SL Version"); // In the emulator this returns NULL with error code 0? https://code.google.com/p/android/issues/detail?id=78977 + log_gl_string(GL_SHADING_LANGUAGE_VERSION, + "SL Version"); // In the emulator this returns NULL with error code 0? + // https://code.google.com/p/android/issues/detail?id=78977 log_gl_string(GL_EXTENSIONS, "Extensions"); loadExtensions(); 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()); + mbgl::Log::Error(mbgl::Event::OpenGL, + "eglMakeCurrent(EGL_NO_CONTEXT) returned error %d", eglGetError()); } } @@ -344,7 +352,8 @@ void NativeMapView::destroySurface() { if (surface != EGL_NO_SURFACE) { if (!eglDestroySurface(display, surface)) { - mbgl::Log::Error(mbgl::Event::OpenGL, "eglDestroySurface() returned error %d", eglGetError()); + mbgl::Log::Error(mbgl::Event::OpenGL, "eglDestroySurface() returned error %d", + eglGetError()); } } @@ -386,7 +395,8 @@ typedef enum { Format24Depth8Stencil = 0, } DepthStencilFormat; -// Tuple is +// Tuple is typedef std::tuple ConfigProperties; EGLConfig NativeMapView::chooseConfig(const EGLConfig configs[], EGLint numConfigs) { @@ -397,65 +407,83 @@ EGLConfig NativeMapView::chooseConfig(const EGLConfig configs[], EGLint numConfi for (int i = 0; i < numConfigs; i++) { mbgl::Log::Info(mbgl::Event::OpenGL, "Config %d:", i); - EGLint caveat, conformant, bits, red, green, blue, alpha, alphaMask, depth, stencil, sampleBuffers, samples; + 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()); + mbgl::Log::Error(mbgl::Event::OpenGL, + "eglGetConfigAttrib(EGL_CONFIG_CAVEAT) returned error %d", + eglGetError()); return nullptr; } if (!eglGetConfigAttrib(display, configs[i], EGL_CONFORMANT, &conformant)) { - mbgl::Log::Error(mbgl::Event::OpenGL, "eglGetConfigAttrib(EGL_CONFORMANT) returned error %d", eglGetError()); + mbgl::Log::Error(mbgl::Event::OpenGL, + "eglGetConfigAttrib(EGL_CONFORMANT) returned error %d", eglGetError()); return nullptr; } if (!eglGetConfigAttrib(display, configs[i], EGL_BUFFER_SIZE, &bits)) { - mbgl::Log::Error(mbgl::Event::OpenGL, "eglGetConfigAttrib(EGL_BUFFER_SIZE) returned error %d", eglGetError()); + mbgl::Log::Error(mbgl::Event::OpenGL, + "eglGetConfigAttrib(EGL_BUFFER_SIZE) returned error %d", + eglGetError()); return nullptr; } if (!eglGetConfigAttrib(display, configs[i], EGL_RED_SIZE, &red)) { - mbgl::Log::Error(mbgl::Event::OpenGL, "eglGetConfigAttrib(EGL_RED_SIZE) returned error %d", eglGetError()); + mbgl::Log::Error(mbgl::Event::OpenGL, + "eglGetConfigAttrib(EGL_RED_SIZE) returned error %d", eglGetError()); return nullptr; } if (!eglGetConfigAttrib(display, configs[i], EGL_GREEN_SIZE, &green)) { - mbgl::Log::Error(mbgl::Event::OpenGL, "eglGetConfigAttrib(EGL_GREEN_SIZE) returned error %d", eglGetError()); + mbgl::Log::Error(mbgl::Event::OpenGL, + "eglGetConfigAttrib(EGL_GREEN_SIZE) returned error %d", eglGetError()); return nullptr; } if (!eglGetConfigAttrib(display, configs[i], EGL_BLUE_SIZE, &blue)) { - mbgl::Log::Error(mbgl::Event::OpenGL, "eglGetConfigAttrib(EGL_BLUE_SIZE) returned error %d", eglGetError()); + mbgl::Log::Error(mbgl::Event::OpenGL, + "eglGetConfigAttrib(EGL_BLUE_SIZE) returned error %d", eglGetError()); return nullptr; } if (!eglGetConfigAttrib(display, configs[i], EGL_ALPHA_SIZE, &alpha)) { - mbgl::Log::Error(mbgl::Event::OpenGL, "eglGetConfigAttrib(EGL_ALPHA_SIZE) returned error %d", eglGetError()); + mbgl::Log::Error(mbgl::Event::OpenGL, + "eglGetConfigAttrib(EGL_ALPHA_SIZE) returned error %d", eglGetError()); return nullptr; } 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()); + mbgl::Log::Error(mbgl::Event::OpenGL, + "eglGetConfigAttrib(EGL_ALPHA_MASK_SIZE) returned error %d", + eglGetError()); return nullptr; } if (!eglGetConfigAttrib(display, configs[i], EGL_DEPTH_SIZE, &depth)) { - mbgl::Log::Error(mbgl::Event::OpenGL, "eglGetConfigAttrib(EGL_DEPTH_SIZE) returned error %d", eglGetError()); + mbgl::Log::Error(mbgl::Event::OpenGL, + "eglGetConfigAttrib(EGL_DEPTH_SIZE) returned error %d", eglGetError()); return nullptr; } if (!eglGetConfigAttrib(display, configs[i], EGL_STENCIL_SIZE, &stencil)) { - mbgl::Log::Error(mbgl::Event::OpenGL, "eglGetConfigAttrib(EGL_STENCIL_SIZE) returned error %d", eglGetError()); + mbgl::Log::Error(mbgl::Event::OpenGL, + "eglGetConfigAttrib(EGL_STENCIL_SIZE) returned error %d", + eglGetError()); return nullptr; } if (!eglGetConfigAttrib(display, configs[i], EGL_SAMPLE_BUFFERS, &sampleBuffers)) { - mbgl::Log::Error(mbgl::Event::OpenGL, "eglGetConfigAttrib(EGL_SAMPLE_BUFFERS) returned error %d", eglGetError()); + mbgl::Log::Error(mbgl::Event::OpenGL, + "eglGetConfigAttrib(EGL_SAMPLE_BUFFERS) returned error %d", + eglGetError()); return nullptr; } if (!eglGetConfigAttrib(display, configs[i], EGL_SAMPLES, &samples)) { - mbgl::Log::Error(mbgl::Event::OpenGL, "eglGetConfigAttrib(EGL_SAMPLES) returned error %d", eglGetError()); + mbgl::Log::Error(mbgl::Event::OpenGL, + "eglGetConfigAttrib(EGL_SAMPLES) returned error %d", eglGetError()); return nullptr; } @@ -507,9 +535,9 @@ EGLConfig NativeMapView::chooseConfig(const EGLConfig configs[], EGLint numConfi EGLConfig configId = configs[i]; // Ignore formats we don't recognise - if (bufferFormat != Unknown) - { - configList.push_back(std::make_tuple(bufferFormat, depthStencilFormat, isNotConformant, isCaveat, i, configId)); + if (bufferFormat != Unknown) { + configList.push_back(std::make_tuple(bufferFormat, depthStencilFormat, + isNotConformant, isCaveat, i, configId)); } } } @@ -556,20 +584,25 @@ void NativeMapView::start() { } void NativeMapView::loadExtensions() { - const GLubyte* str = glGetString(GL_EXTENSIONS); + const GLubyte *str = glGetString(GL_EXTENSIONS); if (str == nullptr) { - mbgl::Log::Error(mbgl::Event::OpenGL, "glGetString(GL_EXTENSIONS) returned error %d", glGetError()); + mbgl::Log::Error(mbgl::Event::OpenGL, "glGetString(GL_EXTENSIONS) returned error %d", + glGetError()); return; } - std::string extensions(reinterpret_cast(str)); + std::string extensions(reinterpret_cast(str)); if (extensions.find("GL_OES_vertex_array_object") != std::string::npos) { mbgl::Log::Info(mbgl::Event::OpenGL, "Using GL_OES_vertex_array_object."); - gl::BindVertexArray = reinterpret_cast(eglGetProcAddress("glBindVertexArrayOES")); - gl::DeleteVertexArrays = reinterpret_cast(eglGetProcAddress("glDeleteVertexArraysOES")); - gl::GenVertexArrays = reinterpret_cast(eglGetProcAddress("glGenVertexArraysOES")); - gl::IsVertexArray = reinterpret_cast(eglGetProcAddress("glIsVertexArrayOES")); + gl::BindVertexArray = reinterpret_cast( + eglGetProcAddress("glBindVertexArrayOES")); + gl::DeleteVertexArrays = reinterpret_cast( + eglGetProcAddress("glDeleteVertexArraysOES")); + gl::GenVertexArrays = reinterpret_cast( + eglGetProcAddress("glGenVertexArraysOES")); + gl::IsVertexArray = + reinterpret_cast(eglGetProcAddress("glIsVertexArrayOES")); assert(gl::BindVertexArray != nullptr); assert(gl::DeleteVertexArrays != nullptr); assert(gl::GenVertexArrays != nullptr); @@ -594,8 +627,10 @@ void NativeMapView::loadExtensions() { GLint numBinaryFormats; MBGL_CHECK_ERROR(glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &numBinaryFormats)); if (numBinaryFormats > 0) { - gl::GetProgramBinary = reinterpret_cast(eglGetProcAddress("glGetProgramBinaryOES")); - gl::ProgramBinary = reinterpret_cast(eglGetProcAddress("glProgramBinaryOES")); + gl::GetProgramBinary = reinterpret_cast( + eglGetProcAddress("glGetProgramBinaryOES")); + gl::ProgramBinary = reinterpret_cast( + eglGetProcAddress("glProgramBinaryOES")); gl::ProgramParameteri = nullptr; // This does not exist until GLES 3.0 assert(gl::GetProgramBinary != nullptr); assert(gl::ProgramBinary != nullptr); @@ -603,17 +638,28 @@ void NativeMapView::loadExtensions() { } if (extensions.find("GL_KHR_debug") != std::string::npos) { - gl::DebugMessageControl = reinterpret_cast(eglGetProcAddress("glDebugMessageControl")); - gl::DebugMessageInsert = reinterpret_cast(eglGetProcAddress("glDebugMessageInsert")); - gl::DebugMessageCallback = reinterpret_cast(eglGetProcAddress("glDebugMessageCallback")); - gl::GetDebugMessageLog = reinterpret_cast(eglGetProcAddress("glGetDebugMessageLog")); - gl::GetPointerv = reinterpret_cast(eglGetProcAddress("glGetPointerv")); - gl::PushDebugGroup = reinterpret_cast(eglGetProcAddress("glPushDebugGroup")); - gl::PopDebugGroup = reinterpret_cast(eglGetProcAddress("glPopDebugGroup")); - gl::ObjectLabel = reinterpret_cast(eglGetProcAddress("glObjectLabel")); - gl::GetObjectLabel = reinterpret_cast(eglGetProcAddress("glGetObjectLabel")); - gl::ObjectPtrLabel = reinterpret_cast(eglGetProcAddress("glObjectPtrLabel")); - gl::GetObjectPtrLabel = reinterpret_cast(eglGetProcAddress("glGetObjectPtrLabel")); + gl::DebugMessageControl = reinterpret_cast( + eglGetProcAddress("glDebugMessageControl")); + gl::DebugMessageInsert = reinterpret_cast( + eglGetProcAddress("glDebugMessageInsert")); + gl::DebugMessageCallback = reinterpret_cast( + eglGetProcAddress("glDebugMessageCallback")); + gl::GetDebugMessageLog = reinterpret_cast( + eglGetProcAddress("glGetDebugMessageLog")); + gl::GetPointerv = + reinterpret_cast(eglGetProcAddress("glGetPointerv")); + gl::PushDebugGroup = + reinterpret_cast(eglGetProcAddress("glPushDebugGroup")); + gl::PopDebugGroup = + reinterpret_cast(eglGetProcAddress("glPopDebugGroup")); + gl::ObjectLabel = + reinterpret_cast(eglGetProcAddress("glObjectLabel")); + gl::GetObjectLabel = + reinterpret_cast(eglGetProcAddress("glGetObjectLabel")); + gl::ObjectPtrLabel = + reinterpret_cast(eglGetProcAddress("glObjectPtrLabel")); + gl::GetObjectPtrLabel = reinterpret_cast( + eglGetProcAddress("glGetObjectPtrLabel")); assert(gl::DebugMessageControl != nullptr); assert(gl::DebugMessageInsert != nullptr); assert(gl::DebugMessageCallback != nullptr); @@ -627,17 +673,22 @@ void NativeMapView::loadExtensions() { assert(gl::GetObjectPtrLabel != nullptr); } else { if (extensions.find("GL_EXT_debug_marker") != std::string::npos) { - gl::InsertEventMarkerEXT = reinterpret_cast(eglGetProcAddress("glInsertEventMarkerEXT")); - gl::PushGroupMarkerEXT = reinterpret_cast(eglGetProcAddress("glPushGroupMarkerEXT")); - gl::PopGroupMarkerEXT = reinterpret_cast(eglGetProcAddress("glPopGroupMarkerEXT")); + gl::InsertEventMarkerEXT = reinterpret_cast( + eglGetProcAddress("glInsertEventMarkerEXT")); + gl::PushGroupMarkerEXT = reinterpret_cast( + eglGetProcAddress("glPushGroupMarkerEXT")); + gl::PopGroupMarkerEXT = reinterpret_cast( + eglGetProcAddress("glPopGroupMarkerEXT")); assert(gl::InsertEventMarkerEXT != nullptr); assert(gl::PushGroupMarkerEXT != nullptr); assert(gl::PopGroupMarkerEXT != nullptr); } if (extensions.find("GL_EXT_debug_label") != std::string::npos) { - gl::LabelObjectEXT = reinterpret_cast(eglGetProcAddress("glLabelObjectEXT")); - gl::GetObjectLabelEXT = reinterpret_cast(eglGetProcAddress("glGetObjectLabelEXT")); + gl::LabelObjectEXT = reinterpret_cast( + eglGetProcAddress("glLabelObjectEXT")); + gl::GetObjectLabelEXT = reinterpret_cast( + eglGetProcAddress("glGetObjectLabelEXT")); assert(gl::LabelObjectEXT != nullptr); assert(gl::GetObjectLabelEXT != nullptr); } @@ -652,9 +703,9 @@ void NativeMapView::stop() { } } - void NativeMapView::pause(bool waitForPause) { - mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::pause %s", (waitForPause) ? "true" : "false"); + mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::pause %s", + (waitForPause) ? "true" : "false"); if ((display != EGL_NO_DISPLAY) && (context != EGL_NO_CONTEXT)) { map.pause(waitForPause); @@ -680,16 +731,12 @@ void NativeMapView::notifyMapChange(mbgl::MapChange, mbgl::timestamp) { assert(vm != nullptr); assert(obj != nullptr); - JavaVMAttachArgs args = { - JNI_VERSION_1_2, - "NativeMapView::notifyMapChange()", - NULL - }; + JavaVMAttachArgs args = {JNI_VERSION_1_2, "NativeMapView::notifyMapChange()", NULL}; jint ret; - JNIEnv* env = nullptr; + JNIEnv *env = nullptr; bool detach = false; - ret = vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6); + ret = vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6); if (ret != JNI_OK) { if (ret != JNI_EDETACHED) { mbgl::Log::Error(mbgl::Event::JNI, "GetEnv() failed with %i", ret); @@ -737,7 +784,7 @@ void NativeMapView::updateFps() { frames++; struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); - int64_t currentTime = now.tv_sec*1000000000LL + now.tv_nsec; + int64_t currentTime = now.tv_sec * 1000000000LL + now.tv_nsec; if (currentTime - timeElapsed >= 1) { fps = frames / ((currentTime - timeElapsed) / 1E9); @@ -749,16 +796,12 @@ void NativeMapView::updateFps() { assert(vm != nullptr); assert(obj != nullptr); - JavaVMAttachArgs args = { - JNI_VERSION_1_2, - "NativeMapView::updateFps()", - NULL - }; + JavaVMAttachArgs args = {JNI_VERSION_1_2, "NativeMapView::updateFps()", NULL}; jint ret; - JNIEnv* env = nullptr; + JNIEnv *env = nullptr; bool detach = false; - ret = vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6); + ret = vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6); if (ret != JNI_OK) { if (ret != JNI_EDETACHED) { mbgl::Log::Error(mbgl::Event::JNI, "GetEnv() failed with %i", ret); @@ -786,6 +829,5 @@ void NativeMapView::updateFps() { } env = nullptr; } - } } diff --git a/include/mbgl/android/jni.hpp b/include/mbgl/android/jni.hpp index 883f691cb..17275b896 100644 --- a/include/mbgl/android/jni.hpp +++ b/include/mbgl/android/jni.hpp @@ -27,14 +27,14 @@ extern jfieldID lonLatZoomLatId; extern jfieldID lonLatZoomZoomId; extern jclass runtimeExceptionClass; -extern jclass nullPointerExceptionClass;; +extern jclass nullPointerExceptionClass; +; extern jmethodID listToArrayId; extern jclass arrayListClass; extern jmethodID arrayListConstructorId; extern jmethodID arrayListAddId; - } } diff --git a/include/mbgl/android/native_map_view.hpp b/include/mbgl/android/native_map_view.hpp index 2f0bde4b0..fae21212c 100644 --- a/include/mbgl/android/native_map_view.hpp +++ b/include/mbgl/android/native_map_view.hpp @@ -16,7 +16,7 @@ namespace android { class NativeMapView : public mbgl::View, private mbgl::util::noncopyable { public: - NativeMapView(JNIEnv* env, jobject obj); + NativeMapView(JNIEnv *env, jobject obj); virtual ~NativeMapView(); void activate() override; @@ -27,8 +27,8 @@ public: void notify() override; void notifyMapChange(mbgl::MapChange change, mbgl::timestamp delay) override; - mbgl::Map& getMap(); - mbgl::CachingHTTPFileSource& getFileSource(); + mbgl::Map &getMap(); + mbgl::CachingHTTPFileSource &getFileSource(); bool initializeDisplay(); void terminateDisplay(); @@ -36,7 +36,7 @@ public: bool initializeContext(); void terminateContext(); - bool createSurface(ANativeWindow* window); + bool createSurface(ANativeWindow *window); void destroySurface(); void start(); @@ -54,10 +54,10 @@ private: void loadExtensions(); private: - JavaVM* vm = nullptr; + JavaVM *vm = nullptr; jobject obj = nullptr; - ANativeWindow* window = nullptr; + ANativeWindow *window = nullptr; mbgl::CachingHTTPFileSource fileSource; mbgl::Map map; @@ -79,7 +79,6 @@ private: bool fpsEnabled = false; double fps = 0.0; }; - } }