summaryrefslogtreecommitdiffstats
path: root/src/gui/painting
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar@trolltech.com>2009-12-01 08:18:47 (GMT)
committerGunnar Sletta <gunnar@trolltech.com>2009-12-01 11:40:36 (GMT)
commitdbfdfdb1bc37dd18dd1b723b5d5b0b65c37f3f41 (patch)
treeff1ca3a0e5e9555111cb60a05009b60cd27f07bf /src/gui/painting
parentb5b9faa7cdc877f8ab32a8d5ae480b5857761409 (diff)
downloadQt-dbfdfdb1bc37dd18dd1b723b5d5b0b65c37f3f41.zip
Qt-dbfdfdb1bc37dd18dd1b723b5d5b0b65c37f3f41.tar.gz
Qt-dbfdfdb1bc37dd18dd1b723b5d5b0b65c37f3f41.tar.bz2
Added caching of vectorpaths to the GL paint engine.
The first time a path is drawn we call makeCachable on the path, which means that if it is drawn again, we start caching it. This is a bit of a trick to avoid caching paths that are drawn once and discared while at the same time cache paths that are reused automatically. The GL engine owns the vertex information and is responsible for cleaning it up. If the vectorpath is destroyed first, it will call the cleanup function. if the engine dies first, we still require some hooks to clean up the cache in the path. More to come. When VBO's are used, these will be a leaked if the path is destroyed after the engine. Reviewed-by: Samuel
Diffstat (limited to 'src/gui/painting')
-rw-r--r--src/gui/painting/qpaintengineex.cpp16
-rw-r--r--src/gui/painting/qvectorpath_p.h13
2 files changed, 23 insertions, 6 deletions
diff --git a/src/gui/painting/qpaintengineex.cpp b/src/gui/painting/qpaintengineex.cpp
index 7d1c109..9a0e319 100644
--- a/src/gui/painting/qpaintengineex.cpp
+++ b/src/gui/painting/qpaintengineex.cpp
@@ -56,6 +56,20 @@ QT_BEGIN_NAMESPACE
* class QVectorPath
*
*/
+QVectorPath::~QVectorPath()
+{
+ if (m_hints & ShouldUseCacheHint) {
+ CacheEntry *e = m_cache;
+ while (e) {
+ if (e->data)
+ e->cleanup(e->engine, e->data);
+ CacheEntry *n = e->next;
+ delete e;
+ e = n;
+ }
+ }
+}
+
QRectF QVectorPath::controlPointRect() const
{
@@ -94,7 +108,7 @@ QRectF QVectorPath::controlPointRect() const
QVectorPath::CacheEntry *QVectorPath::addCacheData(QPaintEngineEx *engine, void *data,
- qvectorpath_cache_cleanup cleanup) {
+ qvectorpath_cache_cleanup cleanup) const{
Q_ASSERT(!lookupCacheData(engine));
if ((m_hints & IsCachedHint) == 0) {
m_cache = 0;
diff --git a/src/gui/painting/qvectorpath_p.h b/src/gui/painting/qvectorpath_p.h
index ec27970..5eaddf4 100644
--- a/src/gui/painting/qvectorpath_p.h
+++ b/src/gui/painting/qvectorpath_p.h
@@ -68,7 +68,7 @@ QT_MODULE(Gui)
class QPaintEngineEx;
-typedef void (*qvectorpath_cache_cleanup)(void *data);
+typedef void (*qvectorpath_cache_cleanup)(QPaintEngineEx *engine, void *data);
struct QRealRect {
qreal x1, y1, x2, y2;
@@ -118,6 +118,8 @@ public:
{
}
+ ~QVectorPath();
+
QRectF controlPointRect() const;
inline Hint shape() const { return (Hint) (m_hints & ShapeMask); }
@@ -128,6 +130,7 @@ public:
inline bool hasImplicitClose() const { return m_hints & ImplicitClose; }
inline bool hasWindingFill() const { return m_hints & WindingFill; }
+ inline void makeCacheable() const { m_hints |= ShouldUseCacheHint; m_cache = 0; }
inline uint hints() const { return m_hints; }
inline const QPainterPath::ElementType *elements() const { return m_elements; }
@@ -146,9 +149,9 @@ public:
CacheEntry *next;
};
- CacheEntry *addCacheData(QPaintEngineEx *engine, void *data, qvectorpath_cache_cleanup cleanup);
+ CacheEntry *addCacheData(QPaintEngineEx *engine, void *data, qvectorpath_cache_cleanup cleanup) const;
inline CacheEntry *lookupCacheData(QPaintEngineEx *engine) const {
- Q_ASSERT(m_hints & IsCachedHint);
+ Q_ASSERT(m_hints & ShouldUseCacheHint);
CacheEntry *e = m_cache;
while (e) {
if (e->engine == engine)
@@ -162,14 +165,14 @@ public:
private:
Q_DISABLE_COPY(QVectorPath)
- CacheEntry *m_cache;
-
const QPainterPath::ElementType *m_elements;
const qreal *m_points;
const int m_count;
mutable uint m_hints;
mutable QRealRect m_cp_rect;
+
+ mutable CacheEntry *m_cache;
};
Q_GUI_EXPORT const QVectorPath &qtVectorPathForPath(const QPainterPath &path);