1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the plugins of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
42 #include "qwaylandxcompositeeglintegration.h"
44 #include "qwaylandxcompositeeglwindow.h"
46 #include <QtCore/QDebug>
48 #include "wayland-xcomposite-client-protocol.h"
50 QWaylandGLIntegration * QWaylandGLIntegration::createGLIntegration(QWaylandDisplay *waylandDisplay)
52 return new QWaylandXCompositeEGLIntegration(waylandDisplay);
55 QWaylandXCompositeEGLIntegration::QWaylandXCompositeEGLIntegration(QWaylandDisplay * waylandDispaly)
56 : QWaylandGLIntegration()
57 , mWaylandDisplay(waylandDispaly)
59 qDebug() << "Using XComposite-EGL";
60 wl_display_add_global_listener(mWaylandDisplay->wl_display(), QWaylandXCompositeEGLIntegration::wlDisplayHandleGlobal,
64 QWaylandXCompositeEGLIntegration::~QWaylandXCompositeEGLIntegration()
66 XCloseDisplay(mDisplay);
69 void QWaylandXCompositeEGLIntegration::initialize()
73 QWaylandWindow * QWaylandXCompositeEGLIntegration::createEglWindow(QWindow *window)
75 return new QWaylandXCompositeEGLWindow(window,this);
78 QPlatformOpenGLContext *QWaylandXCompositeEGLIntegration::createPlatformOpenGLContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share) const
80 return new QWaylandXCompositeEGLContext(glFormat, share, eglDisplay());
83 Display * QWaylandXCompositeEGLIntegration::xDisplay() const
88 EGLDisplay QWaylandXCompositeEGLIntegration::eglDisplay() const
93 int QWaylandXCompositeEGLIntegration::screen() const
98 Window QWaylandXCompositeEGLIntegration::rootWindow() const
103 QWaylandDisplay * QWaylandXCompositeEGLIntegration::waylandDisplay() const
105 return mWaylandDisplay;
107 wl_xcomposite * QWaylandXCompositeEGLIntegration::waylandXComposite() const
109 return mWaylandComposite;
112 const struct wl_xcomposite_listener QWaylandXCompositeEGLIntegration::xcomposite_listener = {
113 QWaylandXCompositeEGLIntegration::rootInformation
116 void QWaylandXCompositeEGLIntegration::wlDisplayHandleGlobal(wl_display *display, uint32_t id, const char *interface, uint32_t version, void *data)
119 if (strcmp(interface, "wl_xcomposite") == 0) {
120 QWaylandXCompositeEGLIntegration *integration = static_cast<QWaylandXCompositeEGLIntegration *>(data);
121 integration->mWaylandComposite = static_cast<struct wl_xcomposite *>(wl_display_bind(display,id,&wl_xcomposite_interface));
122 wl_xcomposite_add_listener(integration->mWaylandComposite,&xcomposite_listener,integration);
127 void QWaylandXCompositeEGLIntegration::rootInformation(void *data, wl_xcomposite *xcomposite, const char *display_name, uint32_t root_window)
129 Q_UNUSED(xcomposite);
130 QWaylandXCompositeEGLIntegration *integration = static_cast<QWaylandXCompositeEGLIntegration *>(data);
132 integration->mDisplay = XOpenDisplay(display_name);
133 integration->mRootWindow = (Window) root_window;
134 integration->mScreen = XDefaultScreen(integration->mDisplay);
135 integration->mEglDisplay = eglGetDisplay(integration->mDisplay);
136 eglBindAPI(EGL_OPENGL_ES_API);
138 if (!eglInitialize(integration->mEglDisplay,&major,&minor)) {
139 qFatal("Failed to initialize EGL");
141 eglSwapInterval(integration->eglDisplay(),0);
142 qDebug() << "ROOT INFORMATION" << integration->mDisplay << integration->mRootWindow << integration->mScreen;