-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrenderqueue.h
More file actions
80 lines (76 loc) · 1.61 KB
/
Copy pathrenderqueue.h
File metadata and controls
80 lines (76 loc) · 1.61 KB
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
#pragma once
#include <QMutex>
#include <QWaitCondition>
#include <QQueue>
class TiledImageGraphicsItem;
struct RenderQueueItem
{
enum {
CACHE_SCALED = 0,
CACHE_RAW,
};
int code;
int priority;
TiledImageGraphicsItem* graphicsItem;
};
class RenderQueue : protected QQueue<RenderQueueItem>
{
typedef QQueue<RenderQueueItem> Container;
public:
void push(const RenderQueueItem& newItem)
{
QMutexLocker locker(&m_queueLock);
bool inserted = false;
Container::iterator it=Container::begin();
for(;it!=Container::end(); ++it) {
const RenderQueueItem& item = *it;
if(item.priority <= newItem.priority) {
Container::insert(it, newItem);
inserted = true;
break;
}
}
if(!inserted) {
Container::push_back(newItem);
}
Q_ASSERT(Container::size());
m_queueNotEmpty.wakeOne();
}
bool empty(void) const
{
QMutexLocker locker(&m_queueLock);
return Container::empty();
}
bool tryPop(RenderQueueItem& item)
{
QMutexLocker locker(&m_queueLock);
bool popped = false;
if(!Container::empty()) {
item = Container::dequeue();
popped = true;
}
return popped;
}
bool waitAndPop(RenderQueueItem& item)
{
QMutexLocker locker(&m_queueLock);
bool popped = false;
while(Container::empty()) {
m_queueNotEmpty.wait(&m_queueLock);
}
if(!Container::empty()) {
item = Container::dequeue();
popped = true;
}
return popped;
}
void clear(void)
{
QMutexLocker locker(&m_queueLock);
Container::clear();
}
private:
mutable QMutex m_queueLock;
QWaitCondition m_queueNotEmpty;
bool closed;
};