From fa5be54a6d53003d290a817245a3ffa99d764201 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 16 Aug 2022 13:49:14 +0300 Subject: [PATCH] Remove Platform::repaint() It doesn't belong in Platform. --- .../x11/windowed/x11_windowed_backend.cpp | 6 +++++- .../x11/windowed/x11_windowed_egl_backend.cpp | 10 +++++++--- .../x11/windowed/x11_windowed_egl_backend.h | 5 +++-- src/backends/x11/windowed/x11_windowed_output.cpp | 15 +++++++++++++++ src/backends/x11/windowed/x11_windowed_output.h | 5 +++++ .../windowed/x11_windowed_qpainter_backend.cpp | 11 ++++++++--- .../x11/windowed/x11_windowed_qpainter_backend.h | 5 +++-- src/platform.cpp | 7 ------- src/platform.h | 1 - 9 files changed, 46 insertions(+), 19 deletions(-) diff --git a/src/backends/x11/windowed/x11_windowed_backend.cpp b/src/backends/x11/windowed/x11_windowed_backend.cpp index 5138335243..782e674e8f 100644 --- a/src/backends/x11/windowed/x11_windowed_backend.cpp +++ b/src/backends/x11/windowed/x11_windowed_backend.cpp @@ -572,7 +572,11 @@ void X11WindowedBackend::handleButtonPress(xcb_button_press_event_t *event) void X11WindowedBackend::handleExpose(xcb_expose_event_t *event) { - repaint(QRect(event->x, event->y, event->width, event->height)); + X11WindowedOutput *output = findOutput(event->window); + if (output) { + output->addExposedArea(QRect(event->x, event->y, event->width, event->height)); + output->renderLoop()->scheduleRepaint(); + } } void X11WindowedBackend::updateSize(xcb_configure_notify_event_t *event) diff --git a/src/backends/x11/windowed/x11_windowed_egl_backend.cpp b/src/backends/x11/windowed/x11_windowed_egl_backend.cpp index 386c318a87..2c10859925 100644 --- a/src/backends/x11/windowed/x11_windowed_egl_backend.cpp +++ b/src/backends/x11/windowed/x11_windowed_egl_backend.cpp @@ -19,7 +19,7 @@ namespace KWin { -X11WindowedEglOutput::X11WindowedEglOutput(X11WindowedEglBackend *backend, Output *output, EGLSurface surface) +X11WindowedEglOutput::X11WindowedEglOutput(X11WindowedEglBackend *backend, X11WindowedOutput *output, EGLSurface surface) : m_eglSurface(surface) , m_output(output) , m_backend(backend) @@ -43,9 +43,13 @@ std::optional X11WindowedEglOutput::beginFrame() eglMakeCurrent(m_backend->eglDisplay(), m_eglSurface, m_eglSurface, m_backend->context()); ensureFbo(); GLFramebuffer::pushFramebuffer(m_fbo.get()); + + QRegion repaint = m_output->exposedArea() + m_output->rect(); + m_output->clearExposedArea(); + return OutputLayerBeginFrameInfo{ .renderTarget = RenderTarget(m_fbo.get()), - .repaint = m_output->rect(), + .repaint = repaint, }; } @@ -97,7 +101,7 @@ bool X11WindowedEglBackend::createSurfaces() if (s == EGL_NO_SURFACE) { return false; } - m_outputs[output] = std::make_shared(this, output, s); + m_outputs[output] = std::make_shared(this, static_cast(output), s); } if (m_outputs.isEmpty()) { return false; diff --git a/src/backends/x11/windowed/x11_windowed_egl_backend.h b/src/backends/x11/windowed/x11_windowed_egl_backend.h index 7219d450f6..e5d34c8f2b 100644 --- a/src/backends/x11/windowed/x11_windowed_egl_backend.h +++ b/src/backends/x11/windowed/x11_windowed_egl_backend.h @@ -18,12 +18,13 @@ namespace KWin { class X11WindowedBackend; +class X11WindowedOutput; class X11WindowedEglBackend; class X11WindowedEglOutput : public OutputLayer { public: - X11WindowedEglOutput(X11WindowedEglBackend *backend, Output *output, EGLSurface surface); + X11WindowedEglOutput(X11WindowedEglBackend *backend, X11WindowedOutput *output, EGLSurface surface); ~X11WindowedEglOutput(); std::optional beginFrame() override; @@ -38,7 +39,7 @@ private: std::unique_ptr m_fbo; QRegion m_lastDamage; - Output *const m_output; + X11WindowedOutput *const m_output; X11WindowedEglBackend *const m_backend; }; diff --git a/src/backends/x11/windowed/x11_windowed_output.cpp b/src/backends/x11/windowed/x11_windowed_output.cpp index bc7f1747fe..8515e0f4b2 100644 --- a/src/backends/x11/windowed/x11_windowed_output.cpp +++ b/src/backends/x11/windowed/x11_windowed_output.cpp @@ -49,6 +49,21 @@ X11WindowedOutput::~X11WindowedOutput() xcb_flush(m_backend->connection()); } +QRegion X11WindowedOutput::exposedArea() const +{ + return m_exposedArea; +} + +void X11WindowedOutput::addExposedArea(const QRect &rect) +{ + m_exposedArea += rect; +} + +void X11WindowedOutput::clearExposedArea() +{ + m_exposedArea = QRegion(); +} + RenderLoop *X11WindowedOutput::renderLoop() const { return m_renderLoop.get(); diff --git a/src/backends/x11/windowed/x11_windowed_output.h b/src/backends/x11/windowed/x11_windowed_output.h index 1034937288..d972779d1e 100644 --- a/src/backends/x11/windowed/x11_windowed_output.h +++ b/src/backends/x11/windowed/x11_windowed_output.h @@ -69,6 +69,10 @@ public: bool usesSoftwareCursor() const override; void updateEnablement(bool enabled) override; + QRegion exposedArea() const; + void addExposedArea(const QRect &rect); + void clearExposedArea(); + private: void initXInputForWindow(); void vblank(std::chrono::nanoseconds timestamp); @@ -78,6 +82,7 @@ private: std::unique_ptr m_renderLoop; std::unique_ptr m_vsyncMonitor; QPoint m_hostPosition; + QRegion m_exposedArea; X11WindowedBackend *m_backend; }; diff --git a/src/backends/x11/windowed/x11_windowed_qpainter_backend.cpp b/src/backends/x11/windowed/x11_windowed_qpainter_backend.cpp index 3de6047b20..3169f436a6 100644 --- a/src/backends/x11/windowed/x11_windowed_qpainter_backend.cpp +++ b/src/backends/x11/windowed/x11_windowed_qpainter_backend.cpp @@ -14,7 +14,7 @@ namespace KWin { -X11WindowedQPainterOutput::X11WindowedQPainterOutput(Output *output, xcb_window_t window) +X11WindowedQPainterOutput::X11WindowedQPainterOutput(X11WindowedOutput *output, xcb_window_t window) : window(window) , m_output(output) { @@ -33,9 +33,13 @@ void X11WindowedQPainterOutput::ensureBuffer() std::optional X11WindowedQPainterOutput::beginFrame() { ensureBuffer(); + + QRegion repaint = m_output->exposedArea() + m_output->rect(); + m_output->clearExposedArea(); + return OutputLayerBeginFrameInfo{ .renderTarget = RenderTarget(&buffer), - .repaint = m_output->rect(), + .repaint = repaint, }; } @@ -69,7 +73,8 @@ X11WindowedQPainterBackend::~X11WindowedQPainterBackend() void X11WindowedQPainterBackend::addOutput(Output *output) { - m_outputs[output] = std::make_unique(output, m_backend->windowForScreen(output)); + X11WindowedOutput *x11Output = static_cast(output); + m_outputs[output] = std::make_unique(x11Output, m_backend->windowForScreen(x11Output)); } void X11WindowedQPainterBackend::removeOutput(Output *output) diff --git a/src/backends/x11/windowed/x11_windowed_qpainter_backend.h b/src/backends/x11/windowed/x11_windowed_qpainter_backend.h index 796e498209..ab8f4ca385 100644 --- a/src/backends/x11/windowed/x11_windowed_qpainter_backend.h +++ b/src/backends/x11/windowed/x11_windowed_qpainter_backend.h @@ -23,11 +23,12 @@ namespace KWin { class X11WindowedBackend; +class X11WindowedOutput; class X11WindowedQPainterOutput : public OutputLayer { public: - X11WindowedQPainterOutput(Output *output, xcb_window_t window); + X11WindowedQPainterOutput(X11WindowedOutput *output, xcb_window_t window); void ensureBuffer(); @@ -36,7 +37,7 @@ public: xcb_window_t window; QImage buffer; - Output *const m_output; + X11WindowedOutput *const m_output; }; class X11WindowedQPainterBackend : public QPainterBackend diff --git a/src/platform.cpp b/src/platform.cpp index 8464201b07..c042dde54e 100644 --- a/src/platform.cpp +++ b/src/platform.cpp @@ -164,13 +164,6 @@ Output *Platform::findOutput(const QString &name) const return nullptr; } -void Platform::repaint(const QRect &rect) -{ - if (Compositor::compositing()) { - Compositor::self()->scene()->addRepaint(rect); - } -} - void Platform::setReady(bool ready) { if (m_ready == ready) { diff --git a/src/platform.h b/src/platform.h index 7d1d1a1185..cd1f07c8e0 100644 --- a/src/platform.h +++ b/src/platform.h @@ -372,7 +372,6 @@ Q_SIGNALS: protected: explicit Platform(QObject *parent = nullptr); - void repaint(const QRect &rect); void setReady(bool ready); QSize initialWindowSize() const {