summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/gfxdrivers/directfb/directfb.pro2
-rw-r--r--src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.cpp61
-rw-r--r--src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.h32
-rw-r--r--src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp529
-rw-r--r--src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp396
-rw-r--r--src/plugins/gfxdrivers/directfb/qdirectfbpixmap.h7
-rw-r--r--src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp515
-rw-r--r--src/plugins/gfxdrivers/directfb/qdirectfbscreen.h50
-rw-r--r--src/plugins/gfxdrivers/directfb/qdirectfbsurface.cpp123
-rw-r--r--src/plugins/gfxdrivers/directfb/qdirectfbsurface.h13
-rw-r--r--src/plugins/gfxdrivers/powervr/README3
-rw-r--r--src/plugins/gfxdrivers/powervr/pvreglscreen/pvreglscreen.cpp2
-rw-r--r--src/plugins/imageformats/jpeg/qjpeghandler.cpp6
13 files changed, 971 insertions, 768 deletions
diff --git a/src/plugins/gfxdrivers/directfb/directfb.pro b/src/plugins/gfxdrivers/directfb/directfb.pro
index 96eb536..89a289c 100644
--- a/src/plugins/gfxdrivers/directfb/directfb.pro
+++ b/src/plugins/gfxdrivers/directfb/directfb.pro
@@ -12,6 +12,8 @@ QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/gfxdrivers
#DEFINES += QT_NO_DIRECTFB_PREALLOCATED
#DEFINES += QT_NO_DIRECTFB_MOUSE
#DEFINES += QT_NO_DIRECTFB_KEYBOARD
+#DEFINES += QT_DIRECTFB_TIMING
+#DEFINES += QT_NO_DIRECTFB_OPAQUE_DETECTION
target.path = $$[QT_INSTALL_PLUGINS]/gfxdrivers
INSTALLS += target
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.cpp
index d1802e4..2a2ef5c 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.cpp
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.cpp
@@ -44,8 +44,13 @@
#include "qdirectfbscreen.h"
#include "qdirectfbpaintdevice.h"
+QDirectFBPaintDevice::~QDirectFBPaintDevice()
+{
+ delete lockedImage;
+}
-IDirectFBSurface *QDirectFBPaintDevice::directFbSurface() const
+
+IDirectFBSurface *QDirectFBPaintDevice::directFBSurface() const
{
return dfbSurface;
}
@@ -59,9 +64,6 @@ void QDirectFBPaintDevice::lockDirectFB() {
void *mem;
int w, h;
- int bpl;
- DFBSurfacePixelFormat format;
-
DFBResult result = dfbSurface->Lock(dfbSurface, DSLF_WRITE, &mem, &bpl);
if (result != DFB_OK || !mem) {
DirectFBError("QDirectFBPixmapData::buffer()", result);
@@ -69,16 +71,14 @@ void QDirectFBPaintDevice::lockDirectFB() {
}
dfbSurface->GetSize(dfbSurface, &w, &h);
- dfbSurface->GetPixelFormat(dfbSurface, &format);
-
lockedImage = new QImage(static_cast<uchar*>(mem), w, h, bpl,
- QDirectFBScreen::getImageFormat(format));
+ QDirectFBScreen::getImageFormat(dfbSurface));
}
void QDirectFBPaintDevice::unlockDirectFB()
{
- if (!lockedImage)
+ if (!lockedImage || !QDirectFBScreen::instance())
return;
dfbSurface->Unlock(dfbSurface);
@@ -98,19 +98,20 @@ void* QDirectFBPaintDevice::memory() const
QImage::Format QDirectFBPaintDevice::format() const
{
- DFBSurfacePixelFormat dfbFormat;
- dfbSurface->GetPixelFormat(dfbSurface, &dfbFormat);
- return QDirectFBScreen::getImageFormat(dfbFormat);
+ return QDirectFBScreen::getImageFormat(dfbSurface);
}
int QDirectFBPaintDevice::bytesPerLine() const
{
- // Can only get the stride when we lock the surface
- QDirectFBPaintDevice* that = const_cast<QDirectFBPaintDevice*>(this);
- that->lockDirectFB();
- Q_ASSERT(that->lockedImage);
- return that->lockedImage->bytesPerLine();
+ if (bpl == -1) {
+ // Can only get the stride when we lock the surface
+ Q_ASSERT(!lockedImage);
+ QDirectFBPaintDevice* that = const_cast<QDirectFBPaintDevice*>(this);
+ that->lockDirectFB();
+ Q_ASSERT(bpl != -1);
+ }
+ return bpl;
}
@@ -121,7 +122,6 @@ QSize QDirectFBPaintDevice::size() const
return QSize(w, h);
}
-
int QDirectFBPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const
{
if (!dfbSurface)
@@ -130,40 +130,21 @@ int QDirectFBPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const
int w, h;
dfbSurface->GetSize(dfbSurface, &w, &h);
- int dpmX, dpmY; // Dots-per-meter ;-)
-
- // Do some common calculations:
- switch (metric) {
- case QPaintDevice::PdmWidthMM:
- case QPaintDevice::PdmPhysicalDpiX:
- case QPaintDevice::PdmDpiX:
- dpmX = (screen->deviceWidth() * 1000) / screen->physicalWidth();
- break;
- case QPaintDevice::PdmHeightMM:
- case QPaintDevice::PdmPhysicalDpiY:
- case QPaintDevice::PdmDpiY:
- dpmY = (screen->deviceHeight() * 1000) / screen->physicalHeight();
- break;
- default:
- break;
- }
-
- // Now use those calculations
switch (metric) {
case QPaintDevice::PdmWidth:
return w;
case QPaintDevice::PdmHeight:
return h;
case QPaintDevice::PdmWidthMM:
- return (w * 1000) / dpmX;
+ return (w * 1000) / dotsPerMeterX();
case QPaintDevice::PdmHeightMM:
- return (h * 1000) / dpmY;
+ return (h * 1000) / dotsPerMeterY();
case QPaintDevice::PdmPhysicalDpiX:
case QPaintDevice::PdmDpiX:
- return (dpmX * 254) / 10000; // 0.0254 meters-per-inch
+ return (dotsPerMeterX() * 254) / 10000; // 0.0254 meters-per-inch
case QPaintDevice::PdmPhysicalDpiY:
case QPaintDevice::PdmDpiY:
- return (dpmY * 254) / 10000; // 0.0254 meters-per-inch
+ return (dotsPerMeterY() * 254) / 10000; // 0.0254 meters-per-inch
case QPaintDevice::PdmDepth:
DFBSurfacePixelFormat format;
dfbSurface->GetPixelFormat(dfbSurface, &format);
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.h b/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.h
index c28d37c..a11064b 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.h
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.h
@@ -54,28 +54,46 @@ QT_MODULE(Gui)
class QDirectFBPaintDevice : public QCustomRasterPaintDevice
{
public:
- QDirectFBPaintDevice(QDirectFBScreen *scr = QDirectFBScreen::instance())
- : QCustomRasterPaintDevice(0),
- dfbSurface(0),
- lockedImage(0),
- screen(scr) {}
+ ~QDirectFBPaintDevice();
- IDirectFBSurface *directFbSurface() const;
+ IDirectFBSurface *directFBSurface() const;
void lockDirectFB();
void unlockDirectFB();
+ inline bool forceRasterPrimitives() const { return forceRaster; }
+
// Reimplemented from QCustomRasterPaintDevice:
void* memory() const;
QImage::Format format() const;
int bytesPerLine() const;
QSize size() const;
int metric(QPaintDevice::PaintDeviceMetric metric) const;
-
protected:
+ // Shouldn't create QDirectFBPaintDevice by itself but only sub-class it:
+ QDirectFBPaintDevice(QDirectFBScreen *scr = QDirectFBScreen::instance())
+ : QCustomRasterPaintDevice(0),
+ dfbSurface(0),
+ lockedImage(0),
+ screen(scr),
+ forceRaster(false) {}
+
+ inline int dotsPerMeterX() const
+ {
+ return (screen->deviceWidth() * 1000) / screen->physicalWidth();
+ }
+ inline int dotsPerMeterY() const
+ {
+ return (screen->deviceHeight() * 1000) / screen->physicalHeight();
+ }
+
IDirectFBSurface *dfbSurface;
QImage *lockedImage;
QDirectFBScreen *screen;
+ int bpl;
+ bool forceRaster;
+private:
+ Q_DISABLE_COPY(QDirectFBPaintDevice)
};
QT_END_HEADER
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp
index 4fc4035..d9346fd 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp
@@ -61,17 +61,6 @@ static inline uint ALPHA_MUL(uint x, uint a)
return t;
}
-static inline QRect mapRect(const QTransform &transform, const QRect &rect)
-{
- return (transform.isIdentity() ? rect : transform.mapRect(rect));
-}
-
-static inline QRect mapRect(const QTransform &transform, const QRectF &rect)
-{
- return (transform.isIdentity() ? rect : transform.mapRect(rect)).
- toRect();
-}
-
class SurfaceCache
{
public:
@@ -112,7 +101,7 @@ CachedImage::CachedImage(const QImage &image)
description = QDirectFBScreen::getSurfaceDescription(image);
QDirectFBScreen* screen = QDirectFBScreen::instance();
- tmpSurface = screen->createDFBSurface(&description);
+ tmpSurface = screen->createDFBSurface(&description, QDirectFBScreen::TrackSurface);
if (!tmpSurface) {
qWarning("CachedImage CreateSurface failed!");
return;
@@ -124,7 +113,7 @@ CachedImage::CachedImage(const QImage &image)
description.flags = DFBSurfaceDescriptionFlags(description.flags & ~DSDESC_PREALLOCATED);
- s = screen->createDFBSurface(&description);
+ s = screen->createDFBSurface(&description, QDirectFBScreen::TrackSurface);
if (!s)
qWarning("QDirectFBPaintEngine failed caching image");
@@ -159,7 +148,7 @@ IDirectFBSurface* SurfaceCache::getSurface(const uint *buf, int size)
DFBSurfaceDescription description;
description = QDirectFBScreen::getSurfaceDescription(buf, size);
- surface = QDirectFBScreen::instance()->createDFBSurface(&description);
+ surface = QDirectFBScreen::instance()->createDFBSurface(&description, QDirectFBScreen::TrackSurface);
if (!surface)
qWarning("QDirectFBPaintEngine: SurfaceCache: Unable to create surface");
@@ -195,6 +184,7 @@ public:
QBrush brush;
bool antialiased;
+ bool forceRasterPrimitives;
bool simplePen;
bool simpleBrush;
@@ -206,12 +196,12 @@ public:
void setPen(const QPen &pen);
void setBrush(const QBrush &brush);
void setCompositionMode(QPainter::CompositionMode mode);
- void setOpacity(const qreal value);
+ void setOpacity(quint8 value);
void setRenderHints(QPainter::RenderHints hints);
- inline void setDFBColor(const QColor &color) const;
+ inline void setDFBColor(const QColor &color);
- inline bool lock();
+ inline void lock();
inline void unlock();
inline bool dfbCanHandleClip(const QRect &rect) const;
@@ -232,43 +222,41 @@ public:
void drawTiledPixmap(const QRectF &dest, const QPixmap &pixmap);
void drawImage(const QRectF &dest, const QImage &image, const QRectF &src);
- void updateClip();
- void updateFlags();
+ inline void updateClip();
inline void setClipDirty();
- void systemStateChanged(); //Needed to be notified when system clip changes
+ void systemStateChanged();
void begin(QPaintDevice *device);
void end();
+ void prepareForBlit(bool alpha);
SurfaceCache *surfaceCache;
-
+ QTransform transform;
+ int lastLockedHeight;
private:
-// QRegion rectsToClippedRegion(const QRect *rects, int n) const;
-// QRegion rectsToClippedRegion(const QRectF *rects, int n) const;
-
IDirectFB *fb;
DFBSurfaceDescription fbDescription;
int fbWidth;
int fbHeight;
quint8 opacity;
- QTransform transform;
- quint32 drawFlags;
- quint32 blitFlags;
- quint32 duffFlags;
- bool dirtyFlags;
+ quint32 drawFlagsFromCompositionMode, blitFlagsFromCompositionMode;
+ DFBSurfacePorterDuffRule porterDuffRule;
+
bool dirtyClip;
bool dfbHandledClip;
+ QDirectFBPaintDevice *dfbDevice;
QDirectFBPaintEngine *q;
};
QDirectFBPaintEnginePrivate::QDirectFBPaintEnginePrivate(QDirectFBPaintEngine *p)
- : surface(0), antialiased(false), simplePen(false),
- simpleBrush(false), matrixRotShear(false), matrixScale(false), fbWidth(-1), fbHeight(-1),
- opacity(255), drawFlags(0), blitFlags(0), duffFlags(0), dirtyFlags(false), dirtyClip(true),
- dfbHandledClip(false), q(p)
+ : surface(0), antialiased(false), forceRasterPrimitives(false), simplePen(false),
+ simpleBrush(false), matrixRotShear(false), matrixScale(false), lastLockedHeight(-1),
+ fbWidth(-1), fbHeight(-1), opacity(255), drawFlagsFromCompositionMode(0),
+ blitFlagsFromCompositionMode(0), porterDuffRule(DSPD_SRC_OVER), dirtyClip(true),
+ dfbHandledClip(false), dfbDevice(0), q(p)
{
fb = QDirectFBScreen::instance()->dfb();
surfaceCache = new SurfaceCache;
@@ -279,7 +267,6 @@ QDirectFBPaintEnginePrivate::QDirectFBPaintEnginePrivate(QDirectFBPaintEngine *p
QDirectFBPaintEnginePrivate::~QDirectFBPaintEnginePrivate()
{
- unlock();
delete surfaceCache;
}
@@ -305,27 +292,20 @@ void QDirectFBPaintEnginePrivate::setClipDirty()
dirtyClip = true;
}
-
-bool QDirectFBPaintEnginePrivate::lock()
+void QDirectFBPaintEnginePrivate::lock()
{
// We will potentially get a new pointer to the buffer after a
// lock so we need to call the base implementation of prepare so
// it updates its rasterBuffer to point to the new buffer address.
- if (device->devType() == QInternal::CustomRaster) {
- prepare(static_cast<QCustomRasterPaintDevice*>(device));
- return true;
- }
- return false;
+ lastLockedHeight = dfbDevice->height();
+
+ Q_ASSERT(dfbDevice);
+ prepare(dfbDevice);
}
void QDirectFBPaintEnginePrivate::unlock()
{
- QPaintDevice *device = q->paintDevice();
- if (!device) //XXX This should probably be an assert
- return;
-
- Q_ASSERT(device->devType() == QInternal::CustomRaster);
- QDirectFBPaintDevice* dfbDevice = static_cast<QDirectFBPaintDevice*>(device);
+ Q_ASSERT(dfbDevice);
dfbDevice->unlockDirectFB();
}
@@ -338,35 +318,31 @@ void QDirectFBPaintEnginePrivate::setTransform(const QTransform &m)
void QDirectFBPaintEnginePrivate::begin(QPaintDevice *device)
{
- QDirectFBPaintDevice* dfbDevice = 0;
-
+ lastLockedHeight = -1;
if (device->devType() == QInternal::CustomRaster)
dfbDevice = static_cast<QDirectFBPaintDevice*>(device);
else if (device->devType() == QInternal::Pixmap) {
QPixmapData *data = static_cast<QPixmap*>(device)->pixmapData();
- if (data->classId() == QPixmapData::DirectFBClass) {
- QDirectFBPixmapData* dfbPixmapData = static_cast<QDirectFBPixmapData*>(data);
- dfbDevice = static_cast<QDirectFBPaintDevice*>(dfbPixmapData);
- }
+ Q_ASSERT(data->classId() == QPixmapData::DirectFBClass);
+ QDirectFBPixmapData* dfbPixmapData = static_cast<QDirectFBPixmapData*>(data);
+ dfbDevice = static_cast<QDirectFBPaintDevice*>(dfbPixmapData);
}
if (dfbDevice)
- surface = dfbDevice->directFbSurface();
+ surface = dfbDevice->directFBSurface();
if (!surface) {
qFatal("QDirectFBPaintEngine used on an invalid device: 0x%x",
device->devType());
}
+ forceRasterPrimitives = dfbDevice->forceRasterPrimitives();
surface->GetSize(surface, &fbWidth, &fbHeight);
setTransform(QTransform());
antialiased = false;
- drawFlags = DSDRAW_BLEND;
- blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
- duffFlags = DSPD_SRC_OVER;
opacity = 255;
- dirtyFlags = true;
+ setCompositionMode(q->state()->compositionMode());
dirtyClip = true;
setPen(q->state()->pen);
setDFBColor(pen.color());
@@ -374,6 +350,7 @@ void QDirectFBPaintEnginePrivate::begin(QPaintDevice *device)
void QDirectFBPaintEnginePrivate::end()
{
+ dfbDevice = 0;
surface->ReleaseSource(surface);
surface->SetClip(surface, NULL);
surface = 0;
@@ -383,13 +360,14 @@ void QDirectFBPaintEnginePrivate::setPen(const QPen &p)
{
pen = p;
simplePen = (pen.style() == Qt::NoPen) ||
- (pen.style() == Qt::SolidLine && !antialiased
+ (pen.style() == Qt::SolidLine
+ && !antialiased
+ && (pen.brush().style() == Qt::SolidPattern)
&& (pen.widthF() <= 1 && !matrixScale));
}
void QDirectFBPaintEnginePrivate::setBrush(const QBrush &b)
{
- // TODO: accelerate texture pattern
brush = b;
simpleBrush = (brush.style() == Qt::NoBrush) ||
(brush.style() == Qt::SolidPattern && !antialiased);
@@ -397,91 +375,72 @@ void QDirectFBPaintEnginePrivate::setBrush(const QBrush &b)
void QDirectFBPaintEnginePrivate::setCompositionMode(QPainter::CompositionMode mode)
{
- drawFlags &= ~(DSDRAW_XOR);
- blitFlags &= ~(DSBLIT_XOR);
-
- // TODO: check these mappings!!!!
- quint32 duff = DSPD_NONE;
- quint32 blit = blitFlags;
+ blitFlagsFromCompositionMode = DSBLIT_NOFX;
+ drawFlagsFromCompositionMode = DSDRAW_NOFX;
+ bool blend = true;
switch (mode) {
case QPainter::CompositionMode_SourceOver:
- duff = DSPD_SRC_OVER;
- blit |= DSBLIT_BLEND_ALPHACHANNEL;
+ porterDuffRule = DSPD_SRC_OVER;
break;
case QPainter::CompositionMode_DestinationOver:
- duff = DSPD_DST_OVER;
- blit |= DSBLIT_BLEND_ALPHACHANNEL;
+ porterDuffRule = DSPD_DST_OVER;
break;
case QPainter::CompositionMode_Clear:
- duff = DSPD_CLEAR;
- blit &= ~DSBLIT_BLEND_ALPHACHANNEL;
+ porterDuffRule = DSPD_CLEAR;
+ blend = false;
break;
case QPainter::CompositionMode_Source:
- duff = DSPD_SRC;
- blit &= ~DSBLIT_BLEND_ALPHACHANNEL;
+ porterDuffRule = DSPD_SRC;
+ blend = false;
break;
case QPainter::CompositionMode_Destination:
- blit &= ~DSBLIT_BLEND_ALPHACHANNEL;
+ porterDuffRule = DSPD_NONE; // ### need to double check this
+ blend = false;
return;
case QPainter::CompositionMode_SourceIn:
- duff = DSPD_SRC_IN;
- blit |= DSBLIT_BLEND_ALPHACHANNEL;
+ porterDuffRule = DSPD_SRC_IN;
break;
case QPainter::CompositionMode_DestinationIn:
- duff = DSPD_DST_IN;
- blit |= DSBLIT_BLEND_ALPHACHANNEL;
+ porterDuffRule = DSPD_DST_IN;
break;
case QPainter::CompositionMode_SourceOut:
- duff = DSPD_SRC_OUT;
- blit |= DSBLIT_BLEND_ALPHACHANNEL;
+ porterDuffRule = DSPD_SRC_OUT;
break;
case QPainter::CompositionMode_DestinationOut:
- duff = DSPD_DST_OUT;
- blit |= DSBLIT_BLEND_ALPHACHANNEL;
- break;
- case QPainter::CompositionMode_SourceAtop:
- duff = DSPD_SRC_OVER;
- blit |= DSBLIT_BLEND_ALPHACHANNEL;
- break;
- case QPainter::CompositionMode_DestinationAtop:
- duff = DSPD_DST_OVER;
+ porterDuffRule = DSPD_DST_OUT;
break;
case QPainter::CompositionMode_Xor:
- duff = DSPD_NONE;
- blit |= DSBLIT_BLEND_ALPHACHANNEL;
- drawFlags |= DSDRAW_XOR;
- blit |= DSBLIT_XOR;
- dirtyFlags = true;
+ porterDuffRule = DSPD_XOR;
+ blitFlagsFromCompositionMode |= DSBLIT_XOR;
+ drawFlagsFromCompositionMode |= DSDRAW_XOR;
break;
+// case QPainter::CompositionMode_Plus: // ???
+// porterDuffRule = DSPD_ADD;
+// break;
default:
qWarning("QDirectFBPaintEnginePrivate::setCompositionMode(): "
"mode %d not implemented", mode);
- break;
+ return;
}
-
- if (duff != duffFlags || blit != blitFlags) {
- duffFlags = duff;
- blitFlags = blit;
- dirtyFlags = true;
+ // intentially not comparing with current porterDuffRule. surface might have changed.
+ if (blend) {
+ blitFlagsFromCompositionMode |= DSBLIT_BLEND_ALPHACHANNEL;
+ drawFlagsFromCompositionMode |= DSDRAW_BLEND;
+ }
+ if (opacity != 255) {
+ setOpacity(opacity);
}
}
-void QDirectFBPaintEnginePrivate::setOpacity(const qreal value)
+void QDirectFBPaintEnginePrivate::setOpacity(quint8 op)
{
- const bool wasOpaque = (opacity == 255);
- opacity = quint8(value * 255);
- const bool opaque = (opacity == 255);
-
- if (opaque == wasOpaque)
- return;
-
- if (opaque)
- blitFlags &= ~(DSBLIT_BLEND_COLORALPHA | DSBLIT_SRC_PREMULTCOLOR);
- else
- blitFlags |= (DSBLIT_BLEND_COLORALPHA | DSBLIT_SRC_PREMULTCOLOR);
-
- dirtyFlags = true;
+ opacity = op;
+ if (opacity == 255) {
+ blitFlagsFromCompositionMode &= ~DSBLIT_BLEND_COLORALPHA;
+ } else {
+ blitFlagsFromCompositionMode |= DSBLIT_BLEND_COLORALPHA;
+ }
}
void QDirectFBPaintEnginePrivate::setRenderHints(QPainter::RenderHints hints)
@@ -493,133 +452,83 @@ void QDirectFBPaintEnginePrivate::setRenderHints(QPainter::RenderHints hints)
}
}
-void QDirectFBPaintEnginePrivate::updateFlags()
+void QDirectFBPaintEnginePrivate::prepareForBlit(bool alpha)
{
- if (!dirtyFlags)
- return;
- surface->SetDrawingFlags(surface, DFBSurfaceDrawingFlags(drawFlags));
- surface->SetBlittingFlags(surface, DFBSurfaceBlittingFlags(blitFlags));
- surface->SetPorterDuff(surface, DFBSurfacePorterDuffRule(duffFlags));
- dirtyFlags = false;
+ quint32 blittingFlags = blitFlagsFromCompositionMode;
+ if (alpha) {
+ surface->SetPorterDuff(surface,
+ (blittingFlags & DSBLIT_BLEND_COLORALPHA)
+ ? DSPD_NONE
+ : porterDuffRule);
+ } else {
+ blittingFlags &= ~DSBLIT_BLEND_ALPHACHANNEL;
+ surface->SetPorterDuff(surface, DSPD_NONE);
+ }
+ surface->SetColor(surface, 0xff, 0xff, 0xff, opacity);
+ surface->SetBlittingFlags(surface, DFBSurfaceBlittingFlags(blittingFlags));
}
-void QDirectFBPaintEnginePrivate::setDFBColor(const QColor &color) const
+void QDirectFBPaintEnginePrivate::setDFBColor(const QColor &color)
{
+ Q_ASSERT(surface);
const quint8 alpha = (opacity == 255 ?
color.alpha() : ALPHA_MUL(color.alpha(), opacity));
surface->SetColor(surface,
color.red(), color.green(), color.blue(), alpha);
+ quint32 drawingFlags = drawFlagsFromCompositionMode;
+ if (alpha == 255) {
+ drawingFlags &= ~DSDRAW_BLEND;
+ }
+ surface->SetPorterDuff(surface, DSPD_NONE);
+ // PorterDuff messes up alpha values for primitives
+ surface->SetDrawingFlags(surface, DFBSurfaceDrawingFlags(drawingFlags));
}
void QDirectFBPaintEnginePrivate::drawLines(const QLine *lines, int n) const
{
- QVarLengthArray<DFBRegion> regions(n);
-
for (int i = 0; i < n; ++i) {
const QLine l = transform.map(lines[i]);
-
- // TODO: clip!
-
- regions[i].x1 = l.x1();
- regions[i].y1 = l.y1();
- regions[i].x2 = l.x2();
- regions[i].y2 = l.y2();
+ surface->DrawLine(surface, l.x1(), l.y1(), l.x2(), l.y2());
}
- surface->DrawLines(surface, regions.data(), n);
}
void QDirectFBPaintEnginePrivate::drawLines(const QLineF *lines, int n) const
{
- QVarLengthArray<DFBRegion> regions(n);
-
for (int i = 0; i < n; ++i) {
const QLine l = transform.map(lines[i]).toLine();
-
- // TODO: clip!
-
- regions[i].x1 = l.x1();
- regions[i].y1 = l.y1();
- regions[i].x2 = l.x2();
- regions[i].y2 = l.y2();
- }
- surface->DrawLines(surface, regions.data(), n);
-}
-
-/* ### Commented out until it can be implemented properly using raster's QClipData
-QRegion QDirectFBPaintEnginePrivate::rectsToClippedRegion(const QRect *rects,
- int n) const
-{
- QRegion region;
-
- for (int i = 0; i < n; ++i) {
- const QRect r = ::mapRect(transform, rects[i]);
- region += clip & r;
- }
-
- return region;
-}
-
-QRegion QDirectFBPaintEnginePrivate::rectsToClippedRegion(const QRectF *rects,
- int n) const
-{
- QRegion region;
-
- for (int i = 0; i < n; ++i) {
- const QRect r = ::mapRect(transform, rects[i]);
- region += clip & r;
+ surface->DrawLine(surface, l.x1(), l.y1(), l.x2(), l.y2());
}
-
- return region;
}
-*/
void QDirectFBPaintEnginePrivate::fillRegion(const QRegion &region) const
{
const QVector<QRect> rects = region.rects();
const int n = rects.size();
- QVarLengthArray<DFBRectangle> dfbRects(n);
-
- for (int i = 0; i < n; ++i) {
- const QRect r = rects.at(i);
- dfbRects[i].x = r.x();
- dfbRects[i].y = r.y();
- dfbRects[i].w = r.width();
- dfbRects[i].h = r.height();
-
- }
- surface->FillRectangles(surface, dfbRects.data(), n);
+ fillRects(rects.constData(), n);
}
void QDirectFBPaintEnginePrivate::fillRects(const QRect *rects, int n) const
{
- QVarLengthArray<DFBRectangle> dfbRects(n);
for (int i = 0; i < n; ++i) {
- const QRect r = ::mapRect(transform, rects[i]);
- dfbRects[i].x = r.x();
- dfbRects[i].y = r.y();
- dfbRects[i].w = r.width();
- dfbRects[i].h = r.height();
+ const QRect r = transform.mapRect(rects[i]);
+ surface->FillRectangle(surface, r.x(), r.y(),
+ r.width(), r.height());
}
- surface->FillRectangles(surface, dfbRects.data(), n);
}
void QDirectFBPaintEnginePrivate::fillRects(const QRectF *rects, int n) const
{
- QVarLengthArray<DFBRectangle> dfbRects(n);
for (int i = 0; i < n; ++i) {
- const QRect r = ::mapRect(transform, rects[i]);
- dfbRects[i].x = r.x();
- dfbRects[i].y = r.y();
- dfbRects[i].w = r.width();
- dfbRects[i].h = r.height();
+ const QRect r = transform.mapRect(rects[i]).toRect();
+ surface->FillRectangle(surface, r.x(), r.y(),
+ r.width(), r.height());
}
- surface->FillRectangles(surface, dfbRects.data(), n);
}
void QDirectFBPaintEnginePrivate::drawRects(const QRect *rects, int n) const
{
for (int i = 0; i < n; ++i) {
- const QRect r = ::mapRect(transform, rects[i]);
+ const QRect r = transform.mapRect(rects[i]);
surface->DrawRectangle(surface, r.x(), r.y(),
r.width() + 1, r.height() + 1);
}
@@ -628,7 +537,7 @@ void QDirectFBPaintEnginePrivate::drawRects(const QRect *rects, int n) const
void QDirectFBPaintEnginePrivate::drawRects(const QRectF *rects, int n) const
{
for (int i = 0; i < n; ++i) {
- const QRect r = ::mapRect(transform, rects[i]);
+ const QRect r = transform.mapRect(rects[i]).toRect();
surface->DrawRectangle(surface, r.x(), r.y(),
r.width() + 1, r.height() + 1);
}
@@ -638,21 +547,13 @@ void QDirectFBPaintEnginePrivate::drawPixmap(const QRectF &dest,
const QPixmap &pixmap,
const QRectF &src)
{
- surface->SetColor(surface, 0xff, 0xff, 0xff, opacity);
-
- const bool changeFlags = !pixmap.hasAlphaChannel()
- && (blitFlags & DSBLIT_BLEND_ALPHACHANNEL);
- if (changeFlags) {
- quint32 flags = blitFlags & ~DSBLIT_BLEND_ALPHACHANNEL;
- surface->SetBlittingFlags(surface, DFBSurfaceBlittingFlags(flags));
- }
-
+ prepareForBlit(pixmap.hasAlphaChannel());
QPixmapData *data = pixmap.pixmapData();
Q_ASSERT(data->classId() == QPixmapData::DirectFBClass);
QDirectFBPixmapData *dfbData = static_cast<QDirectFBPixmapData*>(data);
- IDirectFBSurface *s = dfbData->directFbSurface();
+ IDirectFBSurface *s = dfbData->directFBSurface();
const QRect sr = src.toRect();
- const QRect dr = ::mapRect(transform, dest);
+ const QRect dr = transform.mapRect(dest).toRect();
const DFBRectangle sRect = { sr.x(), sr.y(), sr.width(), sr.height() };
DFBResult result;
@@ -664,27 +565,17 @@ void QDirectFBPaintEnginePrivate::drawPixmap(const QRectF &dest,
}
if (result != DFB_OK)
DirectFBError("QDirectFBPaintEngine::drawPixmap()", result);
- if (changeFlags)
- surface->SetBlittingFlags(surface, DFBSurfaceBlittingFlags(blitFlags));
}
void QDirectFBPaintEnginePrivate::drawTiledPixmap(const QRectF &dest,
const QPixmap &pixmap)
{
- surface->SetColor(surface, 0xff, 0xff, 0xff, opacity);
-
- const bool changeFlags = !pixmap.hasAlphaChannel()
- && (blitFlags & DSBLIT_BLEND_ALPHACHANNEL);
- if (changeFlags) {
- quint32 flags = blitFlags & ~DSBLIT_BLEND_ALPHACHANNEL;
- surface->SetBlittingFlags(surface, DFBSurfaceBlittingFlags(flags));
- }
-
+ prepareForBlit(pixmap.hasAlphaChannel());
QPixmapData *data = pixmap.pixmapData();
Q_ASSERT(data->classId() == QPixmapData::DirectFBClass);
QDirectFBPixmapData *dfbData = static_cast<QDirectFBPixmapData*>(data);
- IDirectFBSurface *s = dfbData->directFbSurface();
- const QRect dr = ::mapRect(transform, dest);
+ IDirectFBSurface *s = dfbData->directFBSurface();
+ const QRect dr = transform.mapRect(dest).toRect();
DFBResult result = DFB_OK;
if (!matrixScale && dr == QRect(0, 0, fbWidth, fbHeight)) {
@@ -706,7 +597,7 @@ void QDirectFBPaintEnginePrivate::drawTiledPixmap(const QRectF &dest,
result = surface->BatchBlit(surface, s, rects.constData(),
points.constData(), points.size());
} else {
- const QRect sr = ::mapRect(transform, QRect(0, 0, pixmap.width(), pixmap.height()));
+ const QRect sr = transform.mapRect(QRect(0, 0, pixmap.width(), pixmap.height()));
const int dx = sr.width();
const int dy = sr.height();
const DFBRectangle sRect = { 0, 0, dx, dy };
@@ -725,25 +616,13 @@ void QDirectFBPaintEnginePrivate::drawTiledPixmap(const QRectF &dest,
if (result != DFB_OK)
DirectFBError("QDirectFBPaintEngine::drawTiledPixmap()", result);
-
- if (changeFlags)
- surface->SetBlittingFlags(surface, DFBSurfaceBlittingFlags(blitFlags));
}
void QDirectFBPaintEnginePrivate::drawImage(const QRectF &dest,
- const QImage &srcImage,
+ const QImage &image,
const QRectF &src)
{
- QImage image = srcImage;
- if (QDirectFBScreen::getSurfacePixelFormat(image) == DSPF_UNKNOWN) {
- QImage::Format format;
- if (image.hasAlphaChannel())
- format = QImage::Format_ARGB32_Premultiplied;
- else
- format = QImage::Format_RGB32;
- image = image.convertToFormat(format);
- }
-
+ Q_ASSERT(QDirectFBScreen::getSurfacePixelFormat(image.format()) != DSPF_UNKNOWN);
CachedImage *img = imageCache[image.cacheKey()];
IDirectFBSurface *imgSurface = 0;
bool doRelease = false;
@@ -767,7 +646,8 @@ void QDirectFBPaintEnginePrivate::drawImage(const QRectF &dest,
DFBSurfaceDescription description;
description = QDirectFBScreen::getSurfaceDescription(image);
- imgSurface = QDirectFBScreen::instance()->createDFBSurface(&description);
+ imgSurface = QDirectFBScreen::instance()->createDFBSurface(&description,
+ QDirectFBScreen::DontTrackSurface);
if (!imgSurface) {
qWarning("QDirectFBPaintEnginePrivate::drawImage");
return;
@@ -781,17 +661,10 @@ void QDirectFBPaintEnginePrivate::drawImage(const QRectF &dest,
}
const QRect sr = src.toRect();
- const QRect dr = ::mapRect(transform, dest);
+ const QRect dr = transform.mapRect(dest).toRect();
const DFBRectangle sRect = { sr.x(), sr.y(), sr.width(), sr.height() };
- surface->SetColor(surface, 0xff, 0xff, 0xff, opacity);
-
- const bool changeFlags = !image.hasAlphaChannel()
- && (blitFlags & DSBLIT_BLEND_ALPHACHANNEL);
- if (changeFlags) {
- quint32 flags = blitFlags & ~DSBLIT_BLEND_ALPHACHANNEL;
- surface->SetBlittingFlags(surface, DFBSurfaceBlittingFlags(flags));
- }
+ prepareForBlit(image.hasAlphaChannel());
if (dr.size() == sr.size()) {
surface->Blit(surface, imgSurface, &sRect, dr.x(), dr.y());
} else {
@@ -799,10 +672,10 @@ void QDirectFBPaintEnginePrivate::drawImage(const QRectF &dest,
dr.width(), dr.height() };
surface->StretchBlit(surface, imgSurface, &sRect, &dRect);
}
- if (changeFlags)
- surface->SetBlittingFlags(surface, DFBSurfaceBlittingFlags(blitFlags));
- if (doRelease)
- QDirectFBScreen::instance()->releaseDFBSurface(imgSurface);
+ if (doRelease) {
+ surface->ReleaseSource(surface);
+ imgSurface->Release(imgSurface);
+ }
}
void QDirectFBPaintEnginePrivate::updateClip()
@@ -893,8 +766,7 @@ void QDirectFBPaintEngine::brushChanged()
void QDirectFBPaintEngine::opacityChanged()
{
Q_D(QDirectFBPaintEngine);
- d->setOpacity(state()->opacity);
-
+ d->setOpacity(quint8(state()->opacity * 255));
QRasterPaintEngine::opacityChanged();
}
@@ -902,7 +774,6 @@ void QDirectFBPaintEngine::compositionModeChanged()
{
Q_D(QDirectFBPaintEngine);
d->setCompositionMode(state()->compositionMode());
-
QRasterPaintEngine::compositionModeChanged();
}
@@ -928,11 +799,10 @@ void QDirectFBPaintEngine::setState(QPainterState *s)
{
Q_D(QDirectFBPaintEngine);
QRasterPaintEngine::setState(s);
- if (d->surface)
- d->updateClip();
+ d->setClipDirty();
d->setPen(state()->pen);
d->setBrush(state()->brush);
- d->setOpacity(state()->opacity);
+ d->setOpacity(quint8(state()->opacity * 255));
d->setCompositionMode(state()->compositionMode());
d->setTransform(state()->transform());
}
@@ -941,6 +811,9 @@ void QDirectFBPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op)
{
Q_D(QDirectFBPaintEngine);
d->setClipDirty();
+ const QPoint bottom = d->transform.map(QPoint(0, path.controlPointRect().y2));
+ if (bottom.y() >= d->lastLockedHeight)
+ d->lock();
QRasterPaintEngine::clip(path, op);
}
@@ -948,15 +821,21 @@ void QDirectFBPaintEngine::clip(const QRect &rect, Qt::ClipOperation op)
{
Q_D(QDirectFBPaintEngine);
d->setClipDirty();
+ if (!d->clip()->hasRectClip && d->clip()->enabled) {
+ const QPoint bottom = d->transform.map(QPoint(0, rect.bottom()));
+ if (bottom.y() >= d->lastLockedHeight)
+ d->lock();
+ }
+
QRasterPaintEngine::clip(rect, op);
}
-
void QDirectFBPaintEngine::drawRects(const QRect *rects, int rectCount)
{
Q_D(QDirectFBPaintEngine);
d->updateClip();
- if (!d->dfbCanHandleClip() || d->matrixRotShear || !d->simpleBrush || !d->simplePen) {
+ if (!d->dfbCanHandleClip() || d->matrixRotShear || !d->simpleBrush
+ || !d->simplePen || d->forceRasterPrimitives) {
d->lock();
QRasterPaintEngine::drawRects(rects, rectCount);
return;
@@ -965,12 +844,10 @@ void QDirectFBPaintEngine::drawRects(const QRect *rects, int rectCount)
d->unlock();
if (d->brush != Qt::NoBrush) {
- d->updateFlags();
d->setDFBColor(d->brush.color());
d->fillRects(rects, rectCount);
}
if (d->pen != Qt::NoPen) {
- d->updateFlags();
d->setDFBColor(d->pen.color());
d->drawRects(rects, rectCount);
}
@@ -980,7 +857,8 @@ void QDirectFBPaintEngine::drawRects(const QRectF *rects, int rectCount)
{
Q_D(QDirectFBPaintEngine);
d->updateClip();
- if (!d->dfbCanHandleClip() || d->matrixRotShear || !d->simpleBrush || !d->simplePen) {
+ if (!d->dfbCanHandleClip() || d->matrixRotShear || !d->simpleBrush
+ || !d->simplePen || d->forceRasterPrimitives) {
d->lock();
QRasterPaintEngine::drawRects(rects, rectCount);
return;
@@ -989,12 +867,10 @@ void QDirectFBPaintEngine::drawRects(const QRectF *rects, int rectCount)
d->unlock();
if (d->brush != Qt::NoBrush) {
- d->updateFlags();
d->setDFBColor(d->brush.color());
d->fillRects(rects, rectCount);
}
if (d->pen != Qt::NoPen) {
- d->updateFlags();
d->setDFBColor(d->pen.color());
d->drawRects(rects, rectCount);
}
@@ -1004,7 +880,7 @@ void QDirectFBPaintEngine::drawLines(const QLine *lines, int lineCount)
{
Q_D(QDirectFBPaintEngine);
d->updateClip();
- if (!d->simplePen || !d->dfbCanHandleClip()) {
+ if (!d->simplePen || !d->dfbCanHandleClip() || d->forceRasterPrimitives) {
d->lock();
QRasterPaintEngine::drawLines(lines, lineCount);
return;
@@ -1012,7 +888,6 @@ void QDirectFBPaintEngine::drawLines(const QLine *lines, int lineCount)
if (d->pen != Qt::NoPen) {
d->unlock();
- d->updateFlags();
d->setDFBColor(d->pen.color());
d->drawLines(lines, lineCount);
}
@@ -1022,7 +897,7 @@ void QDirectFBPaintEngine::drawLines(const QLineF *lines, int lineCount)
{
Q_D(QDirectFBPaintEngine);
d->updateClip();
- if (!d->simplePen || !d->dfbCanHandleClip()) {
+ if (!d->simplePen || !d->dfbCanHandleClip() || d->forceRasterPrimitives) {
d->lock();
QRasterPaintEngine::drawLines(lines, lineCount);
return;
@@ -1030,7 +905,6 @@ void QDirectFBPaintEngine::drawLines(const QLineF *lines, int lineCount)
if (d->pen != Qt::NoPen) {
d->unlock();
- d->updateFlags();
d->setDFBColor(d->pen.color());
d->drawLines(lines, lineCount);
}
@@ -1045,7 +919,8 @@ void QDirectFBPaintEngine::drawImage(const QRectF &r, const QImage &image,
#ifndef QT_NO_DIRECTFB_PREALLOCATED
d->updateClip();
- if (!d->dfbCanHandleClip(r) || d->matrixRotShear)
+ if (!d->dfbCanHandleClip(r) || d->matrixRotShear
+ || QDirectFBScreen::getSurfacePixelFormat(image.format()) == DSPF_UNKNOWN)
#endif
{
d->lock();
@@ -1055,7 +930,6 @@ void QDirectFBPaintEngine::drawImage(const QRectF &r, const QImage &image,
#ifndef QT_NO_DIRECTFB_PREALLOCATED
d->unlock();
- d->updateFlags();
d->drawImage(r, image, sr);
#endif
}
@@ -1074,15 +948,12 @@ void QDirectFBPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pixmap,
if (pixmap.pixmapData()->classId() != QPixmapData::DirectFBClass) {
d->lock();
QRasterPaintEngine::drawPixmap(r, pixmap, sr);
- }
- else if (!d->dfbCanHandleClip(r) || d->matrixRotShear) {
+ } else if (!d->dfbCanHandleClip(r) || d->matrixRotShear) {
const QImage *img = static_cast<QDirectFBPixmapData*>(pixmap.pixmapData())->buffer();
d->lock();
QRasterPaintEngine::drawImage(r, *img, sr);
- }
- else {
+ } else {
d->unlock();
- d->updateFlags();
d->drawPixmap(r, pixmap, sr);
}
}
@@ -1101,18 +972,15 @@ void QDirectFBPaintEngine::drawTiledPixmap(const QRectF &r,
if (pixmap.pixmapData()->classId() != QPixmapData::DirectFBClass) {
d->lock();
QRasterPaintEngine::drawTiledPixmap(r, pixmap, sp);
- }
- else if (!d->dfbCanHandleClip(r) || d->matrixRotShear || !sp.isNull()) {
- QImage* img = static_cast<QDirectFBPixmapData*>(pixmap.pixmapData())->buffer();
+ } else if (!d->dfbCanHandleClip(r) || d->matrixRotShear || !sp.isNull()) {
+ const QImage *img = static_cast<QDirectFBPixmapData*>(pixmap.pixmapData())->buffer();
+ d->lock();
QRasterPixmapData *data = new QRasterPixmapData(QPixmapData::PixmapType);
data->fromImage(*img, Qt::AutoColor);
const QPixmap pix(data);
- d->lock();
QRasterPaintEngine::drawTiledPixmap(r, pix, sp);
- }
- else {
+ } else {
d->unlock();
- d->updateFlags();
d->drawTiledPixmap(r, pixmap);
}
}
@@ -1184,67 +1052,89 @@ void QDirectFBPaintEngine::fill(const QVectorPath &path, const QBrush &brush)
QRasterPaintEngine::fill(path, brush);
}
-void QDirectFBPaintEngine::fillRect(const QRectF &r, const QBrush &brush)
+
+void QDirectFBPaintEngine::fillRect(const QRectF &rect, const QBrush &brush)
{
Q_D(QDirectFBPaintEngine);
- if (brush.style() != Qt::SolidPattern) {
- d->lock();
- QRasterPaintEngine::fillRect(r, brush);
+ d->updateClip();
+ if (d->dfbCanHandleClip(rect) && !d->matrixRotShear) {
+ switch (brush.style()) {
+ case Qt::SolidPattern: {
+ if (d->forceRasterPrimitives)
+ break;
+ d->unlock();
+ d->setDFBColor(brush.color());
+ const QRect r = d->transform.mapRect(rect).toRect();
+ d->surface->FillRectangle(d->surface, r.x(), r.y(),
+ r.width(), r.height());
+ return; }
+ case Qt::TexturePattern:
+ if (state()->brushOrigin == QPointF() && brush.transform().isIdentity()) {
+ //could handle certain types of brush.transform() E.g. scale
+ d->unlock();
+ d->drawTiledPixmap(rect, brush.texture());
+ return;
+ }
+ break;
+ default:
+ break;
+ }
}
- else
- fillRect(r, brush.color());
+ d->lock();
+ QRasterPaintEngine::fillRect(rect, brush);
}
void QDirectFBPaintEngine::fillRect(const QRectF &rect, const QColor &color)
{
Q_D(QDirectFBPaintEngine);
d->updateClip();
- if (!d->dfbCanHandleClip() || d->matrixRotShear) {
+ if (!d->dfbCanHandleClip() || d->matrixRotShear || d->forceRasterPrimitives) {
d->lock();
QRasterPaintEngine::fillRect(rect, color);
} else {
d->unlock();
- d->updateFlags();
d->setDFBColor(color);
- d->fillRects(&rect, 1);
+ const QRect r = d->transform.mapRect(rect).toRect();
+ d->surface->FillRectangle(d->surface, r.x(), r.y(),
+ r.width(), r.height());
}
}
-
-
-
-
-
-
void QDirectFBPaintEngine::drawColorSpans(const QSpan *spans, int count,
uint color)
{
Q_D(QDirectFBPaintEngine);
- color = INV_PREMUL(color);
-
- QVarLengthArray<DFBRegion> lines(count);
- int j = 0;
- for (int i = 0; i < count; ++i) {
- if (spans[i].coverage == 255) {
- lines[j].x1 = spans[i].x;
- lines[j].y1 = spans[i].y;
- lines[j].x2 = spans[i].x + spans[i].len - 1;
- lines[j].y2 = spans[i].y;
- ++j;
- } else {
- DFBSpan span = { spans[i].x, spans[i].len };
- uint c = BYTE_MUL(color, spans[i].coverage);
+ if (d->forceRasterPrimitives) {
+ d->lock();
+ QRasterPaintEngine::drawColorSpans(spans, count, color);
+ } else {
+ color = INV_PREMUL(color);
+
+ QVarLengthArray<DFBRegion> lines(count);
+ int j = 0;
+ for (int i = 0; i < count; ++i) {
+ if (spans[i].coverage == 255) {
+ lines[j].x1 = spans[i].x;
+ lines[j].y1 = spans[i].y;
+ lines[j].x2 = spans[i].x + spans[i].len - 1;
+ lines[j].y2 = spans[i].y;
+ ++j;
+ } else {
+ DFBSpan span = { spans[i].x, spans[i].len };
+ uint c = BYTE_MUL(color, spans[i].coverage);
+ // ### how does this play with setDFBColor
+ d->surface->SetColor(d->surface,
+ qRed(c), qGreen(c), qBlue(c), qAlpha(c));
+ d->surface->FillSpans(d->surface, spans[i].y, &span, 1);
+ }
+ }
+ if (j > 0) {
d->surface->SetColor(d->surface,
- qRed(c), qGreen(c), qBlue(c), qAlpha(c));
- d->surface->FillSpans(d->surface, spans[i].y, &span, 1);
+ qRed(color), qGreen(color), qBlue(color),
+ qAlpha(color));
+ d->surface->DrawLines(d->surface, lines.data(), j);
}
}
- if (j > 0) {
- d->surface->SetColor(d->surface,
- qRed(color), qGreen(color), qBlue(color),
- qAlpha(color));
- d->surface->DrawLines(d->surface, lines.data(), j);
- }
}
void QDirectFBPaintEngine::drawBufferSpan(const uint *buffer, int bufsize,
@@ -1253,6 +1143,7 @@ void QDirectFBPaintEngine::drawBufferSpan(const uint *buffer, int bufsize,
{
Q_D(QDirectFBPaintEngine);
IDirectFBSurface *src = d->surfaceCache->getSurface(buffer, bufsize);
+ // ### how does this play with setDFBColor
src->SetColor(src, 0, 0, 0, const_alpha);
const DFBRectangle rect = { 0, 0, length, 1 };
d->surface->Blit(d->surface, src, &rect, x, y);
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp
index 6352652..0a1696a 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp
@@ -51,7 +51,7 @@ static int global_ser_no = 0;
QDirectFBPixmapData::QDirectFBPixmapData(PixelType pixelType)
: QPixmapData(pixelType, DirectFBClass),
- engine(0)
+ engine(0), format(QImage::Format_Invalid), alpha(false)
{
setSerialNumber(0);
}
@@ -67,81 +67,119 @@ QDirectFBPixmapData::~QDirectFBPixmapData()
void QDirectFBPixmapData::resize(int width, int height)
{
if (width <= 0 || height <= 0) {
- setSerialNumber(0);
+ invalidate();
return;
}
- DFBSurfaceDescription description;
- description.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH |
- DSDESC_HEIGHT);
- description.width = width;
- description.height = height;
-
- dfbSurface = screen->createDFBSurface(&description);
- if (!dfbSurface)
- qCritical("QDirectFBPixmapData::resize(): Unable to allocate surface");
+ format = screen->pixelFormat();
+ dfbSurface = QDirectFBScreen::instance()->createDFBSurface(QSize(width, height),
+ format,
+ QDirectFBScreen::TrackSurface);
+ alpha = false;
+ forceRaster = (format == QImage::Format_RGB32);
+ if (!dfbSurface) {
+ invalidate();
+ qWarning("QDirectFBPixmapData::resize(): Unable to allocate surface");
+ return;
+ }
setSerialNumber(++global_ser_no);
}
-void QDirectFBPixmapData::fromImage(const QImage &img,
- Qt::ImageConversionFlags)
-{
- QImage image;
- if (QDirectFBScreen::getSurfacePixelFormat(img) == DSPF_UNKNOWN)
- image = img.convertToFormat(QImage::Format_ARGB32_Premultiplied);
- else
- image = img;
- DFBSurfaceDescription description;
- description = QDirectFBScreen::getSurfaceDescription(image);
+// mostly duplicated from qimage.cpp (QImageData::checkForAlphaPixels)
+static bool checkForAlphaPixels(const QImage &img)
+{
+ const uchar *bits = img.bits();
+ const int bytes_per_line = img.bytesPerLine();
+ const uchar *end_bits = bits + bytes_per_line;
+ const int width = img.width();
+ const int height = img.height();
+ switch (img.format()) {
+ case QImage::Format_Indexed8:
+ return img.hasAlphaChannel();
+ case QImage::Format_ARGB32:
+ case QImage::Format_ARGB32_Premultiplied:
+ for (int y=0; y<height; ++y) {
+ for (int x=0; x<width; ++x) {
+ if ((((uint *)bits)[x] & 0xff000000) != 0xff000000) {
+ return true;
+ }
+ }
+ bits += bytes_per_line;
+ }
+ break;
+
+ case QImage::Format_ARGB8555_Premultiplied:
+ case QImage::Format_ARGB8565_Premultiplied:
+ for (int y=0; y<height; ++y) {
+ while (bits < end_bits) {
+ if (bits[0] != 0) {
+ return true;
+ }
+ bits += 3;
+ }
+ bits = end_bits;
+ end_bits += bytes_per_line;
+ }
+ break;
+
+ case QImage::Format_ARGB6666_Premultiplied:
+ for (int y=0; y<height; ++y) {
+ while (bits < end_bits) {
+ if ((bits[0] & 0xfc) != 0) {
+ return true;
+ }
+ bits += 3;
+ }
+ bits = end_bits;
+ end_bits += bytes_per_line;
+ }
+ break;
+
+ case QImage::Format_ARGB4444_Premultiplied:
+ for (int y=0; y<height; ++y) {
+ while (bits < end_bits) {
+ if ((bits[0] & 0xf0) != 0) {
+ return true;
+ }
+ bits += 2;
+ }
+ bits = end_bits;
+ end_bits += bytes_per_line;
+ }
+ break;
-#ifndef QT_NO_DIRECTFB_PREALLOCATED
- IDirectFBSurface *imgSurface;
- imgSurface = screen->createDFBSurface(&description);
- if (!imgSurface) {
- qWarning("QDirectFBPixmapData::fromImage()");
- setSerialNumber(0);
- return;
+ default:
+ break;
}
-#ifndef QT_NO_DIRECTFB_PALETTE
- QDirectFBScreen::setSurfaceColorTable(imgSurface, image);
-#endif
-#endif // QT_NO_DIRECTFB_PREALLOCATED
- description.flags = DFBSurfaceDescriptionFlags(description.flags
- & ~DSDESC_PREALLOCATED);
- dfbSurface = screen->createDFBSurface(&description);
+ return false;
+}
+
+void QDirectFBPixmapData::fromImage(const QImage &img,
+ Qt::ImageConversionFlags flags)
+{
+ Q_ASSERT(img.depth() != 1); // these should be handled by QRasterPixmapData
+ if (img.hasAlphaChannel()
+#ifndef QT_NO_DIRECTFB_OPAQUE_DETECTION
+ && (flags & Qt::NoOpaqueDetection || ::checkForAlphaPixels(img))
+#endif
+ ) {
+ alpha = true;
+ format = screen->alphaPixmapFormat();
+ } else {
+ alpha = false;
+ format = screen->pixelFormat();
+ }
+ dfbSurface = screen->copyToDFBSurface(img, format,
+ QDirectFBScreen::TrackSurface);
+ forceRaster = (format == QImage::Format_RGB32);
if (!dfbSurface) {
qWarning("QDirectFBPixmapData::fromImage()");
- setSerialNumber(0);
+ invalidate();
return;
}
-
-#ifndef QT_NO_DIRECTFB_PALETTE
- QDirectFBScreen::setSurfaceColorTable(dfbSurface, image);
-#endif
-
-#ifdef QT_NO_DIRECTFB_PREALLOCATED
- char *mem;
- surface->Lock(surface, DSLF_WRITE, (void**)&mem, &bpl);
- const int w = image.width() * image.depth() / 8;
- for (int i = 0; i < image.height(); ++i) {
- memcpy(mem, image.scanLine(i), w);
- mem += bpl;
- }
- surface->Unlock(surface);
-#else
- DFBResult result;
- dfbSurface->SetBlittingFlags(dfbSurface, DSBLIT_NOFX);
- result = dfbSurface->Blit(dfbSurface, imgSurface, 0, 0, 0);
- if (result != DFB_OK)
- DirectFBError("QDirectFBPixmapData::fromImage()", result);
- dfbSurface->Flip(dfbSurface, 0, DSFLIP_NONE);
- dfbSurface->ReleaseSource(dfbSurface);
- screen->releaseDFBSurface(imgSurface);
-#endif // QT_NO_DIRECTFB_PREALLOCATED
-
setSerialNumber(++global_ser_no);
}
@@ -152,43 +190,55 @@ void QDirectFBPixmapData::copy(const QPixmapData *data, const QRect &rect)
return;
}
- IDirectFBSurface *src = static_cast<const QDirectFBPixmapData*>(data)->directFbSurface();
+ IDirectFBSurface *src = static_cast<const QDirectFBPixmapData*>(data)->directFBSurface();
+ const bool hasAlpha = data->hasAlphaChannel();
+ format = (hasAlpha
+ ? QDirectFBScreen::instance()->alphaPixmapFormat()
+ : QDirectFBScreen::instance()->pixelFormat());
- DFBSurfaceDescription description;
- description.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH |
- DSDESC_HEIGHT |
- DSDESC_PIXELFORMAT);
- description.width = rect.width();
- description.height = rect.height();
- src->GetPixelFormat(src, &description.pixelformat);
-
- dfbSurface = screen->createDFBSurface(&description);
+ dfbSurface = screen->createDFBSurface(rect.size(), format,
+ QDirectFBScreen::TrackSurface);
if (!dfbSurface) {
qWarning("QDirectFBPixmapData::copy()");
- setSerialNumber(0);
+ invalidate();
return;
}
+ forceRaster = (format == QImage::Format_RGB32);
- DFBResult result;
-#ifndef QT_NO_DIRECTFB_PALETTE
- IDirectFBPalette *palette;
- result = src->GetPalette(src, &palette);
- if (result == DFB_OK) {
- dfbSurface->SetPalette(dfbSurface, palette);
- palette->Release(palette);
+ if (hasAlpha) {
+ dfbSurface->Clear(dfbSurface, 0, 0, 0, 0);
+ dfbSurface->SetBlittingFlags(dfbSurface, DSBLIT_BLEND_ALPHACHANNEL);
+ } else {
+ dfbSurface->SetBlittingFlags(dfbSurface, DSBLIT_NOFX);
}
-#endif
-
- dfbSurface->SetBlittingFlags(dfbSurface, DSBLIT_NOFX);
const DFBRectangle blitRect = { rect.x(), rect.y(),
rect.width(), rect.height() };
- result = dfbSurface->Blit(dfbSurface, src, &blitRect, 0, 0);
- if (result != DFB_OK)
+ DFBResult result = dfbSurface->Blit(dfbSurface, src, &blitRect, 0, 0);
+ dfbSurface->ReleaseSource(dfbSurface);
+ if (result != DFB_OK) {
DirectFBError("QDirectFBPixmapData::copy()", result);
+ invalidate();
+ return;
+ }
setSerialNumber(++global_ser_no);
}
+static inline bool isOpaqueFormat(QImage::Format format)
+{
+ switch (format) {
+ case QImage::Format_RGB32:
+ case QImage::Format_RGB16:
+ case QImage::Format_RGB666:
+ case QImage::Format_RGB555:
+ case QImage::Format_RGB888:
+ case QImage::Format_RGB444:
+ return true;
+ default:
+ break;
+ }
+ return false;
+}
void QDirectFBPixmapData::fill(const QColor &color)
{
@@ -197,72 +247,39 @@ void QDirectFBPixmapData::fill(const QColor &color)
Q_ASSERT(dfbSurface);
- if (color.alpha() < 255 && !hasAlphaChannel()) {
- // convert to surface supporting alpha channel
- DFBSurfacePixelFormat format;
- dfbSurface->GetPixelFormat(dfbSurface, &format);
- switch (format) {
- case DSPF_YUY2:
- case DSPF_UYVY:
- format = DSPF_AYUV;
- break;
-#if (Q_DIRECTFB_VERSION >= 0x010100)
- case DSPF_RGB444:
- format = DSPF_ARGB4444;
- break;
- case DSPF_RGB555:
-#endif
- case DSPF_RGB18:
- format = DSPF_ARGB6666;
- break;
- default:
- format = DSPF_ARGB;
- break;
- }
+ alpha = (color.alpha() < 255);
- DFBSurfaceDescription description;
- description.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH |
- DSDESC_HEIGHT |
- DSDESC_PIXELFORMAT);
- dfbSurface->GetSize(dfbSurface, &description.width, &description.height);
- description.pixelformat = format;
- screen->releaseDFBSurface(dfbSurface); // release old surface
-
- dfbSurface = screen->createDFBSurface(&description);
+ if (alpha && ::isOpaqueFormat(format)) {
+ QSize size;
+ dfbSurface->GetSize(dfbSurface, &size.rwidth(), &size.rheight());
+ screen->releaseDFBSurface(dfbSurface);
+ format = screen->alphaPixmapFormat();
+ dfbSurface = screen->createDFBSurface(size, screen->alphaPixmapFormat(), QDirectFBScreen::TrackSurface);
+ forceRaster = false;
+ setSerialNumber(++global_ser_no);
if (!dfbSurface) {
- qWarning("QDirectFBPixmapData::fill()");
- setSerialNumber(0);
+ qWarning("QDirecttFBPixmapData::fill()");
+ invalidate();
return;
}
}
- dfbSurface->Clear(dfbSurface, color.red(), color.green(), color.blue(),
- color.alpha());
-}
-
-bool QDirectFBPixmapData::hasAlphaChannel() const
-{
- if (!serialNumber())
- return false;
-
- DFBSurfacePixelFormat format;
- dfbSurface->GetPixelFormat(dfbSurface, &format);
- switch (format) {
- case DSPF_ARGB1555:
- case DSPF_ARGB:
- case DSPF_LUT8:
- case DSPF_AiRGB:
- case DSPF_A1:
- case DSPF_ARGB2554:
- case DSPF_ARGB4444:
- case DSPF_AYUV:
- case DSPF_A4:
- case DSPF_ARGB1666:
- case DSPF_ARGB6666:
- case DSPF_LUT2:
- return true;
- default:
- return false;
+ if (forceRaster) {
+ // in DSPF_RGB32 all dfb drawing causes the Alpha byte to be
+ // set to 0. This causes issues for the raster engine.
+ char *mem;
+ int bpl;
+ const int h = QPixmapData::height();
+ dfbSurface->Lock(dfbSurface, DSLF_WRITE, (void**)&mem, &bpl);
+ const int c = color.rgba();
+ for (int i = 0; i < h; ++i) {
+ memset(mem, c, bpl);
+ mem += bpl;
+ }
+ dfbSurface->Unlock(dfbSurface);
+ } else {
+ dfbSurface->Clear(dfbSurface, color.red(), color.green(), color.blue(),
+ color.alpha());
}
}
@@ -274,14 +291,12 @@ QPixmap QDirectFBPixmapData::transformed(const QTransform &transform,
{
QDirectFBPixmapData *that = const_cast<QDirectFBPixmapData*>(this);
const QImage *image = that->buffer();
- if (image) { // avoid deep copy
- const QImage transformed = image->transformed(transform, mode);
- that->unlockDirectFB();
- QDirectFBPixmapData *data = new QDirectFBPixmapData(pixelType());
- data->fromImage(transformed, Qt::AutoColor);
- return QPixmap(data);
- }
- return QPixmapData::transformed(transform, mode);
+ Q_ASSERT(image);
+ const QImage transformed = image->transformed(transform, mode);
+ that->unlockDirectFB();
+ QDirectFBPixmapData *data = new QDirectFBPixmapData(QPixmapData::PixmapType);
+ data->fromImage(transformed, Qt::AutoColor);
+ return QPixmap(data);
}
int w, h;
@@ -291,15 +306,23 @@ QPixmap QDirectFBPixmapData::transformed(const QTransform &transform,
if (size.isEmpty())
return QPixmap();
- QDirectFBPixmapData *data = new QDirectFBPixmapData(pixelType());
- data->resize(size.width(), size.height());
-
- IDirectFBSurface *dest = data->dfbSurface;
- dest->SetBlittingFlags(dest, DSBLIT_NOFX);
+ QDirectFBPixmapData *data = new QDirectFBPixmapData(QPixmapData::PixmapType);
+ DFBSurfaceBlittingFlags flags = DSBLIT_NOFX;
+ data->alpha = alpha;
+ if (alpha) {
+ flags = DSBLIT_BLEND_ALPHACHANNEL;
+ }
+ data->dfbSurface = screen->createDFBSurface(size,
+ format,
+ QDirectFBScreen::TrackSurface);
+ if (flags & DSBLIT_BLEND_ALPHACHANNEL) {
+ data->dfbSurface->Clear(data->dfbSurface, 0, 0, 0, 0);
+ }
+ data->dfbSurface->SetBlittingFlags(data->dfbSurface, flags);
- const DFBRectangle srcRect = { 0, 0, w, h };
const DFBRectangle destRect = { 0, 0, size.width(), size.height() };
- dest->StretchBlit(dest, dfbSurface, &srcRect, &destRect);
+ data->dfbSurface->StretchBlit(data->dfbSurface, dfbSurface, 0, &destRect);
+ data->dfbSurface->ReleaseSource(data->dfbSurface);
return QPixmap(data);
}
@@ -309,39 +332,25 @@ QImage QDirectFBPixmapData::toImage() const
if (!dfbSurface)
return QImage();
-#ifdef QT_NO_DIRECTFB_PREALLOCATED
- QDirectFBPixmapData *that = const_cast<QDirectFBPixmapData*>(this);
- const QImage *img = that->buffer();
- const QImage copied = img->copy();
- that->unlockDirectFB();
- return copied;
-#else
-
- int w, h;
- dfbSurface->GetSize(dfbSurface, &w, &h);
-
- // Always convert to ARGB32:
- QImage image(w, h, QImage::Format_ARGB32);
-
- DFBSurfaceDescription description;
- description = QDirectFBScreen::getSurfaceDescription(image);
-
- IDirectFBSurface *imgSurface = screen->createDFBSurface(&description);
- if (!imgSurface) {
- qWarning("QDirectFBPixmapData::toImage()");
- return QImage();
- }
-
- imgSurface->SetBlittingFlags(imgSurface, DSBLIT_NOFX);
- DFBResult result = imgSurface->Blit(imgSurface, dfbSurface, 0, 0, 0);
- if (result != DFB_OK) {
- DirectFBError("QDirectFBPixmapData::toImage() blit failed", result);
- return QImage();
+#ifndef QT_NO_DIRECTFB_PREALLOCATED
+ QImage ret(size(), QDirectFBScreen::getImageFormat(dfbSurface));
+ if (IDirectFBSurface *imgSurface = screen->createDFBSurface(ret, QDirectFBScreen::DontTrackSurface)) {
+ if (hasAlphaChannel()) {
+ imgSurface->SetBlittingFlags(imgSurface, DSBLIT_BLEND_ALPHACHANNEL);
+ imgSurface->Clear(imgSurface, 0, 0, 0, 0);
+ } else {
+ imgSurface->SetBlittingFlags(imgSurface, DSBLIT_NOFX);
+ }
+ imgSurface->Blit(imgSurface, dfbSurface, 0, 0, 0);
+ imgSurface->ReleaseSource(imgSurface);
+ imgSurface->Release(imgSurface);
+ return ret;
}
- screen->releaseDFBSurface(imgSurface);
+#endif
- return image;
-#endif // QT_NO_DIRECTFB_PREALLOCATED
+ QDirectFBPixmapData *that = const_cast<QDirectFBPixmapData*>(this);
+ const QImage *img = that->buffer();
+ return img->copy();
}
QPaintEngine* QDirectFBPixmapData::paintEngine() const
@@ -361,3 +370,10 @@ QImage* QDirectFBPixmapData::buffer()
lockDirectFB();
return lockedImage;
}
+
+void QDirectFBPixmapData::invalidate()
+{
+ setSerialNumber(0);
+ alpha = false;
+ format = QImage::Format_Invalid;
+}
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.h b/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.h
index 32676f8..6cfafcd 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.h
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.h
@@ -64,7 +64,7 @@ public:
void fromImage(const QImage &image, Qt::ImageConversionFlags flags);
void copy(const QPixmapData *data, const QRect &rect);
void fill(const QColor &color);
- bool hasAlphaChannel() const;
+ inline bool hasAlphaChannel() const { return alpha; }
QPixmap transformed(const QTransform &matrix,
Qt::TransformationMode mode) const;
QImage toImage() const;
@@ -73,9 +73,12 @@ public:
// Pure virtual in QPixmapData, so re-implement here and delegate to QDirectFBPaintDevice
int metric(QPaintDevice::PaintDeviceMetric m) const {return QDirectFBPaintDevice::metric(m);}
-
+ inline QImage::Format pixelFormat() const { return format; }
private:
+ void invalidate();
QDirectFBPaintEngine *engine;
+ QImage::Format format;
+ bool alpha;
};
QT_END_HEADER
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp
index 3249e65..041d522 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp
@@ -81,13 +81,15 @@ public:
QDirectFBKeyboardHandler *keyboard;
#endif
bool videoonly;
+ QImage::Format alphaPixmapFormat;
};
QDirectFBScreenPrivate::QDirectFBScreenPrivate(QDirectFBScreen* screen)
- : QWSGraphicsSystem(screen), dfb(0), dfbSurface(0), flipFlags(DSFLIP_BLIT)
+ : QWSGraphicsSystem(screen), dfb(0), dfbSurface(0), flipFlags(DSFLIP_NONE)
#ifndef QT_NO_DIRECTFB_LAYER
, dfbLayer(0)
#endif
+ , dfbScreen(0)
#ifndef QT_NO_DIRECTFB_MOUSE
, mouse(0)
#endif
@@ -95,6 +97,7 @@ QDirectFBScreenPrivate::QDirectFBScreenPrivate(QDirectFBScreen* screen)
, keyboard(0)
#endif
, videoonly(false)
+ , alphaPixmapFormat(QImage::Format_Invalid)
{
#ifndef QT_NO_QWS_SIGNALHANDLER
QWSSignalHandler::instance()->addObject(this);
@@ -129,7 +132,88 @@ QDirectFBScreenPrivate::~QDirectFBScreenPrivate()
dfb->Release(dfb);
}
-IDirectFBSurface* QDirectFBScreen::createDFBSurface(const DFBSurfaceDescription* desc, bool track)
+
+
+// creates a preallocated surface with the same format as the image if
+// possible.
+
+IDirectFBSurface* QDirectFBScreen::createDFBSurface(const QImage &img, SurfaceCreationOptions options)
+{
+ if (img.isNull()) // assert?
+ return 0;
+ if (QDirectFBScreen::getSurfacePixelFormat(img.format()) == DSPF_UNKNOWN) {
+ QImage image = img.convertToFormat(img.hasAlphaChannel()
+ ? d_ptr->alphaPixmapFormat
+ : pixelFormat());
+ IDirectFBSurface *tmp = createDFBSurface(image, false);
+ if (!tmp) {
+ qWarning("Couldn't create surface createDFBSurface(QImage, bool)");
+ return 0;
+ }
+ IDirectFBSurface *surface = copyDFBSurface(tmp, image.format(), options);
+ tmp->Release(tmp);
+ return surface;
+ }
+
+ DFBSurfaceDescription desc = QDirectFBScreen::getSurfaceDescription(img);
+ IDirectFBSurface *surface = createDFBSurface(&desc, options);
+#ifdef QT_NO_DIRECTFB_PREALLOCATED
+ if (surface) {
+ char *mem;
+ int bpl;
+ surface->Lock(surface, DSLF_WRITE, (void**)&mem, &bpl);
+ const int h = img.height();
+ for (int i = 0; i < h; ++i) {
+ memcpy(mem, img.scanLine(i), bpl);
+ mem += bpl;
+ }
+ surface->Unlock(surface);
+ }
+#endif
+#ifndef QT_NO_DIRECTFB_PALETTE
+ if (img.numColors() != 0 && surface)
+ QDirectFBScreen::setSurfaceColorTable(surface, img);
+#endif
+ return surface;
+}
+
+IDirectFBSurface *QDirectFBScreen::copyDFBSurface(IDirectFBSurface *src,
+ QImage::Format format,
+ SurfaceCreationOptions options)
+{
+ Q_ASSERT(src);
+ QSize size;
+ src->GetSize(src, &size.rwidth(), &size.rheight());
+ IDirectFBSurface *surface = createDFBSurface(size, format, options);
+ DFBSurfacePixelFormat dspf;
+ src->GetPixelFormat(src, &dspf);
+ DFBSurfaceBlittingFlags flags = QDirectFBScreen::hasAlpha(dspf)
+ ? DSBLIT_BLEND_ALPHACHANNEL
+ : DSBLIT_NOFX;
+ if (flags & DSBLIT_BLEND_ALPHACHANNEL)
+ surface->Clear(surface, 0, 0, 0, 0);
+
+ surface->SetBlittingFlags(surface, flags);
+ surface->Blit(surface, src, 0, 0, 0);
+ surface->ReleaseSource(surface);
+ return surface;
+}
+
+IDirectFBSurface *QDirectFBScreen::createDFBSurface(const QSize &size,
+ QImage::Format format,
+ SurfaceCreationOptions options)
+{
+ DFBSurfaceDescription desc;
+ desc.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH|DSDESC_HEIGHT);
+ if (!QDirectFBScreen::initSurfaceDescriptionPixelFormat(&desc, format))
+ return 0;
+ desc.width = size.width();
+ desc.height = size.height();
+ return createDFBSurface(&desc, options);
+}
+
+
+IDirectFBSurface* QDirectFBScreen::createDFBSurface(const DFBSurfaceDescription *desc, SurfaceCreationOptions options)
{
DFBResult result;
IDirectFBSurface* newSurface = 0;
@@ -142,22 +226,43 @@ IDirectFBSurface* QDirectFBScreen::createDFBSurface(const DFBSurfaceDescription*
if (d_ptr->videoonly && !(desc->flags & DSDESC_PREALLOCATED)) {
// Add the video only capability. This means the surface will be created in video ram
DFBSurfaceDescription voDesc = *desc;
- voDesc.caps = DFBSurfaceCapabilities(voDesc.caps | DSCAPS_VIDEOONLY);
- voDesc.flags = DFBSurfaceDescriptionFlags(voDesc.flags | DSDESC_CAPS);
+ if (!(voDesc.flags & DSDESC_CAPS)) {
+ voDesc.caps = DSCAPS_VIDEOONLY;
+ voDesc.flags = DFBSurfaceDescriptionFlags(voDesc.flags | DSDESC_CAPS);
+ } else {
+ voDesc.caps = DFBSurfaceCapabilities(voDesc.caps | DSCAPS_VIDEOONLY);
+ }
result = d_ptr->dfb->CreateSurface(d_ptr->dfb, &voDesc, &newSurface);
+ if (result != DFB_OK
+#ifdef QT_NO_DEBUG
+ && (desc->flags & DSDESC_CAPS) && (desc->caps & DSCAPS_PRIMARY)
+#endif
+ ) {
+ qWarning("QDirectFBScreen::createDFBSurface() Failed to create surface in video memory!\n"
+ " Flags %0x Caps %0x width %d height %d pixelformat %0x %d preallocated %p %d\n%s",
+ desc->flags, desc->caps, desc->width, desc->height,
+ desc->pixelformat, DFB_PIXELFORMAT_INDEX(desc->pixelformat),
+ desc->preallocated[0].data, desc->preallocated[0].pitch,
+ DirectFBErrorString(result));
+ }
}
if (!newSurface)
result = d_ptr->dfb->CreateSurface(d_ptr->dfb, desc, &newSurface);
if (result != DFB_OK) {
- DirectFBError("QDirectFBScreen::createDFBSurface", result);
+ qWarning("QDirectFBScreen::createDFBSurface() Failed!\n"
+ " Flags %0x Caps %0x width %d height %d pixelformat %0x %d preallocated %p %d\n%s",
+ desc->flags, desc->caps, desc->width, desc->height,
+ desc->pixelformat, DFB_PIXELFORMAT_INDEX(desc->pixelformat),
+ desc->preallocated[0].data, desc->preallocated[0].pitch,
+ DirectFBErrorString(result));
return 0;
}
Q_ASSERT(newSurface);
- if (track) {
+ if (options & TrackSurface) {
d_ptr->allocatedSurfaces.insert(newSurface);
//qDebug("Created a new DirectFB surface at %p. New count = %d",
@@ -167,8 +272,67 @@ IDirectFBSurface* QDirectFBScreen::createDFBSurface(const DFBSurfaceDescription*
return newSurface;
}
-void QDirectFBScreen::releaseDFBSurface(IDirectFBSurface* surface)
+IDirectFBSurface *QDirectFBScreen::copyToDFBSurface(const QImage &img,
+ QImage::Format pixmapFormat,
+ SurfaceCreationOptions options)
+{
+ QImage image = img;
+ if (QDirectFBScreen::getSurfacePixelFormat(image.format()) == DSPF_UNKNOWN
+#ifdef QT_NO_DIRECTFB_PREALLOCATED
+ || image.format() != pixmapFormat
+#endif
+#ifdef QT_NO_DIRECTFB_PALETTE
+ || image.numColors() != 0
+#endif
+ ) {
+ image = image.convertToFormat(pixmapFormat);
+ }
+
+ IDirectFBSurface *dfbSurface = createDFBSurface(image.size(), pixmapFormat, options);
+ if (!dfbSurface) {
+ qWarning("QDirectFBPixmapData::fromImage() Couldn't create surface");
+ return 0;
+ }
+
+#ifndef QT_NO_DIRECTFB_PREALLOCATED
+ IDirectFBSurface *imgSurface = createDFBSurface(image, DontTrackSurface);
+ if (!imgSurface) {
+ qWarning("QDirectFBPixmapData::fromImage()");
+ QDirectFBScreen::releaseDFBSurface(dfbSurface);
+ return 0;
+ }
+
+ Q_ASSERT(imgSurface);
+ DFBSurfaceBlittingFlags flags = img.hasAlphaChannel()
+ ? DSBLIT_BLEND_ALPHACHANNEL
+ : DSBLIT_NOFX;
+ if (flags & DSBLIT_BLEND_ALPHACHANNEL)
+ dfbSurface->Clear(dfbSurface, 0, 0, 0, 0);
+
+ dfbSurface->SetBlittingFlags(dfbSurface, flags);
+ DFBResult result = dfbSurface->Blit(dfbSurface, imgSurface, 0, 0, 0);
+ if (result != DFB_OK)
+ DirectFBError("QDirectFBPixmapData::fromImage()", result);
+ dfbSurface->ReleaseSource(dfbSurface);
+ imgSurface->Release(imgSurface);
+#else // QT_NO_DIRECTFB_PREALLOCATED
+ Q_ASSERT(image.format() == pixmapFormat);
+ char *mem;
+ int bpl;
+ dfbSurface->Lock(dfbSurface, DSLF_WRITE, (void**)&mem, &bpl);
+ const int w = image.width() * image.depth() / 8;
+ for (int i = 0; i < image.height(); ++i) {
+ memcpy(mem, image.scanLine(i), w);
+ mem += bpl;
+ }
+ dfbSurface->Unlock(dfbSurface);
+#endif
+ return dfbSurface;
+}
+
+void QDirectFBScreen::releaseDFBSurface(IDirectFBSurface *surface)
{
+ Q_ASSERT(QDirectFBScreen::instance());
Q_ASSERT(surface);
surface->Release(surface);
if (!d_ptr->allocatedSurfaces.remove(surface))
@@ -199,9 +363,9 @@ IDirectFBDisplayLayer* QDirectFBScreen::dfbDisplayLayer()
}
#endif
-DFBSurfacePixelFormat QDirectFBScreen::getSurfacePixelFormat(const QImage &image)
+DFBSurfacePixelFormat QDirectFBScreen::getSurfacePixelFormat(QImage::Format format)
{
- switch (image.format()) {
+ switch (format) {
#ifndef QT_NO_DIRECTFB_PALETTE
case QImage::Format_Indexed8:
return DSPF_LUT8;
@@ -232,8 +396,11 @@ DFBSurfacePixelFormat QDirectFBScreen::getSurfacePixelFormat(const QImage &image
};
}
-QImage::Format QDirectFBScreen::getImageFormat(DFBSurfacePixelFormat format)
+QImage::Format QDirectFBScreen::getImageFormat(IDirectFBSurface *surface)
{
+ DFBSurfacePixelFormat format;
+ surface->GetPixelFormat(surface, &format);
+
switch (format) {
case DSPF_LUT8:
return QImage::Format_Indexed8;
@@ -256,8 +423,14 @@ QImage::Format QDirectFBScreen::getImageFormat(DFBSurfacePixelFormat format)
return QImage::Format_RGB666;
case DSPF_RGB32:
return QImage::Format_RGB32;
- case DSPF_ARGB:
- return QImage::Format_ARGB32_Premultiplied;
+ case DSPF_ARGB: {
+ DFBSurfaceCapabilities caps;
+ const DFBResult result = surface->GetCapabilities(surface, &caps);
+ Q_ASSERT(result == DFB_OK);
+ Q_UNUSED(result);
+ return (caps & DSCAPS_PREMULTIPLIED
+ ? QImage::Format_ARGB32_Premultiplied
+ : QImage::Format_ARGB32); }
default:
break;
}
@@ -267,38 +440,32 @@ QImage::Format QDirectFBScreen::getImageFormat(DFBSurfacePixelFormat format)
DFBSurfaceDescription QDirectFBScreen::getSurfaceDescription(const QImage &image)
{
DFBSurfaceDescription description;
- DFBSurfacePixelFormat format = getSurfacePixelFormat(image);
+
+ const DFBSurfacePixelFormat format = getSurfacePixelFormat(image.format());
if (format == DSPF_UNKNOWN || image.isNull()) {
description.flags = DFBSurfaceDescriptionFlags(0);
return description;
}
- description.flags = DFBSurfaceDescriptionFlags(DSDESC_CAPS
- | DSDESC_WIDTH
+ description.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH
| DSDESC_HEIGHT
- | DSDESC_PIXELFORMAT
- | DSDESC_PREALLOCATED);
-
- description.caps = DSCAPS_NONE;
+#ifndef QT_NO_DIRECTFB_PREALLOCATED
+ | DSDESC_PREALLOCATED
+#endif
+ | DSDESC_PIXELFORMAT);
+ QDirectFBScreen::initSurfaceDescriptionPixelFormat(&description, image.format());
description.width = image.width();
description.height = image.height();
- description.pixelformat = format;
+#ifndef QT_NO_DIRECTFB_PREALLOCATED
description.preallocated[0].data = (void*)(image.bits());
description.preallocated[0].pitch = image.bytesPerLine();
description.preallocated[1].data = 0;
description.preallocated[1].pitch = 0;
+#endif
- switch (image.format()) {
- case QImage::Format_ARGB32_Premultiplied:
- case QImage::Format_ARGB8565_Premultiplied:
- case QImage::Format_ARGB6666_Premultiplied:
- case QImage::Format_ARGB8555_Premultiplied:
- case QImage::Format_ARGB4444_Premultiplied:
+ if (QDirectFBScreen::isPremultiplied(image.format()))
description.caps = DSCAPS_PREMULTIPLIED;
- default:
- break;
- }
return description;
}
@@ -336,7 +503,7 @@ void QDirectFBScreen::setSurfaceColorTable(IDirectFBSurface *surface,
if (numColors == 0)
return;
- QVarLengthArray<DFBColor> colors(numColors);
+ QVarLengthArray<DFBColor, 256> colors(numColors);
for (int i = 0; i < numColors; ++i) {
QRgb c = image.color(i);
colors[i].a = qAlpha(c);
@@ -361,50 +528,6 @@ void QDirectFBScreen::setSurfaceColorTable(IDirectFBSurface *surface,
palette->Release(palette);
}
-void QDirectFBScreen::setImageColorTable(QImage *image, IDirectFBSurface *surface)
-{
- if (!image || !surface || image->depth() > 8)
- return;
-
- IDirectFBPalette *palette = 0;
- unsigned int numColors = 0;
- DFBResult result;
- do {
- result = surface->GetPalette(surface, &palette);
- if (result != DFB_OK) {
- DirectFBError("QDirectFBScreen::setImageColorTable GetPalette", result);
- break;
- }
-
- result = palette->GetSize(palette, &numColors);
- if (result != DFB_OK) {
- DirectFBError("QDirectFBScreen::setImageColorTable GetPalette", result);
- break;
- }
-
- if (numColors == 0)
- break;
-
- QVarLengthArray<DFBColor> dfbColors(numColors);
- result = palette->GetEntries(palette, dfbColors.data(), numColors, 0);
- if (result != DFB_OK) {
- DirectFBError("QDirectFBScreen::setImageColorTable GetPalette", result);
- break;
- }
-
- QVector<QRgb> qtColors(numColors);
- for (unsigned int i=0; i<numColors; ++i) {
- const DFBColor &col = dfbColors[i];
- qtColors[i] = qRgba(col.r, col.g, col.b, col.a);
- }
- image->setColorTable(qtColors);
-
- } while (0);
-
- if (palette)
- palette->Release(palette);
-}
-
#endif // QT_NO_DIRECTFB_PALETTE
#if !defined(QT_NO_DIRECTFB_LAYER) && !defined(QT_NO_QWS_CURSOR)
@@ -504,52 +627,43 @@ void QDirectFBScreenCursor::set(const QImage &image, int hotx, int hoty)
} else if (!image.isNull() && implicitHide) {
show();
}
+ cursor = image.convertToFormat(QDirectFBScreen::instance()->alphaPixmapFormat());
+
+ if (!image.isNull()) {
+ Q_ASSERT(cursor.numColors() == 0);
+ size = cursor.size();
+ hotspot = QPoint(hotx, hoty);
+
+ DFBSurfaceDescription description;
+ description = QDirectFBScreen::getSurfaceDescription(cursor);
+
+ IDirectFBSurface *surface;
+ surface = QDirectFBScreen::instance()->createDFBSurface(&description,
+ QDirectFBScreen::TrackSurface);
+ if (!surface) {
+ qWarning("QDirectFBScreenCursor::set: Unable to create surface");
+ return;
+ }
+ DFBResult result = layer->SetCooperativeLevel(layer, DLSCL_ADMINISTRATIVE);
+ if (result != DFB_OK) {
+ DirectFBError("QDirectFBScreenCursor::set: "
+ "Unable to set cooperative level", result);
+ }
+ result = layer->SetCursorShape(layer, surface, hotx, hoty);
+ if (result != DFB_OK) {
+ DirectFBError("QDirectFBScreenCursor::set: Unable to set cursor shape",
+ result);
+ }
-#ifdef QT_NO_DIRECTFB_PALETTE
- if (image.numColors() > 0)
- cursor = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
- else
-#endif
- if (image.format() == QImage::Format_Indexed8) {
- cursor = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
- } else {
- cursor = image;
- }
- size = cursor.size();
- hotspot = QPoint(hotx, hoty);
-
- DFBSurfaceDescription description;
- description = QDirectFBScreen::getSurfaceDescription(cursor);
-
- IDirectFBSurface *surface;
- surface = QDirectFBScreen::instance()->createDFBSurface(&description);
- if (!surface) {
- qWarning("QDirectFBScreenCursor::set: Unable to create surface");
- return;
- }
-#ifndef QT_NO_DIRECTFB_PALETTE
- QDirectFBScreen::setSurfaceColorTable(surface, cursor);
-#endif
-
- DFBResult result = layer->SetCooperativeLevel(layer, DLSCL_ADMINISTRATIVE);
- if (result != DFB_OK) {
- DirectFBError("QDirectFBScreenCursor::set: "
- "Unable to set cooperative level", result);
- }
- result = layer->SetCursorShape(layer, surface, hotx, hoty);
- if (result != DFB_OK) {
- DirectFBError("QDirectFBScreenCursor::set: Unable to set cursor shape",
- result);
- }
+ result = layer->SetCooperativeLevel(layer, DLSCL_SHARED);
+ if (result != DFB_OK) {
+ DirectFBError("QDirectFBScreenCursor::set: "
+ "Unable to reset cooperative level", result);
+ }
- result = layer->SetCooperativeLevel(layer, DLSCL_SHARED);
- if (result != DFB_OK) {
- DirectFBError("QDirectFBScreenCursor::set: "
- "Unable to reset cooperative level", result);
+ if (surface)
+ QDirectFBScreen::instance()->releaseDFBSurface(surface);
}
-
- if (surface)
- QDirectFBScreen::instance()->releaseDFBSurface(surface);
}
#endif // QT_NO_DIRECTFB_LAYER
@@ -608,7 +722,7 @@ int QDirectFBScreen::depth(DFBSurfacePixelFormat format)
void QDirectFBScreenPrivate::setFlipFlags(const QStringList &args)
{
- QRegExp flipRegexp(QLatin1String("^flip=([\\w,]+)$"));
+ QRegExp flipRegexp(QLatin1String("^flip=([\\w,]*)$"));
int index = args.indexOf(flipRegexp);
if (index >= 0) {
const QStringList flips = flipRegexp.cap(1).split(QLatin1Char(','),
@@ -627,6 +741,8 @@ void QDirectFBScreenPrivate::setFlipFlags(const QStringList &args)
qWarning("QDirectFBScreen: Unknown flip argument: %s",
qPrintable(flip));
}
+ } else {
+ flipFlags = DFBSurfaceFlipFlags(DSFLIP_BLIT);
}
}
@@ -656,6 +772,18 @@ static void printDirectFBInfo(IDirectFB *fb)
dev.blitting_flags, dev.drawing_flags, dev.video_memory);
}
+static inline bool setIntOption(const QStringList &arguments, const QString &variable, int *value)
+{
+ Q_ASSERT(value);
+ QRegExp rx(QString("%1=?(\\d+)").arg(variable));
+ rx.setCaseSensitivity(Qt::CaseInsensitive);
+ if (arguments.indexOf(rx) != -1) {
+ *value = rx.cap(1).toInt();
+ return true;
+ }
+ return false;
+}
+
bool QDirectFBScreen::connect(const QString &displaySpec)
{
DFBResult result = DFB_OK;
@@ -677,7 +805,7 @@ bool QDirectFBScreen::connect(const QString &displaySpec)
}
const QStringList displayArgs = displaySpec.split(QLatin1Char(':'),
- QString::SkipEmptyParts);
+ QString::SkipEmptyParts);
d_ptr->setFlipFlags(displayArgs);
@@ -701,23 +829,57 @@ bool QDirectFBScreen::connect(const QString &displaySpec)
DFBSurfaceDescription description;
description.flags = DFBSurfaceDescriptionFlags(DSDESC_CAPS);
+ if (::setIntOption(displayArgs, QLatin1String("width"), &description.width))
+ description.flags = DFBSurfaceDescriptionFlags(description.flags | DSDESC_WIDTH);
+ if (::setIntOption(displayArgs, QLatin1String("height"), &description.height))
+ description.flags = DFBSurfaceDescriptionFlags(description.flags | DSDESC_HEIGHT);
description.caps = DFBSurfaceCapabilities(DSCAPS_PRIMARY
| DSCAPS_DOUBLE
| DSCAPS_STATIC_ALLOC);
- if (!(d_ptr->flipFlags & DSFLIP_BLIT)) {
+ if (displayArgs.contains(QLatin1String("forcepremultiplied"),
+ Qt::CaseInsensitive)) {
description.caps = DFBSurfaceCapabilities(description.caps
- | DSCAPS_DOUBLE
- | DSCAPS_TRIPLE);
+ | DSCAPS_PREMULTIPLIED);
}
-
// We don't track the primary surface as it's released in disconnect
- d_ptr->dfbSurface = createDFBSurface(&description, false);
+ d_ptr->dfbSurface = createDFBSurface(&description, DontTrackSurface);
if (!d_ptr->dfbSurface) {
DirectFBError("QDirectFBScreen: error creating primary surface",
result);
return false;
}
+
+ // Work out what format we're going to use for surfaces with an alpha channel
+ d_ptr->alphaPixmapFormat = QDirectFBScreen::getImageFormat(d_ptr->dfbSurface);
+ setPixelFormat(d_ptr->alphaPixmapFormat);
+ switch (d_ptr->alphaPixmapFormat) {
+ case QImage::Format_RGB666:
+ d_ptr->alphaPixmapFormat = QImage::Format_ARGB6666_Premultiplied;
+ break;
+ case QImage::Format_RGB444:
+ d_ptr->alphaPixmapFormat = QImage::Format_ARGB4444_Premultiplied;
+ break;
+ case QImage::NImageFormats:
+ case QImage::Format_Invalid:
+ case QImage::Format_Mono:
+ case QImage::Format_MonoLSB:
+ case QImage::Format_Indexed8:
+ case QImage::Format_RGB32:
+ case QImage::Format_RGB888:
+ case QImage::Format_RGB16:
+ case QImage::Format_RGB555:
+ d_ptr->alphaPixmapFormat = QImage::Format_ARGB32_Premultiplied;
+ break;
+ case QImage::Format_ARGB32:
+ case QImage::Format_ARGB32_Premultiplied:
+ case QImage::Format_ARGB4444_Premultiplied:
+ case QImage::Format_ARGB8555_Premultiplied:
+ case QImage::Format_ARGB8565_Premultiplied:
+ case QImage::Format_ARGB6666_Premultiplied:
+ // works already
+ break;
+ }
d_ptr->dfbSurface->GetSize(d_ptr->dfbSurface, &w, &h);
data = 0;
@@ -733,21 +895,11 @@ bool QDirectFBScreen::connect(const QString &displaySpec)
else
DirectFBError("QDirectFBScreen: error getting surface format", result);
- setPixelFormat(getImageFormat(format));
+ setPixelFormat(getImageFormat(d_ptr->dfbSurface));
physWidth = physHeight = -1;
- QRegExp mmWidthRx(QLatin1String("mmWidth=?(\\d+)"));
- int dimIdxW = displayArgs.indexOf(mmWidthRx);
- if (dimIdxW >= 0) {
- mmWidthRx.exactMatch(displayArgs.at(dimIdxW));
- physWidth = mmWidthRx.cap(1).toInt();
- }
- QRegExp mmHeightRx(QLatin1String("mmHeight=?(\\d+)"));
- int dimIdxH = displayArgs.indexOf(mmHeightRx);
- if (dimIdxH >= 0) {
- mmHeightRx.exactMatch(displayArgs.at(dimIdxH));
- physHeight = mmHeightRx.cap(1).toInt();
- }
+ ::setIntOption(displayArgs, QLatin1String("mmWidth"), &physWidth);
+ ::setIntOption(displayArgs, QLatin1String("mmHeight"), &physHeight);
const int dpi = 72;
if (physWidth < 0)
physWidth = qRound(dw * 25.4 / dpi);
@@ -855,19 +1007,21 @@ void QDirectFBScreen::blank(bool on)
QWSWindowSurface* QDirectFBScreen::createSurface(QWidget *widget) const
{
#ifdef QT_NO_DIRECTFB_WM
- if (QApplication::type() == QApplication::GuiServer)
- return new QDirectFBSurface(const_cast<QDirectFBScreen*>(this), widget);
- else
+ if (QApplication::type() == QApplication::GuiServer) {
+ return new QDirectFBSurface(d_ptr->flipFlags, const_cast<QDirectFBScreen*>(this), widget);
+ } else {
return QScreen::createSurface(widget);
+ }
#else
- return new QDirectFBSurface(const_cast<QDirectFBScreen*>(this), widget);
+ return new QDirectFBSurface(d_ptr->flipFlags, const_cast<QDirectFBScreen*>(this), widget);
#endif
}
QWSWindowSurface* QDirectFBScreen::createSurface(const QString &key) const
{
- if (key == QLatin1String("directfb"))
- return new QDirectFBSurface(const_cast<QDirectFBScreen*>(this));
+ if (key == QLatin1String("directfb")) {
+ return new QDirectFBSurface(d_ptr->flipFlags, const_cast<QDirectFBScreen*>(this));
+ }
return QScreen::createSurface(key);
}
@@ -900,7 +1054,7 @@ void QDirectFBScreen::compose(const QRegion &region)
if (surface->key() == QLatin1String("directfb")) {
QDirectFBSurface *s = static_cast<QDirectFBSurface*>(surface);
- blit(s->directFbSurface(), offset, r);
+ blit(s->directFBSurface(), offset, r);
} else {
blit(surface->image(), offset, r);
}
@@ -949,11 +1103,12 @@ void QDirectFBScreen::compose(const QRegion &region)
if (surface->key() == QLatin1String("directfb")) {
QDirectFBSurface *s = static_cast<QDirectFBSurface*>(surface);
- blit(s->directFbSurface(), offset, r);
+ blit(s->directFBSurface(), offset, r);
} else {
blit(surface->image(), offset, r);
}
}
+ d_ptr->dfbSurface->ReleaseSource(d_ptr->dfbSurface);
}
// Normally, when using DirectFB to compose the windows (I.e. when
@@ -995,21 +1150,14 @@ void QDirectFBScreen::exposeRegion(QRegion r, int changing)
void QDirectFBScreen::blit(const QImage &img, const QPoint &topLeft,
const QRegion &reg)
{
- IDirectFBSurface *src = 0;
- DFBSurfaceDescription description = getSurfaceDescription(img);
-
- src = createDFBSurface(&description);
+ IDirectFBSurface *src = createDFBSurface(img, QDirectFBScreen::DontTrackSurface);
if (!src) {
qWarning("QDirectFBScreen::blit(): Error creating surface");
return;
}
-#ifndef QT_NO_DIRECTFB_PALETTE
- setSurfaceColorTable(d_ptr->dfbSurface, img);
-#endif
-
blit(src, topLeft, reg);
-
- releaseDFBSurface(src);
+ d_ptr->dfbSurface->ReleaseSource(d_ptr->dfbSurface);
+ src->Release(src);
}
void QDirectFBScreen::blit(IDirectFBSurface *src, const QPoint &topLeft,
@@ -1045,20 +1193,51 @@ void QDirectFBScreen::solidFill(const QColor &color, const QRegion &region)
if (region.isEmpty())
return;
- const QVector<QRect> rects = region.rects();
- QVarLengthArray<DFBRectangle> dfbRects(rects.size());
- for (int i = 0; i < rects.size(); ++i) {
- const QRect r = rects.at(i);
- dfbRects[i].x = r.x();
- dfbRects[i].y = r.y();
- dfbRects[i].w = r.width();
- dfbRects[i].h = r.height();
+ if (QDirectFBScreen::getImageFormat(d_ptr->dfbSurface) == QImage::Format_RGB32) {
+ uchar *mem;
+ int bpl;
+ d_ptr->dfbSurface->Lock(d_ptr->dfbSurface, DSLF_WRITE, (void**)&mem, &bpl);
+ QImage img(mem, w, h, bpl, QImage::Format_RGB32);
+ QPainter p(&img);
+ p.setBrush(color);
+ p.setPen(Qt::NoPen);
+ const QVector<QRect> rects = region.rects();
+ p.drawRects(rects.constData(), rects.size());
+ p.end();
+ d_ptr->dfbSurface->Unlock(d_ptr->dfbSurface);
+ } else {
+ d_ptr->dfbSurface->SetColor(d_ptr->dfbSurface,
+ color.red(), color.green(), color.blue(),
+ color.alpha());
+ const QVector<QRect> rects = region.rects();
+ for (int i=0; i<rects.size(); ++i) {
+ const QRect &r = rects.at(i);
+ d_ptr->dfbSurface->FillRectangle(d_ptr->dfbSurface,
+ r.x(), r.y(), r.width(), r.height());
+ }
}
+}
- d_ptr->dfbSurface->SetColor(d_ptr->dfbSurface,
- color.red(), color.green(), color.blue(),
- color.alpha());
- d_ptr->dfbSurface->FillRectangles(d_ptr->dfbSurface, dfbRects.data(),
- dfbRects.size());
+QImage::Format QDirectFBScreen::alphaPixmapFormat() const
+{
+ return d_ptr->alphaPixmapFormat;
}
+bool QDirectFBScreen::initSurfaceDescriptionPixelFormat(DFBSurfaceDescription *description,
+ QImage::Format format)
+{
+ const DFBSurfacePixelFormat pixelformat = QDirectFBScreen::getSurfacePixelFormat(format);
+ if (pixelformat == DSPF_UNKNOWN)
+ return false;
+ description->flags = DFBSurfaceDescriptionFlags(description->flags | DSDESC_PIXELFORMAT);
+ description->pixelformat = pixelformat;
+ if (QDirectFBScreen::isPremultiplied(format)) {
+ if (!(description->flags & DSDESC_CAPS)) {
+ description->caps = DSCAPS_PREMULTIPLIED;
+ description->flags = DFBSurfaceDescriptionFlags(description->flags | DSDESC_CAPS);
+ } else {
+ description->caps = DFBSurfaceCapabilities(description->caps | DSCAPS_PREMULTIPLIED);
+ }
+ }
+ return true;
+}
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h
index e9a2f63..f394ac1 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h
@@ -88,23 +88,43 @@ public:
#endif
// Track surface creation/release so we can release all on exit
- IDirectFBSurface* createDFBSurface(const DFBSurfaceDescription* desc, bool track = true);
+ enum SurfaceCreationOption {
+ DontTrackSurface = 0,
+ TrackSurface = 1
+ };
+ Q_DECLARE_FLAGS(SurfaceCreationOptions, SurfaceCreationOption);
+ IDirectFBSurface *createDFBSurface(const DFBSurfaceDescription *desc,
+ SurfaceCreationOptions options);
+ IDirectFBSurface *createDFBSurface(const QImage &image,
+ SurfaceCreationOptions options);
+ IDirectFBSurface *createDFBSurface(const QSize &size,
+ QImage::Format format,
+ SurfaceCreationOptions options);
+ IDirectFBSurface *copyDFBSurface(IDirectFBSurface *src,
+ QImage::Format format,
+ SurfaceCreationOptions options);
+ IDirectFBSurface *copyToDFBSurface(const QImage &image,
+ QImage::Format format,
+ SurfaceCreationOptions options);
void releaseDFBSurface(IDirectFBSurface* surface);
+
bool preferVideoOnly() const;
static int depth(DFBSurfacePixelFormat format);
- static DFBSurfacePixelFormat getSurfacePixelFormat(const QImage &image);
+ static DFBSurfacePixelFormat getSurfacePixelFormat(QImage::Format format);
static DFBSurfaceDescription getSurfaceDescription(const QImage &image);
static DFBSurfaceDescription getSurfaceDescription(const uint *buffer,
int length);
- static QImage::Format getImageFormat(DFBSurfacePixelFormat format);
+ static QImage::Format getImageFormat(IDirectFBSurface *surface);
+ static bool initSurfaceDescriptionPixelFormat(DFBSurfaceDescription *description, QImage::Format format);
static inline bool isPremultiplied(QImage::Format format);
+ static inline bool hasAlpha(DFBSurfacePixelFormat format);
+ QImage::Format alphaPixmapFormat() const;
#ifndef QT_NO_DIRECTFB_PALETTE
static void setSurfaceColorTable(IDirectFBSurface *surface,
const QImage &image);
- static void setImageColorTable(QImage *image, IDirectFBSurface *surface);
#endif
private:
@@ -115,6 +135,8 @@ private:
QDirectFBScreenPrivate *d_ptr;
};
+Q_DECLARE_OPERATORS_FOR_FLAGS(QDirectFBScreen::SurfaceCreationOptions);
+
inline bool QDirectFBScreen::isPremultiplied(QImage::Format format)
{
switch (format) {
@@ -130,6 +152,26 @@ inline bool QDirectFBScreen::isPremultiplied(QImage::Format format)
return false;
}
+inline bool QDirectFBScreen::hasAlpha(DFBSurfacePixelFormat format)
+{
+ switch (format) {
+ case DSPF_ARGB1555:
+ case DSPF_ARGB:
+ case DSPF_LUT8:
+ case DSPF_AiRGB:
+ case DSPF_A1:
+ case DSPF_ARGB2554:
+ case DSPF_ARGB4444:
+ case DSPF_AYUV:
+ case DSPF_A4:
+ case DSPF_ARGB1666:
+ case DSPF_ARGB6666:
+ case DSPF_LUT2:
+ return true;
+ default:
+ return false;
+ }
+}
QT_END_HEADER
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbsurface.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbsurface.cpp
index ab1d0f1..8ed308c 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbsurface.cpp
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbsurface.cpp
@@ -50,28 +50,38 @@
//#define QT_DIRECTFB_DEBUG_SURFACES 1
-QDirectFBSurface::QDirectFBSurface(QDirectFBScreen* scr)
+QDirectFBSurface::QDirectFBSurface(DFBSurfaceFlipFlags flip, QDirectFBScreen* scr)
: QDirectFBPaintDevice(scr)
#ifndef QT_NO_DIRECTFB_WM
, dfbWindow(0)
#endif
, engine(0)
+ , flipFlags(flip)
{
setSurfaceFlags(Opaque | Buffered);
+#ifdef QT_DIRECTFB_TIMING
+ frames = 0;
+ timer.start();
+#endif
}
-QDirectFBSurface::QDirectFBSurface(QDirectFBScreen* scr, QWidget *widget)
+QDirectFBSurface::QDirectFBSurface(DFBSurfaceFlipFlags flip, QDirectFBScreen *scr, QWidget *widget)
: QWSWindowSurface(widget), QDirectFBPaintDevice(scr)
#ifndef QT_NO_DIRECTFB_WM
, dfbWindow(0)
#endif
, engine(0)
+ , flipFlags(flip)
{
onscreen = widget->testAttribute(Qt::WA_PaintOnScreen);
if (onscreen)
setSurfaceFlags(Opaque | RegionReserved);
else
setSurfaceFlags(Opaque | Buffered);
+#ifdef QT_DIRECTFB_TIMING
+ frames = 0;
+ timer.start();
+#endif
}
QDirectFBSurface::~QDirectFBSurface()
@@ -86,14 +96,26 @@ bool QDirectFBSurface::isValid() const
#ifndef QT_NO_DIRECTFB_WM
void QDirectFBSurface::createWindow()
{
+#ifdef QT_NO_DIRECTFB_LAYER
+#warning QT_NO_DIRECTFB_LAYER requires QT_NO_DIRECTFB_WM
+#else
IDirectFBDisplayLayer *layer = screen->dfbDisplayLayer();
if (!layer)
qFatal("QDirectFBWindowSurface: Unable to get primary display layer!");
- DFBWindowDescription description;
- description.caps = DFBWindowCapabilities(DWCAPS_NODECORATION |
- DWCAPS_ALPHACHANNEL);
- description.flags = DWDESC_CAPS;
+ DFBWindowDescription description;
+ description.caps = DFBWindowCapabilities(DWCAPS_NODECORATION);
+ description.flags = DFBWindowDescriptionFlags(DWDESC_CAPS
+ |DWDESC_SURFACE_CAPS
+ |DWDESC_PIXELFORMAT);
+
+ description.surface_caps = DSCAPS_NONE;
+ if (screen->preferVideoOnly())
+ description.surface_caps = DFBSurfaceCapabilities(description.surface_caps|DSCAPS_VIDEOONLY);
+ const QImage::Format format = screen->pixelFormat();
+ description.pixelformat = QDirectFBScreen::getSurfacePixelFormat(format);
+ if (QDirectFBScreen::isPremultiplied(format))
+ description.surface_caps = DFBSurfaceCapabilities(DSCAPS_PREMULTIPLIED|description.caps);
DFBResult result = layer->CreateWindow(layer, &description, &dfbWindow);
if (result != DFB_OK)
@@ -103,6 +125,8 @@ void QDirectFBSurface::createWindow()
dfbSurface->Release(dfbSurface);
dfbWindow->GetSurface(dfbWindow, &dfbSurface);
+ forceRaster = (format == QImage::Format_RGB32);
+#endif
}
#endif // QT_NO_DIRECTFB_WM
@@ -115,26 +139,32 @@ void QDirectFBSurface::setGeometry(const QRect &rect, const QRegion &mask)
dfbWindow = 0;
}
#endif
- if (dfbSurface) {
+ if (dfbSurface && dfbSurface != screen->dfbSurface()) {
dfbSurface->Release(dfbSurface);
dfbSurface = 0;
}
} else if (rect != geometry()) {
- const bool isResize = rect.size() != geometry().size();
DFBResult result = DFB_OK;
// If we're in a resize, the surface shouldn't be locked
- Q_ASSERT( (lockedImage == 0) || (isResize == false));
+ Q_ASSERT((lockedImage == 0) || (rect.size() == geometry().size()));
- IDirectFBSurface *s = screen->dfbSurface();
- if (onscreen && s) {
- if (dfbSurface)
+ if (onscreen) {
+ IDirectFBSurface *primarySurface = screen->dfbSurface();
+ Q_ASSERT(primarySurface);
+ if (dfbSurface && dfbSurface != primarySurface)
dfbSurface->Release(dfbSurface);
- DFBRectangle r = { rect.x(), rect.y(),
- rect.width(), rect.height() };
- result = s->GetSubSurface(s, &r, &dfbSurface);
+ if (rect == screen->region().boundingRect()) {
+ dfbSurface = primarySurface;
+ } else {
+ const DFBRectangle r = { rect.x(), rect.y(),
+ rect.width(), rect.height() };
+ result = primarySurface->GetSubSurface(primarySurface, &r, &dfbSurface);
+ }
+ forceRaster = (dfbSurface && QDirectFBScreen::getImageFormat(dfbSurface) == QImage::Format_RGB32);
} else {
+ const bool isResize = rect.size() != geometry().size();
#ifdef QT_NO_DIRECTFB_WM
if (isResize) {
if (dfbSurface)
@@ -152,9 +182,10 @@ void QDirectFBSurface::setGeometry(const QRect &rect, const QRegion &mask)
DSDESC_PIXELFORMAT);
description.width = rect.width();
description.height = rect.height();
- description.pixelformat = DSPF_ARGB;
-
- dfbSurface = QDirectFBScreen::instance()->createDFBSurface(&description, false);
+ QDirectFBScreen::initSurfaceDescriptionPixelFormat(&description,
+ screen->pixelFormat());
+ dfbSurface = screen->createDFBSurface(&description, false);
+ forceRaster = (dfbSurface && QDirectFBScreen::getImageFormat(dfbSurface) == QImage::Format_RGB32);
} else {
Q_ASSERT(dfbSurface);
}
@@ -219,7 +250,7 @@ void QDirectFBSurface::setPermanentState(const QByteArray &state)
bool QDirectFBSurface::scroll(const QRegion &region, int dx, int dy)
{
- if (!dfbSurface)
+ if (!dfbSurface || !(flipFlags & DSFLIP_BLIT))
return false;
const QVector<QRect> rects = region.rects();
@@ -241,7 +272,7 @@ bool QDirectFBSurface::scroll(const QRegion &region, int dx, int dy)
dfbSurface->SetBlittingFlags(dfbSurface, DSBLIT_NOFX);
dfbSurface->BatchBlit(dfbSurface, dfbSurface,
dfbRects.data(), dfbPoints.data(), n);
-
+ dfbSurface->ReleaseSource(dfbSurface);
return true;
}
@@ -306,10 +337,15 @@ inline bool isWidgetOpaque(const QWidget *w)
return false;
}
-
void QDirectFBSurface::flush(QWidget *widget, const QRegion &region,
const QPoint &offset)
{
+ Q_UNUSED(widget);
+#ifdef QT_NO_DIRECTFB_WM
+ Q_UNUSED(region);
+ Q_UNUSED(offset);
+#endif
+
QWidget *win = window();
// hw: make sure opacity information is updated before compositing
@@ -330,18 +366,41 @@ void QDirectFBSurface::flush(QWidget *widget, const QRegion &region,
if (winOpacity != opacity)
dfbWindow->SetOpacity(dfbWindow, winOpacity);
}
+ if (!(flipFlags & DSFLIP_BLIT)) {
+ dfbSurface->Flip(dfbSurface, 0, flipFlags);
+ } else {
+ if (region.numRects() > 1) {
+ const QVector<QRect> rects = region.rects();
+ DFBSurfaceFlipFlags tmpFlags = flipFlags;
+ if (flipFlags & DSFLIP_WAIT)
+ tmpFlags = DFBSurfaceFlipFlags(flipFlags & ~DSFLIP_WAIT);
+ for (int i=0; i<rects.size(); ++i) {
+ const QRect &r = rects.at(i);
+ const DFBRegion dfbReg = { r.x() + offset.x(), r.y() + offset.y(),
+ r.x() + r.width() + offset.x(),
+ r.y() + r.height() + offset.y() };
+ dfbSurface->Flip(dfbSurface, &dfbReg,
+ i + 1 < rects.size()
+ ? tmpFlags
+ : flipFlags);
+ }
+ } else {
+ const QRect r = region.boundingRect();
+ const DFBRegion dfbReg = { r.x() + offset.x(), r.y() + offset.y(),
+ r.x() + r.width() + offset.x(),
+ r.y() + r.height() + offset.y() };
+ dfbSurface->Flip(dfbSurface, &dfbReg, flipFlags);
+ }
+ }
#endif
-
- // XXX: have to call the base function first as the decoration is
- // currently painted there
- QWSWindowSurface::flush(widget, region, offset);
-
-#ifndef QT_NO_DIRECTFB_WM
- const QRect br = region.boundingRect().translated(painterOffset());
- const DFBRegion r = { br.x(), br.y(),
- br.x() + br.width(), br.y() + br.height() };
-
- dfbSurface->Flip(dfbSurface, &r, DSFLIP_NONE);
+#ifdef QT_DIRECTFB_TIMING
+ enum { Secs = 3 };
+ ++frames;
+ if (timer.elapsed() >= Secs * 1000) {
+ qDebug("%d fps", int(double(frames) / double(Secs)));
+ frames = 0;
+ timer.restart();
+ }
#endif
}
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbsurface.h b/src/plugins/gfxdrivers/directfb/qdirectfbsurface.h
index a9cdb7d..ab4145d 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbsurface.h
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbsurface.h
@@ -50,6 +50,10 @@
#include <private/qwindowsurface_qws_p.h>
#include <directfb.h>
+#ifdef QT_DIRECTFB_TIMING
+#include <qdatetime.h>
+#endif
+
QT_BEGIN_HEADER
QT_MODULE(Gui)
@@ -57,8 +61,8 @@ QT_MODULE(Gui)
class QDirectFBSurface: public QWSWindowSurface, public QDirectFBPaintDevice
{
public:
- QDirectFBSurface(QDirectFBScreen* scr);
- QDirectFBSurface(QDirectFBScreen* scr, QWidget *widget);
+ QDirectFBSurface(DFBSurfaceFlipFlags flipFlags, QDirectFBScreen* scr);
+ QDirectFBSurface(DFBSurfaceFlipFlags flipFlags, QDirectFBScreen* scr, QWidget *widget);
~QDirectFBSurface();
bool isValid() const;
@@ -95,6 +99,11 @@ private:
bool onscreen;
QList<QImage*> bufferImages;
+ DFBSurfaceFlipFlags flipFlags;
+#ifdef QT_DIRECTFB_TIMING
+ int frames;
+ QTime timer;
+#endif
};
QT_END_HEADER
diff --git a/src/plugins/gfxdrivers/powervr/README b/src/plugins/gfxdrivers/powervr/README
index b830066..ec02efb 100644
--- a/src/plugins/gfxdrivers/powervr/README
+++ b/src/plugins/gfxdrivers/powervr/README
@@ -8,6 +8,9 @@ is built as two libraries: The actual QScreen plugin used by Qt (in the
pvreglscreen directory) and a WSEGL plugin for the PowerVR drivers (in the
QWSWSEGL directory).
+Qt/Embedded needs to be configured with the QT_QWS_CLIENTBLIT and
+QT_NO_QWS_CURSOR defines.
+
The PowerVR drivers provide the WSEGL plugin API to allow window systems such as
QWS to integrate correctly. In order to use the integration, the WSEGL plugin
(libpvrQWSWSEGL.so, usually installed into the Qt library directory) must be in
diff --git a/src/plugins/gfxdrivers/powervr/pvreglscreen/pvreglscreen.cpp b/src/plugins/gfxdrivers/powervr/pvreglscreen/pvreglscreen.cpp
index 3a94851..b0ffbf1 100644
--- a/src/plugins/gfxdrivers/powervr/pvreglscreen/pvreglscreen.cpp
+++ b/src/plugins/gfxdrivers/powervr/pvreglscreen/pvreglscreen.cpp
@@ -381,7 +381,7 @@ void PvrEglSurfaceHolder::removeSurface()
// create the temporary surface again.
if (surface == EGL_NO_SURFACE && dpy != EGL_NO_DISPLAY) {
surface = eglCreateWindowSurface
- (dpy, config, (EGLNativeWindowType)tempSurface, NULL);
+ (dpy, config, (EGLNativeWindowType)(-1), NULL);
if (surface == EGL_NO_SURFACE)
qWarning("Could not re-create the temporary EGL surface");
}
diff --git a/src/plugins/imageformats/jpeg/qjpeghandler.cpp b/src/plugins/imageformats/jpeg/qjpeghandler.cpp
index 31e5c66..6d0bc1f 100644
--- a/src/plugins/imageformats/jpeg/qjpeghandler.cpp
+++ b/src/plugins/imageformats/jpeg/qjpeghandler.cpp
@@ -809,7 +809,7 @@ static bool read_jpeg_image(QIODevice *device, QImage *outImage,
if (params.contains(QLatin1String("GetHeaderInformation"))) {
if (!ensureValidImage(outImage, &cinfo, true))
- return false;
+ longjmp(jerr.setjmp_buffer, 1);
} else if (params.contains(QLatin1String("Scale"))) {
#if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(Q_OS_WINCE)
sscanf_s(params.toLatin1().data(), "Scale(%i, %i, %1023s)",
@@ -848,7 +848,7 @@ static bool read_jpeg_image(QIODevice *device, QImage *outImage,
// Unsupported format
}
if (outImage->isNull())
- return false;
+ longjmp(jerr.setjmp_buffer, 1);
if (!outImage->isNull()) {
QImage tmpImage(cinfo.output_width, 1, QImage::Format_RGB32);
@@ -894,7 +894,7 @@ static bool read_jpeg_image(QIODevice *device, QImage *outImage,
#endif
} else {
if (!ensureValidImage(outImage, &cinfo))
- return false;
+ longjmp(jerr.setjmp_buffer, 1);
uchar* data = outImage->bits();
int bpl = outImage->bytesPerLine();