Qt 4.8
qwaylandxcompositeeglcontext.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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 
43 
46 
48 #include <QtCore/QDebug>
49 
50 #include "qeglconvenience.h"
51 #include "qxlibeglintegration.h"
52 
53 #include <X11/extensions/Xcomposite.h>
54 
57  , mEglIntegration(glxIntegration)
58  , mWindow(window)
59  , mBuffer(0)
60  , mXWindow(0)
61  , mConfig(q_configFromQPlatformWindowFormat(glxIntegration->eglDisplay(),window->widget()->platformWindowFormat(),true,EGL_WINDOW_BIT))
62  , mWaitingForSync(false)
63 {
64  QVector<EGLint> eglContextAttrs;
65  eglContextAttrs.append(EGL_CONTEXT_CLIENT_VERSION); eglContextAttrs.append(2);
66  eglContextAttrs.append(EGL_NONE);
67 
68  mContext = eglCreateContext(glxIntegration->eglDisplay(),mConfig,EGL_NO_CONTEXT,eglContextAttrs.constData());
69  if (mContext == EGL_NO_CONTEXT) {
70  qFatal("failed to find context");
71  }
72 
74 }
75 
77 {
79 
81 }
82 
84 {
86  eglMakeCurrent(mEglIntegration->eglDisplay(),EGL_NO_SURFACE,EGL_NO_SURFACE,EGL_NO_CONTEXT);
87 }
88 
90 {
91  QSize size = mWindow->geometry().size();
92 
93  eglSwapBuffers(mEglIntegration->eglDisplay(),mEglWindowSurface);
94  mWindow->damage(QRect(QPoint(0,0),size));
96 }
97 
99 {
100  return (void *)eglGetProcAddress(qPrintable(procName));
101 }
102 
104 {
106 }
107 
109 {
111  that->mWaitingForSync = false;
112 }
113 
115 {
116  QSize size(mWindow->geometry().size());
117  if (size.isEmpty()) {
118  //QGLWidget wants a context for a window without geometry
119  size = QSize(1,1);
120  }
121 
122  delete mBuffer;
123  //XFreePixmap deletes the glxPixmap as well
124  if (mXWindow) {
125  XDestroyWindow(mEglIntegration->xDisplay(),mXWindow);
126  }
127 
129 
130  XVisualInfo visualInfoTemplate;
131  memset(&visualInfoTemplate, 0, sizeof(XVisualInfo));
132  visualInfoTemplate.visualid = visualId;
133 
134  int matchingCount = 0;
135  XVisualInfo *visualInfo = XGetVisualInfo(mEglIntegration->xDisplay(), VisualIDMask, &visualInfoTemplate, &matchingCount);
136 
137  Colormap cmap = XCreateColormap(mEglIntegration->xDisplay(),mEglIntegration->rootWindow(),visualInfo->visual,AllocNone);
138 
139  XSetWindowAttributes a;
140  a.colormap = cmap;
141  mXWindow = XCreateWindow(mEglIntegration->xDisplay(), mEglIntegration->rootWindow(),0, 0, size.width(), size.height(),
142  0, visualInfo->depth, InputOutput, visualInfo->visual,
143  CWColormap, &a);
144 
145  XCompositeRedirectWindow(mEglIntegration->xDisplay(), mXWindow, CompositeRedirectManual);
146  XMapWindow(mEglIntegration->xDisplay(), mXWindow);
147 
148  mEglWindowSurface = eglCreateWindowSurface(mEglIntegration->eglDisplay(),mConfig,mXWindow,0);
149  if (mEglWindowSurface == EGL_NO_SURFACE) {
150  qFatal("Could not make eglsurface");
151  }
152 
153  XSync(mEglIntegration->xDisplay(),False);
155  (uint32_t)mXWindow,
156  size,
158  mWindow->attach(mBuffer);
159  wl_display_sync_callback(mEglIntegration->waylandDisplay()->wl_display(),
161  this);
162 
163  mWaitingForSync = true;
164  wl_display_sync(mEglIntegration->waylandDisplay()->wl_display(),0);
166  while (mWaitingForSync) {
168  }
169 }
QPointer< QWidget > widget
virtual QRect geometry() const
Returnes the current geometry of a window.
QWaylandXCompositeEGLWindow * mWindow
EGLConfig q_configFromQPlatformWindowFormat(EGLDisplay display, const QPlatformWindowFormat &format, bool highestPixelFormat, int surfaceType)
struct wl_visual * argbVisual()
virtual void doneCurrent()
Reimplement in subclass to release current context.
The QPlatformWindowFormat class specifies the display format of an OpenGL rendering context and if po...
static QColor cmap[256]
Definition: qgl_mac.mm:760
QWaylandXCompositeEGLContext(QWaylandXCompositeEGLIntegration *glxIntegration, QWaylandXCompositeEGLWindow *window)
long ASN1_INTEGER_get ASN1_INTEGER * a
The QString class provides a Unicode character string.
Definition: qstring.h:83
void * getProcAddress(const QString &procName)
Reimplement in subclass to native getProcAddr calls.
NSWindow * window
static VisualID getCompatibleVisualId(Display *display, EGLDisplay eglDisplay, EGLConfig config)
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
void swapBuffers()
Reimplement in subclass to native swap buffers calls.
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
static const char * data(const QByteArray &arr)
QPlatformWindowFormat platformWindowFormat() const
QWidget has the function qplatformWindowFormat().
virtual void makeCurrent()
Reimplement in subclass to do makeCurrent on native GL context.
void doneCurrent()
Reimplement in subclass to release current context.
void attach(QWaylandBuffer *buffer)
Q_CORE_EXPORT void qFatal(const char *,...)
The QPlatformGLContext class provides an abstraction for native GL contexts.
QPlatformWindowFormat qt_qPlatformWindowFormatFromConfig(EGLDisplay display, const EGLConfig config)
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void makeCurrent()
Reimplement in subclass to do makeCurrent on native GL context.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154
void damage(const QRect &rect)
#define qPrintable(string)
Definition: qglobal.h:1750
QWaylandXCompositeEGLIntegration * mEglIntegration
struct wl_display * wl_display() const