From a902446e7f6d45c4b0a707f1adf4ea607b64f081 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Wed, 16 Jul 2014 18:18:04 -0700 Subject: [PATCH] refs #342 & #346: per-map change callbacks --- common/glfw_view.cpp | 10 +++--- common/glfw_view.hpp | 2 ++ common/headless_view.cpp | 16 +++------- common/headless_view.hpp | 2 ++ include/llmr/map/transform.hpp | 5 ++- include/llmr/map/view.hpp | 20 ++++++++++++ include/llmr/platform/platform.hpp | 18 ----------- ios/mapbox-gl-cocoa | 2 +- src/map/map.cpp | 2 +- src/map/transform.cpp | 50 ++++++++++++++++-------------- 10 files changed, 64 insertions(+), 63 deletions(-) diff --git a/common/glfw_view.cpp b/common/glfw_view.cpp index 0d26928e0..ae992d926 100644 --- a/common/glfw_view.cpp +++ b/common/glfw_view.cpp @@ -1,7 +1,5 @@ #include "glfw_view.hpp" -#include - GLFWView::GLFWView(bool fullscreen) : fullscreen(fullscreen) { #ifdef NVIDIA glDiscardFramebufferEXT = (PFNGLDISCARDFRAMEBUFFEREXTPROC)glfwGetProcAddress("glDiscardFramebufferEXT"); @@ -196,6 +194,10 @@ void GLFWView::swap() { glfwPostEmptyEvent(); } +void GLFWView::notify_map_change(llmr::MapChange change, llmr::timestamp delay) { + // no-op +} + void GLFWView::fps() { static int frames = 0; static double time_elapsed = 0; @@ -283,9 +285,5 @@ void show_color_debug_image(std::string name, const char *data, size_t logical_w } #endif -void notify_map_change(MapChange change, timestamp delay) { - // no-op -} - } } diff --git a/common/glfw_view.hpp b/common/glfw_view.hpp index 62da124ca..05a406328 100644 --- a/common/glfw_view.hpp +++ b/common/glfw_view.hpp @@ -2,6 +2,7 @@ #define LLMR_COMMON_GLFW_VIEW #include +#include #ifdef NVIDIA #define GLFW_INCLUDE_ES2 @@ -18,6 +19,7 @@ public: void initialize(llmr::Map *map); void swap(); void make_active(); + void notify_map_change(llmr::MapChange change, llmr::timestamp delay = 0); static void key(GLFWwindow *window, int key, int scancode, int action, int mods); static void scroll(GLFWwindow *window, double xoffset, double yoffset); diff --git a/common/headless_view.cpp b/common/headless_view.cpp index 2ca804664..6c4054303 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -1,17 +1,5 @@ #include "headless_view.hpp" -#include #include -#include - -namespace llmr { - -namespace platform { - -void notify_map_change(MapChange change, timestamp delay) { - // no-op -} - -} HeadlessView::HeadlessView() { #if LLMR_USE_CGL @@ -161,6 +149,10 @@ HeadlessView::~HeadlessView() { #endif } +void HeadlessView::notify_map_change(llmr::MapChange change, llmr::timestamp delay) { + // no-op +} + void HeadlessView::make_active() { #if LLMR_USE_CGL CGLError error = CGLSetCurrentContext(gl_context); diff --git a/common/headless_view.hpp b/common/headless_view.hpp index b3e1c11b9..efbc08df1 100644 --- a/common/headless_view.hpp +++ b/common/headless_view.hpp @@ -10,6 +10,7 @@ #include #include +#include namespace llmr { @@ -20,6 +21,7 @@ public: void resize(int width, int height); + void notify_map_change(MapChange change, timestamp delay = 0); void make_active(); void swap(); unsigned int root_fbo(); diff --git a/include/llmr/map/transform.hpp b/include/llmr/map/transform.hpp index c4474ff02..16e5b21e8 100644 --- a/include/llmr/map/transform.hpp +++ b/include/llmr/map/transform.hpp @@ -5,6 +5,7 @@ #include #include +#include "view.hpp" #include "transform_state.hpp" #include @@ -15,7 +16,7 @@ struct box; class Transform : private util::noncopyable { public: - Transform(); + Transform(View &view); // Map view // Note: width * ratio does not necessarily equal fb_width @@ -74,6 +75,8 @@ private: void constrain(double& scale, double& y) const; private: + View &view; + mutable uv::rwlock mtx; // This reflects the current state of the transform, representing the actual position of the diff --git a/include/llmr/map/view.hpp b/include/llmr/map/view.hpp index d032f783c..d1fa58aa7 100644 --- a/include/llmr/map/view.hpp +++ b/include/llmr/map/view.hpp @@ -1,10 +1,25 @@ #ifndef LLMR_MAP_VIEW #define LLMR_MAP_VIEW +#include + namespace llmr { class Map; +enum MapChange : uint8_t { + MapChangeRegionWillChange = 0, + MapChangeRegionWillChangeAnimated = 1, + MapChangeRegionDidChange = 2, + MapChangeRegionDidChangeAnimated = 3, + MapChangeWillStartLoadingMap = 4, + MapChangeDidFinishLoadingMap = 5, + MapChangeDidFailLoadingMap = 6, + MapChangeWillStartRenderingMap = 7, + MapChangeDidFinishRenderingMap = 8, + MapChangeDidFinishRenderingMapFullyRendered = 9 +}; + class View { public: virtual void initialize(Map *map) { @@ -26,6 +41,11 @@ public: return 0; } + // Notifies a watcher of map x/y/scale/rotation changes. + // Must only be called from the same thread that caused the change. + // Must not be called from the render thread. + virtual void notify_map_change(MapChange change, timestamp delay = 0) = 0; + protected: llmr::Map *map = nullptr; }; diff --git a/include/llmr/platform/platform.hpp b/include/llmr/platform/platform.hpp index 540f22619..30c6e048b 100644 --- a/include/llmr/platform/platform.hpp +++ b/include/llmr/platform/platform.hpp @@ -1,8 +1,6 @@ #ifndef LLMR_PLATFORM_PLATFORM #define LLMR_PLATFORM_PLATFORM -#include - #include #include #include @@ -26,19 +24,6 @@ struct Response { std::function callback; }; -enum MapChange : uint8_t { - MapChangeRegionWillChange = 0, - MapChangeRegionWillChangeAnimated = 1, - MapChangeRegionDidChange = 2, - MapChangeRegionDidChangeAnimated = 3, - MapChangeWillStartLoadingMap = 4, - MapChangeDidFinishLoadingMap = 5, - MapChangeDidFailLoadingMap = 6, - MapChangeWillStartRenderingMap = 7, - MapChangeDidFinishRenderingMap = 8, - MapChangeDidFinishRenderingMapFullyRendered = 9 -}; - // Makes an HTTP request of a URL, preferrably on a background thread, and calls a function with the // results in the original thread (which runs the libuv loop). // If the loop pointer is NULL, the callback function will be called on an arbitrary thread. @@ -50,9 +35,6 @@ std::shared_ptr request_http(const std::string &url, // Cancels an HTTP request. void cancel_request_http(const std::shared_ptr &req); -// Notifies a watcher of map changes. -void notify_map_change(MapChange key, timestamp delay = 0); - // Shows an alpha image with the specified dimensions in a named window. void show_debug_image(std::string name, const char *data, size_t width, size_t height); diff --git a/ios/mapbox-gl-cocoa b/ios/mapbox-gl-cocoa index fcb1de181..84c3383dc 160000 --- a/ios/mapbox-gl-cocoa +++ b/ios/mapbox-gl-cocoa @@ -1 +1 @@ -Subproject commit fcb1de1812fcf460712c210bdbfe9372ce341e34 +Subproject commit 84c3383dc4394e544268547b3d6bf252fc6a2728 diff --git a/src/map/map.cpp b/src/map/map.cpp index 4d374f1d5..2086ad54b 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -22,7 +22,7 @@ using namespace llmr; Map::Map(View& view) : view(view), - transform(), + transform(view), style(std::make_shared