core: Drop viewport arg in RenderTarget::applyTransformation()

This commit is contained in:
Vlad Zahorodnii 2023-12-20 11:32:06 +02:00
parent b733bb69bf
commit 11aa9abfe2
4 changed files with 27 additions and 23 deletions

View file

@ -34,38 +34,38 @@ QSize RenderTarget::size() const
}
}
QRectF RenderTarget::applyTransformation(const QRectF &rect, const QRectF &viewport) const
QRectF RenderTarget::applyTransformation(const QRectF &rect) const
{
const auto center = viewport.center();
const auto bounds = size();
QMatrix4x4 relativeTransformation;
relativeTransformation.translate(center.x(), center.y());
relativeTransformation.translate(bounds.width() / 2.0, bounds.height() / 2.0);
relativeTransformation *= m_transformation;
relativeTransformation.translate(-center.x(), -center.y());
relativeTransformation.translate(-bounds.width() / 2.0, -bounds.height() / 2.0);
return relativeTransformation.mapRect(rect);
}
QRect RenderTarget::applyTransformation(const QRect &rect, const QRect &viewport) const
QRect RenderTarget::applyTransformation(const QRect &rect) const
{
return applyTransformation(QRectF(rect), QRectF(viewport)).toRect();
return applyTransformation(QRectF(rect)).toRect();
}
QPointF RenderTarget::applyTransformation(const QPointF &point, const QRectF &viewport) const
QPointF RenderTarget::applyTransformation(const QPointF &point) const
{
const auto center = viewport.center();
const auto bounds = size();
QMatrix4x4 relativeTransformation;
relativeTransformation.translate(center.x(), center.y());
relativeTransformation.translate(bounds.width() / 2.0, bounds.height() / 2.0);
relativeTransformation *= m_transformation;
relativeTransformation.translate(-center.x(), -center.y());
relativeTransformation.translate(-bounds.width() / 2.0, -bounds.height() / 2.0);
return relativeTransformation.map(point);
}
QPoint RenderTarget::applyTransformation(const QPoint &point, const QRect &viewport) const
QPoint RenderTarget::applyTransformation(const QPoint &point) const
{
const auto center = viewport.center();
const auto bounds = size();
QMatrix4x4 relativeTransformation;
relativeTransformation.translate(center.x(), center.y());
relativeTransformation.translate(bounds.width() / 2.0, bounds.height() / 2.0);
relativeTransformation *= m_transformation;
relativeTransformation.translate(-center.x(), -center.y());
relativeTransformation.translate(-bounds.width() / 2.0, -bounds.height() / 2.0);
return relativeTransformation.map(point);
}

View file

@ -27,10 +27,10 @@ public:
QSize size() const;
QMatrix4x4 transformation() const;
const ColorDescription &colorDescription() const;
QRectF applyTransformation(const QRectF &rect, const QRectF &viewport) const;
QRect applyTransformation(const QRect &rect, const QRect &viewport) const;
QPointF applyTransformation(const QPointF &point, const QRectF &viewport) const;
QPoint applyTransformation(const QPoint &point, const QRect &viewport) const;
QRectF applyTransformation(const QRectF &rect) const;
QRect applyTransformation(const QRect &rect) const;
QPointF applyTransformation(const QPointF &point) const;
QPoint applyTransformation(const QPoint &point) const;
QImage *image() const;
GLFramebuffer *framebuffer() const;

View file

@ -46,26 +46,26 @@ QRectF RenderViewport::mapToRenderTarget(const QRectF &logicalGeometry) const
{
const QRectF deviceGeometry = scaledRect(logicalGeometry, m_scale)
.translated(-m_deviceRenderRect.topLeft());
return m_renderTarget->applyTransformation(deviceGeometry, QRectF(QPointF(), m_renderTarget->size()));
return m_renderTarget->applyTransformation(deviceGeometry);
}
QRect RenderViewport::mapToRenderTarget(const QRect &logicalGeometry) const
{
const QRect deviceGeometry = snapToPixelGrid(scaledRect(logicalGeometry, m_scale))
.translated(-m_deviceRenderRect.topLeft());
return m_renderTarget->applyTransformation(deviceGeometry, QRect(QPoint(), m_renderTarget->size()));
return m_renderTarget->applyTransformation(deviceGeometry);
}
QPoint RenderViewport::mapToRenderTarget(const QPoint &logicalGeometry) const
{
const QPoint devicePoint = snapToPixelGrid(QPointF(logicalGeometry) * m_scale) - m_deviceRenderRect.topLeft();
return m_renderTarget->applyTransformation(devicePoint, QRect(QPoint(), m_renderTarget->size()));
return m_renderTarget->applyTransformation(devicePoint);
}
QPointF RenderViewport::mapToRenderTarget(const QPointF &logicalGeometry) const
{
const QPointF devicePoint = logicalGeometry * m_scale - m_deviceRenderRect.topLeft();
return m_renderTarget->applyTransformation(devicePoint, QRectF(QPointF(), m_renderTarget->size()));
return m_renderTarget->applyTransformation(devicePoint);
}
QRegion RenderViewport::mapToRenderTarget(const QRegion &logicalGeometry) const

View file

@ -12,6 +12,7 @@
#include "screenshotdbusinterface2.h"
#include "core/output.h"
#include "core/pixelgrid.h"
#include "core/rendertarget.h"
#include "core/renderviewport.h"
#include "effect/effecthandler.h"
@ -370,7 +371,10 @@ QImage ScreenShotEffect::blitScreenshot(const RenderTarget &renderTarget, const
if (effects->isOpenGLCompositing()) {
const auto screenGeometry = m_paintedScreen ? m_paintedScreen->geometry() : effects->virtualScreenGeometry();
const QSize nativeSize = renderTarget.applyTransformation(geometry, screenGeometry).size() * devicePixelRatio;
const QSize nativeSize = renderTarget.applyTransformation(
snapToPixelGrid(scaledRect(geometry, devicePixelRatio))
.translated(-snapToPixelGrid(scaledRect(screenGeometry, devicePixelRatio)).topLeft()))
.size();
image = QImage(nativeSize, QImage::Format_ARGB32);
const auto texture = GLTexture::allocate(GL_RGBA8, nativeSize);