effect: Drop WindowPaintData::projectionMatrix()

This commit is contained in:
Vlad Zahorodnii 2024-02-23 14:15:07 +02:00
parent 18628131df
commit 693cd16b12
12 changed files with 13 additions and 76 deletions

View file

@ -215,19 +215,12 @@ public:
qreal brightness;
int screen;
qreal crossFadeProgress;
QMatrix4x4 projectionMatrix;
};
WindowPaintData::WindowPaintData()
: WindowPaintData(QMatrix4x4())
{
}
WindowPaintData::WindowPaintData(const QMatrix4x4 &projectionMatrix)
: PaintData()
, d(std::make_unique<WindowPaintDataPrivate>())
{
setProjectionMatrix(projectionMatrix);
setOpacity(1.0);
setSaturation(1.0);
setBrightness(1.0);
@ -251,7 +244,6 @@ WindowPaintData::WindowPaintData(const WindowPaintData &other)
setBrightness(other.brightness());
setScreen(other.screen());
setCrossFadeProgress(other.crossFadeProgress());
setProjectionMatrix(other.projectionMatrix());
}
WindowPaintData::~WindowPaintData() = default;
@ -324,21 +316,6 @@ qreal WindowPaintData::multiplyBrightness(qreal factor)
return d->brightness;
}
void WindowPaintData::setProjectionMatrix(const QMatrix4x4 &matrix)
{
d->projectionMatrix = matrix;
}
QMatrix4x4 WindowPaintData::projectionMatrix() const
{
return d->projectionMatrix;
}
QMatrix4x4 &WindowPaintData::rprojectionMatrix()
{
return d->projectionMatrix;
}
WindowPaintData &WindowPaintData::operator*=(qreal scale)
{
this->setXScale(this->xScale() * scale);

View file

@ -300,7 +300,6 @@ class KWIN_EXPORT WindowPaintData : public PaintData
{
public:
WindowPaintData();
explicit WindowPaintData(const QMatrix4x4 &projectionMatrix);
WindowPaintData(const WindowPaintData &other);
~WindowPaintData() override;
/**
@ -437,23 +436,6 @@ public:
*/
qreal crossFadeProgress() const;
/**
* Sets the projection matrix that will be used when painting the window.
*
* The default projection matrix can be overridden by setting this matrix
*/
void setProjectionMatrix(const QMatrix4x4 &matrix);
/**
* Returns the current projection matrix.
*/
QMatrix4x4 projectionMatrix() const;
/**
* Returns a reference to the projection matrix.
*/
QMatrix4x4 &rprojectionMatrix();
private:
const std::unique_ptr<WindowPaintDataPrivate> d;
};

View file

@ -117,14 +117,8 @@ void OffscreenData::maybeRender(EffectWindow *window)
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
QMatrix4x4 projectionMatrix;
projectionMatrix.ortho(QRectF(0, 0, textureSize.width(), textureSize.height()));
WindowPaintData data;
data.setXTranslation(-logicalGeometry.x());
data.setYTranslation(-logicalGeometry.y());
data.setOpacity(1.0);
data.setProjectionMatrix(projectionMatrix);
const int mask = Effect::PAINT_WINDOW_TRANSFORMED | Effect::PAINT_WINDOW_TRANSLUCENT;
effects->drawWindow(renderTarget, viewport, window, mask, infiniteRegion(), data);
@ -185,7 +179,7 @@ void OffscreenData::paint(const RenderTarget &renderTarget, const RenderViewport
const qreal rgb = data.brightness() * data.opacity();
const qreal a = data.opacity();
QMatrix4x4 mvp = data.projectionMatrix();
QMatrix4x4 mvp = viewport.projectionMatrix();
mvp.translate(std::round(window->x() * scale), std::round(window->y() * scale));
const auto toXYZ = renderTarget.colorDescription().colorimetry().toXYZ();

View file

@ -422,7 +422,7 @@ void ContrastEffect::drawWindow(const RenderTarget &renderTarget, const RenderVi
const QRegion effectiveShape = shape & region & screen;
if (!effectiveShape.isEmpty()) {
doContrast(renderTarget, viewport, w, effectiveShape, w->opacity() * data.opacity(), data.projectionMatrix());
doContrast(renderTarget, viewport, w, effectiveShape, w->opacity() * data.opacity(), viewport.projectionMatrix());
}
}

View file

@ -774,7 +774,7 @@ void BlurEffect::blur(const RenderTarget &renderTarget, const RenderViewport &vi
GLFramebuffer::popFramebuffer();
const auto &read = renderInfo.framebuffers[1];
projectionMatrix = data.projectionMatrix();
projectionMatrix = viewport.projectionMatrix();
projectionMatrix.translate(deviceBackgroundRect.x(), deviceBackgroundRect.y());
m_upsamplePass.shader->setUniform(m_upsamplePass.mvpMatrixLocation, projectionMatrix);
@ -816,7 +816,7 @@ void BlurEffect::blur(const RenderTarget &renderTarget, const RenderViewport &vi
if (GLTexture *noiseTexture = ensureNoiseTexture()) {
ShaderManager::instance()->pushShader(m_noisePass.shader.get());
QMatrix4x4 projectionMatrix = data.projectionMatrix();
QMatrix4x4 projectionMatrix = viewport.projectionMatrix();
projectionMatrix.translate(deviceBackgroundRect.x(), deviceBackgroundRect.y());
m_noisePass.shader->setUniform(m_noisePass.mvpMatrixLocation, projectionMatrix);

View file

@ -64,13 +64,10 @@ void WindowScreenCastSource::render(GLFramebuffer *target)
RenderTarget renderTarget(target);
RenderViewport viewport(m_window->clientGeometry(), 1, renderTarget);
WindowPaintData data;
data.setProjectionMatrix(viewport.projectionMatrix());
GLFramebuffer::pushFramebuffer(target);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
Compositor::self()->scene()->renderer()->renderItem(renderTarget, viewport, m_window->windowItem(), Scene::PAINT_WINDOW_TRANSFORMED, infiniteRegion(), data);
Compositor::self()->scene()->renderer()->renderItem(renderTarget, viewport, m_window->windowItem(), Scene::PAINT_WINDOW_TRANSFORMED, infiniteRegion(), WindowPaintData{});
GLFramebuffer::popFramebuffer();
}

View file

@ -228,7 +228,6 @@ void ScreenShotEffect::takeScreenShot(ScreenShotWindowData *screenshot)
{
EffectWindow *window = screenshot->window;
WindowPaintData d;
QRectF geometry = window->expandedGeometry();
qreal devicePixelRatio = 1;
@ -258,9 +257,6 @@ void ScreenShotEffect::takeScreenShot(ScreenShotWindowData *screenshot)
validTarget = target->valid();
}
if (validTarget) {
d.setXTranslation(-geometry.x());
d.setYTranslation(-geometry.y());
// render window into offscreen texture
int mask = PAINT_WINDOW_TRANSFORMED | PAINT_WINDOW_TRANSLUCENT;
QImage img;
@ -272,10 +268,7 @@ void ScreenShotEffect::takeScreenShot(ScreenShotWindowData *screenshot)
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0, 0.0, 0.0, 1.0);
QMatrix4x4 projection;
projection.ortho(QRect(0, 0, geometry.width() * devicePixelRatio, geometry.height() * devicePixelRatio));
d.setProjectionMatrix(projection);
WindowPaintData d;
effects->drawWindow(renderTarget, viewport, window, mask, infiniteRegion(), d);
// copy content from framebuffer into image

View file

@ -62,7 +62,7 @@ void ThumbnailAsideEffect::paintScreen(const RenderTarget &renderTarget, const R
for (const Data &d : std::as_const(windows)) {
if (painted.intersects(d.rect)) {
WindowPaintData data(viewport.projectionMatrix());
WindowPaintData data;
data.multiplyOpacity(opacity);
QRect region;
setPositionTransformations(data, region, d.window, d.rect, Qt::KeepAspectRatio);

View file

@ -58,7 +58,7 @@ void CursorScene::paint(const RenderTarget &renderTarget, const QRegion &region)
RenderViewport viewport(QRectF(QPointF(), QSizeF(renderTarget.size()) / m_paintedOutput->scale()), m_paintedOutput->scale(), renderTarget);
m_renderer->beginFrame(renderTarget, viewport);
m_renderer->renderBackground(renderTarget, viewport, region);
m_renderer->renderItem(renderTarget, viewport, m_rootItem.get(), 0, region, WindowPaintData(viewport.projectionMatrix()));
m_renderer->renderItem(renderTarget, viewport, m_rootItem.get(), 0, region, WindowPaintData{});
m_renderer->endFrame();
}

View file

@ -260,7 +260,7 @@ void ItemRendererOpenGL::renderItem(const RenderTarget &renderTarget, const Rend
}
RenderContext renderContext{
.projectionMatrix = data.projectionMatrix(),
.projectionMatrix = viewport.projectionMatrix(),
.clip = region,
.hardwareClipping = region != infiniteRegion() && ((mask & Scene::PAINT_WINDOW_TRANSFORMED) || (mask & Scene::PAINT_SCREEN_TRANSFORMED)),
.renderTargetScale = viewport.scale(),

View file

@ -435,7 +435,7 @@ void WorkspaceScene::paintSimpleScreen(const RenderTarget &renderTarget, const R
if (m_dndIcon) {
const QRegion repaint = region & m_dndIcon->mapToGlobal(m_dndIcon->boundingRect()).toRect();
if (!repaint.isEmpty()) {
m_renderer->renderItem(renderTarget, viewport, m_dndIcon.get(), 0, repaint, WindowPaintData(viewport.projectionMatrix()));
m_renderer->renderItem(renderTarget, viewport, m_dndIcon.get(), 0, repaint, WindowPaintData{});
}
}
}
@ -462,7 +462,7 @@ void WorkspaceScene::paintWindow(const RenderTarget &renderTarget, const RenderV
return;
}
WindowPaintData data(viewport.projectionMatrix());
WindowPaintData data;
effects->paintWindow(renderTarget, viewport, item->effectWindow(), mask, region, data);
}

View file

@ -117,6 +117,7 @@ void WindowThumbnailSource::update()
if (!m_offscreenTexture) {
return;
}
m_offscreenTexture->setContentTransform(OutputTransform::FlipY);
m_offscreenTexture->setFilter(GL_LINEAR);
m_offscreenTexture->setWrapMode(GL_CLAMP_TO_EDGE);
m_offscreenTarget = std::make_unique<GLFramebuffer>(m_offscreenTexture.get());
@ -128,18 +129,11 @@ void WindowThumbnailSource::update()
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
QMatrix4x4 projectionMatrix;
projectionMatrix.ortho(geometry.x() * devicePixelRatio, (geometry.x() + geometry.width()) * devicePixelRatio,
geometry.y() * devicePixelRatio, (geometry.y() + geometry.height()) * devicePixelRatio, -1, 1);
WindowPaintData data;
data.setProjectionMatrix(projectionMatrix);
// The thumbnail must be rendered using kwin's opengl context as VAOs are not
// shared across contexts. Unfortunately, this also introduces a latency of 1
// frame, which is not ideal, but it is acceptable for things such as thumbnails.
const int mask = Scene::PAINT_WINDOW_TRANSFORMED;
Compositor::self()->scene()->renderer()->renderItem(offscreenRenderTarget, offscreenViewport, m_handle->windowItem(), mask, infiniteRegion(), data);
Compositor::self()->scene()->renderer()->renderItem(offscreenRenderTarget, offscreenViewport, m_handle->windowItem(), mask, infiniteRegion(), WindowPaintData{});
GLFramebuffer::popFramebuffer();
// The fence is needed to avoid the case where qtquick renderer starts using