Results 1 to 5 of 5

Thread: Qt and GTK performance

  1. #1
    Join Date
    Oct 2011
    Posts
    48
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Qt and GTK performance

    Hi,

    I am drawing an underlay and overlay pixmaps and compositing the layers on to a window. I have two different codes using Qt and GTK. My system configuration is;

    OS - RHEL 6.0
    Graphics card - Nvidia GeForce GTX650Ti
    Qt Version - 4.8.4

    The composite time of the pixmaps in Qt is more than GTK.Even the CPU load is more

    CPU LOAD Draw Time Composite Time Total Time

    Qt-4.8.4 29 % 1.00 ms 12.410 ms 13.410 ms

    GTK 1 – 2 % 0.04 ms 0.00 ms 0.04 ms



    Kindly suggest the solution. How to increase the performance in Qt?

    Thanks ,
    Anu

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt and GTK performance

    Qt and GTK differ in their nature, you can just rewrite the code for the other framework using the same semantics and expect a similar behaviour. Without you showing us your code or at least describing what it does there is nothing we can do.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2011
    Posts
    48
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt and GTK performance

    Hi,

    Please find the codes.


    Qt :

    void MainWindow::updateUlayPixmap(void)
    {
    /* Remember last position. */
    static int xPos = 0;

    if (m_ulayPixmap)
    {
    /* Get window size. */
    QRect winRect = m_ui->gfxWidget->rect();

    /* Create painter. */
    QPainter ulayPainter(m_ulayPixmap);
    ulayPainter.setClipRegion(winRect);

    /* Clear to black. */
    ulayPainter.fillRect(winRect, Qt::black);

    /* Create some brushes. */
    QBrush fgBrush(QColor(255, 255, 0, 255));

    /* Draw vertical bar. */
    int boxW = 50;
    int boxH = winRect.height();
    ulayPainter.fillRect(xPos, 0, boxW, boxH, fgBrush);

    /* Update box position. */
    xPos = (xPos + 2) % winRect.width();

    /* Finished rendering. */
    ulayPainter.end();
    }

    } /* MainWindow::updateUlayPixmap() */


    void MainWindow::updateOlayPixmap(void)
    {
    /* Remember last position. */
    static int yPos = 0;

    if (m_olayPixmap)
    {
    /* Get window size. */
    QRect winRect = m_ui->gfxWidget->rect();

    /* Create painter. */
    QPainter olayPainter(m_olayPixmap);
    olayPainter.setClipRegion(winRect);

    /* Configure painter to preserve alpha in rendered graphics. */
    olayPainter.setCompositionMode(QPainter::Compositi onMode_Source);

    /* Set clip region. */
    olayPainter.setClipRegion(winRect);

    /* Clear to transparent. */
    olayPainter.fillRect(winRect, Qt::transparent);

    /* Create some brushes. */
    QBrush fgBrush(QColor(255, 0, 0, 128));

    /* Draw horizontal bar. */
    int boxW = winRect.width();
    int boxH = 50;
    olayPainter.fillRect(0, yPos, boxW, boxH, fgBrush);

    /* Update box position. */
    yPos = (yPos + 2) % winRect.height();

    /* Finished rendering. */
    olayPainter.end();
    }

    } /* MainWindow::updateOlayPixmap() */

    void MainWindow::updateWindow(void)
    {
    static unsigned int updateCount = 0;
    static UINT32 drawTimeMsecs = 0;
    static UINT32 compositeTimeMsecs = 0;

    /* Redraw pixmaps. */
    UINT32 start = GetTickerMsecs();
    updateUlayPixmap();
    updateOlayPixmap();
    drawTimeMsecs += GetTimeDiff(start, GetTickerMsecs());

    /* Update graphics window. */
    start = GetTickerMsecs();
    m_ui->gfxWidget->repaint();
    compositeTimeMsecs += GetTimeDiff(start, GetTickerMsecs());

    /* Update count. */
    updateCount++;

    if (updateCount == 100)
    {
    /* Report times. */
    printf("Average draw time = %.3fms, ", drawTimeMsecs / 100.0);
    printf("composite time = %.3fms, ", compositeTimeMsecs / 100.0);
    printf("total = %.3fms\n",
    (drawTimeMsecs + compositeTimeMsecs) / 100.0);

    fflush(stdout);

    /* Reset. */
    updateCount = 0;
    drawTimeMsecs = 0;
    compositeTimeMsecs = 0;
    }

    } /* MainWindow::updateWindow() */












    GTK:


    static gboolean mainLoopTimer(gpointer data)
    {
    static unsigned int updateCount = 0;
    static UINT32 drawTimeMsecs = 0;
    static UINT32 compositeTimeMsecs = 0;

    /* Redraw pixmaps. */
    UINT32 start = GetTickerMsecs();
    updateUlayPixmap();
    updateOlayPixmap();
    drawTimeMsecs += GetTimeDiff(start, GetTickerMsecs());

    /* Update graphics window. */
    start = GetTickerMsecs();
    compositePixmaps();
    compositeTimeMsecs += GetTimeDiff(start, GetTickerMsecs());

    /* Update count. */
    updateCount++;

    if (updateCount == 100)
    {
    /* Report times. */
    printf("Average draw time = %.3fms, ", drawTimeMsecs / 100.0);
    printf("composite time = %.3fms, ", compositeTimeMsecs / 100.0);
    printf("total = %.3fms\n",
    (drawTimeMsecs + compositeTimeMsecs) / 100.0);
    fflush(stdout);

    /* Reset. */
    updateCount = 0;
    drawTimeMsecs = 0;
    compositeTimeMsecs = 0;
    }

    /* We want to be called again next time. */
    return(TRUE);

    } /* mainLoopTimer() */

    static void updateUlayPixmap(void)
    {
    /* Remember last position. */
    static int xPos = 0;

    if (Ulay24Pixmap)
    {
    /* Get the GFX window width and height */
    int width = GfxDrawingArea->allocation.width;
    int height = GfxDrawingArea->allocation.height;

    /* Create and configure cairo drawing context */
    cairo_t *cr = gdk_cairo_create(Ulay24Pixmap);

    /* Clear to black. */
    cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
    cairo_rectangle(cr, 0.0, 0.0, width, height);
    cairo_fill(cr);

    /* Draw horizontal bar. */
    int boxW = 50;
    int boxH = height;
    cairo_set_source_rgb(cr, 1.0, 1.0, 0.0);
    cairo_rectangle(cr, xPos, 0, boxW, boxH);
    cairo_fill(cr);

    /* Update box position. */
    xPos = (xPos + 2) % width;

    /* Clean up */
    cairo_destroy(cr);
    }

    } /* updateUlayPixmap */

    static void updateOlayPixmap(void)
    {
    /* Remember last position. */
    static int yPos = 0;

    if (Olay32Pixmap)
    {
    /* Get the GFX window width and height */
    int width = GfxDrawingArea->allocation.width;
    int height = GfxDrawingArea->allocation.height;

    /* Create and configure cairo drawing context.
    * Note that 'source' mode must be selected otherwise
    * cairo will blend with the existing pixmap data rather
    * than overwrite.
    */
    cairo_t *cr = gdk_cairo_create(Olay32Pixmap);
    cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);

    /* Clear the background to transparent. */
    cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
    cairo_rectangle(cr, 0.0, 0,width, height);
    cairo_fill(cr);

    /* Draw horizontal bar. */
    int boxW = width;
    int boxH = 50;
    cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.5);
    cairo_rectangle(cr, 0, yPos, boxW, boxH);
    cairo_fill(cr);

    /* Update box position. */
    yPos = (yPos + 2) % height;

    /* Clean up */
    cairo_destroy(cr);
    }

    } /* updateOlayPixmap */

    static void compositePixmaps(void)
    {
    if (Ulay24Pixmap && OlayPicture && CombPicture && GfxWin)
    {
    /* Get the GFX window width and height */
    int width = GfxDrawingArea->allocation.width;
    int height = GfxDrawingArea->allocation.height;

    /* Copy underlay pixmap to combined pixmap. */
    gdk_draw_drawable(Comb24Pixmap,
    Comb24PixmapGC,
    Ulay24Pixmap,
    0, 0,
    0, 0,
    width, height);

    /* Copy overlay graphics into combined pixmap. */
    XRenderComposite(X11Display,
    PictOpOver,
    OlayPicture,
    None,
    CombPicture,
    0, 0,
    0, 0,
    0, 0,
    width, height);

    /* Render combined pixmap to the window. */
    gdk_draw_drawable(GfxWin,
    GfxWinGC,
    Comb24Pixmap,
    0, 0,
    0, 0,
    width, height);
    }

    } /* compositePixmaps */

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt and GTK performance

    Where are you calling updateWindow()? Why are you calling repaint() from within that code? Why are you setting clipping?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt and GTK performance

    One difference seems to be that the Qt code is applying a clip region, thus having to do an inside/outside test for every pixel it draws, while the GTK version doesn't

    Cheers,
    _

Similar Threads

  1. Qt GUI Performance Help!
    By SeppBauer in forum Qt for Embedded and Mobile
    Replies: 4
    Last Post: 27th July 2013, 06:18
  2. Qwt Performance
    By liran ritkop in forum Qwt
    Replies: 1
    Last Post: 27th April 2011, 15:28
  3. Performance
    By manojmka in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 8th March 2010, 21:00
  4. Qt performance
    By yagabey in forum Qt Programming
    Replies: 3
    Last Post: 22nd October 2008, 23:05
  5. UDP Performance bad
    By tigertap in forum Qt Programming
    Replies: 5
    Last Post: 17th March 2008, 17:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.