src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp
changeset 7 f7bc934e204c
parent 3 41300fa6a67c
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 **
   919             else
   919             else
   920                 qWarning("QDirectFBScreen: Unknown flip argument: %s",
   920                 qWarning("QDirectFBScreen: Unknown flip argument: %s",
   921                          qPrintable(flip));
   921                          qPrintable(flip));
   922         }
   922         }
   923     } else {
   923     } else {
   924         flipFlags = DSFLIP_BLIT;
   924         flipFlags = DSFLIP_BLIT|DSFLIP_ONSYNC;
   925     }
   925     }
   926 }
   926 }
   927 
   927 
   928 #ifdef QT_DIRECTFB_WM
   928 #ifdef QT_DIRECTFB_WM
   929 void QDirectFBScreenPrivate::onWindowEvent(QWSWindow *window, QWSServer::WindowEvent event)
   929 void QDirectFBScreenPrivate::onWindowEvent(QWSWindow *window, QWSServer::WindowEvent event)
  1061     return false;
  1061     return false;
  1062 }
  1062 }
  1063 
  1063 
  1064 static inline QColor colorFromName(const QString &name)
  1064 static inline QColor colorFromName(const QString &name)
  1065 {
  1065 {
  1066     QRegExp rx("#([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])");
  1066     QRegExp rx(QLatin1String("#([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])"));
  1067     rx.setCaseSensitivity(Qt::CaseInsensitive);
  1067     rx.setCaseSensitivity(Qt::CaseInsensitive);
  1068     if (rx.exactMatch(name)) {
  1068     if (rx.exactMatch(name)) {
  1069         Q_ASSERT(rx.captureCount() == 4);
  1069         Q_ASSERT(rx.captureCount() == 4);
  1070         int ints[4];
  1070         int ints[4];
  1071         int i;
  1071         int i;
  1124         }
  1124         }
  1125     }
  1125     }
  1126 
  1126 
  1127     if (displayArgs.contains(QLatin1String("boundingrectflip"), Qt::CaseInsensitive)) {
  1127     if (displayArgs.contains(QLatin1String("boundingrectflip"), Qt::CaseInsensitive)) {
  1128         d_ptr->directFBFlags |= BoundingRectFlip;
  1128         d_ptr->directFBFlags |= BoundingRectFlip;
       
  1129     } else if (displayArgs.contains(QLatin1String("nopartialflip"), Qt::CaseInsensitive)) {
       
  1130         d_ptr->directFBFlags |= NoPartialFlip;
  1129     }
  1131     }
  1130 
  1132 
  1131 #ifdef QT_DIRECTFB_IMAGECACHE
  1133 #ifdef QT_DIRECTFB_IMAGECACHE
  1132     int imageCacheSize = 4 * 1024 * 1024; // 4 MB
  1134     int imageCacheSize = 4 * 1024 * 1024; // 4 MB
  1133     setIntOption(displayArgs, QLatin1String("imagecachesize"), &imageCacheSize);
  1135     setIntOption(displayArgs, QLatin1String("imagecachesize"), &imageCacheSize);
  1136 
  1138 
  1137 #ifndef QT_NO_DIRECTFB_WM
  1139 #ifndef QT_NO_DIRECTFB_WM
  1138     if (displayArgs.contains(QLatin1String("fullscreen")))
  1140     if (displayArgs.contains(QLatin1String("fullscreen")))
  1139 #endif
  1141 #endif
  1140         d_ptr->dfb->SetCooperativeLevel(d_ptr->dfb, DFSCL_FULLSCREEN);
  1142         d_ptr->dfb->SetCooperativeLevel(d_ptr->dfb, DFSCL_FULLSCREEN);
       
  1143 
       
  1144     const bool forcePremultiplied = displayArgs.contains(QLatin1String("forcepremultiplied"), Qt::CaseInsensitive);
  1141 
  1145 
  1142     DFBSurfaceDescription description;
  1146     DFBSurfaceDescription description;
  1143     memset(&description, 0, sizeof(DFBSurfaceDescription));
  1147     memset(&description, 0, sizeof(DFBSurfaceDescription));
  1144     IDirectFBSurface *surface;
  1148     IDirectFBSurface *surface;
  1145 
  1149 
  1165     for (int i=0; capabilities[i].name; ++i) {
  1169     for (int i=0; capabilities[i].name; ++i) {
  1166         if (displayArgs.contains(QString::fromLatin1(capabilities[i].name), Qt::CaseInsensitive))
  1170         if (displayArgs.contains(QString::fromLatin1(capabilities[i].name), Qt::CaseInsensitive))
  1167             description.caps |= capabilities[i].cap;
  1171             description.caps |= capabilities[i].cap;
  1168     }
  1172     }
  1169 
  1173 
  1170     if (displayArgs.contains(QLatin1String("forcepremultiplied"), Qt::CaseInsensitive)) {
  1174     if (forcePremultiplied) {
  1171         description.caps |= DSCAPS_PREMULTIPLIED;
  1175         description.caps |= DSCAPS_PREMULTIPLIED;
  1172     }
  1176     }
  1173 
  1177 
  1174     // We don't track the primary surface as it's released in disconnect
  1178     // We don't track the primary surface as it's released in disconnect
  1175     d_ptr->primarySurface = createDFBSurface(description, DontTrackSurface, &result);
  1179     d_ptr->primarySurface = createDFBSurface(description, DontTrackSurface, &result);
  1215     case QImage::Format_RGB16:
  1219     case QImage::Format_RGB16:
  1216     case QImage::Format_RGB555:
  1220     case QImage::Format_RGB555:
  1217         d_ptr->alphaPixmapFormat = QImage::Format_ARGB32_Premultiplied;
  1221         d_ptr->alphaPixmapFormat = QImage::Format_ARGB32_Premultiplied;
  1218         break;
  1222         break;
  1219     case QImage::Format_ARGB32:
  1223     case QImage::Format_ARGB32:
       
  1224         if (forcePremultiplied)
       
  1225             d_ptr->alphaPixmapFormat = pixelFormat = QImage::Format_ARGB32_Premultiplied;
  1220     case QImage::Format_ARGB32_Premultiplied:
  1226     case QImage::Format_ARGB32_Premultiplied:
  1221     case QImage::Format_ARGB4444_Premultiplied:
  1227     case QImage::Format_ARGB4444_Premultiplied:
  1222     case QImage::Format_ARGB8555_Premultiplied:
  1228     case QImage::Format_ARGB8555_Premultiplied:
  1223     case QImage::Format_ARGB8565_Premultiplied:
  1229     case QImage::Format_ARGB8565_Premultiplied:
  1224     case QImage::Format_ARGB6666_Premultiplied:
  1230     case QImage::Format_ARGB6666_Premultiplied:
  1276 
  1282 
  1277     if (w <= 0 || h <= 0) {
  1283     if (w <= 0 || h <= 0) {
  1278 #ifdef QT_NO_DIRECTFB_WM
  1284 #ifdef QT_NO_DIRECTFB_WM
  1279         result = d_ptr->primarySurface->GetSize(d_ptr->primarySurface, &w, &h);
  1285         result = d_ptr->primarySurface->GetSize(d_ptr->primarySurface, &w, &h);
  1280 #elif (Q_DIRECTFB_VERSION >= 0x010000)
  1286 #elif (Q_DIRECTFB_VERSION >= 0x010000)
  1281         result = d_ptr->dfbScreen->GetSize(d_ptr->dfbScreen, &w, &h);
  1287         IDirectFBSurface *layerSurface;
       
  1288         if (d_ptr->dfbLayer->GetSurface(d_ptr->dfbLayer, &layerSurface) != DFB_OK) {
       
  1289             result = layerSurface->GetSize(layerSurface, &w, &h);
       
  1290             layerSurface->Release(layerSurface);
       
  1291         }
       
  1292         if (w <= 0 || h <= 0) {
       
  1293             result = d_ptr->dfbScreen->GetSize(d_ptr->dfbScreen, &w, &h);
       
  1294         }
  1282 #else
  1295 #else
  1283         qWarning("QDirectFBScreen::connect: DirectFB versions prior to 1.0 do not offer a way\n"
  1296         qWarning("QDirectFBScreen::connect: DirectFB versions prior to 1.0 do not offer a way\n"
  1284                  "query the size of the primary surface in windowed mode. You have to specify\n"
  1297                  "query the size of the primary surface in windowed mode. You have to specify\n"
  1285                  "the size of the display using QWS_SIZE=[0-9]x[0-9] or\n"
  1298                  "the size of the display using QWS_SIZE=[0-9]x[0-9] or\n"
  1286                  "QWS_DISPLAY=directfb:width=[0-9]:height=[0-9]");
  1299                  "QWS_DISPLAY=directfb:width=[0-9]:height=[0-9]");
  1665     return true;
  1678     return true;
  1666 }
  1679 }
  1667 
  1680 
  1668 uchar *QDirectFBScreen::lockSurface(IDirectFBSurface *surface, DFBSurfaceLockFlags flags, int *bpl)
  1681 uchar *QDirectFBScreen::lockSurface(IDirectFBSurface *surface, DFBSurfaceLockFlags flags, int *bpl)
  1669 {
  1682 {
  1670     void *mem;
  1683     void *mem = 0;
  1671     const DFBResult result = surface->Lock(surface, flags, &mem, bpl);
  1684     const DFBResult result = surface->Lock(surface, flags, &mem, bpl);
  1672     if (result != DFB_OK) {
  1685     if (result != DFB_OK) {
  1673         DirectFBError("QDirectFBScreen::lockSurface()", result);
  1686         DirectFBError("QDirectFBScreen::lockSurface()", result);
  1674     }
  1687     }
  1675 
  1688 
  1676     return reinterpret_cast<uchar*>(mem);
  1689     return reinterpret_cast<uchar*>(mem);
  1677 }
  1690 }
  1678 
  1691 
       
  1692 static inline bool isFullUpdate(IDirectFBSurface *surface, const QRegion &region, const QPoint &offset)
       
  1693 {
       
  1694     if (offset == QPoint(0, 0) && region.rectCount() == 1) {
       
  1695 	QSize size;
       
  1696 	surface->GetSize(surface, &size.rwidth(), &size.rheight());
       
  1697 	if (region.boundingRect().size() == size)
       
  1698 	    return true;
       
  1699     }
       
  1700     return false;
       
  1701 }
  1679 
  1702 
  1680 void QDirectFBScreen::flipSurface(IDirectFBSurface *surface, DFBSurfaceFlipFlags flipFlags,
  1703 void QDirectFBScreen::flipSurface(IDirectFBSurface *surface, DFBSurfaceFlipFlags flipFlags,
  1681                                   const QRegion &region, const QPoint &offset)
  1704                                   const QRegion &region, const QPoint &offset)
  1682 {
  1705 {
  1683     if (!(flipFlags & DSFLIP_BLIT)) {
  1706     if (d_ptr->directFBFlags & NoPartialFlip
       
  1707         || (!(flipFlags & DSFLIP_BLIT) && QT_PREPEND_NAMESPACE(isFullUpdate(surface, region, offset)))) {
  1684         surface->Flip(surface, 0, flipFlags);
  1708         surface->Flip(surface, 0, flipFlags);
  1685     } else {
  1709     } else {
  1686         if (!(d_ptr->directFBFlags & BoundingRectFlip) && region.rectCount() > 1) {
  1710         if (!(d_ptr->directFBFlags & BoundingRectFlip) && region.rectCount() > 1) {
  1687             const QVector<QRect> rects = region.rects();
  1711             const QVector<QRect> rects = region.rects();
  1688             const DFBSurfaceFlipFlags nonWaitFlags = flipFlags & ~DSFLIP_WAIT;
  1712             const DFBSurfaceFlipFlags nonWaitFlags = flipFlags & ~DSFLIP_WAIT;