author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 08 Apr 2010 14:19:33 +0300 | |
branch | RCL_3 |
changeset 8 | 3f74d0d4af4c |
parent 5 | d3bac044e0f0 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
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 |
{ |
|
8
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
177 |
if (!QFile::exists(filename)) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
178 |
return false; |
0 | 179 |
if (flags == Qt::AutoColor) { |
180 |
if (filename.startsWith(QLatin1Char(':'))) { // resource |
|
181 |
QFile file(filename); |
|
182 |
if (!file.open(QIODevice::ReadOnly)) |
|
183 |
return false; |
|
184 |
const QByteArray data = file.readAll(); |
|
185 |
file.close(); |
|
186 |
return fromData(reinterpret_cast<const uchar*>(data.constData()), data.size(), format, flags); |
|
187 |
} else { |
|
188 |
DFBDataBufferDescription description; |
|
189 |
description.flags = DBDESC_FILE; |
|
190 |
const QByteArray fileNameData = filename.toLocal8Bit(); |
|
191 |
description.file = fileNameData.constData(); |
|
192 |
if (fromDataBufferDescription(description)) { |
|
193 |
return true; |
|
194 |
} |
|
195 |
// fall back to Qt |
|
196 |
} |
|
197 |
} |
|
198 |
return QPixmapData::fromFile(filename, format, flags); |
|
199 |
} |
|
200 |
||
201 |
bool QDirectFBPixmapData::fromData(const uchar *buffer, uint len, const char *format, |
|
202 |
Qt::ImageConversionFlags flags) |
|
203 |
{ |
|
204 |
if (flags == Qt::AutoColor) { |
|
205 |
DFBDataBufferDescription description; |
|
206 |
description.flags = DBDESC_MEMORY; |
|
207 |
description.memory.data = buffer; |
|
208 |
description.memory.length = len; |
|
209 |
if (fromDataBufferDescription(description)) |
|
210 |
return true; |
|
211 |
// fall back to Qt |
|
212 |
} |
|
213 |
return QPixmapData::fromData(buffer, len, format, flags); |
|
214 |
} |
|
215 |
||
216 |
template <typename T> struct QDirectFBInterfaceCleanupHandler |
|
217 |
{ |
|
218 |
static void cleanup(T *t) { if (t) t->Release(t); } |
|
219 |
}; |
|
220 |
||
221 |
template <typename T> |
|
222 |
class QDirectFBPointer : public QScopedPointer<T, QDirectFBInterfaceCleanupHandler<T> > |
|
223 |
{ |
|
224 |
public: |
|
225 |
QDirectFBPointer(T *t = 0) |
|
226 |
: QScopedPointer<T, QDirectFBInterfaceCleanupHandler<T> >(t) |
|
227 |
{} |
|
228 |
}; |
|
229 |
||
230 |
bool QDirectFBPixmapData::fromDataBufferDescription(const DFBDataBufferDescription &dataBufferDescription) |
|
231 |
{ |
|
232 |
IDirectFB *dfb = screen->dfb(); |
|
233 |
Q_ASSERT(dfb); |
|
234 |
DFBResult result = DFB_OK; |
|
235 |
IDirectFBDataBuffer *dataBufferPtr; |
|
236 |
if ((result = dfb->CreateDataBuffer(dfb, &dataBufferDescription, &dataBufferPtr)) != DFB_OK) { |
|
237 |
DirectFBError("QDirectFBPixmapData::fromDataBufferDescription()", result); |
|
238 |
return false; |
|
239 |
} |
|
240 |
QDirectFBPointer<IDirectFBDataBuffer> dataBuffer(dataBufferPtr); |
|
241 |
||
242 |
IDirectFBImageProvider *providerPtr; |
|
243 |
if ((result = dataBuffer->CreateImageProvider(dataBuffer.data(), &providerPtr)) != DFB_OK) { |
|
244 |
DirectFBError("QDirectFBPixmapData::fromDataBufferDescription(): Can't create image provider", result); |
|
245 |
return false; |
|
246 |
} |
|
247 |
QDirectFBPointer<IDirectFBImageProvider> provider(providerPtr); |
|
248 |
||
249 |
DFBSurfaceDescription surfaceDescription; |
|
250 |
if ((result = provider->GetSurfaceDescription(provider.data(), &surfaceDescription)) != DFB_OK) { |
|
251 |
DirectFBError("QDirectFBPixmapData::fromDataBufferDescription(): Can't get surface description", result); |
|
252 |
return false; |
|
253 |
} |
|
254 |
||
255 |
DFBImageDescription imageDescription; |
|
256 |
result = provider->GetImageDescription(provider.data(), &imageDescription); |
|
257 |
if (result != DFB_OK) { |
|
258 |
DirectFBError("QDirectFBPixmapData::fromSurfaceDescription(): Can't get image description", result); |
|
259 |
return false; |
|
260 |
} |
|
261 |
||
262 |
alpha = imageDescription.caps & (DICAPS_ALPHACHANNEL|DICAPS_COLORKEY); |
|
263 |
imageFormat = alpha ? screen->alphaPixmapFormat() : screen->pixelFormat(); |
|
264 |
||
265 |
dfbSurface = screen->createDFBSurface(QSize(surfaceDescription.width, surfaceDescription.height), |
|
266 |
imageFormat, QDirectFBScreen::TrackSurface); |
|
267 |
||
268 |
result = provider->RenderTo(provider.data(), dfbSurface, 0); |
|
269 |
if (result != DFB_OK) { |
|
270 |
DirectFBError("QDirectFBPixmapData::fromSurfaceDescription(): Can't render to surface", result); |
|
271 |
return false; |
|
272 |
} |
|
273 |
||
274 |
w = surfaceDescription.width; |
|
275 |
h = surfaceDescription.height; |
|
276 |
is_null = (w <= 0 || h <= 0); |
|
277 |
d = QDirectFBScreen::depth(imageFormat); |
|
278 |
setSerialNumber(++global_ser_no); |
|
279 |
||
280 |
#if defined QT_DIRECTFB_IMAGEPROVIDER_KEEPALIVE |
|
281 |
screen->setDirectFBImageProvider(providerPtr); |
|
282 |
provider.take(); |
|
283 |
#endif |
|
284 |
||
285 |
return true; |
|
286 |
} |
|
287 |
||
288 |
#endif |
|
289 |
||
290 |
void QDirectFBPixmapData::fromImage(const QImage &img, |
|
291 |
Qt::ImageConversionFlags flags) |
|
292 |
{ |
|
8
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
293 |
if (img.depth() == 1) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
294 |
alpha = true; |
0 | 295 |
#ifndef QT_NO_DIRECTFB_OPAQUE_DETECTION |
8
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
296 |
} else if (flags & Qt::NoOpaqueDetection || QDirectFBPixmapData::hasAlphaChannel(img)) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
297 |
alpha = true; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
298 |
#else |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
299 |
} else if (img.hasAlphaChannel()) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
300 |
alpha = true; |
0 | 301 |
#endif |
302 |
} |
|
8
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
303 |
imageFormat = alpha ? screen->alphaPixmapFormat() : screen->pixelFormat(); |
0 | 304 |
QImage image; |
8
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
305 |
if ((flags & ~Qt::NoOpaqueDetection) != Qt::AutoColor) { |
0 | 306 |
image = img.convertToFormat(imageFormat, flags); |
307 |
flags = Qt::AutoColor; |
|
8
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
308 |
} else if (img.format() == QImage::Format_RGB32 || img.depth() == 1) { |
0 | 309 |
image = img.convertToFormat(imageFormat, flags); |
310 |
} else { |
|
311 |
image = img; |
|
312 |
} |
|
313 |
||
314 |
IDirectFBSurface *imageSurface = screen->createDFBSurface(image, image.format(), QDirectFBScreen::DontTrackSurface); |
|
315 |
if (!imageSurface) { |
|
316 |
qWarning("QDirectFBPixmapData::fromImage()"); |
|
317 |
invalidate(); |
|
318 |
return; |
|
319 |
} |
|
320 |
||
321 |
dfbSurface = screen->createDFBSurface(image.size(), imageFormat, QDirectFBScreen::TrackSurface); |
|
322 |
if (!dfbSurface) { |
|
323 |
qWarning("QDirectFBPixmapData::fromImage()"); |
|
324 |
invalidate(); |
|
325 |
return; |
|
326 |
} |
|
327 |
||
328 |
if (image.hasAlphaChannel()) { |
|
329 |
dfbSurface->Clear(dfbSurface, 0, 0, 0, 0); |
|
330 |
dfbSurface->SetBlittingFlags(dfbSurface, DSBLIT_BLEND_ALPHACHANNEL); |
|
331 |
} else { |
|
332 |
dfbSurface->SetBlittingFlags(dfbSurface, DSBLIT_NOFX); |
|
333 |
} |
|
334 |
||
335 |
dfbSurface->Blit(dfbSurface, imageSurface, 0, 0, 0); |
|
336 |
imageSurface->Release(imageSurface); |
|
337 |
||
338 |
w = image.width(); |
|
339 |
h = image.height(); |
|
340 |
is_null = (w <= 0 || h <= 0); |
|
341 |
d = QDirectFBScreen::depth(imageFormat); |
|
342 |
setSerialNumber(++global_ser_no); |
|
343 |
#ifdef QT_NO_DIRECTFB_OPAQUE_DETECTION |
|
344 |
Q_UNUSED(flags); |
|
345 |
#endif |
|
346 |
} |
|
347 |
||
348 |
void QDirectFBPixmapData::copy(const QPixmapData *data, const QRect &rect) |
|
349 |
{ |
|
350 |
if (data->classId() != DirectFBClass) { |
|
351 |
QPixmapData::copy(data, rect); |
|
352 |
return; |
|
353 |
} |
|
354 |
||
355 |
const QDirectFBPixmapData *otherData = static_cast<const QDirectFBPixmapData*>(data); |
|
356 |
#ifdef QT_NO_DIRECTFB_SUBSURFACE |
|
357 |
if (otherData->lockFlags()) { |
|
358 |
const_cast<QDirectFBPixmapData*>(otherData)->unlockSurface(); |
|
359 |
} |
|
360 |
#endif |
|
361 |
IDirectFBSurface *src = otherData->directFBSurface(); |
|
362 |
alpha = data->hasAlphaChannel(); |
|
363 |
imageFormat = (alpha |
|
364 |
? QDirectFBScreen::instance()->alphaPixmapFormat() |
|
365 |
: QDirectFBScreen::instance()->pixelFormat()); |
|
366 |
||
367 |
||
368 |
dfbSurface = screen->createDFBSurface(rect.size(), imageFormat, |
|
369 |
QDirectFBScreen::TrackSurface); |
|
370 |
if (!dfbSurface) { |
|
371 |
qWarning("QDirectFBPixmapData::copy()"); |
|
372 |
invalidate(); |
|
373 |
return; |
|
374 |
} |
|
375 |
||
376 |
if (alpha) { |
|
377 |
dfbSurface->Clear(dfbSurface, 0, 0, 0, 0); |
|
378 |
dfbSurface->SetBlittingFlags(dfbSurface, DSBLIT_BLEND_ALPHACHANNEL); |
|
379 |
} else { |
|
380 |
dfbSurface->SetBlittingFlags(dfbSurface, DSBLIT_NOFX); |
|
381 |
} |
|
382 |
const DFBRectangle blitRect = { rect.x(), rect.y(), |
|
383 |
rect.width(), rect.height() }; |
|
384 |
w = rect.width(); |
|
385 |
h = rect.height(); |
|
386 |
d = otherData->d; |
|
387 |
is_null = (w <= 0 || h <= 0); |
|
388 |
unlockSurface(); |
|
389 |
DFBResult result = dfbSurface->Blit(dfbSurface, src, &blitRect, 0, 0); |
|
390 |
#if (Q_DIRECTFB_VERSION >= 0x010000) |
|
391 |
dfbSurface->ReleaseSource(dfbSurface); |
|
392 |
#endif |
|
393 |
if (result != DFB_OK) { |
|
394 |
DirectFBError("QDirectFBPixmapData::copy()", result); |
|
395 |
invalidate(); |
|
396 |
return; |
|
397 |
} |
|
398 |
||
399 |
setSerialNumber(++global_ser_no); |
|
400 |
} |
|
401 |
||
402 |
static inline bool isOpaqueFormat(QImage::Format format) |
|
403 |
{ |
|
404 |
switch (format) { |
|
405 |
case QImage::Format_RGB32: |
|
406 |
case QImage::Format_RGB16: |
|
407 |
case QImage::Format_RGB666: |
|
408 |
case QImage::Format_RGB555: |
|
409 |
case QImage::Format_RGB888: |
|
410 |
case QImage::Format_RGB444: |
|
411 |
return true; |
|
412 |
default: |
|
413 |
break; |
|
414 |
} |
|
415 |
return false; |
|
416 |
} |
|
417 |
||
418 |
void QDirectFBPixmapData::fill(const QColor &color) |
|
419 |
{ |
|
420 |
if (!serialNumber()) |
|
421 |
return; |
|
422 |
||
423 |
Q_ASSERT(dfbSurface); |
|
424 |
||
8
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
425 |
alpha |= (color.alpha() < 255); |
0 | 426 |
|
427 |
if (alpha && isOpaqueFormat(imageFormat)) { |
|
428 |
QSize size; |
|
429 |
dfbSurface->GetSize(dfbSurface, &size.rwidth(), &size.rheight()); |
|
430 |
screen->releaseDFBSurface(dfbSurface); |
|
431 |
imageFormat = screen->alphaPixmapFormat(); |
|
432 |
d = QDirectFBScreen::depth(imageFormat); |
|
433 |
dfbSurface = screen->createDFBSurface(size, screen->alphaPixmapFormat(), QDirectFBScreen::TrackSurface); |
|
434 |
setSerialNumber(++global_ser_no); |
|
435 |
if (!dfbSurface) { |
|
436 |
qWarning("QDirectFBPixmapData::fill()"); |
|
437 |
invalidate(); |
|
438 |
return; |
|
439 |
} |
|
440 |
} |
|
441 |
||
442 |
dfbSurface->Clear(dfbSurface, color.red(), color.green(), color.blue(), color.alpha()); |
|
443 |
} |
|
444 |
||
445 |
QPixmap QDirectFBPixmapData::transformed(const QTransform &transform, |
|
446 |
Qt::TransformationMode mode) const |
|
447 |
{ |
|
448 |
QDirectFBPixmapData *that = const_cast<QDirectFBPixmapData*>(this); |
|
449 |
#ifdef QT_NO_DIRECTFB_SUBSURFACE |
|
450 |
if (lockFlags()) |
|
451 |
that->unlockSurface(); |
|
452 |
#endif |
|
453 |
||
454 |
if (!dfbSurface || transform.type() != QTransform::TxScale |
|
455 |
|| mode != Qt::FastTransformation) |
|
456 |
{ |
|
457 |
const QImage *image = that->buffer(); |
|
458 |
Q_ASSERT(image); |
|
459 |
const QImage transformed = image->transformed(transform, mode); |
|
460 |
QDirectFBPixmapData *data = new QDirectFBPixmapData(screen, QPixmapData::PixmapType); |
|
461 |
data->fromImage(transformed, Qt::AutoColor); |
|
462 |
return QPixmap(data); |
|
463 |
} |
|
464 |
||
465 |
const QSize size = transform.mapRect(QRect(0, 0, w, h)).size(); |
|
466 |
if (size.isEmpty()) |
|
467 |
return QPixmap(); |
|
468 |
||
469 |
QDirectFBPixmapData *data = new QDirectFBPixmapData(screen, QPixmapData::PixmapType); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
470 |
data->setSerialNumber(++global_ser_no); |
0 | 471 |
DFBSurfaceBlittingFlags flags = DSBLIT_NOFX; |
472 |
data->alpha = alpha; |
|
473 |
if (alpha) { |
|
474 |
flags = DSBLIT_BLEND_ALPHACHANNEL; |
|
475 |
} |
|
476 |
data->dfbSurface = screen->createDFBSurface(size, |
|
477 |
imageFormat, |
|
478 |
QDirectFBScreen::TrackSurface); |
|
479 |
if (flags & DSBLIT_BLEND_ALPHACHANNEL) { |
|
480 |
data->dfbSurface->Clear(data->dfbSurface, 0, 0, 0, 0); |
|
481 |
} |
|
482 |
data->dfbSurface->SetBlittingFlags(data->dfbSurface, flags); |
|
483 |
||
484 |
const DFBRectangle destRect = { 0, 0, size.width(), size.height() }; |
|
485 |
data->dfbSurface->StretchBlit(data->dfbSurface, dfbSurface, 0, &destRect); |
|
486 |
data->w = size.width(); |
|
487 |
data->h = size.height(); |
|
488 |
data->is_null = (data->w <= 0 || data->h <= 0); |
|
489 |
||
490 |
#if (Q_DIRECTFB_VERSION >= 0x010000) |
|
491 |
data->dfbSurface->ReleaseSource(data->dfbSurface); |
|
492 |
#endif |
|
493 |
return QPixmap(data); |
|
494 |
} |
|
495 |
||
496 |
QImage QDirectFBPixmapData::toImage() const |
|
497 |
{ |
|
498 |
if (!dfbSurface) |
|
499 |
return QImage(); |
|
500 |
||
501 |
#if 0 |
|
502 |
// In later versions of DirectFB one can set a flag to tell |
|
503 |
// DirectFB not to move the surface to videomemory. When that |
|
504 |
// happens we can use this (hopefully faster) codepath |
|
505 |
#ifndef QT_NO_DIRECTFB_PREALLOCATED |
|
506 |
QImage ret(w, h, QDirectFBScreen::getImageFormat(dfbSurface)); |
|
507 |
if (IDirectFBSurface *imgSurface = screen->createDFBSurface(ret, QDirectFBScreen::DontTrackSurface)) { |
|
508 |
if (hasAlphaChannel()) { |
|
509 |
imgSurface->SetBlittingFlags(imgSurface, DSBLIT_BLEND_ALPHACHANNEL); |
|
510 |
imgSurface->Clear(imgSurface, 0, 0, 0, 0); |
|
511 |
} else { |
|
512 |
imgSurface->SetBlittingFlags(imgSurface, DSBLIT_NOFX); |
|
513 |
} |
|
514 |
imgSurface->Blit(imgSurface, dfbSurface, 0, 0, 0); |
|
515 |
#if (Q_DIRECTFB_VERSION >= 0x010000) |
|
516 |
imgSurface->ReleaseSource(imgSurface); |
|
517 |
#endif |
|
518 |
imgSurface->Release(imgSurface); |
|
519 |
return ret; |
|
520 |
} |
|
521 |
#endif |
|
522 |
#endif |
|
523 |
||
524 |
QDirectFBPixmapData *that = const_cast<QDirectFBPixmapData*>(this); |
|
525 |
const QImage *img = that->buffer(); |
|
526 |
return img->copy(); |
|
527 |
} |
|
528 |
||
529 |
/* This is QPixmapData::paintEngine(), not QPaintDevice::paintEngine() */ |
|
530 |
||
531 |
QPaintEngine *QDirectFBPixmapData::paintEngine() const |
|
532 |
{ |
|
533 |
if (!engine) { |
|
534 |
// QDirectFBPixmapData is also a QCustomRasterPaintDevice, so pass |
|
535 |
// that to the paint engine: |
|
536 |
QDirectFBPixmapData *that = const_cast<QDirectFBPixmapData*>(this); |
|
537 |
that->engine = new QDirectFBPaintEngine(that); |
|
538 |
} |
|
539 |
return engine; |
|
540 |
} |
|
541 |
||
542 |
QImage *QDirectFBPixmapData::buffer() |
|
543 |
{ |
|
544 |
if (!lockFlgs) { |
|
545 |
lockSurface(DSLF_READ|DSLF_WRITE); |
|
546 |
} |
|
547 |
Q_ASSERT(lockFlgs); |
|
548 |
Q_ASSERT(!lockedImage.isNull()); |
|
549 |
return &lockedImage; |
|
550 |
} |
|
551 |
||
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
552 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
553 |
bool QDirectFBPixmapData::scroll(int dx, int dy, const QRect &rect) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
554 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
555 |
if (!dfbSurface) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
556 |
return false; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
557 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
558 |
unlockSurface(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
559 |
DFBResult result = dfbSurface->SetBlittingFlags(dfbSurface, DSBLIT_NOFX); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
560 |
if (result != DFB_OK) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
561 |
DirectFBError("QDirectFBPixmapData::scroll", result); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
562 |
return false; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
563 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
564 |
result = dfbSurface->SetPorterDuff(dfbSurface, DSPD_NONE); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
565 |
if (result != DFB_OK) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
566 |
DirectFBError("QDirectFBPixmapData::scroll", result); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
567 |
return false; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
568 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
569 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
570 |
const DFBRectangle source = { rect.x(), rect.y(), rect.width(), rect.height() }; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
571 |
result = dfbSurface->Blit(dfbSurface, dfbSurface, &source, source.x + dx, source.y + dy); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
572 |
if (result != DFB_OK) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
573 |
DirectFBError("QDirectFBPixmapData::scroll", result); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
574 |
return false; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
575 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
576 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
577 |
return true; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
578 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
579 |
|
0 | 580 |
void QDirectFBPixmapData::invalidate() |
581 |
{ |
|
582 |
if (dfbSurface) { |
|
583 |
screen->releaseDFBSurface(dfbSurface); |
|
584 |
dfbSurface = 0; |
|
585 |
} |
|
586 |
setSerialNumber(0); |
|
587 |
alpha = false; |
|
588 |
d = w = h = 0; |
|
589 |
is_null = true; |
|
590 |
imageFormat = QImage::Format_Invalid; |
|
591 |
} |
|
592 |
||
8
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
593 |
#ifndef QT_DIRECTFB_PLUGIN |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
594 |
Q_GUI_EXPORT IDirectFBSurface *qt_directfb_surface_for_pixmap(const QPixmap &pixmap) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
595 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
596 |
const QPixmapData *data = pixmap.pixmapData(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
597 |
if (!data || data->classId() != QPixmapData::DirectFBClass) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
598 |
return 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
599 |
const QDirectFBPixmapData *dfbData = static_cast<const QDirectFBPixmapData*>(data); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
600 |
return dfbData->directFBSurface(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
601 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
602 |
#endif |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
603 |
|
0 | 604 |
QT_END_NAMESPACE |
605 |
||
606 |
#endif // QT_NO_QWS_DIRECTFB |