| 1 |
// Copyright (C) 2017 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 |
|
| 4 |
#include "qeglfskmsgbmwindow_p.h" |
| 5 |
#include "qeglfskmsgbmintegration_p.h" |
| 6 |
#include "qeglfskmsgbmscreen_p.h" |
| 7 |
|
| 8 |
#include <QtGui/private/qeglconvenience_p.h> |
| 9 |
|
| 10 |
QT_BEGIN_NAMESPACE |
| 11 |
|
| 12 |
#ifndef EGL_EXT_platform_base |
| 13 |
typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC) (EGLDisplay dpy, EGLConfig config, void *native_window, const EGLint *attrib_list); |
| 14 |
#endif |
| 15 |
|
| 16 |
void QEglFSKmsGbmWindow::resetSurface() |
| 17 |
{ |
| 18 |
QEglFSKmsGbmScreen *gbmScreen = static_cast<QEglFSKmsGbmScreen *>(screen()); |
| 19 |
EGLDisplay display = gbmScreen->display(); |
| 20 |
QSurfaceFormat platformFormat = m_integration->surfaceFormatFor(window()->requestedFormat()); |
| 21 |
m_config = QEglFSDeviceIntegration::chooseConfig(display, platformFormat); |
| 22 |
m_format = q_glFormatFromConfig(display, m_config, platformFormat); |
| 23 |
// One fullscreen window per screen -> the native window is simply the gbm_surface the screen created. |
| 24 |
m_window = reinterpret_cast<EGLNativeWindowType>(gbmScreen->createSurface(m_config)); |
| 25 |
|
| 26 |
PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC createPlatformWindowSurface = nullptr; |
| 27 |
const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); |
| 28 |
if (extensions && (strstr(extensions, "EGL_KHR_platform_gbm") || strstr(extensions, "EGL_MESA_platform_gbm"))) { |
| 29 |
createPlatformWindowSurface = reinterpret_cast<PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC>( |
| 30 |
eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT")); |
| 31 |
} |
| 32 |
|
| 33 |
if (createPlatformWindowSurface) { |
| 34 |
QVector<EGLint> contextAttributes; |
| 35 |
#ifdef EGL_EXT_protected_content |
| 36 |
if (platformFormat.testOption(QSurfaceFormat::ProtectedContent)) { |
| 37 |
if (q_hasEglExtension(display, "EGL_EXT_protected_content")) { |
| 38 |
contextAttributes.append(EGL_PROTECTED_CONTENT_EXT); |
| 39 |
contextAttributes.append(EGL_TRUE); |
| 40 |
qCDebug(qLcEglfsKmsDebug, "Enabled EGL_PROTECTED_CONTENT_EXT for eglCreatePlatformWindowSurfaceEXT"); |
| 41 |
} else { |
| 42 |
m_format.setOption(QSurfaceFormat::ProtectedContent, false); |
| 43 |
} |
| 44 |
} |
| 45 |
#endif |
| 46 |
contextAttributes.append(EGL_NONE); |
| 47 |
|
| 48 |
m_surface = createPlatformWindowSurface(display, m_config, reinterpret_cast<void *>(m_window), contextAttributes.constData()); |
| 49 |
} else { |
| 50 |
qCDebug(qLcEglfsKmsDebug, "No eglCreatePlatformWindowSurface for GBM, falling back to eglCreateWindowSurface"); |
| 51 |
m_surface = eglCreateWindowSurface(display, m_config, m_window, nullptr); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
void QEglFSKmsGbmWindow::invalidateSurface() |
| 56 |
{ |
| 57 |
QEglFSKmsGbmScreen *gbmScreen = static_cast<QEglFSKmsGbmScreen *>(screen()); |
| 58 |
QEglFSWindow::invalidateSurface(); |
| 59 |
gbmScreen->resetSurface(); |
| 60 |
} |
| 61 |
|
| 62 |
QT_END_NAMESPACE |