diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-07-01 12:39:21 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-07-08 10:40:05 +0200 |
commit | 675ddddee78fa36d60d55c266033f05edda4be48 (patch) | |
tree | e7e09473400600070778b620d1cd1eb0a78d7b7d /android/cpp | |
parent | 3a07cb2f1edb4e8f5e076ec0fef32f733676a95c (diff) | |
download | qtlocation-mapboxgl-675ddddee78fa36d60d55c266033f05edda4be48.tar.gz |
Make pixelRatio constant across a Map object lifetime
also moves framebuffer size out of TransformState into its own object
Diffstat (limited to 'android/cpp')
-rw-r--r-- | android/cpp/jni.cpp | 27 | ||||
-rw-r--r-- | android/cpp/native_map_view.cpp | 26 |
2 files changed, 43 insertions, 10 deletions
diff --git a/android/cpp/jni.cpp b/android/cpp/jni.cpp index 36ef273d68..cfb1291bcd 100644 --- a/android/cpp/jni.cpp +++ b/android/cpp/jni.cpp @@ -180,12 +180,12 @@ namespace { using namespace mbgl::android; jlong JNICALL -nativeCreate(JNIEnv *env, jobject obj, jstring cachePath_, jstring dataPath_, jstring apkPath_) { +nativeCreate(JNIEnv *env, jobject obj, jstring cachePath_, jstring dataPath_, jstring apkPath_, jfloat pixelRatio) { 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 = new NativeMapView(env, obj); + NativeMapView *nativeMapView = new NativeMapView(env, obj, pixelRatio); jlong mapViewPtr = reinterpret_cast<jlong>(nativeMapView); return mapViewPtr; } @@ -285,20 +285,26 @@ void JNICALL nativeOnInvalidate(JNIEnv *env, jobject obj, jlong nativeMapViewPtr nativeMapView->onInvalidate(); } -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"); +void JNICALL nativeViewResize(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jint width, jint height) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeViewResize"); assert(nativeMapViewPtr != 0); assert(width >= 0); assert(height >= 0); assert(width <= UINT16_MAX); assert(height <= UINT16_MAX); + NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); + nativeMapView->resizeView(width, height); +} + +void JNICALL nativeFramebufferResize(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jint fbWidth, jint fbHeight) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeFramebufferResize"); + assert(nativeMapViewPtr != 0); assert(fbWidth >= 0); assert(fbHeight >= 0); assert(fbWidth <= UINT16_MAX); assert(fbHeight <= UINT16_MAX); NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); - nativeMapView->getMap().resize(width, height, ratio); + nativeMapView->resizeFramebuffer(fbWidth, fbHeight); } void JNICALL nativeRemoveClass(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jstring clazz) { @@ -922,7 +928,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { } const std::vector<JNINativeMethod> methods = { - {"nativeCreate", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)J", + {"nativeCreate", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;F)J", reinterpret_cast<void *>(&nativeCreate)}, {"nativeDestroy", "(J)V", reinterpret_cast<void *>(&nativeDestroy)}, {"nativeInitializeDisplay", "(J)V", reinterpret_cast<void *>(&nativeInitializeDisplay)}, @@ -936,9 +942,12 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { {"nativeResume", "(J)V", reinterpret_cast<void *>(&nativeResume)}, {"nativeUpdate", "(J)V", reinterpret_cast<void *>(&nativeUpdate)}, {"nativeOnInvalidate", "(J)V", reinterpret_cast<void *>(&nativeOnInvalidate)}, - {"nativeResize", "(JIIFII)V", + {"nativeViewResize", "(JII)V", + reinterpret_cast<void *>(static_cast<void JNICALL ( + *)(JNIEnv *, jobject, jlong, jint, jint)>(&nativeViewResize))}, + {"nativeFramebufferResize", "(JII)V", reinterpret_cast<void *>(static_cast<void JNICALL ( - *)(JNIEnv *, jobject, jlong, jint, jint, jfloat, jint, jint)>(&nativeResize))}, + *)(JNIEnv *, jobject, jlong, jint, jint)>(&nativeFramebufferResize))}, {"nativeAddClass", "(JLjava/lang/String;)V", reinterpret_cast<void *>(&nativeAddClass)}, {"nativeRemoveClass", "(JLjava/lang/String;)V", diff --git a/android/cpp/native_map_view.cpp b/android/cpp/native_map_view.cpp index 983797767a..ebdc7f7f68 100644 --- a/android/cpp/native_map_view.cpp +++ b/android/cpp/native_map_view.cpp @@ -52,8 +52,9 @@ void log_gl_string(GLenum name, const char *label) { } } -NativeMapView::NativeMapView(JNIEnv *env, jobject obj_) +NativeMapView::NativeMapView(JNIEnv *env, jobject obj_, float pixelRatio_) : mbgl::View(*this), + pixelRatio(pixelRatio_), fileCache(mbgl::android::cachePath + "/mbgl-cache.db"), fileSource(&fileCache), map(*this, fileSource, MapMode::Continuous) { @@ -98,6 +99,18 @@ NativeMapView::~NativeMapView() { vm = nullptr; } +float NativeMapView::getPixelRatio() const { + return pixelRatio; +} + +std::array<uint16_t, 2> NativeMapView::getSize() const { + return {{ static_cast<uint16_t>(width), static_cast<uint16_t>(height) }}; +} + +std::array<uint16_t, 2> NativeMapView::getFramebufferSize() const { + return {{ static_cast<uint16_t>(fbWidth), static_cast<uint16_t>(fbHeight) }}; +} + void NativeMapView::activate() { mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::activate"); if ((display != EGL_NO_DISPLAY) && (surface != EGL_NO_SURFACE) && (context != EGL_NO_CONTEXT)) { @@ -754,5 +767,16 @@ void NativeMapView::onInvalidate() { } } +void NativeMapView::resizeView(int w, int h) { + width = w; + height = h; + map.update(mbgl::Update::Dimensions); +} + +void NativeMapView::resizeFramebuffer(int w, int h) { + fbWidth = w; + fbHeight = h; +} + } } |