[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.
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user