5#include <QtCore/qbytearray.h>
6#include <QtGui/qopenglcontext.h>
12#include <QtGui/private/qmath_p.h>
16#ifndef EGL_OPENGL_ES3_BIT_KHR
17#define EGL_OPENGL_ES3_BIT_KHR 0x0040
24 int redSize =
format.redBufferSize();
25 int greenSize =
format.greenBufferSize();
26 int blueSize =
format.blueBufferSize();
27 int alphaSize =
format.alphaBufferSize();
28 int depthSize =
format.depthBufferSize();
29 int stencilSize =
format.stencilBufferSize();
30 int sampleCount =
format.samples();
56 configAttributes.
append(EGL_RED_SIZE);
57 configAttributes.
append(redSize > 0 ? redSize : 0);
59 configAttributes.
append(EGL_GREEN_SIZE);
60 configAttributes.
append(greenSize > 0 ? greenSize : 0);
62 configAttributes.
append(EGL_BLUE_SIZE);
63 configAttributes.
append(blueSize > 0 ? blueSize : 0);
65 configAttributes.
append(EGL_ALPHA_SIZE);
66 configAttributes.
append(alphaSize > 0 ? alphaSize : 0);
68 configAttributes.
append(EGL_SAMPLES);
69 configAttributes.
append(sampleCount > 0 ? sampleCount : 0);
71 configAttributes.
append(EGL_SAMPLE_BUFFERS);
72 configAttributes.
append(sampleCount > 0);
75 configAttributes.
append(EGL_DEPTH_SIZE);
76 configAttributes.
append(depthSize > 0 ? depthSize : 0);
78 configAttributes.
append(EGL_STENCIL_SIZE);
79 configAttributes.
append(stencilSize > 0 ? stencilSize : 0);
82 configAttributes.
append(EGL_ALPHA_MASK_SIZE);
83 configAttributes.
append(8);
86 return configAttributes;
101#ifdef EGL_VG_ALPHA_FORMAT_PRE_BIT
105 i = configAttributes->
indexOf(EGL_SURFACE_TYPE);
107 EGLint surfaceType = configAttributes->
at(
i +1);
108 if (surfaceType & EGL_VG_ALPHA_FORMAT_PRE_BIT) {
109 surfaceType ^= EGL_VG_ALPHA_FORMAT_PRE_BIT;
110 configAttributes->
replace(
i+1,surfaceType);
121 i = configAttributes->
indexOf(EGL_BUFFER_SIZE);
123 if (configAttributes->
at(
i+1) == 16) {
129 i = configAttributes->
indexOf(EGL_SAMPLES);
135 configAttributes->
remove(
i, 2);
139 i = configAttributes->
indexOf(EGL_SAMPLE_BUFFERS);
145 i = configAttributes->
indexOf(EGL_DEPTH_SIZE);
147 if (configAttributes->
at(
i + 1) >= 32)
148 configAttributes->
replace(
i + 1, 24);
149 else if (configAttributes->
at(
i + 1) > 1)
150 configAttributes->
replace(
i + 1, 1);
152 configAttributes->
remove(
i, 2);
156 i = configAttributes->
indexOf(EGL_ALPHA_SIZE);
159#if defined(EGL_BIND_TO_TEXTURE_RGBA) && defined(EGL_BIND_TO_TEXTURE_RGB)
160 i = configAttributes->
indexOf(EGL_BIND_TO_TEXTURE_RGBA);
162 configAttributes->
replace(
i,EGL_BIND_TO_TEXTURE_RGB);
163 configAttributes->
replace(
i+1,
true);
170 i = configAttributes->
indexOf(EGL_STENCIL_SIZE);
172 if (configAttributes->
at(
i + 1) > 1)
173 configAttributes->
replace(
i + 1, 1);
175 configAttributes->
remove(
i, 2);
179#ifdef EGL_BIND_TO_TEXTURE_RGB
180 i = configAttributes->
indexOf(EGL_BIND_TO_TEXTURE_RGB);
192 , m_surfaceType(EGL_WINDOW_BIT)
208 configureAttributes.
append(EGL_SURFACE_TYPE);
211 configureAttributes.
append(EGL_RENDERABLE_TYPE);
212 bool needsES2Plus =
false;
215 configureAttributes.
append(EGL_OPENVG_BIT);
217#ifdef EGL_VERSION_1_4
221 const char *vendor = eglQueryString(
display(), EGL_VENDOR);
223 configureAttributes.
append(EGL_OPENGL_BIT);
230 configureAttributes.
append(EGL_OPENGL_BIT);
235 configureAttributes.
append(EGL_OPENGL_ES_BIT);
247 configureAttributes.
append(EGL_OPENGL_ES2_BIT);
249 configureAttributes.
append(EGL_NONE);
251 EGLConfig cfg =
nullptr;
255 if (!eglChooseConfig(
display(), configureAttributes.
constData(),
nullptr, 0, &matching) || !matching)
262 i = configureAttributes.
indexOf(EGL_GREEN_SIZE);
264 i = configureAttributes.
indexOf(EGL_BLUE_SIZE);
266 i = configureAttributes.
indexOf(EGL_ALPHA_SIZE);
271 EGLint(configs.
size()), &matching);
272 if (!cfg && matching > 0)
273 cfg = configs.
first();
282 for (
int i = 0;
i < configs.
size(); ++
i) {
284 return configs.
at(
i);
289 qWarning(
"Cannot find EGLConfig, returning null config");
333 EGLint greenSize = 0;
335 EGLint alphaSize = 0;
336 EGLint depthSize = 0;
337 EGLint stencilSize = 0;
338 EGLint sampleCount = 0;
339 EGLint renderableType = 0;
342 eglGetConfigAttrib(
display,
config, EGL_GREEN_SIZE, &greenSize);
343 eglGetConfigAttrib(
display,
config, EGL_BLUE_SIZE, &blueSize);
344 eglGetConfigAttrib(
display,
config, EGL_ALPHA_SIZE, &alphaSize);
345 eglGetConfigAttrib(
display,
config, EGL_DEPTH_SIZE, &depthSize);
346 eglGetConfigAttrib(
display,
config, EGL_STENCIL_SIZE, &stencilSize);
347 eglGetConfigAttrib(
display,
config, EGL_SAMPLES, &sampleCount);
348 eglGetConfigAttrib(
display,
config, EGL_RENDERABLE_TYPE, &renderableType);
352#ifdef EGL_VERSION_1_4
354 && (renderableType & EGL_OPENGL_BIT))
359 && !strstr(eglQueryString(
display, EGL_VENDOR),
"NVIDIA")
361 && (renderableType & EGL_OPENGL_BIT))
367 format.setRedBufferSize(redSize);
368 format.setGreenBufferSize(greenSize);
369 format.setBlueBufferSize(blueSize);
370 format.setAlphaBufferSize(alphaSize);
371 format.setDepthBufferSize(depthSize);
372 format.setStencilBufferSize(stencilSize);
373 format.setSamples(sampleCount);
390 return extensions.
contains(extensionName);
395 {EGL_BUFFER_SIZE,
"EGL_BUFFER_SIZE"},
396 {EGL_ALPHA_SIZE,
"EGL_ALPHA_SIZE"},
397 {EGL_BLUE_SIZE,
"EGL_BLUE_SIZE"},
398 {EGL_GREEN_SIZE,
"EGL_GREEN_SIZE"},
399 {EGL_RED_SIZE,
"EGL_RED_SIZE"},
400 {EGL_DEPTH_SIZE,
"EGL_DEPTH_SIZE"},
401 {EGL_STENCIL_SIZE,
"EGL_STENCIL_SIZE"},
402 {EGL_CONFIG_CAVEAT,
"EGL_CONFIG_CAVEAT"},
403 {EGL_CONFIG_ID,
"EGL_CONFIG_ID"},
404 {EGL_LEVEL,
"EGL_LEVEL"},
405 {EGL_MAX_PBUFFER_HEIGHT,
"EGL_MAX_PBUFFER_HEIGHT"},
406 {EGL_MAX_PBUFFER_PIXELS,
"EGL_MAX_PBUFFER_PIXELS"},
407 {EGL_MAX_PBUFFER_WIDTH,
"EGL_MAX_PBUFFER_WIDTH"},
408 {EGL_NATIVE_RENDERABLE,
"EGL_NATIVE_RENDERABLE"},
409 {EGL_NATIVE_VISUAL_ID,
"EGL_NATIVE_VISUAL_ID"},
410 {EGL_NATIVE_VISUAL_TYPE,
"EGL_NATIVE_VISUAL_TYPE"},
411 {EGL_SAMPLES,
"EGL_SAMPLES"},
412 {EGL_SAMPLE_BUFFERS,
"EGL_SAMPLE_BUFFERS"},
413 {EGL_SURFACE_TYPE,
"EGL_SURFACE_TYPE"},
414 {EGL_TRANSPARENT_TYPE,
"EGL_TRANSPARENT_TYPE"},
415 {EGL_TRANSPARENT_BLUE_VALUE,
"EGL_TRANSPARENT_BLUE_VALUE"},
416 {EGL_TRANSPARENT_GREEN_VALUE,
"EGL_TRANSPARENT_GREEN_VALUE"},
417 {EGL_TRANSPARENT_RED_VALUE,
"EGL_TRANSPARENT_RED_VALUE"},
418 {EGL_BIND_TO_TEXTURE_RGB,
"EGL_BIND_TO_TEXTURE_RGB"},
419 {EGL_BIND_TO_TEXTURE_RGBA,
"EGL_BIND_TO_TEXTURE_RGBA"},
420 {EGL_MIN_SWAP_INTERVAL,
"EGL_MIN_SWAP_INTERVAL"},
421 {EGL_MAX_SWAP_INTERVAL,
"EGL_MAX_SWAP_INTERVAL"},
437QSizeF q_physicalScreenSizeFromFb(
int framebufferDevice,
const QSize &screenSize)
442 const int defaultPhysicalDpi = 100;
445 if (
size.isEmpty()) {
458 QSize screenResolution;
460 struct fb_var_screeninfo vinfo;
462 if (framebufferDevice != -1) {
463 if (ioctl(framebufferDevice, FBIOGET_VSCREENINFO, &vinfo) == -1) {
464 qWarning(
"eglconvenience: Could not query screen info");
468 screenResolution =
QSize(vinfo.xres, vinfo.yres);
475 screenResolution = screenSize.
isEmpty() ? q_screenSizeFromFb(framebufferDevice) : screenSize;
481 if (
w <= 0 ||
h <= 0)
482 qWarning(
"Unable to query physical screen size, defaulting to %d dpi.\n"
483 "To override, set QT_QPA_EGLFS_PHYSICAL_WIDTH "
484 "and QT_QPA_EGLFS_PHYSICAL_HEIGHT (in millimeters).", defaultPhysicalDpi);
490QSize q_screenSizeFromFb(
int framebufferDevice)
495 const int defaultWidth = 800;
496 const int defaultHeight = 600;
499 if (
size.isEmpty()) {
510 struct fb_var_screeninfo vinfo;
514 if (framebufferDevice != -1) {
515 if (ioctl(framebufferDevice, FBIOGET_VSCREENINFO, &vinfo) == -1) {
516 qWarning(
"eglconvenience: Could not read screen info");
523 size.setWidth(xres <= 0 ? defaultWidth : xres);
524 size.setHeight(yres <= 0 ? defaultHeight : yres);
526 size.setWidth(defaultWidth);
527 size.setHeight(defaultHeight);
534int q_screenDepthFromFb(
int framebufferDevice)
544 struct fb_var_screeninfo vinfo;
546 if (framebufferDevice != -1) {
547 if (ioctl(framebufferDevice, FBIOGET_VSCREENINFO, &vinfo) == -1)
548 qWarning(
"eglconvenience: Could not query screen info");
550 depth = vinfo.bits_per_pixel;
563qreal q_refreshRateFromFb(
int framebufferDevice)
573 if (framebufferDevice != -1) {
574 struct fb_var_screeninfo vinfo;
575 if (ioctl(framebufferDevice, FBIOGET_VSCREENINFO, &vinfo) != -1) {
576 const quint64 quot =
quint64(vinfo.left_margin + vinfo.right_margin + vinfo.xres + vinfo.hsync_len)
577 *
quint64(vinfo.upper_margin + vinfo.lower_margin + vinfo.yres + vinfo.vsync_len)
580 rate = 1000000000000LLU / quot;
582 qWarning(
"eglconvenience: Could not query screen info");
QList< QByteArray > split(char sep) const
Splits the byte array into subarrays wherever sep occurs, and returns the list of those arrays.
EGLDisplay display() const
void setSurfaceType(EGLint surfaceType)
virtual bool filterConfig(EGLConfig config) const
void setSurfaceFormat(const QSurfaceFormat &format)
void setIgnoreColorChannels(bool ignore)
virtual ~QEglConfigChooser()
EGLint surfaceType() const
QEglConfigChooser(EGLDisplay display)
qsizetype size() const noexcept
const_pointer constData() const noexcept
const_reference at(qsizetype i) const noexcept
T value(qsizetype i) const
void remove(qsizetype i, qsizetype n=1)
void replace(qsizetype i, parameter_type t)
void append(parameter_type t)
static OpenGLModuleType openGLModuleType()
Returns the underlying OpenGL implementation type.
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
constexpr void setWidth(int w) noexcept
Sets the width to the given width.
constexpr bool isEmpty() const noexcept
Returns true if either of the width and height is less than or equal to 0; otherwise returns false.
struct wl_display * display
Combined button and popup list for selecting options.
EGLConfig q_configFromGLFormat(EGLDisplay display, const QSurfaceFormat &format, bool highestPixelFormat, int surfaceType)
QSurfaceFormat q_glFormatFromConfig(EGLDisplay display, const EGLConfig config, const QSurfaceFormat &referenceFormat)
bool q_hasEglExtension(EGLDisplay display, const char *extensionName)
void q_printEglConfig(EGLDisplay display, EGLConfig config)
bool q_reduceConfigAttributes(QList< EGLint > *configAttributes)
QT_BEGIN_NAMESPACE QList< EGLint > q_createConfigAttributesFromFormat(const QSurfaceFormat &format)
#define EGL_OPENGL_ES3_BIT_KHR
static struct AttrInfo attrs[]
Q_GUI_EXPORT bool q_reduceConfigAttributes(QList< EGLint > *configAttributes)
Q_GUI_EXPORT bool q_hasEglExtension(EGLDisplay display, const char *extensionName)
QT_BEGIN_NAMESPACE Q_GUI_EXPORT QList< EGLint > q_createConfigAttributesFromFormat(const QSurfaceFormat &format)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
typedef EGLDisplay(EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYEXTPROC)(EGLenum platform
static const qreal Q_MM_PER_INCH
constexpr const T & qMin(const T &a, const T &b)
GLint GLenum GLsizei GLsizei GLsizei depth
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
GLfloat GLfloat GLfloat alpha
static int defaultDepth()
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
unsigned long long quint64
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
bool contains(const AT &t) const noexcept