xcb: share code for QRegion -> xcb_rectangle_t[] conversion

... between QXcbWindow and QxcbShmImage.

Replaces one QRegion::rects() call (to be deprecated), fixes potential overflows
that QXcbShmImage did not handle, but QXcbWindow did, and saves ~1KiB of text size.

Change-Id: I55d37021164feefe0cb3e60bd6d22b1976a6467b
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
bb10
Marc Mutz 2017-12-06 10:11:53 +01:00
parent 0302697370
commit 9e18722086
3 changed files with 13 additions and 14 deletions

View File

@ -520,16 +520,7 @@ void QXcbShmImage::setClip(const QRegion &region)
static const uint32_t values[] = { XCB_NONE };
xcb_change_gc(xcb_connection(), m_gc, mask, values);
} else {
const QVector<QRect> qrects = region.rects();
QVector<xcb_rectangle_t> xcb_rects(qrects.size());
for (int i = 0; i < qrects.size(); i++) {
xcb_rects[i].x = qrects[i].x();
xcb_rects[i].y = qrects[i].y();
xcb_rects[i].width = qrects[i].width();
xcb_rects[i].height = qrects[i].height();
}
const auto xcb_rects = qRegionToXcbRectangleList(region);
xcb_set_clip_rectangles(xcb_connection(),
XCB_CLIP_ORDERING_YX_BANDED,
m_gc,

View File

@ -2776,6 +2776,15 @@ void QXcbWindow::setOpacity(qreal level)
(uchar *)&value);
}
QVector<xcb_rectangle_t> qRegionToXcbRectangleList(const QRegion &region)
{
QVector<xcb_rectangle_t> rects;
rects.reserve(region.rectCount());
for (const QRect &r : region)
rects.push_back(qRectToXCBRectangle(r));
return rects;
}
void QXcbWindow::setMask(const QRegion &region)
{
if (!connection()->hasXShape())
@ -2784,10 +2793,7 @@ void QXcbWindow::setMask(const QRegion &region)
xcb_shape_mask(connection()->xcb_connection(), XCB_SHAPE_SO_SET,
XCB_SHAPE_SK_BOUNDING, xcb_window(), 0, 0, XCB_NONE);
} else {
QVector<xcb_rectangle_t> rects;
rects.reserve(region.rectCount());
for (const QRect &r : region)
rects.push_back(qRectToXCBRectangle(r));
const auto rects = qRegionToXcbRectangleList(region);
xcb_shape_rectangles(connection()->xcb_connection(), XCB_SHAPE_SO_SET,
XCB_SHAPE_SK_BOUNDING, XCB_CLIP_ORDERING_UNSORTED,
xcb_window(), 0, 0, rects.size(), &rects[0]);

View File

@ -296,6 +296,8 @@ protected:
void create() override {} // No-op
};
QVector<xcb_rectangle_t> qRegionToXcbRectangleList(const QRegion &region);
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QXcbWindow*)