summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qstatictext_p.h
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-01-29 15:53:39 (GMT)
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-01-29 15:53:39 (GMT)
commitda388773f581e251054abd037dc410ae52cfa69c (patch)
tree5801db3f2793ff9b9d418b25814db50880427550 /src/gui/text/qstatictext_p.h
parent951922772c0c5f8b8833c2793064f8c6ebeecd9c (diff)
downloadQt-da388773f581e251054abd037dc410ae52cfa69c.zip
Qt-da388773f581e251054abd037dc410ae52cfa69c.tar.gz
Qt-da388773f581e251054abd037dc410ae52cfa69c.tar.bz2
Improve performance of QStaticText on OpenGL by caching data on GPU
There's a big improvement to be seen in the OpenGL engine by caching the vertex data for the QStaticText in VBOs. In order to have the buffers properly disposed, I've implemented a userdata concept for QStaticTextItem. By default, the optimizations will be turned off, and can be turned on by using the useBackendOptimizations flag.
Diffstat (limited to 'src/gui/text/qstatictext_p.h')
-rw-r--r--src/gui/text/qstatictext_p.h59
1 files changed, 44 insertions, 15 deletions
diff --git a/src/gui/text/qstatictext_p.h b/src/gui/text/qstatictext_p.h
index 78f7896..bca59e0 100644
--- a/src/gui/text/qstatictext_p.h
+++ b/src/gui/text/qstatictext_p.h
@@ -57,10 +57,35 @@
QT_BEGIN_NAMESPACE
+class QStaticTextUserData
+{
+public:
+ enum Type {
+ NoUserData,
+ OpenGLUserData
+ };
+
+ QStaticTextUserData(Type t) : type(t) {}
+ virtual ~QStaticTextUserData() {}
+
+ Type type;
+};
+
class Q_GUI_EXPORT QStaticTextItem
{
public:
- QStaticTextItem() : chars(0), numChars(0), fontEngine(0) {}
+ QStaticTextItem() : chars(0), numChars(0), fontEngine(0), userData(0),
+ useBackendOptimizations(false), userDataNeedsUpdate(0) {}
+ ~QStaticTextItem() { delete userData; }
+
+ void setUserData(QStaticTextUserData *newUserData)
+ {
+ if (userData == newUserData)
+ return;
+
+ delete userData;
+ userData = newUserData;
+ }
QFixedPoint *glyphPositions; // 8 bytes per glyph
glyph_t *glyphs; // 4 bytes per glyph
@@ -73,8 +98,11 @@ public:
int numChars; // 4 bytes per item
QFontEngine *fontEngine; // 4 bytes per item
QFont font; // 8 bytes per item
+ QStaticTextUserData *userData; // 8 bytes per item
+ char useBackendOptimizations : 1; // 1 byte per item
+ char userDataNeedsUpdate : 1; //
// ================
- // 32 bytes per item
+ // 41 bytes per item
};
class QStaticText;
@@ -86,22 +114,23 @@ public:
void init();
- QAtomicInt ref; // 4 bytes per text
+ QAtomicInt ref; // 4 bytes per text
- QString text; // 4 bytes per text
- QFont font; // 8 bytes per text
- QSizeF size; // 16 bytes per text
- QPointF position; // 16 bytes per text
+ QString text; // 4 bytes per text
+ QFont font; // 8 bytes per text
+ QSizeF size; // 16 bytes per text
+ QPointF position; // 16 bytes per text
- QTransform matrix; // 80 bytes per text
- QStaticTextItem *items; // 4 bytes per text
- int itemCount; // 4 bytes per text
- glyph_t *glyphPool; // 4 bytes per text
- QFixedPoint *positionPool; // 4 bytes per text
+ QTransform matrix; // 80 bytes per text
+ QStaticTextItem *items; // 4 bytes per text
+ int itemCount; // 4 bytes per text
+ glyph_t *glyphPool; // 4 bytes per text
+ QFixedPoint *positionPool; // 4 bytes per text
- char needsClipRect : 1; // 1 byte per text
- // ================
- // 145 bytes per text
+ char needsClipRect : 1; // 1 byte per text
+ char useBackendOptimizations : 1;
+ // ================
+ // 145 bytes per text
static QStaticTextPrivate *get(const QStaticText *q);
};