summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2018-01-26 00:42:03 +0200
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2018-01-26 22:22:57 +0200
commit655f2c2b6f54c361ab69fce069fe8efc00ec2113 (patch)
treefd1e740b8829a8a527a8edd9dc6f346e1dd77b9e
parentd2f1c36ad0c42a06841c90311b587749a6126d8b (diff)
downloadqtlocation-mapboxgl-655f2c2b6f54c361ab69fce069fe8efc00ec2113.tar.gz
[qt] Only use the MapRenderer as scheduler if there is no other
Optimization of when running on the Main Thread that has a RunLoop.
-rw-r--r--platform/qt/src/qmapboxgl_map_renderer.cpp26
-rw-r--r--platform/qt/src/qmapboxgl_map_renderer.hpp2
2 files changed, 19 insertions, 9 deletions
diff --git a/platform/qt/src/qmapboxgl_map_renderer.cpp b/platform/qt/src/qmapboxgl_map_renderer.cpp
index 65fb37f094..81293d7da1 100644
--- a/platform/qt/src/qmapboxgl_map_renderer.cpp
+++ b/platform/qt/src/qmapboxgl_map_renderer.cpp
@@ -5,6 +5,7 @@
QMapboxGLMapRenderer::QMapboxGLMapRenderer(qreal pixelRatio,
mbgl::DefaultFileSource &fs, mbgl::ThreadPool &tp, QMapboxGLSettings::GLContextMode mode)
: m_renderer(std::make_unique<mbgl::Renderer>(m_backend, pixelRatio, fs, tp, static_cast<mbgl::GLContextMode>(mode)))
+ , m_threadWithScheduler(Scheduler::GetCurrent() != nullptr)
{
}
@@ -48,19 +49,26 @@ 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);
+ // If we don't have a Scheduler on this thread, which
+ // is usually the case for render threads, use this
+ // object as scheduler.
+ if (!m_threadWithScheduler) {
+ 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);
- }
+ if (!m_threadWithScheduler) {
+ 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();
+ while (!taskQueue.empty()) {
+ mbgl::Mailbox::maybeReceive(taskQueue.front());
+ taskQueue.pop();
+ }
}
}
diff --git a/platform/qt/src/qmapboxgl_map_renderer.hpp b/platform/qt/src/qmapboxgl_map_renderer.hpp
index e5ead3df32..c15840a85d 100644
--- a/platform/qt/src/qmapboxgl_map_renderer.hpp
+++ b/platform/qt/src/qmapboxgl_map_renderer.hpp
@@ -48,4 +48,6 @@ private:
std::mutex m_taskQueueMutex;
std::queue<std::weak_ptr<mbgl::Mailbox>> m_taskQueue;
+
+ bool m_threadWithScheduler;
};