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.
This commit is contained in:
Vlad Zahorodnii 2022-12-13 14:52:14 +02:00
parent 89613d8673
commit 77570c0667
2 changed files with 38 additions and 30 deletions

View file

@ -218,16 +218,18 @@ void WaylandOutput::renderCursorOpengl(WaylandEglBackend *backend, const QImage
glClearColor(0, 0, 0, 0); glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_BLEND); if (!image.isNull()) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GLTexture texture(image); GLTexture texture(image);
texture.bind(); texture.bind();
ShaderBinder binder(ShaderTrait::MapTexture); ShaderBinder binder(ShaderTrait::MapTexture);
binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp); binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
texture.render(cursorRect, beginInfo->renderTarget.devicePixelRatio()); texture.render(cursorRect, beginInfo->renderTarget.devicePixelRatio());
texture.unbind(); texture.unbind();
glDisable(GL_BLEND); glDisable(GL_BLEND);
}
cursorLayer->endFrame(infiniteRegion(), infiniteRegion()); cursorLayer->endFrame(infiniteRegion(), infiniteRegion());
} }
@ -250,12 +252,14 @@ void WaylandOutput::renderCursorQPainter(WaylandQPainterBackend *backend, const
c->setDevicePixelRatio(scale()); c->setDevicePixelRatio(scale());
c->fill(Qt::transparent); c->fill(Qt::transparent);
QPainter p; if (!image.isNull()) {
p.begin(c); QPainter p;
p.setWorldTransform(logicalToNativeMatrix(cursorRect, 1, transform()).toTransform()); p.begin(c);
p.setRenderHint(QPainter::SmoothPixmapTransform); p.setWorldTransform(logicalToNativeMatrix(cursorRect, 1, transform()).toTransform());
p.drawImage(QPoint(0, 0), image); p.setRenderHint(QPainter::SmoothPixmapTransform);
p.end(); p.drawImage(QPoint(0, 0), image);
p.end();
}
cursorLayer->endFrame(infiniteRegion(), infiniteRegion()); cursorLayer->endFrame(infiniteRegion(), infiniteRegion());
} }

View file

@ -318,16 +318,18 @@ void X11WindowedOutput::renderCursorOpengl(X11WindowedEglBackend *backend, const
glClearColor(0, 0, 0, 0); glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_BLEND); if (!image.isNull()) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GLTexture texture(image); GLTexture texture(image);
texture.bind(); texture.bind();
ShaderBinder binder(ShaderTrait::MapTexture); ShaderBinder binder(ShaderTrait::MapTexture);
binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp); binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
texture.render(cursorRect, beginInfo->renderTarget.devicePixelRatio()); texture.render(cursorRect, beginInfo->renderTarget.devicePixelRatio());
texture.unbind(); texture.unbind();
glDisable(GL_BLEND); glDisable(GL_BLEND);
}
cursorLayer->endFrame(infiniteRegion(), infiniteRegion()); cursorLayer->endFrame(infiniteRegion(), infiniteRegion());
} }
@ -349,12 +351,14 @@ void X11WindowedOutput::renderCursorQPainter(X11WindowedQPainterBackend *backend
c->setDevicePixelRatio(scale()); c->setDevicePixelRatio(scale());
c->fill(Qt::transparent); c->fill(Qt::transparent);
QPainter p; if (!image.isNull()) {
p.begin(c); QPainter p;
p.setWorldTransform(logicalToNativeMatrix(cursorRect, 1, transform()).toTransform()); p.begin(c);
p.setRenderHint(QPainter::SmoothPixmapTransform); p.setWorldTransform(logicalToNativeMatrix(cursorRect, 1, transform()).toTransform());
p.drawImage(QPoint(0, 0), image); p.setRenderHint(QPainter::SmoothPixmapTransform);
p.end(); p.drawImage(QPoint(0, 0), image);
p.end();
}
cursorLayer->endFrame(infiniteRegion(), infiniteRegion()); cursorLayer->endFrame(infiniteRegion(), infiniteRegion());
} }