-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnsrrenderthread.h
161 lines (136 loc) · 3.85 KB
/
nsrrenderthread.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#ifndef __NSRRENDERTHREAD_H__
#define __NSRRENDERTHREAD_H__
/**
* @file nsrrenderthread.h
* @author Alexander Saprykin
* @brief Render thread
*/
#include "nsrrenderedpage.h"
#include "nsrabstractdocument.h"
#include <QThread>
#include <QList>
#include <QHash>
#include <QMutex>
#include <QAtomicInt>
/**
* @class NSRRenderThread nsrrenderthread.h
* @brief Class for render thread
*/
class NSRRenderThread : public QThread
{
Q_OBJECT
public:
/**
* @brief Constructor with parameter
* @param parent Parent object.
*/
explicit NSRRenderThread (QObject *parent = 0);
/**
* @brief Destructor
*/
virtual ~NSRRenderThread ();
/**
* @brief Sets render context
* @param doc File handler for rendering.
*/
void setRenderContext (NSRAbstractDocument *doc);
/**
* @brief Gets render context
* @return File handler for rendering.
*/
inline NSRAbstractDocument * getRenderContext () const {
return _doc;
}
/**
* @brief Adds render request to queue
* @param req Render request.
*/
void addRequest (const NSRRenderRequest &req);
/**
* @brief Cancels all render requests by type
* @param type Render request type.
*/
void cancelRequests (NSRRenderRequest::NSRRenderType type);
/**
* @brief Cancel all render request
*/
void cancelAllRequests ();
/**
* @brief Checks whether thread has render requests of given type
* @param type Render request type.
* @return True if thread has render requests of given type, false
* otherwise.
*/
bool hasRequests (NSRRenderRequest::NSRRenderType type) const;
/**
* @brief Checks whether thread has any render requests
* @return True if thread has any render requests, false otherwise.
*/
bool hasAnyRequests () const;
/**
* @brief Gets last rendered page
* @return Last rendered page.
*/
NSRRenderedPage getRenderedPage ();
/**
* @brief Gets current render request
* @return Current render request.
*/
NSRRenderRequest getCurrentRequest () const;
/**
* @brief Marks current render request as canceled
* @param canceled Whether current render request is canceled.
*/
inline void setRenderCanceled (bool canceled) {
_renderCanceled = canceled ? 1 : 0;
}
/**
* @brief Checks whether current render request is canceled
* @return True if current render request is canceled, false otherwise.
*/
inline bool isRenderCanceled () const {
return (_renderCanceled == 1);
}
/** Reimplemented from QThread */
virtual void run ();
Q_SIGNALS:
/**
* @brief Render finished
*/
void renderDone ();
private:
/**
* @brief Gets render request from the queue
* @return Render request.
*/
NSRRenderRequest getRequest ();
/**
* @brief Marks render request as completed
* @param page Rendered page.
*/
void completeRequest (const NSRRenderedPage& page);
/**
* @brief Sets current render request
* @param req New render request.
*/
void setCurrentRequest (const NSRRenderRequest& req);
/**
* @brief Prepares render context
* @param req Render request.
*/
void prepareRenderContext (const NSRRenderRequest& req);
/**
* @brief Preapres render context for crop pads detection
* @param req Render request.
* @since 1.4.2
*/
void prepareRenderContextForCrop (const NSRRenderRequest& req);
NSRAbstractDocument *_doc; /**< File handler for render */
NSRRenderRequest _currentRequest; /**< Current render request */
QList<NSRRenderRequest> _requestedPages; /**< List of waiting requests */
QList<NSRRenderedPage> _renderedPages; /**< List of rendered pages */
mutable QMutex _requestedMutex; /**< Mutex for render requests */
mutable QMutex _renderedMutex; /**< Mutex for rendered pages */
QAtomicInt _renderCanceled; /**< Render cancel flag */
};
#endif /* __NSRRENDERTHREAD_H__ */