diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-02-05 14:58:20 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-03-06 13:52:25 +0100 |
commit | fb44fc81bdab09d079ed27e22b86718627ded48b (patch) | |
tree | 2a4e7c80eb49624c0b548d7bd33401792da1faa4 | |
parent | 0151fe6c01367ef03a2ff282b90e32dd3785a7c2 (diff) | |
download | qtlocation-mapboxgl-fb44fc81bdab09d079ed27e22b86718627ded48b.tar.gz |
make Map::resize() private
they can only be called by View::resize
-rw-r--r-- | android/cpp/jni.cpp | 20 | ||||
-rw-r--r-- | android/cpp/native_map_view.cpp | 5 | ||||
-rw-r--r-- | android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/NativeMapView.java | 29 | ||||
-rw-r--r-- | include/mbgl/android/native_map_view.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/map/map.hpp | 10 | ||||
-rw-r--r-- | include/mbgl/map/view.hpp | 4 | ||||
-rw-r--r-- | include/mbgl/platform/default/glfw_view.hpp | 10 | ||||
-rw-r--r-- | platform/default/glfw_view.cpp | 26 | ||||
-rw-r--r-- | platform/default/headless_view.cpp | 4 | ||||
-rw-r--r-- | platform/ios/MGLMapView.mm | 8 | ||||
-rw-r--r-- | src/mbgl/map/view.cpp | 11 | ||||
-rw-r--r-- | test/headless/headless.cpp | 1 |
12 files changed, 57 insertions, 73 deletions
diff --git a/android/cpp/jni.cpp b/android/cpp/jni.cpp index 37c790a426..1163c33b57 100644 --- a/android/cpp/jni.cpp +++ b/android/cpp/jni.cpp @@ -327,18 +327,6 @@ void JNICALL nativeSwapped(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { } 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<NativeMapView *>(nativeMapViewPtr); - 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) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeResize"); assert(nativeMapViewPtr != 0); @@ -351,7 +339,7 @@ void JNICALL nativeResize(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jint assert(fbWidth <= UINT16_MAX); assert(fbHeight <= UINT16_MAX); NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); - nativeMapView->getMap().resize(width, height, ratio, fbWidth, fbHeight); + nativeMapView->resize(width, height, ratio, fbWidth, fbHeight); } void JNICALL nativeRemoveClass(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jstring clazz) { @@ -1014,7 +1002,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, 67> methods = {{ // Can remove the extra brace in C++14 + std::array<JNINativeMethod, 66> methods = {{ // Can remove the extra brace in C++14 {"nativeCreate", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)J", reinterpret_cast<void *>(&nativeCreate)}, {"nativeDestroy", "(J)V", reinterpret_cast<void *>(&nativeDestroy)}, @@ -1035,10 +1023,6 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { {"nativeTerminate", "(J)V", reinterpret_cast<void *>(&nativeTerminate)}, {"nativeNeedsSwap", "(J)Z", reinterpret_cast<void *>(&nativeNeedsSwap)}, {"nativeSwapped", "(J)V", reinterpret_cast<void *>(&nativeSwapped)}, - {"nativeResize", "(JIIF)V", - reinterpret_cast<void *>( - static_cast<void JNICALL (*)(JNIEnv *, jobject, jlong, jint, jint, jfloat)>( - &nativeResize))}, {"nativeResize", "(JIIFII)V", reinterpret_cast<void *>(static_cast<void JNICALL ( *)(JNIEnv *, jobject, jlong, jint, jint, jfloat, jint, jint)>(&nativeResize))}, diff --git a/android/cpp/native_map_view.cpp b/android/cpp/native_map_view.cpp index cd3445e24e..599f245989 100644 --- a/android/cpp/native_map_view.cpp +++ b/android/cpp/native_map_view.cpp @@ -823,5 +823,10 @@ void NativeMapView::updateFps() { } env = nullptr; } + +void NativeMapView::resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight) { + View::resize(width, height, ratio, fbWidth, fbHeight); +} + } } diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/NativeMapView.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/NativeMapView.java index ffb439737e..a73a89d2d7 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/NativeMapView.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/NativeMapView.java @@ -113,32 +113,6 @@ class NativeMapView { nativeSwapped(mNativeMapViewPtr); } - public void resize(int width, int height) { - resize(width, height, 1.0f); - } - - public void resize(int width, int height, float ratio) { - if (width < 0) { - throw new IllegalArgumentException("width cannot be negative."); - } - - if (height < 0) { - throw new IllegalArgumentException("height cannot be negative."); - } - - if (width > 65535) { - throw new IllegalArgumentException( - "width cannot be greater than 65535."); - } - - if (height > 65535) { - throw new IllegalArgumentException( - "height cannot be greater than 65535."); - } - - nativeResize(mNativeMapViewPtr, width, height, ratio); - } - public void resize(int width, int height, float ratio, int fbWidth, int fbHeight) { if (width < 0) { @@ -477,9 +451,6 @@ class NativeMapView { private native void nativeSwapped(long nativeMapViewPtr); private native void nativeResize(long nativeMapViewPtr, int width, - int height, float ratio); - - private native void nativeResize(long nativeMapViewPtr, int width, int height, float ratio, int fbWidth, int fbHeight); private native void nativeAddClass(long nativeMapViewPtr, String clazz); diff --git a/include/mbgl/android/native_map_view.hpp b/include/mbgl/android/native_map_view.hpp index bfe544c2b0..eb5f295eaf 100644 --- a/include/mbgl/android/native_map_view.hpp +++ b/include/mbgl/android/native_map_view.hpp @@ -49,6 +49,8 @@ public: void enableFps(bool enable); void updateFps(); + void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight); + private: EGLConfig chooseConfig(const EGLConfig configs[], EGLint numConfigs); diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index fed68cb08a..ed156c5d22 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -43,6 +43,8 @@ struct exception : std::runtime_error { }; class Map : private util::noncopyable { + friend class View; + public: explicit Map(View&, FileSource&); ~Map(); @@ -80,10 +82,6 @@ public: bool needsSwap(); void swapped(); - // Size - void resize(uint16_t width, uint16_t height, float ratio = 1); - void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight); - // Styling void addClass(const std::string&); void removeClass(const std::string&); @@ -152,6 +150,10 @@ public: inline std::chrono::steady_clock::time_point getTime() const { return animationTime; } private: + // This may only be called by the View object. + void resize(uint16_t width, uint16_t height, float ratio = 1); + void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight); + util::ptr<Sprite> getSprite(); uv::worker& getWorker(); diff --git a/include/mbgl/map/view.hpp b/include/mbgl/map/view.hpp index b94b8c0b93..7d8c25f445 100644 --- a/include/mbgl/map/view.hpp +++ b/include/mbgl/map/view.hpp @@ -47,6 +47,10 @@ public: virtual void notifyMapChange(MapChange change, std::chrono::steady_clock::duration delay = std::chrono::steady_clock::duration::zero()) = 0; protected: + // Resizes the view + void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight); + +protected: mbgl::Map *map = nullptr; }; } diff --git a/include/mbgl/platform/default/glfw_view.hpp b/include/mbgl/platform/default/glfw_view.hpp index 7156d4ff1f..8f5cfb7281 100644 --- a/include/mbgl/platform/default/glfw_view.hpp +++ b/include/mbgl/platform/default/glfw_view.hpp @@ -20,11 +20,11 @@ public: void notify(); void notifyMapChange(mbgl::MapChange change, std::chrono::steady_clock::duration delay = std::chrono::steady_clock::duration::zero()); - static void key(GLFWwindow *window, int key, int scancode, int action, int mods); - static void scroll(GLFWwindow *window, double xoffset, double yoffset); - static void resize(GLFWwindow *window, int width, int height); - static void mouseClick(GLFWwindow *window, int button, int action, int modifiers); - static void mouseMove(GLFWwindow *window, double x, double y); + static void onKey(GLFWwindow *window, int key, int scancode, int action, int mods); + static void onScroll(GLFWwindow *window, double xoffset, double yoffset); + static void onResize(GLFWwindow *window, int width, int height); + static void onMouseClick(GLFWwindow *window, int button, int action, int modifiers); + static void onMouseMove(GLFWwindow *window, double x, double y); static void eventloop(void *arg); diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp index 8306229d4a..865636aebf 100644 --- a/platform/default/glfw_view.cpp +++ b/platform/default/glfw_view.cpp @@ -62,14 +62,14 @@ void GLFWView::initialize(mbgl::Map *map_) { int width, height; glfwGetWindowSize(window, &width, &height); - resize(window, width, height); + onResize(window, width, height); - glfwSetCursorPosCallback(window, mouseMove); - glfwSetMouseButtonCallback(window, mouseClick); - glfwSetWindowSizeCallback(window, resize); - glfwSetFramebufferSizeCallback(window, resize); - glfwSetScrollCallback(window, scroll); - glfwSetKeyCallback(window, key); + glfwSetCursorPosCallback(window, onMouseMove); + glfwSetMouseButtonCallback(window, onMouseClick); + glfwSetWindowSizeCallback(window, onResize); + glfwSetFramebufferSizeCallback(window, onResize); + glfwSetScrollCallback(window, onScroll); + glfwSetKeyCallback(window, onKey); const std::string extensions = reinterpret_cast<const char *>(MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS))); { @@ -157,7 +157,7 @@ void GLFWView::initialize(mbgl::Map *map_) { glfwMakeContextCurrent(nullptr); } -void GLFWView::key(GLFWwindow *window, int key, int /*scancode*/, int action, int mods) { +void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, int mods) { GLFWView *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window)); if (action == GLFW_RELEASE) { @@ -190,7 +190,7 @@ void GLFWView::key(GLFWwindow *window, int key, int /*scancode*/, int action, in } } -void GLFWView::scroll(GLFWwindow *window, double /*xOffset*/, double yOffset) { +void GLFWView::onScroll(GLFWwindow *window, double /*xOffset*/, double yOffset) { GLFWView *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window)); double delta = yOffset * 40; @@ -213,16 +213,16 @@ void GLFWView::scroll(GLFWwindow *window, double /*xOffset*/, double yOffset) { view->map->scaleBy(scale, view->lastX, view->lastY); } -void GLFWView::resize(GLFWwindow *window, int width, int height ) { +void GLFWView::onResize(GLFWwindow *window, int width, int height ) { GLFWView *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window)); int fbWidth, fbHeight; glfwGetFramebufferSize(window, &fbWidth, &fbHeight); - view->map->resize(width, height, static_cast<float>(fbWidth) / static_cast<float>(width), fbWidth, fbHeight); + view->resize(width, height, static_cast<float>(fbWidth) / static_cast<float>(width), fbWidth, fbHeight); } -void GLFWView::mouseClick(GLFWwindow *window, int button, int action, int modifiers) { +void GLFWView::onMouseClick(GLFWwindow *window, int button, int action, int modifiers) { GLFWView *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window)); if (button == GLFW_MOUSE_BUTTON_RIGHT || @@ -249,7 +249,7 @@ void GLFWView::mouseClick(GLFWwindow *window, int button, int action, int modifi } } -void GLFWView::mouseMove(GLFWwindow *window, double x, double y) { +void GLFWView::onMouseMove(GLFWwindow *window, double x, double y) { GLFWView *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window)); if (view->tracking) { double dx = x - view->lastX; diff --git a/platform/default/headless_view.cpp b/platform/default/headless_view.cpp index 656a774390..a3128234ea 100644 --- a/platform/default/headless_view.cpp +++ b/platform/default/headless_view.cpp @@ -131,7 +131,7 @@ void HeadlessView::createContext() { #endif } -void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) { +void HeadlessView::resize(const uint16_t width, const uint16_t height, const float pixelRatio) { clearBuffers(); width_ = width; @@ -177,6 +177,8 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) { throw std::runtime_error(error.str()); } + View::resize(width, height, pixelRatio, w, h); + deactivate(); } diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index e68ba6c93f..b1932737b7 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -239,7 +239,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; mbglFileCache = new mbgl::SQLiteCache(defaultCacheDatabase()); mbglFileSource = new mbgl::DefaultFileSource(mbglFileCache); mbglMap = new mbgl::Map(*mbglView, *mbglFileSource); - mbglMap->resize(self.bounds.size.width, self.bounds.size.height, _glView.contentScaleFactor, _glView.drawableWidth, _glView.drawableHeight); + mbglView->resize(self.bounds.size.width, self.bounds.size.height, _glView.contentScaleFactor, _glView.drawableWidth, _glView.drawableHeight); // Notify map object when network reachability status changes. [[NSNotificationCenter defaultCenter] addObserver:self @@ -489,7 +489,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; - (void)glkView:(GLKView *)view drawInRect:(CGRect)rect { - mbglMap->resize(rect.size.width, rect.size.height, view.contentScaleFactor, view.drawableWidth, view.drawableHeight); + mbglView->resize(rect.size.width, rect.size.height, view.contentScaleFactor, view.drawableWidth, view.drawableHeight); } - (void)layoutSubviews @@ -1631,6 +1631,10 @@ class MBGLView : public mbgl::View [EAGLContext setCurrentContext:nil]; } + void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight) { + View::resize(width, height, ratio, fbWidth, fbHeight); + } + void swap() { [nativeView performSelectorOnMainThread:@selector(swap) diff --git a/src/mbgl/map/view.cpp b/src/mbgl/map/view.cpp new file mode 100644 index 0000000000..3927652ba6 --- /dev/null +++ b/src/mbgl/map/view.cpp @@ -0,0 +1,11 @@ +#include <mbgl/map/view.hpp> +#include <mbgl/map/map.hpp> + +namespace mbgl { + +void View::resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight) { + assert(map); + map->resize(width, height, ratio, fbWidth, fbHeight); +} + +} diff --git a/test/headless/headless.cpp b/test/headless/headless.cpp index b92002aa23..bf04cbcb4b 100644 --- a/test/headless/headless.cpp +++ b/test/headless/headless.cpp @@ -146,7 +146,6 @@ TEST_P(HeadlessTest, render) { map.setStyleJSON(style, "test/suite"); view.resize(width, height, pixelRatio); - map.resize(width, height, pixelRatio); map.setLatLngZoom(mbgl::LatLng(latitude, longitude), zoom); map.setBearing(bearing); |