[cairo-commit] 6 commits - src/cairo-qt-surface.cpp
Jeff Muizelaar
jrmuizel at kemper.freedesktop.org
Wed Jul 15 21:23:58 PDT 2009
src/cairo-qt-surface.cpp | 340 ++++++++++++++++++++++++-----------------------
1 file changed, 175 insertions(+), 165 deletions(-)
New commits:
commit 01eec61f4ffae4f492d667b6accb5ed3f6960d2c
Author: Tobias Hunger <tobias.hunger at gmail.com>
Date: Thu Jul 16 00:16:59 2009 -0400
[qt] Remove use of unnecessary QBrush pointer
QBrush is a implicitly shared datastructure. There is on need to layer
"explicit pointer based sharing" atop of it.
Mozilla Bug #498871
diff --git a/src/cairo-qt-surface.cpp b/src/cairo-qt-surface.cpp
index ed28125..70f6d1a 100644
--- a/src/cairo-qt-surface.cpp
+++ b/src/cairo-qt-surface.cpp
@@ -837,9 +837,10 @@ _cairo_qt_surface_intersect_clip_path (void *abstract_surface,
**/
struct PatternToBrushConverter {
- PatternToBrushConverter (const cairo_pattern_t *pattern)
- : mBrush(0),
- mAcquiredImageParent(0)
+ PatternToBrushConverter (const cairo_pattern_t *pattern) :
+ mAcquiredImageParent(0),
+ mAcquiredImage(0),
+ mAcquiredImageExtra(0)
{
if (pattern->type == CAIRO_PATTERN_TYPE_SOLID) {
cairo_solid_pattern_t *solid = (cairo_solid_pattern_t*) pattern;
@@ -849,7 +850,7 @@ struct PatternToBrushConverter {
solid->color.blue,
solid->color.alpha);
- mBrush = new QBrush(color);
+ mBrush = QBrush(color);
} else if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE) {
cairo_surface_pattern_t *spattern = (cairo_surface_pattern_t*) pattern;
cairo_surface_t *surface = spattern->surface;
@@ -858,12 +859,12 @@ struct PatternToBrushConverter {
cairo_qt_surface_t *qs = (cairo_qt_surface_t*) surface;
if (qs->image) {
- mBrush = new QBrush(*qs->image);
+ mBrush = QBrush(*qs->image);
} else if (qs->pixmap) {
- mBrush = new QBrush(*qs->pixmap);
+ mBrush = QBrush(*qs->pixmap);
} else {
// do something smart
- mBrush = new QBrush(0xff0000ff);
+ mBrush = QBrush(0xff0000ff);
}
} else {
cairo_image_surface_t *isurf = NULL;
@@ -883,13 +884,13 @@ struct PatternToBrushConverter {
}
if (isurf) {
- mBrush = new QBrush (QImage ((const uchar *) isurf->data,
+ mBrush = QBrush (QImage ((const uchar *) isurf->data,
isurf->width,
isurf->height,
isurf->stride,
_qimage_format_from_cairo_format (isurf->format)));
} else {
- mBrush = new QBrush(0x0000ffff);
+ mBrush = QBrush(0x0000ffff);
}
}
} else if (pattern->type == CAIRO_PATTERN_TYPE_LINEAR ||
@@ -1025,34 +1026,32 @@ struct PatternToBrushConverter {
grad->setColorAt (offset, color);
}
- mBrush = new QBrush(*grad);
+ mBrush = QBrush(*grad);
delete grad;
}
- if (mBrush &&
+ if (mBrush.style() != Qt::NoBrush &&
pattern->type != CAIRO_PATTERN_TYPE_SOLID &&
! _cairo_matrix_is_identity (&pattern->matrix))
{
cairo_matrix_t pm = pattern->matrix;
cairo_status_t status = cairo_matrix_invert (&pm);
assert (status == CAIRO_STATUS_SUCCESS);
- mBrush->setMatrix (_qmatrix_from_cairo_matrix (pm));
+ mBrush.setMatrix (_qmatrix_from_cairo_matrix (pm));
}
}
~PatternToBrushConverter () {
- delete mBrush;
-
if (mAcquiredImageParent)
_cairo_surface_release_source_image (mAcquiredImageParent, mAcquiredImage, mAcquiredImageExtra);
}
operator QBrush& () {
- return *mBrush;
+ return mBrush;
}
- QBrush *mBrush;
+ QBrush mBrush;
cairo_surface_t *mAcquiredImageParent;
cairo_image_surface_t *mAcquiredImage;
commit 222c12cc4e48c2c9178a7390ea8edd73d7cb56bb
Author: Tobias Hunger <tobias.hunger at gmail.com>
Date: Thu Jul 16 00:16:59 2009 -0400
[qt] Remove use of unnecessary QPen pointer
QPen is a implicitly shared class, so there is no need to do explicit sharing
via pointers.
Mozilla Bug #498873
diff --git a/src/cairo-qt-surface.cpp b/src/cairo-qt-surface.cpp
index 258c173..ed28125 100644
--- a/src/cairo-qt-surface.cpp
+++ b/src/cairo-qt-surface.cpp
@@ -1061,8 +1061,8 @@ struct PatternToBrushConverter {
struct PatternToPenConverter {
PatternToPenConverter (const cairo_pattern_t *source,
- cairo_stroke_style_t *style)
- : mBrushConverter(source)
+ cairo_stroke_style_t *style) :
+ mBrushConverter(source)
{
Qt::PenJoinStyle join = Qt::MiterJoin;
Qt::PenCapStyle cap = Qt::SquareCap;
@@ -1091,8 +1091,8 @@ struct PatternToPenConverter {
break;
}
- mPen = new QPen (mBrushConverter, style->line_width, Qt::SolidLine, cap, join);
- mPen->setMiterLimit (style->miter_limit);
+ mPen = QPen(mBrushConverter, style->line_width, Qt::SolidLine, cap, join);
+ mPen.setMiterLimit (style->miter_limit);
if (style->dash && style->num_dashes) {
Qt::PenStyle pstyle = Qt::NoPen;
@@ -1113,7 +1113,7 @@ struct PatternToPenConverter {
}
if (pstyle != Qt::NoPen) {
- mPen->setStyle(pstyle);
+ mPen.setStyle(pstyle);
return;
}
@@ -1130,20 +1130,18 @@ struct PatternToPenConverter {
}
}
- mPen->setDashPattern (dashes);
- mPen->setDashOffset (style->dash_offset / style->line_width);
+ mPen.setDashPattern(dashes);
+ mPen.setDashOffset(style->dash_offset / style->line_width);
}
}
- ~PatternToPenConverter() {
- delete mPen;
- }
+ ~PatternToPenConverter() { }
operator QPen& () {
- return *mPen;
+ return mPen;
}
- QPen *mPen;
+ QPen mPen;
PatternToBrushConverter mBrushConverter;
};
commit 0797b2fcaad0c17c35e67ec5d01a0556a76ee39d
Author: Tobias Hunger <tobias.hunger at gmail.com>
Date: Thu Jul 16 00:16:59 2009 -0400
[qt] Cleanup some whitespace
Mozilla bug #498843
diff --git a/src/cairo-qt-surface.cpp b/src/cairo-qt-surface.cpp
index fdd922e..258c173 100644
--- a/src/cairo-qt-surface.cpp
+++ b/src/cairo-qt-surface.cpp
@@ -684,7 +684,7 @@ _cairo_qt_surface_intersect_clip_path (void *abstract_surface,
return CAIRO_INT_STATUS_UNSUPPORTED;
if (path == NULL) {
- //fprintf (stderr, "clip clear\n");
+ //fprintf (stderr, "clip clear\n");
// How the clip path is reset depends on whether we own p or not
if (qs->pixmap || qs->image) {
// we own p
@@ -694,10 +694,10 @@ _cairo_qt_surface_intersect_clip_path (void *abstract_surface,
qs->p->save ();
}
- if (!qs->no_update_clip_bounds) {
- qs->clip_bounds.setRect(0, 0, 0, 0);
- qs->has_clipping = false;
- }
+ if (!qs->no_update_clip_bounds) {
+ qs->clip_bounds.setRect(0, 0, 0, 0);
+ qs->has_clipping = false;
+ }
return CAIRO_INT_STATUS_SUCCESS;
}
@@ -1061,86 +1061,86 @@ struct PatternToBrushConverter {
struct PatternToPenConverter {
PatternToPenConverter (const cairo_pattern_t *source,
- cairo_stroke_style_t *style)
+ cairo_stroke_style_t *style)
: mBrushConverter(source)
{
- Qt::PenJoinStyle join = Qt::MiterJoin;
- Qt::PenCapStyle cap = Qt::SquareCap;
-
- switch (style->line_cap) {
- case CAIRO_LINE_CAP_BUTT:
- cap = Qt::FlatCap;
- break;
- case CAIRO_LINE_CAP_ROUND:
- cap = Qt::RoundCap;
- break;
- case CAIRO_LINE_CAP_SQUARE:
- cap = Qt::SquareCap;
- break;
- }
-
- switch (style->line_join) {
- case CAIRO_LINE_JOIN_MITER:
- join = Qt::MiterJoin;
- break;
- case CAIRO_LINE_JOIN_ROUND:
- join = Qt::RoundJoin;
- break;
- case CAIRO_LINE_JOIN_BEVEL:
- join = Qt::BevelJoin;
- break;
- }
-
- mPen = new QPen (mBrushConverter, style->line_width, Qt::SolidLine, cap, join);
- mPen->setMiterLimit (style->miter_limit);
-
- if (style->dash && style->num_dashes) {
- Qt::PenStyle pstyle = Qt::NoPen;
-
- if (style->num_dashes == 2) {
- if ((style->dash[0] == style->line_width &&
- style->dash[1] == style->line_width && style->line_width <= 2.0) ||
- (style->dash[0] == 0.0 &&
- style->dash[1] == style->line_width * 2 && cap == Qt::RoundCap))
- {
- pstyle = Qt::DotLine;
- } else if (style->dash[0] == style->line_width * DASH_LENGTH &&
- style->dash[1] == style->line_width * DASH_LENGTH &&
- cap == Qt::FlatCap)
- {
- pstyle = Qt::DashLine;
- }
- }
-
- if (pstyle != Qt::NoPen) {
- mPen->setStyle(pstyle);
- return;
- }
-
- unsigned int odd_dash = style->num_dashes % 2;
+ Qt::PenJoinStyle join = Qt::MiterJoin;
+ Qt::PenCapStyle cap = Qt::SquareCap;
+
+ switch (style->line_cap) {
+ case CAIRO_LINE_CAP_BUTT:
+ cap = Qt::FlatCap;
+ break;
+ case CAIRO_LINE_CAP_ROUND:
+ cap = Qt::RoundCap;
+ break;
+ case CAIRO_LINE_CAP_SQUARE:
+ cap = Qt::SquareCap;
+ break;
+ }
- QVector<qreal> dashes (odd_dash ? style->num_dashes * 2 : style->num_dashes);
- for (unsigned int i = 0; i < odd_dash+1; i++) {
- for (unsigned int j = 0; j < style->num_dashes; j++) {
- // In Qt, the dash lengths are given in units of line width, whereas
- // in cairo, they are in user-space units. We'll always apply the CTM,
- // so all we have to do here is divide cairo's dash lengths by the line
- // width.
- dashes.append (style->dash[j] / style->line_width);
- }
- }
+ switch (style->line_join) {
+ case CAIRO_LINE_JOIN_MITER:
+ join = Qt::MiterJoin;
+ break;
+ case CAIRO_LINE_JOIN_ROUND:
+ join = Qt::RoundJoin;
+ break;
+ case CAIRO_LINE_JOIN_BEVEL:
+ join = Qt::BevelJoin;
+ break;
+ }
- mPen->setDashPattern (dashes);
- mPen->setDashOffset (style->dash_offset / style->line_width);
- }
+ mPen = new QPen (mBrushConverter, style->line_width, Qt::SolidLine, cap, join);
+ mPen->setMiterLimit (style->miter_limit);
+
+ if (style->dash && style->num_dashes) {
+ Qt::PenStyle pstyle = Qt::NoPen;
+
+ if (style->num_dashes == 2) {
+ if ((style->dash[0] == style->line_width &&
+ style->dash[1] == style->line_width && style->line_width <= 2.0) ||
+ (style->dash[0] == 0.0 &&
+ style->dash[1] == style->line_width * 2 && cap == Qt::RoundCap))
+ {
+ pstyle = Qt::DotLine;
+ } else if (style->dash[0] == style->line_width * DASH_LENGTH &&
+ style->dash[1] == style->line_width * DASH_LENGTH &&
+ cap == Qt::FlatCap)
+ {
+ pstyle = Qt::DashLine;
+ }
+ }
+
+ if (pstyle != Qt::NoPen) {
+ mPen->setStyle(pstyle);
+ return;
+ }
+
+ unsigned int odd_dash = style->num_dashes % 2;
+
+ QVector<qreal> dashes (odd_dash ? style->num_dashes * 2 : style->num_dashes);
+ for (unsigned int i = 0; i < odd_dash+1; i++) {
+ for (unsigned int j = 0; j < style->num_dashes; j++) {
+ // In Qt, the dash lengths are given in units of line width, whereas
+ // in cairo, they are in user-space units. We'll always apply the CTM,
+ // so all we have to do here is divide cairo's dash lengths by the line
+ // width.
+ dashes.append (style->dash[j] / style->line_width);
+ }
+ }
+
+ mPen->setDashPattern (dashes);
+ mPen->setDashOffset (style->dash_offset / style->line_width);
+ }
}
~PatternToPenConverter() {
- delete mPen;
+ delete mPen;
}
operator QPen& () {
- return *mPen;
+ return *mPen;
}
QPen *mPen;
@@ -1204,14 +1204,14 @@ _cairo_qt_fast_fill (cairo_qt_surface_t *qs,
qs->p->save();
if (path) {
- qs->no_update_clip_bounds = true;
- status = _cairo_qt_surface_intersect_clip_path (qs, path, fill_rule, tolerance, antialias);
- qs->no_update_clip_bounds = false;
+ qs->no_update_clip_bounds = true;
+ status = _cairo_qt_surface_intersect_clip_path (qs, path, fill_rule, tolerance, antialias);
+ qs->no_update_clip_bounds = false;
- if (status != CAIRO_INT_STATUS_SUCCESS) {
- qs->p->restore();
- return false;
- }
+ if (status != CAIRO_INT_STATUS_SUCCESS) {
+ qs->p->restore();
+ return false;
+ }
}
qs->p->setWorldMatrix (sourceMatrix.inverted(), true);
@@ -1220,26 +1220,26 @@ _cairo_qt_fast_fill (cairo_qt_surface_t *qs,
case CAIRO_EXTEND_REPEAT:
// XXX handle reflect by tiling 4 times first
case CAIRO_EXTEND_REFLECT: {
- assert (qsSrc_pixmap);
+ assert (qsSrc_pixmap);
- // Render the tiling to cover the entire destination window (because
- // it'll be clipped). Transform the window rect by the inverse
- // of the current world transform so that the device coordinates
- // end up as the right thing.
- QRectF dest = qs->p->worldTransform().inverted().mapRect(QRectF(qs->window));
- QPointF origin = sourceMatrix.map(QPointF(0.0, 0.0));
+ // Render the tiling to cover the entire destination window (because
+ // it'll be clipped). Transform the window rect by the inverse
+ // of the current world transform so that the device coordinates
+ // end up as the right thing.
+ QRectF dest = qs->p->worldTransform().inverted().mapRect(QRectF(qs->window));
+ QPointF origin = sourceMatrix.map(QPointF(0.0, 0.0));
- qs->p->drawTiledPixmap (dest, *qsSrc_pixmap, origin);
- }
- break;
+ qs->p->drawTiledPixmap (dest, *qsSrc_pixmap, origin);
+ }
+ break;
case CAIRO_EXTEND_NONE:
case CAIRO_EXTEND_PAD: // XXX not exactly right, but good enough
default:
- if (qsSrc_image)
- qs->p->drawImage (0, 0, *qsSrc_image);
- else if (qsSrc_pixmap)
- qs->p->drawPixmap (0, 0, *qsSrc_pixmap);
- break;
+ if (qsSrc_image)
+ qs->p->drawImage (0, 0, *qsSrc_image);
+ else if (qsSrc_pixmap)
+ qs->p->drawPixmap (0, 0, *qsSrc_pixmap);
+ break;
}
qs->p->restore();
@@ -1537,16 +1537,16 @@ _cairo_qt_surface_composite (cairo_operator_t op,
QImage *qimg = NULL;
QPixmap *qpixmap = NULL;
- std::auto_ptr<QImage> qimg_d;
+ std::auto_ptr<QImage> qimg_d;
if (surface->type == CAIRO_SURFACE_TYPE_IMAGE) {
cairo_image_surface_t *isurf = (cairo_image_surface_t*) surface;
- qimg = new QImage ((const uchar *) isurf->data,
- isurf->width,
- isurf->height,
- isurf->stride,
- _qimage_format_from_cairo_format (isurf->format));
- qimg_d.reset(qimg);
+ qimg = new QImage ((const uchar *) isurf->data,
+ isurf->width,
+ isurf->height,
+ isurf->stride,
+ _qimage_format_from_cairo_format (isurf->format));
+ qimg_d.reset(qimg);
}
if (surface->type == CAIRO_SURFACE_TYPE_QT) {
@@ -1722,9 +1722,9 @@ cairo_qt_surface_create (QPainter *painter)
qs->p = painter;
if (qs->p->paintEngine())
- qs->supports_porter_duff = qs->p->paintEngine()->hasFeature(QPaintEngine::PorterDuff);
+ qs->supports_porter_duff = qs->p->paintEngine()->hasFeature(QPaintEngine::PorterDuff);
else
- qs->supports_porter_duff = FALSE;
+ qs->supports_porter_duff = FALSE;
// Save so that we can always get back to the original state
qs->p->save();
commit d782ba04b76ae18c562840242dc535e9db48aa13
Author: Tobias Hunger <tobias.hunger at gmail.com>
Date: Thu Jul 16 00:16:58 2009 -0400
[qt] Add method to flush qpainter
This is required for non-X11 rendering backends.
Mozilla bug #498910
diff --git a/src/cairo-qt-surface.cpp b/src/cairo-qt-surface.cpp
index b94f086..fdd922e 100644
--- a/src/cairo-qt-surface.cpp
+++ b/src/cairo-qt-surface.cpp
@@ -1588,6 +1588,18 @@ _cairo_qt_surface_composite (cairo_operator_t op,
return CAIRO_INT_STATUS_SUCCESS;
}
+static cairo_status_t
+_cairo_qt_surface_flush (void *abstract_surface)
+{
+ cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface;
+
+ QPaintDevice * dev = qs->p->device();
+ qs->p->end();
+ qs->p->begin(dev);
+
+ return CAIRO_STATUS_SUCCESS;
+}
+
/**
** Backend struct
**/
@@ -1614,7 +1626,7 @@ static const cairo_surface_backend_t cairo_qt_surface_backend = {
_cairo_qt_surface_get_extents,
NULL, /* old_show_glyphs */
NULL, /* get_font_options */
- NULL, /* flush */
+ _cairo_qt_surface_flush,
NULL, /* mark_dirty_rectangle */
NULL, /* scaled_font_fini */
NULL, /* scaled_glyph_fini */
commit e713857b85ef45d923eae94d8e4c05c7b2049ca5
Author: Tobias Hunger <tobias.hunger at gmail.com>
Date: Thu Jul 16 00:16:58 2009 -0400
[qt] Move _opstr() inside the #if 0 to avoid warnings
Mozilla bug #498917
diff --git a/src/cairo-qt-surface.cpp b/src/cairo-qt-surface.cpp
index bad6b29..b94f086 100644
--- a/src/cairo-qt-surface.cpp
+++ b/src/cairo-qt-surface.cpp
@@ -67,6 +67,31 @@
#if 0
#define D(x) x
+static const char *
+_opstr (cairo_operator_t op)
+{
+ const char *ops[] = {
+ "CLEAR",
+ "SOURCE",
+ "OVER",
+ "IN",
+ "OUT",
+ "ATOP",
+ "DEST",
+ "DEST_OVER",
+ "DEST_IN",
+ "DEST_OUT",
+ "DEST_ATOP",
+ "XOR",
+ "ADD",
+ "SATURATE"
+ };
+
+ if (op < CAIRO_OPERATOR_CLEAR || op > CAIRO_OPERATOR_SATURATE)
+ return "(\?\?\?)";
+
+ return ops[op];
+}
#else
#define D(x) do { } while(0)
#endif
@@ -125,31 +150,6 @@ slim_hidden_proto (cairo_xlib_surface_create_with_xrender_format);
/**
** Helper methods
**/
-static const char *
-_opstr (cairo_operator_t op)
-{
- const char *ops[] = {
- "CLEAR",
- "SOURCE",
- "OVER",
- "IN",
- "OUT",
- "ATOP",
- "DEST",
- "DEST_OVER",
- "DEST_IN",
- "DEST_OUT",
- "DEST_ATOP",
- "XOR",
- "ADD",
- "SATURATE"
- };
-
- if (op < CAIRO_OPERATOR_CLEAR || op > CAIRO_OPERATOR_SATURATE)
- return "(\?\?\?)";
-
- return ops[op];
-}
static QPainter::CompositionMode
_qpainter_compositionmode_from_cairo_op (cairo_operator_t op)
commit 4f9551e5e533deb66401b601766bf4263192b6de
Author: Tobias Hunger <tobias.hunger at gmail.com>
Date: Thu Jul 16 00:16:57 2009 -0400
[qt] Reduce padding in cairo_qt_surface_t struct
Removes 4 bytes of padding (on a 32bit system) from the datastructure by
reordering the members.
Mozilla bug #498880
diff --git a/src/cairo-qt-surface.cpp b/src/cairo-qt-surface.cpp
index 5542abd..bad6b29 100644
--- a/src/cairo-qt-surface.cpp
+++ b/src/cairo-qt-surface.cpp
@@ -82,33 +82,34 @@
typedef struct {
cairo_surface_t base;
- QPainter *p;
-
- /* The pixmap/image constructors will store their objects here */
- QPixmap *pixmap;
- QImage *image;
-
- QRect window;
-
bool has_clipping;
- QRect clip_bounds;
-
// if this is true, calls to intersect_clip_path won't
// update the clip_bounds rect
bool no_update_clip_bounds;
- cairo_surface_t *image_equiv;
+ 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 */
- cairo_surface_t *xlib_equiv;
bool xlib_has_clipping;
+ cairo_surface_t *xlib_equiv;
QRect xlib_clip_bounds;
int xlib_clip_serial;
QPoint redir_offset;
#endif
- cairo_bool_t supports_porter_duff;
+ QPainter *p;
+
+ /* The pixmap/image constructors will store their objects here */
+ QPixmap *pixmap;
+ QImage *image;
+
+ QRect window;
+
+
+ QRect clip_bounds;
+
+ cairo_surface_t *image_equiv;
} cairo_qt_surface_t;
/* Will be true if we ever try to create a QPixmap and end
More information about the cairo-commit
mailing list