Require GLTexture::render() to provide an output scale

This ensures we render the texture at the right scale while providing
geometry information in logical coordinates.
This commit is contained in:
Arjen Hiemstra 2022-08-04 15:26:23 +02:00
parent 74ff3bf082
commit 6cfeb3e3e8
13 changed files with 31 additions and 24 deletions

View file

@ -517,7 +517,7 @@ void DrmOutput::renderCursorOpengl(const RenderTarget &renderTarget, const QSize
m_cursorTexture->bind();
ShaderBinder binder(ShaderTrait::MapTexture);
binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
m_cursorTexture->render(QRect(0, 0, cursorSize.width(), cursorSize.height()));
m_cursorTexture->render(QRect(0, 0, cursorSize.width(), cursorSize.height()), renderTarget.devicePixelRatio());
m_cursorTexture->unbind();
glDisable(GL_BLEND);
}

View file

@ -72,7 +72,7 @@ void CursorDelegateOpenGL::paint(RenderTarget *renderTarget, const QRegion &regi
m_cursorTexture->bind();
ShaderBinder binder(ShaderTrait::MapTexture);
binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
m_cursorTexture->render(region, QRect(0, 0, cursorRect.width(), cursorRect.height()));
m_cursorTexture->render(region, QRect(0, 0, cursorRect.width(), cursorRect.height()), renderTarget->devicePixelRatio());
m_cursorTexture->unbind();
glDisable(GL_BLEND);
}

View file

@ -119,6 +119,7 @@ void MagnifierEffect::paintScreen(int mask, const QRegion &region, ScreenPaintDa
// get the right area from the current rendered screen
const QRect area = magnifierArea();
const QPoint cursor = cursorPos();
const auto scale = effects->renderTargetScale();
QRect srcArea(cursor.x() - (double)area.width() / (m_zoom * 2),
cursor.y() - (double)area.height() / (m_zoom * 2),
@ -133,7 +134,7 @@ void MagnifierEffect::paintScreen(int mask, const QRegion &region, ScreenPaintDa
mvp.ortho(0, size.width(), size.height(), 0, 0, 65535);
mvp.translate(area.x(), area.y());
s->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
m_texture->render(area);
m_texture->render(area, scale);
ShaderManager::instance()->popShader();
m_texture->unbind();
QVector<float> verts;

View file

@ -83,10 +83,11 @@ void ScreenEdgeEffect::paintScreen(int mask, const QRegion &region, ScreenPaintD
ShaderBinder binder(ShaderTrait::MapTexture | ShaderTrait::Modulate);
const QVector4D constant(opacity, opacity, opacity, opacity);
binder.shader()->setUniform(GLShader::ModulationConstant, constant);
const auto scale = effects->renderTargetScale();
QMatrix4x4 mvp = data.projectionMatrix();
mvp.translate(glow->geometry.x(), glow->geometry.y());
binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
texture->render(glow->geometry);
texture->render(glow->geometry, scale);
texture->unbind();
glDisable(GL_BLEND);
} else if (effects->compositingType() == QPainterCompositing) {

View file

@ -222,10 +222,11 @@ void StartupFeedbackEffect::paintScreen(int mask, const QRegion &region, ScreenP
} else {
ShaderManager::instance()->pushShader(ShaderTrait::MapTexture);
}
const auto scale = effects->renderTargetScale();
QMatrix4x4 mvp = data.projectionMatrix();
mvp.translate(m_currentGeometry.x(), m_currentGeometry.y());
mvp.translate(m_currentGeometry.x() * scale, m_currentGeometry.y() * scale);
ShaderManager::instance()->getBoundShader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
texture->render(m_currentGeometry);
texture->render(m_currentGeometry, scale);
ShaderManager::instance()->popShader();
texture->unbind();
glDisable(GL_BLEND);

View file

@ -114,6 +114,7 @@ void TrackMouseEffect::paintScreen(int mask, const QRegion &region, ScreenPaintD
const QPointF p = m_lastRect[0].topLeft() + QPoint(m_lastRect[0].width() / 2.0, m_lastRect[0].height() / 2.0);
const float x = p.x();
const float y = p.y();
const auto scale = effects->renderTargetScale();
for (int i = 0; i < 2; ++i) {
matrix.translate(x, y, 0.0);
matrix.rotate(i ? -2 * m_angle : m_angle, 0, 0, 1.0);
@ -122,7 +123,7 @@ void TrackMouseEffect::paintScreen(int mask, const QRegion &region, ScreenPaintD
mvp.translate(m_lastRect[i].x(), m_lastRect[i].y());
shader->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
m_texture[i]->bind();
m_texture[i]->render(m_lastRect[i]);
m_texture[i]->render(m_lastRect[i], scale);
m_texture[i]->unbind();
}
glDisable(GL_BLEND);

View file

@ -414,7 +414,7 @@ void ZoomEffect::paintScreen(int mask, const QRegion &region, ScreenPaintData &d
QMatrix4x4 mvp = data.projectionMatrix();
mvp.translate(rect.x(), rect.y());
s->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
cursorTexture->render(rect);
cursorTexture->render(rect, effects->renderTargetScale());
ShaderManager::instance()->popShader();
cursorTexture->unbind();
glDisable(GL_BLEND);

View file

@ -506,20 +506,22 @@ void GLTexture::unbind()
glBindTexture(d->m_target, 0);
}
void GLTexture::render(const QRect &rect)
void GLTexture::render(const QRect &rect, qreal scale)
{
render(infiniteRegion(), rect, false);
render(infiniteRegion(), rect, scale, false);
}
void GLTexture::render(const QRegion &region, const QRect &rect, bool hardwareClipping)
void GLTexture::render(const QRegion &region, const QRect &rect, qreal scale, bool hardwareClipping)
{
Q_D(GLTexture);
if (rect.isEmpty()) {
return; // nothing to paint and m_vbo is likely nullptr and d->m_cachedSize empty as well, #337090
}
if (rect.size() != d->m_cachedSize) {
d->m_cachedSize = rect.size();
QRect r(rect);
QRect destinationRect = scaledRect(rect, scale).toRect();
if (destinationRect.size() != d->m_cachedSize) {
d->m_cachedSize = destinationRect.size();
QRect r(destinationRect);
r.moveTo(0, 0);
if (!d->m_vbo) {
d->m_vbo = std::make_unique<GLVertexBuffer>(KWin::GLVertexBuffer::Static);
@ -528,9 +530,9 @@ void GLTexture::render(const QRegion &region, const QRect &rect, bool hardwareCl
const float verts[4 * 2] = {
// NOTICE: r.x/y could be replaced by "0", but that would make it unreadable...
static_cast<float>(r.x()), static_cast<float>(r.y()),
static_cast<float>(r.x()), static_cast<float>(r.y() + rect.height()),
static_cast<float>(r.x() + rect.width()), static_cast<float>(r.y()),
static_cast<float>(r.x() + rect.width()), static_cast<float>(r.y() + rect.height())};
static_cast<float>(r.x()), static_cast<float>(r.y() + destinationRect.height()),
static_cast<float>(r.x() + destinationRect.width()), static_cast<float>(r.y()),
static_cast<float>(r.x() + destinationRect.width()), static_cast<float>(r.y() + destinationRect.height())};
const float texWidth = (target() == GL_TEXTURE_RECTANGLE_ARB) ? width() : 1.0f;
const float texHeight = (target() == GL_TEXTURE_RECTANGLE_ARB) ? height() : 1.0f;

View file

@ -102,8 +102,8 @@ public:
virtual void discard();
void bind();
void unbind();
void render(const QRect &rect);
void render(const QRegion &region, const QRect &rect, bool hardwareClipping = false);
void render(const QRect &rect, qreal scale);
void render(const QRegion &region, const QRect &rect, qreal scale, bool hardwareClipping = false);
GLuint texture() const;
GLenum target() const;

View file

@ -58,7 +58,7 @@ void OutputScreenCastSource::render(GLFramebuffer *target)
GLFramebuffer::pushFramebuffer(target);
outputTexture->bind();
outputTexture->render(geometry);
outputTexture->render(geometry, m_output->scale());
outputTexture->unbind();
GLFramebuffer::popFramebuffer();
}

View file

@ -45,6 +45,7 @@ void RegionScreenCastSource::updateOutput(Output *output)
if (m_renderedTexture) {
const std::shared_ptr<GLTexture> outputTexture = Compositor::self()->scene()->textureForOutput(output);
const auto outputGeometry = output->geometry();
const auto outputScale = output->scale();
if (!outputTexture || !m_region.intersects(output->geometry())) {
return;
}
@ -62,7 +63,7 @@ void RegionScreenCastSource::updateOutput(Output *output)
shaderBinder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, projectionMatrix);
outputTexture->bind();
outputTexture->render(output->geometry());
outputTexture->render(output->geometry(), outputScale);
outputTexture->unbind();
GLFramebuffer::popFramebuffer();
}
@ -95,7 +96,7 @@ void RegionScreenCastSource::render(GLFramebuffer *target)
shader->setUniform(GLShader::ModelViewProjectionMatrix, projectionMatrix);
m_renderedTexture->bind();
m_renderedTexture->render(r);
m_renderedTexture->render(r, m_scale);
m_renderedTexture->unbind();
ShaderManager::instance()->popShader();

View file

@ -484,7 +484,7 @@ void ScreenCastStream::recordFrame(const QRegion &_damagedRegion)
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
m_cursor.texture->render(cursorRect);
m_cursor.texture->render(cursorRect, m_cursor.scale);
glDisable(GL_BLEND);
m_cursor.texture->unbind();

View file

@ -141,7 +141,7 @@ void SceneOpenGL::paintOffscreenQuickView(OffscreenQuickView *w)
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
t->bind();
t->render(rect.toRect());
t->render(w->geometry(), renderTargetScale());
t->unbind();
glDisable(GL_BLEND);