1
// Copyright © 2012 Canonical Ltd
2
// FIXME(loicm) Add copyright notice here.
4
#include "qhybrisscreen.h"
5
#include "qhybriswindow.h"
6
#include <QtPlatformSupport/private/qeglconvenience_p.h>
7
#include <QtPlatformSupport/private/qeglplatformcontext_p.h>
11
class QHybrisContext : public QEGLPlatformContext {
13
QHybrisContext(const QSurfaceFormat& format, QPlatformOpenGLContext* share, EGLDisplay display,
14
EGLenum eglApi = EGL_OPENGL_ES_API)
15
: QEGLPlatformContext(format, share, display, eglApi) {
18
EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface* surface) {
19
QHybrisWindow* window = static_cast<QHybrisWindow*>(surface);
20
QHybrisScreen* screen = static_cast<QHybrisScreen*>(window->screen());
21
return screen->surface();
25
QHybrisScreen::QHybrisScreen(EGLNativeDisplayType display)
27
, m_format(QImage::Format_Invalid)
28
, m_platformContext(0)
31
qWarning("QEglScreen %p\n", this);
35
if (!eglBindAPI(EGL_OPENGL_ES_API)) {
36
qWarning("Could not bind GL_ES API\n");
40
m_dpy = eglGetDisplay(display);
41
if (m_dpy == EGL_NO_DISPLAY) {
42
qWarning("Could not open egl display\n");
45
qWarning("Opened display %p\n", m_dpy);
47
if (!eglInitialize(m_dpy, &major, &minor)) {
48
qWarning("Could not initialize egl display\n");
52
qWarning("Initialized display %d %d\n", major, minor);
55
QByteArray swapIntervalString = qgetenv("QT_QPA_EGLFS_SWAPINTERVAL");
56
if (!swapIntervalString.isEmpty()) {
58
swapInterval = swapIntervalString.toInt(&ok);
62
eglSwapInterval(m_dpy, swapInterval);
65
QHybrisScreen::~QHybrisScreen() {
67
eglDestroySurface(m_dpy, m_surface);
71
void QHybrisScreen::createAndSetPlatformContext() const {
72
const_cast<QHybrisScreen*>(this)->createAndSetPlatformContext();
75
void QHybrisScreen::createAndSetPlatformContext() {
76
QSurfaceFormat platformFormat;
78
QByteArray depthString = qgetenv("QT_QPA_EGLFS_DEPTH");
79
if (depthString.toInt() == 16) {
80
platformFormat.setDepthBufferSize(16);
81
platformFormat.setRedBufferSize(5);
82
platformFormat.setGreenBufferSize(6);
83
platformFormat.setBlueBufferSize(5);
85
m_format = QImage::Format_RGB16;
87
platformFormat.setDepthBufferSize(24);
88
platformFormat.setStencilBufferSize(8);
89
platformFormat.setRedBufferSize(8);
90
platformFormat.setGreenBufferSize(8);
91
platformFormat.setBlueBufferSize(8);
93
m_format = QImage::Format_RGB32;
96
if (!qEnvironmentVariableIsEmpty("QT_QPA_EGLFS_MULTISAMPLE"))
97
platformFormat.setSamples(4);
99
EGLConfig config = q_configFromGLFormat(m_dpy, platformFormat);
101
EGLNativeWindowType eglWindow = 0;
104
q_printEglConfig(m_dpy, config);
107
m_surface = eglCreateWindowSurface(m_dpy, config, eglWindow, NULL);
108
if (m_surface == EGL_NO_SURFACE) {
109
qWarning("Could not create the egl surface: error = 0x%x\n", eglGetError());
114
QEGLPlatformContext* platformContext = new QHybrisContext(platformFormat, 0, m_dpy);
115
m_platformContext = platformContext;
118
eglQuerySurface(m_dpy, m_surface, EGL_WIDTH, &w);
119
eglQuerySurface(m_dpy, m_surface, EGL_HEIGHT, &h);
121
m_geometry = QRect(0,0,w,h);
124
QRect QHybrisScreen::geometry() const {
125
if (m_geometry.isNull()) {
126
createAndSetPlatformContext();
131
int QHybrisScreen::depth() const {
135
QImage::Format QHybrisScreen::format() const {
136
if (m_format == QImage::Format_Invalid)
137
createAndSetPlatformContext();
141
QPlatformOpenGLContext *QHybrisScreen::platformContext() const {
142
if (!m_platformContext) {
143
QHybrisScreen* screen = const_cast<QHybrisScreen*>(this);
144
screen->createAndSetPlatformContext();
146
return m_platformContext;