Merge lp:~mrqtros/ubuntu-docviewer-app/ubuntu-docviewer-app-renderengine-move into lp:ubuntu-docviewer-app
- ubuntu-docviewer-app-renderengine-move
- Merge into lo-viewer
Proposed by
Roman Shchekin
Status: | Merged |
---|---|
Approved by: | Stefano Verzegnassi |
Approved revision: | 240 |
Merged at revision: | 240 |
Proposed branch: | lp:~mrqtros/ubuntu-docviewer-app/ubuntu-docviewer-app-renderengine-move |
Merge into: | lp:ubuntu-docviewer-app |
Diff against target: |
694 lines (+283/-269) 17 files modified
po/com.ubuntu.docviewer.pot (+4/-4) src/app/CMakeLists.txt (+2/-0) src/app/renderengine.cpp (+92/-0) src/app/renderengine.h (+58/-0) src/app/rendertask.cpp (+1/-0) src/app/rendertask.h (+38/-0) src/plugin/libreofficetoolkit-qml-plugin/CMakeLists.txt (+1/-2) src/plugin/libreofficetoolkit-qml-plugin/lopartsimageprovider.cpp (+1/-1) src/plugin/libreofficetoolkit-qml-plugin/lopartsimageprovider.h (+1/-1) src/plugin/libreofficetoolkit-qml-plugin/lopartsmodel.h (+1/-1) src/plugin/libreofficetoolkit-qml-plugin/lorendertask.cpp (+25/-0) src/plugin/libreofficetoolkit-qml-plugin/lorendertask.h (+57/-0) src/plugin/libreofficetoolkit-qml-plugin/loview.h (+2/-2) src/plugin/libreofficetoolkit-qml-plugin/renderengine.cpp (+0/-92) src/plugin/libreofficetoolkit-qml-plugin/renderengine.h (+0/-58) src/plugin/libreofficetoolkit-qml-plugin/rendertask.cpp (+0/-25) src/plugin/libreofficetoolkit-qml-plugin/rendertask.h (+0/-83) |
To merge this branch: | bzr merge lp:~mrqtros/ubuntu-docviewer-app/ubuntu-docviewer-app-renderengine-move |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Stefano Verzegnassi | Approve | ||
Jenkins Bot | continuous-integration | Approve | |
Review via email: mp+281328@code.launchpad.net |
Commit message
RenderEngine now become application-wide tool
Description of the change
RenderEngine now become application-wide tool. This refactoring is required for easy transition to asynchonious PDF rendering.
To post a comment you must log in.
Revision history for this message
Jenkins Bot (ubuntu-core-apps-jenkins-bot) wrote : | # |
review:
Approve
(continuous-integration)
Revision history for this message
Stefano Verzegnassi (verzegnassi-stefano) wrote : | # |
LGTM. Thanks!
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'po/com.ubuntu.docviewer.pot' |
2 | --- po/com.ubuntu.docviewer.pot 2015-12-02 15:12:15 +0000 |
3 | +++ po/com.ubuntu.docviewer.pot 2015-12-23 21:30:11 +0000 |
4 | @@ -8,7 +8,7 @@ |
5 | msgstr "" |
6 | "Project-Id-Version: \n" |
7 | "Report-Msgid-Bugs-To: \n" |
8 | -"POT-Creation-Date: 2015-12-02 16:11+0100\n" |
9 | +"POT-Creation-Date: 2015-12-12 13:04+0300\n" |
10 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
11 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
12 | "Language-Team: LANGUAGE <LL@li.org>\n" |
13 | @@ -211,7 +211,7 @@ |
14 | msgstr "" |
15 | |
16 | #: ../src/app/qml/documentPage/DocumentPage.qml:23 |
17 | -#: /tmp/build-ubuntu-docviewer-app-Desktop-Default/po/com.ubuntu.docviewer.desktop.in.in.h:3 |
18 | +#: /home/qtros/dev/ubuntu-docviewer-app-uitk-13-ethalone-build/po/com.ubuntu.docviewer.desktop.in.in.h:3 |
19 | msgid "Documents" |
20 | msgstr "" |
21 | |
22 | @@ -435,10 +435,10 @@ |
23 | msgid "copy %1" |
24 | msgstr "" |
25 | |
26 | -#: /tmp/build-ubuntu-docviewer-app-Desktop-Default/po/com.ubuntu.docviewer.desktop.in.in.h:1 |
27 | +#: /home/qtros/dev/ubuntu-docviewer-app-uitk-13-ethalone-build/po/com.ubuntu.docviewer.desktop.in.in.h:1 |
28 | msgid "Document Viewer" |
29 | msgstr "" |
30 | |
31 | -#: /tmp/build-ubuntu-docviewer-app-Desktop-Default/po/com.ubuntu.docviewer.desktop.in.in.h:2 |
32 | +#: /home/qtros/dev/ubuntu-docviewer-app-uitk-13-ethalone-build/po/com.ubuntu.docviewer.desktop.in.in.h:2 |
33 | msgid "documents;viewer;pdf;reader;" |
34 | msgstr "" |
35 | |
36 | === modified file 'src/app/CMakeLists.txt' |
37 | --- src/app/CMakeLists.txt 2015-11-30 12:12:10 +0000 |
38 | +++ src/app/CMakeLists.txt 2015-12-23 21:30:11 +0000 |
39 | @@ -22,6 +22,8 @@ |
40 | |
41 | set(docviewer_SRCS |
42 | main.cpp |
43 | + renderengine.cpp |
44 | + rendertask.cpp |
45 | ${QML_SRCS} |
46 | ) |
47 | |
48 | |
49 | === added file 'src/app/renderengine.cpp' |
50 | --- src/app/renderengine.cpp 1970-01-01 00:00:00 +0000 |
51 | +++ src/app/renderengine.cpp 2015-12-23 21:30:11 +0000 |
52 | @@ -0,0 +1,92 @@ |
53 | +#include "renderengine.h" |
54 | +#include <QtConcurrent/QtConcurrent> |
55 | +#include <QThread> |
56 | + |
57 | +RenderEngine* RenderEngine::s_instance = nullptr; |
58 | + |
59 | +RenderEngine::RenderEngine(): |
60 | + QObject(nullptr) |
61 | + ,m_activeTaskCount(0) |
62 | + ,m_lastTask(nullptr) |
63 | +{ |
64 | + int itc = QThread::idealThreadCount(); |
65 | + m_idealThreadCount = itc == -1 ? DefaultIdealThreadCount : itc; |
66 | + |
67 | + // For QMetaObject::invoke. |
68 | + qRegisterMetaType<AbstractRenderTask*>(); |
69 | +} |
70 | + |
71 | +void RenderEngine::enqueueTask(AbstractRenderTask *task) |
72 | +{ |
73 | + m_queue.enqueue(task); |
74 | + doNextTask(); |
75 | +} |
76 | + |
77 | +void RenderEngine::dequeueTask(int id) |
78 | +{ |
79 | + for (int i = 0; i < m_queue.size(); i++) { |
80 | + auto task = m_queue.at(i); |
81 | + if (task->id() == id) { |
82 | + m_queue.removeAt(i); |
83 | + disposeLater(task); |
84 | + break; |
85 | + } |
86 | + } |
87 | +} |
88 | + |
89 | +void RenderEngine::internalRenderCallback(AbstractRenderTask* task, QImage img) |
90 | +{ |
91 | + m_activeTaskCount--; |
92 | + |
93 | + if (!m_activeTaskCount) { |
94 | + m_lastTask = nullptr; |
95 | + doDispose(); |
96 | + } |
97 | + |
98 | + // Notify about result. |
99 | + emit taskRenderFinished(task, img); |
100 | + |
101 | + doNextTask(); |
102 | + disposeLater(task); |
103 | +} |
104 | + |
105 | +void RenderEngine::disposeLater(AbstractRenderTask *task) |
106 | +{ |
107 | + m_disposedTasks.append(task); |
108 | +} |
109 | + |
110 | +void RenderEngine::doDispose() |
111 | +{ |
112 | + for (int i = 0; i < m_disposedTasks.size(); ++i) |
113 | + delete m_disposedTasks.at(i); |
114 | + m_disposedTasks.clear(); |
115 | +} |
116 | + |
117 | +void RenderEngine::doNextTask() |
118 | +{ |
119 | +#ifdef DEBUG_VERBOSE |
120 | + qDebug() << " ---- doNextTask" << m_activeTaskCount << m_queue.count(); |
121 | +#endif |
122 | + |
123 | + // Check for too much threads or empty queue. |
124 | + if (m_activeTaskCount >= m_idealThreadCount || !m_queue.count()) |
125 | + return; |
126 | + |
127 | + AbstractRenderTask* task = m_queue.head(); |
128 | + |
129 | + // If some tasks already in progress, we should ask task about |
130 | + // compatibility of parallel execution with last the task. |
131 | + if (m_activeTaskCount && !task->canBeRunInParallel(m_lastTask)) |
132 | + return; |
133 | + |
134 | + task->prepare(); |
135 | + |
136 | + m_activeTaskCount++; |
137 | + m_lastTask = m_queue.dequeue(); |
138 | + |
139 | + QtConcurrent::run( [=] { |
140 | + QImage img = task->doWork(); |
141 | + QMetaObject::invokeMethod(this, "internalRenderCallback", |
142 | + Q_ARG(AbstractRenderTask*, task), Q_ARG(QImage, img)); |
143 | + }); |
144 | +} |
145 | |
146 | === added file 'src/app/renderengine.h' |
147 | --- src/app/renderengine.h 1970-01-01 00:00:00 +0000 |
148 | +++ src/app/renderengine.h 2015-12-23 21:30:11 +0000 |
149 | @@ -0,0 +1,58 @@ |
150 | +#ifndef RENDERENGINE_H |
151 | +#define RENDERENGINE_H |
152 | + |
153 | +#include <QObject> |
154 | +#include <QImage> |
155 | +#include <QSharedPointer> |
156 | +#include <QHash> |
157 | +#include <QQueue> |
158 | +#include <QAtomicInt> |
159 | +#include <QList> |
160 | + |
161 | +//#include "lodocument.h" |
162 | +#include "rendertask.h" |
163 | + |
164 | +class RenderEngine : public QObject |
165 | +{ |
166 | + Q_OBJECT |
167 | + Q_DISABLE_COPY(RenderEngine) |
168 | + |
169 | + static RenderEngine* s_instance; |
170 | + RenderEngine(); |
171 | + |
172 | + const int DefaultIdealThreadCount = 2; |
173 | + |
174 | +public: |
175 | + void enqueueTask(AbstractRenderTask* task); // Takes ownership. |
176 | + void dequeueTask(int id); |
177 | + |
178 | + static RenderEngine* instance() { |
179 | + if(!s_instance) |
180 | + s_instance = new RenderEngine(); |
181 | + return s_instance; |
182 | + } |
183 | + |
184 | + static int getNextId() { |
185 | + static int idCounter = 0xDEAD0000; |
186 | + return idCounter++; |
187 | + } |
188 | + |
189 | +Q_SIGNALS: |
190 | + void taskRenderFinished(AbstractRenderTask* task, QImage img); |
191 | + |
192 | +private: |
193 | + Q_INVOKABLE void internalRenderCallback(AbstractRenderTask* task, QImage img); |
194 | + void doNextTask(); |
195 | + void disposeLater(AbstractRenderTask* task); // Delayed deletion, must be used in pair with "doDispose". |
196 | + void doDispose(); // Deletes marked objects (disposeLater). |
197 | + |
198 | +private: |
199 | + QQueue<AbstractRenderTask*> m_queue; |
200 | + int m_activeTaskCount; |
201 | + int m_idealThreadCount; |
202 | + |
203 | + AbstractRenderTask* m_lastTask; // WARNING: valid only when: m_activeTaskCount > 0. |
204 | + QList<AbstractRenderTask*> m_disposedTasks; |
205 | +}; |
206 | + |
207 | +#endif // RENDERENGINE_H |
208 | |
209 | === added file 'src/app/rendertask.cpp' |
210 | --- src/app/rendertask.cpp 1970-01-01 00:00:00 +0000 |
211 | +++ src/app/rendertask.cpp 2015-12-23 21:30:11 +0000 |
212 | @@ -0,0 +1,1 @@ |
213 | +#include "rendertask.h" |
214 | |
215 | === added file 'src/app/rendertask.h' |
216 | --- src/app/rendertask.h 1970-01-01 00:00:00 +0000 |
217 | +++ src/app/rendertask.h 2015-12-23 21:30:11 +0000 |
218 | @@ -0,0 +1,38 @@ |
219 | +#ifndef RENDERTASK_H |
220 | +#define RENDERTASK_H |
221 | + |
222 | +#include <QObject> |
223 | +#include <QImage> |
224 | +#include <QSharedPointer> |
225 | +#include <QHash> |
226 | +#include <QQueue> |
227 | + |
228 | +/* Required for super-fast type detection. |
229 | + * NOTE: only leaf nodes in inheritance tree have correct types. |
230 | + */ |
231 | +enum RenderTaskType |
232 | +{ |
233 | + RttUnknown = 0x0, |
234 | + RttTile = 0x1, |
235 | + RttImpressThumbnail = 0x2, |
236 | + RttPdfPage = 0x3 |
237 | +}; |
238 | + |
239 | +class AbstractRenderTask |
240 | +{ |
241 | +public: |
242 | + virtual RenderTaskType type() { return RttUnknown; } |
243 | + virtual QImage doWork() = 0 ; |
244 | + virtual ~AbstractRenderTask() { } |
245 | + virtual bool canBeRunInParallel(AbstractRenderTask*) { return true; } |
246 | + virtual void prepare() = 0 ; |
247 | + |
248 | + int id() { return m_id; } |
249 | + void setId(int i) { m_id = i; } |
250 | +protected: |
251 | + int m_id; |
252 | +}; |
253 | + |
254 | +Q_DECLARE_METATYPE(AbstractRenderTask*) |
255 | + |
256 | +#endif // RENDERTASK_H |
257 | |
258 | === modified file 'src/plugin/libreofficetoolkit-qml-plugin/CMakeLists.txt' |
259 | --- src/plugin/libreofficetoolkit-qml-plugin/CMakeLists.txt 2015-11-22 17:28:09 +0000 |
260 | +++ src/plugin/libreofficetoolkit-qml-plugin/CMakeLists.txt 2015-12-23 21:30:11 +0000 |
261 | @@ -24,8 +24,7 @@ |
262 | sgtileitem.cpp |
263 | lopartsimageprovider.cpp |
264 | lopartsmodel.cpp |
265 | - renderengine.cpp |
266 | - rendertask.cpp |
267 | + lorendertask.cpp |
268 | ${QML_SRCS} |
269 | ) |
270 | |
271 | |
272 | === modified file 'src/plugin/libreofficetoolkit-qml-plugin/lopartsimageprovider.cpp' |
273 | --- src/plugin/libreofficetoolkit-qml-plugin/lopartsimageprovider.cpp 2015-11-28 22:11:54 +0000 |
274 | +++ src/plugin/libreofficetoolkit-qml-plugin/lopartsimageprovider.cpp 2015-12-23 21:30:11 +0000 |
275 | @@ -16,7 +16,7 @@ |
276 | |
277 | #include "lopartsimageprovider.h" |
278 | #include "lodocument.h" |
279 | -#include "renderengine.h" |
280 | +#include "../../app/renderengine.h" |
281 | |
282 | LOPartsImageProvider::LOPartsImageProvider(const QSharedPointer<LODocument>& d) |
283 | : QQuickImageProvider(QQuickImageProvider::Image), |
284 | |
285 | === modified file 'src/plugin/libreofficetoolkit-qml-plugin/lopartsimageprovider.h' |
286 | --- src/plugin/libreofficetoolkit-qml-plugin/lopartsimageprovider.h 2015-11-28 22:11:54 +0000 |
287 | +++ src/plugin/libreofficetoolkit-qml-plugin/lopartsimageprovider.h 2015-12-23 21:30:11 +0000 |
288 | @@ -23,7 +23,7 @@ |
289 | #include <QHash> |
290 | #include <QDebug> |
291 | |
292 | -#include "rendertask.h" |
293 | +#include "lorendertask.h" |
294 | |
295 | class LODocument; |
296 | |
297 | |
298 | === modified file 'src/plugin/libreofficetoolkit-qml-plugin/lopartsmodel.h' |
299 | --- src/plugin/libreofficetoolkit-qml-plugin/lopartsmodel.h 2015-11-28 19:19:26 +0000 |
300 | +++ src/plugin/libreofficetoolkit-qml-plugin/lopartsmodel.h 2015-12-23 21:30:11 +0000 |
301 | @@ -22,7 +22,7 @@ |
302 | #include <QHash> |
303 | #include <QSharedPointer> |
304 | |
305 | -#include "renderengine.h" |
306 | +#include "../../app/renderengine.h" |
307 | |
308 | class LODocument; |
309 | |
310 | |
311 | === added file 'src/plugin/libreofficetoolkit-qml-plugin/lorendertask.cpp' |
312 | --- src/plugin/libreofficetoolkit-qml-plugin/lorendertask.cpp 1970-01-01 00:00:00 +0000 |
313 | +++ src/plugin/libreofficetoolkit-qml-plugin/lorendertask.cpp 2015-12-23 21:30:11 +0000 |
314 | @@ -0,0 +1,25 @@ |
315 | +#include "lorendertask.h" |
316 | + |
317 | +bool LoRenderTask::canBeRunInParallel(AbstractRenderTask* prevTask) |
318 | +{ |
319 | + Q_ASSERT(prevTask != nullptr); |
320 | + if (prevTask->type() == RttTile || prevTask->type() == RttImpressThumbnail) { |
321 | + LoRenderTask* loTask = static_cast<LoRenderTask*>(prevTask); |
322 | + |
323 | + // Another document or the same part in the same document can be run parallel. |
324 | + return (loTask->document() != m_document || |
325 | + loTask->part() == m_part); |
326 | + } |
327 | + |
328 | + return true; |
329 | +} |
330 | + |
331 | +QImage TileRenderTask::doWork() |
332 | +{ |
333 | + return m_document->paintTile(m_area.size(), m_area, m_zoom); |
334 | +} |
335 | + |
336 | +QImage ThumbnailRenderTask::doWork() |
337 | +{ |
338 | + return m_document->paintThumbnail(m_size); |
339 | +} |
340 | |
341 | === added file 'src/plugin/libreofficetoolkit-qml-plugin/lorendertask.h' |
342 | --- src/plugin/libreofficetoolkit-qml-plugin/lorendertask.h 1970-01-01 00:00:00 +0000 |
343 | +++ src/plugin/libreofficetoolkit-qml-plugin/lorendertask.h 2015-12-23 21:30:11 +0000 |
344 | @@ -0,0 +1,57 @@ |
345 | +#ifndef LORENDERTASK_H |
346 | +#define LORENDERTASK_H |
347 | + |
348 | +#include <QObject> |
349 | +#include <QImage> |
350 | +#include <QSharedPointer> |
351 | +#include <QHash> |
352 | +#include <QQueue> |
353 | +#include <QAtomicInt> |
354 | + |
355 | +#include "../../app/rendertask.h" |
356 | +#include "lodocument.h" |
357 | + |
358 | + |
359 | +class LoRenderTask : public AbstractRenderTask |
360 | +{ |
361 | +public: |
362 | + virtual bool canBeRunInParallel(AbstractRenderTask* prevTask); |
363 | + virtual void prepare() { m_document->setDocumentPart(m_part); } |
364 | + |
365 | + int part() { return m_part; } |
366 | + void setPart(int p) { m_part = p; } |
367 | + QSharedPointer<LODocument> document() { return m_document; } |
368 | + void setDocument(QSharedPointer<LODocument> d) { m_document = d; } |
369 | +protected: |
370 | + int m_part; |
371 | + QSharedPointer<LODocument> m_document; |
372 | +}; |
373 | + |
374 | +class TileRenderTask : public LoRenderTask |
375 | +{ |
376 | +public: |
377 | + virtual RenderTaskType type() { return RttTile; } |
378 | + virtual QImage doWork(); |
379 | + |
380 | + QRect area() { return m_area; } |
381 | + void setArea(const QRect& a) { m_area = a; } |
382 | + qreal zoom() { return m_zoom; } |
383 | + void setZoom(qreal z) { m_zoom = z; } |
384 | +protected: |
385 | + QRect m_area; |
386 | + qreal m_zoom; |
387 | +}; |
388 | + |
389 | +class ThumbnailRenderTask : public LoRenderTask |
390 | +{ |
391 | +public: |
392 | + virtual RenderTaskType type() { return RttImpressThumbnail; } |
393 | + virtual QImage doWork(); |
394 | + |
395 | + qreal size() { return m_size; } |
396 | + void setSize(qreal s) { m_size = s; } |
397 | +protected: |
398 | + qreal m_size; |
399 | +}; |
400 | + |
401 | +#endif // LORENDERTASK_H |
402 | |
403 | === modified file 'src/plugin/libreofficetoolkit-qml-plugin/loview.h' |
404 | --- src/plugin/libreofficetoolkit-qml-plugin/loview.h 2015-11-28 22:11:54 +0000 |
405 | +++ src/plugin/libreofficetoolkit-qml-plugin/loview.h 2015-12-23 21:30:11 +0000 |
406 | @@ -24,8 +24,8 @@ |
407 | #include <QQmlEngine> |
408 | |
409 | #include "loerror.h" |
410 | -#include "rendertask.h" |
411 | -#include "renderengine.h" |
412 | +#include "lorendertask.h" |
413 | +#include "../../app/renderengine.h" |
414 | #include "lopartsmodel.h" |
415 | #include "lopartsimageprovider.h" |
416 | |
417 | |
418 | === removed file 'src/plugin/libreofficetoolkit-qml-plugin/renderengine.cpp' |
419 | --- src/plugin/libreofficetoolkit-qml-plugin/renderengine.cpp 2015-11-28 22:11:54 +0000 |
420 | +++ src/plugin/libreofficetoolkit-qml-plugin/renderengine.cpp 1970-01-01 00:00:00 +0000 |
421 | @@ -1,92 +0,0 @@ |
422 | -#include "renderengine.h" |
423 | -#include <QtConcurrent/QtConcurrent> |
424 | -#include <QThread> |
425 | - |
426 | -RenderEngine* RenderEngine::s_instance = nullptr; |
427 | - |
428 | -RenderEngine::RenderEngine(): |
429 | - QObject(nullptr) |
430 | - ,m_activeTaskCount(0) |
431 | - ,m_lastTask(nullptr) |
432 | -{ |
433 | - int itc = QThread::idealThreadCount(); |
434 | - m_idealThreadCount = itc == -1 ? DefaultIdealThreadCount : itc; |
435 | - |
436 | - // For QMetaObject::invoke. |
437 | - qRegisterMetaType<AbstractRenderTask*>(); |
438 | -} |
439 | - |
440 | -void RenderEngine::enqueueTask(AbstractRenderTask *task) |
441 | -{ |
442 | - m_queue.enqueue(task); |
443 | - doNextTask(); |
444 | -} |
445 | - |
446 | -void RenderEngine::dequeueTask(int id) |
447 | -{ |
448 | - for (int i = 0; i < m_queue.size(); i++) { |
449 | - auto task = m_queue.at(i); |
450 | - if (task->id() == id) { |
451 | - m_queue.removeAt(i); |
452 | - disposeLater(task); |
453 | - break; |
454 | - } |
455 | - } |
456 | -} |
457 | - |
458 | -void RenderEngine::internalRenderCallback(AbstractRenderTask* task, QImage img) |
459 | -{ |
460 | - m_activeTaskCount--; |
461 | - |
462 | - if (!m_activeTaskCount) { |
463 | - m_lastTask = nullptr; |
464 | - doDispose(); |
465 | - } |
466 | - |
467 | - // Notify about result. |
468 | - emit taskRenderFinished(task, img); |
469 | - |
470 | - doNextTask(); |
471 | - disposeLater(task); |
472 | -} |
473 | - |
474 | -void RenderEngine::disposeLater(AbstractRenderTask *task) |
475 | -{ |
476 | - m_disposedTasks.append(task); |
477 | -} |
478 | - |
479 | -void RenderEngine::doDispose() |
480 | -{ |
481 | - for (int i = 0; i < m_disposedTasks.size(); ++i) |
482 | - delete m_disposedTasks.at(i); |
483 | - m_disposedTasks.clear(); |
484 | -} |
485 | - |
486 | -void RenderEngine::doNextTask() |
487 | -{ |
488 | -#ifdef DEBUG_VERBOSE |
489 | - qDebug() << " ---- doNextTask" << m_activeTaskCount << m_queue.count(); |
490 | -#endif |
491 | - |
492 | - // Check for too much threads or empty queue. |
493 | - if (m_activeTaskCount >= m_idealThreadCount || !m_queue.count()) |
494 | - return; |
495 | - |
496 | - AbstractRenderTask* task = m_queue.head(); |
497 | - |
498 | - // If some tasks already in progress, we should ask task about |
499 | - // compatibility of parallel execution with last the task. |
500 | - if (m_activeTaskCount && !task->canBeRunInParallel(m_lastTask)) |
501 | - return; |
502 | - |
503 | - task->prepare(); |
504 | - |
505 | - m_activeTaskCount++; |
506 | - m_lastTask = m_queue.dequeue(); |
507 | - |
508 | - QtConcurrent::run( [=] { |
509 | - QImage img = task->doWork(); |
510 | - QMetaObject::invokeMethod(this, "internalRenderCallback", |
511 | - Q_ARG(AbstractRenderTask*, task), Q_ARG(QImage, img)); |
512 | - }); |
513 | -} |
514 | |
515 | === removed file 'src/plugin/libreofficetoolkit-qml-plugin/renderengine.h' |
516 | --- src/plugin/libreofficetoolkit-qml-plugin/renderengine.h 2015-11-28 22:11:54 +0000 |
517 | +++ src/plugin/libreofficetoolkit-qml-plugin/renderengine.h 1970-01-01 00:00:00 +0000 |
518 | @@ -1,58 +0,0 @@ |
519 | -#ifndef RENDERENGINE_H |
520 | -#define RENDERENGINE_H |
521 | - |
522 | -#include <QObject> |
523 | -#include <QImage> |
524 | -#include <QSharedPointer> |
525 | -#include <QHash> |
526 | -#include <QQueue> |
527 | -#include <QAtomicInt> |
528 | -#include <QList> |
529 | - |
530 | -#include "lodocument.h" |
531 | -#include "rendertask.h" |
532 | - |
533 | -class RenderEngine : public QObject |
534 | -{ |
535 | - Q_OBJECT |
536 | - Q_DISABLE_COPY(RenderEngine) |
537 | - |
538 | - static RenderEngine* s_instance; |
539 | - RenderEngine(); |
540 | - |
541 | - const int DefaultIdealThreadCount = 2; |
542 | - |
543 | -public: |
544 | - void enqueueTask(AbstractRenderTask* task); // Takes ownership. |
545 | - void dequeueTask(int id); |
546 | - |
547 | - static RenderEngine* instance() { |
548 | - if(!s_instance) |
549 | - s_instance = new RenderEngine(); |
550 | - return s_instance; |
551 | - } |
552 | - |
553 | - static int getNextId() { |
554 | - static int idCounter = 0xDEAD0000; |
555 | - return idCounter++; |
556 | - } |
557 | - |
558 | -Q_SIGNALS: |
559 | - void taskRenderFinished(AbstractRenderTask* task, QImage img); |
560 | - |
561 | -private: |
562 | - Q_INVOKABLE void internalRenderCallback(AbstractRenderTask* task, QImage img); |
563 | - void doNextTask(); |
564 | - void disposeLater(AbstractRenderTask* task); // Delayed deletion, must be used in pair with "doDispose". |
565 | - void doDispose(); // Deletes marked objects (disposeLater). |
566 | - |
567 | -private: |
568 | - QQueue<AbstractRenderTask*> m_queue; |
569 | - int m_activeTaskCount; |
570 | - int m_idealThreadCount; |
571 | - |
572 | - AbstractRenderTask* m_lastTask; // WARNING: valid only when: m_activeTaskCount > 0. |
573 | - QList<AbstractRenderTask*> m_disposedTasks; |
574 | -}; |
575 | - |
576 | -#endif // RENDERENGINE_H |
577 | |
578 | === removed file 'src/plugin/libreofficetoolkit-qml-plugin/rendertask.cpp' |
579 | --- src/plugin/libreofficetoolkit-qml-plugin/rendertask.cpp 2015-11-28 21:13:54 +0000 |
580 | +++ src/plugin/libreofficetoolkit-qml-plugin/rendertask.cpp 1970-01-01 00:00:00 +0000 |
581 | @@ -1,25 +0,0 @@ |
582 | -#include "rendertask.h" |
583 | - |
584 | -bool LoRenderTask::canBeRunInParallel(AbstractRenderTask* prevTask) |
585 | -{ |
586 | - Q_ASSERT(prevTask != nullptr); |
587 | - if (prevTask->type() == RttTile || prevTask->type() == RttImpressThumbnail) { |
588 | - LoRenderTask* loTask = static_cast<LoRenderTask*>(prevTask); |
589 | - |
590 | - // Another document or the same part in the same document can be run parallel. |
591 | - return (loTask->document() != m_document || |
592 | - loTask->part() == m_part); |
593 | - } |
594 | - |
595 | - return true; |
596 | -} |
597 | - |
598 | -QImage TileRenderTask::doWork() |
599 | -{ |
600 | - return m_document->paintTile(m_area.size(), m_area, m_zoom); |
601 | -} |
602 | - |
603 | -QImage ThumbnailRenderTask::doWork() |
604 | -{ |
605 | - return m_document->paintThumbnail(m_size); |
606 | -} |
607 | |
608 | === removed file 'src/plugin/libreofficetoolkit-qml-plugin/rendertask.h' |
609 | --- src/plugin/libreofficetoolkit-qml-plugin/rendertask.h 2015-11-28 22:11:54 +0000 |
610 | +++ src/plugin/libreofficetoolkit-qml-plugin/rendertask.h 1970-01-01 00:00:00 +0000 |
611 | @@ -1,83 +0,0 @@ |
612 | -#ifndef RENDERTASK_H |
613 | -#define RENDERTASK_H |
614 | - |
615 | -#include <QObject> |
616 | -#include <QImage> |
617 | -#include <QSharedPointer> |
618 | -#include <QHash> |
619 | -#include <QQueue> |
620 | -#include <QAtomicInt> |
621 | - |
622 | -#include "lodocument.h" |
623 | - |
624 | -/* Required for super-fast type detection. |
625 | - * NOTE: only leaf nodes in inheritance tree have correct types. |
626 | - */ |
627 | -enum RenderTaskType |
628 | -{ |
629 | - RttUnknown = 0x0, |
630 | - RttTile = 0x1, |
631 | - RttImpressThumbnail = 0x2, |
632 | - RttPdfPage = 0x3 |
633 | -}; |
634 | - |
635 | -class AbstractRenderTask |
636 | -{ |
637 | -public: |
638 | - virtual RenderTaskType type() { return RttUnknown; } |
639 | - virtual QImage doWork() = 0 ; |
640 | - virtual ~AbstractRenderTask() { } |
641 | - virtual bool canBeRunInParallel(AbstractRenderTask*) { return true; } |
642 | - virtual void prepare() = 0 ; |
643 | - |
644 | - int id() { return m_id; } |
645 | - void setId(int i) { m_id = i; } |
646 | -protected: |
647 | - int m_id; |
648 | -}; |
649 | - |
650 | -Q_DECLARE_METATYPE(AbstractRenderTask*) |
651 | - |
652 | -class LoRenderTask : public AbstractRenderTask |
653 | -{ |
654 | -public: |
655 | - virtual bool canBeRunInParallel(AbstractRenderTask* prevTask); |
656 | - virtual void prepare() { m_document->setDocumentPart(m_part); } |
657 | - |
658 | - int part() { return m_part; } |
659 | - void setPart(int p) { m_part = p; } |
660 | - QSharedPointer<LODocument> document() { return m_document; } |
661 | - void setDocument(QSharedPointer<LODocument> d) { m_document = d; } |
662 | -protected: |
663 | - int m_part; |
664 | - QSharedPointer<LODocument> m_document; |
665 | -}; |
666 | - |
667 | -class TileRenderTask : public LoRenderTask |
668 | -{ |
669 | -public: |
670 | - virtual RenderTaskType type() { return RttTile; } |
671 | - virtual QImage doWork(); |
672 | - |
673 | - QRect area() { return m_area; } |
674 | - void setArea(const QRect& a) { m_area = a; } |
675 | - qreal zoom() { return m_zoom; } |
676 | - void setZoom(qreal z) { m_zoom = z; } |
677 | -protected: |
678 | - QRect m_area; |
679 | - qreal m_zoom; |
680 | -}; |
681 | - |
682 | -class ThumbnailRenderTask : public LoRenderTask |
683 | -{ |
684 | -public: |
685 | - virtual RenderTaskType type() { return RttImpressThumbnail; } |
686 | - virtual QImage doWork(); |
687 | - |
688 | - qreal size() { return m_size; } |
689 | - void setSize(qreal s) { m_size = s; } |
690 | -protected: |
691 | - qreal m_size; |
692 | -}; |
693 | - |
694 | -#endif // RENDERTASK_H |
PASSED: Continuous integration, rev:240 /core-apps- jenkins. ubuntu. com/job/ docviewer- app-ci/ 52/ /core-apps- jenkins. ubuntu. com/job/ generic- update- mp/275/ console
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild: /core-apps- jenkins. ubuntu. com/job/ docviewer- app-ci/ 52/rebuild
https:/