[Window Thumbnails] Don't crash if Composite is disabled

We were checking for Composite at compile-time but not at runtime causing a crash
when Composite has explicitly been disable in which case Damage might still be availab.e

REVIEW: 126296
This commit is contained in:
Kai Uwe Broulik 2015-12-13 20:25:20 +01:00
parent e3fdc030ec
commit 9b48e3d010
2 changed files with 13 additions and 3 deletions

View File

@ -63,6 +63,7 @@ WindowThumbnail::WindowThumbnail(QQuickItem *parent)
: QQuickItem(parent) : QQuickItem(parent)
, QAbstractNativeEventFilter() , QAbstractNativeEventFilter()
, m_xcb(false) , m_xcb(false)
, m_composite(false)
, m_winId(0) , m_winId(0)
, m_paintedSize(QSizeF()) , m_paintedSize(QSizeF())
, m_thumbnailAvailable(false) , m_thumbnailAvailable(false)
@ -103,6 +104,10 @@ WindowThumbnail::WindowThumbnail(QQuickItem *parent)
gui->installNativeEventFilter(this); gui->installNativeEventFilter(this);
#if HAVE_XCB_COMPOSITE #if HAVE_XCB_COMPOSITE
xcb_connection_t *c = QX11Info::connection(); xcb_connection_t *c = QX11Info::connection();
xcb_prefetch_extension_data(c, &xcb_composite_id);
const auto *compositeReply = xcb_get_extension_data(c, &xcb_composite_id);
m_composite = (compositeReply && compositeReply->present);
xcb_prefetch_extension_data(c, &xcb_damage_id); xcb_prefetch_extension_data(c, &xcb_damage_id);
const auto *reply = xcb_get_extension_data(c, &xcb_damage_id); const auto *reply = xcb_get_extension_data(c, &xcb_damage_id);
m_damageEventBase = reply->first_event; m_damageEventBase = reply->first_event;
@ -190,7 +195,7 @@ QSGNode *WindowThumbnail::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData
bool WindowThumbnail::nativeEventFilter(const QByteArray &eventType, void *message, long int *result) bool WindowThumbnail::nativeEventFilter(const QByteArray &eventType, void *message, long int *result)
{ {
Q_UNUSED(result) Q_UNUSED(result)
if (!m_xcb || eventType != QByteArrayLiteral("xcb_generic_event_t")) { if (!m_xcb || !m_composite || eventType != QByteArrayLiteral("xcb_generic_event_t")) {
// currently we are only interested in XCB events // currently we are only interested in XCB events
return false; return false;
} }
@ -390,6 +395,10 @@ void WindowThumbnail::windowToTexture(WindowTextureNode *textureNode)
#if HAVE_XCB_COMPOSITE #if HAVE_XCB_COMPOSITE
xcb_pixmap_t WindowThumbnail::pixmapForWindow() xcb_pixmap_t WindowThumbnail::pixmapForWindow()
{ {
if (!m_composite) {
return XCB_PIXMAP_NONE;
}
xcb_connection_t *c = QX11Info::connection(); xcb_connection_t *c = QX11Info::connection();
xcb_pixmap_t pix = xcb_generate_id(c); xcb_pixmap_t pix = xcb_generate_id(c);
auto cookie = xcb_composite_name_window_pixmap_checked(c, m_winId, pix); auto cookie = xcb_composite_name_window_pixmap_checked(c, m_winId, pix);
@ -544,7 +553,7 @@ void WindowThumbnail::resetDamaged()
void WindowThumbnail::stopRedirecting() void WindowThumbnail::stopRedirecting()
{ {
if (!m_xcb) { if (!m_xcb || !m_composite) {
return; return;
} }
#if HAVE_XCB_COMPOSITE #if HAVE_XCB_COMPOSITE
@ -567,7 +576,7 @@ void WindowThumbnail::stopRedirecting()
void WindowThumbnail::startRedirecting() void WindowThumbnail::startRedirecting()
{ {
if (!m_xcb || !window() || window()->winId() == m_winId) { if (!m_xcb || !m_composite || !window() || window()->winId() == m_winId) {
return; return;
} }
#if HAVE_XCB_COMPOSITE #if HAVE_XCB_COMPOSITE

View File

@ -109,6 +109,7 @@ private:
void setThumbnailAvailable(bool thumbnailAvailable); void setThumbnailAvailable(bool thumbnailAvailable);
bool m_xcb; bool m_xcb;
bool m_composite;
uint32_t m_winId; uint32_t m_winId;
QSizeF m_paintedSize; QSizeF m_paintedSize;
bool m_thumbnailAvailable; bool m_thumbnailAvailable;