QtOpenGL/plugins/platformsupport: use new QRegion::begin()/end() instead of rect()
Saves e.g. ~900b and ~2900b in text size in QtOpenGL and XcbQpa libs, resp., on optimized GCC 5.3 Linux AMD64 builds. Change-Id: Id904689164ca32df41118a23747c70048d8e6604 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
parent
9d3a415562
commit
9c1d3bc253
@ -1006,11 +1006,11 @@ void QGL2PaintEngineExPrivate::fillStencilWithVertexArray(const float *data,
|
||||
glStencilMask(0xff); // Enable stencil writes
|
||||
|
||||
if (dirtyStencilRegion.intersects(currentScissorBounds)) {
|
||||
QVector<QRect> clearRegion = dirtyStencilRegion.intersected(currentScissorBounds).rects();
|
||||
const QRegion clearRegion = dirtyStencilRegion.intersected(currentScissorBounds);
|
||||
glClearStencil(0); // Clear to zero
|
||||
for (int i = 0; i < clearRegion.size(); ++i) {
|
||||
for (const QRect &rect : clearRegion) {
|
||||
#ifndef QT_GL_NO_SCISSOR_TEST
|
||||
setScissor(clearRegion.at(i));
|
||||
setScissor(rect);
|
||||
#endif
|
||||
glClear(GL_STENCIL_BUFFER_BIT);
|
||||
}
|
||||
|
@ -206,15 +206,13 @@ void QFbScreen::generateRects()
|
||||
remainingScreen -= localGeometry;
|
||||
QRegion windowRegion(localGeometry);
|
||||
windowRegion -= remainingScreen;
|
||||
foreach (const QRect &rect, windowRegion.rects()) {
|
||||
for (const QRect &rect : windowRegion)
|
||||
mCachedRects += QPair<QRect, int>(rect, i);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
const QVector<QRect> remainingScreenRects = remainingScreen.rects();
|
||||
mCachedRects.reserve(mCachedRects.count() + remainingScreenRects.count());
|
||||
foreach (const QRect &rect, remainingScreenRects)
|
||||
mCachedRects.reserve(mCachedRects.count() + remainingScreen.rectCount());
|
||||
for (const QRect &rect : remainingScreen)
|
||||
mCachedRects += QPair<QRect, int>(rect, -1);
|
||||
mIsUpToDate = true;
|
||||
}
|
||||
@ -253,7 +251,7 @@ QRegion QFbScreen::doRedraw()
|
||||
rectRegion -= intersect;
|
||||
|
||||
// we only expect one rectangle, but defensive coding...
|
||||
foreach (const QRect &rect, intersect.rects()) {
|
||||
for (const QRect &rect : intersect) {
|
||||
bool firstLayer = true;
|
||||
if (layer == -1) {
|
||||
mCompositePainter->fillRect(rect, Qt::black);
|
||||
|
@ -89,7 +89,7 @@ bool QRasterBackingStore::scroll(const QRegion ®ion, int dx, int dy)
|
||||
const qreal devicePixelRatio = m_image.devicePixelRatio();
|
||||
const QPoint delta(dx * devicePixelRatio, dy * devicePixelRatio);
|
||||
|
||||
foreach (const QRect &rect, region.rects())
|
||||
for (const QRect &rect : region)
|
||||
qt_scrollRectInImage(m_image, QRect(rect.topLeft() * devicePixelRatio, rect.size() * devicePixelRatio), delta);
|
||||
|
||||
return true;
|
||||
@ -103,7 +103,7 @@ void QRasterBackingStore::beginPaint(const QRegion ®ion)
|
||||
QPainter painter(&m_image);
|
||||
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
const QColor blank = Qt::transparent;
|
||||
foreach (const QRect &rect, region.rects())
|
||||
for (const QRect &rect : region)
|
||||
painter.fillRect(rect, blank);
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ void QOpenGLCompositorBackingStore::updateTexture()
|
||||
|
||||
QOpenGLContext *ctx = QOpenGLContext::currentContext();
|
||||
if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) {
|
||||
foreach (const QRect &rect, m_dirty.rects()) {
|
||||
for (const QRect &rect : m_dirty) {
|
||||
QRect r = imageRect & rect;
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_image.width());
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, r.x(), r.y(), r.width(), r.height(), GL_RGBA, GL_UNSIGNED_BYTE,
|
||||
@ -148,7 +148,7 @@ void QOpenGLCompositorBackingStore::updateTexture()
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
}
|
||||
} else {
|
||||
foreach (const QRect &rect, m_dirty.rects()) {
|
||||
for (const QRect &rect : m_dirty) {
|
||||
// intersect with image rect to be sure
|
||||
QRect r = imageRect & rect;
|
||||
|
||||
@ -161,7 +161,7 @@ void QOpenGLCompositorBackingStore::updateTexture()
|
||||
|
||||
fixed |= r;
|
||||
}
|
||||
foreach (const QRect &rect, fixed.rects()) {
|
||||
for (const QRect &rect : fixed) {
|
||||
// if the sub-rect is full-width we can pass the image data directly to
|
||||
// OpenGL instead of copying, since there's no gap between scanlines
|
||||
if (rect.width() == imageRect.width()) {
|
||||
@ -258,7 +258,7 @@ void QOpenGLCompositorBackingStore::beginPaint(const QRegion ®ion)
|
||||
if (m_image.hasAlphaChannel()) {
|
||||
QPainter p(&m_image);
|
||||
p.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
foreach (const QRect &r, region.rects())
|
||||
for (const QRect &r : region)
|
||||
p.fillRect(r, Qt::transparent);
|
||||
}
|
||||
}
|
||||
|
@ -379,9 +379,8 @@ void QAndroidPlatformScreen::doRedraw()
|
||||
}
|
||||
}
|
||||
|
||||
foreach (const QRect &rect, visibleRegion.rects()) {
|
||||
for (const QRect &rect : visibleRegion)
|
||||
compositePainter.fillRect(rect, QColor(Qt::transparent));
|
||||
}
|
||||
|
||||
ret = ANativeWindow_unlockAndPost(m_nativeSurface);
|
||||
if (ret >= 0)
|
||||
|
@ -96,9 +96,8 @@ bool QCocoaBackingStore::scroll(const QRegion &area, int dx, int dy)
|
||||
extern void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset);
|
||||
const qreal devicePixelRatio = m_qImage.devicePixelRatio();
|
||||
QPoint qpoint(dx * devicePixelRatio, dy * devicePixelRatio);
|
||||
const QVector<QRect> qrects = area.rects();
|
||||
for (int i = 0; i < qrects.count(); ++i) {
|
||||
const QRect &qrect = QRect(qrects.at(i).topLeft() * devicePixelRatio, qrects.at(i).size() * devicePixelRatio);
|
||||
for (const QRect &rect : area) {
|
||||
const QRect qrect(rect.topLeft() * devicePixelRatio, rect.size() * devicePixelRatio);
|
||||
qt_scrollRectInImage(m_qImage, qrect, qpoint);
|
||||
}
|
||||
return true;
|
||||
@ -109,10 +108,9 @@ void QCocoaBackingStore::beginPaint(const QRegion ®ion)
|
||||
if (m_qImage.hasAlphaChannel()) {
|
||||
QPainter p(&m_qImage);
|
||||
p.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
const QVector<QRect> rects = region.rects();
|
||||
const QColor blank = Qt::transparent;
|
||||
for (QVector<QRect>::const_iterator it = rects.begin(), end = rects.end(); it != end; ++it)
|
||||
p.fillRect(*it, blank);
|
||||
for (const QRect &rect : region)
|
||||
p.fillRect(rect, blank);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,15 +200,9 @@ NSImage *qt_mac_create_nsimage(const QIcon &icon)
|
||||
HIMutableShapeRef qt_mac_QRegionToHIMutableShape(const QRegion ®ion)
|
||||
{
|
||||
HIMutableShapeRef shape = HIShapeCreateMutable();
|
||||
QVector<QRect> rects = region.rects();
|
||||
if (!rects.isEmpty()) {
|
||||
int n = rects.count();
|
||||
const QRect *qt_r = rects.constData();
|
||||
while (n--) {
|
||||
CGRect cgRect = CGRectMake(qt_r->x(), qt_r->y(), qt_r->width(), qt_r->height());
|
||||
HIShapeUnionWithRect(shape, &cgRect);
|
||||
++qt_r;
|
||||
}
|
||||
for (const QRect &rect : region) {
|
||||
CGRect cgRect = CGRectMake(rect.x(), rect.y(), rect.width(), rect.height());
|
||||
HIShapeUnionWithRect(shape, &cgRect);
|
||||
}
|
||||
return shape;
|
||||
}
|
||||
|
@ -514,7 +514,7 @@ QT_WARNING_POP
|
||||
{
|
||||
m_backingStore = backingStore;
|
||||
m_backingStoreOffset = offset * m_backingStore->getBackingStoreDevicePixelRatio();
|
||||
foreach (QRect rect, region.rects())
|
||||
for (const QRect &rect : region)
|
||||
[self setNeedsDisplayInRect:NSMakeRect(rect.x(), rect.y(), rect.width(), rect.height())];
|
||||
}
|
||||
|
||||
|
@ -88,10 +88,7 @@ static void qt_mac_clip_cg(CGContextRef hd, const QRegion &rgn, CGAffineTransfor
|
||||
if (rgn.isEmpty()) {
|
||||
CGContextAddRect(hd, CGRectMake(0, 0, 0, 0));
|
||||
} else {
|
||||
QVector<QRect> rects = rgn.rects();
|
||||
const int count = rects.size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
const QRect &r = rects[i];
|
||||
for (const QRect &r : rgn) {
|
||||
CGRect mac_r = CGRectMake(r.x(), r.y(), r.width(), r.height());
|
||||
CGContextAddRect(hd, mac_r);
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ void QWindowsDirect2DBackingStore::beginPaint(const QRegion ®ion)
|
||||
|
||||
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
|
||||
foreach (const QRect &r, region.rects())
|
||||
for (const QRect &r, region)
|
||||
painter.fillRect(r, clear);
|
||||
}
|
||||
|
||||
@ -127,9 +127,8 @@ void QWindowsDirect2DBackingStore::resize(const QSize &size, const QRegion ®i
|
||||
QPixmap *newPixmap = nativeWindow(window())->pixmap();
|
||||
|
||||
if (!old.isNull()) {
|
||||
foreach (const QRect &rect, region.rects()) {
|
||||
for (const QRect &rect : region)
|
||||
platformPixmap(newPixmap)->copy(old.handle(), rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ void QWindowsDirect2DWindow::flush(QWindowsDirect2DBitmap *bitmap, const QRegion
|
||||
QRegion clipped = region;
|
||||
clipped &= QRect(QPoint(), size);
|
||||
|
||||
foreach (const QRect &rect, clipped.rects()) {
|
||||
for (const QRect &rect : clipped) {
|
||||
QRectF rectF(rect);
|
||||
dc->DrawBitmap(bitmap->bitmap(),
|
||||
to_d2d_rect_f(rectF),
|
||||
|
@ -70,9 +70,7 @@ void QDirectFbBackingStore::flush(QWindow *, const QRegion ®ion, const QPoint
|
||||
{
|
||||
m_pmdata->blittable()->unlock();
|
||||
|
||||
QVector<QRect> rects = region.rects();
|
||||
for (int i = 0 ; i < rects.size(); i++) {
|
||||
const QRect rect = rects.at(i);
|
||||
for (const QRect &rect : region) {
|
||||
DFBRegion dfbReg = { rect.x() + offset.x(),rect.y() + offset.y(),rect.right() + offset.x(),rect.bottom() + offset.y()};
|
||||
m_dfbSurface->Flip(m_dfbSurface.data(), &dfbReg, DFBSurfaceFlipFlags(DSFLIP_BLIT|DSFLIP_ONSYNC));
|
||||
}
|
||||
@ -108,11 +106,8 @@ bool QDirectFbBackingStore::scroll(const QRegion &area, int dx, int dy)
|
||||
if (area.rectCount() == 1) {
|
||||
scrollSurface(m_dfbSurface.data(), area.boundingRect(), dx, dy);
|
||||
} else {
|
||||
const QVector<QRect> rects = area.rects();
|
||||
const int n = rects.size();
|
||||
for (int i=0; i<n; ++i) {
|
||||
scrollSurface(m_dfbSurface.data(), rects.at(i), dx, dy);
|
||||
}
|
||||
for (const QRect &rect : area)
|
||||
scrollSurface(m_dfbSurface.data(), rect, dx, dy);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -414,9 +414,8 @@ QRegion QLinuxFbScreen::doRedraw()
|
||||
if (!mBlitter)
|
||||
mBlitter = new QPainter(&mFbScreenImage);
|
||||
|
||||
QVector<QRect> rects = touched.rects();
|
||||
for (int i = 0; i < rects.size(); i++)
|
||||
mBlitter->drawImage(rects[i], *mScreenImage, rects[i]);
|
||||
for (const QRect &rect : touched)
|
||||
mBlitter->drawImage(rect, *mScreenImage, rect);
|
||||
return touched;
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ void QMirClientBackingStore::updateTexture()
|
||||
QRegion fixed;
|
||||
QRect imageRect = mImage.rect();
|
||||
|
||||
Q_FOREACH (const QRect &rect, mDirty.rects()) {
|
||||
for (const QRect &rect : mDirty) {
|
||||
// intersect with image rect to be sure
|
||||
QRect r = imageRect & rect;
|
||||
|
||||
@ -110,7 +110,7 @@ void QMirClientBackingStore::updateTexture()
|
||||
fixed |= r;
|
||||
}
|
||||
|
||||
Q_FOREACH (const QRect &rect, fixed.rects()) {
|
||||
for (const QRect &rect : fixed) {
|
||||
// if the sub-rect is full-width we can pass the image data directly to
|
||||
// OpenGL instead of copying, since there is no gap between scanlines
|
||||
if (rect.width() == imageRect.width()) {
|
||||
|
@ -179,9 +179,8 @@ bool QOffscreenBackingStore::scroll(const QRegion &area, int dx, int dy)
|
||||
if (m_image.isNull())
|
||||
return false;
|
||||
|
||||
const QVector<QRect> rects = area.rects();
|
||||
for (int i = 0; i < rects.size(); ++i)
|
||||
qt_scrollRectInImage(m_image, rects.at(i), QPoint(dx, dy));
|
||||
for (const QRect &rect : area)
|
||||
qt_scrollRectInImage(m_image, rect, QPoint(dx, dy));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ void QQnxRasterBackingStore::beginPaint(const QRegion ®ion)
|
||||
platformWindow()->adjustBufferSize();
|
||||
|
||||
if (window()->requestedFormat().alphaBufferSize() > 0) {
|
||||
foreach (const QRect &r, region.rects()) {
|
||||
for (const QRect &r : region) {
|
||||
// Clear transparent regions
|
||||
const int bg[] = {
|
||||
SCREEN_BLIT_COLOR, 0x00000000,
|
||||
|
@ -208,10 +208,9 @@ void QQnxRasterWindow::blitPreviousToCurrent(const QRegion ®ion, int dx, int
|
||||
QQnxBuffer &previousBuffer = m_buffers[m_previousBufferIndex];
|
||||
|
||||
// Break down region into non-overlapping rectangles
|
||||
const QVector<QRect> rects = region.rects();
|
||||
for (int i = rects.size() - 1; i >= 0; i--) {
|
||||
for (auto rit = region.rbegin(), rend = region.rend(); rit != rend; ++rit) {
|
||||
// Clip rectangle to bounds of target
|
||||
const QRect rect = rects[i].intersected(currentBuffer.rect());
|
||||
const QRect rect = rit->intersected(currentBuffer.rect());
|
||||
|
||||
if (rect.isEmpty())
|
||||
continue;
|
||||
|
@ -175,7 +175,7 @@ void QWindowsBackingStore::resize(const QSize &size, const QRegion ®ion)
|
||||
staticRegion &= QRect(0, 0, newimg.width(), newimg.height());
|
||||
QPainter painter(&newimg);
|
||||
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
foreach (const QRect &rect, staticRegion.rects())
|
||||
for (const QRect &rect : staticRegion)
|
||||
painter.drawImage(rect, oldimg, rect);
|
||||
}
|
||||
|
||||
@ -190,10 +190,9 @@ bool QWindowsBackingStore::scroll(const QRegion &area, int dx, int dy)
|
||||
if (m_image.isNull() || m_image->image().isNull())
|
||||
return false;
|
||||
|
||||
const QVector<QRect> rects = area.rects();
|
||||
const QPoint offset(dx, dy);
|
||||
for (int i = 0; i < rects.size(); ++i)
|
||||
qt_scrollRectInImage(m_image->image(), rects.at(i), offset);
|
||||
for (const QRect &rect : area)
|
||||
qt_scrollRectInImage(m_image->image(), rect, offset);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -207,7 +206,7 @@ void QWindowsBackingStore::beginPaint(const QRegion ®ion)
|
||||
QPainter p(&m_image->image());
|
||||
p.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
const QColor blank = Qt::transparent;
|
||||
foreach (const QRect &r, region.rects())
|
||||
for (const QRect &r : region)
|
||||
p.fillRect(r, blank);
|
||||
}
|
||||
}
|
||||
|
@ -2047,15 +2047,13 @@ static inline void addRectToWinRegion(const QRect &rect, HRGN *winRegion)
|
||||
|
||||
static HRGN qRegionToWinRegion(const QRegion ®ion)
|
||||
{
|
||||
const QVector<QRect> rects = region.rects();
|
||||
if (rects.isEmpty())
|
||||
return NULL;
|
||||
const int rectCount = rects.size();
|
||||
if (rectCount == 1)
|
||||
return createRectRegion(region.boundingRect());
|
||||
HRGN hRegion = createRectRegion(rects.front());
|
||||
for (int i = 1; i < rectCount; ++i)
|
||||
addRectToWinRegion(rects.at(i), &hRegion);
|
||||
auto it = region.begin();
|
||||
const auto end = region.end();
|
||||
if (it == end)
|
||||
return nullptr;
|
||||
HRGN hRegion = createRectRegion(*it);
|
||||
while (++it != end)
|
||||
addRectToWinRegion(*it, &hRegion);
|
||||
return hRegion;
|
||||
}
|
||||
|
||||
|
@ -335,11 +335,9 @@ void QXcbBackingStore::beginPaint(const QRegion ®ion)
|
||||
if (m_image->hasAlpha()) {
|
||||
QPainter p(paintDevice());
|
||||
p.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
const QVector<QRect> rects = m_paintRegion.rects();
|
||||
const QColor blank = Qt::transparent;
|
||||
for (QVector<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it) {
|
||||
p.fillRect(*it, blank);
|
||||
}
|
||||
for (const QRect &rect : m_paintRegion)
|
||||
p.fillRect(rect, blank);
|
||||
}
|
||||
}
|
||||
|
||||
@ -351,11 +349,12 @@ void QXcbBackingStore::endPaint()
|
||||
|
||||
// Slow path: the paint device was m_rgbImage. Now copy with swapping red
|
||||
// and blue into m_image.
|
||||
const QVector<QRect> rects = m_paintRegion.rects();
|
||||
if (rects.isEmpty())
|
||||
auto it = m_paintRegion.begin();
|
||||
const auto end = m_paintRegion.end();
|
||||
if (it == end)
|
||||
return;
|
||||
QPainter p(m_image->image());
|
||||
for (QVector<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it) {
|
||||
while (it != end) {
|
||||
const QRect rect = *it;
|
||||
p.drawImage(rect.topLeft(), m_rgbImage.copy(rect).rgbSwapped());
|
||||
}
|
||||
@ -397,9 +396,8 @@ void QXcbBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoin
|
||||
return;
|
||||
}
|
||||
|
||||
QVector<QRect> rects = clipped.rects();
|
||||
for (int i = 0; i < rects.size(); ++i) {
|
||||
QRect rect = QRect(rects.at(i).topLeft(), rects.at(i).size());
|
||||
for (const QRect &r : clipped) {
|
||||
QRect rect = QRect(r.topLeft(), r.size());
|
||||
m_image->put(platformWindow->xcb_window(), rect.topLeft(), rect.translated(offset));
|
||||
}
|
||||
|
||||
@ -463,9 +461,8 @@ bool QXcbBackingStore::scroll(const QRegion &area, int dx, int dy)
|
||||
m_image->preparePaint(area);
|
||||
|
||||
QPoint delta(dx, dy);
|
||||
const QVector<QRect> rects = area.rects();
|
||||
for (int i = 0; i < rects.size(); ++i)
|
||||
qt_scrollRectInImage(*m_image->image(), rects.at(i), delta);
|
||||
for (const QRect &rect : area)
|
||||
qt_scrollRectInImage(*m_image->image(), rect, delta);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2741,9 +2741,8 @@ void QXcbWindow::setMask(const QRegion ®ion)
|
||||
XCB_SHAPE_SK_BOUNDING, xcb_window(), 0, 0, XCB_NONE);
|
||||
} else {
|
||||
QVector<xcb_rectangle_t> rects;
|
||||
const QVector<QRect> regionRects = region.rects();
|
||||
rects.reserve(regionRects.count());
|
||||
foreach (const QRect &r, regionRects)
|
||||
rects.reserve(region.rectCount());
|
||||
for (const QRect &r : region)
|
||||
rects.push_back(qRectToXCBRectangle(r));
|
||||
xcb_shape_rectangles(connection()->xcb_connection(), XCB_SHAPE_SO_SET,
|
||||
XCB_SHAPE_SK_BOUNDING, XCB_CLIP_ORDERING_UNSORTED,
|
||||
|
Loading…
Reference in New Issue
Block a user