src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp
changeset 37 758a864f9613
parent 30 5dc02b23752f
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
   165     }
   165     }
   166 };
   166 };
   167 static QCache<qint64, CachedImage> imageCache(4*1024*1024); // 4 MB
   167 static QCache<qint64, CachedImage> imageCache(4*1024*1024); // 4 MB
   168 #endif
   168 #endif
   169 
   169 
   170 #if defined QT_DIRECTFB_WARN_ON_RASTERFALLBACKS || defined QT_DIRECTFB_DISABLE_RASTERFALLBACKS || defined QT_DEBUG
       
   171 #define VOID_ARG() static_cast<bool>(false)
   170 #define VOID_ARG() static_cast<bool>(false)
   172 enum PaintOperation {
   171 enum PaintOperation {
   173     DRAW_RECTS = 0x0001, DRAW_LINES = 0x0002, DRAW_IMAGE = 0x0004,
   172     DRAW_RECTS = 0x0001, DRAW_LINES = 0x0002, DRAW_IMAGE = 0x0004,
   174     DRAW_PIXMAP = 0x0008, DRAW_TILED_PIXMAP = 0x0010, STROKE_PATH = 0x0020,
   173     DRAW_PIXMAP = 0x0008, DRAW_TILED_PIXMAP = 0x0010, STROKE_PATH = 0x0020,
   175     DRAW_PATH = 0x0040, DRAW_POINTS = 0x0080, DRAW_ELLIPSE = 0x0100,
   174     DRAW_PATH = 0x0040, DRAW_POINTS = 0x0080, DRAW_ELLIPSE = 0x0100,
   176     DRAW_POLYGON = 0x0200, DRAW_TEXT = 0x0400, FILL_PATH = 0x0800,
   175     DRAW_POLYGON = 0x0200, DRAW_TEXT = 0x0400, FILL_PATH = 0x0800,
   177     FILL_RECT = 0x1000, DRAW_COLORSPANS = 0x2000, DRAW_ROUNDED_RECT = 0x4000,
   176     FILL_RECT = 0x1000, DRAW_COLORSPANS = 0x2000, DRAW_ROUNDED_RECT = 0x4000,
   178     DRAW_STATICTEXT = 0x8000, ALL = 0xffff
   177     DRAW_STATICTEXT = 0x8000, ALL = 0xffff
   179 };
   178 };
   180 
   179 
   181 #ifdef QT_DEBUG
   180 enum { RasterWarn = 1, RasterDisable = 2 };
   182 static void initRasterFallbacksMasks(int *warningMask, int *disableMask)
   181 static inline uint rasterFallbacksMask(PaintOperation op)
   183 {
   182 {
   184     struct {
   183     uint ret = 0;
   185         const char *name;
   184 #ifdef QT_DIRECTFB_WARN_ON_RASTERFALLBACKS
   186         PaintOperation operation;
   185     if (op & QT_DIRECTFB_WARN_ON_RASTERFALLBACKS)
   187     } const operations[] = {
   186         ret |= RasterWarn;
   188         { "DRAW_RECTS", DRAW_RECTS },
   187 #endif
   189         { "DRAW_LINES", DRAW_LINES },
   188 #ifdef QT_DIRECTFB_DISABLE_RASTERFALLBACKS
   190         { "DRAW_IMAGE", DRAW_IMAGE },
   189     if (op & QT_DIRECTFB_DISABLE_RASTERFALLBACKS)
   191         { "DRAW_PIXMAP", DRAW_PIXMAP },
   190         ret |= RasterDisable;
   192         { "DRAW_TILED_PIXMAP", DRAW_TILED_PIXMAP },
   191 #endif
   193         { "STROKE_PATH", STROKE_PATH },
   192     static int warningMask = -1;
   194         { "DRAW_PATH", DRAW_PATH },
   193     static int disableMask = -1;
   195         { "DRAW_POINTS", DRAW_POINTS },
   194     if (warningMask < 0) {
   196         { "DRAW_ELLIPSE", DRAW_ELLIPSE },
   195         struct {
   197         { "DRAW_POLYGON", DRAW_POLYGON },
   196             const char *name;
   198         { "DRAW_TEXT", DRAW_TEXT },
   197             PaintOperation operation;
   199         { "FILL_PATH", FILL_PATH },
   198         } const operations[] = {
   200         { "FILL_RECT", FILL_RECT },
   199             { "DRAW_RECTS", DRAW_RECTS },
   201         { "DRAW_COLORSPANS", DRAW_COLORSPANS },
   200             { "DRAW_LINES", DRAW_LINES },
   202         { "DRAW_ROUNDED_RECT", DRAW_ROUNDED_RECT },
   201             { "DRAW_IMAGE", DRAW_IMAGE },
   203         { "ALL", ALL },
   202             { "DRAW_PIXMAP", DRAW_PIXMAP },
   204         { 0, ALL }
   203             { "DRAW_TILED_PIXMAP", DRAW_TILED_PIXMAP },
   205     };
   204             { "STROKE_PATH", STROKE_PATH },
   206 
   205             { "DRAW_PATH", DRAW_PATH },
   207     QStringList warning = QString::fromLatin1(qgetenv("QT_DIRECTFB_WARN_ON_RASTERFALLBACKS")).toUpper().split(QLatin1Char('|'),
   206             { "DRAW_POINTS", DRAW_POINTS },
   208                                                                                                               QString::SkipEmptyParts);
   207             { "DRAW_ELLIPSE", DRAW_ELLIPSE },
   209     QStringList disable = QString::fromLatin1(qgetenv("QT_DIRECTFB_DISABLE_RASTERFALLBACKS")).toUpper().split(QLatin1Char('|'),
   208             { "DRAW_POLYGON", DRAW_POLYGON },
   210                                                                                                               QString::SkipEmptyParts);
   209             { "DRAW_TEXT", DRAW_TEXT },
   211     *warningMask = 0;
   210             { "FILL_PATH", FILL_PATH },
   212     *disableMask = 0;
   211             { "FILL_RECT", FILL_RECT },
   213     if (!warning.isEmpty() || !disable.isEmpty()) {
   212             { "DRAW_COLORSPANS", DRAW_COLORSPANS },
   214         for (int i=0; operations[i].name; ++i) {
   213             { "DRAW_ROUNDED_RECT", DRAW_ROUNDED_RECT },
   215             const QString name = QString::fromLatin1(operations[i].name);
   214             { "ALL", ALL },
   216             int idx = warning.indexOf(name);
   215             { 0, ALL }
   217             if (idx != -1) {
   216         };
   218                 *warningMask |= operations[i].operation;
   217 
   219                 warning.erase(warning.begin() + idx);
   218         QStringList warning = QString::fromLatin1(qgetenv("QT_DIRECTFB_WARN_ON_RASTERFALLBACKS")).toUpper().split(QLatin1Char('|'),
   220             }
   219                                                                                                                   QString::SkipEmptyParts);
   221             idx = disable.indexOf(name);
   220         QStringList disable = QString::fromLatin1(qgetenv("QT_DIRECTFB_DISABLE_RASTERFALLBACKS")).toUpper().split(QLatin1Char('|'),
   222             if (idx != -1) {
   221                                                                                                                   QString::SkipEmptyParts);
   223                 *disableMask |= operations[i].operation;
   222         warningMask = 0;
   224                 disable.erase(disable.begin() + idx);
   223         disableMask = 0;
       
   224         if (!warning.isEmpty() || !disable.isEmpty()) {
       
   225             for (int i=0; operations[i].name; ++i) {
       
   226                 const QString name = QString::fromLatin1(operations[i].name);
       
   227                 int idx = warning.indexOf(name);
       
   228                 if (idx != -1) {
       
   229                     warningMask |= operations[i].operation;
       
   230                     warning.erase(warning.begin() + idx);
       
   231                 }
       
   232                 idx = disable.indexOf(name);
       
   233                 if (idx != -1) {
       
   234                     disableMask |= operations[i].operation;
       
   235                     disable.erase(disable.begin() + idx);
       
   236                 }
   225             }
   237             }
   226         }
   238         }
   227     }
   239         if (!warning.isEmpty()) {
   228     if (!warning.isEmpty()) {
   240             qWarning("QDirectFBPaintEngine QT_DIRECTFB_WARN_ON_RASTERFALLBACKS Unknown operation(s): %s",
   229         qWarning("QDirectFBPaintEngine QT_DIRECTFB_WARN_ON_RASTERFALLBACKS Unknown operation(s): %s",
   241                      qPrintable(warning.join(QLatin1String("|"))));
   230                  qPrintable(warning.join(QLatin1String("|"))));
   242         }
   231     }
   243         if (!disable.isEmpty()) {
   232     if (!disable.isEmpty()) {
   244             qWarning("QDirectFBPaintEngine QT_DIRECTFB_DISABLE_RASTERFALLBACKS Unknown operation(s): %s",
   233         qWarning("QDirectFBPaintEngine QT_DIRECTFB_DISABLE_RASTERFALLBACKS Unknown operation(s): %s",
   245                      qPrintable(disable.join(QLatin1String("|"))));
   234                  qPrintable(disable.join(QLatin1String("|"))));
   246         }
   235     }
   247     }
   236 
   248     if (op & warningMask)
   237 }
   249         ret |= RasterWarn;
   238 #endif
   250     if (op & disableMask)
   239 
   251         ret |= RasterDisable;
   240 static inline int rasterFallbacksMask(bool warn)
   252     return ret;
   241 {
   253 }
   242 #ifdef QT_DIRECTFB_WARN_ON_RASTERFALLBACKS
   254 
   243     if (warn)
       
   244         return QT_DIRECTFB_WARN_ON_RASTERFALLBACKS;
       
   245 #endif
       
   246 #ifdef QT_DIRECTFB_DISABLE_RASTERFALLBACKS
       
   247     if (!warn)
       
   248         return QT_DIRECTFB_DISABLE_RASTERFALLBACKS;
       
   249 #endif
       
   250 #ifndef QT_DEBUG
       
   251     return 0;
       
   252 #else
       
   253     static int warnMask = -1;
       
   254     static int disableMask = -1;
       
   255     if (warnMask == -1)
       
   256         initRasterFallbacksMasks(&warnMask, &disableMask);
       
   257     return warn ? warnMask : disableMask;
       
   258 #endif
       
   259 }
       
   260 #endif
       
   261 
       
   262 #if defined QT_DIRECTFB_WARN_ON_RASTERFALLBACKS || defined QT_DEBUG
       
   263 template <typename device, typename T1, typename T2, typename T3>
   255 template <typename device, typename T1, typename T2, typename T3>
   264 static void rasterFallbackWarn(const char *msg, const char *func, const device *dev,
   256 static void rasterFallbackWarn(const char *msg, const char *func, const device *dev,
   265                                uint transformationType, bool simplePen,
   257                                uint transformationType, bool simplePen,
   266                                uint clipType, uint compositionModeStatus,
   258                                uint clipType, uint compositionModeStatus,
   267                                const char *nameOne, const T1 &one,
   259                                const char *nameOne, const T1 &one,
   268                                const char *nameTwo, const T2 &two,
   260                                const char *nameTwo, const T2 &two,
   269                                const char *nameThree, const T3 &three);
   261                                const char *nameThree, const T3 &three);
   270 #endif
   262 
   271 
       
   272 #if defined QT_DEBUG || (defined QT_DIRECTFB_WARN_ON_RASTERFALLBACKS && defined QT_DIRECTFB_DISABLE_RASTERFALLBACKS)
       
   273 #define RASTERFALLBACK(op, one, two, three)                             \
   263 #define RASTERFALLBACK(op, one, two, three)                             \
   274     {                                                                   \
   264     {                                                                   \
   275         const bool disable = op & rasterFallbacksMask(false);           \
   265         static const uint rasterFallbacks = rasterFallbacksMask(op);    \
   276         if (op & rasterFallbacksMask(true))                             \
   266         switch (rasterFallbacks) {                                      \
   277             rasterFallbackWarn(disable                                  \
   267         case 0: break;                                                  \
   278                                ? "Disabled raster engine operation"     \
   268         case RasterWarn:                                                \
   279                                : "Falling back to raster engine for",   \
   269             rasterFallbackWarn("Falling back to raster engine for",     \
   280                                __FUNCTION__,                            \
   270                                __FUNCTION__,                            \
   281                                state()->painter->device(),              \
   271                                state()->painter->device(),              \
   282                                d_func()->transformationType,            \
   272                                d_func()->transformationType,            \
   283                                d_func()->simplePen,                     \
   273                                d_func()->simplePen,                     \
   284                                d_func()->clipType,                      \
   274                                d_func()->clipType,                      \
   285                                d_func()->compositionModeStatus,         \
   275                                d_func()->compositionModeStatus,         \
   286                                #one, one, #two, two, #three, three);    \
   276                                #one, one, #two, two, #three, three);    \
   287         if (disable)                                                    \
   277             break;                                                      \
       
   278         case RasterDisable|RasterWarn:                                  \
       
   279             rasterFallbackWarn("Disabled raster engine operation",      \
       
   280                                __FUNCTION__,                            \
       
   281                                state()->painter->device(),              \
       
   282                                d_func()->transformationType,            \
       
   283                                d_func()->simplePen,                     \
       
   284                                d_func()->clipType,                      \
       
   285                                d_func()->compositionModeStatus,         \
       
   286                                #one, one, #two, two, #three, three);    \
       
   287         case RasterDisable:                                             \
   288             return;                                                     \
   288             return;                                                     \
   289     }
   289         }                                                               \
   290 #elif defined QT_DIRECTFB_DISABLE_RASTERFALLBACKS
   290     }
   291 #define RASTERFALLBACK(op, one, two, three)                             \
       
   292     if (op & rasterFallbacksMask(false))                                \
       
   293         return;
       
   294 #elif defined QT_DIRECTFB_WARN_ON_RASTERFALLBACKS
       
   295 #define RASTERFALLBACK(op, one, two, three)                             \
       
   296     if (op & rasterFallbacksMask(true))                                 \
       
   297         rasterFallbackWarn("Falling back to raster engine for",         \
       
   298                            __FUNCTION__, state()->painter->device(),    \
       
   299                            d_func()->transformationType,                \
       
   300                            d_func()->simplePen,                         \
       
   301                            d_func()->clipType,                          \
       
   302                            d_func()->compositionModeStatus,             \
       
   303                            #one, one, #two, two, #three, three);
       
   304 #else
       
   305 #define RASTERFALLBACK(op, one, two, three)
       
   306 #endif
       
   307 
   291 
   308 template <class T>
   292 template <class T>
   309 static inline void drawLines(const T *lines, int n, const QTransform &transform, IDirectFBSurface *surface);
   293 static inline void drawLines(const T *lines, int n, const QTransform &transform, IDirectFBSurface *surface);
   310 template <class T>
   294 template <class T>
   311 static inline void fillRects(const T *rects, int n, const QTransform &transform, IDirectFBSurface *surface);
   295 static inline void fillRects(const T *rects, int n, const QTransform &transform, IDirectFBSurface *surface);
  1360         const QRect r = mapRect(transform, rects[i]);
  1344         const QRect r = mapRect(transform, rects[i]);
  1361         surface->DrawRectangle(surface, r.x(), r.y(), r.width(), r.height());
  1345         surface->DrawRectangle(surface, r.x(), r.y(), r.width(), r.height());
  1362     }
  1346     }
  1363 }
  1347 }
  1364 
  1348 
  1365 #if defined QT_DIRECTFB_WARN_ON_RASTERFALLBACKS || defined QT_DEBUG
       
  1366 template <typename T> inline const T *ptr(const T &t) { return &t; }
  1349 template <typename T> inline const T *ptr(const T &t) { return &t; }
  1367 template <> inline const bool* ptr<bool>(const bool &) { return 0; }
  1350 template <> inline const bool* ptr<bool>(const bool &) { return 0; }
  1368 template <typename device, typename T1, typename T2, typename T3>
  1351 template <typename device, typename T1, typename T2, typename T3>
  1369 static void rasterFallbackWarn(const char *msg, const char *func, const device *dev,
  1352 static void rasterFallbackWarn(const char *msg, const char *func, const device *dev,
  1370                                uint transformationType, bool simplePen,
  1353                                uint transformationType, bool simplePen,
  1401         }
  1384         }
  1402     }
  1385     }
  1403     qWarning("%s", qPrintable(out));
  1386     qWarning("%s", qPrintable(out));
  1404 }
  1387 }
  1405 
  1388 
  1406 #endif // QT_DIRECTFB_WARN_ON_RASTERFALLBACKS
       
  1407 
       
  1408 QT_END_NAMESPACE
  1389 QT_END_NAMESPACE
  1409 
  1390 
  1410 #endif // QT_NO_QWS_DIRECTFB
  1391 #endif // QT_NO_QWS_DIRECTFB