summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleg Romashin <romaxa@gmail.com>2010-07-16 09:47:23 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2010-07-16 09:49:42 +0100
commit6b92d5a0f9fce28f99b07177454da00f984fdb43 (patch)
tree03dfea698268e4ab5da3b1ce95a898c4dbb7c33f
parentf53f072a223c3fbdeba315f5cba755cba498e121 (diff)
qt: Use native glyph rendering.
Remove the hack of using the xlib surface to do glyph rendering and use the new interface introduced with Qt4.7, or else fallback to image rendering with freetype. Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> [2 files changed, 35 insertions(+), 140 deletions(-) \o/]
-rw-r--r--src/cairo-qt-surface.cpp169
-rw-r--r--src/cairo-xlib-surface.c6
2 files changed, 35 insertions, 140 deletions
diff --git a/src/cairo-qt-surface.cpp b/src/cairo-qt-surface.cpp
index 2ac06ef5..5b61b422 100644
--- a/src/cairo-qt-surface.cpp
+++ b/src/cairo-qt-surface.cpp
@@ -45,6 +45,7 @@
#include "cairo-surface-clipper-private.h"
#include "cairo-types-private.h"
+#include "cairo-ft.h"
#include "cairo-qt.h"
#include <memory>
@@ -58,14 +59,10 @@
#include <QtGui/QPen>
#include <QtGui/QWidget>
#include <QtGui/QX11Info>
+#include <QtCore/QVarLengthArray>
-#if CAIRO_HAS_XLIB_XRENDER_SURFACE
-#include "cairo-xlib.h"
-#include "cairo-xlib-xrender.h"
-// I hate X
-#undef Status
-#undef CursorShape
-#undef Bool
+#if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)) || defined(QT_GLYPHS_API_BACKPORT)
+extern void qt_draw_glyphs(QPainter *, const quint32 *glyphs, const QPointF *positions, int count);
#endif
#include <sys/time.h>
@@ -118,15 +115,6 @@ struct cairo_qt_surface_t {
cairo_bool_t supports_porter_duff;
-#if defined(Q_WS_X11) && CAIRO_HAS_XLIB_XRENDER_SURFACE
- /* temporary, so that we can share the xlib surface's glyphs code */
- bool xlib_has_clipping;
- cairo_surface_t *xlib_equiv;
- QRect xlib_clip_bounds;
- int xlib_clip_serial;
- QPoint redir_offset;
-#endif
-
QPainter *p;
/* The pixmap/image constructors will store their objects here */
@@ -145,11 +133,6 @@ struct cairo_qt_surface_t {
*/
static cairo_bool_t _qpixmaps_have_no_alpha = FALSE;
-#if defined(Q_WS_X11) && CAIRO_HAS_XLIB_XRENDER_SURFACE
-slim_hidden_proto (cairo_xlib_surface_create);
-slim_hidden_proto (cairo_xlib_surface_create_with_xrender_format);
-#endif
-
/**
** Helper methods
**/
@@ -498,11 +481,6 @@ _cairo_qt_surface_finish (void *abstract_surface)
_cairo_surface_clipper_reset (&qs->clipper);
-#if defined(Q_WS_X11) && CAIRO_HAS_XLIB_XRENDER_SURFACE
- if (qs->xlib_equiv)
- cairo_surface_destroy (qs->xlib_equiv);
-#endif
-
if (qs->image)
delete qs->image;
@@ -1392,33 +1370,40 @@ _cairo_qt_surface_show_glyphs (void *abstract_surface,
cairo_clip_t *clip,
int *remaining_glyphs)
{
+#if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)) || defined(QT_GLYPHS_API_BACKPORT)
cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface;
-#if defined(Q_WS_X11) && CAIRO_HAS_XLIB_XRENDER_SURFACE
- /* If we have an equivalent X surface, let the xlib surface handle this
- * until we figure out how to do this natively with Qt.
- */
- if (qs->xlib_equiv) {
- D(fprintf(stderr, "q[%p] show_glyphs (x11 equiv) op:%s nglyphs: %d\n", abstract_surface, _opstr(op), num_glyphs));
-
- for (int i = 0; i < num_glyphs; i++) {
- glyphs[i].x -= qs->redir_offset.x();
- glyphs[i].y -= qs->redir_offset.y();
- }
-
- return (cairo_int_status_t)
- _cairo_surface_show_text_glyphs (qs->xlib_equiv,
- op, source,
- NULL, 0,
- glyphs, num_glyphs,
- NULL, 0,
- (cairo_text_cluster_flags_t) 0,
- scaled_font,
- clip);
+ // pick out the colour to use from the cairo source
+ cairo_solid_pattern_t *solid = (cairo_solid_pattern_t*) source;
+ cairo_scaled_glyph_t* glyph;
+ // documentation says you have to freeze the cache, but I don't believe it
+ _cairo_scaled_font_freeze_cache(scaled_font);
+
+ QColor tempColour(solid->color.red * 255, solid->color.green * 255, solid->color.blue * 255);
+ QVarLengthArray<QPointF> positions(num_glyphs);
+ QVarLengthArray<unsigned int> glyphss(num_glyphs);
+ FT_Face face = cairo_ft_scaled_font_lock_face (scaled_font);
+ const FT_Size_Metrics& ftMetrics = face->size->metrics;
+ QFont font(face->family_name);
+ font.setStyleStrategy(QFont::NoFontMerging);
+ font.setBold(face->style_flags & FT_STYLE_FLAG_BOLD);
+ font.setItalic(face->style_flags & FT_STYLE_FLAG_ITALIC);
+ font.setKerning(face->face_flags & FT_FACE_FLAG_KERNING);
+ font.setPixelSize(ftMetrics.y_ppem);
+ cairo_ft_scaled_font_unlock_face(scaled_font);
+ qs->p->setFont(font);
+ qs->p->setPen(tempColour);
+ for (int currentGlyph = 0; currentGlyph < num_glyphs; currentGlyph++) {
+ positions[currentGlyph].setX(glyphs[currentGlyph].x);
+ positions[currentGlyph].setY(glyphs[currentGlyph].y);
+ glyphss[currentGlyph] = glyphs[currentGlyph].index;
}
-#endif
-
+ qt_draw_glyphs(qs->p, glyphss.data(), positions.data(), num_glyphs);
+ _cairo_scaled_font_thaw_cache(scaled_font);
+ return CAIRO_INT_STATUS_SUCCESS;
+#else
return CAIRO_INT_STATUS_UNSUPPORTED;
+#endif
}
static cairo_int_status_t
@@ -1555,24 +1540,6 @@ _cairo_qt_surface_composite (cairo_operator_t op,
}
static cairo_status_t
-_cairo_qt_surface_flush (void *abstract_surface)
-{
- cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface;
-
- if (qs->p == NULL)
- return CAIRO_STATUS_SUCCESS;
-
- if (qs->image || qs->pixmap) {
- qs->p->end ();
- qs->p->begin (qs->p->device ());
- } else {
- qs->p->restore ();
- }
-
- return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
_cairo_qt_surface_mark_dirty (void *abstract_surface,
int x, int y,
int width, int height)
@@ -1609,7 +1576,7 @@ static const cairo_surface_backend_t cairo_qt_surface_backend = {
_cairo_qt_surface_get_extents,
NULL, /* old_show_glyphs */
NULL, /* get_font_options */
- _cairo_qt_surface_flush,
+ NULL, /* flush */
_cairo_qt_surface_mark_dirty,
NULL, /* scaled_font_fini */
NULL, /* scaled_glyph_fini */
@@ -1629,64 +1596,6 @@ static const cairo_surface_backend_t cairo_qt_surface_backend = {
NULL, /* show_text_glyphs */
};
-#if defined(Q_WS_X11) && CAIRO_HAS_XLIB_XRENDER_SURFACE
-static cairo_surface_t *
-_cairo_qt_create_xlib_surface (cairo_qt_surface_t *qs)
-{
- if (!qs->p)
- return NULL;
-
- QPaintDevice *pd = qs->p->device();
- if (!pd)
- return NULL;
-
- QPoint offs;
- QPaintDevice *rpd = QPainter::redirected(pd, &offs);
- if (rpd) {
- pd = rpd;
- qs->redir_offset = offs;
- }
-
- if (pd->devType() == QInternal::Widget) {
- QWidget *w = (QWidget*) pd;
- QX11Info xinfo = w->x11Info();
-
- return cairo_xlib_surface_create (xinfo.display(),
- (Drawable) w->handle (),
- (Visual *) xinfo.visual (),
- w->width (), w->height ());
- } else if (pd->devType() == QInternal::Pixmap) {
- QPixmap *pixmap = (QPixmap*) pd;
- QX11Info xinfo = pixmap->x11Info ();
- XRenderPictFormat *xrender_format;
- int pict_format;
-
- switch (pixmap->depth ()) {
- case 1:
- pict_format = PictStandardA1; break;
- case 8:
- pict_format = PictStandardA8; break;
- case 24:
- pict_format = PictStandardRGB24; break;
- default:
- ASSERT_NOT_REACHED;
- case 32:
- pict_format = PictStandardARGB32; break;
- }
- xrender_format = XRenderFindStandardFormat (xinfo.display (),
- pict_format);
-
- return cairo_xlib_surface_create_with_xrender_format (xinfo.display(),
- (Drawable) pixmap->handle (),
- ScreenOfDisplay (xinfo.display (),
- xinfo.screen ()),
- xrender_format,
- pixmap->width (), pixmap->height ());
- } else
- return NULL;
-}
-#endif
-
cairo_surface_t *
cairo_qt_surface_create (QPainter *painter)
{
@@ -1717,10 +1626,6 @@ cairo_qt_surface_create (QPainter *painter)
qs->window = painter->window();
-#if defined(Q_WS_X11) && CAIRO_HAS_XLIB_XRENDER_SURFACE
- qs->xlib_equiv = _cairo_qt_create_xlib_surface (qs);
-#endif
-
D(fprintf(stderr, "qpainter_surface_create: window: [%d %d %d %d] pd:%d\n",
qs->window.x(), qs->window.y(), qs->window.width(), qs->window.height(),
qs->supports_porter_duff));
@@ -1819,10 +1724,6 @@ cairo_qt_surface_create_with_qpixmap (cairo_content_t content,
qs->window = QRect(0, 0, width, height);
-#if defined(Q_WS_X11) && CAIRO_HAS_XLIB_XRENDER_SURFACE
- qs->xlib_equiv = _cairo_qt_create_xlib_surface (qs);
-#endif
-
D(fprintf(stderr, "qpainter_surface_create: qpixmap: [%d %d %d %d] pd:%d\n",
qs->window.x(), qs->window.y(), qs->window.width(), qs->window.height(),
qs->supports_porter_duff));
diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 92351300..350331d1 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -176,10 +176,6 @@ _cairo_xlib_surface_show_glyphs (void *abstract_dst,
cairo_clip_t *clip,
int *remaining_glyphs);
-/* XXX temporarily used by cairo-qt-surface.c */
-slim_hidden_proto (cairo_xlib_surface_create);
-slim_hidden_proto (cairo_xlib_surface_create_with_xrender_format);
-
/*
* Instead of taking two round trips for each blending request,
* assume that if a particular drawable fails GetImage that it will
@@ -3392,7 +3388,6 @@ cairo_xlib_surface_create (Display *dpy,
visual, NULL,
width, height, 0);
}
-slim_hidden_def (cairo_xlib_surface_create);
/**
* cairo_xlib_surface_create_for_bitmap:
@@ -3476,7 +3471,6 @@ cairo_xlib_surface_create_with_xrender_format (Display *dpy,
_visual_for_xrender_format (scr, format),
format, width, height, 0);
}
-slim_hidden_def (cairo_xlib_surface_create_with_xrender_format);
/**
* cairo_xlib_surface_get_xrender_format: