Qt 4.8
qeglfsscreen.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 "qeglfsscreen.h"
43 
44 #include "../eglconvenience/qeglconvenience.h"
45 #include "../eglconvenience/qeglplatformcontext.h"
46 
47 #ifdef Q_OPENKODE
48 #include <KD/kd.h>
49 #include <KD/NV_initialize.h>
50 #endif //Q_OPENKODE
51 
53 
54 // #define QEGL_EXTRA_DEBUG
55 
56 #ifdef QEGL_EXTRA_DEBUG
57 struct AttrInfo { EGLint attr; const char *name; };
58 static struct AttrInfo attrs[] = {
59  {EGL_BUFFER_SIZE, "EGL_BUFFER_SIZE"},
60  {EGL_ALPHA_SIZE, "EGL_ALPHA_SIZE"},
61  {EGL_BLUE_SIZE, "EGL_BLUE_SIZE"},
62  {EGL_GREEN_SIZE, "EGL_GREEN_SIZE"},
63  {EGL_RED_SIZE, "EGL_RED_SIZE"},
64  {EGL_DEPTH_SIZE, "EGL_DEPTH_SIZE"},
65  {EGL_STENCIL_SIZE, "EGL_STENCIL_SIZE"},
66  {EGL_CONFIG_CAVEAT, "EGL_CONFIG_CAVEAT"},
67  {EGL_CONFIG_ID, "EGL_CONFIG_ID"},
68  {EGL_LEVEL, "EGL_LEVEL"},
69  {EGL_MAX_PBUFFER_HEIGHT, "EGL_MAX_PBUFFER_HEIGHT"},
70  {EGL_MAX_PBUFFER_PIXELS, "EGL_MAX_PBUFFER_PIXELS"},
71  {EGL_MAX_PBUFFER_WIDTH, "EGL_MAX_PBUFFER_WIDTH"},
72  {EGL_NATIVE_RENDERABLE, "EGL_NATIVE_RENDERABLE"},
73  {EGL_NATIVE_VISUAL_ID, "EGL_NATIVE_VISUAL_ID"},
74  {EGL_NATIVE_VISUAL_TYPE, "EGL_NATIVE_VISUAL_TYPE"},
75  {EGL_SAMPLES, "EGL_SAMPLES"},
76  {EGL_SAMPLE_BUFFERS, "EGL_SAMPLE_BUFFERS"},
77  {EGL_SURFACE_TYPE, "EGL_SURFACE_TYPE"},
78  {EGL_TRANSPARENT_TYPE, "EGL_TRANSPARENT_TYPE"},
79  {EGL_TRANSPARENT_BLUE_VALUE, "EGL_TRANSPARENT_BLUE_VALUE"},
80  {EGL_TRANSPARENT_GREEN_VALUE, "EGL_TRANSPARENT_GREEN_VALUE"},
81  {EGL_TRANSPARENT_RED_VALUE, "EGL_TRANSPARENT_RED_VALUE"},
82  {EGL_BIND_TO_TEXTURE_RGB, "EGL_BIND_TO_TEXTURE_RGB"},
83  {EGL_BIND_TO_TEXTURE_RGBA, "EGL_BIND_TO_TEXTURE_RGBA"},
84  {EGL_MIN_SWAP_INTERVAL, "EGL_MIN_SWAP_INTERVAL"},
85  {EGL_MAX_SWAP_INTERVAL, "EGL_MAX_SWAP_INTERVAL"},
86  {-1, 0}};
87 #endif //QEGL_EXTRA_DEBUG
88 
90  : m_depth(32)
91  , m_format(QImage::Format_Invalid)
92  , m_platformContext(0)
93  , m_surface(0)
94 {
95 #ifdef QEGL_EXTRA_DEBUG
96  qWarning("QEglScreen %p\n", this);
97 #endif
98 
99  EGLint major, minor;
100 #ifdef QEGL_EXTRA_DEBUG
101  EGLint index;
102 #endif
103  if (!eglBindAPI(EGL_OPENGL_ES_API)) {
104  qWarning("Could not bind GL_ES API\n");
105  qFatal("EGL error");
106  }
107 
108  m_dpy = eglGetDisplay(display);
109  if (m_dpy == EGL_NO_DISPLAY) {
110  qWarning("Could not open egl display\n");
111  qFatal("EGL error");
112  }
113  qWarning("Opened display %p\n", m_dpy);
114 
115  if (!eglInitialize(m_dpy, &major, &minor)) {
116  qWarning("Could not initialize egl display\n");
117  qFatal("EGL error");
118  }
119 
120  qWarning("Initialized display %d %d\n", major, minor);
121 
122  int swapInterval = 1;
123  QByteArray swapIntervalString = qgetenv("QT_QPA_EGLFS_SWAPINTERVAL");
124  if (!swapIntervalString.isEmpty()) {
125  bool ok;
126  swapInterval = swapIntervalString.toInt(&ok);
127  if (!ok)
128  swapInterval = 1;
129  }
130  eglSwapInterval(m_dpy, swapInterval);
131 }
132 
134  const_cast<QEglFSScreen *>(this)->createAndSetPlatformContext();
135 }
136 
138 {
140 
142 
143  QByteArray depthString = qgetenv("QT_QPA_EGLFS_DEPTH");
144  if (depthString.toInt() == 16) {
145  platformFormat.setDepth(16);
146  platformFormat.setRedBufferSize(5);
147  platformFormat.setGreenBufferSize(6);
148  platformFormat.setBlueBufferSize(5);
149  m_depth = 16;
151  } else {
152  platformFormat.setDepth(32);
153  platformFormat.setRedBufferSize(8);
154  platformFormat.setGreenBufferSize(8);
155  platformFormat.setBlueBufferSize(8);
156  m_depth = 32;
158  }
159  if (!qgetenv("QT_QPA_EGLFS_MULTISAMPLE").isEmpty()) {
160  platformFormat.setSampleBuffers(true);
161  }
162 
163 
164  EGLConfig config = q_configFromQPlatformWindowFormat(m_dpy, platformFormat);
165 
166  EGLNativeWindowType eglWindow = 0;
167 #ifdef Q_OPENKODE
168  if (kdInitializeNV() == KD_ENOTINITIALIZED) {
169  qFatal("Did not manage to initialize openkode");
170  }
171  KDWindow *window = kdCreateWindow(m_dpy,config,0);
172 
173  kdRealizeWindow(window,&eglWindow);
174 #endif
175 
176  m_surface = eglCreateWindowSurface(m_dpy, config, eglWindow, NULL);
177  if (m_surface == EGL_NO_SURFACE) {
178  qWarning("Could not create the egl surface: error = 0x%x\n", eglGetError());
179  eglTerminate(m_dpy);
180  qFatal("EGL error");
181  }
182  // qWarning("Created surface %dx%d\n", w, h);
183 
184 #ifdef QEGL_EXTRA_DEBUG
185  qWarning("Configuration %d matches requirements\n", (int)config);
186 
187  for (index = 0; attrs[index].attr != -1; ++index) {
188  EGLint value;
189  if (eglGetConfigAttrib(m_dpy, config, attrs[index].attr, &value)) {
190  qWarning("\t%s: %d\n", attrs[index].name, (int)value);
191  }
192  }
193  qWarning("\n");
194 #endif
195 
196  EGLint temp;
197  EGLint attribList[32];
198 
199  temp = 0;
200 
201  attribList[temp++] = EGL_CONTEXT_CLIENT_VERSION;
202  attribList[temp++] = 2; // GLES version 2
203  attribList[temp++] = EGL_NONE;
204 
205  QEGLPlatformContext *platformContext = new QEGLPlatformContext(m_dpy,config,attribList,m_surface,EGL_OPENGL_ES_API);
207 
208  EGLint w,h; // screen size detection
209  eglQuerySurface(m_dpy, m_surface, EGL_WIDTH, &w);
210  eglQuerySurface(m_dpy, m_surface, EGL_HEIGHT, &h);
211 
212  m_geometry = QRect(0,0,w,h);
213 
214 }
215 
217 {
218  if (m_geometry.isNull()) {
220  }
221  return m_geometry;
222 }
223 
225 {
226  return m_depth;
227 }
228 
230 {
233  return m_format;
234 }
236 {
237  if (!m_platformContext) {
238  QEglFSScreen *that = const_cast<QEglFSScreen *>(this);
240  }
241  return m_platformContext;
242 }
243 
Format
The following image formats are available in Qt.
Definition: qimage.h:91
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:231
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
EGLConfig q_configFromQPlatformWindowFormat(EGLDisplay display, const QPlatformWindowFormat &format, bool highestPixelFormat, int surfaceType)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static QPlatformWindowFormat defaultFormat()
Returns the default QPlatformWindowFormat for the application.
int depth() const
Reimplement in subclass to return current depth of the screen.
The QPlatformWindowFormat class specifies the display format of an OpenGL rendering context and if po...
void setBlueBufferSize(int size)
Set the preferred blue buffer size to size.
QImage::Format m_format
Definition: qeglfsscreen.h:73
QPlatformGLContext * m_platformContext
Definition: qeglfsscreen.h:74
NativeWindowType EGLNativeWindowType
Definition: qegl_p.h:116
NSWindow * window
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
static bool isEmpty(const char *str)
const char * name
Q_CORE_EXPORT void qWarning(const char *,...)
QRect m_geometry
Definition: qeglfsscreen.h:71
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
void createAndSetPlatformContext() const
EGLDisplay m_dpy
Definition: qeglfsscreen.h:75
EGLSurface m_surface
Definition: qeglfsscreen.h:76
Q_CORE_EXPORT void qFatal(const char *,...)
The QPlatformGLContext class provides an abstraction for native GL contexts.
int toInt(bool *ok=0, int base=10) const
Returns the byte array converted to an int using base base, which is 10 by default and must be betwee...
void setSampleBuffers(bool enable)
If enable is true, a GL context with multisample buffer support is picked; otherwise ignored...
void setWindowApi(QPlatformWindowFormat::WindowApi api)
QPlatformGLContext * platformContext() const
QImage::Format format() const
Reimplement in subclass to return the image format which corresponds to the screen format...
QRect geometry() const
Reimplement in subclass to return the pixel geometry of the screen.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void setRedBufferSize(int size)
Set the preferred red buffer size to size.
quint16 index
NativeDisplayType EGLNativeDisplayType
Definition: qegl_p.h:118
QEglFSScreen(EGLNativeDisplayType display)
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
void setGreenBufferSize(int size)
Set the preferred green buffer size to size.
void setDepth(bool enable)
If enable is true enables the depth buffer; otherwise disables the depth buffer.