Qt 4.8
qwaylandglcontext.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 
42 #include "qwaylandglcontext.h"
43 
44 #include "qwaylanddisplay.h"
45 #include "qwaylandwindow.h"
46 
47 #include "../../../eglconvenience/qeglconvenience.h"
48 
49 #include <QtGui/QPlatformGLContext>
50 #include <QtGui/QPlatformWindowFormat>
51 #include <QtCore/QMutex>
52 
55  , mEglDisplay(eglDisplay)
56  , mSurface(EGL_NO_SURFACE)
57  , mConfig(q_configFromQPlatformWindowFormat(mEglDisplay,format,true))
58  , mFormat(qt_qPlatformWindowFormatFromConfig(mEglDisplay,mConfig))
59 {
60  QPlatformGLContext *sharePlatformContext = 0;
61  sharePlatformContext = format.sharedGLContext();
62  mFormat.setSharedContext(sharePlatformContext);
63  EGLContext shareEGLContext = EGL_NO_CONTEXT;
64  if (sharePlatformContext)
65  shareEGLContext = static_cast<const QWaylandGLContext*>(sharePlatformContext)->mContext;
66 
67  eglBindAPI(EGL_OPENGL_ES_API);
68 
69  QVector<EGLint> eglContextAttrs;
70  eglContextAttrs.append(EGL_CONTEXT_CLIENT_VERSION);
71  eglContextAttrs.append(2);
72  eglContextAttrs.append(EGL_NONE);
73 
74  mContext = eglCreateContext(mEglDisplay, mConfig,
75  shareEGLContext, eglContextAttrs.constData());
76 }
77 
80  , mEglDisplay(0)
81  , mContext(EGL_NO_CONTEXT)
82  , mSurface(EGL_NO_SURFACE)
83  , mConfig(0)
84 { }
85 
87 {
88  eglDestroyContext(mEglDisplay,mContext);
89 }
90 
92 {
94  if (mSurface == EGL_NO_SURFACE) {
95  qWarning("makeCurrent with EGL_NO_SURFACE");
96  }
97  eglMakeCurrent(mEglDisplay, mSurface, mSurface, mContext);
98 }
99 
101 {
103  eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
104 }
105 
107 {
108  eglSwapBuffers(mEglDisplay,mSurface);
109 }
110 
112 {
113  return (void *) eglGetProcAddress(string.toLatin1().data());
114 }
115 
116 void QWaylandGLContext::setEglSurface(EGLSurface surface)
117 {
118  bool wasCurrent = false;
119  if (QPlatformGLContext::currentContext() == this) {
120  wasCurrent = true;
121  doneCurrent();
122  }
123  mSurface = surface;
124  if (wasCurrent) {
125  makeCurrent();
126  }
127 }
128 
130 {
131  return mConfig;
132 }
133 
static const QPlatformGLContext * currentContext()
Returns the last context which called makeCurrent.
void setSharedContext(QPlatformGLContext *context)
void * getProcAddress(const QString &)
Reimplement in subclass to native getProcAddr calls.
void makeCurrent()
Reimplement in subclass to do makeCurrent on native GL context.
EGLConfig q_configFromQPlatformWindowFormat(EGLDisplay display, const QPlatformWindowFormat &format, bool highestPixelFormat, int surfaceType)
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...
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setEglSurface(EGLSurface surface)
QPlatformGLContext * sharedGLContext() const
void swapBuffers()
Reimplement in subclass to native swap buffers calls.
QPlatformWindowFormat mFormat
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
virtual void makeCurrent()
Reimplement in subclass to do makeCurrent on native GL context.
EGLConfig eglConfig() const
The QPlatformGLContext class provides an abstraction for native GL contexts.
void doneCurrent()
Reimplement in subclass to release current context.
QPlatformWindowFormat qt_qPlatformWindowFormatFromConfig(EGLDisplay display, const EGLConfig config)
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154