1 | // Copyright (C) 2020 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 <QtGui/qoffscreensurface.h> |
5 | #include "qeglpbuffer_p.h" |
6 | #include "qeglconvenience_p.h" |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | /*! |
11 | \class QEGLPbuffer |
12 | \brief A pbuffer-based implementation of QPlatformOffscreenSurface for EGL. |
13 | \since 5.2 |
14 | \internal |
15 | \ingroup qpa |
16 | |
17 | To use this implementation in the platform plugin simply |
18 | reimplement QPlatformIntegration::createPlatformOffscreenSurface() |
19 | and return a new instance of this class. |
20 | */ |
21 | |
22 | QEGLPbuffer::QEGLPbuffer(EGLDisplay display, const QSurfaceFormat &format, QOffscreenSurface *offscreenSurface, |
23 | QEGLPlatformContext::Flags flags) |
24 | : QPlatformOffscreenSurface(offscreenSurface) |
25 | , m_format(format) |
26 | , m_display(display) |
27 | , m_pbuffer(EGL_NO_SURFACE) |
28 | { |
29 | m_hasSurfaceless = !flags.testFlag(flag: QEGLPlatformContext::NoSurfaceless) |
30 | && q_hasEglExtension(display, extensionName: "EGL_KHR_surfaceless_context" ); |
31 | |
32 | if (m_hasSurfaceless) |
33 | return; |
34 | |
35 | EGLConfig config = q_configFromGLFormat(display: m_display, format: m_format, highestPixelFormat: false, EGL_PBUFFER_BIT); |
36 | |
37 | if (config) { |
38 | const EGLint attributes[] = { |
39 | EGL_WIDTH, offscreenSurface->size().width(), |
40 | EGL_HEIGHT, offscreenSurface->size().height(), |
41 | EGL_LARGEST_PBUFFER, EGL_FALSE, |
42 | EGL_NONE |
43 | }; |
44 | |
45 | m_pbuffer = eglCreatePbufferSurface(dpy: m_display, config, attrib_list: attributes); |
46 | |
47 | if (m_pbuffer != EGL_NO_SURFACE) |
48 | m_format = q_glFormatFromConfig(display: m_display, config); |
49 | } |
50 | } |
51 | |
52 | QEGLPbuffer::~QEGLPbuffer() |
53 | { |
54 | if (m_pbuffer != EGL_NO_SURFACE) |
55 | eglDestroySurface(dpy: m_display, surface: m_pbuffer); |
56 | } |
57 | |
58 | bool QEGLPbuffer::isValid() const |
59 | { |
60 | return m_pbuffer != EGL_NO_SURFACE || m_hasSurfaceless; |
61 | } |
62 | |
63 | QT_END_NAMESPACE |
64 | |