~verzegnassi-stefano/ubuntu-docviewer-app/fix-1524712

« back to all changes in this revision

Viewing changes to src/plugin/libreofficetoolkit-qml-plugin/renderengine.cpp

  • Committer: Stefano Verzegnassi
  • Date: 2015-11-22 17:28:09 UTC
  • mfrom: (202 lo-viewer)
  • mto: This revision was merged to the branch mainline in revision 207.
  • Revision ID: stefano92.100@gmail.com-20151122172809-ozk6xf1q0ef7tl2x
Merged 'reboot' - Fixed conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
RenderEngine* RenderEngine::s_instance = nullptr;
6
6
 
7
7
RenderEngine::RenderEngine():
8
 
    QObject(nullptr),
9
 
    m_activeTaskCount(0),
10
 
    m_lastPart(-1)
 
8
    QObject(nullptr)
 
9
    ,m_activeTaskCount(0)
 
10
    ,m_lastTask(nullptr)
11
11
{
12
12
    int itc = QThread::idealThreadCount();
13
13
    m_idealThreadCount = itc == -1 ? DefaultIdealThreadCount : itc;
55
55
        auto task = m_queue.at(i);
56
56
        if (task->id() == id) {
57
57
            m_queue.removeAt(i);
58
 
            disposeTask(task);
 
58
            disposeLater(task);
59
59
            break;
60
60
        }
61
61
    }
65
65
{
66
66
    m_activeTaskCount--;
67
67
 
 
68
    if (!m_activeTaskCount) {
 
69
        m_lastTask = nullptr;
 
70
        doDispose();
 
71
    }
 
72
 
68
73
    switch (task->type())
69
74
    {
70
75
    case RttTile:
73
78
    case RttImpressThumbnail:
74
79
        Q_EMIT thumbnailRenderFinished(task->id(), img);
75
80
        break;
 
81
    case RttPdfPage:
 
82
    case RttUnknown:
 
83
    default:
 
84
        break;
76
85
    }
77
86
 
78
 
    disposeTask(task);
79
 
 
80
87
    doNextTask();
81
 
}
82
 
 
83
 
void RenderEngine::disposeTask(AbstractRenderTask *task)
84
 
{
85
 
    delete task;
 
88
 
 
89
    disposeLater(task);
 
90
}
 
91
 
 
92
void RenderEngine::disposeLater(AbstractRenderTask *task)
 
93
{
 
94
    m_disposedTasks.append(task);
 
95
}
 
96
 
 
97
void RenderEngine::doDispose()
 
98
{
 
99
    for (int i = 0; i < m_disposedTasks.size(); ++i)
 
100
        delete m_disposedTasks.at(i);
 
101
    m_disposedTasks.clear();
86
102
}
87
103
 
88
104
void RenderEngine::doNextTask()
97
113
 
98
114
    AbstractRenderTask* task = m_queue.head();
99
115
 
100
 
    // LoRenderTask requires special check.
101
 
    if (task->type() == RttTile || task->type() == RttImpressThumbnail) {
102
 
        LoRenderTask* loTask = static_cast<LoRenderTask*>(task);
103
 
 
104
 
        if (m_activeTaskCount && loTask->part() != m_lastPart)
105
 
            return;
106
 
 
107
 
        // Set correct part.
108
 
        m_lastPart = loTask->part();
109
 
        loTask->document()->setDocumentPart(m_lastPart);
110
 
    }
 
116
    // If some tasks already in progress, we should ask task about
 
117
    // compatibility of parallel execution with last the task.
 
118
    if (m_activeTaskCount && !task->canBeRunInParallel(m_lastTask))
 
119
        return;
 
120
 
 
121
    task->prepare();
111
122
 
112
123
    m_activeTaskCount++;
113
 
    m_queue.dequeue();
 
124
    m_lastTask = m_queue.dequeue();
114
125
 
115
126
    QtConcurrent::run( [=] {
116
127
        QImage img = task->doWork();