A9am
18th June 2013, 14:14
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
wysota
18th June 2013, 22:31
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.
A9am
19th June 2013, 05:36
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 */
wysota
19th June 2013, 06:17
Where are you calling updateWindow()? Why are you calling repaint() from within that code? Why are you setting clipping?
anda_skoa
19th June 2013, 07:48
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,
_
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.