summaryrefslogtreecommitdiffstats
path: root/src/opengl/qpaintengine_opengl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/opengl/qpaintengine_opengl.cpp')
-rw-r--r--src/opengl/qpaintengine_opengl.cpp108
1 files changed, 39 insertions, 69 deletions
diff --git a/src/opengl/qpaintengine_opengl.cpp b/src/opengl/qpaintengine_opengl.cpp
index c254597..0f33cab 100644
--- a/src/opengl/qpaintengine_opengl.cpp
+++ b/src/opengl/qpaintengine_opengl.cpp
@@ -2119,6 +2119,7 @@ void QOpenGLPaintEnginePrivate::fillPath(const QPainterPath &path)
updateGLMatrix();
}
+Q_GUI_EXPORT bool qt_isExtendedRadialGradient(const QBrush &brush);
static inline bool needsEmulation(Qt::BrushStyle style)
{
@@ -2129,9 +2130,11 @@ static inline bool needsEmulation(Qt::BrushStyle style)
void QOpenGLPaintEnginePrivate::updateUseEmulation()
{
- use_emulation = !use_fragment_programs
- && ((has_pen && needsEmulation(pen_brush_style))
- || (has_brush && needsEmulation(brush_style)));
+ use_emulation = (!use_fragment_programs
+ && ((has_pen && needsEmulation(pen_brush_style))
+ || (has_brush && needsEmulation(brush_style))))
+ || (has_pen && qt_isExtendedRadialGradient(cpen.brush()))
+ || (has_brush && qt_isExtendedRadialGradient(cbrush));
}
void QOpenGLPaintEngine::updatePen(const QPen &pen)
@@ -4533,11 +4536,14 @@ struct QGLGlyphCoord {
};
struct QGLFontTexture {
+ QGLFontTexture() : data(0) { }
+ ~QGLFontTexture() { free(data); }
int x_offset; // glyph offset within the
int y_offset;
GLuint texture;
int width;
int height;
+ uchar *data;
};
typedef QHash<glyph_t, QGLGlyphCoord*> QGLGlyphHash;
@@ -4560,7 +4566,7 @@ public:
QGLGlyphCoord *lookup(QFontEngine *, glyph_t);
void cacheGlyphs(QGLContext *, QFontEngine *, glyph_t *glyphs, int numGlyphs);
void cleanCache();
- void allocTexture(int width, int height, GLuint texture);
+ void allocTexture(QGLFontTexture *);
public slots:
void cleanupContext(const QGLContext *);
@@ -4678,19 +4684,18 @@ void QGLGlyphCache::cleanCache()
qt_context_cache.clear();
}
-void QGLGlyphCache::allocTexture(int width, int height, GLuint texture)
+void QGLGlyphCache::allocTexture(QGLFontTexture *font_tex)
{
- uchar *tex_data = (uchar *) malloc(width*height*2);
- memset(tex_data, 0, width*height*2);
- glBindTexture(GL_TEXTURE_2D, texture);
+ font_tex->data = (uchar *) malloc(font_tex->width*font_tex->height*2);
+ memset(font_tex->data, 0, font_tex->width*font_tex->height*2);
+ glBindTexture(GL_TEXTURE_2D, font_tex->texture);
#ifndef QT_OPENGL_ES
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE8_ALPHA8,
- width, height, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, tex_data);
+ font_tex->width, font_tex->height, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, font_tex->data);
#else
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA,
- width, height, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, tex_data);
+ font_tex->width, font_tex->height, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, font_tex->data);
#endif
- free(tex_data);
}
#if 0
@@ -4736,7 +4741,7 @@ void QGLGlyphCache::cacheGlyphs(QGLContext *context, QFontEngine *fontEngine,
// qDebug() << "new context" << context << font_cache;
qt_context_cache.insert(context, font_cache);
if (context->isValid()) {
- if (context->device()->devType() == QInternal::Widget) {
+ if (context->device() && context->device()->devType() == QInternal::Widget) {
QWidget *widget = static_cast<QWidget *>(context->device());
connect(widget, SIGNAL(destroyed(QObject*)), SLOT(widgetDestroyed(QObject*)));
}
@@ -4774,13 +4779,13 @@ void QGLGlyphCache::cacheGlyphs(QGLContext *context, QFontEngine *fontEngine,
Q_ASSERT(max_tex_size > 0);
if (tex_width > max_tex_size)
tex_width = max_tex_size;
- allocTexture(tex_width, tex_height, font_texture);
font_tex = new QGLFontTexture;
font_tex->texture = font_texture;
font_tex->x_offset = x_margin;
font_tex->y_offset = y_margin;
font_tex->width = tex_width;
font_tex->height = tex_height;
+ allocTexture(font_tex);
// qDebug() << "new font tex - width:" << tex_width << "height:"<< tex_height
// << hex << "tex id:" << font_tex->texture << "key:" << font_key << "num cached:" << qt_font_textures.size();
qt_font_textures.insert(font_key, font_tex);
@@ -4803,21 +4808,19 @@ void QGLGlyphCache::cacheGlyphs(QGLContext *context, QFontEngine *fontEngine,
font_tex->y_offset += strip_height;
if (font_tex->y_offset >= font_tex->height) {
// get hold of the old font texture
- uchar *old_tex_data = (uchar *) malloc(font_tex->width*font_tex->height*2);
+ uchar *old_tex_data = font_tex->data;
int old_tex_height = font_tex->height;
-#ifndef QT_OPENGL_ES
- glGetTexImage(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, old_tex_data);
-#endif
// realloc a larger texture
glDeleteTextures(1, &font_tex->texture);
glGenTextures(1, &font_tex->texture);
font_tex->height = qt_next_power_of_two(font_tex->height + strip_height);
- allocTexture(font_tex->width, font_tex->height, font_tex->texture);
+ allocTexture(font_tex);
// write back the old texture data
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, font_tex->width, old_tex_height,
GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, old_tex_data);
+ memcpy(font_tex->data, old_tex_data, font_tex->width*old_tex_height*2);
free(old_tex_data);
// update the texture coords and the y offset for the existing glyphs in
@@ -4832,7 +4835,6 @@ void QGLGlyphCache::cacheGlyphs(QGLContext *context, QFontEngine *fontEngine,
}
QImage glyph_im(fontEngine->alphaMapForGlyph(glyphs[i]));
- glyph_im = glyph_im.convertToFormat(QImage::Format_Indexed8);
glyph_width = glyph_im.width();
Q_ASSERT(glyph_width >= 0);
// pad the glyph width to an even number
@@ -4855,15 +4857,23 @@ void QGLGlyphCache::cacheGlyphs(QGLContext *context, QFontEngine *fontEngine,
#endif
if (!glyph_im.isNull()) {
-
int idx = 0;
uchar *tex_data = (uchar *) malloc(glyph_width*glyph_im.height()*2);
memset(tex_data, 0, glyph_width*glyph_im.height()*2);
+ bool is8BitGray = false;
+#ifdef Q_WS_QPA
+ if (glyph_im.format() == QImage::Format_Indexed8) {
+ is8BitGray = true;
+ }
+#endif
+ glyph_im = glyph_im.convertToFormat(QImage::Format_Indexed8);
+ int cacheLineStart = (font_tex->x_offset + font_tex->y_offset*font_tex->width)*2;
for (int y=0; y<glyph_im.height(); ++y) {
uchar *s = (uchar *) glyph_im.scanLine(y);
+ int lineStart = idx;
for (int x=0; x<glyph_im.width(); ++x) {
- uchar alpha = qAlpha(glyph_im.color(*s));
+ uchar alpha = is8BitGray ? *s : qAlpha(glyph_im.color(*s));
tex_data[idx] = alpha;
tex_data[idx+1] = alpha;
++s;
@@ -4871,6 +4881,9 @@ void QGLGlyphCache::cacheGlyphs(QGLContext *context, QFontEngine *fontEngine,
}
if (glyph_im.width()%2 != 0)
idx += 2;
+ // update cache
+ memcpy(font_tex->data+cacheLineStart, tex_data+lineStart, glyph_width*2);
+ cacheLineStart += font_tex->width*2;
}
glTexSubImage2D(GL_TEXTURE_2D, 0, font_tex->x_offset, font_tex->y_offset,
glyph_width, glyph_im.height(),
@@ -4942,7 +4955,7 @@ void QOpenGLPaintEngine::drawStaticTextItem(QStaticTextItem *textItem)
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
bool antialias = !(textItem->fontEngine()->fontDef.styleStrategy & QFont::NoAntialias)
- && (d->matrix.type() > QTransform::TxTranslate);
+ && (d->matrix.type() > QTransform::TxTranslate);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, antialias ? GL_LINEAR : GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, antialias ? GL_LINEAR : GL_NEAREST);
@@ -5442,50 +5455,7 @@ void QOpenGLPaintEngine::transformChanged()
updateMatrix(state()->matrix);
}
-static QPainterPath painterPathFromVectorPath(const QVectorPath &path)
-{
- const qreal *points = path.points();
- const QPainterPath::ElementType *types = path.elements();
-
- QPainterPath p;
- if (types) {
- int id = 0;
- for (int i=0; i<path.elementCount(); ++i) {
- switch(types[i]) {
- case QPainterPath::MoveToElement:
- p.moveTo(QPointF(points[id], points[id+1]));
- id+=2;
- break;
- case QPainterPath::LineToElement:
- p.lineTo(QPointF(points[id], points[id+1]));
- id+=2;
- break;
- case QPainterPath::CurveToElement: {
- QPointF p1(points[id], points[id+1]);
- QPointF p2(points[id+2], points[id+3]);
- QPointF p3(points[id+4], points[id+5]);
- p.cubicTo(p1, p2, p3);
- id+=6;
- break;
- }
- case QPainterPath::CurveToDataElement:
- ;
- break;
- }
- }
- } else {
- p.moveTo(QPointF(points[0], points[1]));
- int id = 2;
- for (int i=1; i<path.elementCount(); ++i) {
- p.lineTo(QPointF(points[id], points[id+1]));
- id+=2;
- }
- }
- if (path.hints() & QVectorPath::WindingFill)
- p.setFillRule(Qt::WindingFill);
-
- return p;
-}
+Q_GUI_EXPORT QPainterPath qt_painterPathFromVectorPath(const QVectorPath &path);
void QOpenGLPaintEngine::fill(const QVectorPath &path, const QBrush &brush)
{
@@ -5494,11 +5464,11 @@ void QOpenGLPaintEngine::fill(const QVectorPath &path, const QBrush &brush)
if (brush.style() == Qt::NoBrush)
return;
- if (!d->use_fragment_programs && needsEmulation(brush.style())) {
+ if ((!d->use_fragment_programs && needsEmulation(brush.style())) || qt_isExtendedRadialGradient(brush)) {
QPainter *p = painter();
QBrush oldBrush = p->brush();
p->setBrush(brush);
- qt_draw_helper(p->d_ptr.data(), painterPathFromVectorPath(path), QPainterPrivate::FillDraw);
+ qt_draw_helper(p->d_ptr.data(), qt_painterPathFromVectorPath(path), QPainterPrivate::FillDraw);
p->setBrush(oldBrush);
return;
}
@@ -5515,7 +5485,7 @@ void QOpenGLPaintEngine::fill(const QVectorPath &path, const QBrush &brush)
drawRects(&r, 1);
updatePen(old_pen);
} else {
- d->fillPath(painterPathFromVectorPath(path));
+ d->fillPath(qt_painterPathFromVectorPath(path));
}
updateBrush(old_brush, state()->brushOrigin);