summaryrefslogtreecommitdiffstats
path: root/src/gui/painting
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2017-11-30 09:43:44 +0100
committerMarc Mutz <marc.mutz@kdab.com>2017-12-06 18:30:55 +0000
commit03026973700f1fcdff602dffa3d94b04912acd44 (patch)
treeab3c22ea63e11e01573605f9a879edeffb160930 /src/gui/painting
parent85d8975bc999d65d04db9027f66c030574a5caf0 (diff)
QtGui: port away from QRegion::rects()
Use begin()/end()/rectCount() instead, which don't require QRegionPrivate ::vectorize() calls. In QPaintEngineEx::clip(), the rectCount() == 1 case called clip(QRect), but forgot to return, causing another clip(QVectorPath) call with the same arguments. Fixed. Change-Id: Ife33112fc8006ed4bdff6409e2b8465ce7acb9d1 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/gui/painting')
-rw-r--r--src/gui/painting/qpaintengine_raster.cpp12
-rw-r--r--src/gui/painting/qpaintengineex.cpp37
-rw-r--r--src/gui/painting/qregion.cpp11
3 files changed, 30 insertions, 30 deletions
diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp
index d0d948bbb7..873303f78e 100644
--- a/src/gui/painting/qpaintengine_raster.cpp
+++ b/src/gui/painting/qpaintengine_raster.cpp
@@ -3782,8 +3782,8 @@ void QClipData::initialize()
}
} else if (hasRegionClip) {
- const QVector<QRect> rects = clipRegion.rects();
- const int numRects = rects.size();
+ const auto rects = clipRegion.begin();
+ const int numRects = clipRegion.rectCount();
{ // resize
const int maxSpans = (ymax - ymin) * numRects;
@@ -3797,8 +3797,8 @@ void QClipData::initialize()
int firstInBand = 0;
count = 0;
while (firstInBand < numRects) {
- const int currMinY = rects.at(firstInBand).y();
- const int currMaxY = currMinY + rects.at(firstInBand).height();
+ const int currMinY = rects[firstInBand].y();
+ const int currMaxY = currMinY + rects[firstInBand].height();
while (y < currMinY) {
m_clipLines[y].spans = 0;
@@ -3807,7 +3807,7 @@ void QClipData::initialize()
}
int lastInBand = firstInBand;
- while (lastInBand + 1 < numRects && rects.at(lastInBand+1).top() == y)
+ while (lastInBand + 1 < numRects && rects[lastInBand+1].top() == y)
++lastInBand;
while (y < currMaxY) {
@@ -3816,7 +3816,7 @@ void QClipData::initialize()
m_clipLines[y].count = lastInBand - firstInBand + 1;
for (int r = firstInBand; r <= lastInBand; ++r) {
- const QRect &currRect = rects.at(r);
+ const QRect &currRect = rects[r];
QSpan *span = m_spans + count;
span->x = currRect.x();
span->len = currRect.width();
diff --git a/src/gui/painting/qpaintengineex.cpp b/src/gui/painting/qpaintengineex.cpp
index 812cb8c02d..0643a7cbb6 100644
--- a/src/gui/painting/qpaintengineex.cpp
+++ b/src/gui/painting/qpaintengineex.cpp
@@ -619,18 +619,17 @@ void QPaintEngineEx::clip(const QRect &r, Qt::ClipOperation op)
void QPaintEngineEx::clip(const QRegion &region, Qt::ClipOperation op)
{
- if (region.rectCount() == 1)
- clip(region.boundingRect(), op);
-
- QVector<QRect> rects = region.rects();
- if (rects.size() <= 32) {
+ const auto rectsInRegion = region.rectCount();
+ if (rectsInRegion == 1) {
+ clip(*region.begin(), op);
+ } else if (rectsInRegion <= 32) {
qreal pts[2*32*4];
int pos = 0;
- for (QVector<QRect>::const_iterator i = rects.constBegin(); i != rects.constEnd(); ++i) {
- qreal x1 = i->x();
- qreal y1 = i->y();
- qreal x2 = i->x() + i->width();
- qreal y2 = i->y() + i->height();
+ for (QRect r : region) {
+ qreal x1 = r.x();
+ qreal y1 = r.y();
+ qreal x2 = r.x() + r.width();
+ qreal y2 = r.y() + r.height();
pts[pos++] = x1;
pts[pos++] = y1;
@@ -644,19 +643,19 @@ void QPaintEngineEx::clip(const QRegion &region, Qt::ClipOperation op)
pts[pos++] = x1;
pts[pos++] = y2;
}
- QVectorPath vp(pts, rects.size() * 4, qpaintengineex_rect4_types_32);
+ QVectorPath vp(pts, rectsInRegion * 4, qpaintengineex_rect4_types_32);
clip(vp, op);
} else {
- QVarLengthArray<qreal> pts(rects.size() * 2 * 4);
- QVarLengthArray<QPainterPath::ElementType> types(rects.size() * 4);
+ QVarLengthArray<qreal> pts(rectsInRegion * 2 * 4);
+ QVarLengthArray<QPainterPath::ElementType> types(rectsInRegion * 4);
int ppos = 0;
int tpos = 0;
- for (QVector<QRect>::const_iterator i = rects.constBegin(); i != rects.constEnd(); ++i) {
- qreal x1 = i->x();
- qreal y1 = i->y();
- qreal x2 = i->x() + i->width();
- qreal y2 = i->y() + i->height();
+ for (QRect r : region) {
+ qreal x1 = r.x();
+ qreal y1 = r.y();
+ qreal x2 = r.x() + r.width();
+ qreal y2 = r.y() + r.height();
pts[ppos++] = x1;
pts[ppos++] = y1;
@@ -676,7 +675,7 @@ void QPaintEngineEx::clip(const QRegion &region, Qt::ClipOperation op)
types[tpos++] = QPainterPath::LineToElement;
}
- QVectorPath vp(pts.data(), rects.size() * 4, types.data());
+ QVectorPath vp(pts.data(), rectsInRegion * 4, types.data());
clip(vp, op);
}
diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp
index 1b8aae16e1..dcff6a1d72 100644
--- a/src/gui/painting/qregion.cpp
+++ b/src/gui/painting/qregion.cpp
@@ -447,19 +447,20 @@ QDebug operator<<(QDebug s, const QRegion &r)
} else if (r.isEmpty()) {
s << "empty";
} else {
- const QVector<QRect> rects = r.rects();
- const int count = rects.size();
+ const int count = r.rectCount();
if (count > 1)
s << "size=" << count << ", bounds=(";
QtDebugUtils::formatQRect(s, r.boundingRect());
if (count > 1) {
s << ") - [";
- for (int i = 0; i < count; ++i) {
- if (i)
+ bool first = true;
+ for (const QRect &rect : r) {
+ if (!first)
s << ", ";
s << '(';
- QtDebugUtils::formatQRect(s, rects.at(i));
+ QtDebugUtils::formatQRect(s, rect);
s << ')';
+ first = false;
}
s << ']';
}