File indexing completed on 2025-02-09 06:35:13

0001 /*
0002     SPDX-FileCopyrightText: 2016 Rohan Garg <rohan@kde.org>
0003     SPDX-FileCopyrightText: 2020-2021 Harald Sitter <sitter@kde.org>
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "GPUEntry.h"
0008 
0009 #include <QDebug>
0010 #include <QOffscreenSurface>
0011 #include <QOpenGLContext>
0012 #include <QOpenGLFunctions>
0013 
0014 #include <KLocalizedString>
0015 
0016 #include "FancyString.h"
0017 
0018 GPUEntry::GPUEntry()
0019     : Entry(ki18n("Graphics Processor:"), QString())
0020 {
0021     QOpenGLContext context;
0022     QOffscreenSurface surface;
0023     surface.create();
0024     if (!context.create()) {
0025         qWarning() << "Failed create QOpenGLContext";
0026         return;
0027     }
0028 
0029     if (context.makeCurrent(&surface)) {
0030         m_value = QString::fromUtf8(reinterpret_cast<const char *>(context.functions()->glGetString(GL_RENDERER)));
0031         m_value = FancyString::fromUgly(m_value);
0032         // It seems the renderer value may have excess information in parentheses ->
0033         // strip that. Elide would probably be nicer, a bit meh with QWidgets though.
0034         m_value = m_value.mid(0, m_value.indexOf('('));
0035         // Leads to trailing space in my case, don't know whether that is happening
0036         // everywhere, though. Thus removing trailing spaces separately.
0037         m_value = m_value.trimmed();
0038         context.doneCurrent();
0039     } else {
0040         qWarning() << "Failed to make QOpenGLContext current";
0041         return;
0042     }
0043 }