author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 16 Apr 2010 15:50:13 +0300 | |
changeset 18 | 2f34d5167611 |
parent 3 | 41300fa6a67c |
child 19 | fcece45ef507 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the plugins of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qdirectfbwindowsurface.h" |
|
43 |
#include "qdirectfbscreen.h" |
|
44 |
#include "qdirectfbpaintengine.h" |
|
45 |
||
46 |
#include <private/qwidget_p.h> |
|
47 |
#include <qwidget.h> |
|
48 |
#include <qwindowsystem_qws.h> |
|
49 |
#include <qpaintdevice.h> |
|
50 |
#include <qvarlengtharray.h> |
|
51 |
||
52 |
#ifndef QT_NO_QWS_DIRECTFB |
|
53 |
||
54 |
QT_BEGIN_NAMESPACE |
|
55 |
||
56 |
QDirectFBWindowSurface::QDirectFBWindowSurface(DFBSurfaceFlipFlags flip, QDirectFBScreen *scr) |
|
57 |
: QDirectFBPaintDevice(scr) |
|
58 |
, sibling(0) |
|
59 |
#ifndef QT_NO_DIRECTFB_WM |
|
60 |
, dfbWindow(0) |
|
61 |
#endif |
|
62 |
, flipFlags(flip) |
|
63 |
, boundingRectFlip(scr->directFBFlags() & QDirectFBScreen::BoundingRectFlip) |
|
64 |
{ |
|
65 |
#ifdef QT_NO_DIRECTFB_WM |
|
66 |
mode = Offscreen; |
|
67 |
#endif |
|
68 |
setSurfaceFlags(Opaque | Buffered); |
|
69 |
#ifdef QT_DIRECTFB_TIMING |
|
70 |
frames = 0; |
|
71 |
timer.start(); |
|
72 |
#endif |
|
73 |
} |
|
74 |
||
75 |
QDirectFBWindowSurface::QDirectFBWindowSurface(DFBSurfaceFlipFlags flip, QDirectFBScreen *scr, QWidget *widget) |
|
76 |
: QWSWindowSurface(widget), QDirectFBPaintDevice(scr) |
|
77 |
, sibling(0) |
|
78 |
#ifndef QT_NO_DIRECTFB_WM |
|
79 |
, dfbWindow(0) |
|
80 |
#endif |
|
81 |
, flipFlags(flip) |
|
82 |
, boundingRectFlip(scr->directFBFlags() & QDirectFBScreen::BoundingRectFlip) |
|
83 |
{ |
|
84 |
SurfaceFlags flags = 0; |
|
85 |
if (!widget || widget->window()->windowOpacity() == 0xff) |
|
86 |
flags |= Opaque; |
|
87 |
#ifdef QT_NO_DIRECTFB_WM |
|
88 |
if (widget && widget->testAttribute(Qt::WA_PaintOnScreen)) { |
|
89 |
flags = RegionReserved; |
|
90 |
mode = Primary; |
|
91 |
} else { |
|
92 |
mode = Offscreen; |
|
93 |
flags = Buffered; |
|
94 |
} |
|
95 |
#else |
|
96 |
noSystemBackground = widget && widget->testAttribute(Qt::WA_NoSystemBackground); |
|
97 |
if (noSystemBackground) |
|
98 |
flags &= ~Opaque; |
|
99 |
#endif |
|
100 |
setSurfaceFlags(flags); |
|
101 |
#ifdef QT_DIRECTFB_TIMING |
|
102 |
frames = 0; |
|
103 |
timer.start(); |
|
104 |
#endif |
|
105 |
} |
|
106 |
||
107 |
QDirectFBWindowSurface::~QDirectFBWindowSurface() |
|
108 |
{ |
|
109 |
releaseSurface(); |
|
110 |
// these are not tracked by QDirectFBScreen so we don't want QDirectFBPaintDevice to release it |
|
111 |
} |
|
112 |
||
113 |
bool QDirectFBWindowSurface::isValid() const |
|
114 |
{ |
|
115 |
return true; |
|
116 |
} |
|
117 |
||
118 |
#ifdef QT_DIRECTFB_WM |
|
119 |
void QDirectFBWindowSurface::raise() |
|
120 |
{ |
|
121 |
if (IDirectFBWindow *window = directFBWindow()) { |
|
122 |
window->RaiseToTop(window); |
|
123 |
} |
|
124 |
} |
|
125 |
||
126 |
IDirectFBWindow *QDirectFBWindowSurface::directFBWindow() const |
|
127 |
{ |
|
128 |
return (dfbWindow ? dfbWindow : (sibling ? sibling->dfbWindow : 0)); |
|
129 |
} |
|
130 |
||
131 |
void QDirectFBWindowSurface::createWindow(const QRect &rect) |
|
132 |
{ |
|
133 |
IDirectFBDisplayLayer *layer = screen->dfbDisplayLayer(); |
|
134 |
if (!layer) |
|
135 |
qFatal("QDirectFBWindowSurface: Unable to get primary display layer!"); |
|
136 |
||
137 |
DFBWindowDescription description; |
|
138 |
memset(&description, 0, sizeof(DFBWindowDescription)); |
|
139 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
140 |
description.caps = DWCAPS_NODECORATION; |
0 | 141 |
description.flags = DWDESC_CAPS|DWDESC_SURFACE_CAPS|DWDESC_PIXELFORMAT|DWDESC_HEIGHT|DWDESC_WIDTH|DWDESC_POSX|DWDESC_POSY; |
142 |
#if (Q_DIRECTFB_VERSION >= 0x010200) |
|
143 |
description.flags |= DWDESC_OPTIONS; |
|
144 |
#endif |
|
145 |
||
146 |
if (noSystemBackground) { |
|
147 |
description.caps |= DWCAPS_ALPHACHANNEL; |
|
148 |
#if (Q_DIRECTFB_VERSION >= 0x010200) |
|
149 |
description.options |= DWOP_ALPHACHANNEL; |
|
150 |
#endif |
|
151 |
} |
|
152 |
||
153 |
description.posx = rect.x(); |
|
154 |
description.posy = rect.y(); |
|
155 |
description.width = rect.width(); |
|
156 |
description.height = rect.height(); |
|
157 |
description.surface_caps = DSCAPS_NONE; |
|
158 |
if (screen->directFBFlags() & QDirectFBScreen::VideoOnly) |
|
159 |
description.surface_caps |= DSCAPS_VIDEOONLY; |
|
160 |
const QImage::Format format = (noSystemBackground ? screen->alphaPixmapFormat() : screen->pixelFormat()); |
|
161 |
description.pixelformat = QDirectFBScreen::getSurfacePixelFormat(format); |
|
162 |
if (QDirectFBScreen::isPremultiplied(format)) |
|
163 |
description.surface_caps = DSCAPS_PREMULTIPLIED; |
|
164 |
||
165 |
DFBResult result = layer->CreateWindow(layer, &description, &dfbWindow); |
|
166 |
||
167 |
if (result != DFB_OK) |
|
168 |
DirectFBErrorFatal("QDirectFBWindowSurface::createWindow", result); |
|
169 |
||
170 |
if (window()) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
171 |
if (window()->windowFlags() & Qt::WindowStaysOnTopHint) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
172 |
dfbWindow->SetStackingClass(dfbWindow, DWSC_UPPER); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
173 |
} |
0 | 174 |
DFBWindowID winid; |
175 |
result = dfbWindow->GetID(dfbWindow, &winid); |
|
176 |
if (result != DFB_OK) { |
|
177 |
DirectFBError("QDirectFBWindowSurface::createWindow. Can't get ID", result); |
|
178 |
} else { |
|
179 |
window()->setProperty("_q_DirectFBWindowID", winid); |
|
180 |
} |
|
181 |
} |
|
182 |
||
183 |
Q_ASSERT(!dfbSurface); |
|
184 |
dfbWindow->GetSurface(dfbWindow, &dfbSurface); |
|
185 |
updateFormat(); |
|
186 |
} |
|
187 |
||
188 |
static DFBResult setWindowGeometry(IDirectFBWindow *dfbWindow, const QRect &old, const QRect &rect) |
|
189 |
{ |
|
190 |
DFBResult result = DFB_OK; |
|
191 |
const bool isMove = old.isEmpty() || rect.topLeft() != old.topLeft(); |
|
192 |
const bool isResize = rect.size() != old.size(); |
|
193 |
||
194 |
#if (Q_DIRECTFB_VERSION >= 0x010000) |
|
195 |
if (isResize && isMove) { |
|
196 |
result = dfbWindow->SetBounds(dfbWindow, rect.x(), rect.y(), |
|
197 |
rect.width(), rect.height()); |
|
198 |
} else if (isResize) { |
|
199 |
result = dfbWindow->Resize(dfbWindow, |
|
200 |
rect.width(), rect.height()); |
|
201 |
} else if (isMove) { |
|
202 |
result = dfbWindow->MoveTo(dfbWindow, rect.x(), rect.y()); |
|
203 |
} |
|
204 |
#else |
|
205 |
if (isResize) { |
|
206 |
result = dfbWindow->Resize(dfbWindow, |
|
207 |
rect.width(), rect.height()); |
|
208 |
} |
|
209 |
if (isMove) { |
|
210 |
result = dfbWindow->MoveTo(dfbWindow, rect.x(), rect.y()); |
|
211 |
} |
|
212 |
#endif |
|
213 |
return result; |
|
214 |
} |
|
215 |
#endif // QT_NO_DIRECTFB_WM |
|
216 |
||
217 |
void QDirectFBWindowSurface::setGeometry(const QRect &rect) |
|
218 |
{ |
|
219 |
const QRect oldRect = geometry(); |
|
220 |
if (oldRect == rect) |
|
221 |
return; |
|
222 |
||
223 |
IDirectFBSurface *oldSurface = dfbSurface; |
|
224 |
const bool sizeChanged = oldRect.size() != rect.size(); |
|
225 |
if (sizeChanged) { |
|
226 |
delete engine; |
|
227 |
engine = 0; |
|
228 |
releaseSurface(); |
|
229 |
Q_ASSERT(!dfbSurface); |
|
230 |
} |
|
231 |
||
232 |
if (rect.isNull()) { |
|
233 |
#ifndef QT_NO_DIRECTFB_WM |
|
234 |
if (dfbWindow) { |
|
235 |
if (window()) |
|
236 |
window()->setProperty("_q_DirectFBWindowID", QVariant()); |
|
237 |
||
238 |
dfbWindow->Release(dfbWindow); |
|
239 |
dfbWindow = 0; |
|
240 |
} |
|
241 |
#endif |
|
242 |
Q_ASSERT(!dfbSurface); |
|
243 |
#ifdef QT_DIRECTFB_SUBSURFACE |
|
244 |
Q_ASSERT(!subSurface); |
|
245 |
#endif |
|
246 |
} else { |
|
247 |
#ifdef QT_DIRECTFB_WM |
|
248 |
if (!dfbWindow) { |
|
249 |
createWindow(rect); |
|
250 |
} else { |
|
251 |
setWindowGeometry(dfbWindow, oldRect, rect); |
|
252 |
Q_ASSERT(!sizeChanged || !dfbSurface); |
|
253 |
if (sizeChanged) |
|
254 |
dfbWindow->GetSurface(dfbWindow, &dfbSurface); |
|
255 |
} |
|
256 |
#else |
|
257 |
IDirectFBSurface *primarySurface = screen->primarySurface(); |
|
258 |
DFBResult result = DFB_OK; |
|
259 |
if (mode == Primary) { |
|
260 |
Q_ASSERT(primarySurface); |
|
261 |
if (rect == screen->region().boundingRect()) { |
|
262 |
dfbSurface = primarySurface; |
|
263 |
} else { |
|
264 |
const DFBRectangle r = { rect.x(), rect.y(), |
|
265 |
rect.width(), rect.height() }; |
|
266 |
result = primarySurface->GetSubSurface(primarySurface, &r, &dfbSurface); |
|
267 |
} |
|
268 |
} else { // mode == Offscreen |
|
269 |
if (!dfbSurface) { |
|
270 |
dfbSurface = screen->createDFBSurface(rect.size(), screen->pixelFormat(), QDirectFBScreen::DontTrackSurface); |
|
271 |
} |
|
272 |
} |
|
273 |
if (result != DFB_OK) |
|
274 |
DirectFBErrorFatal("QDirectFBWindowSurface::setGeometry()", result); |
|
275 |
#endif |
|
276 |
} |
|
277 |
if (oldSurface != dfbSurface) |
|
278 |
updateFormat(); |
|
279 |
||
280 |
if (oldRect.size() != rect.size()) { |
|
281 |
QWSWindowSurface::setGeometry(rect); |
|
282 |
} else { |
|
283 |
QWindowSurface::setGeometry(rect); |
|
284 |
} |
|
285 |
} |
|
286 |
||
287 |
QByteArray QDirectFBWindowSurface::permanentState() const |
|
288 |
{ |
|
289 |
QByteArray state(sizeof(this), 0); |
|
290 |
*reinterpret_cast<const QDirectFBWindowSurface**>(state.data()) = this; |
|
291 |
return state; |
|
292 |
} |
|
293 |
||
294 |
void QDirectFBWindowSurface::setPermanentState(const QByteArray &state) |
|
295 |
{ |
|
296 |
if (state.size() == sizeof(this)) { |
|
297 |
sibling = *reinterpret_cast<QDirectFBWindowSurface *const*>(state.constData()); |
|
298 |
Q_ASSERT(sibling); |
|
299 |
sibling->setSurfaceFlags(surfaceFlags()); |
|
300 |
} |
|
301 |
} |
|
302 |
||
303 |
static inline void scrollSurface(IDirectFBSurface *surface, const QRect &r, int dx, int dy) |
|
304 |
{ |
|
305 |
const DFBRectangle rect = { r.x(), r.y(), r.width(), r.height() }; |
|
306 |
surface->Blit(surface, surface, &rect, r.x() + dx, r.y() + dy); |
|
307 |
const DFBRegion region = { rect.x + dx, rect.y + dy, r.right() + dx, r.bottom() + dy }; |
|
308 |
surface->Flip(surface, ®ion, DSFLIP_BLIT); |
|
309 |
} |
|
310 |
||
311 |
bool QDirectFBWindowSurface::scroll(const QRegion ®ion, int dx, int dy) |
|
312 |
{ |
|
313 |
if (!dfbSurface || !(flipFlags & DSFLIP_BLIT) || region.isEmpty()) |
|
314 |
return false; |
|
315 |
dfbSurface->SetBlittingFlags(dfbSurface, DSBLIT_NOFX); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
316 |
if (region.rectCount() == 1) { |
0 | 317 |
scrollSurface(dfbSurface, region.boundingRect(), dx, dy); |
318 |
} else { |
|
319 |
const QVector<QRect> rects = region.rects(); |
|
320 |
const int n = rects.size(); |
|
321 |
for (int i=0; i<n; ++i) { |
|
322 |
scrollSurface(dfbSurface, rects.at(i), dx, dy); |
|
323 |
} |
|
324 |
} |
|
325 |
return true; |
|
326 |
} |
|
327 |
||
328 |
bool QDirectFBWindowSurface::move(const QPoint &moveBy) |
|
329 |
{ |
|
330 |
setGeometry(geometry().translated(moveBy)); |
|
331 |
return true; |
|
332 |
} |
|
333 |
||
334 |
void QDirectFBWindowSurface::setOpaque(bool opaque) |
|
335 |
{ |
|
336 |
SurfaceFlags flags = surfaceFlags(); |
|
337 |
if (opaque != (flags & Opaque)) { |
|
338 |
if (opaque) { |
|
339 |
flags |= Opaque; |
|
340 |
} else { |
|
341 |
flags &= ~Opaque; |
|
342 |
} |
|
343 |
setSurfaceFlags(flags); |
|
344 |
} |
|
345 |
} |
|
346 |
||
347 |
||
348 |
void QDirectFBWindowSurface::flush(QWidget *widget, const QRegion ®ion, |
|
349 |
const QPoint &offset) |
|
350 |
{ |
|
351 |
QWidget *win = window(); |
|
352 |
if (!win) |
|
353 |
return; |
|
354 |
||
355 |
QWExtra *extra = qt_widget_private(widget)->extraData(); |
|
356 |
if (extra && extra->proxyWidget) |
|
357 |
return; |
|
358 |
||
359 |
const quint8 windowOpacity = quint8(win->windowOpacity() * 0xff); |
|
360 |
const QRect windowGeometry = geometry(); |
|
361 |
#ifdef QT_DIRECTFB_WM |
|
362 |
const bool wasNoSystemBackground = noSystemBackground; |
|
363 |
noSystemBackground = win->testAttribute(Qt::WA_NoSystemBackground); |
|
364 |
quint8 currentOpacity; |
|
365 |
Q_ASSERT(dfbWindow); |
|
366 |
dfbWindow->GetOpacity(dfbWindow, ¤tOpacity); |
|
367 |
if (currentOpacity != windowOpacity) { |
|
368 |
dfbWindow->SetOpacity(dfbWindow, windowOpacity); |
|
369 |
} |
|
370 |
||
371 |
setOpaque(noSystemBackground || windowOpacity != 0xff); |
|
372 |
if (wasNoSystemBackground != noSystemBackground) { |
|
373 |
releaseSurface(); |
|
374 |
dfbWindow->Release(dfbWindow); |
|
375 |
dfbWindow = 0; |
|
376 |
createWindow(windowGeometry); |
|
377 |
win->update(); |
|
378 |
return; |
|
379 |
} |
|
380 |
screen->flipSurface(dfbSurface, flipFlags, region, offset); |
|
381 |
#else |
|
382 |
setOpaque(windowOpacity != 0xff); |
|
383 |
if (mode == Offscreen) { |
|
384 |
screen->exposeRegion(region.translated(offset + geometry().topLeft()), 0); |
|
385 |
} else { |
|
386 |
screen->flipSurface(dfbSurface, flipFlags, region, offset); |
|
387 |
} |
|
388 |
#endif |
|
389 |
||
390 |
#ifdef QT_DIRECTFB_TIMING |
|
391 |
enum { Secs = 3 }; |
|
392 |
++frames; |
|
393 |
if (timer.elapsed() >= Secs * 1000) { |
|
394 |
qDebug("%d fps", int(double(frames) / double(Secs))); |
|
395 |
frames = 0; |
|
396 |
timer.restart(); |
|
397 |
} |
|
398 |
#endif |
|
399 |
} |
|
400 |
||
401 |
void QDirectFBWindowSurface::beginPaint(const QRegion &) |
|
402 |
{ |
|
403 |
if (!engine) { |
|
404 |
engine = new QDirectFBPaintEngine(this); |
|
405 |
} |
|
406 |
} |
|
407 |
||
408 |
void QDirectFBWindowSurface::endPaint(const QRegion &) |
|
409 |
{ |
|
410 |
#ifdef QT_NO_DIRECTFB_SUBSURFACE |
|
411 |
unlockSurface(); |
|
412 |
#endif |
|
413 |
} |
|
414 |
||
415 |
IDirectFBSurface *QDirectFBWindowSurface::directFBSurface() const |
|
416 |
{ |
|
417 |
if (!dfbSurface && sibling && sibling->dfbSurface) |
|
418 |
return sibling->dfbSurface; |
|
419 |
return dfbSurface; |
|
420 |
} |
|
421 |
||
422 |
||
423 |
IDirectFBSurface *QDirectFBWindowSurface::surfaceForWidget(const QWidget *widget, QRect *rect) const |
|
424 |
{ |
|
425 |
Q_ASSERT(widget); |
|
426 |
if (!dfbSurface) { |
|
427 |
if (sibling && (!sibling->sibling || sibling->dfbSurface)) |
|
428 |
return sibling->surfaceForWidget(widget, rect); |
|
429 |
return 0; |
|
430 |
} |
|
431 |
QWidget *win = window(); |
|
432 |
Q_ASSERT(win); |
|
433 |
if (rect) { |
|
434 |
if (win == widget) { |
|
435 |
*rect = widget->rect(); |
|
436 |
} else { |
|
437 |
*rect = QRect(widget->mapTo(win, QPoint(0, 0)), widget->size()); |
|
438 |
} |
|
439 |
} |
|
440 |
||
441 |
Q_ASSERT(win == widget || win->isAncestorOf(widget)); |
|
442 |
return dfbSurface; |
|
443 |
} |
|
444 |
||
445 |
void QDirectFBWindowSurface::updateFormat() |
|
446 |
{ |
|
447 |
imageFormat = dfbSurface ? QDirectFBScreen::getImageFormat(dfbSurface) : QImage::Format_Invalid; |
|
448 |
} |
|
449 |
||
450 |
void QDirectFBWindowSurface::releaseSurface() |
|
451 |
{ |
|
452 |
if (dfbSurface) { |
|
453 |
#ifdef QT_DIRECTFB_SUBSURFACE |
|
454 |
releaseSubSurface(); |
|
455 |
#else |
|
456 |
unlockSurface(); |
|
457 |
#endif |
|
458 |
#ifdef QT_NO_DIRECTFB_WM |
|
459 |
Q_ASSERT(screen->primarySurface()); |
|
460 |
if (dfbSurface != screen->primarySurface()) |
|
461 |
#endif |
|
462 |
||
463 |
dfbSurface->Release(dfbSurface); |
|
464 |
dfbSurface = 0; |
|
465 |
} |
|
466 |
} |
|
467 |
||
468 |
||
469 |
QT_END_NAMESPACE |
|
470 |
||
471 |
#endif // QT_NO_QWS_DIRECTFB |
|
472 |
||
473 |