175 |
175 |
176 void init(QGLContext *context, const QGLWidget* shareWidget); |
176 void init(QGLContext *context, const QGLWidget* shareWidget); |
177 void initContext(QGLContext *context, const QGLWidget* shareWidget); |
177 void initContext(QGLContext *context, const QGLWidget* shareWidget); |
178 bool renderCxPm(QPixmap *pixmap); |
178 bool renderCxPm(QPixmap *pixmap); |
179 void cleanupColormaps(); |
179 void cleanupColormaps(); |
|
180 void aboutToDestroy() { |
|
181 if (glcx) |
|
182 glcx->reset(); |
|
183 } |
180 |
184 |
181 QGLContext *glcx; |
185 QGLContext *glcx; |
182 QGLWidgetGLPaintDevice glDevice; |
186 QGLWidgetGLPaintDevice glDevice; |
183 bool autoSwap; |
187 bool autoSwap; |
184 |
188 |
228 void removeGuard(QGLSharedResourceGuard *guard); |
232 void removeGuard(QGLSharedResourceGuard *guard); |
229 |
233 |
230 static void addShare(const QGLContext *context, const QGLContext *share); |
234 static void addShare(const QGLContext *context, const QGLContext *share); |
231 static void removeShare(const QGLContext *context); |
235 static void removeShare(const QGLContext *context); |
232 private: |
236 private: |
233 QGLContextGroup(const QGLContext *context) : m_context(context), m_guards(0), m_refs(1) { } |
237 QGLContextGroup(const QGLContext *context); |
234 |
238 |
235 QGLExtensionFuncs m_extensionFuncs; |
239 QGLExtensionFuncs m_extensionFuncs; |
236 const QGLContext *m_context; // context group's representative |
240 const QGLContext *m_context; // context group's representative |
237 QList<const QGLContext *> m_shares; |
241 QList<const QGLContext *> m_shares; |
238 QHash<QGLContextResource *, void *> m_resources; |
242 QHash<QGLContextResource *, void *> m_resources; |
409 static inline QGLExtensionFuncs& extensionFuncs(const QGLContext *ctx) { return ctx->d_ptr->group->extensionFuncs(); } |
414 static inline QGLExtensionFuncs& extensionFuncs(const QGLContext *ctx) { return ctx->d_ptr->group->extensionFuncs(); } |
410 #endif |
415 #endif |
411 |
416 |
412 #if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS) |
417 #if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS) |
413 static QGLExtensionFuncs qt_extensionFuncs; |
418 static QGLExtensionFuncs qt_extensionFuncs; |
414 static inline QGLExtensionFuncs& extensionFuncs(const QGLContext *) { return qt_extensionFuncs; } |
419 static Q_OPENGL_EXPORT QGLExtensionFuncs& extensionFuncs(const QGLContext *); |
415 #endif |
420 #endif |
416 |
421 |
417 static void setCurrentContext(QGLContext *context); |
422 static void setCurrentContext(QGLContext *context); |
418 }; |
423 }; |
419 |
424 |
520 (const char *buf, int len, const char *format = 0); |
525 (const char *buf, int len, const char *format = 0); |
521 QSize bindCompressedTextureDDS(const char *buf, int len); |
526 QSize bindCompressedTextureDDS(const char *buf, int len); |
522 QSize bindCompressedTexturePVR(const char *buf, int len); |
527 QSize bindCompressedTexturePVR(const char *buf, int len); |
523 }; |
528 }; |
524 |
529 |
|
530 struct QGLTextureCacheKey { |
|
531 qint64 key; |
|
532 QGLContextGroup *group; |
|
533 }; |
|
534 |
|
535 inline bool operator==(const QGLTextureCacheKey &a, const QGLTextureCacheKey &b) |
|
536 { |
|
537 return a.key == b.key && a.group == b.group; |
|
538 } |
|
539 |
|
540 inline uint qHash(const QGLTextureCacheKey &key) |
|
541 { |
|
542 return qHash(key.key) ^ qHash(key.group); |
|
543 } |
|
544 |
|
545 |
525 class Q_AUTOTEST_EXPORT QGLTextureCache { |
546 class Q_AUTOTEST_EXPORT QGLTextureCache { |
526 public: |
547 public: |
527 QGLTextureCache(); |
548 QGLTextureCache(); |
528 ~QGLTextureCache(); |
549 ~QGLTextureCache(); |
529 |
550 |
530 void insert(QGLContext *ctx, qint64 key, QGLTexture *texture, int cost); |
551 void insert(QGLContext *ctx, qint64 key, QGLTexture *texture, int cost); |
531 inline void remove(quint64 key); |
552 void remove(qint64 key); |
532 inline int size(); |
553 inline int size(); |
533 inline void setMaxCost(int newMax); |
554 inline void setMaxCost(int newMax); |
534 inline int maxCost(); |
555 inline int maxCost(); |
535 inline QGLTexture* getTexture(quint64 key); |
556 inline QGLTexture* getTexture(QGLContext *ctx, qint64 key); |
536 |
557 |
537 bool remove(QGLContext *ctx, GLuint textureId); |
558 bool remove(QGLContext *ctx, GLuint textureId); |
538 void removeContextTextures(QGLContext *ctx); |
559 void removeContextTextures(QGLContext *ctx); |
539 static QGLTextureCache *instance(); |
560 static QGLTextureCache *instance(); |
540 static void cleanupTexturesForCacheKey(qint64 cacheKey); |
561 static void cleanupTexturesForCacheKey(qint64 cacheKey); |
541 static void cleanupTexturesForPixampData(QPixmapData* pixmap); |
562 static void cleanupTexturesForPixampData(QPixmapData* pixmap); |
542 static void cleanupBeforePixmapDestruction(QPixmapData* pixmap); |
563 static void cleanupBeforePixmapDestruction(QPixmapData* pixmap); |
543 |
564 |
544 private: |
565 private: |
545 QCache<qint64, QGLTexture> m_cache; |
566 QCache<QGLTextureCacheKey, QGLTexture> m_cache; |
546 QReadWriteLock m_lock; |
567 QReadWriteLock m_lock; |
547 }; |
568 }; |
548 |
569 |
549 int QGLTextureCache::size() { |
570 int QGLTextureCache::size() { |
550 QReadLocker locker(&m_lock); |
571 QReadLocker locker(&m_lock); |
561 { |
582 { |
562 QReadLocker locker(&m_lock); |
583 QReadLocker locker(&m_lock); |
563 return m_cache.maxCost(); |
584 return m_cache.maxCost(); |
564 } |
585 } |
565 |
586 |
566 QGLTexture* QGLTextureCache::getTexture(quint64 key) |
587 QGLTexture* QGLTextureCache::getTexture(QGLContext *ctx, qint64 key) |
567 { |
588 { |
568 QReadLocker locker(&m_lock); |
589 QReadLocker locker(&m_lock); |
569 return m_cache.object(key); |
590 const QGLTextureCacheKey cacheKey = {key, QGLContextPrivate::contextGroup(ctx)}; |
|
591 return m_cache.object(cacheKey); |
570 } |
592 } |
571 |
|
572 void QGLTextureCache::remove(quint64 key) |
|
573 { |
|
574 QWriteLocker locker(&m_lock); |
|
575 m_cache.remove(key); |
|
576 } |
|
577 |
|
578 |
593 |
579 extern Q_OPENGL_EXPORT QPaintEngine* qt_qgl_paint_engine(); |
594 extern Q_OPENGL_EXPORT QPaintEngine* qt_qgl_paint_engine(); |
580 |
595 |
581 bool qt_gl_preferGL2Engine(); |
596 bool qt_gl_preferGL2Engine(); |
582 |
597 |