Index: trunk/src/gui/painting/qwindowsurface_pm.cpp
===================================================================
--- trunk/src/gui/painting/qwindowsurface_pm.cpp	(revision 740)
+++ trunk/src/gui/painting/qwindowsurface_pm.cpp	(revision 742)
@@ -255,4 +255,5 @@
 static char *diveFrameBuf = NULL;
 static bool diveHideMouse = false;
+static FOURCC diveBestBufFormat = 0;
 
 static LONG mousePtrSize = 0;
@@ -294,8 +295,6 @@
 // fourccToFormat(). If isFB is true, the selection is made for the direct
 // framebuffer access mode.
-static FOURCC fourccScreenToBuffer(FOURCC fourcc, bool isFB = false)
-{
-    Q_UNUSED(isFB);
-
+static FOURCC fourccScreenToBuffer(FOURCC fourcc, bool isFB)
+{
     // return it as is if supported by fourccToFormat()
     if (fourccToFormat(fourcc) != QImage::Format_Invalid)
@@ -313,4 +312,7 @@
 
     // in direct framebuffer access mode, we use BGR4 which should be faster
+    // (note that our color conversion table built in QPMDiveWindowSurface::create()
+    // only works with BGR4 for now so we must return it here otherwise the FB
+    // mode will be disabled)
     return FOURCC_BGR4;
 }
@@ -361,5 +363,6 @@
     // note that fccSrcColorFormat overrides the value specified during the
     // source buffer creation, so they must match
-    d->setup.fccSrcColorFormat = fourccScreenToBuffer(diveCaps.fccColorEncoding);
+    Q_ASSERT(diveBestBufFormat != 0);
+    d->setup.fccSrcColorFormat = diveBestBufFormat;
     d->setup.fccDstColorFormat = FOURCC_SCRN;
 
@@ -768,10 +771,11 @@
                          << ((char*)&diveCaps.fccColorEncoding)[3]);
 
-                FOURCC bestBufFormat = fourccScreenToBuffer(diveCaps.fccColorEncoding);
-                DEBUG(() << "bestBufFormat"
-                         << ((char*)&bestBufFormat)[0]
-                         << ((char*)&bestBufFormat)[1]
-                         << ((char*)&bestBufFormat)[2]
-                         << ((char*)&bestBufFormat)[3]);
+                diveBestBufFormat = fourccScreenToBuffer(diveCaps.fccColorEncoding,
+                                                         diveUseFB);
+                DEBUG(() << "diveBestBufFormat"
+                         << ((char*)&diveBestBufFormat)[0]
+                         << ((char*)&diveBestBufFormat)[1]
+                         << ((char*)&diveBestBufFormat)[2]
+                         << ((char*)&diveBestBufFormat)[3]);
 
                 if (diveUseFB) {
@@ -781,7 +785,7 @@
                         diveUseFB = false;
                     } else {
-                        if (bestBufFormat == diveCaps.fccColorEncoding) {
+                        if (diveBestBufFormat == diveCaps.fccColorEncoding) {
                             // no color conversion is required
-                        } else if (bestBufFormat == FOURCC_BGR4) {
+                        } else if (diveBestBufFormat == FOURCC_BGR4) {
                             // build the color conversion table
                             switch (diveCaps.fccColorEncoding) {
@@ -831,16 +835,19 @@
                         }
                     }
+
+                    if (!diveUseFB) {
+                        // we disabled FB, recalculate the best format
+                        diveBestBufFormat = fourccScreenToBuffer(diveCaps.fccColorEncoding,
+                                                                 diveUseFB);
+                        DEBUG(() << "diveBestBufFormat (final)"
+                                 << ((char*)&diveBestBufFormat)[0]
+                                 << ((char*)&diveBestBufFormat)[1]
+                                 << ((char*)&diveBestBufFormat)[2]
+                                 << ((char*)&diveBestBufFormat)[3]);
+                    }
                 }
 
                 if (!diveUseFB) {
-                    FOURCC bestBufFormat =
-                        fourccScreenToBuffer(diveCaps.fccColorEncoding);
-                    DEBUG(() << "bestBufFormat"
-                             << ((char*)&bestBufFormat)[0]
-                             << ((char*)&bestBufFormat)[1]
-                             << ((char*)&bestBufFormat)[2]
-                             << ((char*)&bestBufFormat)[3]);
-
-                    if (bestBufFormat == 0) {
+                    if (diveBestBufFormat == 0) {
                         // there is no working pixel format for the buffer for
                         // DiveBlitImage() to work correctly with the current screen
