plugins/screencast: Make grabTexture() more nicer to memfd code path

OutputTransform::Normal is handled by doGrabTexture().

If the texture transform is neither normal nor flip-y, the GPU is going
to be used to transform the texture, however since it doesn't flip the y
axis, doGrabTexture() will flip the y axis on the cpu side. To fix that,
make the contents of backingTexture mirrored vertically.
This commit is contained in:
Vlad Zahorodnii 2024-02-15 16:08:18 +02:00
parent af12a103ae
commit 7297e62283

View file

@ -83,23 +83,24 @@ static void doGrabTexture(GLTexture *texture, spa_data *spa, spa_video_format fo
static void grabTexture(GLTexture *texture, spa_data *spa, spa_video_format format)
{
// transform to correct orientation with the GPU first
const QSize size = texture->contentTransform().map(texture->size());
if (texture->contentTransform() == OutputTransform::FlipY) {
const OutputTransform contentTransform = texture->contentTransform();
if (contentTransform == OutputTransform::Normal || contentTransform == OutputTransform::FlipY) {
doGrabTexture(texture, spa, format);
} else {
// need to transform the texture to a usable transformation first
const QSize size = contentTransform.map(texture->size());
const auto backingTexture = GLTexture::allocate(GL_RGBA8, size);
if (!backingTexture) {
return;
}
GLFramebuffer fbo(backingTexture.get());
backingTexture->setContentTransform(OutputTransform::FlipY);
ShaderBinder shaderBinder(ShaderTrait::MapTexture);
QMatrix4x4 projectionMatrix;
projectionMatrix.scale(1, -1);
projectionMatrix.ortho(QRect(QPoint(), size));
shaderBinder.shader()->setUniform(GLShader::Mat4Uniform::ModelViewProjectionMatrix, projectionMatrix);
GLFramebuffer fbo(backingTexture.get());
GLFramebuffer::pushFramebuffer(&fbo);
texture->render(size);
GLFramebuffer::popFramebuffer();