Render threads won't have a scheduler, so we create one that is shared by all the maps rendering at this thread. The bad side effect of this is that we need to wake up the render thread to process events. Mapbox GL should get rid of processing events on the render thread. This solution is a workaround.
39 lines
831 B
C++
39 lines
831 B
C++
#include "qmapboxgl_scheduler.hpp"
|
|
|
|
#include <mbgl/util/util.hpp>
|
|
|
|
#include <cassert>
|
|
|
|
QMapboxGLScheduler::QMapboxGLScheduler()
|
|
{
|
|
}
|
|
|
|
QMapboxGLScheduler::~QMapboxGLScheduler()
|
|
{
|
|
MBGL_VERIFY_THREAD(tid);
|
|
}
|
|
|
|
void QMapboxGLScheduler::schedule(std::weak_ptr<mbgl::Mailbox> mailbox)
|
|
{
|
|
std::lock_guard<std::mutex> lock(m_taskQueueMutex);
|
|
m_taskQueue.push(mailbox);
|
|
|
|
// Need to force the main thread to wake
|
|
// up this thread and process the events.
|
|
emit needsProcessing();
|
|
}
|
|
|
|
void QMapboxGLScheduler::processEvents()
|
|
{
|
|
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();
|
|
}
|
|
}
|