Merge branch 'android-mason' of github.com:mapbox/mapbox-gl-native into android-mason
Conflicts: android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java
This commit is contained in:
@@ -11,9 +11,11 @@
|
||||
|
||||
#include <android/native_window_jni.h>
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#include "NativeMapView.hpp"
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/android/jni.hpp>
|
||||
#include <mbgl/android/log.hpp>
|
||||
#include <mbgl/android/native_map_view.hpp>
|
||||
#include <mbgl/platform/android/log_android.hpp>
|
||||
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
|
||||
@@ -21,6 +23,7 @@ namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
std::string cache_path;
|
||||
std::string data_path;
|
||||
|
||||
jmethodID on_map_changed_id = nullptr;
|
||||
|
||||
@@ -129,19 +132,17 @@ jobject std_vector_string_to_jobject(JNIEnv* env, std::vector<std::string> 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_) {
|
||||
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.");
|
||||
@@ -239,49 +240,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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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) {
|
||||
@@ -292,7 +293,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<NativeMapView*>(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) {
|
||||
@@ -307,79 +308,78 @@ 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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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) {
|
||||
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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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) {
|
||||
@@ -399,9 +399,7 @@ 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);
|
||||
native_map_view->getMap().setLonLat(lon, lat, duration);
|
||||
}
|
||||
|
||||
jobject JNICALL nativeGetLonLat(JNIEnv* env, jobject obj, jlong native_map_view_ptr) {
|
||||
@@ -409,7 +407,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<NativeMapView*>(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) {
|
||||
@@ -424,56 +422,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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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) {
|
||||
@@ -499,7 +497,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) {
|
||||
@@ -507,7 +505,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<NativeMapView*>(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) {
|
||||
@@ -522,126 +520,128 @@ 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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(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<NativeMapView*>(native_map_view_ptr);
|
||||
native_map_view->getMap()->setReachability(status);
|
||||
native_map_view->getMap().setReachability(status);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
mbgl::Log::Set<mbgl::AndroidLogBackend>();
|
||||
|
||||
LOG_VERBOSE("JNI_OnLoad");
|
||||
|
||||
JNIEnv* env = nullptr;
|
||||
@@ -754,7 +754,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<JNINativeMethod, 60> methods = {{ // Can remove the extra brace in C++14
|
||||
{ "nativeCreate", "(Ljava/lang/String;)J", reinterpret_cast<void*>(&nativeCreate) },
|
||||
{ "nativeCreate", "(Ljava/lang/String;Ljava/lang/String;)J", reinterpret_cast<void*>(&nativeCreate) },
|
||||
{ "nativeDestroy", "(J)V", reinterpret_cast<void*>(&nativeDestroy) },
|
||||
{ "nativeInitializeDisplay", "(J)V", reinterpret_cast<void*>(&nativeInitializeDisplay) },
|
||||
{ "nativeTerminateDisplay", "(J)V", reinterpret_cast<void*>(&nativeTerminateDisplay) },
|
||||
@@ -889,4 +889,4 @@ extern "C" JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) {
|
||||
array_list_add_id = nullptr;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
}
|
||||
@@ -5,12 +5,11 @@
|
||||
|
||||
#include <GLES2/gl2.h>
|
||||
|
||||
#include <mbgl/android/log.hpp>
|
||||
#include <mbgl/android/native_map_view.hpp>
|
||||
|
||||
#include <mbgl/platform/platform.hpp>
|
||||
#include <mbgl/platform/android/log_android.hpp>
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#include "NativeMapView.hpp"
|
||||
#include <mbgl/android/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
@@ -33,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_) : view(*this), map(view) {
|
||||
LOG_VERBOSE("NativeMapView::NativeMapView");
|
||||
|
||||
LOG_ASSERT(env != nullptr);
|
||||
@@ -49,22 +96,13 @@ NativeMapView::NativeMapView(JNIEnv* env, jobject obj_) {
|
||||
env->ExceptionDescribe();
|
||||
return;
|
||||
}
|
||||
|
||||
mbgl::Log::Set<mbgl::AndroidLogBackend>();
|
||||
|
||||
view = new MBGLView(this);
|
||||
map = new mbgl::Map(*view);
|
||||
}
|
||||
|
||||
NativeMapView::~NativeMapView() {
|
||||
LOG_VERBOSE("NativeMapView::~NativeMapView");
|
||||
terminateContext();
|
||||
|
||||
delete map;
|
||||
map = nullptr;
|
||||
|
||||
delete view;
|
||||
view = nullptr;
|
||||
destroySurface();
|
||||
terminateDisplay();
|
||||
|
||||
LOG_ASSERT(vm != nullptr);
|
||||
LOG_ASSERT(obj != nullptr);
|
||||
@@ -165,8 +203,8 @@ bool NativeMapView::initializeDisplay() {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO make_unique missing in Android NDK?
|
||||
// const std::unique_ptr<EGLConfig[]> configs = std::make_unique(new EGLConfig[num_configs]);
|
||||
// TODO: make_unique is missing in Android NDK?
|
||||
// const std::unique_ptr<EGLConfig[]> configs = std::make_unique(new EGLConfig[num_configs]);
|
||||
const std::unique_ptr<EGLConfig[]> configs(new EGLConfig[num_configs]);
|
||||
if (!eglChooseConfig(display, config_attribs, configs.get(), num_configs,
|
||||
&num_configs)) {
|
||||
@@ -195,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)) {
|
||||
@@ -241,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)) {
|
||||
@@ -477,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() {
|
||||
@@ -512,7 +546,7 @@ void NativeMapView::stop() {
|
||||
LOG_ASSERT(display != EGL_NO_DISPLAY);
|
||||
LOG_ASSERT(context != EGL_NO_CONTEXT);
|
||||
|
||||
map->stop();
|
||||
map.stop();
|
||||
}
|
||||
|
||||
|
||||
@@ -522,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() {
|
||||
@@ -532,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");
|
||||
}
|
||||
@@ -550,7 +584,6 @@ void NativeMapView::notifyMapChange() {
|
||||
NULL
|
||||
};
|
||||
|
||||
// TODO do this only once per thread?
|
||||
jint ret;
|
||||
JNIEnv* env = nullptr;
|
||||
bool detach = false;
|
||||
@@ -581,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
|
||||
@@ -2,7 +2,7 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mapbox.mapboxgl.app"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
android:versionName="0.1" >
|
||||
|
||||
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mapbox.mapboxgl.lib"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
android:versionName="0.1" >
|
||||
|
||||
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
|
||||
|
||||
|
||||
@@ -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<String> assets = new ArrayList<String>();
|
||||
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);
|
||||
|
||||
|
||||
@@ -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 = "https://mapbox.github.io/mapbox-gl-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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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',
|
||||
|
||||
37
include/mbgl/android/jni.hpp
Normal file
37
include/mbgl/android/jni.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef MBGL_ANDROID_JNI
|
||||
#define MBGL_ANDROID_JNI
|
||||
|
||||
#include <string>
|
||||
#include <jni.h>
|
||||
|
||||
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
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef LOG_H
|
||||
#define LOG_H
|
||||
#ifndef MBGL_ANDROID_LOG
|
||||
#define MBGL_ANDROID_LOG
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
@@ -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
|
||||
@@ -1,52 +1,45 @@
|
||||
#ifndef MAP_VIEW_HPP
|
||||
#define MAP_VIEW_HPP
|
||||
#ifndef MBGL_ANDROID_NATIVE_MAP_VIEW
|
||||
#define MBGL_ANDROID_NATIVE_MAP_VIEW
|
||||
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/map/view.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <string>
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <android/native_window.h>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
|
||||
#include <mbgl/mbgl.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
extern std::string cache_path;
|
||||
class NativeMapView;
|
||||
|
||||
extern jmethodID on_map_changed_id;
|
||||
class MBGLView: public mbgl::View, private mbgl::util::noncopyable {
|
||||
public:
|
||||
explicit MBGLView(NativeMapView& nativeView_) :
|
||||
nativeView(nativeView_) {
|
||||
}
|
||||
|
||||
extern jclass lon_lat_class;
|
||||
extern jmethodID lon_lat_constructor_id;
|
||||
extern jfieldID lon_lat_lon_id;
|
||||
extern jfieldID lon_lat_lat_id;
|
||||
void make_active() override;
|
||||
void make_inactive() override;
|
||||
|
||||
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;
|
||||
void swap() override;
|
||||
|
||||
extern jclass runtime_exception_class;
|
||||
void notify() override;
|
||||
void notify_map_change(mbgl::MapChange change, mbgl::timestamp delay = 0) override;
|
||||
|
||||
extern jmethodID list_to_array_id;
|
||||
private:
|
||||
NativeMapView& nativeView;
|
||||
};
|
||||
|
||||
extern jclass array_list_class;
|
||||
extern jmethodID array_list_constructor_id;
|
||||
extern jmethodID array_list_add_id;
|
||||
|
||||
class MBGLView;
|
||||
|
||||
class NativeMapView {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -79,8 +72,8 @@ private:
|
||||
|
||||
ANativeWindow* window = nullptr;
|
||||
|
||||
mbgl::Map* map = nullptr;
|
||||
MBGLView* view = nullptr;
|
||||
MBGLView view; // Must be before map
|
||||
mbgl::Map map;
|
||||
|
||||
EGLDisplay display = EGL_NO_DISPLAY;
|
||||
EGLSurface surface = EGL_NO_SURFACE;
|
||||
@@ -95,27 +88,7 @@ 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;
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
|
||||
#endif // MAP_VIEW_HPP
|
||||
#endif
|
||||
@@ -3,13 +3,14 @@
|
||||
|
||||
#include <mbgl/mbgl.hpp>
|
||||
#include <mbgl/util/time.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#ifdef NVIDIA
|
||||
#define GLFW_INCLUDE_ES2
|
||||
#endif
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
class GLFWView : public mbgl::View {
|
||||
class GLFWView : public mbgl::View, private mbgl::util::noncopyable {
|
||||
public:
|
||||
GLFWView(bool fullscreen = false);
|
||||
~GLFWView();
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#ifndef MBGL_COMMON_HEADLESS_DISPLAY
|
||||
#define MBGL_COMMON_HEADLESS_DISPLAY
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include "headless_view.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class HeadlessDisplay {
|
||||
class HeadlessDisplay, private mbgl::util::noncopyable {
|
||||
public:
|
||||
HeadlessDisplay();
|
||||
~HeadlessDisplay();
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
#define MBGL_USE_CGL 1
|
||||
#else
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <GL/glx.h>
|
||||
#include <mbgl/platform/default/glx.h>
|
||||
#define MBGL_USE_GLX 1
|
||||
#endif
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/map/view.hpp>
|
||||
#include <mbgl/platform/gl.hpp>
|
||||
|
||||
@@ -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<HeadlessDisplay> display);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <mbgl/platform/platform.hpp>
|
||||
#include "../../android/cpp/NativeMapView.hpp"
|
||||
#include <mbgl/android/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace platform {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#include <mbgl/mbgl.hpp>
|
||||
#include <mbgl/storage/http_request_baton.hpp>
|
||||
#include <mbgl/util/uv-messenger.h>
|
||||
#include <mbgl/util/time.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include "../../android/cpp/NativeMapView.hpp"
|
||||
#include <mbgl/android/jni.hpp>
|
||||
#endif
|
||||
|
||||
#include <uv.h>
|
||||
@@ -12,6 +15,20 @@
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
// 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:
|
||||
|
||||
/***************************************************************************
|
||||
@@ -423,7 +440,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.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <mbgl/util/image.hpp>
|
||||
#include <mbgl/platform/log.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
|
||||
#include <png.h>
|
||||
|
||||
@@ -9,6 +10,19 @@
|
||||
#include <cstring>
|
||||
|
||||
|
||||
// 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 {
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <mbgl/geometry/sprite_atlas.hpp>
|
||||
#include <mbgl/storage/file_source.hpp>
|
||||
#include <mbgl/platform/log.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
@@ -28,6 +29,60 @@
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <cmath>
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
// 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 <zlib.h>
|
||||
// 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 <sqlite3.h>
|
||||
// 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_)
|
||||
@@ -319,7 +374,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<Map *>(async->data);
|
||||
assert(uv_thread_self() == map->map_thread);
|
||||
@@ -334,13 +388,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
|
||||
|
||||
Reference in New Issue
Block a user