Qt 4.8
Public Functions | Static Public Functions | Properties | List of all members
QGLTextureCache Class Reference

#include <qgl_p.h>

Public Functions

QGLTexturegetTexture (QGLContext *ctx, qint64 key)
 
void insert (QGLContext *ctx, qint64 key, QGLTexture *texture, int cost)
 
int maxCost ()
 
 QGLTextureCache ()
 
void remove (qint64 key)
 
bool remove (QGLContext *ctx, GLuint textureId)
 
void removeContextTextures (QGLContext *ctx)
 
void setMaxCost (int newMax)
 
int size ()
 
 ~QGLTextureCache ()
 

Static Public Functions

static void cleanupBeforePixmapDestruction (QPixmapData *pixmap)
 
static void cleanupTexturesForCacheKey (qint64 cacheKey)
 
static void cleanupTexturesForPixampData (QPixmapData *pixmap)
 
static QGLTextureCacheinstance ()
 

Properties

QCache< QGLTextureCacheKey, QGLTexturem_cache
 
QReadWriteLock m_lock
 

Detailed Description

Definition at line 656 of file qgl_p.h.

Constructors and Destructors

◆ QGLTextureCache()

QGLTextureCache::QGLTextureCache ( )

Definition at line 1907 of file qgl.cpp.

1908  : m_cache(64*1024) // cache ~64 MB worth of textures - this is not accurate though
1909 {
1913 }
static void cleanupTexturesForPixampData(QPixmapData *pixmap)
Definition: qgl.cpp:1977
void addPixmapDataModificationHook(_qt_pixmap_cleanup_hook_pmd)
QCache< QGLTextureCacheKey, QGLTexture > m_cache
Definition: qgl_p.h:676
void addPixmapDataDestructionHook(_qt_pixmap_cleanup_hook_pmd)
static void cleanupBeforePixmapDestruction(QPixmapData *pixmap)
Definition: qgl.cpp:1982
static QImagePixmapCleanupHooks * instance()
static void cleanupTexturesForCacheKey(qint64 cacheKey)
Definition: qgl.cpp:1971
void addImageHook(_qt_image_cleanup_hook_64)

◆ ~QGLTextureCache()

QGLTextureCache::~QGLTextureCache ( )

Definition at line 1915 of file qgl.cpp.

1916 {
1920 }
static void cleanupTexturesForPixampData(QPixmapData *pixmap)
Definition: qgl.cpp:1977
void removePixmapDataModificationHook(_qt_pixmap_cleanup_hook_pmd)
void removePixmapDataDestructionHook(_qt_pixmap_cleanup_hook_pmd)
static void cleanupBeforePixmapDestruction(QPixmapData *pixmap)
Definition: qgl.cpp:1982
void removeImageHook(_qt_image_cleanup_hook_64)
static QImagePixmapCleanupHooks * instance()
static void cleanupTexturesForCacheKey(qint64 cacheKey)
Definition: qgl.cpp:1971

Functions

◆ cleanupBeforePixmapDestruction()

void QGLTextureCache::cleanupBeforePixmapDestruction ( QPixmapData pixmap)
static

Definition at line 1982 of file qgl.cpp.

1983 {
1984  // Remove any bound textures first:
1986 
1987 #if defined(Q_WS_X11)
1988  if (pmd->classId() == QPixmapData::X11Class) {
1989  Q_ASSERT(pmd->ref == 0); // Make sure reference counting isn't broken
1991  }
1992 #endif
1993 }
static void cleanupTexturesForPixampData(QPixmapData *pixmap)
Definition: qgl.cpp:1977
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static void destroyGlSurfaceForPixmap(QPixmapData *)
Definition: qgl_x11.cpp:1890

◆ cleanupTexturesForCacheKey()

void QGLTextureCache::cleanupTexturesForCacheKey ( qint64  cacheKey)
static

Definition at line 1971 of file qgl.cpp.

1972 {
1973  qt_gl_texture_cache()->remove(cacheKey);
1974 }

◆ cleanupTexturesForPixampData()

void QGLTextureCache::cleanupTexturesForPixampData ( QPixmapData pixmap)
static

Definition at line 1977 of file qgl.cpp.

1978 {
1979  cleanupTexturesForCacheKey(pmd->cacheKey());
1980 }
static void cleanupTexturesForCacheKey(qint64 cacheKey)
Definition: qgl.cpp:1971

◆ getTexture()

QGLTexture * QGLTextureCache::getTexture ( QGLContext ctx,
qint64  key 
)
inline

Definition at line 697 of file qgl_p.h.

698 {
699  // Can't be a QReadLocker since QCache::object() modifies the cache (reprioritizes the object)
700  QWriteLocker locker(&m_lock);
701  const QGLTextureCacheKey cacheKey = {key, QGLContextPrivate::contextGroup(ctx)};
702  return m_cache.object(cacheKey);
703 }
T * object(const Key &key) const
Definition: qcache.h:147
QCache< QGLTextureCacheKey, QGLTexture > m_cache
Definition: qgl_p.h:676
QReadWriteLock m_lock
Definition: qgl_p.h:677
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
static QGLContextGroup * contextGroup(const QGLContext *ctx)
Definition: qgl_p.h:464
int key

◆ insert()

void QGLTextureCache::insert ( QGLContext ctx,
qint64  key,
QGLTexture texture,
int  cost 
)

Definition at line 1922 of file qgl.cpp.

Referenced by QGLContextPrivate::bindTextureFromNativePixmap().

1923 {
1924  QWriteLocker locker(&m_lock);
1925  const QGLTextureCacheKey cacheKey = {key, QGLContextPrivate::contextGroup(ctx)};
1926  m_cache.insert(cacheKey, texture, cost);
1927 }
QCache< QGLTextureCacheKey, QGLTexture > m_cache
Definition: qgl_p.h:676
QReadWriteLock m_lock
Definition: qgl_p.h:677
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
bool insert(const Key &key, T *object, int cost=1)
Definition: qcache.h:181
static QGLContextGroup * contextGroup(const QGLContext *ctx)
Definition: qgl_p.h:464
int key

◆ instance()

QGLTextureCache * QGLTextureCache::instance ( )
static

Definition at line 1995 of file qgl.cpp.

Referenced by QGLContextPrivate::bindTextureFromNativePixmap(), QGLTexturePool::hibernate(), QX11GLSharedContexts::QX11GLSharedContexts(), and QGLTexturePool::reclaimSpace().

1996 {
1997  return qt_gl_texture_cache();
1998 }

◆ maxCost()

int QGLTextureCache::maxCost ( )
inline

Definition at line 691 of file qgl_p.h.

692 {
693  QReadLocker locker(&m_lock);
694  return m_cache.maxCost();
695 }
QCache< QGLTextureCacheKey, QGLTexture > m_cache
Definition: qgl_p.h:676
int maxCost() const
Definition: qcache.h:105
The QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks f...
QReadWriteLock m_lock
Definition: qgl_p.h:677

◆ remove() [1/2]

void QGLTextureCache::remove ( qint64  key)

Definition at line 1929 of file qgl.cpp.

Referenced by QGLTexturePool::hibernate(), and QGLTexturePool::reclaimSpace().

1930 {
1931  QWriteLocker locker(&m_lock);
1932  QMutexLocker groupLocker(&qt_context_groups()->m_mutex);
1933  QList<QGLContextGroup *>::const_iterator it = qt_context_groups()->m_list.constBegin();
1934  while (it != qt_context_groups()->m_list.constEnd()) {
1935  const QGLTextureCacheKey cacheKey = {key, *it};
1936  m_cache.remove(cacheKey);
1937  ++it;
1938  }
1939 }
QCache< QGLTextureCacheKey, QGLTexture > m_cache
Definition: qgl_p.h:676
#define it(className, varName)
The QList::const_iterator class provides an STL-style const iterator for QList and QQueue...
Definition: qlist.h:228
QReadWriteLock m_lock
Definition: qgl_p.h:677
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int key
bool remove(const Key &key)
Definition: qcache.h:155

◆ remove() [2/2]

bool QGLTextureCache::remove ( QGLContext ctx,
GLuint  textureId 
)

Definition at line 1941 of file qgl.cpp.

1942 {
1943  QWriteLocker locker(&m_lock);
1945  for (int i = 0; i < keys.size(); ++i) {
1946  QGLTexture *tex = m_cache.object(keys.at(i));
1947  if (tex->id == textureId && tex->context == ctx) {
1948  tex->options |= QGLContext::MemoryManagedBindOption; // forces a glDeleteTextures() call
1949  m_cache.remove(keys.at(i));
1950  return true;
1951  }
1952  }
1953  return false;
1954 }
T * object(const Key &key) const
Definition: qcache.h:147
QCache< QGLTextureCacheKey, QGLTexture > m_cache
Definition: qgl_p.h:676
QGLContext::BindOptions options
Definition: qgl_p.h:611
QStringList keys
GLuint id
Definition: qgl_p.h:608
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QReadWriteLock m_lock
Definition: qgl_p.h:677
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
QGLContext * context
Definition: qgl_p.h:607
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QList< Key > keys() const
Definition: qcache.h:112
bool remove(const Key &key)
Definition: qcache.h:155
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ removeContextTextures()

void QGLTextureCache::removeContextTextures ( QGLContext ctx)

Definition at line 1956 of file qgl.cpp.

1957 {
1958  QWriteLocker locker(&m_lock);
1960  for (int i = 0; i < keys.size(); ++i) {
1961  const QGLTextureCacheKey &key = keys.at(i);
1962  if (m_cache.object(key)->context == ctx)
1963  m_cache.remove(key);
1964  }
1965 }
T * object(const Key &key) const
Definition: qcache.h:147
QCache< QGLTextureCacheKey, QGLTexture > m_cache
Definition: qgl_p.h:676
QStringList keys
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QReadWriteLock m_lock
Definition: qgl_p.h:677
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
QGLContext * context
Definition: qgl_p.h:607
#define ctx
Definition: qgl.cpp:6094
int key
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QList< Key > keys() const
Definition: qcache.h:112
bool remove(const Key &key)
Definition: qcache.h:155
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ setMaxCost()

void QGLTextureCache::setMaxCost ( int  newMax)
inline

Definition at line 685 of file qgl_p.h.

686 {
687  QWriteLocker locker(&m_lock);
688  m_cache.setMaxCost(newMax);
689 }
QCache< QGLTextureCacheKey, QGLTexture > m_cache
Definition: qgl_p.h:676
void setMaxCost(int m)
Definition: qcache.h:143
QReadWriteLock m_lock
Definition: qgl_p.h:677
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...

◆ size()

int QGLTextureCache::size ( )
inline

Definition at line 680 of file qgl_p.h.

680  {
681  QReadLocker locker(&m_lock);
682  return m_cache.size();
683 }
QCache< QGLTextureCacheKey, QGLTexture > m_cache
Definition: qgl_p.h:676
int size() const
Definition: qcache.h:109
The QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks f...
QReadWriteLock m_lock
Definition: qgl_p.h:677

Properties

◆ m_cache

QCache<QGLTextureCacheKey, QGLTexture> QGLTextureCache::m_cache
private

Definition at line 676 of file qgl_p.h.

◆ m_lock

QReadWriteLock QGLTextureCache::m_lock
private

Definition at line 677 of file qgl_p.h.


The documentation for this class was generated from the following files: