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