From 5c36257e21d00106e36f5b68eea78507efc3f39c Mon Sep 17 00:00:00 2001 From: Anders Bakken Date: Thu, 9 Apr 2009 16:55:48 -0700 Subject: Beautify displayArgs parsing Also add support for setting the width and height of the primary surface using display arguments (which can be good when debugging performace issues). Reviewed-by: Donald --- .../gfxdrivers/directfb/qdirectfbscreen.cpp | 30 +++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp index a230bf9..041d522 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp @@ -772,6 +772,18 @@ static void printDirectFBInfo(IDirectFB *fb) dev.blitting_flags, dev.drawing_flags, dev.video_memory); } +static inline bool setIntOption(const QStringList &arguments, const QString &variable, int *value) +{ + Q_ASSERT(value); + QRegExp rx(QString("%1=?(\\d+)").arg(variable)); + rx.setCaseSensitivity(Qt::CaseInsensitive); + if (arguments.indexOf(rx) != -1) { + *value = rx.cap(1).toInt(); + return true; + } + return false; +} + bool QDirectFBScreen::connect(const QString &displaySpec) { DFBResult result = DFB_OK; @@ -817,6 +829,10 @@ bool QDirectFBScreen::connect(const QString &displaySpec) DFBSurfaceDescription description; description.flags = DFBSurfaceDescriptionFlags(DSDESC_CAPS); + if (::setIntOption(displayArgs, QLatin1String("width"), &description.width)) + description.flags = DFBSurfaceDescriptionFlags(description.flags | DSDESC_WIDTH); + if (::setIntOption(displayArgs, QLatin1String("height"), &description.height)) + description.flags = DFBSurfaceDescriptionFlags(description.flags | DSDESC_HEIGHT); description.caps = DFBSurfaceCapabilities(DSCAPS_PRIMARY | DSCAPS_DOUBLE | DSCAPS_STATIC_ALLOC); @@ -882,18 +898,8 @@ bool QDirectFBScreen::connect(const QString &displaySpec) setPixelFormat(getImageFormat(d_ptr->dfbSurface)); physWidth = physHeight = -1; - QRegExp mmWidthRx(QLatin1String("mmWidth=?(\\d+)")); - int dimIdxW = displayArgs.indexOf(mmWidthRx); - if (dimIdxW >= 0) { - mmWidthRx.exactMatch(displayArgs.at(dimIdxW)); - physWidth = mmWidthRx.cap(1).toInt(); - } - QRegExp mmHeightRx(QLatin1String("mmHeight=?(\\d+)")); - int dimIdxH = displayArgs.indexOf(mmHeightRx); - if (dimIdxH >= 0) { - mmHeightRx.exactMatch(displayArgs.at(dimIdxH)); - physHeight = mmHeightRx.cap(1).toInt(); - } + ::setIntOption(displayArgs, QLatin1String("mmWidth"), &physWidth); + ::setIntOption(displayArgs, QLatin1String("mmHeight"), &physHeight); const int dpi = 72; if (physWidth < 0) physWidth = qRound(dw * 25.4 / dpi); -- cgit v0.12