From 9d353864a42c60cea90e931cf80766d1dd5e9a11 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Sun, 19 Feb 2023 01:04:22 +0100 Subject: [PATCH] kwinglutils: use QSizeF instead of QRect The method is ignoring the position of the rectangle, which is very unintuitive when using it --- src/cursordelegate_opengl.cpp | 2 +- src/effects.cpp | 2 +- src/effects/magnifier/magnifier.cpp | 2 +- src/effects/screenedge/screenedgeeffect.cpp | 2 +- .../startupfeedback/startupfeedback.cpp | 2 +- src/effects/trackmouse/trackmouse.cpp | 2 +- src/effects/zoom/zoom.cpp | 9 +++---- src/libkwineffects/kwingltexture.cpp | 25 ++++++++----------- src/libkwineffects/kwingltexture.h | 4 +-- src/libkwineffects/kwingltexture_p.h | 2 +- .../screencast/outputscreencastsource.cpp | 6 ++--- .../screencast/regionscreencastsource.cpp | 7 +++--- src/plugins/screencast/screencaststream.cpp | 2 +- 13 files changed, 30 insertions(+), 37 deletions(-) diff --git a/src/cursordelegate_opengl.cpp b/src/cursordelegate_opengl.cpp index 73e4b48a4d..392ce6df2d 100644 --- a/src/cursordelegate_opengl.cpp +++ b/src/cursordelegate_opengl.cpp @@ -61,7 +61,7 @@ void CursorDelegateOpenGL::paint(RenderTarget *renderTarget, const QRegion ®i m_texture->bind(); ShaderBinder binder(ShaderTrait::MapTexture); binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp); - m_texture->render(region, QRect(0, 0, cursorRect.width(), cursorRect.height()), scale); + m_texture->render(region, cursorRect.size(), scale); m_texture->unbind(); glDisable(GL_BLEND); diff --git a/src/effects.cpp b/src/effects.cpp index 23bf425a10..81f2df5b51 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -1767,7 +1767,7 @@ void EffectsHandlerImpl::renderOffscreenQuickView(OffscreenQuickView *w) const glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); t->bind(); - t->render(w->geometry(), m_scene->renderer()->renderTargetScale()); + t->render(w->size(), m_scene->renderer()->renderTargetScale()); t->unbind(); glDisable(GL_BLEND); diff --git a/src/effects/magnifier/magnifier.cpp b/src/effects/magnifier/magnifier.cpp index 906b9bb97b..7321534f46 100644 --- a/src/effects/magnifier/magnifier.cpp +++ b/src/effects/magnifier/magnifier.cpp @@ -131,7 +131,7 @@ void MagnifierEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintDa mvp.ortho(0, size.width() * scale, size.height() * scale, 0, 0, 65535); mvp.translate(area.x() * scale, area.y() * scale); s->setUniform(GLShader::ModelViewProjectionMatrix, mvp); - m_texture->render(area, scale); + m_texture->render(area.size(), scale); ShaderManager::instance()->popShader(); m_texture->unbind(); QVector verts; diff --git a/src/effects/screenedge/screenedgeeffect.cpp b/src/effects/screenedge/screenedgeeffect.cpp index a717d066d6..34ea9e2b66 100644 --- a/src/effects/screenedge/screenedgeeffect.cpp +++ b/src/effects/screenedge/screenedgeeffect.cpp @@ -87,7 +87,7 @@ void ScreenEdgeEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintD QMatrix4x4 mvp = data.projectionMatrix(); mvp.translate(glow->geometry.x() * scale, glow->geometry.y() * scale); binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp); - texture->render(glow->geometry, scale); + texture->render(glow->geometry.size(), scale); texture->unbind(); glDisable(GL_BLEND); } else if (effects->compositingType() == QPainterCompositing) { diff --git a/src/effects/startupfeedback/startupfeedback.cpp b/src/effects/startupfeedback/startupfeedback.cpp index e2f1cbab86..8138f91c19 100644 --- a/src/effects/startupfeedback/startupfeedback.cpp +++ b/src/effects/startupfeedback/startupfeedback.cpp @@ -224,7 +224,7 @@ void StartupFeedbackEffect::paintScreen(int mask, const QRegion ®ion, ScreenP QMatrix4x4 mvp = data.projectionMatrix(); mvp.translate(m_currentGeometry.x() * scale, m_currentGeometry.y() * scale); ShaderManager::instance()->getBoundShader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp); - texture->render(m_currentGeometry, scale); + texture->render(m_currentGeometry.size(), scale); ShaderManager::instance()->popShader(); texture->unbind(); glDisable(GL_BLEND); diff --git a/src/effects/trackmouse/trackmouse.cpp b/src/effects/trackmouse/trackmouse.cpp index 0bdd7fe73c..2e2d374f7e 100644 --- a/src/effects/trackmouse/trackmouse.cpp +++ b/src/effects/trackmouse/trackmouse.cpp @@ -122,7 +122,7 @@ void TrackMouseEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintD mvp.translate(m_lastRect[i].x() * scale, m_lastRect[i].y() * scale); shader->setUniform(GLShader::ModelViewProjectionMatrix, mvp); m_texture[i]->bind(); - m_texture[i]->render(m_lastRect[i], scale); + m_texture[i]->render(m_lastRect[i].size(), scale); m_texture[i]->unbind(); } glDisable(GL_BLEND); diff --git a/src/effects/zoom/zoom.cpp b/src/effects/zoom/zoom.cpp index b2c0b13ef4..f46fd88c1a 100644 --- a/src/effects/zoom/zoom.cpp +++ b/src/effects/zoom/zoom.cpp @@ -391,22 +391,21 @@ void ZoomEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData &d GLTexture *cursorTexture = ensureCursorTexture(); if (cursorTexture) { const auto cursor = effects->cursorImage(); - QSize cursorSize = cursor.image().size() / cursor.image().devicePixelRatio(); + QSizeF cursorSize = QSizeF(cursor.image().size()) / cursor.image().devicePixelRatio(); if (mousePointer == MousePointerScale) { cursorSize *= zoom; } - const QPoint p = effects->cursorPos() - cursor.hotSpot(); - QRect rect(p * zoom + QPoint(xTranslation, yTranslation), cursorSize); + const QPoint p = (effects->cursorPos() - cursor.hotSpot()) * zoom + QPoint(xTranslation, yTranslation); cursorTexture->bind(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); auto s = ShaderManager::instance()->pushShader(ShaderTrait::MapTexture); QMatrix4x4 mvp = data.projectionMatrix(); - mvp.translate(rect.x() * scale, rect.y() * scale); + mvp.translate(p.x() * scale, p.y() * scale); s->setUniform(GLShader::ModelViewProjectionMatrix, mvp); - cursorTexture->render(rect, scale); + cursorTexture->render(cursorSize, scale); ShaderManager::instance()->popShader(); cursorTexture->unbind(); glDisable(GL_BLEND); diff --git a/src/libkwineffects/kwingltexture.cpp b/src/libkwineffects/kwingltexture.cpp index 38edb5468b..3e704822db 100644 --- a/src/libkwineffects/kwingltexture.cpp +++ b/src/libkwineffects/kwingltexture.cpp @@ -506,33 +506,30 @@ void GLTexture::unbind() glBindTexture(d->m_target, 0); } -void GLTexture::render(const QRect &rect, qreal scale) +void GLTexture::render(const QSizeF &size, qreal scale) { - render(infiniteRegion(), rect, scale, false); + render(infiniteRegion(), size, scale, false); } -void GLTexture::render(const QRegion ®ion, const QRect &rect, qreal scale, bool hardwareClipping) +void GLTexture::render(const QRegion ®ion, const QSizeF &size, double scale, bool hardwareClipping) { Q_D(GLTexture); - if (rect.isEmpty()) { + if (size.isEmpty()) { return; // nothing to paint and m_vbo is likely nullptr and d->m_cachedSize empty as well, #337090 } - QRect destinationRect = scaledRect(rect, scale).toRect(); - if (destinationRect.size() != d->m_cachedSize) { - d->m_cachedSize = destinationRect.size(); - QRect r(destinationRect); - r.moveTo(0, 0); + QSizeF destinationSize = (size * scale).toSize(); + if (destinationSize != d->m_cachedSize) { + d->m_cachedSize = destinationSize; if (!d->m_vbo) { d->m_vbo = std::make_unique(KWin::GLVertexBuffer::Static); } const float verts[4 * 2] = { - // NOTICE: r.x/y could be replaced by "0", but that would make it unreadable... - static_cast(r.x()), static_cast(r.y()), - static_cast(r.x()), static_cast(r.y() + destinationRect.height()), - static_cast(r.x() + destinationRect.width()), static_cast(r.y()), - static_cast(r.x() + destinationRect.width()), static_cast(r.y() + destinationRect.height())}; + 0.0f, 0.0f, + 0.0f, float(destinationSize.height()), + float(destinationSize.width()), 0, + float(destinationSize.width()), float(destinationSize.height())}; const float texWidth = (target() == GL_TEXTURE_RECTANGLE_ARB) ? width() : 1.0f; const float texHeight = (target() == GL_TEXTURE_RECTANGLE_ARB) ? height() : 1.0f; diff --git a/src/libkwineffects/kwingltexture.h b/src/libkwineffects/kwingltexture.h index 295c93de60..07e6119cf2 100644 --- a/src/libkwineffects/kwingltexture.h +++ b/src/libkwineffects/kwingltexture.h @@ -101,8 +101,8 @@ public: virtual void discard(); void bind(); void unbind(); - void render(const QRect &rect, qreal scale); - void render(const QRegion ®ion, const QRect &rect, qreal scale, bool hardwareClipping = false); + void render(const QSizeF &size, double scale); + void render(const QRegion ®ion, const QSizeF &size, double scale, bool hardwareClipping = false); GLuint texture() const; GLenum target() const; diff --git a/src/libkwineffects/kwingltexture_p.h b/src/libkwineffects/kwingltexture_p.h index e41fca8e64..7a672d399e 100644 --- a/src/libkwineffects/kwingltexture_p.h +++ b/src/libkwineffects/kwingltexture_p.h @@ -57,7 +57,7 @@ public: int m_unnormalizeActive; // 0 - no, otherwise refcount int m_normalizeActive; // 0 - no, otherwise refcount std::unique_ptr m_vbo; - QSize m_cachedSize; + QSizeF m_cachedSize; static void initStatic(); diff --git a/src/plugins/screencast/outputscreencastsource.cpp b/src/plugins/screencast/outputscreencastsource.cpp index bc9cda7368..3e8ecf3ca5 100644 --- a/src/plugins/screencast/outputscreencastsource.cpp +++ b/src/plugins/screencast/outputscreencastsource.cpp @@ -49,17 +49,15 @@ void OutputScreenCastSource::render(GLFramebuffer *target) return; } - const QRect geometry(QPoint(), textureSize()); - ShaderBinder shaderBinder(ShaderTrait::MapTexture); QMatrix4x4 projectionMatrix; projectionMatrix.scale(1, -1); - projectionMatrix.ortho(scaledRect(geometry, m_output->scale())); + projectionMatrix.ortho(QRect(QPoint(), textureSize() * m_output->scale())); shaderBinder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, projectionMatrix); GLFramebuffer::pushFramebuffer(target); outputTexture->bind(); - outputTexture->render(geometry, m_output->scale()); + outputTexture->render(textureSize(), m_output->scale()); outputTexture->unbind(); GLFramebuffer::popFramebuffer(); } diff --git a/src/plugins/screencast/regionscreencastsource.cpp b/src/plugins/screencast/regionscreencastsource.cpp index 29ed37f6d5..7dc46c3aa6 100644 --- a/src/plugins/screencast/regionscreencastsource.cpp +++ b/src/plugins/screencast/regionscreencastsource.cpp @@ -59,7 +59,7 @@ void RegionScreenCastSource::updateOutput(Output *output) shaderBinder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, projectionMatrix); outputTexture->bind(); - outputTexture->render(output->geometry(), 1 / m_scale); + outputTexture->render(output->geometry().size(), 1 / m_scale); outputTexture->unbind(); GLFramebuffer::popFramebuffer(); } @@ -89,16 +89,15 @@ void RegionScreenCastSource::render(GLFramebuffer *target) ensureTexture(); GLFramebuffer::pushFramebuffer(target); - QRect r(QPoint(), target->size()); auto shader = ShaderManager::instance()->pushShader(ShaderTrait::MapTexture); QMatrix4x4 projectionMatrix; projectionMatrix.scale(1, -1); - projectionMatrix.ortho(r); + projectionMatrix.ortho(QRect(QPoint(), target->size())); shader->setUniform(GLShader::ModelViewProjectionMatrix, projectionMatrix); m_renderedTexture->bind(); - m_renderedTexture->render(r, m_scale); + m_renderedTexture->render(target->size(), m_scale); m_renderedTexture->unbind(); ShaderManager::instance()->popShader(); diff --git a/src/plugins/screencast/screencaststream.cpp b/src/plugins/screencast/screencaststream.cpp index c7efd12882..bab5b2e481 100644 --- a/src/plugins/screencast/screencaststream.cpp +++ b/src/plugins/screencast/screencaststream.cpp @@ -486,7 +486,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.scale); + m_cursor.texture->render(cursorRect.size(), m_cursor.scale); glDisable(GL_BLEND); m_cursor.texture->unbind();