Qt 4.8
qwaylandxcompositeglxcontext.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 <X11/extensions/Xcomposite.h>
51 
54  , mGlxIntegration(glxIntegration)
55  , mWindow(window)
56  , mBuffer(0)
57  , mXWindow(0)
58  , mConfig(qglx_findConfig(glxIntegration->xDisplay(),glxIntegration->screen(),window->widget()->platformWindowFormat()))
59  , mWaitingForSyncCallback(false)
60 {
61  XVisualInfo *visualInfo = glXGetVisualFromFBConfig(glxIntegration->xDisplay(),mConfig);
62  mContext = glXCreateContext(glxIntegration->xDisplay(),visualInfo,0,TRUE);
63 
65 }
66 
68 {
70  glXMakeCurrent(mGlxIntegration->xDisplay(),mXWindow,mContext);
71 }
72 
74 {
75  glXMakeCurrent(mGlxIntegration->xDisplay(),0,0);
77 }
78 
80 {
81  QSize size = mWindow->geometry().size();
82 
83  glXSwapBuffers(mGlxIntegration->xDisplay(),mXWindow);
84  mWindow->damage(QRect(QPoint(0,0),size));
86 }
87 
89 {
90  return (void *) glXGetProcAddress(reinterpret_cast<GLubyte *>(procName.toLatin1().data()));
91 }
92 
94 {
96 }
97 
99 {
101  that->mWaitingForSyncCallback = false;
102 }
103 
105 {
106  wl_display_sync_callback(mGlxIntegration->waylandDisplay()->wl_display(),
108  this);
110  wl_display_sync(mGlxIntegration->waylandDisplay()->wl_display(),0);
112  while (mWaitingForSyncCallback) {
114  }
115 }
116 
118 {
119  QSize size(mWindow->geometry().size());
120  if (size.isEmpty()) {
121  //QGLWidget wants a context for a window without geometry
122  size = QSize(1,1);
123  }
124 
125  delete mBuffer;
126  //XFreePixmap deletes the glxPixmap as well
127  if (mXWindow) {
128  XDestroyWindow(mGlxIntegration->xDisplay(),mXWindow);
129  }
130 
131  XVisualInfo *visualInfo = glXGetVisualFromFBConfig(mGlxIntegration->xDisplay(),mConfig);
132  Colormap cmap = XCreateColormap(mGlxIntegration->xDisplay(),mGlxIntegration->rootWindow(),visualInfo->visual,AllocNone);
133 
134  XSetWindowAttributes a;
135  a.background_pixel = WhitePixel(mGlxIntegration->xDisplay(), mGlxIntegration->screen());
136  a.border_pixel = BlackPixel(mGlxIntegration->xDisplay(), mGlxIntegration->screen());
137  a.colormap = cmap;
138  mXWindow = XCreateWindow(mGlxIntegration->xDisplay(), mGlxIntegration->rootWindow(),0, 0, size.width(), size.height(),
139  0, visualInfo->depth, InputOutput, visualInfo->visual,
140  CWBackPixel|CWBorderPixel|CWColormap, &a);
141 
142  XCompositeRedirectWindow(mGlxIntegration->xDisplay(), mXWindow, CompositeRedirectManual);
143  XMapWindow(mGlxIntegration->xDisplay(), mXWindow);
144 
145  XSync(mGlxIntegration->xDisplay(),False);
147  (uint32_t)mXWindow,
148  size,
150  mWindow->attach(mBuffer);
151  waitForSync();
152 }
QPointer< QWidget > widget
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
QPlatformWindowFormat qglx_platformWindowFromGLXFBConfig(Display *display, GLXFBConfig config, GLXContext ctx)
void swapBuffers()
Reimplement in subclass to native swap buffers calls.
virtual QRect geometry() const
Returnes the current geometry of a window.
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
long ASN1_INTEGER_get ASN1_INTEGER * a
The QString class provides a Unicode character string.
Definition: qstring.h:83
void makeCurrent()
Reimplement in subclass to do makeCurrent on native GL context.
void doneCurrent()
Reimplement in subclass to release current context.
NSWindow * window
void * getProcAddress(const QString &procName)
Reimplement in subclass to native getProcAddr calls.
QPlatformWindowFormat platformWindowFormat() const
QWidget has the function qplatformWindowFormat().
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
struct wl_xcomposite * waylandXComposite() const
static const char * data(const QByteArray &arr)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
virtual void makeCurrent()
Reimplement in subclass to do makeCurrent on native GL context.
void attach(QWaylandBuffer *buffer)
QWaylandXCompositeGLXWindow * mWindow
GLXFBConfig qglx_findConfig(Display *display, int screen, const QPlatformWindowFormat &format, int drawableBit)
#define TRUE
Synonym for true.
Definition: qglobal.h:1018
The QPlatformGLContext class provides an abstraction for native GL contexts.
QWaylandXCompositeGLXIntegration * mGlxIntegration
QWaylandXCompositeGLXContext(QWaylandXCompositeGLXIntegration *glxIntegration, QWaylandXCompositeGLXWindow *window)
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
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void damage(const QRect &rect)
struct wl_display * wl_display() const