Changeset 846 for trunk/src/gui/painting/qtextureglyphcache.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/painting/qtextureglyphcache.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 48 48 #include "private/qfontengine_ft_p.h" 49 49 50 #ifndef QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH51 #define QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH 25652 #endif53 54 50 QT_BEGIN_NAMESPACE 55 51 56 52 // #define CACHE_DEBUG 57 53 58 void QTextureGlyphCache::populate(const QTextItemInt &ti, 59 const QVarLengthArray<glyph_t> &glyphs, 60 const QVarLengthArray<QFixedPoint> &) 54 // returns the highest number closest to v, which is a power of 2 55 // NB! assumes 32 bit ints 56 static inline int qt_next_power_of_two(int v) 57 { 58 v--; 59 v |= v >> 1; 60 v |= v >> 2; 61 v |= v >> 4; 62 v |= v >> 8; 63 v |= v >> 16; 64 ++v; 65 return v; 66 } 67 68 bool QTextureGlyphCache::populate(QFontEngine *fontEngine, int numGlyphs, const glyph_t *glyphs, 69 const QFixedPoint *) 61 70 { 62 71 #ifdef CACHE_DEBUG 63 printf("Populating with '%s'\n", QString::fromRawData(ti.chars, ti.num_chars).toLatin1().data());72 printf("Populating with %d glyphs\n", numGlyphs); 64 73 qDebug() << " -> current transformation: " << m_transform; 65 74 #endif 66 75 67 m_current_ textitem = &ti;76 m_current_fontengine = fontEngine; 68 77 const int margin = glyphMargin(); 78 const int paddingDoubled = glyphPadding() * 2; 69 79 70 80 QHash<glyph_t, Coord> listItemCoordinates; … … 72 82 73 83 // check each glyph for its metrics and get the required rowHeight. 74 for (int i=0; i < glyphs.size(); ++i) {84 for (int i=0; i < numGlyphs; ++i) { 75 85 const glyph_t glyph = glyphs[i]; 76 86 if (coords.contains(glyph)) … … 78 88 if (listItemCoordinates.contains(glyph)) 79 89 continue; 80 glyph_metrics_t metrics = ti.fontEngine->boundingBox(glyph, m_transform);90 glyph_metrics_t metrics = fontEngine->boundingBox(glyph, m_transform); 81 91 82 92 #ifdef CACHE_DEBUG 83 printf("'%c' (%4x): w=%.2f, h=%.2f, xoff=%.2f, yoff=%.2f, x=%.2f, y=%.2f, ti.ascent=%.2f, ti.descent=%.2f\n", 84 ti.chars[i].toLatin1(), 93 printf("(%4x): w=%.2f, h=%.2f, xoff=%.2f, yoff=%.2f, x=%.2f, y=%.2f\n", 85 94 glyph, 86 95 metrics.width.toReal(), … … 89 98 metrics.yoff.toReal(), 90 99 metrics.x.toReal(), 91 metrics.y.toReal(), 92 ti.ascent.toReal(), 93 ti.descent.toReal()); 100 metrics.y.toReal()); 94 101 #endif 95 102 int glyph_width = metrics.width.ceil().toInt(); … … 113 120 } 114 121 if (listItemCoordinates.isEmpty()) 115 return ;116 117 rowHeight += margin * 2 ;122 return true; 123 124 rowHeight += margin * 2 + paddingDoubled; 118 125 if (isNull()) 119 createCache(QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH, rowHeight);126 createCache(QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH, qt_next_power_of_two(rowHeight)); 120 127 121 128 // now actually use the coords and paint the wanted glyps into cache. … … 124 131 Coord c = iter.value(); 125 132 133 m_currentRowHeight = qMax(m_currentRowHeight, c.h + margin * 2); 134 126 135 if (m_cx + c.w > m_w) { 127 // no room on the current line, start new glyph strip 128 m_cx = 0; 129 m_cy = m_h; 136 int new_width = m_w*2; 137 while (new_width < m_cx + c.w) 138 new_width *= 2; 139 if (new_width <= maxTextureWidth()) { 140 resizeTextureData(new_width, m_h); 141 m_w = new_width; 142 } else { 143 // no room on the current line, start new glyph strip 144 m_cx = 0; 145 m_cy += m_currentRowHeight + paddingDoubled; 146 m_currentRowHeight = c.h + margin * 2; // New row 147 } 130 148 } 131 149 if (m_cy + c.h > m_h) { 132 int new_height; 133 if (m_cx == 0) { // add a whole row 134 new_height = m_h + rowHeight; 135 m_cy = m_h; 136 } else { // just extend row 137 new_height = m_cy + rowHeight; 138 } 150 int new_height = m_h*2; 151 while (new_height < m_cy + c.h) 152 new_height *= 2; 153 154 if (maxTextureHeight() > 0 && new_height > maxTextureHeight()) { 155 // We can't make a new texture of the required size, so 156 // bail out 157 return false; 158 } 159 139 160 // if no room in the current texture - realloc a larger texture 140 161 resizeTextureData(m_w, new_height); … … 148 169 coords.insert(iter.key(), c); 149 170 150 if (m_cx + c.w > m_w) { 151 m_cx = 0; 152 m_cy += rowHeight; 153 } else { 154 // for the Mono case, glyph_width is 8-bit aligned, 155 // and therefore so will m_cx 156 m_cx += c.w; 157 } 171 m_cx += c.w + paddingDoubled; 158 172 ++iter; 159 173 } 160 174 161 175 return true; 162 176 } 163 177 … … 183 197 }; 184 198 185 QFontEngineFT *ft = static_cast<QFontEngineFT*> (m_current_ textitem->fontEngine);199 QFontEngineFT *ft = static_cast<QFontEngineFT*> (m_current_fontengine); 186 200 QFontEngineFT::QGlyphSet *gset = ft->loadTransformedGlyphSet(m_transform); 187 201 188 202 if (gset && ft->loadGlyphs(gset, &g, 1, format)) { 189 QFontEngineFT::Glyph *glyph = gset->g lyph_data.value(g);203 QFontEngineFT::Glyph *glyph = gset->getGlyph(g); 190 204 const int bytesPerLine = (format == QFontEngineFT::Format_Mono ? ((glyph->width + 31) & ~31) >> 3 191 205 : (glyph->width + 3) & ~3); … … 195 209 #endif 196 210 if (m_type == QFontEngineGlyphCache::Raster_RGBMask) 197 return m_current_ textitem->fontEngine->alphaRGBMapForGlyph(g, glyphMargin(), m_transform);211 return m_current_fontengine->alphaRGBMapForGlyph(g, glyphMargin(), m_transform); 198 212 else 199 return m_current_ textitem->fontEngine->alphaMapForGlyph(g, m_transform);213 return m_current_fontengine->alphaMapForGlyph(g, m_transform); 200 214 201 215 return QImage(); … … 253 267 #endif 254 268 255 if (m_type == QFontEngineGlyphCache::Raster_RGBMask) { 256 QPainter p(&m_image); 269 if (m_type == QFontEngineGlyphCache::Raster_RGBMask) { 270 QImage ref(m_image.bits() + (c.x * 4 + c.y * m_image.bytesPerLine()), 271 qMax(mask.width(), c.w), qMax(mask.height(), c.h), m_image.bytesPerLine(), 272 m_image.format()); 273 QPainter p(&ref); 257 274 p.setCompositionMode(QPainter::CompositionMode_Source); 258 p.fillRect( c.x, c.y, c.w, c.h, QColor(0,0,0,0)); // TODO optimize this259 p.drawImage( c.x, c.y, mask);275 p.fillRect(0, 0, c.w, c.h, QColor(0,0,0,0)); // TODO optimize this 276 p.drawImage(0, 0, mask); 260 277 p.end(); 261 278 } else if (m_type == QFontEngineGlyphCache::Raster_Mono) { … … 325 342 if (m_image.rect().contains(base)) 326 343 m_image.setPixel(base, 255); 327 m_image.save(QString::fromLatin1("cache-%1-%2-%3.png") 328 .arg(m_current_textitem->font().family()) 329 .arg(m_current_textitem->font().pointSize()) 330 .arg(m_transform.type())); 344 m_image.save(QString::fromLatin1("cache-%1.png").arg(int(this))); 331 345 #endif 332 346 }
Note:
See TracChangeset
for help on using the changeset viewer.