|
| 1 | +// SPDX-FileCopyrightText: 2023 Pier Luigi Fiorini <[email protected]> |
| 2 | +// SPDX-License-Identifier: GPL-3.0-or-later |
| 3 | + |
| 4 | +#include "eglfscategories.h" |
| 5 | +#include "eglfsinfo.h" |
| 6 | + |
| 7 | +#include <GLES2/gl2.h> |
| 8 | +#include <EGL/egl.h> |
| 9 | + |
| 10 | +const char *tab = " "; |
| 11 | + |
| 12 | +static void logGLextensions(const char *prefix, const QList<QByteArray> &extensions) |
| 13 | +{ |
| 14 | + QString extensionString; |
| 15 | + const int maxLineLength = 98; |
| 16 | + int currentLineLength = 0; |
| 17 | + |
| 18 | + for (int i = 0; i < extensions.size(); i++) { |
| 19 | + const auto extension = extensions[i]; |
| 20 | + |
| 21 | + // Check if adding the current extension fits in the current line |
| 22 | + if (currentLineLength + extension.length() + 2 <= maxLineLength) { // 2 accounts for " " |
| 23 | + if (!extensionString.isEmpty()) { |
| 24 | + extensionString += QStringLiteral(" "); |
| 25 | + currentLineLength += 2; |
| 26 | + } |
| 27 | + extensionString += QString::fromUtf8(extension); |
| 28 | + currentLineLength += extension.length(); |
| 29 | + } else { |
| 30 | + extensionString += QStringLiteral("\n") + QString::fromUtf8(extension); |
| 31 | + currentLineLength = extension.length(); |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + if (!extensionString.isEmpty()) { |
| 36 | + const auto numSpaces = qMax<int>(0, 18 - strlen(prefix) - 1); |
| 37 | + auto lines = extensionString.split(QLatin1Char('\n')); |
| 38 | + |
| 39 | + for (int i = 0; i < lines.size(); i++) { |
| 40 | + const auto line = lines[i]; |
| 41 | + if (i == 0) |
| 42 | + qCInfo(gLcEglFS, "%s:%*s%s", prefix, numSpaces, " ", qPrintable(line)); |
| 43 | + else |
| 44 | + qCInfo(gLcEglFS, "%s%s", tab, qPrintable(line)); |
| 45 | + } |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +void logGLInfo() |
| 50 | +{ |
| 51 | + const char *str; |
| 52 | + |
| 53 | + str = reinterpret_cast<const char *>(glGetString(GL_VERSION)); |
| 54 | + qCInfo(gLcEglFS, "GL version: %s", str ? str : "(null)"); |
| 55 | + |
| 56 | + str = reinterpret_cast<const char *>(glGetString(GL_SHADING_LANGUAGE_VERSION)); |
| 57 | + qCInfo(gLcEglFS, "GLSL version: %s", str ? str : "(null)"); |
| 58 | + |
| 59 | + str = reinterpret_cast<const char *>(glGetString(GL_VENDOR)); |
| 60 | + qCInfo(gLcEglFS, "GL vendor: %s", str ? str : "(null)"); |
| 61 | + |
| 62 | + str = reinterpret_cast<const char *>(glGetString(GL_RENDERER)); |
| 63 | + qCInfo(gLcEglFS, "GL renderer: %s", str ? str : "(null)"); |
| 64 | + |
| 65 | + QList<QByteArray> extensions = |
| 66 | + QByteArray(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS))).split(' '); |
| 67 | + logGLextensions("GL extensions", extensions); |
| 68 | +} |
| 69 | + |
| 70 | +void logEGLInfo(EGLDisplay display) |
| 71 | +{ |
| 72 | + const char *str; |
| 73 | + |
| 74 | + str = eglQueryString(display, EGL_VERSION); |
| 75 | + qCInfo(gLcEglFS, "EGL version: %s", str ? str : "(null)"); |
| 76 | + |
| 77 | + str = eglQueryString(display, EGL_VENDOR); |
| 78 | + qCInfo(gLcEglFS, "EGL vendor: %s", str ? str : "(null)"); |
| 79 | + |
| 80 | + str = eglQueryString(display, EGL_CLIENT_APIS); |
| 81 | + qCInfo(gLcEglFS, "EGL client APIs: %s", str ? str : "(null)"); |
| 82 | + |
| 83 | + QList<QByteArray> extensions = QByteArray(eglQueryString(display, EGL_EXTENSIONS)).split(' '); |
| 84 | + logGLextensions("EGL extensions", extensions); |
| 85 | +} |
| 86 | + |
| 87 | +void logEGLConfigInfo(EGLDisplay display, EGLConfig config) |
| 88 | +{ |
| 89 | + if (!config) |
| 90 | + return; |
| 91 | + |
| 92 | + EGLint r, g, b, a; |
| 93 | + |
| 94 | + qCInfo(gLcEglFS, "EGL attributes:"); |
| 95 | + |
| 96 | + if (eglGetConfigAttrib(display, config, EGL_RED_SIZE, &r) |
| 97 | + && eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &g) |
| 98 | + && eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &b) |
| 99 | + && eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &a)) |
| 100 | + qCInfo(gLcEglFS, "%sRGBA bits: %d %d %d %d", tab, r, g, b, a); |
| 101 | + else |
| 102 | + qCInfo(gLcEglFS, "%sRGBA bits: unknown", tab); |
| 103 | + |
| 104 | + if (eglGetConfigAttrib(display, config, EGL_MIN_SWAP_INTERVAL, &a) |
| 105 | + && eglGetConfigAttrib(display, config, EGL_MAX_SWAP_INTERVAL, &b)) |
| 106 | + qCInfo(gLcEglFS, "%sSwap interval range: %d - %d", tab, a, b); |
| 107 | + else |
| 108 | + qCInfo(gLcEglFS, "%sSwap interval range: unknown", tab); |
| 109 | +} |
0 commit comments