diff options
Diffstat (limited to 'src/gui/painting')
-rw-r--r-- | src/gui/painting/qdrawhelper.cpp | 6 | ||||
-rw-r--r-- | src/gui/painting/qpaintengine_blitter.cpp | 18 | ||||
-rw-r--r-- | src/gui/painting/qpaintengine_raster.cpp | 2 | ||||
-rw-r--r-- | src/gui/painting/qpainter.cpp | 10 | ||||
-rw-r--r-- | src/gui/painting/qpainterpath.cpp | 7 | ||||
-rw-r--r-- | src/gui/painting/qpdf.cpp | 5 | ||||
-rw-r--r-- | src/gui/painting/qplatformbackingstore.cpp | 5 | ||||
-rw-r--r-- | src/gui/painting/qregion.cpp | 156 | ||||
-rw-r--r-- | src/gui/painting/qregion.h | 12 | ||||
-rw-r--r-- | src/gui/painting/qtextureglyphcache.cpp | 2 | ||||
-rw-r--r-- | src/gui/painting/qtextureglyphcache_p.h | 2 |
11 files changed, 172 insertions, 53 deletions
diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index a325ee923e..29c3ba3480 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -4032,7 +4032,7 @@ template<typename T> struct QBlendBase { typedef T BlendType; - QBlendBase(QSpanData *d, Operator o) + QBlendBase(QSpanData *d, const Operator &o) : data(d) , op(o) , dest(0) @@ -4051,7 +4051,7 @@ struct QBlendBase class BlendSrcGeneric : public QBlendBase<uint> { public: - BlendSrcGeneric(QSpanData *d, Operator o) + BlendSrcGeneric(QSpanData *d, const Operator &o) : QBlendBase<uint>(d, o) { } @@ -4077,7 +4077,7 @@ public: class BlendSrcGenericRGB64 : public QBlendBase<QRgba64> { public: - BlendSrcGenericRGB64(QSpanData *d, Operator o) + BlendSrcGenericRGB64(QSpanData *d, const Operator &o) : QBlendBase<QRgba64>(d, o) { } diff --git a/src/gui/painting/qpaintengine_blitter.cpp b/src/gui/painting/qpaintengine_blitter.cpp index 81191d07b8..a50d1dfd73 100644 --- a/src/gui/painting/qpaintengine_blitter.cpp +++ b/src/gui/painting/qpaintengine_blitter.cpp @@ -312,7 +312,7 @@ void QBlitterPaintEnginePrivate::updateBrushState(QPainterState *s) { Qt::BrushStyle style = qbrush_style(s->brush); - caps.updateState(STATE_BRUSH_PATTERN, style > Qt::SolidPattern); + caps.updateState(STATE_BRUSH_PATTERN, style != Qt::SolidPattern); caps.updateState(STATE_BRUSH_ALPHA, qbrush_color(s->brush).alpha() < 255); } @@ -374,9 +374,8 @@ void QBlitterPaintEnginePrivate::fillRect(const QRectF &rect, const QColor &colo else pmData->blittable()->fillRect(targetRect & clipData->clipRect, color); } else if (clipData->hasRegionClip) { - QVector<QRect> rects = clipData->clipRegion.rects(); - for (int i = 0; i < rects.size(); ++i) { - QRect intersectRect = rects.at(i).intersected(targetRect.toRect()); + for (const QRect &rect : clipData->clipRegion) { + QRect intersectRect = rect.intersected(targetRect.toRect()); if (!intersectRect.isEmpty()) { unlock(); if (alpha) @@ -609,10 +608,8 @@ void QBlitterPaintEngine::fillRect(const QRectF &rect, const QBrush &brush) } } else if (clipData->hasRegionClip) { QRect unclippedTargetRect(x, y, blitWidth, blitHeight); - const QVector<QRect> intersectedRects = clipData->clipRegion.intersected(unclippedTargetRect).rects(); - const int intersectedSize = intersectedRects.size(); - for (int i = 0; i < intersectedSize; ++i) { - const QRect &targetRect = intersectedRects.at(i); + const QRegion targetRegion = clipData->clipRegion.intersected(unclippedTargetRect); + for (const QRect &targetRect : targetRegion) { if (!targetRect.isValid() || targetRect.isEmpty()) continue; int tmpSrcX = srcX + (targetRect.x() - x); @@ -686,9 +683,8 @@ void QBlitterPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const Q if (clipData->hasRectClip) { d->clipAndDrawPixmap(clipData->clipRect, targetRect, pm, sr, canDrawOpacity); } else if (clipData->hasRegionClip) { - QVector<QRect>rects = clipData->clipRegion.rects(); - for (int i = 0; i<rects.size(); ++i) - d->clipAndDrawPixmap(rects.at(i), targetRect, pm, sr, canDrawOpacity); + for (const QRect &rect : clipData->clipRegion) + d->clipAndDrawPixmap(rect, targetRect, pm, sr, canDrawOpacity); } } else { QRectF deviceRect(0, 0, paintDevice()->width(), paintDevice()->height()); diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 4ab029cf7a..00dc4ccb81 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -3893,7 +3893,7 @@ void QClipData::setClipRect(const QRect &rect) void QClipData::setClipRegion(const QRegion ®ion) { if (region.rectCount() == 1) { - setClipRect(region.rects().at(0)); + setClipRect(*region.begin()); return; } diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index bcef14ca61..e70079915a 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -2835,7 +2835,7 @@ void QPainter::setClipRegion(const QRegion &r, Qt::ClipOperation op) QRect rect = r.boundingRect(); if (qt_show_painter_debug_output) printf("QPainter::setClipRegion(), size=%d, [%d,%d,%d,%d]\n", - r.rects().size(), rect.x(), rect.y(), rect.width(), rect.height()); + r.rectCount(), rect.x(), rect.y(), rect.width(), rect.height()); #endif if (!d->engine) { qWarning("QPainter::setClipRegion: Painter not active"); @@ -6473,6 +6473,8 @@ void QPainterPrivate::drawTextItem(const QPointF &p, const QTextItem &_ti, QText extended->drawTextItem(QPointF(x, y), ti2); else engine->drawTextItem(QPointF(x, y), ti2); + drawTextItemDecoration(q, p, ti2.fontEngine, textEngine, ti2.underlineStyle, + ti2.flags, ti2.width.toReal(), ti2.charFormat); if (!rtl) x += ti2.width.toReal(); @@ -6504,6 +6506,8 @@ void QPainterPrivate::drawTextItem(const QPointF &p, const QTextItem &_ti, QText extended->drawTextItem(QPointF(x, y), ti2); else engine->drawTextItem(QPointF(x,y), ti2); + drawTextItemDecoration(q, p, ti2.fontEngine, textEngine, ti2.underlineStyle, + ti2.flags, ti2.width.toReal(), ti2.charFormat); // reset the high byte for all glyphs const int hi = which << 24; @@ -6515,9 +6519,9 @@ void QPainterPrivate::drawTextItem(const QPointF &p, const QTextItem &_ti, QText extended->drawTextItem(p, ti); else engine->drawTextItem(p, ti); + drawTextItemDecoration(q, p, ti.fontEngine, textEngine, ti.underlineStyle, + ti.flags, ti.width.toReal(), ti.charFormat); } - drawTextItemDecoration(q, p, ti.fontEngine, textEngine, ti.underlineStyle, - ti.flags, ti.width.toReal(), ti.charFormat); if (state->renderHints != oldRenderHints) { state->renderHints = oldRenderHints; diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp index ba14a45d4a..7072a2d79c 100644 --- a/src/gui/painting/qpainterpath.cpp +++ b/src/gui/painting/qpainterpath.cpp @@ -1294,10 +1294,9 @@ void QPainterPath::addRegion(const QRegion ®ion) ensureData(); detach(); - QVector<QRect> rects = region.rects(); - d_func()->elements.reserve(rects.size() * 5); - for (int i=0; i<rects.size(); ++i) - addRect(rects.at(i)); + d_func()->elements.reserve(region.rectCount() * 5); + for (const QRect &rect : region) + addRect(rect); } diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index f83f1c997e..86f176bc99 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -1078,9 +1078,8 @@ void QPdfEngine::updateState(const QPaintEngineState &state) } else if (flags & DirtyClipRegion) { d->clipEnabled = true; QPainterPath path; - QVector<QRect> rects = state.clipRegion().rects(); - for (int i = 0; i < rects.size(); ++i) - path.addRect(rects.at(i)); + for (const QRect &rect : state.clipRegion()) + path.addRect(rect); updateClipPath(path, state.clipOperation()); flags |= DirtyClipPath; } else if (flags & DirtyClipEnabled) { diff --git a/src/gui/painting/qplatformbackingstore.cpp b/src/gui/painting/qplatformbackingstore.cpp index 6cec4a0a8d..61975ee045 100644 --- a/src/gui/painting/qplatformbackingstore.cpp +++ b/src/gui/painting/qplatformbackingstore.cpp @@ -250,9 +250,8 @@ static QRegion deviceRegion(const QRegion ®ion, QWindow *window, const QPoint return region; QVector<QRect> rects; - const QVector<QRect> regionRects = region.rects(); - rects.reserve(regionRects.count()); - for (const QRect &rect : regionRects) + rects.reserve(region.rectCount()); + for (const QRect &rect : region) rects.append(deviceRect(rect.translated(offset), window)); QRegion deviceRegion; diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp index 35c4abb3ac..b70257a00f 100644 --- a/src/gui/painting/qregion.cpp +++ b/src/gui/painting/qregion.cpp @@ -81,8 +81,8 @@ QT_BEGIN_NAMESPACE contains() a QPoint or QRect. The bounding rectangle can be found with boundingRect(). - The function rects() gives a decomposition of the region into - rectangles. + Iteration over the region (with begin(), end()) gives a decomposition of + the region into rectangles. The same sequence of rectangles is returned by rects(). Example of using complex regions: \snippet code/src_gui_painting_qregion.cpp 0 @@ -395,23 +395,24 @@ void QRegion::exec(const QByteArray &buffer, int ver, QDataStream::ByteOrder byt QDataStream &operator<<(QDataStream &s, const QRegion &r) { - QVector<QRect> a = r.rects(); - if (a.isEmpty()) { + auto b = r.begin(), e = r.end(); + if (b == e) { s << (quint32)0; } else { + const auto size = e - b; if (s.version() == 1) { - int i; - for (i = a.size() - 1; i > 0; --i) { + for (auto i = size - 1; i > 0; --i) { s << (quint32)(12 + i * 24); s << (int)QRGN_OR; } - for (i = 0; i < a.size(); ++i) { - s << (quint32)(4+8) << (int)QRGN_SETRECT << a[i]; - } + for (auto it = b; it != e; ++it) + s << (quint32)(4+8) << (int)QRGN_SETRECT << *it; } else { - s << (quint32)(4 + 4 + 16 * a.size()); // 16: storage size of QRect + s << quint32(4 + 4 + 16 * size); // 16: storage size of QRect s << (qint32)QRGN_RECTS; - s << a; + s << quint32(size); + for (auto it = b; it != e; ++it) + s << *it; } } return s; @@ -722,12 +723,9 @@ bool QRegion::intersects(const QRegion ®ion) const if (rectCount() == 1 && region.rectCount() == 1) return true; - const QVector<QRect> myRects = rects(); - const QVector<QRect> otherRects = region.rects(); - - for (QVector<QRect>::const_iterator i1 = myRects.constBegin(); i1 < myRects.constEnd(); ++i1) - for (QVector<QRect>::const_iterator i2 = otherRects.constBegin(); i2 < otherRects.constEnd(); ++i2) - if (rect_intersects(*i1, *i2)) + for (const QRect &myRect : *this) + for (const QRect &otherRect : region) + if (rect_intersects(myRect, otherRect)) return true; return false; } @@ -928,6 +926,100 @@ QRegion QRegion::intersect(const QRect &r) const */ /*! + \typedef QRegion::const_iterator + \since 5.8 + + An iterator over the QRects that make up the region. + + QRegion does not offer mutable iterators. + + \sa begin(), end() +*/ + +/*! + \typedef QRegion::const_reverse_iterator + \since 5.8 + + A reverse iterator over the QRects that make up the region. + + QRegion does not offer mutable iterators. + + \sa rbegin(), rend() +*/ + +/*! + \fn QRegion::begin() const + \since 5.8 + + Returns a const_iterator pointing to the beginning of the range of + rectangles that make up this range, in the order in which rects() + returns them. + + \sa rbegin(), cbegin(), end() +*/ + +/*! + \fn QRegion::cbegin() const + \since 5.8 + + Same as begin(). +*/ + +/*! + \fn QRegion::end() const + \since 5.8 + + Returns a const_iterator pointing to one past the end of the range of + rectangles that make up this range, in the order in which rects() + returns them. + + \sa rend(), cend(), begin() +*/ + +/*! + \fn QRegion::cend() const + \since 5.8 + + Same as end(). +*/ + +/*! + \fn QRegion::rbegin() const + \since 5.8 + + Returns a const_reverse_iterator pointing to the beginning of the range of + rectangles that make up this range, in the reverse order in which rects() + returns them. + + \sa begin(), crbegin(), rend() +*/ + +/*! + \fn QRegion::crbegin() const + \since 5.8 + + Same as rbegin(). +*/ + +/*! + \fn QRegion::rend() const + \since 5.8 + + Returns a const_reverse_iterator pointing to one past the end of the range of + rectangles that make up this range, in the reverse order in which rects() + returns them. + + \sa end(), crend(), rbegin() +*/ + +/*! + \fn QRegion::crend() const + \since 5.8 + + Same as rend(). +*/ + +/*! \fn void QRegion::setRects(const QRect *rects, int number) Sets the region using the array of rectangles specified by \a rects and @@ -1057,13 +1149,11 @@ Q_GUI_EXPORT QPainterPath qt_regionToPath(const QRegion ®ion) return result; } - const QVector<QRect> rects = region.rects(); + auto rect = region.begin(); + const auto end = region.end(); QVarLengthArray<Segment> segments; - segments.resize(4 * rects.size()); - - const QRect *rect = rects.constData(); - const QRect *end = rect + rects.size(); + segments.resize(4 * (end - rect)); int lastRowSegmentCount = 0; Segment *lastRowSegments = 0; @@ -1171,6 +1261,12 @@ struct QRegionPrivate { } } + const QRect *begin() const Q_DECL_NOTHROW + { return numRects == 1 ? &extents : rects.data(); } // avoid vectorize() + + const QRect *end() const Q_DECL_NOTHROW + { return begin() + numRects; } + inline void append(const QRect *r); void append(const QRegionPrivate *r); void prepend(const QRect *r); @@ -4248,6 +4344,16 @@ QVector<QRect> QRegion::rects() const } } +QRegion::const_iterator QRegion::begin() const Q_DECL_NOTHROW +{ + return d->qt_rgn ? d->qt_rgn->begin() : nullptr; +} + +QRegion::const_iterator QRegion::end() const Q_DECL_NOTHROW +{ + return d->qt_rgn ? d->qt_rgn->end() : nullptr; +} + void QRegion::setRects(const QRect *rects, int num) { *this = QRegion(); @@ -4310,10 +4416,10 @@ bool QRegion::intersects(const QRect &rect) const if (d->qt_rgn->numRects == 1) return true; - const QVector<QRect> myRects = rects(); - for (QVector<QRect>::const_iterator it = myRects.constBegin(); it < myRects.constEnd(); ++it) - if (rect_intersects(r, *it)) + for (const QRect &rect : *this) { + if (rect_intersects(r, rect)) return true; + } return false; } diff --git a/src/gui/painting/qregion.h b/src/gui/painting/qregion.h index d66f80fcde..f00b1fd284 100644 --- a/src/gui/painting/qregion.h +++ b/src/gui/painting/qregion.h @@ -81,6 +81,18 @@ public: bool isEmpty() const; bool isNull() const; + typedef const QRect *const_iterator; + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + + const_iterator begin() const Q_DECL_NOTHROW; + const_iterator cbegin() const Q_DECL_NOTHROW { return begin(); } + const_iterator end() const Q_DECL_NOTHROW; + const_iterator cend() const Q_DECL_NOTHROW { return end(); } + const_reverse_iterator rbegin() const Q_DECL_NOTHROW { return const_reverse_iterator(end()); } + const_reverse_iterator crbegin() const Q_DECL_NOTHROW { return rbegin(); } + const_reverse_iterator rend() const Q_DECL_NOTHROW { return const_reverse_iterator(begin()); } + const_reverse_iterator crend() const Q_DECL_NOTHROW { return rend(); } + bool contains(const QPoint &p) const; bool contains(const QRect &r) const; diff --git a/src/gui/painting/qtextureglyphcache.cpp b/src/gui/painting/qtextureglyphcache.cpp index d2c3eceeef..bfc8551a9b 100644 --- a/src/gui/painting/qtextureglyphcache.cpp +++ b/src/gui/painting/qtextureglyphcache.cpp @@ -247,6 +247,7 @@ void QTextureGlyphCache::fillInPendingGlyphs() resizeCache(qNextPowerOfTwo(requiredWidth - 1), qNextPowerOfTwo(requiredHeight - 1)); } + beginFillTexture(); { QHash<GlyphAndSubPixelPosition, Coord>::iterator iter = m_pendingGlyphs.begin(); while (iter != m_pendingGlyphs.end()) { @@ -256,6 +257,7 @@ void QTextureGlyphCache::fillInPendingGlyphs() ++iter; } } + endFillTexture(); m_pendingGlyphs.clear(); } diff --git a/src/gui/painting/qtextureglyphcache_p.h b/src/gui/painting/qtextureglyphcache_p.h index 14271ccc65..a8efb4abb1 100644 --- a/src/gui/painting/qtextureglyphcache_p.h +++ b/src/gui/painting/qtextureglyphcache_p.h @@ -117,7 +117,9 @@ public: virtual void resizeTextureData(int width, int height) = 0; virtual int glyphPadding() const { return 0; } + virtual void beginFillTexture() { } virtual void fillTexture(const Coord &coord, glyph_t glyph, QFixed subPixelPosition) = 0; + virtual void endFillTexture() { } inline void createCache(int width, int height) { m_w = width; |