1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the plugins of the Qt Toolkit.
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.
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.
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.
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.
40
****************************************************************************/
42
#include "qminimaleglscreen.h"
43
#include "qminimaleglwindow.h"
45
#include <QtPlatformSupport/private/qeglconvenience_p.h>
46
#include <QtPlatformSupport/private/qeglplatformcontext_p.h>
50
#include <KD/NV_initialize.h>
55
// #define QEGL_EXTRA_DEBUG
57
class QMinimalEglContext : public QEGLPlatformContext
60
QMinimalEglContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display,
61
EGLenum eglApi = EGL_OPENGL_ES_API)
62
: QEGLPlatformContext(format, share, display, eglApi)
66
EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface)
68
QMinimalEglWindow *window = static_cast<QMinimalEglWindow *>(surface);
69
QMinimalEglScreen *screen = static_cast<QMinimalEglScreen *>(window->screen());
70
return screen->surface();
74
QMinimalEglScreen::QMinimalEglScreen(EGLNativeDisplayType display)
76
, m_format(QImage::Format_Invalid)
77
, m_platformContext(0)
80
#ifdef QEGL_EXTRA_DEBUG
81
qWarning("QEglScreen %p\n", this);
86
if (!eglBindAPI(EGL_OPENGL_ES_API)) {
87
qWarning("Could not bind GL_ES API\n");
91
m_dpy = eglGetDisplay(display);
92
if (m_dpy == EGL_NO_DISPLAY) {
93
qWarning("Could not open egl display\n");
96
qWarning("Opened display %p\n", m_dpy);
98
if (!eglInitialize(m_dpy, &major, &minor)) {
99
qWarning("Could not initialize egl display\n");
103
qWarning("Initialized display %d %d\n", major, minor);
105
int swapInterval = 1;
106
QByteArray swapIntervalString = qgetenv("QT_QPA_EGLFS_SWAPINTERVAL");
107
if (!swapIntervalString.isEmpty()) {
109
swapInterval = swapIntervalString.toInt(&ok);
113
eglSwapInterval(m_dpy, swapInterval);
116
QMinimalEglScreen::~QMinimalEglScreen()
119
eglDestroySurface(m_dpy, m_surface);
124
void QMinimalEglScreen::createAndSetPlatformContext() const {
125
const_cast<QMinimalEglScreen *>(this)->createAndSetPlatformContext();
128
void QMinimalEglScreen::createAndSetPlatformContext()
130
QSurfaceFormat platformFormat;
132
QByteArray depthString = qgetenv("QT_QPA_EGLFS_DEPTH");
133
if (depthString.toInt() == 16) {
134
platformFormat.setDepthBufferSize(16);
135
platformFormat.setRedBufferSize(5);
136
platformFormat.setGreenBufferSize(6);
137
platformFormat.setBlueBufferSize(5);
139
m_format = QImage::Format_RGB16;
141
platformFormat.setDepthBufferSize(24);
142
platformFormat.setStencilBufferSize(8);
143
platformFormat.setRedBufferSize(8);
144
platformFormat.setGreenBufferSize(8);
145
platformFormat.setBlueBufferSize(8);
147
m_format = QImage::Format_RGB32;
150
if (!qEnvironmentVariableIsEmpty("QT_QPA_EGLFS_MULTISAMPLE"))
151
platformFormat.setSamples(4);
153
EGLConfig config = q_configFromGLFormat(m_dpy, platformFormat);
155
EGLNativeWindowType eglWindow = 0;
157
if (kdInitializeNV() == KD_ENOTINITIALIZED) {
158
qFatal("Did not manage to initialize openkode");
160
KDWindow *window = kdCreateWindow(m_dpy,config,0);
162
kdRealizeWindow(window,&eglWindow);
165
#ifdef QEGL_EXTRA_DEBUG
166
q_printEglConfig(m_dpy, config);
169
m_surface = eglCreateWindowSurface(m_dpy, config, eglWindow, NULL);
170
if (m_surface == EGL_NO_SURFACE) {
171
qWarning("Could not create the egl surface: error = 0x%x\n", eglGetError());
175
// qWarning("Created surface %dx%d\n", w, h);
177
QEGLPlatformContext *platformContext = new QMinimalEglContext(platformFormat, 0, m_dpy);
178
m_platformContext = platformContext;
180
EGLint w,h; // screen size detection
181
eglQuerySurface(m_dpy, m_surface, EGL_WIDTH, &w);
182
eglQuerySurface(m_dpy, m_surface, EGL_HEIGHT, &h);
184
m_geometry = QRect(0,0,w,h);
188
QRect QMinimalEglScreen::geometry() const
190
if (m_geometry.isNull()) {
191
createAndSetPlatformContext();
196
int QMinimalEglScreen::depth() const
201
QImage::Format QMinimalEglScreen::format() const
203
if (m_format == QImage::Format_Invalid)
204
createAndSetPlatformContext();
207
QPlatformOpenGLContext *QMinimalEglScreen::platformContext() const
209
if (!m_platformContext) {
210
QMinimalEglScreen *that = const_cast<QMinimalEglScreen *>(this);
211
that->createAndSetPlatformContext();
213
return m_platformContext;