Skip to content
Snippets Groups Projects
Commit 70d1d262 authored by Fatih Uzunoğlu's avatar Fatih Uzunoğlu Committed by Steve Lhomme
Browse files

qt: workaround for nvidia on xwayland

parent 235ba564
No related branches found
No related tags found
1 merge request!3788qt: xwayland workaround for garbage nvidia drivers
Pipeline #394598 passed with stage
in 40 minutes and 37 seconds
......@@ -21,7 +21,8 @@
#include <QQuickWindow>
#include <QQuickItem>
#include <QOffscreenSurface>
#include <QGuiApplication>
#include <QApplication>
#include <QThread>
#include "compositor_x11_uisurface.hpp"
#include "compositor_common.hpp"
......@@ -48,6 +49,13 @@ CompositorX11UISurface::CompositorX11UISurface(QWindow* window, QScreen* screen)
// UI is renderred on offscreen, no need for double bufferring
format.setSwapBehavior(QSurfaceFormat::SingleBuffer);
// Check if this is XWayland:
if (Q_UNLIKELY(QApplication::platformName() == QLatin1String("xcb") &&
qEnvironmentVariable("XDG_SESSION_TYPE") == QLatin1String("wayland")))
{
applyNvidiaWorkaround(format);
}
setFormat(format);
m_context = new QOpenGLContext();
......@@ -322,6 +330,33 @@ void CompositorX11UISurface::resizeFbo()
}
}
void CompositorX11UISurface::applyNvidiaWorkaround(QSurfaceFormat &format)
{
assert(QThread::currentThread() == qApp->thread());
QOffscreenSurface surface;
surface.setFormat(format);
surface.create();
QOpenGLContext ctx;
ctx.setFormat(format);
if (ctx.create() && ctx.makeCurrent(&surface))
{
// Context needs to be created to access the functions
if (QOpenGLFunctions * const func = ctx.functions())
{
if (const GLubyte* str = func->glGetString(GL_VENDOR))
{
if (!strcmp(reinterpret_cast<const char *>(str), "NVIDIA Corporation"))
{
// for some reason SingleBuffer is not supported:
format.setSwapBehavior(QSurfaceFormat::DefaultSwapBehavior);
}
}
}
}
}
void CompositorX11UISurface::resizeEvent(QResizeEvent *)
{
if (m_onscreenSize != size() * devicePixelRatio())
......
......@@ -90,6 +90,8 @@ protected:
void resizeFbo();
private:
static void applyNvidiaWorkaround(QSurfaceFormat& format);
QQuickItem* m_rootItem = nullptr;
QOpenGLContext *m_context = nullptr;
CompositorOffscreenWindow* m_uiWindow = nullptr;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment