diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2017-12-06 10:11:53 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2017-12-06 18:30:57 +0000 |
commit | 9e187220868dedfa911da758881b85ffd0c64418 (patch) | |
tree | 372465eadec34de3d8c238923bc04576ec0cd4db /src/plugins/platforms/xcb | |
parent | 03026973700f1fcdff602dffa3d94b04912acd44 (diff) |
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>
Diffstat (limited to 'src/plugins/platforms/xcb')
-rw-r--r-- | src/plugins/platforms/xcb/qxcbbackingstore.cpp | 11 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbwindow.cpp | 14 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbwindow.h | 2 |
3 files changed, 13 insertions, 14 deletions
diff --git a/src/plugins/platforms/xcb/qxcbbackingstore.cpp b/src/plugins/platforms/xcb/qxcbbackingstore.cpp index 1e046aa677..979c8142f7 100644 --- a/src/plugins/platforms/xcb/qxcbbackingstore.cpp +++ b/src/plugins/platforms/xcb/qxcbbackingstore.cpp @@ -520,16 +520,7 @@ void QXcbShmImage::setClip(const QRegion ®ion) 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, diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index 5ea865f74a..e7096fb8f0 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -2776,6 +2776,15 @@ void QXcbWindow::setOpacity(qreal level) (uchar *)&value); } +QVector<xcb_rectangle_t> qRegionToXcbRectangleList(const QRegion ®ion) +{ + 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 ®ion) { if (!connection()->hasXShape()) @@ -2784,10 +2793,7 @@ void QXcbWindow::setMask(const QRegion ®ion) 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]); diff --git a/src/plugins/platforms/xcb/qxcbwindow.h b/src/plugins/platforms/xcb/qxcbwindow.h index b89dddf72f..638ab26cea 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.h +++ b/src/plugins/platforms/xcb/qxcbwindow.h @@ -296,6 +296,8 @@ protected: void create() override {} // No-op }; +QVector<xcb_rectangle_t> qRegionToXcbRectangleList(const QRegion ®ion); + QT_END_NAMESPACE Q_DECLARE_METATYPE(QXcbWindow*) |