Change copyrights from Nokia to Digia
[profile/ivi/qtwayland.git] / src / plugins / platforms / wayland / gl_integration / xcomposite_egl / qwaylandxcompositeeglintegration.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
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.
16 **
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.
24 **
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.
28 **
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.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qwaylandxcompositeeglintegration.h"
43
44 #include "qwaylandxcompositeeglwindow.h"
45
46 #include <QtCore/QDebug>
47
48 #include "wayland-xcomposite-client-protocol.h"
49
50 QWaylandGLIntegration * QWaylandGLIntegration::createGLIntegration(QWaylandDisplay *waylandDisplay)
51 {
52     return new QWaylandXCompositeEGLIntegration(waylandDisplay);
53 }
54
55 QWaylandXCompositeEGLIntegration::QWaylandXCompositeEGLIntegration(QWaylandDisplay * waylandDispaly)
56     : QWaylandGLIntegration()
57     , mWaylandDisplay(waylandDispaly)
58 {
59     qDebug() << "Using XComposite-EGL";
60     wl_display_add_global_listener(mWaylandDisplay->wl_display(), QWaylandXCompositeEGLIntegration::wlDisplayHandleGlobal,
61                                    this);
62 }
63
64 QWaylandXCompositeEGLIntegration::~QWaylandXCompositeEGLIntegration()
65 {
66     XCloseDisplay(mDisplay);
67 }
68
69 void QWaylandXCompositeEGLIntegration::initialize()
70 {
71 }
72
73 QWaylandWindow * QWaylandXCompositeEGLIntegration::createEglWindow(QWindow *window)
74 {
75     return new QWaylandXCompositeEGLWindow(window,this);
76 }
77
78 QPlatformOpenGLContext *QWaylandXCompositeEGLIntegration::createPlatformOpenGLContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share) const
79 {
80     return new QWaylandXCompositeEGLContext(glFormat, share, eglDisplay());
81 }
82
83 Display * QWaylandXCompositeEGLIntegration::xDisplay() const
84 {
85     return mDisplay;
86 }
87
88 EGLDisplay QWaylandXCompositeEGLIntegration::eglDisplay() const
89 {
90     return mEglDisplay;
91 }
92
93 int QWaylandXCompositeEGLIntegration::screen() const
94 {
95     return mScreen;
96 }
97
98 Window QWaylandXCompositeEGLIntegration::rootWindow() const
99 {
100     return mRootWindow;
101 }
102
103 QWaylandDisplay * QWaylandXCompositeEGLIntegration::waylandDisplay() const
104 {
105     return mWaylandDisplay;
106 }
107 wl_xcomposite * QWaylandXCompositeEGLIntegration::waylandXComposite() const
108 {
109     return mWaylandComposite;
110 }
111
112 const struct wl_xcomposite_listener QWaylandXCompositeEGLIntegration::xcomposite_listener = {
113     QWaylandXCompositeEGLIntegration::rootInformation
114 };
115
116 void QWaylandXCompositeEGLIntegration::wlDisplayHandleGlobal(wl_display *display, uint32_t id, const char *interface, uint32_t version, void *data)
117 {
118     Q_UNUSED(version);
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);
123     }
124
125 }
126
127 void QWaylandXCompositeEGLIntegration::rootInformation(void *data, wl_xcomposite *xcomposite, const char *display_name, uint32_t root_window)
128 {
129     Q_UNUSED(xcomposite);
130     QWaylandXCompositeEGLIntegration *integration = static_cast<QWaylandXCompositeEGLIntegration *>(data);
131
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);
137     EGLint minor,major;
138     if (!eglInitialize(integration->mEglDisplay,&major,&minor)) {
139         qFatal("Failed to initialize EGL");
140     }
141     eglSwapInterval(integration->eglDisplay(),0);
142     qDebug() << "ROOT INFORMATION" << integration->mDisplay << integration->mRootWindow << integration->mScreen;
143 }
144