diff options
author | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2018-01-25 02:19:36 +0200 |
---|---|---|
committer | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2018-02-09 20:28:54 +0200 |
commit | bb00f558fb31f000eefa1bb825bb580445cedc10 (patch) | |
tree | d16f76e2a2b96f23133ca0b0edaf24031416da80 /platform | |
parent | a062f3e17b6f42252a283b50bd36de3411571b7d (diff) | |
download | qtlocation-mapboxgl-bb00f558fb31f000eefa1bb825bb580445cedc10.tar.gz |
[qt] Make MapboxGLMapRenderer a scheduler to receive messages when rendering
Diffstat (limited to 'platform')
-rw-r--r-- | platform/qt/src/qmapboxgl_map_renderer.cpp | 26 | ||||
-rw-r--r-- | platform/qt/src/qmapboxgl_map_renderer.hpp | 9 |
2 files changed, 32 insertions, 3 deletions
diff --git a/platform/qt/src/qmapboxgl_map_renderer.cpp b/platform/qt/src/qmapboxgl_map_renderer.cpp index a343d56668..65fb37f094 100644 --- a/platform/qt/src/qmapboxgl_map_renderer.cpp +++ b/platform/qt/src/qmapboxgl_map_renderer.cpp @@ -12,6 +12,12 @@ QMapboxGLMapRenderer::~QMapboxGLMapRenderer() { } +void QMapboxGLMapRenderer::schedule(std::weak_ptr<mbgl::Mailbox> mailbox) +{ + std::lock_guard<std::mutex> lock(m_taskQueueMutex); + m_taskQueue.push(mailbox); +} + void QMapboxGLMapRenderer::updateParameters(std::shared_ptr<mbgl::UpdateParameters> newParameters) { std::lock_guard<std::mutex> lock(m_updateMutex); @@ -29,8 +35,11 @@ void QMapboxGLMapRenderer::render() std::shared_ptr<mbgl::UpdateParameters> params; { // Lock on the parameters - std::unique_lock<std::mutex> lock(m_updateMutex); - if (!m_updateParameters) return; + std::lock_guard<std::mutex> lock(m_updateMutex); + + if (!m_updateParameters) { + return; + } // Hold on to the update parameters during render params = m_updateParameters; @@ -39,7 +48,20 @@ void QMapboxGLMapRenderer::render() // The OpenGL implementation automatically enables the OpenGL context for us. mbgl::BackendScope scope(m_backend, mbgl::BackendScope::ScopeType::Implicit); + Scheduler::SetCurrent(this); + m_renderer->render(*params); + + std::queue<std::weak_ptr<mbgl::Mailbox>> taskQueue; + { + std::unique_lock<std::mutex> lock(m_taskQueueMutex); + std::swap(taskQueue, m_taskQueue); + } + + while (!taskQueue.empty()) { + mbgl::Mailbox::maybeReceive(taskQueue.front()); + taskQueue.pop(); + } } void QMapboxGLMapRenderer::setObserver(std::shared_ptr<mbgl::RendererObserver> observer) diff --git a/platform/qt/src/qmapboxgl_map_renderer.hpp b/platform/qt/src/qmapboxgl_map_renderer.hpp index 5769432f0f..e5ead3df32 100644 --- a/platform/qt/src/qmapboxgl_map_renderer.hpp +++ b/platform/qt/src/qmapboxgl_map_renderer.hpp @@ -11,6 +11,7 @@ #include <memory> #include <mutex> +#include <queue> namespace mbgl { class Renderer; @@ -19,13 +20,16 @@ class UpdateParameters; class QMapboxGLRendererBackend; -class QMapboxGLMapRenderer +class QMapboxGLMapRenderer : public mbgl::Scheduler { public: QMapboxGLMapRenderer(qreal pixelRatio, mbgl::DefaultFileSource &, mbgl::ThreadPool &, QMapboxGLSettings::GLContextMode); virtual ~QMapboxGLMapRenderer(); + // mbgl::Scheduler implementation. + void schedule(std::weak_ptr<mbgl::Mailbox> scheduled) final; + void render(); void setObserver(std::shared_ptr<mbgl::RendererObserver>); @@ -41,4 +45,7 @@ private: QMapboxGLRendererBackend m_backend; std::unique_ptr<mbgl::Renderer> m_renderer; + + std::mutex m_taskQueueMutex; + std::queue<std::weak_ptr<mbgl::Mailbox>> m_taskQueue; }; |