Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I optimize the performance of a QGraphicsView-based app?

I have an app which is based on the Qt Graphics View framework.
It's a jigsaw puzzle game which basically cuts a pixmap into smaller pixmaps (puzzle pieces) and displays them as QGraphicsItems in a QGraphicsView. I want this app to run on smartphones and tablets. (It already runs on the Nokia N900 and some Symbian phones. Not optimized for Symbian^3 yet.)
The source is on Gitorious.

The items inherit QGraphicsItem and QObject, and have Q_PROPERTY macros for the pos() and rotation() of the QGraphicsItem to enable animating them with the Qt Animation framework.
I perform transformations on the items, such as scaling and rotating (the latter only in the in-development multitouch branch), and I also use QGraphicsDropShadowEffect on them.

I use a QGLWidget as viewport of the QGraphicsView in order to enable OpenGL acceleration for the app.

The problem is that despite being OpenGL-accelerated, the app is not smooth at all. (Especially the animations and especially since I added the rotation transform to the multitouch branch.) There are not many graphics items displayed, and there are no 3D operations or anything serious, just 2D drawing.
I'm not a graphics expert at all, so I have no idea why this app runs slowly. I've seen other games with lot more complicated effects run a lot smoother than this.

What's the secret? How could I optimize this app?

like image 791
Venemo Avatar asked Oct 11 '11 11:10

Venemo


1 Answers

Okay, I've waited for this long for a solution.

In the meantime, I've rewritten the app's UI in QML, and to my surprise, the performance is a LOT better and the app is very smooth now.

Some conclusions:

  • OpenGL acceleration is best when running in full-screen mode. Having the whole UI in a QDeclarativeView and setting its viewPort to a QGLWidget, and displaying it in fullscreen make this possible.
  • It seems that the overhead of QWidgets is a lot more than we had thought.
  • QML can perform a lot better than expected.
  • The impact of the QGraphicsDropshadowEffect was marginal, but I removed it and now I use a stroke effect instead. In the future, I might consider using QML shader effects.
  • It's worth to set all kinds of optimalization flags for the QDeclarativeView
  • Drawing items with alpha transparency performs a lot worse than drawing them without. Avoid alpha transparency whenever possible.
  • Rewriting a QGraphicsItem subclass to be a QDeclarativeItem subclass is really easy and worth the effort.

Source code is here.

like image 89
Venemo Avatar answered Oct 03 '22 01:10

Venemo