From 77570c0667e5b70d77b2e38133a8cbd59b43e6cf Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 13 Dec 2022 14:52:14 +0200 Subject: [PATCH] backends/{x11,wayland}: Avoid painting null cursor image GLTexture(QImage()) may construct an invalid texture, which is going to make GLTexture::bind() and other requests fail. --- src/backends/wayland/wayland_output.cpp | 34 +++++++++++-------- .../x11/windowed/x11_windowed_output.cpp | 34 +++++++++++-------- 2 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/backends/wayland/wayland_output.cpp b/src/backends/wayland/wayland_output.cpp index 302dc36315..57f06ea201 100644 --- a/src/backends/wayland/wayland_output.cpp +++ b/src/backends/wayland/wayland_output.cpp @@ -218,16 +218,18 @@ void WaylandOutput::renderCursorOpengl(WaylandEglBackend *backend, const QImage glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + if (!image.isNull()) { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - GLTexture texture(image); - texture.bind(); - ShaderBinder binder(ShaderTrait::MapTexture); - binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp); - texture.render(cursorRect, beginInfo->renderTarget.devicePixelRatio()); - texture.unbind(); - glDisable(GL_BLEND); + GLTexture texture(image); + texture.bind(); + ShaderBinder binder(ShaderTrait::MapTexture); + binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp); + texture.render(cursorRect, beginInfo->renderTarget.devicePixelRatio()); + texture.unbind(); + glDisable(GL_BLEND); + } cursorLayer->endFrame(infiniteRegion(), infiniteRegion()); } @@ -250,12 +252,14 @@ void WaylandOutput::renderCursorQPainter(WaylandQPainterBackend *backend, const c->setDevicePixelRatio(scale()); c->fill(Qt::transparent); - QPainter p; - p.begin(c); - p.setWorldTransform(logicalToNativeMatrix(cursorRect, 1, transform()).toTransform()); - p.setRenderHint(QPainter::SmoothPixmapTransform); - p.drawImage(QPoint(0, 0), image); - p.end(); + if (!image.isNull()) { + QPainter p; + p.begin(c); + p.setWorldTransform(logicalToNativeMatrix(cursorRect, 1, transform()).toTransform()); + p.setRenderHint(QPainter::SmoothPixmapTransform); + p.drawImage(QPoint(0, 0), image); + p.end(); + } cursorLayer->endFrame(infiniteRegion(), infiniteRegion()); } diff --git a/src/backends/x11/windowed/x11_windowed_output.cpp b/src/backends/x11/windowed/x11_windowed_output.cpp index d0568e7e02..44cdb98646 100644 --- a/src/backends/x11/windowed/x11_windowed_output.cpp +++ b/src/backends/x11/windowed/x11_windowed_output.cpp @@ -318,16 +318,18 @@ void X11WindowedOutput::renderCursorOpengl(X11WindowedEglBackend *backend, const glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + if (!image.isNull()) { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - GLTexture texture(image); - texture.bind(); - ShaderBinder binder(ShaderTrait::MapTexture); - binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp); - texture.render(cursorRect, beginInfo->renderTarget.devicePixelRatio()); - texture.unbind(); - glDisable(GL_BLEND); + GLTexture texture(image); + texture.bind(); + ShaderBinder binder(ShaderTrait::MapTexture); + binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp); + texture.render(cursorRect, beginInfo->renderTarget.devicePixelRatio()); + texture.unbind(); + glDisable(GL_BLEND); + } cursorLayer->endFrame(infiniteRegion(), infiniteRegion()); } @@ -349,12 +351,14 @@ void X11WindowedOutput::renderCursorQPainter(X11WindowedQPainterBackend *backend c->setDevicePixelRatio(scale()); c->fill(Qt::transparent); - QPainter p; - p.begin(c); - p.setWorldTransform(logicalToNativeMatrix(cursorRect, 1, transform()).toTransform()); - p.setRenderHint(QPainter::SmoothPixmapTransform); - p.drawImage(QPoint(0, 0), image); - p.end(); + if (!image.isNull()) { + QPainter p; + p.begin(c); + p.setWorldTransform(logicalToNativeMatrix(cursorRect, 1, transform()).toTransform()); + p.setRenderHint(QPainter::SmoothPixmapTransform); + p.drawImage(QPoint(0, 0), image); + p.end(); + } cursorLayer->endFrame(infiniteRegion(), infiniteRegion()); }