From 659e6bf8ca14ab96acdb5d1b384e8e15ee7b0491 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 12 Apr 2023 13:09:25 +0200 Subject: Add timing information in debug output This can help in debugging performance issues with some shapes. Change-Id: Id94f8f3d016346b00a7c45f39f6c957607258bda Reviewed-by: Eirik Aavitsland --- src/svg/qsvggraphics.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src') diff --git a/src/svg/qsvggraphics.cpp b/src/svg/qsvggraphics.cpp index 4f735b6..facb190 100644 --- a/src/svg/qsvggraphics.cpp +++ b/src/svg/qsvggraphics.cpp @@ -13,12 +13,23 @@ #include #include +#include +#include + #include #include QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(lcSvgDraw, "qt.svg.draw") +Q_LOGGING_CATEGORY(lcSvgTiming, "qt.svg.timing") + +#define QT_SVG_TIMING_ENTER \ + QElapsedTimer qtSvgTimer; qtSvgTimer.start(); + +#define QT_SVG_TIMING_EXIT(TYPE) \ + if (Q_UNLIKELY(lcSvgTiming().isDebugEnabled())) \ + qCDebug(lcSvgTiming) << "Drawing" << TYPE << "took" << (qtSvgTimer.nsecsElapsed() / 1000000.0f) << "ms"; #define QT_SVG_DRAW_SHAPE(command) \ qreal oldOpacity = p->opacity(); \ @@ -66,9 +77,11 @@ QRectF QSvgEllipse::bounds(QPainter *p, QSvgExtraStates &) const void QSvgEllipse::draw(QPainter *p, QSvgExtraStates &states) { + QT_SVG_TIMING_ENTER applyStyle(p, states); QT_SVG_DRAW_SHAPE(p->drawEllipse(m_bounds)); revertStyle(p, states); + QT_SVG_TIMING_EXIT("Ellipse") } QSvgArc::QSvgArc(QSvgNode *parent, const QPainterPath &path) @@ -78,6 +91,7 @@ QSvgArc::QSvgArc(QSvgNode *parent, const QPainterPath &path) void QSvgArc::draw(QPainter *p, QSvgExtraStates &states) { + QT_SVG_TIMING_ENTER applyStyle(p, states); if (p->pen().widthF() != 0) { qreal oldOpacity = p->opacity(); @@ -86,6 +100,7 @@ void QSvgArc::draw(QPainter *p, QSvgExtraStates &states) p->setOpacity(oldOpacity); } revertStyle(p, states); + QT_SVG_TIMING_EXIT("Arc") } QSvgImage::QSvgImage(QSvgNode *parent, const QImage &image, @@ -101,9 +116,11 @@ QSvgImage::QSvgImage(QSvgNode *parent, const QImage &image, void QSvgImage::draw(QPainter *p, QSvgExtraStates &states) { + QT_SVG_TIMING_ENTER applyStyle(p, states); p->drawImage(m_bounds, m_image); revertStyle(p, states); + QT_SVG_TIMING_EXIT("Image") } @@ -115,6 +132,7 @@ QSvgLine::QSvgLine(QSvgNode *parent, const QLineF &line) void QSvgLine::draw(QPainter *p, QSvgExtraStates &states) { + QT_SVG_TIMING_ENTER applyStyle(p, states); if (p->pen().widthF() != 0) { qreal oldOpacity = p->opacity(); @@ -123,6 +141,7 @@ void QSvgLine::draw(QPainter *p, QSvgExtraStates &states) p->setOpacity(oldOpacity); } revertStyle(p, states); + QT_SVG_TIMING_EXIT("Line") } QSvgPath::QSvgPath(QSvgNode *parent, const QPainterPath &qpath) @@ -132,10 +151,12 @@ QSvgPath::QSvgPath(QSvgNode *parent, const QPainterPath &qpath) void QSvgPath::draw(QPainter *p, QSvgExtraStates &states) { + QT_SVG_TIMING_ENTER applyStyle(p, states); m_path.setFillRule(states.fillRule); QT_SVG_DRAW_SHAPE(p->drawPath(m_path)); revertStyle(p, states); + QT_SVG_TIMING_EXIT("Path") } QRectF QSvgPath::bounds(QPainter *p, QSvgExtraStates &) const @@ -164,9 +185,11 @@ QRectF QSvgPolygon::bounds(QPainter *p, QSvgExtraStates &) const void QSvgPolygon::draw(QPainter *p, QSvgExtraStates &states) { + QT_SVG_TIMING_ENTER applyStyle(p, states); QT_SVG_DRAW_SHAPE(p->drawPolygon(m_poly, states.fillRule)); revertStyle(p, states); + QT_SVG_TIMING_EXIT("Polygon") } @@ -178,6 +201,7 @@ QSvgPolyline::QSvgPolyline(QSvgNode *parent, const QPolygonF &poly) void QSvgPolyline::draw(QPainter *p, QSvgExtraStates &states) { + QT_SVG_TIMING_ENTER applyStyle(p, states); qreal oldOpacity = p->opacity(); if (p->brush().style() != Qt::NoBrush) { @@ -193,6 +217,7 @@ void QSvgPolyline::draw(QPainter *p, QSvgExtraStates &states) } p->setOpacity(oldOpacity); revertStyle(p, states); + QT_SVG_TIMING_EXIT("Polyline") } QSvgRect::QSvgRect(QSvgNode *node, const QRectF &rect, int rx, int ry) @@ -215,6 +240,7 @@ QRectF QSvgRect::bounds(QPainter *p, QSvgExtraStates &) const void QSvgRect::draw(QPainter *p, QSvgExtraStates &states) { + QT_SVG_TIMING_ENTER applyStyle(p, states); if (m_rx || m_ry) { QT_SVG_DRAW_SHAPE(p->drawRoundedRect(m_rect, m_rx, m_ry, Qt::RelativeSize)); @@ -222,6 +248,7 @@ void QSvgRect::draw(QPainter *p, QSvgExtraStates &states) QT_SVG_DRAW_SHAPE(p->drawRect(m_rect)); } revertStyle(p, states); + QT_SVG_TIMING_EXIT("Rect") } QSvgTspan * const QSvgText::LINEBREAK = 0; @@ -258,7 +285,9 @@ QRectF QSvgText::bounds(QPainter *p, QSvgExtraStates &states) const void QSvgText::draw(QPainter *p, QSvgExtraStates &states) { + QT_SVG_TIMING_ENTER draw_helper(p, states); + QT_SVG_TIMING_EXIT("Text") } void QSvgText::draw_helper(QPainter *p, QSvgExtraStates &states, QRectF *boundingRect) const @@ -453,6 +482,7 @@ QSvgUse::QSvgUse(const QPointF &start, QSvgNode *parent, QSvgNode *node) void QSvgUse::draw(QPainter *p, QSvgExtraStates &states) { + QT_SVG_TIMING_ENTER if (Q_UNLIKELY(!m_link || isDescendantOf(m_link) || m_recursing)) return; @@ -482,6 +512,7 @@ void QSvgUse::draw(QPainter *p, QSvgExtraStates &states) } revertStyle(p, states); + QT_SVG_TIMING_EXIT("Use") } void QSvgVideo::draw(QPainter *p, QSvgExtraStates &states) -- cgit v1.2.1