src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   129 {
   129 {
   130 #ifndef QT_NO_QWS_SIGNALHANDLER
   130 #ifndef QT_NO_QWS_SIGNALHANDLER
   131     QWSSignalHandler::instance()->addObject(this);
   131     QWSSignalHandler::instance()->addObject(this);
   132 #endif
   132 #endif
   133 #ifdef QT_DIRECTFB_WM
   133 #ifdef QT_DIRECTFB_WM
   134     connect(QWSServer::instance(), SIGNAL(windowEvent(QWSWindow*, QWSServer::WindowEvent)),
   134     connect(QWSServer::instance(), SIGNAL(windowEvent(QWSWindow*,QWSServer::WindowEvent)),
   135             this, SLOT(onWindowEvent(QWSWindow*, QWSServer::WindowEvent)));
   135             this, SLOT(onWindowEvent(QWSWindow*,QWSServer::WindowEvent)));
   136 #endif
   136 #endif
   137 }
   137 }
   138 
   138 
   139 QDirectFBScreenPrivate::~QDirectFBScreenPrivate()
   139 QDirectFBScreenPrivate::~QDirectFBScreenPrivate()
   140 {
   140 {
   212         uchar *mem = QDirectFBScreen::lockSurface(surface, DSLF_WRITE, &bplDFB);
   212         uchar *mem = QDirectFBScreen::lockSurface(surface, DSLF_WRITE, &bplDFB);
   213         if (mem) {
   213         if (mem) {
   214             const int height = image.height();
   214             const int height = image.height();
   215             const int bplQt = image.bytesPerLine();
   215             const int bplQt = image.bytesPerLine();
   216             if (bplQt == bplDFB && bplQt == (image.width() * image.depth() / 8)) {
   216             if (bplQt == bplDFB && bplQt == (image.width() * image.depth() / 8)) {
   217                 memcpy(mem, image.bits(), image.numBytes());
   217                 memcpy(mem, image.bits(), image.byteCount());
   218             } else {
   218             } else {
   219                 for (int i=0; i<height; ++i) {
   219                 for (int i=0; i<height; ++i) {
   220                     memcpy(mem, image.scanLine(i), bplQt);
   220                     memcpy(mem, image.scanLine(i), bplQt);
   221                     mem += bplDFB;
   221                     mem += bplDFB;
   222                 }
   222                 }
   223             }
   223             }
   224             surface->Unlock(surface);
   224             surface->Unlock(surface);
   225         }
   225         }
   226     }
   226     }
   227 #ifdef QT_DIRECTFB_PALETTE
   227 #ifdef QT_DIRECTFB_PALETTE
   228     if (image.numColors() != 0 && surface)
   228     if (image.colorCount() != 0 && surface)
   229         QDirectFBScreen::setSurfaceColorTable(surface, image);
   229         QDirectFBScreen::setSurfaceColorTable(surface, image);
   230 #endif
   230 #endif
   231     return surface;
   231     return surface;
   232 }
   232 }
   233 
   233 
   495                                            const QImage &image)
   495                                            const QImage &image)
   496 {
   496 {
   497     if (!surface)
   497     if (!surface)
   498         return;
   498         return;
   499 
   499 
   500     const int numColors = image.numColors();
   500     const int numColors = image.colorCount();
   501     if (numColors == 0)
   501     if (numColors == 0)
   502         return;
   502         return;
   503 
   503 
   504     QVarLengthArray<DFBColor, 256> colors(numColors);
   504     QVarLengthArray<DFBColor, 256> colors(numColors);
   505     for (int i = 0; i < numColors; ++i) {
   505     for (int i = 0; i < numColors; ++i) {
   956     const char *name;
   956     const char *name;
   957     uint flag;
   957     uint flag;
   958 };
   958 };
   959 
   959 
   960 static const FlagDescription accelerationDescriptions[] = {
   960 static const FlagDescription accelerationDescriptions[] = {
   961     { " DFXL_NONE ", DFXL_NONE },
   961     { "DFXL_NONE", DFXL_NONE },
   962     { " DFXL_FILLRECTANGLE", DFXL_FILLRECTANGLE },
   962     { "DFXL_FILLRECTANGLE", DFXL_FILLRECTANGLE },
   963     { " DFXL_DRAWRECTANGLE", DFXL_DRAWRECTANGLE },
   963     { "DFXL_DRAWRECTANGLE", DFXL_DRAWRECTANGLE },
   964     { " DFXL_DRAWLINE", DFXL_DRAWLINE },
   964     { "DFXL_DRAWLINE", DFXL_DRAWLINE },
   965     { " DFXL_FILLTRIANGLE", DFXL_FILLTRIANGLE },
   965     { "DFXL_FILLTRIANGLE", DFXL_FILLTRIANGLE },
   966     { " DFXL_BLIT", DFXL_BLIT },
   966     { "DFXL_BLIT", DFXL_BLIT },
   967     { " DFXL_STRETCHBLIT", DFXL_STRETCHBLIT },
   967     { "DFXL_STRETCHBLIT", DFXL_STRETCHBLIT },
   968     { " DFXL_TEXTRIANGLES", DFXL_TEXTRIANGLES },
   968     { "DFXL_TEXTRIANGLES", DFXL_TEXTRIANGLES },
   969     { " DFXL_DRAWSTRING", DFXL_DRAWSTRING },
   969     { "DFXL_DRAWSTRING", DFXL_DRAWSTRING },
   970     { 0, 0 }
   970     { 0, 0 }
   971 };
   971 };
   972 
   972 
   973 static const FlagDescription blitDescriptions[] = {
   973 static const FlagDescription blitDescriptions[] = {
   974     { " DSBLIT_NOFX", DSBLIT_NOFX },
   974     { "DSBLIT_NOFX", DSBLIT_NOFX },
   975     { " DSBLIT_BLEND_ALPHACHANNEL", DSBLIT_BLEND_ALPHACHANNEL },
   975     { "DSBLIT_BLEND_ALPHACHANNEL", DSBLIT_BLEND_ALPHACHANNEL },
   976     { " DSBLIT_BLEND_COLORALPHA", DSBLIT_BLEND_COLORALPHA },
   976     { "DSBLIT_BLEND_COLORALPHA", DSBLIT_BLEND_COLORALPHA },
   977     { " DSBLIT_COLORIZE", DSBLIT_COLORIZE },
   977     { "DSBLIT_COLORIZE", DSBLIT_COLORIZE },
   978     { " DSBLIT_SRC_COLORKEY", DSBLIT_SRC_COLORKEY },
   978     { "DSBLIT_SRC_COLORKEY", DSBLIT_SRC_COLORKEY },
   979     { " DSBLIT_DST_COLORKEY", DSBLIT_DST_COLORKEY },
   979     { "DSBLIT_DST_COLORKEY", DSBLIT_DST_COLORKEY },
   980     { " DSBLIT_SRC_PREMULTIPLY", DSBLIT_SRC_PREMULTIPLY },
   980     { "DSBLIT_SRC_PREMULTIPLY", DSBLIT_SRC_PREMULTIPLY },
   981     { " DSBLIT_DST_PREMULTIPLY", DSBLIT_DST_PREMULTIPLY },
   981     { "DSBLIT_DST_PREMULTIPLY", DSBLIT_DST_PREMULTIPLY },
   982     { " DSBLIT_DEMULTIPLY", DSBLIT_DEMULTIPLY },
   982     { "DSBLIT_DEMULTIPLY", DSBLIT_DEMULTIPLY },
   983     { " DSBLIT_DEINTERLACE", DSBLIT_DEINTERLACE },
   983     { "DSBLIT_DEINTERLACE", DSBLIT_DEINTERLACE },
   984 #if (Q_DIRECTFB_VERSION >= 0x000923)
   984 #if (Q_DIRECTFB_VERSION >= 0x000923)
   985     { " DSBLIT_SRC_PREMULTCOLOR", DSBLIT_SRC_PREMULTCOLOR },
   985     { "DSBLIT_SRC_PREMULTCOLOR", DSBLIT_SRC_PREMULTCOLOR },
   986     { " DSBLIT_XOR", DSBLIT_XOR },
   986     { "DSBLIT_XOR", DSBLIT_XOR },
   987 #endif
   987 #endif
   988 #if (Q_DIRECTFB_VERSION >= 0x010000)
   988 #if (Q_DIRECTFB_VERSION >= 0x010000)
   989     { " DSBLIT_INDEX_TRANSLATION", DSBLIT_INDEX_TRANSLATION },
   989     { "DSBLIT_INDEX_TRANSLATION", DSBLIT_INDEX_TRANSLATION },
   990 #endif
   990 #endif
   991     { 0, 0 }
   991     { 0, 0 }
   992 };
   992 };
   993 
   993 
   994 static const FlagDescription drawDescriptions[] = {
   994 static const FlagDescription drawDescriptions[] = {
   995     { " DSDRAW_NOFX", DSDRAW_NOFX },
   995     { "DSDRAW_NOFX", DSDRAW_NOFX },
   996     { " DSDRAW_BLEND", DSDRAW_BLEND },
   996     { "DSDRAW_BLEND", DSDRAW_BLEND },
   997     { " DSDRAW_DST_COLORKEY", DSDRAW_DST_COLORKEY },
   997     { "DSDRAW_DST_COLORKEY", DSDRAW_DST_COLORKEY },
   998     { " DSDRAW_SRC_PREMULTIPLY", DSDRAW_SRC_PREMULTIPLY },
   998     { "DSDRAW_SRC_PREMULTIPLY", DSDRAW_SRC_PREMULTIPLY },
   999     { " DSDRAW_DST_PREMULTIPLY", DSDRAW_DST_PREMULTIPLY },
   999     { "DSDRAW_DST_PREMULTIPLY", DSDRAW_DST_PREMULTIPLY },
  1000     { " DSDRAW_DEMULTIPLY", DSDRAW_DEMULTIPLY },
  1000     { "DSDRAW_DEMULTIPLY", DSDRAW_DEMULTIPLY },
  1001     { " DSDRAW_XOR", DSDRAW_XOR },
  1001     { "DSDRAW_XOR", DSDRAW_XOR },
  1002     { 0, 0 }
  1002     { 0, 0 }
  1003 };
  1003 };
  1004 #endif
  1004 #endif
  1005 
  1005 
  1006 static const QByteArray flagDescriptions(uint mask, const FlagDescription *flags)
  1006 static const QByteArray flagDescriptions(uint mask, const FlagDescription *flags)
  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("#([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.numCaptures() == 4);
  1069         Q_ASSERT(rx.captureCount() == 4);
  1070         int ints[4];
  1070         int ints[4];
  1071         int i;
  1071         int i;
  1072         for (i=0; i<4; ++i) {
  1072         for (i=0; i<4; ++i) {
  1073             bool ok;
  1073             bool ok;
  1074             ints[i] = rx.cap(i + 1).toUInt(&ok, 16);
  1074             ints[i] = rx.cap(i + 1).toUInt(&ok, 16);
  1257 
  1257 
  1258     setIntOption(displayArgs, QLatin1String("width"), &w);
  1258     setIntOption(displayArgs, QLatin1String("width"), &w);
  1259     setIntOption(displayArgs, QLatin1String("height"), &h);
  1259     setIntOption(displayArgs, QLatin1String("height"), &h);
  1260 
  1260 
  1261 #ifndef QT_NO_DIRECTFB_LAYER
  1261 #ifndef QT_NO_DIRECTFB_LAYER
  1262     result = d_ptr->dfb->GetDisplayLayer(d_ptr->dfb, DLID_PRIMARY,
  1262     int layerId = DLID_PRIMARY;
       
  1263     setIntOption(displayArgs, QLatin1String("layerid"), &layerId);
       
  1264 
       
  1265     result = d_ptr->dfb->GetDisplayLayer(d_ptr->dfb, static_cast<DFBDisplayLayerID>(layerId),
  1263                                          &d_ptr->dfbLayer);
  1266                                          &d_ptr->dfbLayer);
  1264     if (result != DFB_OK) {
  1267     if (result != DFB_OK) {
  1265         DirectFBError("QDirectFBScreen::connect: "
  1268         DirectFBError("QDirectFBScreen::connect: "
  1266                       "Unable to get primary display layer!", result);
  1269                       "Unable to get display layer!", result);
  1267         return false;
  1270         return false;
  1268     }
  1271     }
  1269     result = d_ptr->dfbLayer->GetScreen(d_ptr->dfbLayer, &d_ptr->dfbScreen);
  1272     result = d_ptr->dfbLayer->GetScreen(d_ptr->dfbLayer, &d_ptr->dfbScreen);
  1270 #else
  1273 #else
  1271     result = d_ptr->dfb->GetScreen(d_ptr->dfb, 0, &d_ptr->dfbScreen);
  1274     result = d_ptr->dfb->GetScreen(d_ptr->dfb, 0, &d_ptr->dfbScreen);
  1562         primary->SetBlittingFlags(primary, cmd.blittingFlags);
  1565         primary->SetBlittingFlags(primary, cmd.blittingFlags);
  1563         if (cmd.blittingFlags & DSBLIT_BLEND_COLORALPHA) {
  1566         if (cmd.blittingFlags & DSBLIT_BLEND_COLORALPHA) {
  1564             primary->SetColor(primary, 0xff, 0xff, 0xff, cmd.windowOpacity);
  1567             primary->SetColor(primary, 0xff, 0xff, 0xff, cmd.windowOpacity);
  1565         }
  1568         }
  1566         const QRegion &region = cmd.source;
  1569         const QRegion &region = cmd.source;
  1567         const int rectCount = region.numRects();
  1570         const int rectCount = region.rectCount();
  1568         DFBRectangle source;
  1571         DFBRectangle source;
  1569         if (rectCount == 1) {
  1572         if (rectCount == 1) {
  1570             ::initParameters(source, region.boundingRect(), cmd.windowPosition);
  1573             ::initParameters(source, region.boundingRect(), cmd.windowPosition);
  1571             primary->Blit(primary, surface, &source, cmd.windowPosition.x() + source.x, cmd.windowPosition.y() + source.y);
  1574             primary->Blit(primary, surface, &source, cmd.windowPosition.x() + source.x, cmd.windowPosition.y() + source.y);
  1572         } else {
  1575         } else {
  1617         return;
  1620         return;
  1618 
  1621 
  1619     d_ptr->primarySurface->SetColor(d_ptr->primarySurface,
  1622     d_ptr->primarySurface->SetColor(d_ptr->primarySurface,
  1620                                     color.red(), color.green(), color.blue(),
  1623                                     color.red(), color.green(), color.blue(),
  1621                                     color.alpha());
  1624                                     color.alpha());
  1622     const int n = region.numRects();
  1625     const int n = region.rectCount();
  1623     if (n == 1) {
  1626     if (n == 1) {
  1624         const QRect r = region.boundingRect();
  1627         const QRect r = region.boundingRect();
  1625         d_ptr->primarySurface->FillRectangle(d_ptr->primarySurface, r.x(), r.y(), r.width(), r.height());
  1628         d_ptr->primarySurface->FillRectangle(d_ptr->primarySurface, r.x(), r.y(), r.width(), r.height());
  1626     } else {
  1629     } else {
  1627         const QVector<QRect> rects = region.rects();
  1630         const QVector<QRect> rects = region.rects();
  1678                                   const QRegion &region, const QPoint &offset)
  1681                                   const QRegion &region, const QPoint &offset)
  1679 {
  1682 {
  1680     if (!(flipFlags & DSFLIP_BLIT)) {
  1683     if (!(flipFlags & DSFLIP_BLIT)) {
  1681         surface->Flip(surface, 0, flipFlags);
  1684         surface->Flip(surface, 0, flipFlags);
  1682     } else {
  1685     } else {
  1683         if (!(d_ptr->directFBFlags & BoundingRectFlip) && region.numRects() > 1) {
  1686         if (!(d_ptr->directFBFlags & BoundingRectFlip) && region.rectCount() > 1) {
  1684             const QVector<QRect> rects = region.rects();
  1687             const QVector<QRect> rects = region.rects();
  1685             const DFBSurfaceFlipFlags nonWaitFlags = flipFlags & ~DSFLIP_WAIT;
  1688             const DFBSurfaceFlipFlags nonWaitFlags = flipFlags & ~DSFLIP_WAIT;
  1686             for (int i=0; i<rects.size(); ++i) {
  1689             for (int i=0; i<rects.size(); ++i) {
  1687                 const QRect &r = rects.at(i);
  1690                 const QRect &r = rects.at(i);
  1688                 const DFBRegion dfbReg = { r.x() + offset.x(), r.y() + offset.y(),
  1691                 const DFBRegion dfbReg = { r.x() + offset.x(), r.y() + offset.y(),