summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2015-11-29 00:27:34 +0200
committerThiago Marcos P. Santos <thiago@mapbox.com>2016-03-21 23:58:48 -0300
commitbaf30cd1f776ec0a44688c12580bacf45e33c93c (patch)
tree26bd25735140f3556762a967e0f60897eecf4a4e
parentc50194ebfabd90225a65b1e85323827541a3079b (diff)
downloadqtlocation-mapboxgl-baf30cd1f776ec0a44688c12580bacf45e33c93c.tar.gz
[glfw] Main loop integration
This new code can be used for rendering on the Main thread while it will also work for rendering on the Map thread before we make the switch. Needed by #2909.
-rw-r--r--include/mbgl/platform/default/glfw_view.hpp5
-rw-r--r--include/mbgl/util/timer.hpp (renamed from src/mbgl/util/timer.hpp)0
-rw-r--r--platform/default/glfw_view.cpp17
3 files changed, 19 insertions, 3 deletions
diff --git a/include/mbgl/platform/default/glfw_view.hpp b/include/mbgl/platform/default/glfw_view.hpp
index ae5bf340d5..802f61b0c0 100644
--- a/include/mbgl/platform/default/glfw_view.hpp
+++ b/include/mbgl/platform/default/glfw_view.hpp
@@ -2,6 +2,8 @@
#define MBGL_COMMON_GLFW_VIEW
#include <mbgl/mbgl.hpp>
+#include <mbgl/util/run_loop.hpp>
+#include <mbgl/util/timer.hpp>
#ifdef MBGL_USE_GLES2
#define GLFW_INCLUDE_ES2
@@ -92,6 +94,9 @@ private:
std::function<void()> changeStyleCallback;
+ mbgl::util::RunLoop runLoop;
+ mbgl::util::Timer frameTick;
+
GLFWwindow *window = nullptr;
std::atomic_flag clean = ATOMIC_FLAG_INIT;
};
diff --git a/src/mbgl/util/timer.hpp b/include/mbgl/util/timer.hpp
index 783241847d..783241847d 100644
--- a/src/mbgl/util/timer.hpp
+++ b/include/mbgl/util/timer.hpp
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp
index 6a7e798625..e65693c4c0 100644
--- a/platform/default/glfw_view.cpp
+++ b/platform/default/glfw_view.cpp
@@ -419,8 +419,16 @@ void GLFWView::onMouseMove(GLFWwindow *window, double x, double y) {
}
void GLFWView::run() {
- while (!glfwWindowShouldClose(window)) {
- glfwWaitEvents();
+ auto callback = [&] {
+ if (glfwWindowShouldClose(window)) {
+ frameTick.stop();
+ runLoop.stop();
+
+ return;
+ }
+
+ glfwPollEvents();
+
const bool dirty = !clean.test_and_set();
if (dirty) {
const double started = glfwGetTime();
@@ -430,7 +438,10 @@ void GLFWView::run() {
map->update(mbgl::Update::Repaint);
}
}
- }
+ };
+
+ frameTick.start(mbgl::Duration::zero(), mbgl::Milliseconds(1000 / 60), callback);
+ runLoop.run();
}
float GLFWView::getPixelRatio() const {