summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/glfw_view.cpp10
-rw-r--r--common/glfw_view.hpp2
-rw-r--r--common/headless_view.cpp16
-rw-r--r--common/headless_view.hpp2
-rw-r--r--include/llmr/map/transform.hpp5
-rw-r--r--include/llmr/map/view.hpp20
-rw-r--r--include/llmr/platform/platform.hpp18
m---------ios/mapbox-gl-cocoa0
-rw-r--r--src/map/map.cpp2
-rw-r--r--src/map/transform.cpp50
10 files changed, 63 insertions, 62 deletions
diff --git a/common/glfw_view.cpp b/common/glfw_view.cpp
index 0d26928e08..ae992d9268 100644
--- a/common/glfw_view.cpp
+++ b/common/glfw_view.cpp
@@ -1,7 +1,5 @@
#include "glfw_view.hpp"
-#include <llmr/util/time.hpp>
-
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 62da124caa..05a4063289 100644
--- a/common/glfw_view.hpp
+++ b/common/glfw_view.hpp
@@ -2,6 +2,7 @@
#define LLMR_COMMON_GLFW_VIEW
#include <llmr/llmr.hpp>
+#include <llmr/util/time.hpp>
#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 2ca804664e..6c4054303a 100644
--- a/common/headless_view.cpp
+++ b/common/headless_view.cpp
@@ -1,17 +1,5 @@
#include "headless_view.hpp"
-#include <llmr/util/time.hpp>
#include <llmr/util/timer.hpp>
-#include <llmr/platform/platform.hpp>
-
-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 b3e1c11b9b..efbc08df1b 100644
--- a/common/headless_view.hpp
+++ b/common/headless_view.hpp
@@ -10,6 +10,7 @@
#include <llmr/map/view.hpp>
#include <llmr/platform/gl.hpp>
+#include <llmr/util/time.hpp>
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 c4474ff024..16e5b21e87 100644
--- a/include/llmr/map/transform.hpp
+++ b/include/llmr/map/transform.hpp
@@ -5,6 +5,7 @@
#include <llmr/util/noncopyable.hpp>
#include <llmr/util/uv.hpp>
+#include "view.hpp"
#include "transform_state.hpp"
#include <forward_list>
@@ -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 d032f783cb..d1fa58aa71 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 <llmr/util/time.hpp>
+
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 540f226195..30c6e048bc 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 <llmr/util/time.hpp>
-
#include <memory>
#include <functional>
#include <string>
@@ -26,19 +24,6 @@ struct Response {
std::function<void(Response *)> 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> request_http(const std::string &url,
// Cancels an HTTP request.
void cancel_request_http(const std::shared_ptr<Request> &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
-Subproject fcb1de1812fcf460712c210bdbfe9372ce341e3
+Subproject 84c3383dc4394e544268547b3d6bf252fc6a272
diff --git a/src/map/map.cpp b/src/map/map.cpp
index 4d374f1d5e..2086ad54b7 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<Style>()),
glyphAtlas(std::make_shared<GlyphAtlas>(1024, 1024)),
spriteAtlas(std::make_shared<SpriteAtlas>(512, 512)),
diff --git a/src/map/transform.cpp b/src/map/transform.cpp
index 46ddc237cf..f6623485f9 100644
--- a/src/map/transform.cpp
+++ b/src/map/transform.cpp
@@ -14,7 +14,9 @@ const double R2D = 180.0 / M_PI;
const double M2PI = 2 * M_PI;
const double MIN_ROTATE_SCALE = 8;
-Transform::Transform() {
+Transform::Transform(View &view)
+ : view(view) {
+
setScale(current.scale);
setAngle(current.angle);
}
@@ -28,7 +30,7 @@ bool Transform::resize(const uint16_t w, const uint16_t h, const float ratio,
if (final.width != w || final.height != h || final.pixelRatio != ratio ||
final.framebuffer[0] != fb_w || final.framebuffer[1] != fb_h) {
- platform::notify_map_change(platform::MapChangeRegionWillChange);
+ view.notify_map_change(MapChangeRegionWillChange);
current.width = final.width = w;
current.height = final.height = h;
@@ -38,7 +40,7 @@ bool Transform::resize(const uint16_t w, const uint16_t h, const float ratio,
if (!canRotate() && current.angle) _setAngle(0);
constrain(current.scale, current.y);
- platform::notify_map_change(platform::MapChangeRegionDidChange);
+ view.notify_map_change(MapChangeRegionDidChange);
return true;
} else {
@@ -57,9 +59,9 @@ void Transform::moveBy(const double dx, const double dy, const timestamp duratio
void Transform::_moveBy(const double dx, const double dy, const timestamp duration) {
// This is only called internally, so we don't need a lock here.
- platform::notify_map_change(duration ?
- platform::MapChangeRegionWillChangeAnimated :
- platform::MapChangeRegionWillChange);
+ view.notify_map_change(duration ?
+ MapChangeRegionWillChangeAnimated :
+ MapChangeRegionWillChange);
final.x = current.x + std::cos(current.angle) * dx + std::sin(current.angle) * dy;
final.y = current.y + std::cos(current.angle) * dy + std::sin(-current.angle) * dx;
@@ -84,10 +86,10 @@ void Transform::_moveBy(const double dx, const double dy, const timestamp durati
std::make_shared<util::ease_transition<double>>(current.y, final.y, current.y, start, duration));
}
- platform::notify_map_change(duration ?
- platform::MapChangeRegionDidChangeAnimated :
- platform::MapChangeRegionDidChange,
- duration);
+ view.notify_map_change(duration ?
+ MapChangeRegionDidChangeAnimated :
+ MapChangeRegionDidChange,
+ duration);
}
void Transform::setLonLat(const double lon, const double lat, const timestamp duration) {
@@ -276,9 +278,9 @@ void Transform::_setScaleXY(const double new_scale, const double xn, const doubl
const timestamp duration) {
// This is only called internally, so we don't need a lock here.
- platform::notify_map_change(duration ?
- platform::MapChangeRegionWillChangeAnimated :
- platform::MapChangeRegionWillChange);
+ view.notify_map_change(duration ?
+ MapChangeRegionWillChangeAnimated :
+ MapChangeRegionWillChange);
final.scale = new_scale;
final.x = xn;
@@ -309,10 +311,10 @@ void Transform::_setScaleXY(const double new_scale, const double xn, const doubl
Bc = s / 360;
Cc = s / (2 * M_PI);
- platform::notify_map_change(duration ?
- platform::MapChangeRegionDidChangeAnimated :
- platform::MapChangeRegionDidChange,
- duration);
+ view.notify_map_change(duration ?
+ MapChangeRegionDidChangeAnimated :
+ MapChangeRegionDidChange,
+ duration);
}
#pragma mark - Constraints
@@ -388,9 +390,9 @@ void Transform::setAngle(const double new_angle, const double cx, const double c
void Transform::_setAngle(double new_angle, const timestamp duration) {
// This is only called internally, so we don't need a lock here.
- platform::notify_map_change(duration ?
- platform::MapChangeRegionWillChangeAnimated :
- platform::MapChangeRegionWillChange);
+ view.notify_map_change(duration ?
+ MapChangeRegionWillChangeAnimated :
+ MapChangeRegionWillChange);
while (new_angle > M_PI)
new_angle -= M2PI;
@@ -410,10 +412,10 @@ void Transform::_setAngle(double new_angle, const timestamp duration) {
current.angle, final.angle, current.angle, start, duration));
}
- platform::notify_map_change(duration ?
- platform::MapChangeRegionDidChangeAnimated :
- platform::MapChangeRegionDidChange,
- duration);
+ view.notify_map_change(duration ?
+ MapChangeRegionDidChangeAnimated :
+ MapChangeRegionDidChange,
+ duration);
}
double Transform::getAngle() const {