[qt] Make MapboxGLMapRenderer a scheduler to receive messages when rendering
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user