diff options
-rw-r--r-- | src/plugins/platforms/xcb/qxcbscreen.cpp | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp index b4c772dd3b..23585ab511 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.cpp +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -387,10 +387,9 @@ QSurfaceFormat QXcbScreen::surfaceFormatFor(const QSurfaceFormat &format) const const xcb_visualtype_t *QXcbScreen::visualForFormat(const QSurfaceFormat &format) const { - QVector<const xcb_visualtype_t *> candidates; + const xcb_visualtype_t *candidate = nullptr; - for (auto ii = m_visuals.constBegin(); ii != m_visuals.constEnd(); ++ii) { - const xcb_visualtype_t &xcb_visualtype = ii.value(); + for (const xcb_visualtype_t &xcb_visualtype : m_visuals) { const int redSize = qPopulationCount(xcb_visualtype.red_mask); const int greenSize = qPopulationCount(xcb_visualtype.green_mask); @@ -409,19 +408,17 @@ const xcb_visualtype_t *QXcbScreen::visualForFormat(const QSurfaceFormat &format if (format.alphaBufferSize() != -1 && alphaSize != format.alphaBufferSize()) continue; - candidates.append(&xcb_visualtype); - } - - if (candidates.isEmpty()) - return nullptr; + // Try to find a RGB visual rather than e.g. BGR or GBR + if (qCountTrailingZeroBits(xcb_visualtype.blue_mask) == 0) + return &xcb_visualtype; - // Try to find a RGB visual rather than e.g. BGR or GBR - for (const xcb_visualtype_t *candidate : qAsConst(candidates)) - if (qCountTrailingZeroBits(candidate->blue_mask) == 0) - return candidate; + // In case we do not find anything we like, just remember the first one + // and hope for the best: + if (!candidate) + candidate = &xcb_visualtype; + } - // Did not find anything we like, just grab the first one and hope for the best - return candidates.first(); + return candidate; } void QXcbScreen::sendStartupMessage(const QByteArray &message) const |