source: terepaima/terepaima-0.4.16/sources/rendertask.h

desarrollostretch
Last change on this file was 1f4adec, checked in by aosorio <aosorio@…>, 8 years ago

Agregado proyecto base, esto luego del dh_make -f

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2
3Copyright 2013-2015 Adam Reichold
4
5This file is part of qpdfview.
6
7qpdfview is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 2 of the License, or
10(at your option) any later version.
11
12qpdfview is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with qpdfview.  If not, see <http://www.gnu.org/licenses/>.
19
20*/
21
22#ifndef RENDERTASK_H
23#define RENDERTASK_H
24
25#include <QImage>
26#include <QMutex>
27#include <QRunnable>
28#include <QWaitCondition>
29
30#include "renderparam.h"
31
32namespace qpdfview
33{
34
35namespace Model
36{
37class Page;
38}
39
40class Settings;
41
42class RenderTask : public QObject, QRunnable
43{
44    Q_OBJECT
45
46public:
47    explicit RenderTask(Model::Page* page, QObject* parent = 0);
48
49    void wait();
50
51    bool isRunning() const;
52
53    bool wasCanceled() const { return loadCancellation() != NotCanceled; }
54    bool wasCanceledNormally() const { return loadCancellation() == CanceledNormally; }
55    bool wasCanceledForcibly() const { return loadCancellation() == CanceledForcibly; }
56
57    void run();
58
59signals:
60    void finished();
61
62    void imageReady(const RenderParam& renderParam,
63                    const QRect& rect, bool prefetch,
64                    const QImage& image, const QRectF& cropRect);
65
66public slots:
67    void start(const RenderParam& renderParam,
68               const QRect& rect, bool prefetch);
69
70    void cancel(bool force = false) { setCancellation(force); }
71
72private:
73    Q_DISABLE_COPY(RenderTask)
74
75    static Settings* s_settings;
76
77    mutable QMutex m_mutex;
78    QWaitCondition m_waitCondition;
79
80    bool m_isRunning;
81    QAtomicInt m_wasCanceled;
82
83    enum
84    {
85        NotCanceled = 0,
86        CanceledNormally = 1,
87        CanceledForcibly = 2
88    };
89
90    void setCancellation(bool force);
91    void resetCancellation();
92    bool testCancellation();
93    int loadCancellation() const;
94
95    void finish();
96
97
98    Model::Page* m_page;
99
100    static RenderParam s_defaultRenderParam;
101    RenderParam m_renderParam;
102
103    QRect m_rect;
104    bool m_prefetch;
105
106};
107
108#if QT_VERSION > QT_VERSION_CHECK(5,0,0)
109
110inline void RenderTask::setCancellation(bool force)
111{
112    m_wasCanceled.storeRelease(force ? CanceledForcibly : CanceledNormally);
113}
114
115inline void RenderTask::resetCancellation()
116{
117    m_wasCanceled.storeRelease(NotCanceled);
118}
119
120inline bool RenderTask::testCancellation()
121{
122    return m_prefetch ?
123                m_wasCanceled.load() == CanceledForcibly :
124                m_wasCanceled.load() != NotCanceled;
125}
126
127inline int RenderTask::loadCancellation() const
128{
129    return m_wasCanceled.load();
130}
131
132#else
133
134inline void RenderTask::setCancellation(bool force)
135{
136    m_wasCanceled.fetchAndStoreRelease(force ? CanceledForcibly : CanceledNormally);
137}
138
139inline void RenderTask::resetCancellation()
140{
141    m_wasCanceled.fetchAndStoreRelease(NotCanceled);
142}
143
144inline bool RenderTask::testCancellation()
145{
146    return m_prefetch ?
147                m_wasCanceled.testAndSetRelaxed(CanceledForcibly, CanceledForcibly) :
148                !m_wasCanceled.testAndSetRelaxed(NotCanceled, NotCanceled);
149}
150
151inline int RenderTask::loadCancellation() const
152{
153    return m_wasCanceled;
154}
155
156#endif // QT_VERSION
157
158} // qpdfview
159
160#endif // RENDERTASK_H
Note: See TracBrowser for help on using the repository browser.