6#include <QtWaylandClient/private/qwaylanddisplay_p.h>
7#include <QtWaylandClient/private/qwaylandwindow_p.h>
8#include <QtWaylandClient/private/qwaylandsubsurface_p.h>
9#include <QtWaylandClient/private/qwaylandabstractdecoration_p.h>
10#include <QtWaylandClient/private/qwaylandintegration_p.h>
14#include <QtGui/private/qeglconvenience_p.h>
15#include <QtGui/private/qopenglcontext_p.h>
16#include <QtOpenGL/private/qopengltexturecache_p.h>
17#include <QtGui/private/qguiapplication_p.h>
19#include <qpa/qplatformopenglcontext.h>
20#include <QtGui/QSurfaceFormat>
21#include <QtOpenGL/QOpenGLShaderProgram>
22#include <QtGui/QOpenGLFunctions>
23#include <QOpenGLBuffer>
25#include <QtCore/qmutex.h>
30#ifndef EGL_CONTEXT_MINOR_VERSION_KHR
31#define EGL_CONTEXT_MINOR_VERSION_KHR 0x30FB
33#ifndef EGL_CONTEXT_FLAGS_KHR
34#define EGL_CONTEXT_FLAGS_KHR 0x30FC
36#ifndef EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR
37#define EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR 0x30FD
39#ifndef EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR
40#define EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR 0x00000001
42#ifndef EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR
43#define EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR 0x00000002
45#ifndef EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR
46#define EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR 0x00000001
48#ifndef EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR
49#define EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR 0x00000002
53#ifndef GL_CONTEXT_FLAGS
54#define GL_CONTEXT_FLAGS 0x821E
56#ifndef GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT
57#define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT 0x0001
59#ifndef GL_CONTEXT_FLAG_DEBUG_BIT
60#define GL_CONTEXT_FLAG_DEBUG_BIT 0x00000002
62#ifndef GL_CONTEXT_PROFILE_MASK
63#define GL_CONTEXT_PROFILE_MASK 0x9126
65#ifndef GL_CONTEXT_CORE_PROFILE_BIT
66#define GL_CONTEXT_CORE_PROFILE_BIT 0x00000001
68#ifndef GL_CONTEXT_COMPATIBILITY_PROFILE_BIT
69#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002
85 attribute vec4 texCoords;\n\
86 varying vec2 outTexCoords;\n\
89 gl_Position = position;\n\
90 outTexCoords = texCoords.xy;\n\
93 uniform sampler2D texture;\n\
96 gl_FragColor = texture2D(texture, outTexCoords);\n\
103 qDebug() <<
"Shader Program link failed.";
121 static const GLfloat squareVertices[] = {
127 static const GLfloat inverseSquareVertices[] = {
133 static const GLfloat textureVertices[] = {
144 m_buffer.
allocate(
sizeof(squareVertices) +
sizeof(inverseSquareVertices) +
sizeof(textureVertices));
204 m_api = EGL_OPENVG_API;
206#ifdef EGL_VERSION_1_4
208 m_api = EGL_OPENGL_API;
212 m_api = EGL_OPENGL_ES_API;
218 QList<EGLint> eglDecorationsContextAttrs = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
221 if (m_decorationsContext == EGL_NO_CONTEXT)
222 qWarning(
"QWaylandGLContext: Failed to create the decorations EGLContext. Decorations will not be drawn.");
224 EGLint
a = EGL_MIN_SWAP_INTERVAL;
225 EGLint
b = EGL_MAX_SWAP_INTERVAL;
228 m_supportNonBlockingSwap =
false;
234 m_supportNonBlockingSwap = supportNonBlockingSwap != 0;
236 if (!m_supportNonBlockingSwap) {
237 qWarning(lcQpaWayland) <<
"Non-blocking swap buffers not supported."
238 <<
"Subsurface rendering can be affected."
239 <<
"It may also cause the event loop to freeze in some situations";
246 m_eglWindow = wl_egl_window_create(m_wlSurface, 1, 1);
247#if QT_CONFIG(egl_extension_platform_wayland)
259 wl_egl_window_destroy(m_eglWindow);
260 m_eglWindow =
nullptr;
261 wl_surface_destroy(m_wlSurface);
262 m_wlSurface =
nullptr;
270 if (m_decorationsContext != EGL_NO_CONTEXT)
271 eglDestroyContext(
eglDisplay(), m_decorationsContext);
276 Q_ASSERT(m_currentWindow !=
nullptr);
282 Q_ASSERT(m_currentWindow !=
nullptr);
297 if (eglQueryAPI() != m_api) {
306 qWarning(
"QWaylandGLContext::makeCurrent: eglError: %#x, this: %p \n", eglGetError(),
this);
314 if (m_decorationsContext != EGL_NO_CONTEXT && !m_currentWindow->
decoration())
317 if (eglSurface == EGL_NO_SURFACE) {
323 qWarning(
"QWaylandGLContext::makeCurrent: eglError: %#x, this: %p \n", eglGetError(),
this);
338 eglMakeCurrent(
eglDisplay(), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
347 if (
window->decoration()) {
348 if (m_api != EGL_OPENGL_ES_API)
349 eglBindAPI(EGL_OPENGL_ES_API);
352 EGLDisplay currentDisplay = eglGetCurrentDisplay();
353 EGLContext currentContext = eglGetCurrentContext();
354 EGLSurface currentSurfaceDraw = eglGetCurrentSurface(EGL_DRAW);
355 EGLSurface currentSurfaceRead = eglGetCurrentSurface(EGL_READ);
356 eglMakeCurrent(
eglDisplay(), eglSurface, eglSurface, m_decorationsContext);
362 if (m_api != EGL_OPENGL_ES_API)
364 eglMakeCurrent(currentDisplay, currentSurfaceDraw, currentSurfaceRead, currentContext);
369 if (swapInterval == 0 &&
format().swapInterval() > 0) {
372 window->waitForFrameSync(100);
377 window->setCanResize(
true);
387 QFunctionPointer proc = (QFunctionPointer) eglGetProcAddress(procName);
389 proc = (QFunctionPointer) dlsym(RTLD_DEFAULT, procName);
An EGL context implementation.
EGLConfig eglConfig() const
EGLDisplay eglDisplay() const
QSurfaceFormat format() const override
EGLContext eglContext() const
virtual void invalidateContext() override
bool isValid() const override
const_pointer constData() const noexcept
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
The QOpenGLBuffer class provides functions for creating and managing OpenGL buffer objects.
bool bind()
Binds the buffer associated with this object to the current OpenGL context.
void write(int offset, const void *data, int count)
Replaces the count bytes of this buffer starting at offset with the contents of data.
bool create()
Creates the buffer object in the OpenGL server.
void allocate(const void *data, int count)
Allocates count bytes of space to the buffer, initialized to the contents of data.
static QOpenGLContext * setCurrentContext(QOpenGLContext *context)
QOpenGLFunctions * functions() const
Get the QOpenGLFunctions instance for this context.
The QOpenGLFunctions class provides cross-platform access to the OpenGL ES 2.0 API.
void glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
Convenience function that calls glViewport(x, y, width, height).
void glDrawArrays(GLenum mode, GLint first, GLsizei count)
Convenience function that calls glDrawArrays(mode, first, count).
void glTexParameteri(GLenum target, GLenum pname, GLint param)
Convenience function that calls glTexParameteri(target, pname, param).
void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
Convenience function that calls glColorMask(red, green, blue, alpha).
void glBindTexture(GLenum target, GLuint texture)
Convenience function that calls glBindTexture(target, texture).
void glDepthMask(GLboolean flag)
Convenience function that calls glDepthMask(flag).
void glDisable(GLenum cap)
Convenience function that calls glDisable(cap).
void initializeOpenGLFunctions()
Initializes OpenGL function resolution for the current context.
bool hasOpenGLFeature(QOpenGLFunctions::OpenGLFeature feature) const
Returns true if feature is present on this system's OpenGL implementation; false otherwise.
The QOpenGLShaderProgram class allows OpenGL shader programs to be linked and used.
void bindAttributeLocation(const char *name, int location)
Binds the attribute name to the specified location.
bool addShaderFromSourceCode(QOpenGLShader::ShaderType type, const char *source)
Compiles source as a shader of the specified type and adds it to this shader program.
void enableAttributeArray(int location)
Enables the vertex array at location in this shader program so that the value set by setAttributeArra...
virtual bool link()
Links together the shaders that were added to this program with addShader().
QString log() const
Returns the errors and warnings that occurred during the last link() or addShader() with explicitly s...
bool bind()
Binds this shader program to the active QOpenGLContext and makes it the current shader program.
void setAttributeBuffer(int location, GLenum type, int offset, int tupleSize, int stride=0)
Sets an array of vertex values on the attribute at location in this shader program,...
static QOpenGLTextureCache * cacheForContext(QOpenGLContext *context)
The QPlatformOpenGLContext class provides an abstraction for native GL contexts.
QOpenGLContext * context() const
\inmodule QtCore\reentrant
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
QWaylandGLContext * m_context
QOpenGLShaderProgram * m_blitProgram
int m_squareVerticesOffset
int m_textureVerticesOffset
int m_inverseSquareVerticesOffset
DecorationsBlitter(QWaylandGLContext *context)
void blit(QWaylandEglWindow *window)
struct wl_surface * createSurface(void *handle)
bool needToUpdateContentFBO() const
void updateSurface(bool create)
EGLSurface eglSurface() const
QFunctionPointer getProcAddress(const char *procName) override
Reimplement in subclass to allow dynamic querying of OpenGL symbols.
void swapBuffers(QPlatformSurface *surface) override
Reimplement in subclass to native swap buffers calls.
EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface) override
QWaylandGLContext(EGLDisplay eglDisplay, QWaylandDisplay *display, const QSurfaceFormat &format, QPlatformOpenGLContext *share)
EGLSurface createTemporaryOffscreenSurface() override
void endFrame() override
Called when the RHI ends rendering a in the context.
void beginFrame() override
Called when the RHI begins rendering a new frame in the context.
void destroyTemporaryOffscreenSurface(EGLSurface surface) override
void doneCurrent() override
GLuint defaultFramebufferObject(QPlatformSurface *surface) const override
Reimplement in subclass if your platform uses framebuffer objects for surfaces.
bool makeCurrent(QPlatformSurface *surface) override
QWaylandAbstractDecoration * decoration() const
bool isExposed() const override
Returns if this window is exposed in the windowing system.
void setCanResize(bool canResize)
QCache< int, Employee > cache
[0]
struct wl_display * display
Combined button and popup list for selecting options.
typedef EGLSurface(EGLAPIENTRYP PFNEGLCREATESTREAMPRODUCERSURFACEKHRPROC)(EGLDisplay dpy
typedef EGLDisplay(EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYEXTPROC)(EGLenum platform
GLboolean GLboolean GLboolean b
typedef GLfloat(GL_APIENTRYP PFNGLGETPATHLENGTHNVPROC)(GLuint path
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLenum GLenum GLenum GLenum scale
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
QVideoFrameFormat::PixelFormat fmt