Allow specifying a render target scale for windows

This allows overriding the render target scale when rendering windows
and makes use of it in the screencasting plugin.
master
Arjen Hiemstra 2 years ago
parent ec6b9ed67e
commit cc4787500d

@ -246,6 +246,7 @@ void ScreenShotEffect::takeScreenShot(ScreenShotWindowData *screenshot)
if (validTarget) {
d.setXTranslation(-geometry.x());
d.setYTranslation(-geometry.y());
d.setRenderTargetScale(devicePixelRatio);
// render window into offscreen texture
int mask = PAINT_WINDOW_TRANSFORMED | PAINT_WINDOW_TRANSLUCENT;

@ -233,6 +233,7 @@ public:
qreal crossFadeProgress;
QMatrix4x4 pMatrix;
QMatrix4x4 screenProjectionMatrix;
std::optional<qreal> renderTargetScale = std::nullopt;
};
WindowPaintData::WindowPaintData()
@ -411,6 +412,16 @@ QMatrix4x4 WindowPaintData::screenProjectionMatrix() const
return d->screenProjectionMatrix;
}
std::optional<qreal> WindowPaintData::renderTargetScale() const
{
return d->renderTargetScale;
}
void WindowPaintData::setRenderTargetScale(qreal scale)
{
d->renderTargetScale = scale;
}
class ScreenPaintData::Private
{
public:

@ -39,6 +39,7 @@
#include <climits>
#include <functional>
#include <optional>
class KConfigGroup;
class QFont;
@ -3300,6 +3301,15 @@ public:
*/
QMatrix4x4 screenProjectionMatrix() const;
/**
* An override for the scale the window should be rendered at.
*
* When set, this value will be used instead of the window's output scale
* when rendering.
*/
std::optional<qreal> renderTargetScale() const;
void setRenderTargetScale(qreal scale);
/**
* Shader to be used for rendering, if any.
*/

@ -50,15 +50,14 @@ void WindowScreenCastSource::render(QImage *image)
void WindowScreenCastSource::render(GLFramebuffer *target)
{
auto targetScale = Compositor::self()->scene()->renderTargetScale();
const QRectF geometry = scaledRect(m_window->clientGeometry(), targetScale);
const QRectF geometry = m_window->clientGeometry();
QMatrix4x4 projectionMatrix;
projectionMatrix.ortho(geometry.x(), geometry.x() + geometry.width(),
geometry.y(), geometry.y() + geometry.height(), -1, 1);
WindowPaintData data;
data.setProjectionMatrix(projectionMatrix);
data.setRenderTargetScale(1.0);
GLFramebuffer::pushFramebuffer(target);
glClearColor(0.0, 0.0, 0.0, 0.0);

@ -429,7 +429,7 @@ void SceneOpenGL::render(Item *item, int mask, const QRegion &region, const Wind
RenderContext renderContext{
.clip = region,
.hardwareClipping = region != infiniteRegion() && ((mask & Scene::PAINT_WINDOW_TRANSFORMED) || (mask & Scene::PAINT_SCREEN_TRANSFORMED)),
.renderTargetScale = renderTargetScale(),
.renderTargetScale = data.renderTargetScale().value_or(renderTargetScale()),
};
renderContext.transformStack.push(QMatrix4x4());

Loading…
Cancel
Save