[qt] Only use the MapRenderer as scheduler if there is no other
Optimization of when running on the Main Thread that has a RunLoop.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,4 +48,6 @@ private:
|
||||
|
||||
std::mutex m_taskQueueMutex;
|
||||
std::queue<std::weak_ptr<mbgl::Mailbox>> m_taskQueue;
|
||||
|
||||
bool m_threadWithScheduler;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user