From 8927084d0acfea2bb3fc8a932069c1d5ceb001d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 10 Jan 2013 15:09:32 +0100 Subject: Refactor paint/font-engine shouldDrawCachedGlyphs and supportsTransformations Some cruft had built up over time, and this is an attempt at cleaning up the naming and use of these functions, and should not have any behavioral effects. The function supportsTransformations() has been renamed in QPaintEngineEx to reflect its use, which is to decide if QPainter needs to pre-transform the coordinates of the static text before asking the paint-engine to draw it. The new name is requiresPretransformedGlyphPositions(). The OpenGL and CoreGraphics (Mac) paint engines keep their behavior of not needing pre-transformed text, while the raster engine needs this when using cached glyphs. The base-class implementation assumes that all transforms that include a projection will need pre-transform, which is also the case for the raster engine. All decisions in the paint engines about whether or not to use the glyph cache when drawing text are now deferred to the function shouldDrawCachedGlyphs(), which has been refactored for the GL paint engine(s) to share more logic. All implementations call the base class implementation, which ensures that large font sizes will not be cached. The raster engine will in addition ask the font engine whether or not it can produce glyphs for the glyph-cache with the given transform. This is the only remaining instance of the supportsTransformations() function, and will for all font engines except the CoreText engine support affine transformations. The CoreText engine on the other hand only supports translations (for now). Change-Id: I8fb5e43e3de3ef62a526a79a6dfeda7f9546771d Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../gl2paintengineex/qpaintengineex_opengl2.cpp | 22 ++++++++++++---------- .../gl2paintengineex/qpaintengineex_opengl2_p.h | 3 ++- 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'src/opengl/gl2paintengineex') diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index 7284efa53b..ebff94da77 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -626,6 +626,16 @@ bool QGL2PaintEngineEx::isNativePaintingActive() const { return d->nativePaintingActive; } +bool QGL2PaintEngineEx::shouldDrawCachedGlyphs(QFontEngine *fontEngine, const QTransform &t) const +{ + float det = t.determinant(); + + // Don't try to cache huge fonts or vastly transformed fonts + return t.type() < QTransform::TxProject + && QPaintEngineEx::shouldDrawCachedGlyphs(fontEngine, t) + && det >= 0.25f && det <= 4.f; +} + void QGL2PaintEngineExPrivate::transferMode(EngineMode newMode) { if (newMode == mode) @@ -1439,11 +1449,10 @@ void QGL2PaintEngineEx::drawStaticTextItem(QStaticTextItem *textItem) ensureActive(); QPainterState *s = state(); - float det = s->matrix.determinant(); // don't try to cache huge fonts or vastly transformed fonts QFontEngine *fontEngine = textItem->fontEngine(); - if (shouldDrawCachedGlyphs(fontEngine, s->matrix) && det >= 0.25f && det <= 4.f) { + if (shouldDrawCachedGlyphs(fontEngine, s->matrix)) { QFontEngineGlyphCache::Type glyphType = fontEngine->glyphFormat >= 0 ? QFontEngineGlyphCache::Type(textItem->fontEngine()->glyphFormat) : d->glyphCacheType; @@ -1497,13 +1506,6 @@ void QGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &textItem QTransform::TransformationType txtype = s->matrix.type(); - float det = s->matrix.determinant(); - bool drawCached = txtype < QTransform::TxProject; - - // don't try to cache huge fonts or vastly transformed fonts - if (!shouldDrawCachedGlyphs(ti.fontEngine, s->matrix) || det < 0.25f || det > 4.f) - drawCached = false; - QFontEngineGlyphCache::Type glyphType = ti.fontEngine->glyphFormat >= 0 ? QFontEngineGlyphCache::Type(ti.fontEngine->glyphFormat) : d->glyphCacheType; @@ -1519,7 +1521,7 @@ void QGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &textItem } } - if (drawCached) { + if (shouldDrawCachedGlyphs(ti.fontEngine, s->matrix)) { QVarLengthArray positions; QVarLengthArray glyphs; QTransform matrix = QTransform::fromTranslate(p.x(), p.y()); diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h index f2dc5af768..dd09046bc9 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h @@ -155,7 +155,8 @@ public: void setRenderTextActive(bool); bool isNativePaintingActive() const; - bool supportsTransformations(QFontEngine *, const QTransform &) const { return true; } + bool requiresPretransformedGlyphPositions(QFontEngine *, const QTransform &) const { return false; } + bool shouldDrawCachedGlyphs(QFontEngine *, const QTransform &) const; private: Q_DISABLE_COPY(QGL2PaintEngineEx) }; -- cgit v1.2.3