[directfb] Implement QPixmap::fromFile using DirectFB routines
The code is based on Qt 4.8 DirectFB support, it was reduced in size (cosmetic changes, by using the outPtr()) and it has a bugfix to pass loadAsBitmapOrPixmap that assumes the loadFromFile routine will add '.png' and other extensions to the file. Change-Id: I25b11206053c02be5c04730fba5bb42bd07426d1 Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
This commit is contained in:
parent
b1c803a925
commit
c8746d886f
@ -45,10 +45,16 @@
|
|||||||
#include <QtGui/private/qpixmap_blitter_p.h>
|
#include <QtGui/private/qpixmap_blitter_p.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
#include <directfb.h>
|
#include <directfb.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define QDFB_STRINGIFY(x) #x
|
||||||
|
#define QDFB_TOSTRING(x) QDFB_STRINGIFY(x)
|
||||||
|
#define QDFB_PRETTY \
|
||||||
|
(__FILE__ ":" QDFB_TOSTRING(__LINE__))
|
||||||
|
|
||||||
static QBlittable::Capabilities dfb_blitter_capabilities()
|
static QBlittable::Capabilities dfb_blitter_capabilities()
|
||||||
{
|
{
|
||||||
return QBlittable::Capabilities(QBlittable::SolidRectCapability
|
return QBlittable::Capabilities(QBlittable::SolidRectCapability
|
||||||
@ -178,6 +184,94 @@ QImage *QDirectFbBlitter::doLock()
|
|||||||
return &m_image;
|
return &m_image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QDirectFbBlitterPlatformPixmap::fromDataBufferDescription(const DFBDataBufferDescription &dataBufferDescription)
|
||||||
|
{
|
||||||
|
DFBResult result;
|
||||||
|
IDirectFB *dfb = QDirectFbConvenience::dfbInterface();
|
||||||
|
|
||||||
|
// Create a data buffer
|
||||||
|
QDirectFBPointer<IDirectFBDataBuffer> dataBuffer;
|
||||||
|
result = dfb->CreateDataBuffer(dfb, &dataBufferDescription, dataBuffer.outPtr());
|
||||||
|
if (result != DFB_OK) {
|
||||||
|
DirectFBError(QDFB_PRETTY, result);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the image provider
|
||||||
|
QDirectFBPointer<IDirectFBImageProvider> provider;
|
||||||
|
result = dataBuffer->CreateImageProvider(dataBuffer.data(), provider.outPtr());
|
||||||
|
if (result != DFB_OK) {
|
||||||
|
DirectFBError(QDFB_PRETTY, result);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract image information
|
||||||
|
DFBImageDescription imageDescription;
|
||||||
|
result = provider->GetImageDescription(provider.data(), &imageDescription);
|
||||||
|
if (result != DFB_OK) {
|
||||||
|
DirectFBError(QDFB_PRETTY, result);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Can we handle this directlu?
|
||||||
|
if (imageDescription.caps & DICAPS_COLORKEY)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
DFBSurfaceDescription surfaceDescription;
|
||||||
|
result = provider->GetSurfaceDescription(provider.data(), &surfaceDescription);
|
||||||
|
if (result != DFB_OK) {
|
||||||
|
DirectFBError(QDFB_PRETTY, result);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_alpha = imageDescription.caps & DICAPS_ALPHACHANNEL;
|
||||||
|
resize(surfaceDescription.width, surfaceDescription.height);
|
||||||
|
// TODO: FIXME; update d
|
||||||
|
|
||||||
|
|
||||||
|
result = provider->RenderTo(provider.data(), dfbBlitter()->dfbSurface(), 0);
|
||||||
|
if (result != DFB_OK) {
|
||||||
|
DirectFBError(QDFB_PRETTY, result);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QDirectFbBlitterPlatformPixmap::fromFile(const QString &filename, const char *format,
|
||||||
|
Qt::ImageConversionFlags flags)
|
||||||
|
{
|
||||||
|
// If we can't find the file, pass it on to the base class as it is
|
||||||
|
// trying harder by appending various extensions to the path.
|
||||||
|
if (!QFile::exists(filename))
|
||||||
|
return QBlittablePlatformPixmap::fromFile(filename, format, flags);
|
||||||
|
|
||||||
|
// Stop if there is a requirement for colors
|
||||||
|
if (flags != Qt::AutoColor)
|
||||||
|
return QBlittablePlatformPixmap::fromFile(filename, format, flags);
|
||||||
|
|
||||||
|
// Deal with resources
|
||||||
|
if (filename.startsWith(QLatin1Char(':'))) { // resource
|
||||||
|
QFile file(filename);
|
||||||
|
if (!file.open(QIODevice::ReadOnly))
|
||||||
|
return false;
|
||||||
|
const QByteArray data = file.readAll();
|
||||||
|
file.close();
|
||||||
|
return fromData(reinterpret_cast<const uchar*>(data.constData()), data.size(), format, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to use directfb to load it.
|
||||||
|
DFBDataBufferDescription description;
|
||||||
|
description.flags = DBDESC_FILE;
|
||||||
|
const QByteArray fileNameData = filename.toLocal8Bit();
|
||||||
|
description.file = fileNameData.constData();
|
||||||
|
if (fromDataBufferDescription(description))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Fallback
|
||||||
|
return QBlittablePlatformPixmap::fromFile(filename, format, flags);
|
||||||
|
}
|
||||||
|
|
||||||
void QDirectFbBlitter::doUnlock()
|
void QDirectFbBlitter::doUnlock()
|
||||||
{
|
{
|
||||||
m_surface->Unlock(m_surface.data());
|
m_surface->Unlock(m_surface.data());
|
||||||
|
@ -58,6 +58,8 @@ public:
|
|||||||
virtual void fillRect(const QRectF &rect, const QColor &color);
|
virtual void fillRect(const QRectF &rect, const QColor &color);
|
||||||
virtual void drawPixmap(const QRectF &rect, const QPixmap &pixmap, const QRectF &subrect);
|
virtual void drawPixmap(const QRectF &rect, const QPixmap &pixmap, const QRectF &subrect);
|
||||||
|
|
||||||
|
IDirectFBSurface *dfbSurface() const;
|
||||||
|
|
||||||
static DFBSurfacePixelFormat alphaPixmapFormat();
|
static DFBSurfacePixelFormat alphaPixmapFormat();
|
||||||
static DFBSurfacePixelFormat pixmapFormat();
|
static DFBSurfacePixelFormat pixmapFormat();
|
||||||
static DFBSurfacePixelFormat selectPixmapFormat(bool withAlpha);
|
static DFBSurfacePixelFormat selectPixmapFormat(bool withAlpha);
|
||||||
@ -76,6 +78,14 @@ class QDirectFbBlitterPlatformPixmap : public QBlittablePlatformPixmap
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QBlittable *createBlittable(const QSize &size, bool alpha) const;
|
QBlittable *createBlittable(const QSize &size, bool alpha) const;
|
||||||
|
|
||||||
|
QDirectFbBlitter *dfbBlitter() const;
|
||||||
|
|
||||||
|
virtual bool fromFile(const QString &filename, const char *format,
|
||||||
|
Qt::ImageConversionFlags flags);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool fromDataBufferDescription(const DFBDataBufferDescription &);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline QBlittable *QDirectFbBlitterPlatformPixmap::createBlittable(const QSize& size, bool alpha) const
|
inline QBlittable *QDirectFbBlitterPlatformPixmap::createBlittable(const QSize& size, bool alpha) const
|
||||||
@ -83,4 +93,14 @@ inline QBlittable *QDirectFbBlitterPlatformPixmap::createBlittable(const QSize&
|
|||||||
return new QDirectFbBlitter(size, alpha);
|
return new QDirectFbBlitter(size, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline QDirectFbBlitter *QDirectFbBlitterPlatformPixmap::dfbBlitter() const
|
||||||
|
{
|
||||||
|
return static_cast<QDirectFbBlitter*>(blittable());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline IDirectFBSurface *QDirectFbBlitter::dfbSurface() const
|
||||||
|
{
|
||||||
|
return m_surface.data();
|
||||||
|
}
|
||||||
|
|
||||||
#endif // QDIRECTFBBLITTER_H
|
#endif // QDIRECTFBBLITTER_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user