Qt 4.8
Public Slots | Public Functions | Protected Variables | List of all members
QGLGlyphCache Class Reference
Inheritance diagram for QGLGlyphCache:
QObject

Public Slots

void cleanupContext (const QGLContext *)
 
void fontEngineDestroyed (QObject *)
 
void widgetDestroyed (QObject *)
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Public Functions

void allocTexture (QGLFontTexture *)
 
void cacheGlyphs (QGLContext *, QFontEngine *, glyph_t *glyphs, int numGlyphs)
 
void cleanCache ()
 
QGLGlyphCoordlookup (QFontEngine *, glyph_t)
 
 QGLGlyphCache ()
 
 ~QGLGlyphCache ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Variables

QGLGlyphHashcurrent_cache
 
QGLContextHash qt_context_cache
 
QGLFontTexHash qt_font_textures
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 

Additional Inherited Members

- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 4559 of file qpaintengine_opengl.cpp.

Constructors and Destructors

◆ QGLGlyphCache()

QGLGlyphCache::QGLGlyphCache ( )
inline

Definition at line 4563 of file qpaintengine_opengl.cpp.

4563 : QObject(0) { current_cache = 0; }
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
QGLGlyphHash * current_cache

◆ ~QGLGlyphCache()

QGLGlyphCache::~QGLGlyphCache ( )

Definition at line 4581 of file qpaintengine_opengl.cpp.

4582 {
4583 // qDebug() << "cleaning out the QGLGlyphCache";
4584  cleanCache();
4585 }

Functions

◆ allocTexture()

void QGLGlyphCache::allocTexture ( QGLFontTexture font_tex)

Definition at line 4686 of file qpaintengine_opengl.cpp.

4687 {
4688  font_tex->data = (uchar *) malloc(font_tex->width*font_tex->height*2);
4689  memset(font_tex->data, 0, font_tex->width*font_tex->height*2);
4690  glBindTexture(GL_TEXTURE_2D, font_tex->texture);
4691 #ifndef QT_OPENGL_ES
4692  glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE8_ALPHA8,
4693  font_tex->width, font_tex->height, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, font_tex->data);
4694 #else
4695  glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA,
4696  font_tex->width, font_tex->height, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, font_tex->data);
4697 #endif
4698 }
#define GL_TEXTURE_2D
unsigned char uchar
Definition: qglobal.h:994
#define GL_LUMINANCE_ALPHA
#define GL_UNSIGNED_BYTE

◆ cacheGlyphs()

void QGLGlyphCache::cacheGlyphs ( QGLContext context,
QFontEngine fontEngine,
glyph_t glyphs,
int  numGlyphs 
)

Definition at line 4717 of file qpaintengine_opengl.cpp.

4719 {
4721  QGLFontGlyphHash *font_cache = 0;
4722  const QGLContext *context_key = 0;
4723 
4724  if (dev_it == qt_context_cache.constEnd()) {
4725  // check for shared contexts
4727  for (int i=0; i<contexts.size(); ++i) {
4728  const QGLContext *ctx = contexts.at(i);
4729  if (ctx != context && QGLContext::areSharing(context, ctx)) {
4730  context_key = ctx;
4731  dev_it = qt_context_cache.constFind(context_key);
4732  break;
4733  }
4734  }
4735  }
4736 
4737  if (dev_it == qt_context_cache.constEnd()) {
4738  // no shared contexts either - create a new entry
4739  font_cache = new QGLFontGlyphHash;
4740 // qDebug() << "new context" << context << font_cache;
4741  qt_context_cache.insert(context, font_cache);
4742  if (context->isValid()) {
4743  if (context->device() && context->device()->devType() == QInternal::Widget) {
4744  QWidget *widget = static_cast<QWidget *>(context->device());
4746  }
4748  SIGNAL(aboutToDestroyContext(const QGLContext*)),
4749  SLOT(cleanupContext(const QGLContext*)));
4750  }
4751  } else {
4752  font_cache = dev_it.value();
4753  }
4754  Q_ASSERT(font_cache != 0);
4755 
4756  QGLFontGlyphHash::const_iterator cache_it = font_cache->constFind(fontEngine);
4757  QGLGlyphHash *cache = 0;
4758  if (cache_it == font_cache->constEnd()) {
4759  cache = new QGLGlyphHash;
4760  font_cache->insert(fontEngine, cache);
4762  } else {
4763  cache = cache_it.value();
4764  }
4765  current_cache = cache;
4766 
4767  quint64 font_key = (reinterpret_cast<quint64>(context_key ? context_key : context) << 32)
4768  | reinterpret_cast<quint64>(fontEngine);
4770  QGLFontTexture *font_tex;
4771  if (it == qt_font_textures.constEnd()) {
4772  GLuint font_texture;
4773  glGenTextures(1, &font_texture);
4774  GLint tex_height = qt_next_power_of_two(qRound(fontEngine->ascent().toReal() + fontEngine->descent().toReal())+2);
4775  GLint tex_width = qt_next_power_of_two(tex_height*30); // ###
4776  GLint max_tex_size;
4777  glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_tex_size);
4778  Q_ASSERT(max_tex_size > 0);
4779  if (tex_width > max_tex_size)
4780  tex_width = max_tex_size;
4781  font_tex = new QGLFontTexture;
4782  font_tex->texture = font_texture;
4783  font_tex->x_offset = x_margin;
4784  font_tex->y_offset = y_margin;
4785  font_tex->width = tex_width;
4786  font_tex->height = tex_height;
4787  allocTexture(font_tex);
4788 // qDebug() << "new font tex - width:" << tex_width << "height:"<< tex_height
4789 // << hex << "tex id:" << font_tex->texture << "key:" << font_key << "num cached:" << qt_font_textures.size();
4790  qt_font_textures.insert(font_key, font_tex);
4791  } else {
4792  font_tex = it.value();
4793  glBindTexture(GL_TEXTURE_2D, font_tex->texture);
4794  }
4795 
4796  for (int i=0; i< numGlyphs; ++i) {
4797  QGLGlyphHash::const_iterator it = cache->constFind(glyphs[i]);
4798  if (it == cache->constEnd()) {
4799  // render new glyph and put it in the cache
4800  glyph_metrics_t metrics = fontEngine->boundingBox(glyphs[i]);
4801  QImage glyph_im(fontEngine->alphaMapForGlyph(glyphs[i]));
4802  int glyph_width = glyph_im.width();
4803  int glyph_height = qRound(fontEngine->ascent().toReal() + fontEngine->descent().toReal()) + 2;
4804  Q_ASSERT(glyph_width >= 0);
4805  // pad the glyph width to an even number
4806  if (glyph_width % 2 != 0)
4807  ++glyph_width;
4808 
4809  if (font_tex->x_offset + glyph_width + x_margin > font_tex->width) {
4810  int strip_height = qt_next_power_of_two(qRound(fontEngine->ascent().toReal() + fontEngine->descent().toReal())+2);
4811  font_tex->x_offset = x_margin;
4812  font_tex->y_offset += strip_height;
4813  if (font_tex->y_offset + strip_height > font_tex->height) {
4814  // get hold of the old font texture
4815  uchar *old_tex_data = font_tex->data;
4816  int old_tex_height = font_tex->height;
4817 
4818  // realloc a larger texture
4819  glDeleteTextures(1, &font_tex->texture);
4820  glGenTextures(1, &font_tex->texture);
4821  font_tex->height = qt_next_power_of_two(font_tex->height + strip_height);
4822  allocTexture(font_tex);
4823 
4824  // write back the old texture data
4825  glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, font_tex->width, old_tex_height,
4826  GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, old_tex_data);
4827  memcpy(font_tex->data, old_tex_data, font_tex->width*old_tex_height*2);
4828  free(old_tex_data);
4829 
4830  // update the texture coords and the y offset for the existing glyphs in
4831  // the cache, because of the texture size change
4832  QGLGlyphHash::iterator it = cache->begin();
4833  while (it != cache->end()) {
4834  it.value()->height = (it.value()->height * old_tex_height) / font_tex->height;
4835  it.value()->y = (it.value()->y * old_tex_height) / font_tex->height;
4836  ++it;
4837  }
4838  }
4839  }
4840 
4841  glyph_height = qMin(glyph_height, glyph_im.height());
4842 
4843  QGLGlyphCoord *qgl_glyph = new QGLGlyphCoord;
4844  qgl_glyph->x = qreal(font_tex->x_offset) / font_tex->width;
4845  qgl_glyph->y = qreal(font_tex->y_offset) / font_tex->height;
4846  qgl_glyph->width = qreal(glyph_width) / font_tex->width;
4847  qgl_glyph->height = qreal(glyph_height) / font_tex->height;
4848  qgl_glyph->log_width = qreal(glyph_width);
4849  qgl_glyph->log_height = qgl_glyph->height * font_tex->height;
4850 #ifdef Q_WS_MAC
4851  qgl_glyph->x_offset = -metrics.x + 1;
4852  qgl_glyph->y_offset = metrics.y - 2;
4853 #else
4854  qgl_glyph->x_offset = -metrics.x;
4855  qgl_glyph->y_offset = metrics.y;
4856 #endif
4857 
4858  if (!glyph_im.isNull()) {
4859  int idx = 0;
4860  uchar *tex_data = (uchar *) malloc(glyph_width*glyph_height*2);
4861  memset(tex_data, 0, glyph_width*glyph_height*2);
4862 
4863  bool is8BitGray = false;
4864 #ifdef Q_WS_QPA
4865  if (glyph_im.format() == QImage::Format_Indexed8) {
4866  is8BitGray = true;
4867  }
4868 #endif
4869  glyph_im = glyph_im.convertToFormat(QImage::Format_Indexed8);
4870  int cacheLineStart = (font_tex->x_offset + font_tex->y_offset*font_tex->width)*2;
4871  for (int y=0; y<glyph_height; ++y) {
4872  uchar *s = (uchar *) glyph_im.scanLine(y);
4873  int lineStart = idx;
4874  for (int x=0; x<glyph_im.width(); ++x) {
4875  uchar alpha = is8BitGray ? *s : qAlpha(glyph_im.color(*s));
4876  tex_data[idx] = alpha;
4877  tex_data[idx+1] = alpha;
4878  ++s;
4879  idx += 2;
4880  }
4881  if (glyph_im.width()%2 != 0)
4882  idx += 2;
4883  // update cache
4884  memcpy(font_tex->data+cacheLineStart, tex_data+lineStart, glyph_width*2);
4885  cacheLineStart += font_tex->width*2;
4886  }
4887  glTexSubImage2D(GL_TEXTURE_2D, 0, font_tex->x_offset, font_tex->y_offset,
4888  glyph_width, glyph_height,
4890  free(tex_data);
4891  }
4892 
4893  font_tex->x_offset += glyph_width + x_margin;
4894 
4895  cache->insert(glyphs[i], qgl_glyph);
4896  }
4897  }
4898 }
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
double qreal
Definition: qglobal.h:1193
virtual QImage alphaMapForGlyph(glyph_t)
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
void allocTexture(QGLFontTexture *)
QPointer< QWidget > widget
#define GL_MAX_TEXTURE_SIZE
#define it(className, varName)
QGLFontTexHash qt_font_textures
Q_GUI_EXPORT_INLINE int qAlpha(QRgb rgb)
Definition: qrgb.h:66
#define SLOT(a)
Definition: qobjectdefs.h:226
static QGLSignalProxy * instance()
Definition: qgl.cpp:148
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QGLContextHash qt_context_cache
T & value() const
Returns a modifiable reference to the current item&#39;s value.
Definition: qhash.h:348
void fontEngineDestroyed(QObject *)
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
int qt_next_power_of_two(int v)
Definition: qgl.cpp:1886
void widgetDestroyed(QObject *)
virtual int devType() const
Definition: qpaintdevice.h:167
#define GL_TEXTURE_2D
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
static bool areSharing(const QGLContext *context1, const QGLContext *context2)
Returns true if context1 and context2 are sharing their GL resources such as textures, shader programs, etc; otherwise returns false.
Definition: qgl.cpp:3319
#define SIGNAL(a)
Definition: qobjectdefs.h:227
unsigned char uchar
Definition: qglobal.h:994
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
unsigned __int64 quint64
Definition: qglobal.h:943
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
virtual QFixed ascent() const =0
QHash< glyph_t, QGLGlyphCoord * > QGLGlyphHash
virtual QFixed descent() const =0
const T & value() const
Returns the current item&#39;s value.
Definition: qhash.h:420
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
const_iterator constFind(const Key &key) const
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:859
#define GL_LUMINANCE_ALPHA
QPaintDevice * device() const
Returns the paint device set for this context.
Definition: qgl.cpp:3507
virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs)=0
QHash< QFontEngine *, QGLGlyphHash * > QGLFontGlyphHash
void cleanupContext(const QGLContext *)
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
bool isValid() const
Returns true if a GL rendering context has been successfully created; otherwise returns false...
Definition: qgl.cpp:3477
#define GL_UNSIGNED_BYTE
static const int y_margin
#define ctx
Definition: qgl.cpp:6094
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
qreal toReal() const
Definition: qfixed_p.h:77
typedef GLint
Definition: glfunctions.h:67
QList< Key > keys() const
Returns a list containing all the keys in the hash, in an arbitrary order.
Definition: qhash.h:648
QGLGlyphHash * current_cache
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
static const int x_margin

◆ cleanCache()

void QGLGlyphCache::cleanCache ( )

Definition at line 4658 of file qpaintengine_opengl.cpp.

4659 {
4662  while (it != qt_font_textures.constEnd()) {
4663 #if defined(Q_WS_MAC) && defined(QT_MAC_USE_COCOA)
4664  if (qt_current_nsopengl_context() == 0)
4665  break;
4666 #endif
4667  glDeleteTextures(1, &it.value()->texture);
4668  ++it;
4669  }
4670  }
4673 
4675  for (int i=0; i < keys.size(); ++i) {
4676  QGLFontGlyphHash *font_cache = qt_context_cache.value(keys.at(i));
4677  QGLFontGlyphHash::Iterator it = font_cache->begin();
4678  for (; it != font_cache->end(); ++it)
4680  font_cache->clear();
4681  }
4684 }
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
void clear()
Removes all items from the hash.
Definition: qhash.h:574
#define it(className, varName)
QGLFontTexHash qt_font_textures
QGLContextHash qt_context_cache
T & value() const
Returns a modifiable reference to the current item&#39;s value.
Definition: qhash.h:348
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
QStringList keys
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
const T & value() const
Returns the current item&#39;s value.
Definition: qhash.h:420
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
QList< Key > keys() const
Returns a list containing all the keys in the hash, in an arbitrary order.
Definition: qhash.h:648
static void qt_delete_glyph_hash(QGLGlyphHash *hash)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ cleanupContext

void QGLGlyphCache::cleanupContext ( const QGLContext ctx)
slot

Definition at line 4627 of file qpaintengine_opengl.cpp.

4628 {
4629 // qDebug() << "==> cleaning for: " << hex << ctx;
4630  QGLFontGlyphHash *font_cache = qt_context_cache.take(ctx);
4631 
4632  if (font_cache) {
4633  QList<QFontEngine *> keys = font_cache->keys();
4634  for (int i=0; i < keys.size(); ++i) {
4635  QFontEngine *fe = keys.at(i);
4636  qt_delete_glyph_hash(font_cache->take(fe));
4637  quint64 font_key = (reinterpret_cast<quint64>(ctx) << 32) | reinterpret_cast<quint64>(fe);
4638  QGLFontTexture *font_tex = qt_font_textures.take(font_key);
4639  if (font_tex) {
4640 #ifdef Q_WS_MAC
4641  if (
4642 # ifndef QT_MAC_USE_COCOA
4643  aglGetCurrentContext() == 0
4644 # else
4645  qt_current_nsopengl_context() != 0
4646 # endif
4647  )
4648 #endif
4649  glDeleteTextures(1, &font_tex->texture);
4650  delete font_tex;
4651  }
4652  }
4653  delete font_cache;
4654  }
4655 // qDebug() << "<=== done cleaning, num tex:" << qt_font_textures.size() << "num ctx:" << qt_context_cache.size();
4656 }
QGLFontTexHash qt_font_textures
QGLContextHash qt_context_cache
T take(const Key &key)
Removes the item with the key from the hash and returns the value associated with it...
Definition: qhash.h:807
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
QStringList keys
unsigned __int64 quint64
Definition: qglobal.h:943
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define ctx
Definition: qgl.cpp:6094
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QList< Key > keys() const
Returns a list containing all the keys in the hash, in an arbitrary order.
Definition: qhash.h:648
static void qt_delete_glyph_hash(QGLGlyphHash *hash)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ fontEngineDestroyed

void QGLGlyphCache::fontEngineDestroyed ( QObject o)
slot

Definition at line 4587 of file qpaintengine_opengl.cpp.

4588 {
4589 // qDebug() << "fontEngineDestroyed()";
4590  QFontEngine *fe = static_cast<QFontEngine *>(o); // safe, since only the type is used
4592  const QGLContext *ctx = 0;
4593 
4594  for (int i=0; i < keys.size(); ++i) {
4595  QGLFontGlyphHash *font_cache = qt_context_cache.value(keys.at(i));
4596  if (font_cache->find(fe) != font_cache->end()) {
4597  ctx = keys.at(i);
4598  QGLGlyphHash *cache = font_cache->take(fe);
4599  qt_delete_glyph_hash(cache);
4600  break;
4601  }
4602  }
4603 
4604  quint64 font_key = (reinterpret_cast<quint64>(ctx) << 32) | reinterpret_cast<quint64>(fe);
4605  QGLFontTexture *tex = qt_font_textures.take(font_key);
4606  if (tex) {
4607 #ifdef Q_WS_MAC
4608  if (
4609 # ifndef QT_MAC_USE_COCOA
4610  aglGetCurrentContext() != 0
4611 # else
4612  qt_current_nsopengl_context() != 0
4613 # endif
4614  )
4615 #endif
4616  glDeleteTextures(1, &tex->texture);
4617  delete tex;
4618  }
4619 }
QGLFontTexHash qt_font_textures
QGLContextHash qt_context_cache
T take(const Key &key)
Removes the item with the key from the hash and returns the value associated with it...
Definition: qhash.h:807
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
QStringList keys
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
unsigned __int64 quint64
Definition: qglobal.h:943
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
#define ctx
Definition: qgl.cpp:6094
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
QList< Key > keys() const
Returns a list containing all the keys in the hash, in an arbitrary order.
Definition: qhash.h:648
static void qt_delete_glyph_hash(QGLGlyphHash *hash)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ lookup()

QGLGlyphCoord * QGLGlyphCache::lookup ( QFontEngine ,
glyph_t  g 
)

Definition at line 4900 of file qpaintengine_opengl.cpp.

4901 {
4902  Q_ASSERT(current_cache != 0);
4903  // ### careful here
4905  if (it == current_cache->constEnd())
4906  return 0;
4907  else
4908  return it.value();
4909 }
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
#define it(className, varName)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const T & value() const
Returns the current item&#39;s value.
Definition: qhash.h:420
const_iterator constFind(const Key &key) const
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:859
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
QGLGlyphHash * current_cache

◆ widgetDestroyed

void QGLGlyphCache::widgetDestroyed ( QObject )
slot

Definition at line 4621 of file qpaintengine_opengl.cpp.

4622 {
4623 // qDebug() << "widget destroyed";
4624  cleanCache(); // ###
4625 }

Properties

◆ current_cache

QGLGlyphHash* QGLGlyphCache::current_cache
protected

Definition at line 4576 of file qpaintengine_opengl.cpp.

◆ qt_context_cache

QGLContextHash QGLGlyphCache::qt_context_cache
protected

Definition at line 4578 of file qpaintengine_opengl.cpp.

◆ qt_font_textures

QGLFontTexHash QGLGlyphCache::qt_font_textures
protected

Definition at line 4577 of file qpaintengine_opengl.cpp.


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