author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
child 7 | f7bc934e204c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
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 "qdirectfbpaintengine.h" |
|
43 |
||
44 |
#ifndef QT_NO_QWS_DIRECTFB |
|
45 |
||
46 |
#include "qdirectfbwindowsurface.h" |
|
47 |
#include "qdirectfbscreen.h" |
|
48 |
#include "qdirectfbpixmap.h" |
|
49 |
#include <directfb.h> |
|
50 |
#include <qtransform.h> |
|
51 |
#include <qvarlengtharray.h> |
|
52 |
#include <qcache.h> |
|
53 |
#include <qmath.h> |
|
54 |
#include <private/qpixmapdata_p.h> |
|
55 |
#include <private/qpixmap_raster_p.h> |
|
56 |
#include <private/qimagepixmapcleanuphooks_p.h> |
|
57 |
||
58 |
QT_BEGIN_NAMESPACE |
|
59 |
||
60 |
class SurfaceCache; |
|
61 |
class QDirectFBPaintEnginePrivate : public QRasterPaintEnginePrivate |
|
62 |
{ |
|
63 |
public: |
|
64 |
enum TransformationTypeFlags { |
|
65 |
Matrix_NegativeScale = 0x100, |
|
66 |
Matrix_RectsUnsupported = (QTransform::TxRotate|QTransform::TxShear|QTransform::TxProject), |
|
67 |
Matrix_BlitsUnsupported = (Matrix_NegativeScale|Matrix_RectsUnsupported) |
|
68 |
}; |
|
69 |
||
70 |
enum CompositionModeStatus { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
71 |
PorterDuff_None = 0x00, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
72 |
PorterDuff_SupportedBlits = 0x01, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
PorterDuff_SupportedPrimitives = 0x02, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
74 |
PorterDuff_SupportedOpaquePrimitives = 0x04, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
75 |
PorterDuff_Dirty = 0x10 |
0 | 76 |
}; |
77 |
||
78 |
enum ClipType { |
|
79 |
ClipUnset, |
|
80 |
NoClip, |
|
81 |
RectClip, |
|
82 |
RegionClip, |
|
83 |
ComplexClip |
|
84 |
}; |
|
85 |
||
86 |
QDirectFBPaintEnginePrivate(QDirectFBPaintEngine *p); |
|
87 |
~QDirectFBPaintEnginePrivate(); |
|
88 |
||
89 |
inline void setTransform(const QTransform &transforma); |
|
90 |
inline void setPen(const QPen &pen); |
|
91 |
inline void setCompositionMode(QPainter::CompositionMode mode); |
|
92 |
inline void setRenderHints(QPainter::RenderHints hints); |
|
93 |
||
94 |
inline void setDFBColor(const QColor &color); |
|
95 |
||
96 |
inline void lock(); |
|
97 |
inline void unlock(); |
|
98 |
static inline void unlock(QDirectFBPaintDevice *device); |
|
99 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
100 |
inline bool testCompositionMode(const QPen *pen, const QBrush *brush, const QColor *color = 0) const; |
0 | 101 |
inline bool isSimpleBrush(const QBrush &brush) const; |
102 |
||
103 |
void drawTiledPixmap(const QRectF &dest, const QPixmap &pixmap, const QPointF &pos); |
|
104 |
void blit(const QRectF &dest, IDirectFBSurface *surface, const QRectF &src); |
|
105 |
||
106 |
inline void updateClip(); |
|
107 |
virtual void systemStateChanged(); |
|
108 |
||
109 |
static IDirectFBSurface *getSurface(const QImage &img, bool *release); |
|
110 |
||
111 |
#ifdef QT_DIRECTFB_IMAGECACHE |
|
112 |
static inline int cacheCost(const QImage &img) { return img.width() * img.height() * img.depth() / 8; } |
|
113 |
#endif |
|
114 |
||
115 |
void prepareForBlit(bool alpha); |
|
116 |
||
117 |
IDirectFBSurface *surface; |
|
118 |
||
119 |
bool antialiased; |
|
120 |
bool simplePen; |
|
121 |
||
122 |
uint transformationType; // this is QTransform::type() + Matrix_NegativeScale if qMin(transform.m11(), transform.m22()) < 0 |
|
123 |
||
124 |
SurfaceCache *surfaceCache; |
|
125 |
IDirectFB *fb; |
|
126 |
quint8 opacity; |
|
127 |
||
128 |
ClipType clipType; |
|
129 |
QDirectFBPaintDevice *dfbDevice; |
|
130 |
uint compositionModeStatus; |
|
131 |
||
132 |
bool inClip; |
|
133 |
QRect currentClip; |
|
134 |
||
135 |
QDirectFBPaintEngine *q; |
|
136 |
}; |
|
137 |
||
138 |
class SurfaceCache |
|
139 |
{ |
|
140 |
public: |
|
141 |
SurfaceCache() : surface(0), buffer(0), bufsize(0) {} |
|
142 |
~SurfaceCache() { clear(); } |
|
143 |
IDirectFBSurface *getSurface(const uint *buf, int size); |
|
144 |
void clear(); |
|
145 |
private: |
|
146 |
IDirectFBSurface *surface; |
|
147 |
uint *buffer; |
|
148 |
int bufsize; |
|
149 |
}; |
|
150 |
||
151 |
||
152 |
#ifdef QT_DIRECTFB_IMAGECACHE |
|
153 |
QT_BEGIN_INCLUDE_NAMESPACE |
|
154 |
#include <private/qimage_p.h> |
|
155 |
QT_END_INCLUDE_NAMESPACE |
|
156 |
struct CachedImage |
|
157 |
{ |
|
158 |
IDirectFBSurface *surface; |
|
159 |
~CachedImage() |
|
160 |
{ |
|
161 |
if (surface && QDirectFBScreen::instance()) { |
|
162 |
QDirectFBScreen::instance()->releaseDFBSurface(surface); |
|
163 |
} |
|
164 |
} |
|
165 |
}; |
|
166 |
static QCache<qint64, CachedImage> imageCache(4*1024*1024); // 4 MB |
|
167 |
#endif |
|
168 |
||
169 |
#if defined QT_DIRECTFB_WARN_ON_RASTERFALLBACKS || defined QT_DIRECTFB_DISABLE_RASTERFALLBACKS |
|
170 |
#define VOID_ARG() static_cast<bool>(false) |
|
171 |
enum PaintOperation { |
|
172 |
DRAW_RECTS = 0x0001, DRAW_LINES = 0x0002, DRAW_IMAGE = 0x0004, |
|
173 |
DRAW_PIXMAP = 0x0008, DRAW_TILED_PIXMAP = 0x0010, STROKE_PATH = 0x0020, |
|
174 |
DRAW_PATH = 0x0040, DRAW_POINTS = 0x0080, DRAW_ELLIPSE = 0x0100, |
|
175 |
DRAW_POLYGON = 0x0200, DRAW_TEXT = 0x0400, FILL_PATH = 0x0800, |
|
176 |
FILL_RECT = 0x1000, DRAW_COLORSPANS = 0x2000, DRAW_ROUNDED_RECT = 0x4000, |
|
177 |
ALL = 0xffff |
|
178 |
}; |
|
179 |
#endif |
|
180 |
||
181 |
#ifdef QT_DIRECTFB_WARN_ON_RASTERFALLBACKS |
|
182 |
template <typename device, typename T1, typename T2, typename T3> |
|
183 |
static void rasterFallbackWarn(const char *msg, const char *func, const device *dev, |
|
184 |
uint transformationType, bool simplePen, |
|
185 |
uint clipType, uint compositionModeStatus, |
|
186 |
const char *nameOne, const T1 &one, |
|
187 |
const char *nameTwo, const T2 &two, |
|
188 |
const char *nameThree, const T3 &three); |
|
189 |
#endif |
|
190 |
||
191 |
#if defined QT_DIRECTFB_WARN_ON_RASTERFALLBACKS && defined QT_DIRECTFB_DISABLE_RASTERFALLBACKS |
|
192 |
#define RASTERFALLBACK(op, one, two, three) \ |
|
193 |
if (op & (QT_DIRECTFB_WARN_ON_RASTERFALLBACKS)) \ |
|
194 |
rasterFallbackWarn("Disabled raster engine operation", \ |
|
195 |
__FUNCTION__, state()->painter->device(), \ |
|
196 |
d_func()->transformationType, \ |
|
197 |
d_func()->simplePen, \ |
|
198 |
d_func()->clipType, \ |
|
199 |
d_func()->compositionModeStatus, \ |
|
200 |
#one, one, #two, two, #three, three); \ |
|
201 |
if (op & (QT_DIRECTFB_DISABLE_RASTERFALLBACKS)) \ |
|
202 |
return; |
|
203 |
#elif defined QT_DIRECTFB_DISABLE_RASTERFALLBACKS |
|
204 |
#define RASTERFALLBACK(op, one, two, three) \ |
|
205 |
if (op & (QT_DIRECTFB_DISABLE_RASTERFALLBACKS)) \ |
|
206 |
return; |
|
207 |
#elif defined QT_DIRECTFB_WARN_ON_RASTERFALLBACKS |
|
208 |
#define RASTERFALLBACK(op, one, two, three) \ |
|
209 |
if (op & (QT_DIRECTFB_WARN_ON_RASTERFALLBACKS)) \ |
|
210 |
rasterFallbackWarn("Falling back to raster engine for", \ |
|
211 |
__FUNCTION__, state()->painter->device(), \ |
|
212 |
d_func()->transformationType, \ |
|
213 |
d_func()->simplePen, \ |
|
214 |
d_func()->clipType, \ |
|
215 |
d_func()->compositionModeStatus, \ |
|
216 |
#one, one, #two, two, #three, three); |
|
217 |
#else |
|
218 |
#define RASTERFALLBACK(op, one, two, three) |
|
219 |
#endif |
|
220 |
||
221 |
template <class T> |
|
222 |
static inline void drawLines(const T *lines, int n, const QTransform &transform, IDirectFBSurface *surface); |
|
223 |
template <class T> |
|
224 |
static inline void fillRects(const T *rects, int n, const QTransform &transform, IDirectFBSurface *surface); |
|
225 |
template <class T> |
|
226 |
static inline void drawRects(const T *rects, int n, const QTransform &transform, IDirectFBSurface *surface); |
|
227 |
||
228 |
#define CLIPPED_PAINT(operation) { \ |
|
229 |
d->unlock(); \ |
|
230 |
DFBRegion clipRegion; \ |
|
231 |
switch (d->clipType) { \ |
|
232 |
case QDirectFBPaintEnginePrivate::NoClip: \ |
|
233 |
case QDirectFBPaintEnginePrivate::RectClip: \ |
|
234 |
operation; \ |
|
235 |
break; \ |
|
236 |
case QDirectFBPaintEnginePrivate::RegionClip: { \ |
|
237 |
Q_ASSERT(d->clip()); \ |
|
238 |
const QVector<QRect> cr = d->clip()->clipRegion.rects(); \ |
|
239 |
const int size = cr.size(); \ |
|
240 |
for (int i=0; i<size; ++i) { \ |
|
241 |
d->currentClip = cr.at(i); \ |
|
242 |
clipRegion.x1 = d->currentClip.x(); \ |
|
243 |
clipRegion.y1 = d->currentClip.y(); \ |
|
244 |
clipRegion.x2 = d->currentClip.right(); \ |
|
245 |
clipRegion.y2 = d->currentClip.bottom(); \ |
|
246 |
d->surface->SetClip(d->surface, &clipRegion); \ |
|
247 |
operation; \ |
|
248 |
} \ |
|
249 |
d->updateClip(); \ |
|
250 |
break; } \ |
|
251 |
case QDirectFBPaintEnginePrivate::ComplexClip: \ |
|
252 |
case QDirectFBPaintEnginePrivate::ClipUnset: \ |
|
253 |
qFatal("CLIPPED_PAINT internal error %d", d->clipType); \ |
|
254 |
break; \ |
|
255 |
} \ |
|
256 |
} |
|
257 |
||
258 |
||
259 |
QDirectFBPaintEngine::QDirectFBPaintEngine(QPaintDevice *device) |
|
260 |
: QRasterPaintEngine(*(new QDirectFBPaintEnginePrivate(this)), device) |
|
261 |
{ |
|
262 |
} |
|
263 |
||
264 |
QDirectFBPaintEngine::~QDirectFBPaintEngine() |
|
265 |
{ |
|
266 |
} |
|
267 |
||
268 |
bool QDirectFBPaintEngine::begin(QPaintDevice *device) |
|
269 |
{ |
|
270 |
Q_D(QDirectFBPaintEngine); |
|
271 |
if (device->devType() == QInternal::CustomRaster) { |
|
272 |
d->dfbDevice = static_cast<QDirectFBPaintDevice*>(device); |
|
273 |
} else if (device->devType() == QInternal::Pixmap) { |
|
274 |
QPixmapData *data = static_cast<QPixmap*>(device)->pixmapData(); |
|
275 |
Q_ASSERT(data->classId() == QPixmapData::DirectFBClass); |
|
276 |
QDirectFBPixmapData *dfbPixmapData = static_cast<QDirectFBPixmapData*>(data); |
|
277 |
QDirectFBPaintEnginePrivate::unlock(dfbPixmapData); |
|
278 |
d->dfbDevice = static_cast<QDirectFBPaintDevice*>(dfbPixmapData); |
|
279 |
} |
|
280 |
||
281 |
if (d->dfbDevice) |
|
282 |
d->surface = d->dfbDevice->directFBSurface(); |
|
283 |
||
284 |
if (!d->surface) { |
|
285 |
qFatal("QDirectFBPaintEngine used on an invalid device: 0x%x", |
|
286 |
device->devType()); |
|
287 |
} |
|
288 |
||
289 |
d->prepare(d->dfbDevice); |
|
290 |
gccaps = AllFeatures; |
|
291 |
d->setCompositionMode(state()->composition_mode); |
|
292 |
||
293 |
return QRasterPaintEngine::begin(device); |
|
294 |
} |
|
295 |
||
296 |
bool QDirectFBPaintEngine::end() |
|
297 |
{ |
|
298 |
Q_D(QDirectFBPaintEngine); |
|
299 |
d->unlock(); |
|
300 |
d->dfbDevice = 0; |
|
301 |
#if (Q_DIRECTFB_VERSION >= 0x010000) |
|
302 |
d->surface->ReleaseSource(d->surface); |
|
303 |
#endif |
|
304 |
d->currentClip = QRect(); |
|
305 |
d->surface->SetClip(d->surface, NULL); |
|
306 |
d->surface = 0; |
|
307 |
return QRasterPaintEngine::end(); |
|
308 |
} |
|
309 |
||
310 |
void QDirectFBPaintEngine::clipEnabledChanged() |
|
311 |
{ |
|
312 |
Q_D(QDirectFBPaintEngine); |
|
313 |
QRasterPaintEngine::clipEnabledChanged(); |
|
314 |
d->updateClip(); |
|
315 |
} |
|
316 |
||
317 |
void QDirectFBPaintEngine::penChanged() |
|
318 |
{ |
|
319 |
Q_D(QDirectFBPaintEngine); |
|
320 |
d->setPen(state()->pen); |
|
321 |
||
322 |
QRasterPaintEngine::penChanged(); |
|
323 |
} |
|
324 |
||
325 |
void QDirectFBPaintEngine::opacityChanged() |
|
326 |
{ |
|
327 |
Q_D(QDirectFBPaintEngine); |
|
328 |
d->opacity = quint8(state()->opacity * 255); |
|
329 |
QRasterPaintEngine::opacityChanged(); |
|
330 |
} |
|
331 |
||
332 |
void QDirectFBPaintEngine::compositionModeChanged() |
|
333 |
{ |
|
334 |
Q_D(QDirectFBPaintEngine); |
|
335 |
d->setCompositionMode(state()->compositionMode()); |
|
336 |
QRasterPaintEngine::compositionModeChanged(); |
|
337 |
} |
|
338 |
||
339 |
void QDirectFBPaintEngine::renderHintsChanged() |
|
340 |
{ |
|
341 |
Q_D(QDirectFBPaintEngine); |
|
342 |
d->setRenderHints(state()->renderHints); |
|
343 |
QRasterPaintEngine::renderHintsChanged(); |
|
344 |
} |
|
345 |
||
346 |
void QDirectFBPaintEngine::transformChanged() |
|
347 |
{ |
|
348 |
Q_D(QDirectFBPaintEngine); |
|
349 |
d->setTransform(state()->matrix); |
|
350 |
QRasterPaintEngine::transformChanged(); |
|
351 |
} |
|
352 |
||
353 |
void QDirectFBPaintEngine::setState(QPainterState *state) |
|
354 |
{ |
|
355 |
Q_D(QDirectFBPaintEngine); |
|
356 |
QRasterPaintEngine::setState(state); |
|
357 |
d->setPen(state->pen); |
|
358 |
d->opacity = quint8(state->opacity * 255); |
|
359 |
d->setCompositionMode(state->compositionMode()); |
|
360 |
d->setTransform(state->transform()); |
|
361 |
d->setRenderHints(state->renderHints); |
|
362 |
if (d->surface) |
|
363 |
d->updateClip(); |
|
364 |
} |
|
365 |
||
366 |
void QDirectFBPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op) |
|
367 |
{ |
|
368 |
Q_D(QDirectFBPaintEngine); |
|
369 |
const bool wasInClip = d->inClip; |
|
370 |
d->inClip = true; |
|
371 |
QRasterPaintEngine::clip(path, op); |
|
372 |
if (!wasInClip) { |
|
373 |
d->inClip = false; |
|
374 |
d->updateClip(); |
|
375 |
} |
|
376 |
} |
|
377 |
||
378 |
void QDirectFBPaintEngine::clip(const QRegion ®ion, Qt::ClipOperation op) |
|
379 |
{ |
|
380 |
Q_D(QDirectFBPaintEngine); |
|
381 |
const bool wasInClip = d->inClip; |
|
382 |
d->inClip = true; |
|
383 |
QRasterPaintEngine::clip(region, op); |
|
384 |
if (!wasInClip) { |
|
385 |
d->inClip = false; |
|
386 |
d->updateClip(); |
|
387 |
} |
|
388 |
} |
|
389 |
||
390 |
void QDirectFBPaintEngine::clip(const QRect &rect, Qt::ClipOperation op) |
|
391 |
{ |
|
392 |
Q_D(QDirectFBPaintEngine); |
|
393 |
const bool wasInClip = d->inClip; |
|
394 |
d->inClip = true; |
|
395 |
QRasterPaintEngine::clip(rect, op); |
|
396 |
if (!wasInClip) { |
|
397 |
d->inClip = false; |
|
398 |
d->updateClip(); |
|
399 |
} |
|
400 |
} |
|
401 |
||
402 |
void QDirectFBPaintEngine::drawRects(const QRect *rects, int rectCount) |
|
403 |
{ |
|
404 |
Q_D(QDirectFBPaintEngine); |
|
405 |
const QPen &pen = state()->pen; |
|
406 |
const QBrush &brush = state()->brush; |
|
407 |
if (brush.style() == Qt::NoBrush && pen.style() == Qt::NoPen) |
|
408 |
return; |
|
409 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
410 |
if ((d->transformationType & QDirectFBPaintEnginePrivate::Matrix_RectsUnsupported) |
0 | 411 |
|| !d->simplePen |
412 |
|| d->clipType == QDirectFBPaintEnginePrivate::ComplexClip |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
413 |
|| !d->isSimpleBrush(brush) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
414 |
|| !d->testCompositionMode(&pen, &brush)) { |
0 | 415 |
RASTERFALLBACK(DRAW_RECTS, rectCount, VOID_ARG(), VOID_ARG()); |
416 |
d->lock(); |
|
417 |
QRasterPaintEngine::drawRects(rects, rectCount); |
|
418 |
return; |
|
419 |
} |
|
420 |
||
421 |
if (brush.style() != Qt::NoBrush) { |
|
422 |
d->setDFBColor(brush.color()); |
|
423 |
CLIPPED_PAINT(QT_PREPEND_NAMESPACE(fillRects<QRect>)(rects, rectCount, state()->matrix, d->surface)); |
|
424 |
} |
|
425 |
||
426 |
if (pen.style() != Qt::NoPen) { |
|
427 |
d->setDFBColor(pen.color()); |
|
428 |
CLIPPED_PAINT(QT_PREPEND_NAMESPACE(drawRects<QRect>)(rects, rectCount, state()->matrix, d->surface)); |
|
429 |
} |
|
430 |
} |
|
431 |
||
432 |
void QDirectFBPaintEngine::drawRects(const QRectF *rects, int rectCount) |
|
433 |
{ |
|
434 |
Q_D(QDirectFBPaintEngine); |
|
435 |
const QPen &pen = state()->pen; |
|
436 |
const QBrush &brush = state()->brush; |
|
437 |
if (brush.style() == Qt::NoBrush && pen.style() == Qt::NoPen) |
|
438 |
return; |
|
439 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
440 |
if ((d->transformationType & QDirectFBPaintEnginePrivate::Matrix_RectsUnsupported) |
0 | 441 |
|| !d->simplePen |
442 |
|| d->clipType == QDirectFBPaintEnginePrivate::ComplexClip |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
443 |
|| !d->isSimpleBrush(brush) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
444 |
|| !d->testCompositionMode(&pen, &brush)) { |
0 | 445 |
RASTERFALLBACK(DRAW_RECTS, rectCount, VOID_ARG(), VOID_ARG()); |
446 |
d->lock(); |
|
447 |
QRasterPaintEngine::drawRects(rects, rectCount); |
|
448 |
return; |
|
449 |
} |
|
450 |
||
451 |
if (brush.style() != Qt::NoBrush) { |
|
452 |
d->setDFBColor(brush.color()); |
|
453 |
CLIPPED_PAINT(fillRects<QRectF>(rects, rectCount, state()->matrix, d->surface)); |
|
454 |
} |
|
455 |
||
456 |
if (pen.style() != Qt::NoPen) { |
|
457 |
d->setDFBColor(pen.color()); |
|
458 |
CLIPPED_PAINT(QT_PREPEND_NAMESPACE(drawRects<QRectF>)(rects, rectCount, state()->matrix, d->surface)); |
|
459 |
} |
|
460 |
} |
|
461 |
||
462 |
void QDirectFBPaintEngine::drawLines(const QLine *lines, int lineCount) |
|
463 |
{ |
|
464 |
Q_D(QDirectFBPaintEngine); |
|
465 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
466 |
const QPen &pen = state()->pen; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
467 |
if (!d->simplePen |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
468 |
|| d->clipType == QDirectFBPaintEnginePrivate::ComplexClip |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
469 |
|| !d->testCompositionMode(&pen, 0)) { |
0 | 470 |
RASTERFALLBACK(DRAW_LINES, lineCount, VOID_ARG(), VOID_ARG()); |
471 |
d->lock(); |
|
472 |
QRasterPaintEngine::drawLines(lines, lineCount); |
|
473 |
return; |
|
474 |
} |
|
475 |
||
476 |
if (pen.style() != Qt::NoPen) { |
|
477 |
d->setDFBColor(pen.color()); |
|
478 |
CLIPPED_PAINT(QT_PREPEND_NAMESPACE(drawLines<QLine>)(lines, lineCount, state()->matrix, d->surface)); |
|
479 |
} |
|
480 |
} |
|
481 |
||
482 |
void QDirectFBPaintEngine::drawLines(const QLineF *lines, int lineCount) |
|
483 |
{ |
|
484 |
Q_D(QDirectFBPaintEngine); |
|
485 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
486 |
const QPen &pen = state()->pen; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
487 |
if (!d->simplePen |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
488 |
|| d->clipType == QDirectFBPaintEnginePrivate::ComplexClip |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
489 |
|| !d->testCompositionMode(&pen, 0)) { |
0 | 490 |
RASTERFALLBACK(DRAW_LINES, lineCount, VOID_ARG(), VOID_ARG()); |
491 |
d->lock(); |
|
492 |
QRasterPaintEngine::drawLines(lines, lineCount); |
|
493 |
return; |
|
494 |
} |
|
495 |
||
496 |
if (pen.style() != Qt::NoPen) { |
|
497 |
d->setDFBColor(pen.color()); |
|
498 |
CLIPPED_PAINT(QT_PREPEND_NAMESPACE(drawLines<QLineF>)(lines, lineCount, state()->matrix, d->surface)); |
|
499 |
} |
|
500 |
} |
|
501 |
||
502 |
void QDirectFBPaintEngine::drawImage(const QRectF &r, const QImage &image, |
|
503 |
const QRectF &sr, |
|
504 |
Qt::ImageConversionFlags flags) |
|
505 |
{ |
|
506 |
Q_D(QDirectFBPaintEngine); |
|
507 |
Q_UNUSED(flags); |
|
508 |
||
509 |
/* This is hard to read. The way it works is like this: |
|
510 |
||
511 |
- If you do not have support for preallocated surfaces and do not use an |
|
512 |
image cache we always fall back to raster engine. |
|
513 |
||
514 |
- If it's rotated/sheared/mirrored (negative scale) or we can't |
|
515 |
clip it we fall back to raster engine. |
|
516 |
||
517 |
- If we don't cache the image, but we do have support for |
|
518 |
preallocated surfaces we fall back to the raster engine if the |
|
519 |
image is in a format DirectFB can't handle. |
|
520 |
||
521 |
- If we do cache the image but don't have support for preallocated |
|
522 |
images and the cost of caching the image (bytes used) is higher |
|
523 |
than the max image cache size we fall back to raster engine. |
|
524 |
*/ |
|
525 |
||
526 |
#if !defined QT_NO_DIRECTFB_PREALLOCATED || defined QT_DIRECTFB_IMAGECACHE |
|
527 |
if (!(d->compositionModeStatus & QDirectFBPaintEnginePrivate::PorterDuff_SupportedBlits) |
|
528 |
|| (d->transformationType & QDirectFBPaintEnginePrivate::Matrix_BlitsUnsupported) |
|
529 |
|| d->clipType == QDirectFBPaintEnginePrivate::ComplexClip |
|
530 |
#ifndef QT_DIRECTFB_IMAGECACHE |
|
531 |
|| QDirectFBScreen::getSurfacePixelFormat(image.format()) == DSPF_UNKNOWN |
|
532 |
#elif defined QT_NO_DIRECTFB_PREALLOCATED |
|
533 |
|| QDirectFBPaintEnginePrivate::cacheCost(image) > imageCache.maxCost() |
|
534 |
#endif |
|
535 |
) |
|
536 |
#endif |
|
537 |
{ |
|
538 |
RASTERFALLBACK(DRAW_IMAGE, r, image.size(), sr); |
|
539 |
d->lock(); |
|
540 |
QRasterPaintEngine::drawImage(r, image, sr, flags); |
|
541 |
return; |
|
542 |
} |
|
543 |
#if !defined QT_NO_DIRECTFB_PREALLOCATED || defined QT_DIRECTFB_IMAGECACHE |
|
544 |
bool release; |
|
545 |
IDirectFBSurface *imgSurface = d->getSurface(image, &release); |
|
546 |
d->prepareForBlit(QDirectFBScreen::hasAlphaChannel(imgSurface)); |
|
547 |
CLIPPED_PAINT(d->blit(r, imgSurface, sr)); |
|
548 |
if (release) { |
|
549 |
#if (Q_DIRECTFB_VERSION >= 0x010000) |
|
550 |
d->surface->ReleaseSource(d->surface); |
|
551 |
#endif |
|
552 |
imgSurface->Release(imgSurface); |
|
553 |
} |
|
554 |
#endif |
|
555 |
} |
|
556 |
||
557 |
void QDirectFBPaintEngine::drawImage(const QPointF &p, const QImage &img) |
|
558 |
{ |
|
559 |
drawImage(QRectF(p, img.size()), img, img.rect()); |
|
560 |
} |
|
561 |
||
562 |
void QDirectFBPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pixmap, |
|
563 |
const QRectF &sr) |
|
564 |
{ |
|
565 |
Q_D(QDirectFBPaintEngine); |
|
566 |
||
567 |
if (pixmap.pixmapData()->classId() != QPixmapData::DirectFBClass) { |
|
568 |
RASTERFALLBACK(DRAW_PIXMAP, r, pixmap.size(), sr); |
|
569 |
d->lock(); |
|
570 |
QRasterPaintEngine::drawPixmap(r, pixmap, sr); |
|
571 |
} else { |
|
572 |
QPixmapData *data = pixmap.pixmapData(); |
|
573 |
Q_ASSERT(data->classId() == QPixmapData::DirectFBClass); |
|
574 |
QDirectFBPixmapData *dfbData = static_cast<QDirectFBPixmapData*>(data); |
|
575 |
if (!(d->compositionModeStatus & QDirectFBPaintEnginePrivate::PorterDuff_SupportedBlits) |
|
576 |
|| (d->transformationType & QDirectFBPaintEnginePrivate::Matrix_BlitsUnsupported) |
|
577 |
|| d->clipType == QDirectFBPaintEnginePrivate::ComplexClip |
|
578 |
|| (state()->renderHints & QPainter::SmoothPixmapTransform |
|
579 |
&& state()->matrix.mapRect(r).size() != sr.size())) { |
|
580 |
RASTERFALLBACK(DRAW_PIXMAP, r, pixmap.size(), sr); |
|
581 |
const QImage *img = dfbData->buffer(); |
|
582 |
d->lock(); |
|
583 |
QRasterPaintEngine::drawImage(r, *img, sr); |
|
584 |
} else { |
|
585 |
QDirectFBPaintEnginePrivate::unlock(dfbData); |
|
586 |
d->prepareForBlit(pixmap.hasAlphaChannel()); |
|
587 |
IDirectFBSurface *s = dfbData->directFBSurface(); |
|
588 |
CLIPPED_PAINT(d->blit(r, s, sr)); |
|
589 |
} |
|
590 |
} |
|
591 |
} |
|
592 |
||
593 |
void QDirectFBPaintEngine::drawPixmap(const QPointF &p, const QPixmap &pm) |
|
594 |
{ |
|
595 |
drawPixmap(QRectF(p, pm.size()), pm, pm.rect()); |
|
596 |
} |
|
597 |
||
598 |
void QDirectFBPaintEngine::drawTiledPixmap(const QRectF &r, |
|
599 |
const QPixmap &pixmap, |
|
600 |
const QPointF &offset) |
|
601 |
{ |
|
602 |
Q_D(QDirectFBPaintEngine); |
|
603 |
if (pixmap.pixmapData()->classId() != QPixmapData::DirectFBClass) { |
|
604 |
RASTERFALLBACK(DRAW_TILED_PIXMAP, r, pixmap.size(), offset); |
|
605 |
d->lock(); |
|
606 |
QRasterPaintEngine::drawTiledPixmap(r, pixmap, offset); |
|
607 |
} else if (!(d->compositionModeStatus & QDirectFBPaintEnginePrivate::PorterDuff_SupportedBlits) |
|
608 |
|| (d->transformationType & QDirectFBPaintEnginePrivate::Matrix_BlitsUnsupported) |
|
609 |
|| d->clipType == QDirectFBPaintEnginePrivate::ComplexClip |
|
610 |
|| (state()->renderHints & QPainter::SmoothPixmapTransform && state()->matrix.isScaling())) { |
|
611 |
RASTERFALLBACK(DRAW_TILED_PIXMAP, r, pixmap.size(), offset); |
|
612 |
QPixmapData *pixmapData = pixmap.pixmapData(); |
|
613 |
Q_ASSERT(pixmapData->classId() == QPixmapData::DirectFBClass); |
|
614 |
QDirectFBPixmapData *dfbData = static_cast<QDirectFBPixmapData*>(pixmapData); |
|
615 |
const QImage *img = dfbData->buffer(); |
|
616 |
d->lock(); |
|
617 |
QRasterPixmapData *data = new QRasterPixmapData(QPixmapData::PixmapType); |
|
618 |
data->fromImage(*img, Qt::AutoColor); |
|
619 |
const QPixmap pix(data); |
|
620 |
QRasterPaintEngine::drawTiledPixmap(r, pix, offset); |
|
621 |
} else { |
|
622 |
CLIPPED_PAINT(d->drawTiledPixmap(r, pixmap, offset)); |
|
623 |
} |
|
624 |
} |
|
625 |
||
626 |
||
627 |
void QDirectFBPaintEngine::stroke(const QVectorPath &path, const QPen &pen) |
|
628 |
{ |
|
629 |
RASTERFALLBACK(STROKE_PATH, path, VOID_ARG(), VOID_ARG()); |
|
630 |
Q_D(QDirectFBPaintEngine); |
|
631 |
d->lock(); |
|
632 |
QRasterPaintEngine::stroke(path, pen); |
|
633 |
} |
|
634 |
||
635 |
void QDirectFBPaintEngine::drawPath(const QPainterPath &path) |
|
636 |
{ |
|
637 |
RASTERFALLBACK(DRAW_PATH, path, VOID_ARG(), VOID_ARG()); |
|
638 |
Q_D(QDirectFBPaintEngine); |
|
639 |
d->lock(); |
|
640 |
QRasterPaintEngine::drawPath(path); |
|
641 |
} |
|
642 |
||
643 |
void QDirectFBPaintEngine::drawPoints(const QPointF *points, int pointCount) |
|
644 |
{ |
|
645 |
RASTERFALLBACK(DRAW_POINTS, pointCount, VOID_ARG(), VOID_ARG()); |
|
646 |
Q_D(QDirectFBPaintEngine); |
|
647 |
d->lock(); |
|
648 |
QRasterPaintEngine::drawPoints(points, pointCount); |
|
649 |
} |
|
650 |
||
651 |
void QDirectFBPaintEngine::drawPoints(const QPoint *points, int pointCount) |
|
652 |
{ |
|
653 |
RASTERFALLBACK(DRAW_POINTS, pointCount, VOID_ARG(), VOID_ARG()); |
|
654 |
Q_D(QDirectFBPaintEngine); |
|
655 |
d->lock(); |
|
656 |
QRasterPaintEngine::drawPoints(points, pointCount); |
|
657 |
} |
|
658 |
||
659 |
void QDirectFBPaintEngine::drawEllipse(const QRectF &rect) |
|
660 |
{ |
|
661 |
RASTERFALLBACK(DRAW_ELLIPSE, rect, VOID_ARG(), VOID_ARG()); |
|
662 |
Q_D(QDirectFBPaintEngine); |
|
663 |
d->lock(); |
|
664 |
QRasterPaintEngine::drawEllipse(rect); |
|
665 |
} |
|
666 |
||
667 |
void QDirectFBPaintEngine::drawPolygon(const QPointF *points, int pointCount, |
|
668 |
PolygonDrawMode mode) |
|
669 |
{ |
|
670 |
RASTERFALLBACK(DRAW_POLYGON, pointCount, mode, VOID_ARG()); |
|
671 |
Q_D(QDirectFBPaintEngine); |
|
672 |
d->lock(); |
|
673 |
QRasterPaintEngine::drawPolygon(points, pointCount, mode); |
|
674 |
} |
|
675 |
||
676 |
void QDirectFBPaintEngine::drawPolygon(const QPoint *points, int pointCount, |
|
677 |
PolygonDrawMode mode) |
|
678 |
{ |
|
679 |
RASTERFALLBACK(DRAW_POLYGON, pointCount, mode, VOID_ARG()); |
|
680 |
Q_D(QDirectFBPaintEngine); |
|
681 |
d->lock(); |
|
682 |
QRasterPaintEngine::drawPolygon(points, pointCount, mode); |
|
683 |
} |
|
684 |
||
685 |
void QDirectFBPaintEngine::drawTextItem(const QPointF &p, |
|
686 |
const QTextItem &textItem) |
|
687 |
{ |
|
688 |
RASTERFALLBACK(DRAW_TEXT, p, textItem.text(), VOID_ARG()); |
|
689 |
Q_D(QDirectFBPaintEngine); |
|
690 |
d->lock(); |
|
691 |
QRasterPaintEngine::drawTextItem(p, textItem); |
|
692 |
} |
|
693 |
||
694 |
void QDirectFBPaintEngine::fill(const QVectorPath &path, const QBrush &brush) |
|
695 |
{ |
|
696 |
if (brush.style() == Qt::NoBrush) |
|
697 |
return; |
|
698 |
RASTERFALLBACK(FILL_PATH, path, brush, VOID_ARG()); |
|
699 |
Q_D(QDirectFBPaintEngine); |
|
700 |
d->lock(); |
|
701 |
QRasterPaintEngine::fill(path, brush); |
|
702 |
} |
|
703 |
||
704 |
void QDirectFBPaintEngine::drawRoundedRect(const QRectF &rect, qreal xrad, qreal yrad, Qt::SizeMode mode) |
|
705 |
{ |
|
706 |
RASTERFALLBACK(DRAW_ROUNDED_RECT, rect, xrad, yrad); |
|
707 |
Q_D(QDirectFBPaintEngine); |
|
708 |
d->lock(); |
|
709 |
QRasterPaintEngine::drawRoundedRect(rect, xrad, yrad, mode); |
|
710 |
} |
|
711 |
||
712 |
void QDirectFBPaintEngine::fillRect(const QRectF &rect, const QBrush &brush) |
|
713 |
{ |
|
714 |
Q_D(QDirectFBPaintEngine); |
|
715 |
if (brush.style() == Qt::NoBrush) |
|
716 |
return; |
|
717 |
if (d->clipType != QDirectFBPaintEnginePrivate::ComplexClip) { |
|
718 |
switch (brush.style()) { |
|
719 |
case Qt::SolidPattern: { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
720 |
if (d->transformationType & QDirectFBPaintEnginePrivate::Matrix_RectsUnsupported |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
721 |
|| !d->testCompositionMode(0, &brush)) { |
0 | 722 |
break; |
723 |
} |
|
724 |
const QColor color = brush.color(); |
|
725 |
if (!color.isValid()) |
|
726 |
return; |
|
727 |
d->setDFBColor(color); |
|
728 |
const QRect r = state()->matrix.mapRect(rect).toRect(); |
|
729 |
CLIPPED_PAINT(d->surface->FillRectangle(d->surface, r.x(), r.y(), r.width(), r.height())); |
|
730 |
return; } |
|
731 |
||
732 |
case Qt::TexturePattern: { |
|
733 |
if (!(d->compositionModeStatus & QDirectFBPaintEnginePrivate::PorterDuff_SupportedBlits) |
|
734 |
|| (d->transformationType & QDirectFBPaintEnginePrivate::Matrix_BlitsUnsupported) |
|
735 |
|| (state()->renderHints & QPainter::SmoothPixmapTransform && state()->matrix.isScaling())) { |
|
736 |
break; |
|
737 |
} |
|
738 |
||
739 |
const QPixmap texture = brush.texture(); |
|
740 |
if (texture.pixmapData()->classId() != QPixmapData::DirectFBClass) |
|
741 |
break; |
|
742 |
||
743 |
CLIPPED_PAINT(d->drawTiledPixmap(rect, texture, rect.topLeft() - state()->brushOrigin)); |
|
744 |
return; } |
|
745 |
default: |
|
746 |
break; |
|
747 |
} |
|
748 |
} |
|
749 |
RASTERFALLBACK(FILL_RECT, rect, brush, VOID_ARG()); |
|
750 |
d->lock(); |
|
751 |
QRasterPaintEngine::fillRect(rect, brush); |
|
752 |
} |
|
753 |
||
754 |
void QDirectFBPaintEngine::fillRect(const QRectF &rect, const QColor &color) |
|
755 |
{ |
|
756 |
if (!color.isValid()) |
|
757 |
return; |
|
758 |
Q_D(QDirectFBPaintEngine); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
759 |
if ((d->transformationType & QDirectFBPaintEnginePrivate::Matrix_RectsUnsupported) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
760 |
|| d->clipType == QDirectFBPaintEnginePrivate::ComplexClip |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
761 |
|| !d->testCompositionMode(0, 0, &color)) { |
0 | 762 |
RASTERFALLBACK(FILL_RECT, rect, color, VOID_ARG()); |
763 |
d->lock(); |
|
764 |
QRasterPaintEngine::fillRect(rect, color); |
|
765 |
} else { |
|
766 |
d->setDFBColor(color); |
|
767 |
const QRect r = state()->matrix.mapRect(rect).toRect(); |
|
768 |
CLIPPED_PAINT(d->surface->FillRectangle(d->surface, r.x(), r.y(), r.width(), r.height())); |
|
769 |
} |
|
770 |
} |
|
771 |
||
772 |
void QDirectFBPaintEngine::drawBufferSpan(const uint *buffer, int bufsize, |
|
773 |
int x, int y, int length, |
|
774 |
uint const_alpha) |
|
775 |
{ |
|
776 |
Q_D(QDirectFBPaintEngine); |
|
777 |
IDirectFBSurface *src = d->surfaceCache->getSurface(buffer, bufsize); |
|
778 |
// ### how does this play with setDFBColor |
|
779 |
src->SetColor(src, 0, 0, 0, const_alpha); |
|
780 |
const DFBRectangle rect = { 0, 0, length, 1 }; |
|
781 |
d->surface->Blit(d->surface, src, &rect, x, y); |
|
782 |
} |
|
783 |
||
784 |
#ifdef QT_DIRECTFB_IMAGECACHE |
|
785 |
static void cachedImageCleanupHook(qint64 key) |
|
786 |
{ |
|
787 |
delete imageCache.take(key); |
|
788 |
} |
|
789 |
void QDirectFBPaintEngine::initImageCache(int size) |
|
790 |
{ |
|
791 |
Q_ASSERT(size >= 0); |
|
792 |
imageCache.setMaxCost(size); |
|
793 |
QImagePixmapCleanupHooks::instance()->addImageHook(cachedImageCleanupHook); |
|
794 |
} |
|
795 |
||
796 |
#endif // QT_DIRECTFB_IMAGECACHE |
|
797 |
||
798 |
// ---- QDirectFBPaintEnginePrivate ---- |
|
799 |
||
800 |
||
801 |
QDirectFBPaintEnginePrivate::QDirectFBPaintEnginePrivate(QDirectFBPaintEngine *p) |
|
802 |
: surface(0), antialiased(false), simplePen(false), |
|
803 |
transformationType(0), opacity(255), |
|
804 |
clipType(ClipUnset), dfbDevice(0), |
|
805 |
compositionModeStatus(0), inClip(false), q(p) |
|
806 |
{ |
|
807 |
fb = QDirectFBScreen::instance()->dfb(); |
|
808 |
surfaceCache = new SurfaceCache; |
|
809 |
} |
|
810 |
||
811 |
QDirectFBPaintEnginePrivate::~QDirectFBPaintEnginePrivate() |
|
812 |
{ |
|
813 |
delete surfaceCache; |
|
814 |
} |
|
815 |
||
816 |
bool QDirectFBPaintEnginePrivate::isSimpleBrush(const QBrush &brush) const |
|
817 |
{ |
|
818 |
return (brush.style() == Qt::NoBrush) || (brush.style() == Qt::SolidPattern && !antialiased); |
|
819 |
} |
|
820 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
821 |
bool QDirectFBPaintEnginePrivate::testCompositionMode(const QPen *pen, const QBrush *brush, const QColor *color) const |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
822 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
823 |
Q_ASSERT(!pen || pen->style() == Qt::NoPen || pen->style() == Qt::SolidLine); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
824 |
Q_ASSERT(!brush || brush->style() == Qt::NoBrush || brush->style() == Qt::SolidPattern); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
825 |
switch (compositionModeStatus & (QDirectFBPaintEnginePrivate::PorterDuff_SupportedOpaquePrimitives |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
826 |
|QDirectFBPaintEnginePrivate::PorterDuff_SupportedPrimitives)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
827 |
case QDirectFBPaintEnginePrivate::PorterDuff_SupportedPrimitives: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
828 |
return true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
829 |
case QDirectFBPaintEnginePrivate::PorterDuff_SupportedOpaquePrimitives: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
830 |
if (pen && pen->style() == Qt::SolidLine && pen->color().alpha() != 255) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
831 |
return false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
832 |
if (brush) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
833 |
if (brush->style() == Qt::SolidPattern && brush->color().alpha() != 255) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
834 |
return false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
835 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
836 |
} else if (color && color->alpha() != 255) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
837 |
return false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
838 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
839 |
return true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
840 |
case QDirectFBPaintEnginePrivate::PorterDuff_None: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
841 |
return false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
842 |
default: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
843 |
// ### PorterDuff_SupportedOpaquePrimitives|PorterDuff_SupportedPrimitives can't be combined |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
844 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
845 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
846 |
Q_ASSERT(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
847 |
return false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
848 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
849 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
850 |
|
0 | 851 |
void QDirectFBPaintEnginePrivate::lock() |
852 |
{ |
|
853 |
// We will potentially get a new pointer to the buffer after a |
|
854 |
// lock so we need to call the base implementation of prepare so |
|
855 |
// it updates its rasterBuffer to point to the new buffer address. |
|
856 |
Q_ASSERT(dfbDevice); |
|
857 |
if (dfbDevice->lockSurface(DSLF_READ|DSLF_WRITE)) { |
|
858 |
prepare(dfbDevice); |
|
859 |
} |
|
860 |
} |
|
861 |
||
862 |
void QDirectFBPaintEnginePrivate::unlock() |
|
863 |
{ |
|
864 |
Q_ASSERT(dfbDevice); |
|
865 |
#ifdef QT_DIRECTFB_SUBSURFACE |
|
866 |
dfbDevice->syncPending = true; |
|
867 |
#else |
|
868 |
QDirectFBPaintEnginePrivate::unlock(dfbDevice); |
|
869 |
#endif |
|
870 |
} |
|
871 |
||
872 |
void QDirectFBPaintEnginePrivate::unlock(QDirectFBPaintDevice *device) |
|
873 |
{ |
|
874 |
#ifdef QT_NO_DIRECTFB_SUBSURFACE |
|
875 |
Q_ASSERT(device); |
|
876 |
device->unlockSurface(); |
|
877 |
#else |
|
878 |
Q_UNUSED(device); |
|
879 |
#endif |
|
880 |
} |
|
881 |
||
882 |
void QDirectFBPaintEnginePrivate::setTransform(const QTransform &transform) |
|
883 |
{ |
|
884 |
transformationType = transform.type(); |
|
885 |
if (qMin(transform.m11(), transform.m22()) < 0) { |
|
886 |
transformationType |= QDirectFBPaintEnginePrivate::Matrix_NegativeScale; |
|
887 |
} |
|
888 |
setPen(q->state()->pen); |
|
889 |
} |
|
890 |
||
891 |
void QDirectFBPaintEnginePrivate::setPen(const QPen &pen) |
|
892 |
{ |
|
893 |
if (pen.style() == Qt::NoPen) { |
|
894 |
simplePen = true; |
|
895 |
} else if (pen.style() == Qt::SolidLine |
|
896 |
&& !antialiased |
|
897 |
&& pen.brush().style() == Qt::SolidPattern |
|
898 |
&& pen.widthF() <= 1.0 |
|
899 |
&& (transformationType < QTransform::TxScale || pen.isCosmetic())) { |
|
900 |
simplePen = true; |
|
901 |
} else { |
|
902 |
simplePen = false; |
|
903 |
} |
|
904 |
} |
|
905 |
||
906 |
void QDirectFBPaintEnginePrivate::setCompositionMode(QPainter::CompositionMode mode) |
|
907 |
{ |
|
908 |
if (!surface) |
|
909 |
return; |
|
910 |
||
911 |
static const bool forceRasterFallBack = qgetenv("QT_DIRECTFB_FORCE_RASTER").toInt() > 0; |
|
912 |
if (forceRasterFallBack) { |
|
913 |
compositionModeStatus = 0; |
|
914 |
return; |
|
915 |
} |
|
916 |
||
917 |
compositionModeStatus = PorterDuff_SupportedBlits; |
|
918 |
switch (mode) { |
|
919 |
case QPainter::CompositionMode_Clear: |
|
920 |
surface->SetPorterDuff(surface, DSPD_CLEAR); |
|
921 |
break; |
|
922 |
case QPainter::CompositionMode_Source: |
|
923 |
surface->SetPorterDuff(surface, DSPD_SRC); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
924 |
compositionModeStatus |= PorterDuff_SupportedOpaquePrimitives; |
0 | 925 |
break; |
926 |
case QPainter::CompositionMode_SourceOver: |
|
927 |
compositionModeStatus |= PorterDuff_SupportedPrimitives; |
|
928 |
surface->SetPorterDuff(surface, DSPD_SRC_OVER); |
|
929 |
break; |
|
930 |
case QPainter::CompositionMode_DestinationOver: |
|
931 |
surface->SetPorterDuff(surface, DSPD_DST_OVER); |
|
932 |
break; |
|
933 |
case QPainter::CompositionMode_SourceIn: |
|
934 |
surface->SetPorterDuff(surface, DSPD_SRC_IN); |
|
935 |
break; |
|
936 |
case QPainter::CompositionMode_DestinationIn: |
|
937 |
surface->SetPorterDuff(surface, DSPD_DST_IN); |
|
938 |
break; |
|
939 |
case QPainter::CompositionMode_SourceOut: |
|
940 |
surface->SetPorterDuff(surface, DSPD_SRC_OUT); |
|
941 |
break; |
|
942 |
case QPainter::CompositionMode_DestinationOut: |
|
943 |
surface->SetPorterDuff(surface, DSPD_DST_OUT); |
|
944 |
break; |
|
945 |
#if (Q_DIRECTFB_VERSION >= 0x010000) |
|
946 |
case QPainter::CompositionMode_SourceAtop: |
|
947 |
surface->SetPorterDuff(surface, DSPD_SRC_ATOP); |
|
948 |
break; |
|
949 |
case QPainter::CompositionMode_DestinationAtop: |
|
950 |
surface->SetPorterDuff(surface, DSPD_DST_ATOP); |
|
951 |
break; |
|
952 |
case QPainter::CompositionMode_Plus: |
|
953 |
surface->SetPorterDuff(surface, DSPD_ADD); |
|
954 |
break; |
|
955 |
case QPainter::CompositionMode_Xor: |
|
956 |
surface->SetPorterDuff(surface, DSPD_XOR); |
|
957 |
break; |
|
958 |
#endif |
|
959 |
default: |
|
960 |
compositionModeStatus = 0; |
|
961 |
break; |
|
962 |
} |
|
963 |
} |
|
964 |
||
965 |
void QDirectFBPaintEnginePrivate::setRenderHints(QPainter::RenderHints hints) |
|
966 |
{ |
|
967 |
const bool old = antialiased; |
|
968 |
antialiased = bool(hints & QPainter::Antialiasing); |
|
969 |
if (old != antialiased) { |
|
970 |
setPen(q->state()->pen); |
|
971 |
} |
|
972 |
} |
|
973 |
||
974 |
void QDirectFBPaintEnginePrivate::prepareForBlit(bool alpha) |
|
975 |
{ |
|
976 |
DFBSurfaceBlittingFlags blittingFlags = alpha ? DSBLIT_BLEND_ALPHACHANNEL : DSBLIT_NOFX; |
|
977 |
if (opacity != 255) { |
|
978 |
blittingFlags |= DSBLIT_BLEND_COLORALPHA; |
|
979 |
} |
|
980 |
surface->SetColor(surface, 0xff, 0xff, 0xff, opacity); |
|
981 |
surface->SetBlittingFlags(surface, blittingFlags); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
982 |
if (compositionModeStatus & PorterDuff_Dirty) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
983 |
setCompositionMode(q->state()->composition_mode); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
984 |
} |
0 | 985 |
} |
986 |
||
987 |
static inline uint ALPHA_MUL(uint x, uint a) |
|
988 |
{ |
|
989 |
uint t = x * a; |
|
990 |
t = ((t + (t >> 8) + 0x80) >> 8) & 0xff; |
|
991 |
return t; |
|
992 |
} |
|
993 |
||
994 |
void QDirectFBPaintEnginePrivate::setDFBColor(const QColor &color) |
|
995 |
{ |
|
996 |
Q_ASSERT(surface); |
|
997 |
const quint8 alpha = (opacity == 255 ? |
|
998 |
color.alpha() : ALPHA_MUL(color.alpha(), opacity)); |
|
999 |
surface->SetColor(surface, color.red(), color.green(), color.blue(), alpha); |
|
1000 |
surface->SetPorterDuff(surface, DSPD_NONE); |
|
1001 |
surface->SetDrawingFlags(surface, alpha == 255 ? DSDRAW_NOFX : DSDRAW_BLEND); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1002 |
compositionModeStatus |= PorterDuff_Dirty; |
0 | 1003 |
} |
1004 |
||
1005 |
IDirectFBSurface *QDirectFBPaintEnginePrivate::getSurface(const QImage &img, bool *release) |
|
1006 |
{ |
|
1007 |
#ifdef QT_NO_DIRECTFB_IMAGECACHE |
|
1008 |
*release = true; |
|
1009 |
return QDirectFBScreen::instance()->createDFBSurface(img, img.format(), QDirectFBScreen::DontTrackSurface); |
|
1010 |
#else |
|
1011 |
const qint64 key = img.cacheKey(); |
|
1012 |
*release = false; |
|
1013 |
if (imageCache.contains(key)) { |
|
1014 |
return imageCache[key]->surface; |
|
1015 |
} |
|
1016 |
||
1017 |
const int cost = cacheCost(img); |
|
1018 |
const bool cache = cost <= imageCache.maxCost(); |
|
1019 |
QDirectFBScreen *screen = QDirectFBScreen::instance(); |
|
1020 |
const QImage::Format format = (img.format() == screen->alphaPixmapFormat() || QDirectFBPixmapData::hasAlphaChannel(img) |
|
1021 |
? screen->alphaPixmapFormat() : screen->pixelFormat()); |
|
1022 |
||
1023 |
IDirectFBSurface *surface = screen->createDFBSurface(img, format, |
|
1024 |
cache |
|
1025 |
? QDirectFBScreen::TrackSurface |
|
1026 |
: QDirectFBScreen::DontTrackSurface); |
|
1027 |
if (cache) { |
|
1028 |
CachedImage *cachedImage = new CachedImage; |
|
1029 |
const_cast<QImage&>(img).data_ptr()->is_cached = true; |
|
1030 |
cachedImage->surface = surface; |
|
1031 |
imageCache.insert(key, cachedImage, cost); |
|
1032 |
} else { |
|
1033 |
*release = true; |
|
1034 |
} |
|
1035 |
return surface; |
|
1036 |
#endif |
|
1037 |
} |
|
1038 |
||
1039 |
||
1040 |
void QDirectFBPaintEnginePrivate::blit(const QRectF &dest, IDirectFBSurface *s, const QRectF &src) |
|
1041 |
{ |
|
1042 |
const QRect sr = src.toRect(); |
|
1043 |
const QRect dr = q->state()->matrix.mapRect(dest).toRect(); |
|
1044 |
if (dr.isEmpty()) |
|
1045 |
return; |
|
1046 |
const DFBRectangle sRect = { sr.x(), sr.y(), sr.width(), sr.height() }; |
|
1047 |
DFBResult result; |
|
1048 |
||
1049 |
if (dr.size() == sr.size()) { |
|
1050 |
result = surface->Blit(surface, s, &sRect, dr.x(), dr.y()); |
|
1051 |
} else { |
|
1052 |
const DFBRectangle dRect = { dr.x(), dr.y(), dr.width(), dr.height() }; |
|
1053 |
result = surface->StretchBlit(surface, s, &sRect, &dRect); |
|
1054 |
} |
|
1055 |
if (result != DFB_OK) |
|
1056 |
DirectFBError("QDirectFBPaintEngine::drawPixmap()", result); |
|
1057 |
} |
|
1058 |
||
1059 |
static inline qreal fixCoord(qreal rect_pos, qreal pixmapSize, qreal offset) |
|
1060 |
{ |
|
1061 |
qreal pos = rect_pos - offset; |
|
1062 |
while (pos > rect_pos) |
|
1063 |
pos -= pixmapSize; |
|
1064 |
while (pos + pixmapSize < rect_pos) |
|
1065 |
pos += pixmapSize; |
|
1066 |
return pos; |
|
1067 |
} |
|
1068 |
||
1069 |
void QDirectFBPaintEnginePrivate::drawTiledPixmap(const QRectF &dest, const QPixmap &pixmap, const QPointF &off) |
|
1070 |
{ |
|
1071 |
Q_ASSERT(!(transformationType & Matrix_BlitsUnsupported)); |
|
1072 |
const QTransform &transform = q->state()->matrix; |
|
1073 |
const QRect destinationRect = transform.mapRect(dest).toRect().normalized(); |
|
1074 |
QRect newClip = destinationRect; |
|
1075 |
if (!currentClip.isEmpty()) |
|
1076 |
newClip &= currentClip; |
|
1077 |
||
1078 |
if (newClip.isNull()) |
|
1079 |
return; |
|
1080 |
||
1081 |
const DFBRegion clip = { |
|
1082 |
newClip.x(), |
|
1083 |
newClip.y(), |
|
1084 |
newClip.right(), |
|
1085 |
newClip.bottom() |
|
1086 |
}; |
|
1087 |
surface->SetClip(surface, &clip); |
|
1088 |
||
1089 |
QPointF offset = off; |
|
1090 |
Q_ASSERT(transform.type() <= QTransform::TxScale); |
|
1091 |
prepareForBlit(pixmap.hasAlphaChannel()); |
|
1092 |
QPixmapData *data = pixmap.pixmapData(); |
|
1093 |
Q_ASSERT(data->classId() == QPixmapData::DirectFBClass); |
|
1094 |
QDirectFBPixmapData *dfbData = static_cast<QDirectFBPixmapData*>(data); |
|
1095 |
QDirectFBPaintEnginePrivate::unlock(dfbData); |
|
1096 |
const QSize pixmapSize = dfbData->size(); |
|
1097 |
IDirectFBSurface *sourceSurface = dfbData->directFBSurface(); |
|
1098 |
if (transform.isScaling()) { |
|
1099 |
Q_ASSERT(qMin(transform.m11(), transform.m22()) >= 0); |
|
1100 |
offset.rx() *= transform.m11(); |
|
1101 |
offset.ry() *= transform.m22(); |
|
1102 |
||
1103 |
const QSizeF mappedSize(pixmapSize.width() * transform.m11(), pixmapSize.height() * transform.m22()); |
|
1104 |
qreal y = fixCoord(destinationRect.y(), mappedSize.height(), offset.y()); |
|
1105 |
const qreal startX = fixCoord(destinationRect.x(), mappedSize.width(), offset.x()); |
|
1106 |
while (y <= destinationRect.bottom()) { |
|
1107 |
qreal x = startX; |
|
1108 |
while (x <= destinationRect.right()) { |
|
1109 |
const DFBRectangle destination = { qRound(x), qRound(y), mappedSize.width(), mappedSize.height() }; |
|
1110 |
surface->StretchBlit(surface, sourceSurface, 0, &destination); |
|
1111 |
x += mappedSize.width(); |
|
1112 |
} |
|
1113 |
y += mappedSize.height(); |
|
1114 |
} |
|
1115 |
} else { |
|
1116 |
qreal y = fixCoord(destinationRect.y(), pixmapSize.height(), offset.y()); |
|
1117 |
const qreal startX = fixCoord(destinationRect.x(), pixmapSize.width(), offset.x()); |
|
1118 |
int horizontal = qMax(1, destinationRect.width() / pixmapSize.width()) + 1; |
|
1119 |
if (startX != destinationRect.x()) |
|
1120 |
++horizontal; |
|
1121 |
int vertical = qMax(1, destinationRect.height() / pixmapSize.height()) + 1; |
|
1122 |
if (y != destinationRect.y()) |
|
1123 |
++vertical; |
|
1124 |
||
1125 |
const int maxCount = (vertical * horizontal); |
|
1126 |
QVarLengthArray<DFBRectangle, 16> sourceRects(maxCount); |
|
1127 |
QVarLengthArray<DFBPoint, 16> points(maxCount); |
|
1128 |
||
1129 |
int i = 0; |
|
1130 |
while (y <= destinationRect.bottom()) { |
|
1131 |
Q_ASSERT(i < maxCount); |
|
1132 |
qreal x = startX; |
|
1133 |
while (x <= destinationRect.right()) { |
|
1134 |
points[i].x = qRound(x); |
|
1135 |
points[i].y = qRound(y); |
|
1136 |
sourceRects[i].x = 0; |
|
1137 |
sourceRects[i].y = 0; |
|
1138 |
sourceRects[i].w = int(pixmapSize.width()); |
|
1139 |
sourceRects[i].h = int(pixmapSize.height()); |
|
1140 |
x += pixmapSize.width(); |
|
1141 |
++i; |
|
1142 |
} |
|
1143 |
y += pixmapSize.height(); |
|
1144 |
} |
|
1145 |
surface->BatchBlit(surface, sourceSurface, sourceRects.constData(), points.constData(), i); |
|
1146 |
} |
|
1147 |
||
1148 |
if (currentClip.isEmpty()) { |
|
1149 |
surface->SetClip(surface, 0); |
|
1150 |
} else { |
|
1151 |
const DFBRegion clip = { |
|
1152 |
currentClip.x(), |
|
1153 |
currentClip.y(), |
|
1154 |
currentClip.right(), |
|
1155 |
currentClip.bottom() |
|
1156 |
}; |
|
1157 |
surface->SetClip(surface, &clip); |
|
1158 |
} |
|
1159 |
} |
|
1160 |
||
1161 |
void QDirectFBPaintEnginePrivate::updateClip() |
|
1162 |
{ |
|
1163 |
Q_ASSERT(surface); |
|
1164 |
currentClip = QRect(); |
|
1165 |
const QClipData *clipData = clip(); |
|
1166 |
if (!clipData || !clipData->enabled) { |
|
1167 |
surface->SetClip(surface, NULL); |
|
1168 |
clipType = NoClip; |
|
1169 |
} else if (clipData->hasRectClip) { |
|
1170 |
const DFBRegion r = { |
|
1171 |
clipData->clipRect.x(), |
|
1172 |
clipData->clipRect.y(), |
|
1173 |
clipData->clipRect.right(), |
|
1174 |
clipData->clipRect.bottom() |
|
1175 |
}; |
|
1176 |
surface->SetClip(surface, &r); |
|
1177 |
currentClip = clipData->clipRect.normalized(); |
|
1178 |
// ### is this guaranteed to always be normalized? |
|
1179 |
clipType = RectClip; |
|
1180 |
} else if (clipData->hasRegionClip) { |
|
1181 |
clipType = RegionClip; |
|
1182 |
} else { |
|
1183 |
clipType = ComplexClip; |
|
1184 |
} |
|
1185 |
} |
|
1186 |
||
1187 |
void QDirectFBPaintEnginePrivate::systemStateChanged() |
|
1188 |
{ |
|
1189 |
QRasterPaintEnginePrivate::systemStateChanged(); |
|
1190 |
updateClip(); |
|
1191 |
} |
|
1192 |
||
1193 |
IDirectFBSurface *SurfaceCache::getSurface(const uint *buf, int size) |
|
1194 |
{ |
|
1195 |
if (buffer == buf && bufsize == size) |
|
1196 |
return surface; |
|
1197 |
||
1198 |
clear(); |
|
1199 |
||
1200 |
const DFBSurfaceDescription description = QDirectFBScreen::getSurfaceDescription(buf, size); |
|
1201 |
surface = QDirectFBScreen::instance()->createDFBSurface(description, QDirectFBScreen::TrackSurface, 0); |
|
1202 |
if (!surface) |
|
1203 |
qWarning("QDirectFBPaintEngine: SurfaceCache: Unable to create surface"); |
|
1204 |
||
1205 |
buffer = const_cast<uint*>(buf); |
|
1206 |
bufsize = size; |
|
1207 |
||
1208 |
return surface; |
|
1209 |
} |
|
1210 |
||
1211 |
void SurfaceCache::clear() |
|
1212 |
{ |
|
1213 |
if (surface && QDirectFBScreen::instance()) |
|
1214 |
QDirectFBScreen::instance()->releaseDFBSurface(surface); |
|
1215 |
surface = 0; |
|
1216 |
buffer = 0; |
|
1217 |
bufsize = 0; |
|
1218 |
} |
|
1219 |
||
1220 |
||
1221 |
static inline QRect mapRect(const QTransform &transform, const QRect &rect) { return transform.mapRect(rect); } |
|
1222 |
static inline QRect mapRect(const QTransform &transform, const QRectF &rect) { return transform.mapRect(rect).toRect(); } |
|
1223 |
static inline QLine map(const QTransform &transform, const QLine &line) { return transform.map(line); } |
|
1224 |
static inline QLine map(const QTransform &transform, const QLineF &line) { return transform.map(line).toLine(); } |
|
1225 |
template <class T> |
|
1226 |
static inline void drawLines(const T *lines, int n, const QTransform &transform, IDirectFBSurface *surface) |
|
1227 |
{ |
|
1228 |
if (n == 1) { |
|
1229 |
const QLine l = map(transform, lines[0]); |
|
1230 |
surface->DrawLine(surface, l.x1(), l.y1(), l.x2(), l.y2()); |
|
1231 |
} else { |
|
1232 |
QVarLengthArray<DFBRegion, 32> lineArray(n); |
|
1233 |
for (int i=0; i<n; ++i) { |
|
1234 |
const QLine l = map(transform, lines[i]); |
|
1235 |
lineArray[i].x1 = l.x1(); |
|
1236 |
lineArray[i].y1 = l.y1(); |
|
1237 |
lineArray[i].x2 = l.x2(); |
|
1238 |
lineArray[i].y2 = l.y2(); |
|
1239 |
} |
|
1240 |
surface->DrawLines(surface, lineArray.constData(), n); |
|
1241 |
} |
|
1242 |
} |
|
1243 |
||
1244 |
template <class T> |
|
1245 |
static inline void fillRects(const T *rects, int n, const QTransform &transform, IDirectFBSurface *surface) |
|
1246 |
{ |
|
1247 |
if (n == 1) { |
|
1248 |
const QRect r = mapRect(transform, rects[0]); |
|
1249 |
surface->FillRectangle(surface, r.x(), r.y(), r.width(), r.height()); |
|
1250 |
} else { |
|
1251 |
QVarLengthArray<DFBRectangle, 32> rectArray(n); |
|
1252 |
for (int i=0; i<n; ++i) { |
|
1253 |
const QRect r = mapRect(transform, rects[i]); |
|
1254 |
rectArray[i].x = r.x(); |
|
1255 |
rectArray[i].y = r.y(); |
|
1256 |
rectArray[i].w = r.width(); |
|
1257 |
rectArray[i].h = r.height(); |
|
1258 |
} |
|
1259 |
surface->FillRectangles(surface, rectArray.constData(), n); |
|
1260 |
} |
|
1261 |
} |
|
1262 |
||
1263 |
template <class T> |
|
1264 |
static inline void drawRects(const T *rects, int n, const QTransform &transform, IDirectFBSurface *surface) |
|
1265 |
{ |
|
1266 |
for (int i=0; i<n; ++i) { |
|
1267 |
const QRect r = mapRect(transform, rects[i]); |
|
1268 |
surface->DrawRectangle(surface, r.x(), r.y(), r.width(), r.height()); |
|
1269 |
} |
|
1270 |
} |
|
1271 |
||
1272 |
#ifdef QT_DIRECTFB_WARN_ON_RASTERFALLBACKS |
|
1273 |
template <typename T> inline const T *ptr(const T &t) { return &t; } |
|
1274 |
template <> inline const bool* ptr<bool>(const bool &) { return 0; } |
|
1275 |
template <typename device, typename T1, typename T2, typename T3> |
|
1276 |
static void rasterFallbackWarn(const char *msg, const char *func, const device *dev, |
|
1277 |
uint transformationType, bool simplePen, |
|
1278 |
uint clipType, uint compositionModeStatus, |
|
1279 |
const char *nameOne, const T1 &one, |
|
1280 |
const char *nameTwo, const T2 &two, |
|
1281 |
const char *nameThree, const T3 &three) |
|
1282 |
{ |
|
1283 |
QString out; |
|
1284 |
QDebug dbg(&out); |
|
1285 |
dbg << msg << (QByteArray(func) + "()") << "painting on"; |
|
1286 |
if (dev->devType() == QInternal::Widget) { |
|
1287 |
dbg << static_cast<const QWidget*>(dev); |
|
1288 |
} else { |
|
1289 |
dbg << dev << "of type" << dev->devType(); |
|
1290 |
} |
|
1291 |
||
1292 |
dbg << QString::fromLatin1("transformationType 0x%1").arg(transformationType, 3, 16, QLatin1Char('0')) |
|
1293 |
<< "simplePen" << simplePen |
|
1294 |
<< "clipType" << clipType |
|
1295 |
<< "compositionModeStatus" << compositionModeStatus; |
|
1296 |
||
1297 |
const T1 *t1 = ptr(one); |
|
1298 |
const T2 *t2 = ptr(two); |
|
1299 |
const T3 *t3 = ptr(three); |
|
1300 |
||
1301 |
if (t1) { |
|
1302 |
dbg << nameOne << *t1; |
|
1303 |
if (t2) { |
|
1304 |
dbg << nameTwo << *t2; |
|
1305 |
if (t3) { |
|
1306 |
dbg << nameThree << *t3; |
|
1307 |
} |
|
1308 |
} |
|
1309 |
} |
|
1310 |
qWarning("%s", qPrintable(out)); |
|
1311 |
} |
|
1312 |
||
1313 |
#endif // QT_DIRECTFB_WARN_ON_RASTERFALLBACKS |
|
1314 |
||
1315 |
QT_END_NAMESPACE |
|
1316 |
||
1317 |
#endif // QT_NO_QWS_DIRECTFB |