1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the plugins of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qxcbconnection.h"
43 #include "qxcbkeyboard.h"
44 #include "qxcbscreen.h"
45 #include "qxcbwindow.h"
46 #include "qxcbclipboard.h"
48 #include "qxcbwmsupport.h"
50 #include <QtAlgorithms>
51 #include <QSocketNotifier>
52 #include <QtGui/private/qguiapplication_p.h>
53 #include <QAbstractEventDispatcher>
55 #include <QtCore/QDebug>
59 #include <xcb/xfixes.h>
63 #include <X11/Xlib-xcb.h>
67 #include <xcb/render.h>
70 #ifdef XCB_USE_EGL //dont pull in eglext prototypes
79 #define MESA_EGL_NO_X11_HEADERS
80 #define EGL_EGLEXT_PROTOTYPES
82 #include <EGL/eglext.h>
85 QXcbConnection::QXcbConnection(const char *displayName)
86 : m_displayName(displayName ? QByteArray(displayName) : qgetenv("DISPLAY"))
90 , m_dri2_support_probed(false)
91 , m_has_support_for_dri2(false)
97 Display *dpy = XOpenDisplay(m_displayName.constData());
98 m_primaryScreen = DefaultScreen(dpy);
99 m_connection = XGetXCBConnection(dpy);
100 XSetEventQueueOwner(dpy, XCBOwnsEventQueue);
101 m_xlib_display = dpy;
103 EGLDisplay eglDisplay = eglGetDisplay(dpy);
104 m_egl_display = eglDisplay;
106 eglBindAPI(EGL_OPENGL_ES_API);
107 m_has_egl = eglInitialize(eglDisplay,&major,&minor);
110 m_connection = xcb_connect(m_displayName.constData(), &primaryScreen);
112 #endif //XCB_USE_XLIB
113 m_setup = xcb_get_setup(xcb_connection());
115 initializeAllAtoms();
117 m_time = XCB_CURRENT_TIME;
119 xcb_screen_iterator_t it = xcb_setup_roots_iterator(m_setup);
121 int screenNumber = 0;
123 m_screens << new QXcbScreen(this, it.data, screenNumber++);
124 xcb_screen_next(&it);
127 m_wmSupport = new QXcbWMSupport(this);
128 m_keyboard = new QXcbKeyboard(this);
129 m_clipboard = new QXcbClipboard(this);
130 m_drag = new QXcbDrag(this);
139 QSocketNotifier *notifier = new QSocketNotifier(xcb_get_file_descriptor(xcb_connection()), QSocketNotifier::Read, this);
140 connect(notifier, SIGNAL(activated(int)), this, SLOT(processXcbEvents()));
142 QAbstractEventDispatcher *dispatcher = QAbstractEventDispatcher::instance(qApp->thread());
143 connect(dispatcher, SIGNAL(aboutToBlock()), this, SLOT(processXcbEvents()));
144 connect(dispatcher, SIGNAL(awake()), this, SLOT(processXcbEvents()));
149 QXcbConnection::~QXcbConnection()
153 qDeleteAll(m_screens);
156 XCloseDisplay((Display *)m_xlib_display);
158 xcb_disconnect(xcb_connection());
164 void QXcbConnection::addWindow(xcb_window_t id, QXcbWindow *window)
166 m_mapper.insert(id, window);
169 void QXcbConnection::removeWindow(xcb_window_t id)
174 QXcbWindow *QXcbConnection::platformWindowFromId(xcb_window_t id)
176 return m_mapper.value(id, 0);
179 #define HANDLE_PLATFORM_WINDOW_EVENT(event_t, windowMember, handler) \
181 event_t *e = (event_t *)event; \
182 if (QXcbWindow *platformWindow = platformWindowFromId(e->windowMember)) \
183 platformWindow->handler(e); \
187 #define HANDLE_KEYBOARD_EVENT(event_t, handler) \
189 event_t *e = (event_t *)event; \
190 if (QXcbWindow *platformWindow = platformWindowFromId(e->event)) \
191 m_keyboard->handler(platformWindow, e); \
195 //#define XCB_EVENT_DEBUG
197 void printXcbEvent(const char *message, xcb_generic_event_t *event)
199 #ifdef XCB_EVENT_DEBUG
200 #define PRINT_XCB_EVENT(ev) \
202 printf("%s: %d - %s - sequence: %d\n", message, int(ev), #ev, event->sequence); \
205 switch (event->response_type & ~0x80) {
206 PRINT_XCB_EVENT(XCB_KEY_PRESS);
207 PRINT_XCB_EVENT(XCB_KEY_RELEASE);
208 PRINT_XCB_EVENT(XCB_BUTTON_PRESS);
209 PRINT_XCB_EVENT(XCB_BUTTON_RELEASE);
210 PRINT_XCB_EVENT(XCB_MOTION_NOTIFY);
211 PRINT_XCB_EVENT(XCB_ENTER_NOTIFY);
212 PRINT_XCB_EVENT(XCB_LEAVE_NOTIFY);
213 PRINT_XCB_EVENT(XCB_FOCUS_IN);
214 PRINT_XCB_EVENT(XCB_FOCUS_OUT);
215 PRINT_XCB_EVENT(XCB_KEYMAP_NOTIFY);
216 PRINT_XCB_EVENT(XCB_EXPOSE);
217 PRINT_XCB_EVENT(XCB_GRAPHICS_EXPOSURE);
218 PRINT_XCB_EVENT(XCB_VISIBILITY_NOTIFY);
219 PRINT_XCB_EVENT(XCB_CREATE_NOTIFY);
220 PRINT_XCB_EVENT(XCB_DESTROY_NOTIFY);
221 PRINT_XCB_EVENT(XCB_UNMAP_NOTIFY);
222 PRINT_XCB_EVENT(XCB_MAP_NOTIFY);
223 PRINT_XCB_EVENT(XCB_MAP_REQUEST);
224 PRINT_XCB_EVENT(XCB_REPARENT_NOTIFY);
225 PRINT_XCB_EVENT(XCB_CONFIGURE_NOTIFY);
226 PRINT_XCB_EVENT(XCB_CONFIGURE_REQUEST);
227 PRINT_XCB_EVENT(XCB_GRAVITY_NOTIFY);
228 PRINT_XCB_EVENT(XCB_RESIZE_REQUEST);
229 PRINT_XCB_EVENT(XCB_CIRCULATE_NOTIFY);
230 PRINT_XCB_EVENT(XCB_CIRCULATE_REQUEST);
231 PRINT_XCB_EVENT(XCB_PROPERTY_NOTIFY);
232 PRINT_XCB_EVENT(XCB_SELECTION_CLEAR);
233 PRINT_XCB_EVENT(XCB_SELECTION_REQUEST);
234 PRINT_XCB_EVENT(XCB_SELECTION_NOTIFY);
235 PRINT_XCB_EVENT(XCB_COLORMAP_NOTIFY);
236 PRINT_XCB_EVENT(XCB_CLIENT_MESSAGE);
237 PRINT_XCB_EVENT(XCB_MAPPING_NOTIFY);
239 printf("%s: unknown event - response_type: %d - sequence: %d\n", message, int(event->response_type & ~0x80), int(event->sequence));
247 const char *xcb_errors[] =
270 const char *xcb_protocol_request_codes[] =
274 "ChangeWindowAttributes",
275 "GetWindowAttributes",
302 "ChangeActivePointerGrab",
352 "CopyColormapAndFree",
355 "ListInstalledColormaps",
372 "ChangeKeyboardMapping",
373 "GetKeyboardMapping",
374 "ChangeKeyboardControl",
375 "GetKeyboardControl",
377 "ChangePointerControl",
390 "SetModifierMapping",
391 "GetModifierMapping",
396 void QXcbConnection::log(const char *file, int line, int sequence)
399 info.sequence = sequence;
406 void QXcbConnection::handleXcbError(xcb_generic_error_t *error)
408 uint clamped_error_code = qMin<uint>(error->error_code, (sizeof(xcb_errors) / sizeof(xcb_errors[0])) - 1);
409 uint clamped_major_code = qMin<uint>(error->major_code, (sizeof(xcb_protocol_request_codes) / sizeof(xcb_protocol_request_codes[0])) - 1);
411 printf("XCB error: %d (%s), sequence: %d, resource id: %d, major code: %d (%s), minor code: %d\n",
412 int(error->error_code), xcb_errors[clamped_error_code],
413 int(error->sequence), int(error->resource_id),
414 int(error->major_code), xcb_protocol_request_codes[clamped_major_code],
415 int(error->minor_code));
418 for (; i < m_callLog.size(); ++i) {
419 if (m_callLog.at(i).sequence == error->sequence) {
420 printf("Caused by: %s:%d\n", qPrintable(m_callLog.at(i).file), m_callLog.at(i).line);
422 } else if (m_callLog.at(i).sequence > error->sequence) {
423 printf("Caused some time before: %s:%d\n", qPrintable(m_callLog.at(i).file), m_callLog.at(i).line);
425 printf("and after: %s:%d\n", qPrintable(m_callLog.at(i-1).file), m_callLog.at(i-1).line);
429 if (i == m_callLog.size() && !m_callLog.isEmpty())
430 printf("Caused some time after: %s:%d\n", qPrintable(m_callLog.first().file), m_callLog.first().line);
434 void QXcbConnection::handleXcbEvent(xcb_generic_event_t *event)
439 for (; i < m_callLog.size(); ++i)
440 if (m_callLog.at(i).sequence >= event->sequence)
442 m_callLog.remove(0, i);
447 uint response_type = event->response_type & ~0x80;
449 switch (response_type) {
451 HANDLE_PLATFORM_WINDOW_EVENT(xcb_expose_event_t, window, handleExposeEvent);
452 case XCB_BUTTON_PRESS:
453 HANDLE_PLATFORM_WINDOW_EVENT(xcb_button_press_event_t, event, handleButtonPressEvent);
454 case XCB_BUTTON_RELEASE:
455 HANDLE_PLATFORM_WINDOW_EVENT(xcb_button_release_event_t, event, handleButtonReleaseEvent);
456 case XCB_MOTION_NOTIFY:
457 HANDLE_PLATFORM_WINDOW_EVENT(xcb_motion_notify_event_t, event, handleMotionNotifyEvent);
458 case XCB_CONFIGURE_NOTIFY:
459 HANDLE_PLATFORM_WINDOW_EVENT(xcb_configure_notify_event_t, event, handleConfigureNotifyEvent);
461 HANDLE_PLATFORM_WINDOW_EVENT(xcb_map_notify_event_t, event, handleMapNotifyEvent);
462 case XCB_UNMAP_NOTIFY:
463 HANDLE_PLATFORM_WINDOW_EVENT(xcb_unmap_notify_event_t, event, handleUnmapNotifyEvent);
464 case XCB_CLIENT_MESSAGE:
465 handleClientMessageEvent((xcb_client_message_event_t *)event);
466 case XCB_ENTER_NOTIFY:
467 HANDLE_PLATFORM_WINDOW_EVENT(xcb_enter_notify_event_t, event, handleEnterNotifyEvent);
468 case XCB_LEAVE_NOTIFY:
469 HANDLE_PLATFORM_WINDOW_EVENT(xcb_leave_notify_event_t, event, handleLeaveNotifyEvent);
471 HANDLE_PLATFORM_WINDOW_EVENT(xcb_focus_in_event_t, event, handleFocusInEvent);
473 HANDLE_PLATFORM_WINDOW_EVENT(xcb_focus_out_event_t, event, handleFocusOutEvent);
475 HANDLE_KEYBOARD_EVENT(xcb_key_press_event_t, handleKeyPressEvent);
476 case XCB_KEY_RELEASE:
477 HANDLE_KEYBOARD_EVENT(xcb_key_release_event_t, handleKeyReleaseEvent);
478 case XCB_MAPPING_NOTIFY:
479 m_keyboard->handleMappingNotifyEvent((xcb_mapping_notify_event_t *)event);
481 case XCB_SELECTION_REQUEST:
483 xcb_selection_request_event_t *sr = (xcb_selection_request_event_t *)event;
484 if (sr->selection == atom(QXcbAtom::XdndSelection))
485 m_drag->handleSelectionRequest(sr);
487 m_clipboard->handleSelectionRequest(sr);
490 case XCB_SELECTION_CLEAR:
491 setTime(((xcb_selection_clear_event_t *)event)->time);
492 m_clipboard->handleSelectionClearRequest((xcb_selection_clear_event_t *)event);
495 case XCB_SELECTION_NOTIFY:
496 setTime(((xcb_selection_notify_event_t *)event)->time);
497 qDebug() << "XCB_SELECTION_NOTIFY";
500 case XCB_PROPERTY_NOTIFY:
501 setTime(((xcb_property_notify_event_t *)event)->time);
502 // qDebug() << "XCB_PROPERTY_NOTIFY";
510 printXcbEvent("Handled XCB event", event);
512 printXcbEvent("Unhandled XCB event", event);
515 void QXcbConnection::addPeekFunc(PeekFunc f)
517 m_peekFuncs.append(f);
520 void QXcbConnection::processXcbEvents()
522 while (xcb_generic_event_t *event = xcb_poll_for_event(xcb_connection()))
523 eventqueue.append(event);
525 for(int i = 0; i < eventqueue.size(); ++i) {
526 xcb_generic_event_t *event = eventqueue.at(i);
531 uint response_type = event->response_type & ~0x80;
533 if (!response_type) {
534 handleXcbError((xcb_generic_error_t *)event);
536 QVector<PeekFunc>::iterator it = m_peekFuncs.begin();
537 while (it != m_peekFuncs.end()) {
538 // These callbacks return true if the event is what they were
539 // waiting for, remove them from the list in that case.
541 it = m_peekFuncs.erase(it);
545 handleXcbEvent(event);
553 // Indicate with a null event that the event the callbacks are waiting for
554 // is not in the queue currently.
555 Q_FOREACH (PeekFunc f, m_peekFuncs)
559 xcb_flush(xcb_connection());
562 void QXcbConnection::handleClientMessageEvent(const xcb_client_message_event_t *event)
564 if (event->format != 32)
567 if (event->type == atom(QXcbAtom::XdndStatus)) {
568 drag()->handleStatus(event, false);
569 } else if (event->type == atom(QXcbAtom::XdndFinished)) {
570 drag()->handleFinished(event, false);
573 QXcbWindow *window = platformWindowFromId(event->window);
577 window->handleClientMessageEvent(event);
581 xcb_generic_event_t *QXcbConnection::checkEvent(int type)
583 while (xcb_generic_event_t *event = xcb_poll_for_event(xcb_connection()))
584 eventqueue.append(event);
586 for (int i = 0; i < eventqueue.size(); ++i) {
587 xcb_generic_event_t *event = eventqueue.at(i);
588 if (event->response_type == type) {
596 static const char * xcb_atomnames = {
597 // window-manager <-> client protocols
602 "_NET_WM_CONTEXT_HELP\0"
603 "_NET_WM_SYNC_REQUEST\0"
604 "_NET_WM_SYNC_REQUEST_COUNTER\0"
606 // ICCCM window state
610 // Session management
624 "_QT_CLIPBOARD_SENTINEL\0"
625 "_QT_SELECTION_SENTINEL\0"
626 "CLIPBOARD_MANAGER\0"
633 "_QT_INPUT_ENCODING\0"
638 "ENLIGHTENMENT_DESKTOP\0"
640 "_SGI_DESKS_MANAGER\0"
644 "_NET_VIRTUAL_ROOTS\0"
647 "_NET_MOVERESIZE_WINDOW\0"
648 "_NET_WM_MOVERESIZE\0"
651 "_NET_WM_ICON_NAME\0"
656 "_NET_WM_WINDOW_OPACITY\0"
659 "_NET_WM_STATE_ABOVE\0"
660 "_NET_WM_STATE_BELOW\0"
661 "_NET_WM_STATE_FULLSCREEN\0"
662 "_NET_WM_STATE_MAXIMIZED_HORZ\0"
663 "_NET_WM_STATE_MAXIMIZED_VERT\0"
664 "_NET_WM_STATE_MODAL\0"
665 "_NET_WM_STATE_STAYS_ON_TOP\0"
666 "_NET_WM_STATE_DEMANDS_ATTENTION\0"
668 "_NET_WM_USER_TIME\0"
669 "_NET_WM_USER_TIME_WINDOW\0"
670 "_NET_WM_FULL_PLACEMENT\0"
672 "_NET_WM_WINDOW_TYPE\0"
673 "_NET_WM_WINDOW_TYPE_DESKTOP\0"
674 "_NET_WM_WINDOW_TYPE_DOCK\0"
675 "_NET_WM_WINDOW_TYPE_TOOLBAR\0"
676 "_NET_WM_WINDOW_TYPE_MENU\0"
677 "_NET_WM_WINDOW_TYPE_UTILITY\0"
678 "_NET_WM_WINDOW_TYPE_SPLASH\0"
679 "_NET_WM_WINDOW_TYPE_DIALOG\0"
680 "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU\0"
681 "_NET_WM_WINDOW_TYPE_POPUP_MENU\0"
682 "_NET_WM_WINDOW_TYPE_TOOLTIP\0"
683 "_NET_WM_WINDOW_TYPE_NOTIFICATION\0"
684 "_NET_WM_WINDOW_TYPE_COMBO\0"
685 "_NET_WM_WINDOW_TYPE_DND\0"
686 "_NET_WM_WINDOW_TYPE_NORMAL\0"
687 "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE\0"
689 "_KDE_NET_WM_FRAME_STRUT\0"
691 "_NET_STARTUP_INFO\0"
692 "_NET_STARTUP_INFO_BEGIN\0"
694 "_NET_SUPPORTING_WM_CHECK\0"
698 "_NET_SYSTEM_TRAY_VISUAL\0"
700 "_NET_ACTIVE_WINDOW\0"
724 "XdndActionPrivate\0"
727 "_MOTIF_DRAG_AND_DROP_MESSAGE\0"
728 "_MOTIF_DRAG_INITIATOR_INFO\0"
729 "_MOTIF_DRAG_RECEIVER_INFO\0"
730 "_MOTIF_DRAG_WINDOW\0"
731 "_MOTIF_DRAG_TARGETS\0"
733 "XmTRANSFER_SUCCESS\0"
734 "XmTRANSFER_FAILURE\0"
743 // Wacom old. (before version 0.10)
753 xcb_atom_t QXcbConnection::atom(QXcbAtom::Atom atom)
755 return m_allAtoms[atom];
758 void QXcbConnection::initializeAllAtoms() {
759 const char *names[QXcbAtom::NAtoms];
760 const char *ptr = xcb_atomnames;
770 Q_ASSERT(i == QXcbAtom::NPredefinedAtoms);
772 QByteArray settings_atom_name("_QT_SETTINGS_TIMESTAMP_");
773 settings_atom_name += m_displayName;
774 names[i++] = settings_atom_name;
776 xcb_intern_atom_cookie_t cookies[QXcbAtom::NAtoms];
778 Q_ASSERT(i == QXcbAtom::NAtoms);
779 for (i = 0; i < QXcbAtom::NAtoms; ++i)
780 cookies[i] = xcb_intern_atom(xcb_connection(), false, strlen(names[i]), names[i]);
782 for (i = 0; i < QXcbAtom::NAtoms; ++i) {
783 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(xcb_connection(), cookies[i], 0);
784 m_allAtoms[i] = reply->atom;
789 xcb_atom_t QXcbConnection::internAtom(const char *name)
791 if (!name || *name == 0)
794 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(xcb_connection(), false, strlen(name), name);
795 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(xcb_connection(), cookie, 0);
796 int atom = reply->atom;
801 QByteArray QXcbConnection::atomName(xcb_atom_t atom)
806 xcb_generic_error_t *error = 0;
807 xcb_get_atom_name_cookie_t cookie = Q_XCB_CALL(xcb_get_atom_name(xcb_connection(), atom));
808 xcb_get_atom_name_reply_t *reply = xcb_get_atom_name_reply(xcb_connection(), cookie, &error);
810 qWarning() << "QXcbConnection::atomName: bad Atom" << atom;
813 QByteArray result(xcb_get_atom_name_name(reply), xcb_get_atom_name_name_length(reply));
820 const xcb_format_t *QXcbConnection::formatForDepth(uint8_t depth) const
822 xcb_format_iterator_t iterator =
823 xcb_setup_pixmap_formats_iterator(m_setup);
825 while (iterator.rem) {
826 xcb_format_t *format = iterator.data;
827 if (format->depth == depth)
829 xcb_format_next(&iterator);
835 void QXcbConnection::sync()
838 xcb_get_input_focus_cookie_t cookie = Q_XCB_CALL(xcb_get_input_focus(xcb_connection()));
839 free(xcb_get_input_focus_reply(xcb_connection(), cookie, 0));
842 void QXcbConnection::initializeXFixes()
844 xcb_generic_error_t *error = 0;
845 xcb_prefetch_extension_data (m_connection, &xcb_xfixes_id);
846 xcb_xfixes_query_version_cookie_t xfixes_query_cookie = xcb_xfixes_query_version(m_connection,
847 XCB_XFIXES_MAJOR_VERSION,
848 XCB_XFIXES_MINOR_VERSION);
849 xcb_xfixes_query_version_reply_t *xfixes_query = xcb_xfixes_query_version_reply (m_connection,
850 xfixes_query_cookie, &error);
851 if (!xfixes_query || error || xfixes_query->major_version < 2) {
852 qWarning("Failed to initialize XFixes");
858 void QXcbConnection::initializeXRender()
860 #ifdef XCB_USE_RENDER
861 xcb_generic_error_t *error = 0;
862 xcb_render_query_version_cookie_t xrender_query_cookie = xcb_render_query_version(m_connection,
863 XCB_RENDER_MAJOR_VERSION,
864 XCB_RENDER_MINOR_VERSION);
865 xcb_render_query_version_reply_t *xrender_query = xcb_render_query_version_reply(m_connection,
866 xrender_query_cookie, &error);
867 if (!xrender_query || error || (xrender_query->major_version == 0 && xrender_query->minor_version < 5)) {
868 qWarning("Failed to initialize XRender");
875 #if defined(XCB_USE_EGL)
876 bool QXcbConnection::hasEgl() const
880 #endif // defined(XCB_USE_EGL)
883 void QXcbConnection::initializeDri2()
885 xcb_dri2_connect_cookie_t connect_cookie = xcb_dri2_connect_unchecked (m_connection,
886 m_screens[0]->root(),
887 XCB_DRI2_DRIVER_TYPE_DRI);
889 xcb_dri2_connect_reply_t *connect = xcb_dri2_connect_reply (m_connection,
890 connect_cookie, NULL);
892 if (! connect || connect->driver_name_length + connect->device_name_length == 0) {
893 qDebug() << "Failed to connect to dri2";
897 m_dri2_device_name = QByteArray(xcb_dri2_connect_device_name (connect),
898 xcb_dri2_connect_device_name_length (connect));
901 int fd = open(m_dri2_device_name.constData(), O_RDWR);
903 qDebug() << "InitializeDri2: Could'nt open device << dri2DeviceName";
904 m_dri2_device_name = QByteArray();
909 if (drmGetMagic(fd, &magic)) {
910 qDebug() << "Failed to get drmMagic";
914 xcb_dri2_authenticate_cookie_t authenticate_cookie = xcb_dri2_authenticate_unchecked(m_connection,
915 m_screens[0]->root(), magic);
916 xcb_dri2_authenticate_reply_t *authenticate = xcb_dri2_authenticate_reply(m_connection,
917 authenticate_cookie, NULL);
918 if (authenticate == NULL || !authenticate->authenticated) {
919 fprintf(stderr, "DRI2: failed to authenticate\n");
926 EGLDisplay display = eglGetDRMDisplayMESA(fd);
928 fprintf(stderr, "failed to create display\n");
932 m_egl_display = display;
934 if (!eglInitialize(display, &major, &minor)) {
935 fprintf(stderr, "failed to initialize display\n");
940 bool QXcbConnection::hasSupportForDri2() const
942 if (!m_dri2_support_probed) {
943 xcb_generic_error_t *error = 0;
945 xcb_prefetch_extension_data (m_connection, &xcb_dri2_id);
947 xcb_dri2_query_version_cookie_t dri2_query_cookie = xcb_dri2_query_version (m_connection,
948 XCB_DRI2_MAJOR_VERSION,
949 XCB_DRI2_MINOR_VERSION);
951 xcb_dri2_query_version_reply_t *dri2_query = xcb_dri2_query_version_reply (m_connection,
952 dri2_query_cookie, &error);
953 if (!dri2_query || error) {
959 QXcbConnection *that = const_cast<QXcbConnection *>(this);
960 that->m_dri2_major = dri2_query->major_version;
961 that->m_dri2_minor = dri2_query->minor_version;
963 that->m_has_support_for_dri2 = true;
964 that->m_dri2_support_probed = true;
966 return m_has_support_for_dri2;
968 #endif //XCB_USE_DRI2