Port away from QRegion::rects
Summary: QRegion::rects was deprecated in Qt 5.11. It is advised to use begin() and end() methods instead. Reviewers: #kwin, romangg Reviewed By: #kwin, romangg Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D22353
This commit is contained in:
parent
e839c7067e
commit
4e5d3d0010
17 changed files with 58 additions and 65 deletions
|
@ -442,16 +442,15 @@ void ContrastEffect::drawWindow(EffectWindow *w, int mask, QRegion region, Windo
|
|||
const bool scaled = data.xScale() != 1 || data.yScale() != 1;
|
||||
if (scaled) {
|
||||
QPoint pt = shape.boundingRect().topLeft();
|
||||
QVector<QRect> shapeRects = shape.rects();
|
||||
shape = QRegion(); // clear
|
||||
foreach (QRect r, shapeRects) {
|
||||
QRegion scaledShape;
|
||||
for (QRect r : shape) {
|
||||
r.moveTo(pt.x() + (r.x() - pt.x()) * data.xScale() + data.xTranslation(),
|
||||
pt.y() + (r.y() - pt.y()) * data.yScale() + data.yTranslation());
|
||||
r.setWidth(r.width() * data.xScale());
|
||||
r.setHeight(r.height() * data.yScale());
|
||||
shape |= r;
|
||||
scaledShape |= r;
|
||||
}
|
||||
shape = shape & region;
|
||||
shape = scaledShape & region;
|
||||
|
||||
//Only translated, not scaled
|
||||
} else if (translated) {
|
||||
|
|
|
@ -591,16 +591,15 @@ void BlurEffect::drawWindow(EffectWindow *w, int mask, QRegion region, WindowPai
|
|||
const bool scaled = data.xScale() != 1 || data.yScale() != 1;
|
||||
if (scaled) {
|
||||
QPoint pt = shape.boundingRect().topLeft();
|
||||
QVector<QRect> shapeRects = shape.rects();
|
||||
shape = QRegion(); // clear
|
||||
foreach (QRect r, shapeRects) {
|
||||
QRegion scaledShape;
|
||||
for (QRect r : shape) {
|
||||
r.moveTo(pt.x() + (r.x() - pt.x()) * data.xScale() + data.xTranslation(),
|
||||
pt.y() + (r.y() - pt.y()) * data.yScale() + data.yTranslation());
|
||||
r.setWidth(r.width() * data.xScale());
|
||||
r.setHeight(r.height() * data.yScale());
|
||||
shape |= r;
|
||||
scaledShape |= r;
|
||||
}
|
||||
shape = shape & region;
|
||||
shape = scaledShape & region;
|
||||
|
||||
//Only translated, not scaled
|
||||
} else if (translated) {
|
||||
|
|
|
@ -1283,7 +1283,7 @@ void CubeEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPa
|
|||
quadSize = 150.0f;
|
||||
else
|
||||
quadSize = 250.0f;
|
||||
foreach (const QRect & paintRect, paint.rects()) {
|
||||
for (const QRect &paintRect : paint) {
|
||||
for (int i = 0; i <= (paintRect.height() / quadSize); i++) {
|
||||
for (int j = 0; j <= (paintRect.width() / quadSize); j++) {
|
||||
verts << qMin(paintRect.x() + (j + 1)*quadSize, (float)paintRect.x() + paintRect.width()) << paintRect.y() + i*quadSize;
|
||||
|
|
|
@ -93,8 +93,8 @@ void ResizeEffect::paintWindow(EffectWindow* w, int mask, QRegion region, Window
|
|||
color.setAlphaF(alpha);
|
||||
vbo->setColor(color);
|
||||
QVector<float> verts;
|
||||
verts.reserve(paintRegion.rects().count() * 12);
|
||||
foreach (const QRect & r, paintRegion.rects()) {
|
||||
verts.reserve(paintRegion.rectCount() * 12);
|
||||
for (const QRect &r : paintRegion) {
|
||||
verts << r.x() + r.width() << r.y();
|
||||
verts << r.x() << r.y();
|
||||
verts << r.x() << r.y() + r.height();
|
||||
|
@ -110,7 +110,7 @@ void ResizeEffect::paintWindow(EffectWindow* w, int mask, QRegion region, Window
|
|||
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
||||
if (effects->compositingType() == XRenderCompositing) {
|
||||
QVector<xcb_rectangle_t> rects;
|
||||
foreach (const QRect & r, paintRegion.rects()) {
|
||||
for (const QRect &r : paintRegion) {
|
||||
xcb_rectangle_t rect = {int16_t(r.x()), int16_t(r.y()), uint16_t(r.width()), uint16_t(r.height())};
|
||||
rects << rect;
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ void ResizeEffect::paintWindow(EffectWindow* w, int mask, QRegion region, Window
|
|||
QPainter *painter = effects->scenePainter();
|
||||
painter->save();
|
||||
color.setAlphaF(alpha);
|
||||
foreach (const QRect &r, paintRegion.rects()) {
|
||||
for (const QRect &r : paintRegion) {
|
||||
painter->fillRect(r, color);
|
||||
}
|
||||
painter->restore();
|
||||
|
|
|
@ -145,8 +145,9 @@ void ShowFpsEffect::paintWindow(EffectWindow* w, int mask, QRegion region, Windo
|
|||
QRegion r2 = region & QRect(w->x(), w->y(), w->width(), w->height());
|
||||
r2 -= fps_rect;
|
||||
int winsize = 0;
|
||||
foreach (const QRect & r, r2.rects())
|
||||
winsize += r.width() * r.height();
|
||||
for (const QRect &r : r2) {
|
||||
winsize += r.width() * r.height();
|
||||
}
|
||||
paint_size[ paints_pos ] += winsize;
|
||||
}
|
||||
|
||||
|
|
22
geometry.cpp
22
geometry.cpp
|
@ -1178,44 +1178,44 @@ void AbstractClient::checkWorkspacePosition(QRect oldGeometry, int oldDesktop, Q
|
|||
&Workspace::previousRestrictedMoveArea : //... the restricted areas changed
|
||||
&Workspace::restrictedMoveArea; //... when e.g. active desktop or screen changes
|
||||
|
||||
foreach (const QRect & r, (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaTop).rects()) {
|
||||
for (const QRect &r : (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaTop)) {
|
||||
QRect rect = r & oldGeomTall;
|
||||
if (!rect.isEmpty())
|
||||
oldTopMax = qMax(oldTopMax, rect.y() + rect.height());
|
||||
}
|
||||
foreach (const QRect & r, (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaRight).rects()) {
|
||||
for (const QRect &r : (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaRight)) {
|
||||
QRect rect = r & oldGeomWide;
|
||||
if (!rect.isEmpty())
|
||||
oldRightMax = qMin(oldRightMax, rect.x());
|
||||
}
|
||||
foreach (const QRect & r, (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaBottom).rects()) {
|
||||
for (const QRect &r : (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaBottom)) {
|
||||
QRect rect = r & oldGeomTall;
|
||||
if (!rect.isEmpty())
|
||||
oldBottomMax = qMin(oldBottomMax, rect.y());
|
||||
}
|
||||
foreach (const QRect & r, (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaLeft).rects()) {
|
||||
for (const QRect &r : (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaLeft)) {
|
||||
QRect rect = r & oldGeomWide;
|
||||
if (!rect.isEmpty())
|
||||
oldLeftMax = qMax(oldLeftMax, rect.x() + rect.width());
|
||||
}
|
||||
|
||||
// These 4 compute new bounds
|
||||
foreach (const QRect & r, workspace()->restrictedMoveArea(desktop(), StrutAreaTop).rects()) {
|
||||
for (const QRect &r : workspace()->restrictedMoveArea(desktop(), StrutAreaTop)) {
|
||||
QRect rect = r & newGeomTall;
|
||||
if (!rect.isEmpty())
|
||||
topMax = qMax(topMax, rect.y() + rect.height());
|
||||
}
|
||||
foreach (const QRect & r, workspace()->restrictedMoveArea(desktop(), StrutAreaRight).rects()) {
|
||||
for (const QRect &r : workspace()->restrictedMoveArea(desktop(), StrutAreaRight)) {
|
||||
QRect rect = r & newGeomWide;
|
||||
if (!rect.isEmpty())
|
||||
rightMax = qMin(rightMax, rect.x());
|
||||
}
|
||||
foreach (const QRect & r, workspace()->restrictedMoveArea(desktop(), StrutAreaBottom).rects()) {
|
||||
for (const QRect &r : workspace()->restrictedMoveArea(desktop(), StrutAreaBottom)) {
|
||||
QRect rect = r & newGeomTall;
|
||||
if (!rect.isEmpty())
|
||||
bottomMax = qMin(bottomMax, rect.y());
|
||||
}
|
||||
foreach (const QRect & r, workspace()->restrictedMoveArea(desktop(), StrutAreaLeft).rects()) {
|
||||
for (const QRect &r : workspace()->restrictedMoveArea(desktop(), StrutAreaLeft)) {
|
||||
QRect rect = r & newGeomWide;
|
||||
if (!rect.isEmpty())
|
||||
leftMax = qMax(leftMax, rect.x() + rect.width());
|
||||
|
@ -2948,7 +2948,7 @@ void AbstractClient::handleMoveResize(int x, int y, int x_root, int y_root)
|
|||
const QRect titleRect(bTitleRect.translated(moveResizeGeometry().topLeft()));
|
||||
int visiblePixels = 0;
|
||||
int realVisiblePixels = 0;
|
||||
foreach (const QRect &rect, availableArea.rects()) {
|
||||
for (const QRect &rect : availableArea) {
|
||||
const QRect r = rect & titleRect;
|
||||
realVisiblePixels += r.width() * r.height();
|
||||
if ((transposed && r.width() == titleRect.width()) || // Only the full size regions...
|
||||
|
@ -3073,7 +3073,7 @@ void AbstractClient::handleMoveResize(int x, int y, int x_root, int y_root)
|
|||
QRect moveResizeGeom = moveResizeGeometry();
|
||||
const QRect titleRect(bTitleRect.translated(moveResizeGeom.topLeft()));
|
||||
int visiblePixels = 0;
|
||||
foreach (const QRect &rect, availableArea.rects()) {
|
||||
for (const QRect &rect : availableArea) {
|
||||
const QRect r = rect & titleRect;
|
||||
if ((transposed && r.width() == titleRect.width()) || // Only the full size regions...
|
||||
(!transposed && r.height() == titleRect.height())) // ...prevents long slim areas
|
||||
|
@ -3094,7 +3094,7 @@ void AbstractClient::handleMoveResize(int x, int y, int x_root, int y_root)
|
|||
if (screens()->count() > 1) { // optimization
|
||||
// TODO: could be useful on partial screen struts (half-width panels etc.)
|
||||
int newTitleTop = -1;
|
||||
foreach (const QRect &r, strut.rects()) {
|
||||
for (const QRect &r : strut) {
|
||||
if (r.top() == 0 && r.width() > r.height() && // "top panel"
|
||||
r.intersects(moveResizeGeom) && moveResizeGeom.top() < r.bottom()) {
|
||||
newTitleTop = r.bottom() + 1;
|
||||
|
|
|
@ -167,18 +167,15 @@ XRenderPictureData::~XRenderPictureData()
|
|||
XFixesRegion::XFixesRegion(const QRegion ®ion)
|
||||
{
|
||||
m_region = xcb_generate_id(XRenderUtils::s_connection);
|
||||
QVector< QRect > rects = region.rects();
|
||||
QVector< xcb_rectangle_t > xrects(rects.count());
|
||||
for (int i = 0;
|
||||
i < rects.count();
|
||||
++i) {
|
||||
const QRect &rect = rects.at(i);
|
||||
QVector<xcb_rectangle_t> xrects;
|
||||
xrects.reserve(region.rectCount());
|
||||
for (const QRect &rect : region) {
|
||||
xcb_rectangle_t xrect;
|
||||
xrect.x = rect.x();
|
||||
xrect.y = rect.y();
|
||||
xrect.width = rect.width();
|
||||
xrect.height = rect.height();
|
||||
xrects[i] = xrect;
|
||||
xrects.append(xrect);
|
||||
}
|
||||
xcb_xfixes_create_region(XRenderUtils::s_connection, m_region, xrects.count(), xrects.constData());
|
||||
}
|
||||
|
|
|
@ -407,14 +407,14 @@ void AbstractEglTexture::updateTexture(WindowPixmap *pixmap)
|
|||
if (GLPlatform::instance()->isGLES()) {
|
||||
if (s_supportsARGB32 && (image.format() == QImage::Format_ARGB32 || image.format() == QImage::Format_ARGB32_Premultiplied)) {
|
||||
const QImage im = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
||||
for (const QRect &rect : damage.rects()) {
|
||||
for (const QRect &rect : damage) {
|
||||
auto scaledRect = QRect(rect.x() * scale, rect.y() * scale, rect.width() * scale, rect.height() * scale);
|
||||
glTexSubImage2D(m_target, 0, scaledRect.x(), scaledRect.y(), scaledRect.width(), scaledRect.height(),
|
||||
GL_BGRA_EXT, GL_UNSIGNED_BYTE, im.copy(scaledRect).bits());
|
||||
}
|
||||
} else {
|
||||
const QImage im = image.convertToFormat(QImage::Format_RGBA8888_Premultiplied);
|
||||
for (const QRect &rect : damage.rects()) {
|
||||
for (const QRect &rect : damage) {
|
||||
auto scaledRect = QRect(rect.x() * scale, rect.y() * scale, rect.width() * scale, rect.height() * scale);
|
||||
glTexSubImage2D(m_target, 0, scaledRect.x(), scaledRect.y(), scaledRect.width(), scaledRect.height(),
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, im.copy(scaledRect).bits());
|
||||
|
@ -422,7 +422,7 @@ void AbstractEglTexture::updateTexture(WindowPixmap *pixmap)
|
|||
}
|
||||
} else {
|
||||
const QImage im = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
||||
for (const QRect &rect : damage.rects()) {
|
||||
for (const QRect &rect : damage) {
|
||||
auto scaledRect = QRect(rect.x() * scale, rect.y() * scale, rect.width() * scale, rect.height() * scale);
|
||||
glTexSubImage2D(m_target, 0, scaledRect.x(), scaledRect.y(), scaledRect.width(), scaledRect.height(),
|
||||
GL_BGRA, GL_UNSIGNED_BYTE, im.copy(scaledRect).bits());
|
||||
|
|
|
@ -106,7 +106,7 @@ bool OpenGLBackend::perScreenRendering() const
|
|||
void OpenGLBackend::copyPixels(const QRegion ®ion)
|
||||
{
|
||||
const int height = screens()->size().height();
|
||||
foreach (const QRect &r, region.rects()) {
|
||||
for (const QRect &r : region) {
|
||||
const int x0 = r.x();
|
||||
const int y0 = height - r.y() - r.height();
|
||||
const int x1 = r.x() + r.width();
|
||||
|
|
|
@ -374,7 +374,7 @@ void EglOnXBackend::presentSurface(EGLSurface surface, const QRegion &damage, co
|
|||
}
|
||||
} else {
|
||||
// a part of the screen changed, and we can use eglPostSubBufferNV to copy the updated area
|
||||
foreach (const QRect & r, damage.rects()) {
|
||||
for (const QRect &r : damage) {
|
||||
eglPostSubBufferNV(eglDisplay(), surface, r.left(), screenGeometry.height() - r.bottom() - 1, r.width(), r.height());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -733,7 +733,7 @@ void GlxBackend::present()
|
|||
glXQueryDrawable(display(), glxWindow, GLX_BACK_BUFFER_AGE_EXT, (GLuint *) &m_bufferAge);
|
||||
}
|
||||
} else if (m_haveMESACopySubBuffer) {
|
||||
foreach (const QRect & r, lastDamage().rects()) {
|
||||
for (const QRect &r : lastDamage()) {
|
||||
// convert to OpenGL coordinates
|
||||
int y = screenSize.height() - r.y() - r.height();
|
||||
glXCopySubBufferMESA(display(), glxWindow, r.x(), y, r.width(), r.height());
|
||||
|
|
|
@ -124,19 +124,9 @@ void OverlayWindowX11::setShape(const QRegion& reg)
|
|||
// and triggers something).
|
||||
if (reg == m_shape)
|
||||
return;
|
||||
QVector< QRect > rects = reg.rects();
|
||||
xcb_rectangle_t *xrects = new xcb_rectangle_t[rects.count()];
|
||||
for (int i = 0;
|
||||
i < rects.count();
|
||||
++i) {
|
||||
xrects[ i ].x = rects[ i ].x();
|
||||
xrects[ i ].y = rects[ i ].y();
|
||||
xrects[ i ].width = rects[ i ].width();
|
||||
xrects[ i ].height = rects[ i ].height();
|
||||
}
|
||||
const QVector<xcb_rectangle_t> xrects = Xcb::regionToRects(reg);
|
||||
xcb_shape_rectangles(connection(), XCB_SHAPE_SO_SET, XCB_SHAPE_SK_BOUNDING, XCB_CLIP_ORDERING_UNSORTED,
|
||||
m_window, 0, 0, rects.count(), xrects);
|
||||
delete[] xrects;
|
||||
m_window, 0, 0, xrects.count(), xrects.data());
|
||||
setupInputShape(m_window);
|
||||
m_shape = reg;
|
||||
}
|
||||
|
|
|
@ -153,7 +153,9 @@ qint64 SceneQPainter::paint(QRegion damage, ToplevelList toplevels)
|
|||
void SceneQPainter::paintBackground(QRegion region)
|
||||
{
|
||||
m_painter->setBrush(Qt::black);
|
||||
m_painter->drawRects(region.rects());
|
||||
for (const QRect &rect : region) {
|
||||
m_painter->drawRect(rect);
|
||||
}
|
||||
}
|
||||
|
||||
void SceneQPainter::paintCursor()
|
||||
|
|
|
@ -494,11 +494,16 @@ void SceneXrender::Window::performPaint(int mask, QRegion region, WindowPaintDat
|
|||
xform.matrix22 = DOUBLE_TO_FIXED(1.0 / yscale);
|
||||
|
||||
// transform the shape for clipping in paintTransformedScreen()
|
||||
QVector<QRect> rects = transformed_shape.rects();
|
||||
for (int i = 0; i < rects.count(); ++i) {
|
||||
QRect& r = rects[ i ];
|
||||
r.setRect(qRound(r.x() * xscale), qRound(r.y() * yscale),
|
||||
qRound(r.width() * xscale), qRound(r.height() * yscale));
|
||||
QVector<QRect> rects;
|
||||
rects.reserve(transformed_shape.rectCount());
|
||||
for (const QRect &rect : transformed_shape) {
|
||||
const QRect transformedRect(
|
||||
qRound(rect.x() * xscale),
|
||||
qRound(rect.y() * yscale),
|
||||
qRound(rect.width() * xscale),
|
||||
qRound(rect.height() * yscale)
|
||||
);
|
||||
rects.append(transformedRect);
|
||||
}
|
||||
transformed_shape.setRects(rects.constData(), rects.count());
|
||||
}
|
||||
|
|
|
@ -1008,7 +1008,7 @@ void ScreenEdges::recreateEdges()
|
|||
for (int i=0; i<screens()->count(); ++i) {
|
||||
const QRegion screen = QRegion(screens()->geometry(i)).subtracted(processedRegion);
|
||||
processedRegion += screen;
|
||||
Q_FOREACH (const QRect &screenPart, screen.rects()) {
|
||||
for (const QRect &screenPart : screen) {
|
||||
if (isLeftScreen(screenPart, fullArea)) {
|
||||
// left most screen
|
||||
createVerticalEdge(ElectricLeft, screenPart, fullArea);
|
||||
|
|
|
@ -739,7 +739,7 @@ void Toplevel::addDamage(const QRegion &damage)
|
|||
{
|
||||
m_isDamaged = true;
|
||||
damage_region += damage;
|
||||
for (const QRect &r : damage.rects()) {
|
||||
for (const QRect &r : damage) {
|
||||
emit damaged(this, r);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1787,10 +1787,10 @@ static inline xcb_rectangle_t fromQt(const QRect &rect)
|
|||
|
||||
static inline QVector<xcb_rectangle_t> regionToRects(const QRegion ®ion)
|
||||
{
|
||||
const QVector<QRect> regionRects = region.rects();
|
||||
QVector<xcb_rectangle_t> rects(regionRects.count());
|
||||
for (int i=0; i<regionRects.count(); ++i) {
|
||||
rects[i] = Xcb::fromQt(regionRects.at(i));
|
||||
QVector<xcb_rectangle_t> rects;
|
||||
rects.reserve(region.rectCount());
|
||||
for (const QRect &rect : region) {
|
||||
rects.append(Xcb::fromQt(rect));
|
||||
}
|
||||
return rects;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue