summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAnders Bakken <anders.bakken@nokia.com>2009-07-17 10:09:10 (GMT)
committerAnders Bakken <anders.bakken@nokia.com>2009-07-17 10:19:42 (GMT)
commitbb5692384aef0b87362966609b8fd58c0974e4b5 (patch)
tree5427c615af08cc9455193fce5b0cd72e83ab20d5 /src
parent4652f0e0a03083b5baa1488237084333b134c516 (diff)
downloadQt-bb5692384aef0b87362966609b8fd58c0974e4b5.zip
Qt-bb5692384aef0b87362966609b8fd58c0974e4b5.tar.gz
Qt-bb5692384aef0b87362966609b8fd58c0974e4b5.tar.bz2
Clean up directfb bit flipping
DirectFB declares variables that are bit fields as enums. E.g. DFBSurfaceCapabilities caps; caps |= DSCAPS_LOCK; // doesn't compile in C++ Work around this problem by declaring operators for these operations. This greatly improves the readability of the code. Reviewed-by: TrustMe
Diffstat (limited to 'src')
-rw-r--r--src/plugins/gfxdrivers/directfb/qdirectfbmouse.cpp2
-rw-r--r--src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.cpp19
-rw-r--r--src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.h18
-rw-r--r--src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp2
-rw-r--r--src/plugins/gfxdrivers/directfb/qdirectfbpixmap.h2
-rw-r--r--src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp62
-rw-r--r--src/plugins/gfxdrivers/directfb/qdirectfbscreen.h18
-rw-r--r--src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.cpp12
8 files changed, 66 insertions, 69 deletions
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbmouse.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbmouse.cpp
index 15fb6f4..694ba51 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbmouse.cpp
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbmouse.cpp
@@ -101,7 +101,7 @@ QDirectFBMouseHandlerPrivate::QDirectFBMouseHandlerPrivate(QDirectFBMouseHandler
#endif
DFBInputDeviceCapabilities caps;
- caps = DFBInputDeviceCapabilities(DICAPS_BUTTONS | DICAPS_AXES);
+ caps = DICAPS_BUTTONS | DICAPS_AXES;
result = fb->CreateInputEventBuffer(fb, caps, DFB_TRUE, &eventBuffer);
if (result != DFB_OK) {
DirectFBError("QDirectFBMouseHandler: "
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.cpp
index 178dbae..8ad5264 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.cpp
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.cpp
@@ -56,20 +56,17 @@ IDirectFBSurface *QDirectFBPaintDevice::directFBSurface() const
}
-void QDirectFBPaintDevice::lockDirectFB(uint flags)
+void QDirectFBPaintDevice::lockDirectFB(DFBSurfaceLockFlags flags)
{
if (!(lock & flags)) {
if (lock)
unlockDirectFB();
- if ((mem = QDirectFBScreen::lockSurface(dfbSurface, flags, &bpl))) {
- const QSize s = size();
- lockedImage = new QImage(mem, s.width(), s.height(), bpl,
- QDirectFBScreen::getImageFormat(dfbSurface));
- lock = flags;
- Q_ASSERT(mem);
- } else {
- lock = 0;
- }
+ mem = QDirectFBScreen::lockSurface(dfbSurface, flags, &bpl);
+ Q_ASSERT(mem);
+ const QSize s = size();
+ lockedImage = new QImage(mem, s.width(), s.height(), bpl,
+ QDirectFBScreen::getImageFormat(dfbSurface));
+ lock = flags;
}
}
@@ -83,7 +80,7 @@ void QDirectFBPaintDevice::unlockDirectFB()
delete lockedImage;
lockedImage = 0;
mem = 0;
- lock = 0;
+ lock = DFBSurfaceLockFlags(0);
}
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.h b/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.h
index 32c49bb..248a15b 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.h
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.h
@@ -51,14 +51,14 @@ QT_BEGIN_HEADER
QT_MODULE(Gui)
// Inherited by both window surface and pixmap
-class QDirectFBPaintDevice : public QCustomRasterPaintDevice
+ class QDirectFBPaintDevice : public QCustomRasterPaintDevice
{
public:
~QDirectFBPaintDevice();
IDirectFBSurface *directFBSurface() const;
- void lockDirectFB(uint flags);
+ void lockDirectFB(DFBSurfaceLockFlags lock);
void unlockDirectFB();
// Reimplemented from QCustomRasterPaintDevice:
@@ -67,16 +67,12 @@ public:
int bytesPerLine() const;
QSize size() const;
int metric(QPaintDevice::PaintDeviceMetric metric) const;
- uint lockFlags() const { return lock; }
+ DFBSurfaceLockFlags lockFlags() const { return lock; }
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),
- lock(0),
- mem(0)
+ : QCustomRasterPaintDevice(0), dfbSurface(0), lockedImage(0), screen(scr),
+ lock(DFBSurfaceLockFlags(0)), mem(0)
{}
inline int dotsPerMeterX() const
@@ -92,11 +88,11 @@ protected:
QImage *lockedImage;
QDirectFBScreen *screen;
int bpl;
- uint lock;
+ DFBSurfaceLockFlags lock;
uchar *mem;
private:
Q_DISABLE_COPY(QDirectFBPaintDevice)
-};
+ };
QT_END_HEADER
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp
index c75cba6..dd7faf3 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp
@@ -374,7 +374,7 @@ QImage *QDirectFBPixmapData::buffer()
return lockedImage;
}
-QImage * QDirectFBPixmapData::buffer(uint lockFlags)
+QImage * QDirectFBPixmapData::buffer(DFBSurfaceLockFlags lockFlags)
{
lockDirectFB(lockFlags);
return lockedImage;
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.h b/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.h
index ad6c38e..8f3ce41 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.h
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbpixmap.h
@@ -70,7 +70,7 @@ public:
QImage toImage() const;
QPaintEngine* paintEngine() const;
virtual QImage *buffer();
- QImage *buffer(uint lockFlags);
+ QImage *buffer(DFBSurfaceLockFlags lockFlags);
// Pure virtual in QPixmapData, so re-implement here and delegate to QDirectFBPaintDevice
int metric(QPaintDevice::PaintDeviceMetric m) const {return QDirectFBPaintDevice::metric(m);}
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp
index b2e424c..ecead0b 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp
@@ -208,7 +208,7 @@ IDirectFBSurface *QDirectFBScreen::createDFBSurface(const QSize &size,
{
DFBSurfaceDescription desc;
memset(&desc, 0, sizeof(DFBSurfaceDescription));
- desc.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH|DSDESC_HEIGHT);
+ desc.flags |= DSDESC_WIDTH|DSDESC_HEIGHT;
if (!QDirectFBScreen::initSurfaceDescriptionPixelFormat(&desc, format))
return 0;
desc.width = size.width();
@@ -230,9 +230,9 @@ IDirectFBSurface *QDirectFBScreen::createDFBSurface(DFBSurfaceDescription desc,
// Add the video only capability. This means the surface will be created in video ram
if (!(desc.flags & DSDESC_CAPS)) {
desc.caps = DSCAPS_VIDEOONLY;
- desc.flags = DFBSurfaceDescriptionFlags(desc.flags | DSDESC_CAPS);
+ desc.flags |= DSDESC_CAPS;
} else {
- desc.caps = DFBSurfaceCapabilities(desc.caps | DSCAPS_VIDEOONLY);
+ desc.caps |= DSCAPS_VIDEOONLY;
}
result = d_ptr->dfb->CreateSurface(d_ptr->dfb, &desc, &newSurface);
if (result != DFB_OK
@@ -247,11 +247,11 @@ IDirectFBSurface *QDirectFBScreen::createDFBSurface(DFBSurfaceDescription desc,
desc.preallocated[0].data, desc.preallocated[0].pitch,
DirectFBErrorString(result));
}
- desc.caps = DFBSurfaceCapabilities(desc.caps & ~DSCAPS_VIDEOONLY);
+ desc.caps &= ~DSCAPS_VIDEOONLY;
}
if (d_ptr->directFBFlags & SystemOnly)
- desc.caps = DFBSurfaceCapabilities(desc.caps | DSCAPS_SYSTEMONLY);
+ desc.caps |= DSCAPS_SYSTEMONLY;
if (!newSurface)
result = d_ptr->dfb->CreateSurface(d_ptr->dfb, &desc, &newSurface);
@@ -459,20 +459,16 @@ DFBSurfaceDescription QDirectFBScreen::getSurfaceDescription(const QImage &image
const DFBSurfacePixelFormat format = getSurfacePixelFormat(image.format());
if (format == DSPF_UNKNOWN || image.isNull()) {
- description.flags = DFBSurfaceDescriptionFlags(0);
+ description.flags = DSDESC_NONE;
return description;
}
- description.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH
- | DSDESC_HEIGHT
-#ifndef QT_NO_DIRECTFB_PREALLOCATED
- | DSDESC_PREALLOCATED
-#endif
- | DSDESC_PIXELFORMAT);
+ description.flags = DSDESC_WIDTH|DSDESC_HEIGHT|DSDESC_PIXELFORMAT;
QDirectFBScreen::initSurfaceDescriptionPixelFormat(&description, image.format());
description.width = image.width();
description.height = image.height();
#ifndef QT_NO_DIRECTFB_PREALLOCATED
+ description.flags |= DSDESC_PREALLOCATED;
description.preallocated[0].data = (void*)(image.bits());
description.preallocated[0].pitch = image.bytesPerLine();
description.preallocated[1].data = 0;
@@ -491,11 +487,7 @@ DFBSurfaceDescription QDirectFBScreen::getSurfaceDescription(const uint *buffer,
DFBSurfaceDescription description;
memset(&description, 0, sizeof(DFBSurfaceDescription));
- description.flags = DFBSurfaceDescriptionFlags(DSDESC_CAPS
- | DSDESC_WIDTH
- | DSDESC_HEIGHT
- | DSDESC_PIXELFORMAT
- | DSDESC_PREALLOCATED);
+ description.flags = DSDESC_CAPS|DSDESC_WIDTH|DSDESC_HEIGHT|DSDESC_PIXELFORMAT|DSDESC_PREALLOCATED;
description.caps = DSCAPS_PREMULTIPLIED;
description.width = length;
description.height = 1;
@@ -504,8 +496,7 @@ DFBSurfaceDescription QDirectFBScreen::getSurfaceDescription(const uint *buffer,
description.preallocated[0].pitch = length * sizeof(uint);
description.preallocated[1].data = 0;
description.preallocated[1].pitch = 0;
-
- return description;
+return description;
}
#ifndef QT_NO_DIRECTFB_PALETTE
@@ -727,19 +718,19 @@ void QDirectFBScreenPrivate::setFlipFlags(const QStringList &args)
flipFlags = DSFLIP_NONE;
foreach(const QString &flip, flips) {
if (flip == QLatin1String("wait"))
- flipFlags = DFBSurfaceFlipFlags(flipFlags | DSFLIP_WAIT);
+ flipFlags |= DSFLIP_WAIT;
else if (flip == QLatin1String("blit"))
- flipFlags = DFBSurfaceFlipFlags(flipFlags | DSFLIP_BLIT);
+ flipFlags |= DSFLIP_BLIT;
else if (flip == QLatin1String("onsync"))
- flipFlags = DFBSurfaceFlipFlags(flipFlags | DSFLIP_ONSYNC);
+ flipFlags |= DSFLIP_ONSYNC;
else if (flip == QLatin1String("pipeline"))
- flipFlags = DFBSurfaceFlipFlags(flipFlags | DSFLIP_PIPELINE);
+ flipFlags |= DSFLIP_PIPELINE;
else
qWarning("QDirectFBScreen: Unknown flip argument: %s",
qPrintable(flip));
}
} else {
- flipFlags = DFBSurfaceFlipFlags(DSFLIP_BLIT);
+ flipFlags = DSFLIP_BLIT;
}
}
@@ -933,13 +924,13 @@ bool QDirectFBScreen::connect(const QString &displaySpec)
DFBSurfaceDescription description;
memset(&description, 0, sizeof(DFBSurfaceDescription));
- description.flags = DFBSurfaceDescriptionFlags(DSDESC_CAPS);
+ description.flags = DSDESC_CAPS;
if (::setIntOption(displayArgs, QLatin1String("width"), &description.width))
- description.flags = DFBSurfaceDescriptionFlags(description.flags | DSDESC_WIDTH);
+ description.flags |= DSDESC_WIDTH;
if (::setIntOption(displayArgs, QLatin1String("height"), &description.height))
- description.flags = DFBSurfaceDescriptionFlags(description.flags | DSDESC_HEIGHT);
+ description.flags |= DSDESC_HEIGHT;
- uint caps = DSCAPS_PRIMARY|DSCAPS_DOUBLE;
+ description.caps = DSCAPS_PRIMARY|DSCAPS_DOUBLE;
struct {
const char *name;
const DFBSurfaceCapabilities cap;
@@ -953,14 +944,13 @@ bool QDirectFBScreen::connect(const QString &displaySpec)
};
for (int i=0; capabilities[i].name; ++i) {
if (displayArgs.contains(QString::fromLatin1(capabilities[i].name), Qt::CaseInsensitive))
- caps |= capabilities[i].cap;
+ description.caps |= capabilities[i].cap;
}
if (displayArgs.contains(QLatin1String("forcepremultiplied"), Qt::CaseInsensitive)) {
- caps |= DSCAPS_PREMULTIPLIED;
+ description.caps |= DSCAPS_PREMULTIPLIED;
}
- description.caps = DFBSurfaceCapabilities(caps);
// We don't track the primary surface as it's released in disconnect
d_ptr->dfbSurface = createDFBSurface(description, DontTrackSurface);
if (!d_ptr->dfbSurface) {
@@ -1218,10 +1208,10 @@ void QDirectFBScreen::compose(const QRegion &region)
DFBSurfaceBlittingFlags flags = DSBLIT_NOFX;
if (!win->isOpaque()) {
- flags = DFBSurfaceBlittingFlags(flags | DSBLIT_BLEND_ALPHACHANNEL);
+ flags |= DSBLIT_BLEND_ALPHACHANNEL;
const uint opacity = win->opacity();
if (opacity < 255) {
- flags = DFBSurfaceBlittingFlags(flags | DSBLIT_BLEND_COLORALPHA);
+ flags |= DSBLIT_BLEND_COLORALPHA;
d_ptr->dfbSurface->SetColor(d_ptr->dfbSurface, 0xff, 0xff, 0xff, opacity);
}
}
@@ -1361,14 +1351,14 @@ bool QDirectFBScreen::initSurfaceDescriptionPixelFormat(DFBSurfaceDescription *d
const DFBSurfacePixelFormat pixelformat = QDirectFBScreen::getSurfacePixelFormat(format);
if (pixelformat == DSPF_UNKNOWN)
return false;
- description->flags = DFBSurfaceDescriptionFlags(description->flags | DSDESC_PIXELFORMAT);
+ 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);
+ description->flags |= DSDESC_CAPS;
} else {
- description->caps = DFBSurfaceCapabilities(description->caps | DSCAPS_PREMULTIPLIED);
+ description->caps |= DSCAPS_PREMULTIPLIED;
}
}
return true;
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h
index c2c9a59..9d1e670 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h
@@ -51,8 +51,24 @@ QT_MODULE(Gui)
#define Q_DIRECTFB_VERSION ((DIRECTFB_MAJOR_VERSION << 16) | (DIRECTFB_MINOR_VERION << 8) | DIRECTFB_MICRO_VERSION)
-class QDirectFBScreenPrivate;
+#include <QDebug>
+#define DIRECTFB_DECLARE_OPERATORS_FOR_FLAGS(F) \
+ static inline F operator~(F f) { return F(~int(f)); } \
+ static inline F operator&(F left, F right) { return F(int(left) & int(right)); } \
+ static inline F operator|(F left, F right) { return F(int(left) | int(right)); } \
+ static inline F &operator|=(F &left, F right) { left = (left | right); return left; } \
+ static inline F &operator&=(F &left, F right) { left = (left & right); return left; }
+
+DIRECTFB_DECLARE_OPERATORS_FOR_FLAGS(DFBInputDeviceCapabilities);
+DIRECTFB_DECLARE_OPERATORS_FOR_FLAGS(DFBWindowDescriptionFlags);
+DIRECTFB_DECLARE_OPERATORS_FOR_FLAGS(DFBSurfaceDescriptionFlags);
+DIRECTFB_DECLARE_OPERATORS_FOR_FLAGS(DFBSurfaceCapabilities);
+DIRECTFB_DECLARE_OPERATORS_FOR_FLAGS(DFBSurfaceLockFlags);
+DIRECTFB_DECLARE_OPERATORS_FOR_FLAGS(DFBSurfaceBlittingFlags);
+DIRECTFB_DECLARE_OPERATORS_FOR_FLAGS(DFBSurfaceDrawingFlags);
+DIRECTFB_DECLARE_OPERATORS_FOR_FLAGS(DFBSurfaceFlipFlags);
+class QDirectFBScreenPrivate;
class Q_GUI_EXPORT QDirectFBScreen : public QScreen
{
public:
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.cpp
index 86ee62c..7dcf398 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.cpp
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.cpp
@@ -106,18 +106,16 @@ void QDirectFBWindowSurface::createWindow()
qFatal("QDirectFBWindowSurface: Unable to get primary display layer!");
DFBWindowDescription description;
- description.caps = DFBWindowCapabilities(DWCAPS_NODECORATION);
- description.flags = DFBWindowDescriptionFlags(DWDESC_CAPS
- |DWDESC_SURFACE_CAPS
- |DWDESC_PIXELFORMAT);
+ description.caps = DWCAPS_NODECORATION;
+ description.flags = DWDESC_CAPS|DWDESC_SURFACE_CAPS|DWDESC_PIXELFORMAT;
description.surface_caps = DSCAPS_NONE;
if (screen->directFBFlags() & QDirectFBScreen::VideoOnly)
- description.surface_caps = DFBSurfaceCapabilities(description.surface_caps|DSCAPS_VIDEOONLY);
+ 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);
+ description.surface_caps = DSCAPS_PREMULTIPLIED;
DFBResult result = layer->CreateWindow(layer, &description, &dfbWindow);
if (result != DFB_OK)
@@ -370,7 +368,7 @@ void QDirectFBWindowSurface::flush(QWidget *widget, const QRegion &region,
} else {
if (!boundingRectFlip && region.numRects() > 1) {
const QVector<QRect> rects = region.rects();
- const DFBSurfaceFlipFlags nonWaitFlags = DFBSurfaceFlipFlags(flipFlags & ~DSFLIP_WAIT);
+ const DFBSurfaceFlipFlags nonWaitFlags = 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(),