Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / quick / scenegraph / qsgdefaultdistancefieldglyphcache.cpp
index 95ccc8f..ef5b24d 100644 (file)
@@ -1,8 +1,7 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
 **
 ** This file is part of the QtDeclarative module of the Qt Toolkit.
 **
@@ -35,6 +34,7 @@
 **
 **
 **
+**
 ** $QT_END_LICENSE$
 **
 ****************************************************************************/
@@ -65,31 +65,19 @@ QSGDefaultDistanceFieldGlyphCache::QSGDefaultDistanceFieldGlyphCache(QSGDistance
     m_textureData = textureData(c);
 }
 
-void QSGDefaultDistanceFieldGlyphCache::requestGlyphs(const QVector<glyph_t> &glyphs)
+void QSGDefaultDistanceFieldGlyphCache::requestGlyphs(const QSet<glyph_t> &glyphs)
 {
-    int count = glyphs.count();
-
-    // Avoid useless and costly glyph re-generation
-    if (cacheIsFull() && !m_textureData->unusedGlyphs.isEmpty()) {
-        for (int i = 0; i < count; ++i) {
-            glyph_t glyphIndex = glyphs.at(i);
-            if (containsGlyph(glyphIndex) && m_textureData->unusedGlyphs.contains(glyphIndex))
-                m_textureData->unusedGlyphs.remove(glyphIndex);
-        }
-    }
-
     QList<GlyphPosition> glyphPositions;
     QVector<glyph_t> glyphsToRender;
 
-    for (int i = 0; i < count; ++i) {
-        glyph_t glyphIndex = glyphs.at(i);
-
-        if (++m_textureData->glyphRefCount[glyphIndex] == 1)
-            m_textureData->unusedGlyphs.remove(glyphIndex);
+    for (QSet<glyph_t>::const_iterator it = glyphs.constBegin(); it != glyphs.constEnd() ; ++it) {
+        glyph_t glyphIndex = *it;
 
         if (cacheIsFull() && m_textureData->unusedGlyphs.isEmpty())
             continue;
 
+        m_textureData->unusedGlyphs.remove(glyphIndex);
+
         GlyphPosition p;
         p.glyph = glyphIndex;
         p.position = QPointF(m_textureData->currX, m_textureData->currY);
@@ -117,7 +105,7 @@ void QSGDefaultDistanceFieldGlyphCache::requestGlyphs(const QVector<glyph_t> &gl
         }
     }
 
-    addGlyphPositions(glyphPositions);
+    setGlyphsPosition(glyphPositions);
     markGlyphsToRender(glyphsToRender);
 }
 
@@ -159,17 +147,17 @@ void QSGDefaultDistanceFieldGlyphCache::storeGlyphs(const QHash<glyph_t, QImage>
     Texture t;
     t.textureId = m_textureData->texture;
     t.size = m_textureData->size;
-    addGlyphTextures(glyphTextures, t);
+    setGlyphsTexture(glyphTextures, t);
 }
 
-void QSGDefaultDistanceFieldGlyphCache::releaseGlyphs(const QVector<glyph_t> &glyphs)
+void QSGDefaultDistanceFieldGlyphCache::referenceGlyphs(const QSet<glyph_t> &glyphs)
 {
-    int count = glyphs.count();
-    for (int i = 0; i < count; ++i) {
-        glyph_t glyphIndex = glyphs.at(i);
-        if (--m_textureData->glyphRefCount[glyphIndex] == 0 && !glyphTexCoord(glyphIndex).isNull())
-            m_textureData->unusedGlyphs.insert(glyphIndex);
-    }
+    m_textureData->unusedGlyphs -= glyphs;
+}
+
+void QSGDefaultDistanceFieldGlyphCache::releaseGlyphs(const QSet<glyph_t> &glyphs)
+{
+    m_textureData->unusedGlyphs += glyphs;
 }
 
 void QSGDefaultDistanceFieldGlyphCache::createTexture(int width, int height)
@@ -300,6 +288,9 @@ void QSGDefaultDistanceFieldGlyphCache::resizeTexture(int width, int height)
         glEnable(GL_BLEND);
     glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
     ctx->functions()->glUseProgram(oldProgram);
+
+    m_textureData->blitProgram->disableAttributeArray(int(QT_VERTEX_COORDS_ATTR));
+    m_textureData->blitProgram->disableAttributeArray(int(QT_TEXTURE_COORDS_ATTR));
 }
 
 bool QSGDefaultDistanceFieldGlyphCache::useWorkaroundBrokenFBOReadback() const