Add convenience AbstractOutput::rect() function

Foobar::rect() is a common Qt API convention which is very handy when
you need a rect that looks like rect(0, 0, w, h).
This commit is contained in:
Vlad Zahorodnii 2022-04-05 20:48:05 +03:00
parent 809f383d44
commit d6af43763c
6 changed files with 16 additions and 6 deletions

View file

@ -137,6 +137,11 @@ public:
*/
virtual QRect geometry() const = 0;
/**
* Equivalent to `QRect(QPoint(0, 0), geometry().size())`
*/
QRect rect() const;
/**
* Returns the approximate vertical refresh rate of this output, in mHz.
*/
@ -285,6 +290,11 @@ private:
friend class EffectScreenImpl; // to access m_effectScreen
};
inline QRect AbstractOutput::rect() const
{
return QRect(QPoint(0, 0), geometry().size());
}
KWIN_EXPORT QDebug operator<<(QDebug debug, const AbstractOutput *output);
} // namespace KWin

View file

@ -39,7 +39,7 @@ void DrmAbstractOutput::pageFlipped(std::chrono::nanoseconds timestamp) const
QVector<int32_t> DrmAbstractOutput::regionToRects(const QRegion &region) const
{
const int height = pixelSize().height();
const QMatrix4x4 matrix = AbstractWaylandOutput::logicalToNativeMatrix(QRect(QPoint(0, 0), geometry().size()), scale(), transform());
const QMatrix4x4 matrix = AbstractWaylandOutput::logicalToNativeMatrix(rect(), scale(), transform());
QVector<EGLint> rects;
rects.reserve(region.rectCount() * 4);
for (const QRect &_rect : region) {

View file

@ -297,7 +297,7 @@ bool EglWaylandBackend::initBufferConfigs()
static QVector<EGLint> regionToRects(const QRegion &region, AbstractWaylandOutput *output)
{
const int height = output->modeSize().height();
const QMatrix4x4 matrix = WaylandOutput::logicalToNativeMatrix(QRect(QPoint(0, 0), output->geometry().size()),
const QMatrix4x4 matrix = WaylandOutput::logicalToNativeMatrix(output->rect(),
output->scale(),
output->transform());

View file

@ -71,7 +71,7 @@ QRegion EglX11Backend::beginFrame(AbstractOutput *output)
const EglX11Output *rendererOutput = m_outputs[output];
makeContextCurrent(rendererOutput->m_eglSurface);
GLRenderTarget::pushRenderTarget(rendererOutput->m_renderTarget.data());
return QRect(QPoint(0, 0), output->geometry().size());
return output->rect();
}
void EglX11Backend::endFrame(AbstractOutput *output, const QRegion &renderedRegion, const QRegion &damagedRegion)

View file

@ -52,7 +52,7 @@ QImage *X11WindowedQPainterBackend::bufferForScreen(AbstractOutput *output)
QRegion X11WindowedQPainterBackend::beginFrame(AbstractOutput *output)
{
return QRect(QPoint(0, 0), output->geometry().size());
return output->rect();
}
void X11WindowedQPainterBackend::endFrame(AbstractOutput *output, const QRegion &renderedRegion, const QRegion &damagedRegion)

View file

@ -434,9 +434,9 @@ void Compositor::addOutput(AbstractOutput *output)
auto workspaceLayer = new RenderLayer(output->renderLoop());
workspaceLayer->setDelegate(new SceneDelegate(m_scene, output));
workspaceLayer->setGeometry(QRect(QPoint(0, 0), output->geometry().size()));
workspaceLayer->setGeometry(output->rect());
connect(output, &AbstractOutput::geometryChanged, workspaceLayer, [output, workspaceLayer]() {
workspaceLayer->setGeometry(QRect(QPoint(0, 0), output->geometry().size()));
workspaceLayer->setGeometry(output->rect());
});
auto cursorLayer = new RenderLayer(output->renderLoop());