~ubuntu-branches/ubuntu/vivid/qtdeclarative-opensource-src-gles/vivid

« back to all changes in this revision

Viewing changes to src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2015-03-11 16:51:45 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20150311165145-7653iqap3mau92gy
Tags: 5.4.1-0ubuntu1
Sync package with qtdeclarative-opensource-src - 5.4.1-1ubuntu3

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
 
49
49
DEFINE_BOOL_CONFIG_OPTION(qmlUseGlyphCacheWorkaround, QML_USE_GLYPHCACHE_WORKAROUND)
50
50
 
 
51
#if !defined(QSG_DEFAULT_DISTANCEFIELD_GLYPH_CACHE_PADDING)
 
52
#  define QSG_DEFAULT_DISTANCEFIELD_GLYPH_CACHE_PADDING 2
 
53
#endif
 
54
 
51
55
QSGDefaultDistanceFieldGlyphCache::QSGDefaultDistanceFieldGlyphCache(QSGDistanceFieldGlyphCacheManager *man, QOpenGLContext *c, const QRawFont &font)
52
56
    : QSGDistanceFieldGlyphCache(man, c, font)
53
57
    , m_maxTextureSize(0)
90
94
    for (QSet<glyph_t>::const_iterator it = glyphs.constBegin(); it != glyphs.constEnd() ; ++it) {
91
95
        glyph_t glyphIndex = *it;
92
96
 
 
97
        int padding = QSG_DEFAULT_DISTANCEFIELD_GLYPH_CACHE_PADDING;
93
98
        int glyphWidth = qCeil(glyphData(glyphIndex).boundingRect.width()) + distanceFieldRadius() * 2;
94
 
        QSize glyphSize(glyphWidth, QT_DISTANCEFIELD_TILESIZE(doubleGlyphResolution()));
 
99
        QSize glyphSize(glyphWidth + padding * 2, QT_DISTANCEFIELD_TILESIZE(doubleGlyphResolution()) + padding * 2);
95
100
        QRect alloc = m_areaAllocator->allocate(glyphSize);
96
101
 
97
102
        if (alloc.isNull()) {
101
106
 
102
107
                TexCoord unusedCoord = glyphTexCoord(unusedGlyph);
103
108
                int unusedGlyphWidth = qCeil(glyphData(unusedGlyph).boundingRect.width()) + distanceFieldRadius() * 2;
104
 
                m_areaAllocator->deallocate(QRect(unusedCoord.x, unusedCoord.y, unusedGlyphWidth, QT_DISTANCEFIELD_TILESIZE(doubleGlyphResolution())));
 
109
                m_areaAllocator->deallocate(QRect(unusedCoord.x - padding,
 
110
                                                  unusedCoord.y - padding,
 
111
                                                  padding * 2 + unusedGlyphWidth,
 
112
                                                  padding * 2 + QT_DISTANCEFIELD_TILESIZE(doubleGlyphResolution())));
105
113
 
106
114
                m_unusedGlyphs.remove(unusedGlyph);
107
115
                m_glyphsTexture.remove(unusedGlyph);
117
125
 
118
126
        TextureInfo *tex = textureInfo(alloc.y() / maxTextureSize());
119
127
        alloc = QRect(alloc.x(), alloc.y() % maxTextureSize(), alloc.width(), alloc.height());
 
128
 
120
129
        tex->allocatedArea |= alloc;
 
130
        Q_ASSERT(tex->padding == padding || tex->padding < 0);
 
131
        tex->padding = padding;
121
132
 
122
133
        GlyphPosition p;
123
134
        p.glyph = glyphIndex;
124
 
        p.position = alloc.topLeft();
 
135
        p.position = alloc.topLeft() + QPoint(padding, padding);
125
136
 
126
137
        glyphPositions.append(p);
127
138
        glyphsToRender.append(glyphIndex);
153
164
 
154
165
        glyphTextures[texInfo].append(glyphIndex);
155
166
 
 
167
        int padding = texInfo->padding;
156
168
        int expectedWidth = qCeil(c.width + c.xMargin * 2);
157
 
        if (glyph.width() != expectedWidth)
158
 
            glyph = glyph.copy(0, 0, expectedWidth, glyph.height());
 
169
        glyph = glyph.copy(-padding, -padding,
 
170
                           expectedWidth + padding  * 2, glyph.height() + padding * 2);
159
171
 
160
172
        if (useTextureResizeWorkaround()) {
161
173
            uchar *inBits = glyph.scanLine(0);
162
 
            uchar *outBits = texInfo->image.scanLine(int(c.y)) + int(c.x);
 
174
            uchar *outBits = texInfo->image.scanLine(int(c.y) - padding) + int(c.x) - padding;
163
175
            for (int y = 0; y < glyph.height(); ++y) {
164
176
                memcpy(outBits, inBits, glyph.width());
165
177
                inBits += glyph.width();
175
187
        if (useTextureUploadWorkaround()) {
176
188
            for (int i = 0; i < glyph.height(); ++i) {
177
189
                m_funcs->glTexSubImage2D(GL_TEXTURE_2D, 0,
178
 
                                         c.x, c.y + i, glyph.width(),1,
 
190
                                         c.x - padding, c.y + i - padding, glyph.width(),1,
179
191
                                         format, GL_UNSIGNED_BYTE,
180
192
                                         glyph.scanLine(i));
181
193
            }
182
194
        } else {
183
195
            m_funcs->glTexSubImage2D(GL_TEXTURE_2D, 0,
184
 
                                     c.x, c.y, glyph.width(), glyph.height(),
 
196
                                     c.x - padding, c.y - padding, glyph.width(), glyph.height(),
185
197
                                     format, GL_UNSIGNED_BYTE,
186
198
                                     glyph.constBits());
187
199
        }