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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
#include "fb_base.h"
#include <qpainter.h>
#include <private/qapplication_p.h>
#include <qdebug.h>
#include <qgraphicssystemcursor.h>
QGraphicsSystemFbScreen::QGraphicsSystemFbScreen() : cursor(0), mGeometry(), mDepth(16), mFormat(QImage::Format_RGB16), mScreenImage(0)
{
mScreenImage = new QImage(mGeometry.size(), mFormat);
redrawTimer.setSingleShot(true);
redrawTimer.setInterval(0);
QObject::connect(&redrawTimer, SIGNAL(timeout()), this, SLOT(doRedraw()));
}
void QGraphicsSystemFbScreen::setGeometry(QRect rect)
{
delete mScreenImage;
mGeometry = rect;
mScreenImage = new QImage(mGeometry.size(), mFormat);
}
void QGraphicsSystemFbScreen::setDepth(int depth)
{
mDepth = depth;
}
void QGraphicsSystemFbScreen::setPhysicalSize(QSize size)
{
mPhysicalSize = size;
}
void QGraphicsSystemFbScreen::setFormat(QImage::Format format)
{
mFormat = format;
delete mScreenImage;
mScreenImage = new QImage(mGeometry.size(), mFormat);
}
QGraphicsSystemFbScreen::~QGraphicsSystemFbScreen()
{
delete mScreenImage;
}
void QGraphicsSystemFbScreen::setDirty(const QRect &rect)
{
repaintRegion += rect;
if (!redrawTimer.isActive()) {
redrawTimer.start();
}
}
QRegion QGraphicsSystemFbScreen::doRedraw()
{
QRegion touchedRegion;
if (cursor)
repaintRegion += cursor->dirtyRect();
if (repaintRegion.isEmpty())
return touchedRegion;
QPainter compositePainter(mScreenImage);
QVector<QRect> rects = repaintRegion.rects();
for (int rectIndex = 0; rectIndex < repaintRegion.numRects(); rectIndex++) {
QRect rect = rects[rectIndex];
// Blank the affected area, just in case there's nothing to display
compositePainter.fillRect(rect, Qt::black);
for (int i = windowStack.length() - 1; i >= 0; i--) {
if (!windowStack[i]->visible())
continue;
QRect windowRect = windowStack[i]->geometry();
QRect intersect = windowRect.intersected(rect);
QRect windowIntersect = intersect.translated(-windowRect.left(),
-windowRect.top());
if (intersect.isNull())
continue;
compositePainter.drawImage(intersect, windowStack[i]->image(),
windowIntersect);
}
}
QRect cursorRect;
if (cursor) {
cursorRect = cursor->drawCursor(compositePainter);
touchedRegion += cursorRect;
}
touchedRegion += repaintRegion;
repaintRegion = QRegion();
return touchedRegion;
}
void QGraphicsSystemFbScreen::removeWindowSurface(QGraphicsSystemFbWindowSurface * surface)
{
windowStack.removeOne(surface);
setDirty(surface->geometry());
}
void QGraphicsSystemFbWindowSurface::raise()
{
mScreen->raise(this);
}
void QGraphicsSystemFbScreen::raise(QWindowSurface * surface)
{
QGraphicsSystemFbWindowSurface *s = static_cast<QGraphicsSystemFbWindowSurface *>(surface);
int index = windowStack.indexOf(s);
if (index <= 0)
return;
windowStack.move(index, 0);
setDirty(s->geometry());
}
void QGraphicsSystemFbWindowSurface::lower()
{
mScreen->lower(this);
}
void QGraphicsSystemFbScreen::lower(QWindowSurface * surface)
{
QGraphicsSystemFbWindowSurface *s = static_cast<QGraphicsSystemFbWindowSurface *>(surface);
int index = windowStack.indexOf(s);
if (index == -1 || index == (windowStack.size() - 1))
return;
windowStack.move(index, windowStack.size() - 1);
setDirty(s->geometry());
}
void QGraphicsSystemFbScreen::pointerEvent(QMouseEvent & me)
{
QWidget * widget = topLevelAt(me.pos());
if (!widget) {
QApplicationPrivate::handleMouseEvent(0, me);
return;
}
QPoint localPosition = me.pos();
QPoint topLeft = widget->geometry().topLeft();
localPosition.setX(localPosition.x() - topLeft.x());
localPosition.setY(localPosition.y() - topLeft.y());
QMouseEvent e(me.type(), localPosition, me.globalPos(), me.button(), me.buttons(), me.modifiers());
QApplicationPrivate::handleMouseEvent(widget, e);
}
QWidget * QGraphicsSystemFbScreen::topLevelAt(QPoint p)
{
for(int i = 0; i < windowStack.size(); i++) {
if (windowStack[i]->geometry().contains(p, false) &&
windowStack[i]->visible()) {
return windowStack[i]->window();
}
}
return 0;
}
QGraphicsSystemFbWindowSurface::QGraphicsSystemFbWindowSurface(QGraphicsSystemFbScreen *screen, QWidget *window)
: QWindowSurface(window),
mScreen(screen),
visibleFlag(false)
{
mImage = QImage(window->size(), mScreen->format());
}
QGraphicsSystemFbWindowSurface::~QGraphicsSystemFbWindowSurface()
{
mScreen->removeWindowSurface(this);
}
void QGraphicsSystemFbWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &offset)
{
Q_UNUSED(widget);
Q_UNUSED(offset);
QRect currentGeometry = geometry();
// If this is a move, redraw the previous location
if (oldGeometry != currentGeometry) {
mScreen->setDirty(oldGeometry);
oldGeometry = currentGeometry;
}
QRect dirtyClient = region.boundingRect();
QRect dirtyRegion(currentGeometry.left() + dirtyClient.left(),
currentGeometry.top() + dirtyClient.top(),
dirtyClient.width(),
dirtyClient.height());
mScreen->setDirty(dirtyRegion);
}
void QGraphicsSystemFbWindowSurface::setGeometry(const QRect &rect)
{
// store previous geometry for screen update
oldGeometry = geometry();
// change the widget's QImage if this is a resize
if (mImage.size() != rect.size())
mImage = QImage(rect.size(), mScreen->format());
QApplicationPrivate::handleGeometryChange(this->window(), rect);
QWindowSurface::setGeometry(rect);
}
bool QGraphicsSystemFbWindowSurface::scroll(const QRegion &area, int dx, int dy)
{
return QWindowSurface::scroll(area, dx, dy);
}
void QGraphicsSystemFbWindowSurface::beginPaint(const QRegion ®ion)
{
Q_UNUSED(region);
}
void QGraphicsSystemFbWindowSurface::endPaint(const QRegion ®ion)
{
Q_UNUSED(region);
}
void QGraphicsSystemFbWindowSurface::setVisible(bool visible)
{
visibleFlag = visible;
mScreen->setDirty(geometry());
}
|