author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 16 Apr 2010 15:50:13 +0300 | |
changeset 18 | 2f34d5167611 |
parent 0 | 1918ee327afb |
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:
0
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 "qdirectfbpixmap.h" |
|
43 |
||
44 |
#ifndef QT_NO_QWS_DIRECTFB |
|
45 |
||
46 |
#include "qdirectfbscreen.h" |
|
47 |
#include "qdirectfbpaintengine.h" |
|
48 |
||
49 |
#include <QtGui/qbitmap.h> |
|
50 |
#include <QtCore/qfile.h> |
|
51 |
#include <directfb.h> |
|
52 |
||
53 |
||
54 |
QT_BEGIN_NAMESPACE |
|
55 |
||
56 |
static int global_ser_no = 0; |
|
57 |
||
58 |
QDirectFBPixmapData::QDirectFBPixmapData(QDirectFBScreen *screen, PixelType pixelType) |
|
59 |
: QPixmapData(pixelType, DirectFBClass), QDirectFBPaintDevice(screen), |
|
60 |
alpha(false) |
|
61 |
{ |
|
62 |
setSerialNumber(0); |
|
63 |
} |
|
64 |
||
65 |
QDirectFBPixmapData::~QDirectFBPixmapData() |
|
66 |
{ |
|
67 |
} |
|
68 |
||
69 |
void QDirectFBPixmapData::resize(int width, int height) |
|
70 |
{ |
|
71 |
if (width <= 0 || height <= 0) { |
|
72 |
invalidate(); |
|
73 |
return; |
|
74 |
} |
|
75 |
||
76 |
imageFormat = screen->pixelFormat(); |
|
77 |
dfbSurface = screen->createDFBSurface(QSize(width, height), |
|
78 |
imageFormat, |
|
79 |
QDirectFBScreen::TrackSurface); |
|
80 |
d = QDirectFBScreen::depth(imageFormat); |
|
81 |
alpha = false; |
|
82 |
if (!dfbSurface) { |
|
83 |
invalidate(); |
|
84 |
qWarning("QDirectFBPixmapData::resize(): Unable to allocate surface"); |
|
85 |
return; |
|
86 |
} |
|
87 |
||
88 |
w = width; |
|
89 |
h = height; |
|
90 |
is_null = (w <= 0 || h <= 0); |
|
91 |
setSerialNumber(++global_ser_no); |
|
92 |
} |
|
93 |
||
94 |
// mostly duplicated from qimage.cpp (QImageData::checkForAlphaPixels) |
|
95 |
static bool checkForAlphaPixels(const QImage &img) |
|
96 |
{ |
|
97 |
const uchar *bits = img.bits(); |
|
98 |
const int bytes_per_line = img.bytesPerLine(); |
|
99 |
const uchar *end_bits = bits + bytes_per_line; |
|
100 |
const int width = img.width(); |
|
101 |
const int height = img.height(); |
|
102 |
switch (img.format()) { |
|
103 |
case QImage::Format_Indexed8: |
|
104 |
return img.hasAlphaChannel(); |
|
105 |
case QImage::Format_ARGB32: |
|
106 |
case QImage::Format_ARGB32_Premultiplied: |
|
107 |
for (int y=0; y<height; ++y) { |
|
108 |
for (int x=0; x<width; ++x) { |
|
109 |
if ((((uint *)bits)[x] & 0xff000000) != 0xff000000) { |
|
110 |
return true; |
|
111 |
} |
|
112 |
} |
|
113 |
bits += bytes_per_line; |
|
114 |
} |
|
115 |
break; |
|
116 |
||
117 |
case QImage::Format_ARGB8555_Premultiplied: |
|
118 |
case QImage::Format_ARGB8565_Premultiplied: |
|
119 |
for (int y=0; y<height; ++y) { |
|
120 |
while (bits < end_bits) { |
|
121 |
if (bits[0] != 0) { |
|
122 |
return true; |
|
123 |
} |
|
124 |
bits += 3; |
|
125 |
} |
|
126 |
bits = end_bits; |
|
127 |
end_bits += bytes_per_line; |
|
128 |
} |
|
129 |
break; |
|
130 |
||
131 |
case QImage::Format_ARGB6666_Premultiplied: |
|
132 |
for (int y=0; y<height; ++y) { |
|
133 |
while (bits < end_bits) { |
|
134 |
if ((bits[0] & 0xfc) != 0) { |
|
135 |
return true; |
|
136 |
} |
|
137 |
bits += 3; |
|
138 |
} |
|
139 |
bits = end_bits; |
|
140 |
end_bits += bytes_per_line; |
|
141 |
} |
|
142 |
break; |
|
143 |
||
144 |
case QImage::Format_ARGB4444_Premultiplied: |
|
145 |
for (int y=0; y<height; ++y) { |
|
146 |
while (bits < end_bits) { |
|
147 |
if ((bits[0] & 0xf0) != 0) { |
|
148 |
return true; |
|
149 |
} |
|
150 |
bits += 2; |
|
151 |
} |
|
152 |
bits = end_bits; |
|
153 |
end_bits += bytes_per_line; |
|
154 |
} |
|
155 |
break; |
|
156 |
||
157 |
default: |
|
158 |
break; |
|
159 |
} |
|
160 |
||
161 |
return false; |
|
162 |
} |
|
163 |
||
164 |
bool QDirectFBPixmapData::hasAlphaChannel(const QImage &img) |
|
165 |
{ |
|
166 |
#ifndef QT_NO_DIRECTFB_OPAQUE_DETECTION |
|
167 |
return checkForAlphaPixels(img); |
|
168 |
#else |
|
169 |
return img.hasAlphaChannel(); |
|
170 |
#endif |
|
171 |
} |
|
172 |
||
173 |
#ifdef QT_DIRECTFB_IMAGEPROVIDER |
|
174 |
bool QDirectFBPixmapData::fromFile(const QString &filename, const char *format, |
|
175 |
Qt::ImageConversionFlags flags) |
|
176 |
{ |
|
177 |
if (flags == Qt::AutoColor) { |
|
178 |
if (filename.startsWith(QLatin1Char(':'))) { // resource |
|
179 |
QFile file(filename); |
|
180 |
if (!file.open(QIODevice::ReadOnly)) |
|
181 |
return false; |
|
182 |
const QByteArray data = file.readAll(); |
|
183 |
file.close(); |
|
184 |
return fromData(reinterpret_cast<const uchar*>(data.constData()), data.size(), format, flags); |
|
185 |
} else { |
|
186 |
DFBDataBufferDescription description; |
|
187 |
description.flags = DBDESC_FILE; |
|
188 |
const QByteArray fileNameData = filename.toLocal8Bit(); |
|
189 |
description.file = fileNameData.constData(); |
|
190 |
if (fromDataBufferDescription(description)) { |
|
191 |
return true; |
|
192 |
} |
|
193 |
// fall back to Qt |
|
194 |
} |
|
195 |
} |
|
196 |
return QPixmapData::fromFile(filename, format, flags); |
|
197 |
} |
|
198 |
||
199 |
bool QDirectFBPixmapData::fromData(const uchar *buffer, uint len, const char *format, |
|
200 |
Qt::ImageConversionFlags flags) |
|
201 |
{ |
|
202 |
if (flags == Qt::AutoColor) { |
|
203 |
DFBDataBufferDescription description; |
|
204 |
description.flags = DBDESC_MEMORY; |
|
205 |
description.memory.data = buffer; |
|
206 |
description.memory.length = len; |
|
207 |
if (fromDataBufferDescription(description)) |
|
208 |
return true; |
|
209 |
// fall back to Qt |
|
210 |
} |
|
211 |
return QPixmapData::fromData(buffer, len, format, flags); |
|
212 |
} |
|
213 |
||
214 |
template <typename T> struct QDirectFBInterfaceCleanupHandler |
|
215 |
{ |
|
216 |
static void cleanup(T *t) { if (t) t->Release(t); } |
|
217 |
}; |
|
218 |
||
219 |
template <typename T> |
|
220 |
class QDirectFBPointer : public QScopedPointer<T, QDirectFBInterfaceCleanupHandler<T> > |
|
221 |
{ |
|
222 |
public: |
|
223 |
QDirectFBPointer(T *t = 0) |
|
224 |
: QScopedPointer<T, QDirectFBInterfaceCleanupHandler<T> >(t) |
|
225 |
{} |
|
226 |
}; |
|
227 |
||
228 |
bool QDirectFBPixmapData::fromDataBufferDescription(const DFBDataBufferDescription &dataBufferDescription) |
|
229 |
{ |
|
230 |
IDirectFB *dfb = screen->dfb(); |
|
231 |
Q_ASSERT(dfb); |
|
232 |
DFBResult result = DFB_OK; |
|
233 |
IDirectFBDataBuffer *dataBufferPtr; |
|
234 |
if ((result = dfb->CreateDataBuffer(dfb, &dataBufferDescription, &dataBufferPtr)) != DFB_OK) { |
|
235 |
DirectFBError("QDirectFBPixmapData::fromDataBufferDescription()", result); |
|
236 |
return false; |
|
237 |
} |
|
238 |
QDirectFBPointer<IDirectFBDataBuffer> dataBuffer(dataBufferPtr); |
|
239 |
||
240 |
IDirectFBImageProvider *providerPtr; |
|
241 |
if ((result = dataBuffer->CreateImageProvider(dataBuffer.data(), &providerPtr)) != DFB_OK) { |
|
242 |
DirectFBError("QDirectFBPixmapData::fromDataBufferDescription(): Can't create image provider", result); |
|
243 |
return false; |
|
244 |
} |
|
245 |
QDirectFBPointer<IDirectFBImageProvider> provider(providerPtr); |
|
246 |
||
247 |
DFBSurfaceDescription surfaceDescription; |
|
248 |
if ((result = provider->GetSurfaceDescription(provider.data(), &surfaceDescription)) != DFB_OK) { |
|
249 |
DirectFBError("QDirectFBPixmapData::fromDataBufferDescription(): Can't get surface description", result); |
|
250 |
return false; |
|
251 |
} |
|
252 |
||
253 |
DFBImageDescription imageDescription; |
|
254 |
result = provider->GetImageDescription(provider.data(), &imageDescription); |
|
255 |
if (result != DFB_OK) { |
|
256 |
DirectFBError("QDirectFBPixmapData::fromSurfaceDescription(): Can't get image description", result); |
|
257 |
return false; |
|
258 |
} |
|
259 |
||
260 |
alpha = imageDescription.caps & (DICAPS_ALPHACHANNEL|DICAPS_COLORKEY); |
|
261 |
imageFormat = alpha ? screen->alphaPixmapFormat() : screen->pixelFormat(); |
|
262 |
||
263 |
dfbSurface = screen->createDFBSurface(QSize(surfaceDescription.width, surfaceDescription.height), |
|
264 |
imageFormat, QDirectFBScreen::TrackSurface); |
|
265 |
||
266 |
result = provider->RenderTo(provider.data(), dfbSurface, 0); |
|
267 |
if (result != DFB_OK) { |
|
268 |
DirectFBError("QDirectFBPixmapData::fromSurfaceDescription(): Can't render to surface", result); |
|
269 |
return false; |
|
270 |
} |
|
271 |
||
272 |
w = surfaceDescription.width; |
|
273 |
h = surfaceDescription.height; |
|
274 |
is_null = (w <= 0 || h <= 0); |
|
275 |
d = QDirectFBScreen::depth(imageFormat); |
|
276 |
setSerialNumber(++global_ser_no); |
|
277 |
||
278 |
#if defined QT_DIRECTFB_IMAGEPROVIDER_KEEPALIVE |
|
279 |
screen->setDirectFBImageProvider(providerPtr); |
|
280 |
provider.take(); |
|
281 |
#endif |
|
282 |
||
283 |
return true; |
|
284 |
} |
|
285 |
||
286 |
#endif |
|
287 |
||
288 |
void QDirectFBPixmapData::fromImage(const QImage &img, |
|
289 |
Qt::ImageConversionFlags flags) |
|
290 |
{ |
|
291 |
if (img.depth() == 1 || img.format() == QImage::Format_RGB32) { |
|
292 |
fromImage(img.convertToFormat(screen->alphaPixmapFormat()), flags); |
|
293 |
return; |
|
294 |
} |
|
295 |
||
296 |
if (img.hasAlphaChannel() |
|
297 |
#ifndef QT_NO_DIRECTFB_OPAQUE_DETECTION |
|
298 |
&& (flags & Qt::NoOpaqueDetection || QDirectFBPixmapData::hasAlphaChannel(img)) |
|
299 |
#endif |
|
300 |
) { |
|
301 |
alpha = true; |
|
302 |
imageFormat = screen->alphaPixmapFormat(); |
|
303 |
} else { |
|
304 |
alpha = false; |
|
305 |
imageFormat = screen->pixelFormat(); |
|
306 |
} |
|
307 |
QImage image; |
|
308 |
if (flags != Qt::AutoColor) { |
|
309 |
image = img.convertToFormat(imageFormat, flags); |
|
310 |
flags = Qt::AutoColor; |
|
311 |
} else if (img.format() == QImage::Format_RGB32) { |
|
312 |
image = img.convertToFormat(imageFormat, flags); |
|
313 |
} else { |
|
314 |
image = img; |
|
315 |
} |
|
316 |
||
317 |
IDirectFBSurface *imageSurface = screen->createDFBSurface(image, image.format(), QDirectFBScreen::DontTrackSurface); |
|
318 |
if (!imageSurface) { |
|
319 |
qWarning("QDirectFBPixmapData::fromImage()"); |
|
320 |
invalidate(); |
|
321 |
return; |
|
322 |
} |
|
323 |
||
324 |
dfbSurface = screen->createDFBSurface(image.size(), imageFormat, QDirectFBScreen::TrackSurface); |
|
325 |
if (!dfbSurface) { |
|
326 |
qWarning("QDirectFBPixmapData::fromImage()"); |
|
327 |
invalidate(); |
|
328 |
return; |
|
329 |
} |
|
330 |
||
331 |
if (image.hasAlphaChannel()) { |
|
332 |
dfbSurface->Clear(dfbSurface, 0, 0, 0, 0); |
|
333 |
dfbSurface->SetBlittingFlags(dfbSurface, DSBLIT_BLEND_ALPHACHANNEL); |
|
334 |
} else { |
|
335 |
dfbSurface->SetBlittingFlags(dfbSurface, DSBLIT_NOFX); |
|
336 |
} |
|
337 |
||
338 |
dfbSurface->Blit(dfbSurface, imageSurface, 0, 0, 0); |
|
339 |
imageSurface->Release(imageSurface); |
|
340 |
||
341 |
w = image.width(); |
|
342 |
h = image.height(); |
|
343 |
is_null = (w <= 0 || h <= 0); |
|
344 |
d = QDirectFBScreen::depth(imageFormat); |
|
345 |
setSerialNumber(++global_ser_no); |
|
346 |
#ifdef QT_NO_DIRECTFB_OPAQUE_DETECTION |
|
347 |
Q_UNUSED(flags); |
|
348 |
#endif |
|
349 |
} |
|
350 |
||
351 |
void QDirectFBPixmapData::copy(const QPixmapData *data, const QRect &rect) |
|
352 |
{ |
|
353 |
if (data->classId() != DirectFBClass) { |
|
354 |
QPixmapData::copy(data, rect); |
|
355 |
return; |
|
356 |
} |
|
357 |
||
358 |
const QDirectFBPixmapData *otherData = static_cast<const QDirectFBPixmapData*>(data); |
|
359 |
#ifdef QT_NO_DIRECTFB_SUBSURFACE |
|
360 |
if (otherData->lockFlags()) { |
|
361 |
const_cast<QDirectFBPixmapData*>(otherData)->unlockSurface(); |
|
362 |
} |
|
363 |
#endif |
|
364 |
IDirectFBSurface *src = otherData->directFBSurface(); |
|
365 |
alpha = data->hasAlphaChannel(); |
|
366 |
imageFormat = (alpha |
|
367 |
? QDirectFBScreen::instance()->alphaPixmapFormat() |
|
368 |
: QDirectFBScreen::instance()->pixelFormat()); |
|
369 |
||
370 |
||
371 |
dfbSurface = screen->createDFBSurface(rect.size(), imageFormat, |
|
372 |
QDirectFBScreen::TrackSurface); |
|
373 |
if (!dfbSurface) { |
|
374 |
qWarning("QDirectFBPixmapData::copy()"); |
|
375 |
invalidate(); |
|
376 |
return; |
|
377 |
} |
|
378 |
||
379 |
if (alpha) { |
|
380 |
dfbSurface->Clear(dfbSurface, 0, 0, 0, 0); |
|
381 |
dfbSurface->SetBlittingFlags(dfbSurface, DSBLIT_BLEND_ALPHACHANNEL); |
|
382 |
} else { |
|
383 |
dfbSurface->SetBlittingFlags(dfbSurface, DSBLIT_NOFX); |
|
384 |
} |
|
385 |
const DFBRectangle blitRect = { rect.x(), rect.y(), |
|
386 |
rect.width(), rect.height() }; |
|
387 |
w = rect.width(); |
|
388 |
h = rect.height(); |
|
389 |
d = otherData->d; |
|
390 |
is_null = (w <= 0 || h <= 0); |
|
391 |
unlockSurface(); |
|
392 |
DFBResult result = dfbSurface->Blit(dfbSurface, src, &blitRect, 0, 0); |
|
393 |
#if (Q_DIRECTFB_VERSION >= 0x010000) |
|
394 |
dfbSurface->ReleaseSource(dfbSurface); |
|
395 |
#endif |
|
396 |
if (result != DFB_OK) { |
|
397 |
DirectFBError("QDirectFBPixmapData::copy()", result); |
|
398 |
invalidate(); |
|
399 |
return; |
|
400 |
} |
|
401 |
||
402 |
setSerialNumber(++global_ser_no); |
|
403 |
} |
|
404 |
||
405 |
static inline bool isOpaqueFormat(QImage::Format format) |
|
406 |
{ |
|
407 |
switch (format) { |
|
408 |
case QImage::Format_RGB32: |
|
409 |
case QImage::Format_RGB16: |
|
410 |
case QImage::Format_RGB666: |
|
411 |
case QImage::Format_RGB555: |
|
412 |
case QImage::Format_RGB888: |
|
413 |
case QImage::Format_RGB444: |
|
414 |
return true; |
|
415 |
default: |
|
416 |
break; |
|
417 |
} |
|
418 |
return false; |
|
419 |
} |
|
420 |
||
421 |
void QDirectFBPixmapData::fill(const QColor &color) |
|
422 |
{ |
|
423 |
if (!serialNumber()) |
|
424 |
return; |
|
425 |
||
426 |
Q_ASSERT(dfbSurface); |
|
427 |
||
428 |
alpha = (color.alpha() < 255); |
|
429 |
||
430 |
if (alpha && isOpaqueFormat(imageFormat)) { |
|
431 |
QSize size; |
|
432 |
dfbSurface->GetSize(dfbSurface, &size.rwidth(), &size.rheight()); |
|
433 |
screen->releaseDFBSurface(dfbSurface); |
|
434 |
imageFormat = screen->alphaPixmapFormat(); |
|
435 |
d = QDirectFBScreen::depth(imageFormat); |
|
436 |
dfbSurface = screen->createDFBSurface(size, screen->alphaPixmapFormat(), QDirectFBScreen::TrackSurface); |
|
437 |
setSerialNumber(++global_ser_no); |
|
438 |
if (!dfbSurface) { |
|
439 |
qWarning("QDirectFBPixmapData::fill()"); |
|
440 |
invalidate(); |
|
441 |
return; |
|
442 |
} |
|
443 |
} |
|
444 |
||
445 |
dfbSurface->Clear(dfbSurface, color.red(), color.green(), color.blue(), color.alpha()); |
|
446 |
} |
|
447 |
||
448 |
QPixmap QDirectFBPixmapData::transformed(const QTransform &transform, |
|
449 |
Qt::TransformationMode mode) const |
|
450 |
{ |
|
451 |
QDirectFBPixmapData *that = const_cast<QDirectFBPixmapData*>(this); |
|
452 |
#ifdef QT_NO_DIRECTFB_SUBSURFACE |
|
453 |
if (lockFlags()) |
|
454 |
that->unlockSurface(); |
|
455 |
#endif |
|
456 |
||
457 |
if (!dfbSurface || transform.type() != QTransform::TxScale |
|
458 |
|| mode != Qt::FastTransformation) |
|
459 |
{ |
|
460 |
const QImage *image = that->buffer(); |
|
461 |
Q_ASSERT(image); |
|
462 |
const QImage transformed = image->transformed(transform, mode); |
|
463 |
QDirectFBPixmapData *data = new QDirectFBPixmapData(screen, QPixmapData::PixmapType); |
|
464 |
data->fromImage(transformed, Qt::AutoColor); |
|
465 |
return QPixmap(data); |
|
466 |
} |
|
467 |
||
468 |
const QSize size = transform.mapRect(QRect(0, 0, w, h)).size(); |
|
469 |
if (size.isEmpty()) |
|
470 |
return QPixmap(); |
|
471 |
||
472 |
QDirectFBPixmapData *data = new QDirectFBPixmapData(screen, QPixmapData::PixmapType); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
473 |
data->setSerialNumber(++global_ser_no); |
0 | 474 |
DFBSurfaceBlittingFlags flags = DSBLIT_NOFX; |
475 |
data->alpha = alpha; |
|
476 |
if (alpha) { |
|
477 |
flags = DSBLIT_BLEND_ALPHACHANNEL; |
|
478 |
} |
|
479 |
data->dfbSurface = screen->createDFBSurface(size, |
|
480 |
imageFormat, |
|
481 |
QDirectFBScreen::TrackSurface); |
|
482 |
if (flags & DSBLIT_BLEND_ALPHACHANNEL) { |
|
483 |
data->dfbSurface->Clear(data->dfbSurface, 0, 0, 0, 0); |
|
484 |
} |
|
485 |
data->dfbSurface->SetBlittingFlags(data->dfbSurface, flags); |
|
486 |
||
487 |
const DFBRectangle destRect = { 0, 0, size.width(), size.height() }; |
|
488 |
data->dfbSurface->StretchBlit(data->dfbSurface, dfbSurface, 0, &destRect); |
|
489 |
data->w = size.width(); |
|
490 |
data->h = size.height(); |
|
491 |
data->is_null = (data->w <= 0 || data->h <= 0); |
|
492 |
||
493 |
#if (Q_DIRECTFB_VERSION >= 0x010000) |
|
494 |
data->dfbSurface->ReleaseSource(data->dfbSurface); |
|
495 |
#endif |
|
496 |
return QPixmap(data); |
|
497 |
} |
|
498 |
||
499 |
QImage QDirectFBPixmapData::toImage() const |
|
500 |
{ |
|
501 |
if (!dfbSurface) |
|
502 |
return QImage(); |
|
503 |
||
504 |
#if 0 |
|
505 |
// In later versions of DirectFB one can set a flag to tell |
|
506 |
// DirectFB not to move the surface to videomemory. When that |
|
507 |
// happens we can use this (hopefully faster) codepath |
|
508 |
#ifndef QT_NO_DIRECTFB_PREALLOCATED |
|
509 |
QImage ret(w, h, QDirectFBScreen::getImageFormat(dfbSurface)); |
|
510 |
if (IDirectFBSurface *imgSurface = screen->createDFBSurface(ret, QDirectFBScreen::DontTrackSurface)) { |
|
511 |
if (hasAlphaChannel()) { |
|
512 |
imgSurface->SetBlittingFlags(imgSurface, DSBLIT_BLEND_ALPHACHANNEL); |
|
513 |
imgSurface->Clear(imgSurface, 0, 0, 0, 0); |
|
514 |
} else { |
|
515 |
imgSurface->SetBlittingFlags(imgSurface, DSBLIT_NOFX); |
|
516 |
} |
|
517 |
imgSurface->Blit(imgSurface, dfbSurface, 0, 0, 0); |
|
518 |
#if (Q_DIRECTFB_VERSION >= 0x010000) |
|
519 |
imgSurface->ReleaseSource(imgSurface); |
|
520 |
#endif |
|
521 |
imgSurface->Release(imgSurface); |
|
522 |
return ret; |
|
523 |
} |
|
524 |
#endif |
|
525 |
#endif |
|
526 |
||
527 |
QDirectFBPixmapData *that = const_cast<QDirectFBPixmapData*>(this); |
|
528 |
const QImage *img = that->buffer(); |
|
529 |
return img->copy(); |
|
530 |
} |
|
531 |
||
532 |
/* This is QPixmapData::paintEngine(), not QPaintDevice::paintEngine() */ |
|
533 |
||
534 |
QPaintEngine *QDirectFBPixmapData::paintEngine() const |
|
535 |
{ |
|
536 |
if (!engine) { |
|
537 |
// QDirectFBPixmapData is also a QCustomRasterPaintDevice, so pass |
|
538 |
// that to the paint engine: |
|
539 |
QDirectFBPixmapData *that = const_cast<QDirectFBPixmapData*>(this); |
|
540 |
that->engine = new QDirectFBPaintEngine(that); |
|
541 |
} |
|
542 |
return engine; |
|
543 |
} |
|
544 |
||
545 |
QImage *QDirectFBPixmapData::buffer() |
|
546 |
{ |
|
547 |
if (!lockFlgs) { |
|
548 |
lockSurface(DSLF_READ|DSLF_WRITE); |
|
549 |
} |
|
550 |
Q_ASSERT(lockFlgs); |
|
551 |
Q_ASSERT(!lockedImage.isNull()); |
|
552 |
return &lockedImage; |
|
553 |
} |
|
554 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
555 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
556 |
bool QDirectFBPixmapData::scroll(int dx, int dy, const QRect &rect) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
557 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
558 |
if (!dfbSurface) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
559 |
return false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
560 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
561 |
unlockSurface(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
562 |
DFBResult result = dfbSurface->SetBlittingFlags(dfbSurface, DSBLIT_NOFX); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
563 |
if (result != DFB_OK) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
564 |
DirectFBError("QDirectFBPixmapData::scroll", result); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
565 |
return false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
566 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
567 |
result = dfbSurface->SetPorterDuff(dfbSurface, DSPD_NONE); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
568 |
if (result != DFB_OK) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
569 |
DirectFBError("QDirectFBPixmapData::scroll", result); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
570 |
return false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
571 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
572 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
573 |
const DFBRectangle source = { rect.x(), rect.y(), rect.width(), rect.height() }; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
574 |
result = dfbSurface->Blit(dfbSurface, dfbSurface, &source, source.x + dx, source.y + dy); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
575 |
if (result != DFB_OK) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
576 |
DirectFBError("QDirectFBPixmapData::scroll", result); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
577 |
return false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
578 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
579 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
580 |
return true; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
581 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
582 |
|
0 | 583 |
void QDirectFBPixmapData::invalidate() |
584 |
{ |
|
585 |
if (dfbSurface) { |
|
586 |
screen->releaseDFBSurface(dfbSurface); |
|
587 |
dfbSurface = 0; |
|
588 |
} |
|
589 |
setSerialNumber(0); |
|
590 |
alpha = false; |
|
591 |
d = w = h = 0; |
|
592 |
is_null = true; |
|
593 |
imageFormat = QImage::Format_Invalid; |
|
594 |
} |
|
595 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
596 |
#ifndef QT_DIRECTFB_PLUGIN |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
597 |
Q_GUI_EXPORT IDirectFBSurface *qt_directfb_surface_for_pixmap(const QPixmap &pixmap) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
598 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
599 |
const QPixmapData *data = pixmap.pixmapData(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
600 |
if (!data || data->classId() != QPixmapData::DirectFBClass) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
601 |
return 0; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
602 |
const QDirectFBPixmapData *dfbData = static_cast<const QDirectFBPixmapData*>(data); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
603 |
return dfbData->directFBSurface(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
604 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
605 |
#endif |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
606 |
|
0 | 607 |
QT_END_NAMESPACE |
608 |
||
609 |
#endif // QT_NO_QWS_DIRECTFB |