src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp
changeset 7 f7bc934e204c
parent 0 1918ee327afb
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the plugins of the Qt Toolkit.
     7 ** This file is part of the plugins of the Qt Toolkit.
     8 **
     8 **
   172 
   172 
   173 #ifdef QT_DIRECTFB_IMAGEPROVIDER
   173 #ifdef QT_DIRECTFB_IMAGEPROVIDER
   174 bool QDirectFBPixmapData::fromFile(const QString &filename, const char *format,
   174 bool QDirectFBPixmapData::fromFile(const QString &filename, const char *format,
   175                                    Qt::ImageConversionFlags flags)
   175                                    Qt::ImageConversionFlags flags)
   176 {
   176 {
       
   177     if (!QFile::exists(filename))
       
   178         return false;
   177     if (flags == Qt::AutoColor) {
   179     if (flags == Qt::AutoColor) {
   178         if (filename.startsWith(QLatin1Char(':'))) { // resource
   180         if (filename.startsWith(QLatin1Char(':'))) { // resource
   179             QFile file(filename);
   181             QFile file(filename);
   180             if (!file.open(QIODevice::ReadOnly))
   182             if (!file.open(QIODevice::ReadOnly))
   181                 return false;
   183                 return false;
   286 #endif
   288 #endif
   287 
   289 
   288 void QDirectFBPixmapData::fromImage(const QImage &img,
   290 void QDirectFBPixmapData::fromImage(const QImage &img,
   289                                     Qt::ImageConversionFlags flags)
   291                                     Qt::ImageConversionFlags flags)
   290 {
   292 {
   291     if (img.depth() == 1 || img.format() == QImage::Format_RGB32) {
   293     if (img.depth() == 1) {
   292         fromImage(img.convertToFormat(screen->alphaPixmapFormat()), flags);
   294         alpha = true;
   293         return;
       
   294     }
       
   295 
       
   296     if (img.hasAlphaChannel()
       
   297 #ifndef QT_NO_DIRECTFB_OPAQUE_DETECTION
   295 #ifndef QT_NO_DIRECTFB_OPAQUE_DETECTION
   298         && (flags & Qt::NoOpaqueDetection || QDirectFBPixmapData::hasAlphaChannel(img))
   296     } else if (flags & Qt::NoOpaqueDetection || QDirectFBPixmapData::hasAlphaChannel(img)) {
   299 #endif
       
   300         ) {
       
   301         alpha = true;
   297         alpha = true;
   302         imageFormat = screen->alphaPixmapFormat();
   298 #else
   303     } else {
   299     } else if (img.hasAlphaChannel()) {
   304         alpha = false;
   300         alpha = true;
   305         imageFormat = screen->pixelFormat();
   301 #endif
   306     }
   302     }
       
   303     imageFormat = alpha ? screen->alphaPixmapFormat() : screen->pixelFormat();
   307     QImage image;
   304     QImage image;
   308     if (flags != Qt::AutoColor) {
   305     if ((flags & ~Qt::NoOpaqueDetection) != Qt::AutoColor) {
   309         image = img.convertToFormat(imageFormat, flags);
   306         image = img.convertToFormat(imageFormat, flags);
   310         flags = Qt::AutoColor;
   307         flags = Qt::AutoColor;
   311     } else if (img.format() == QImage::Format_RGB32) {
   308     } else if (img.format() == QImage::Format_RGB32 || img.depth() == 1) {
   312         image = img.convertToFormat(imageFormat, flags);
   309         image = img.convertToFormat(imageFormat, flags);
   313     } else {
   310     } else {
   314         image = img;
   311         image = img;
   315     }
   312     }
   316 
   313 
   423     if (!serialNumber())
   420     if (!serialNumber())
   424         return;
   421         return;
   425 
   422 
   426     Q_ASSERT(dfbSurface);
   423     Q_ASSERT(dfbSurface);
   427 
   424 
   428     alpha = (color.alpha() < 255);
   425     alpha |= (color.alpha() < 255);
   429 
   426 
   430     if (alpha && isOpaqueFormat(imageFormat)) {
   427     if (alpha && isOpaqueFormat(imageFormat)) {
   431         QSize size;
   428         QSize size;
   432         dfbSurface->GetSize(dfbSurface, &size.rwidth(), &size.rheight());
   429         dfbSurface->GetSize(dfbSurface, &size.rwidth(), &size.rheight());
   433         screen->releaseDFBSurface(dfbSurface);
   430         screen->releaseDFBSurface(dfbSurface);
   468     const QSize size = transform.mapRect(QRect(0, 0, w, h)).size();
   465     const QSize size = transform.mapRect(QRect(0, 0, w, h)).size();
   469     if (size.isEmpty())
   466     if (size.isEmpty())
   470         return QPixmap();
   467         return QPixmap();
   471 
   468 
   472     QDirectFBPixmapData *data = new QDirectFBPixmapData(screen, QPixmapData::PixmapType);
   469     QDirectFBPixmapData *data = new QDirectFBPixmapData(screen, QPixmapData::PixmapType);
       
   470     data->setSerialNumber(++global_ser_no);
   473     DFBSurfaceBlittingFlags flags = DSBLIT_NOFX;
   471     DFBSurfaceBlittingFlags flags = DSBLIT_NOFX;
   474     data->alpha = alpha;
   472     data->alpha = alpha;
   475     if (alpha) {
   473     if (alpha) {
   476         flags = DSBLIT_BLEND_ALPHACHANNEL;
   474         flags = DSBLIT_BLEND_ALPHACHANNEL;
   477     }
   475     }
   549     Q_ASSERT(lockFlgs);
   547     Q_ASSERT(lockFlgs);
   550     Q_ASSERT(!lockedImage.isNull());
   548     Q_ASSERT(!lockedImage.isNull());
   551     return &lockedImage;
   549     return &lockedImage;
   552 }
   550 }
   553 
   551 
       
   552 
       
   553 bool QDirectFBPixmapData::scroll(int dx, int dy, const QRect &rect)
       
   554 {
       
   555     if (!dfbSurface) {
       
   556         return false;
       
   557     }
       
   558     unlockSurface();
       
   559     DFBResult result = dfbSurface->SetBlittingFlags(dfbSurface, DSBLIT_NOFX);
       
   560     if (result != DFB_OK) {
       
   561         DirectFBError("QDirectFBPixmapData::scroll", result);
       
   562         return false;
       
   563     }
       
   564     result = dfbSurface->SetPorterDuff(dfbSurface, DSPD_NONE);
       
   565     if (result != DFB_OK) {
       
   566         DirectFBError("QDirectFBPixmapData::scroll", result);
       
   567         return false;
       
   568     }
       
   569 
       
   570     const DFBRectangle source = { rect.x(), rect.y(), rect.width(), rect.height() };
       
   571     result = dfbSurface->Blit(dfbSurface, dfbSurface, &source, source.x + dx, source.y + dy);
       
   572     if (result != DFB_OK) {
       
   573         DirectFBError("QDirectFBPixmapData::scroll", result);
       
   574         return false;
       
   575     }
       
   576 
       
   577     return true;
       
   578 }
       
   579 
   554 void QDirectFBPixmapData::invalidate()
   580 void QDirectFBPixmapData::invalidate()
   555 {
   581 {
   556     if (dfbSurface) {
   582     if (dfbSurface) {
   557         screen->releaseDFBSurface(dfbSurface);
   583         screen->releaseDFBSurface(dfbSurface);
   558         dfbSurface = 0;
   584         dfbSurface = 0;
   562     d = w = h = 0;
   588     d = w = h = 0;
   563     is_null = true;
   589     is_null = true;
   564     imageFormat = QImage::Format_Invalid;
   590     imageFormat = QImage::Format_Invalid;
   565 }
   591 }
   566 
   592 
       
   593 #ifndef QT_DIRECTFB_PLUGIN
       
   594 Q_GUI_EXPORT IDirectFBSurface *qt_directfb_surface_for_pixmap(const QPixmap &pixmap)
       
   595 {
       
   596     const QPixmapData *data = pixmap.pixmapData();
       
   597     if (!data || data->classId() != QPixmapData::DirectFBClass)
       
   598         return 0;
       
   599     const QDirectFBPixmapData *dfbData = static_cast<const QDirectFBPixmapData*>(data);
       
   600     return dfbData->directFBSurface();
       
   601 }
       
   602 #endif
       
   603 
   567 QT_END_NAMESPACE
   604 QT_END_NAMESPACE
   568 
   605 
   569 #endif // QT_NO_QWS_DIRECTFB
   606 #endif // QT_NO_QWS_DIRECTFB
   570 
       
   571 
       
   572