1
#include "renderengine.h"
2
#include <QtConcurrent/QtConcurrent>
5
RenderEngine* RenderEngine::s_instance = nullptr;
7
RenderEngine::RenderEngine():
11
int itc = QThread::idealThreadCount();
12
m_idealThreadCount = itc == -1 ? DefaultIdealThreadCount : itc;
15
void RenderEngine::enqueueTask(const QSharedPointer<LODocument>& doc, const QRect& area, int id)
17
Q_ASSERT(doc != nullptr);
19
m_queue.enqueue(EngineTask(doc, area, id));
24
void RenderEngine::dequeueTask(int id)
26
for (int i = 0; i < m_queue.size(); i++)
27
if (m_queue.at(i).id == id) {
33
void RenderEngine::internalRenderCallback(int id, QImage img)
36
Q_EMIT renderFinished(id, img);
40
void RenderEngine::doNextTask()
43
qDebug() << " ---- doNextTask" << m_activeTaskCount << m_queue.count();
46
if (m_activeTaskCount >= m_idealThreadCount || !m_queue.count())
50
auto task = m_queue.dequeue();
52
QtConcurrent::run( [=] {
53
QImage img = task.document->paintTile(task.area.size(), task.area);
54
QMetaObject::invokeMethod(this, "internalRenderCallback", Q_ARG(int, task.id), Q_ARG(QImage, img));