From 2e888da70ecfbc38fecebed689175c1737337c06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 8 Oct 2015 15:53:03 +0200 Subject: [PATCH] [backends/virtual] Move save screenshot functionality to the backend Allows code reusability when adding an OpenGL backend. --- .../scene_qpainter_virtual_backend.cpp | 15 ++------------- .../virtual/scene_qpainter_virtual_backend.h | 3 --- backends/virtual/virtual_backend.cpp | 19 +++++++++++++++++++ backends/virtual/virtual_backend.h | 8 ++++++++ 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/backends/virtual/scene_qpainter_virtual_backend.cpp b/backends/virtual/scene_qpainter_virtual_backend.cpp index c4e8754095..9027538093 100644 --- a/backends/virtual/scene_qpainter_virtual_backend.cpp +++ b/backends/virtual/scene_qpainter_virtual_backend.cpp @@ -21,9 +21,7 @@ along with this program. If not, see . #include "virtual_backend.h" #include "cursor.h" -#include #include -#include namespace KWin { @@ -32,15 +30,6 @@ VirtualQPainterBackend::VirtualQPainterBackend(VirtualBackend *backend) , m_backBuffer(backend->size(), QImage::Format_RGB32) , m_backend(backend) { - if (qEnvironmentVariableIsSet("KWIN_WAYLAND_VIRTUAL_SCREENSHOTS")) { - m_screenshotDir.reset(new QTemporaryDir); - if (!m_screenshotDir->isValid()) { - m_screenshotDir.reset(); - } - if (!m_screenshotDir.isNull()) { - qDebug() << "Screenshots saved to: " << m_screenshotDir->path(); - } - } } VirtualQPainterBackend::~VirtualQPainterBackend() = default; @@ -71,8 +60,8 @@ void VirtualQPainterBackend::present(int mask, const QRegion &damage) { Q_UNUSED(mask) Q_UNUSED(damage) - if (!m_screenshotDir.isNull()) { - m_backBuffer.save(QStringLiteral("%1/%2.png").arg(m_screenshotDir->path()).arg(QString::number(m_frameCounter++))); + if (m_backend->saveFrames()) { + m_backBuffer.save(QStringLiteral("%1/%2.png").arg(m_backend->screenshotDirPath()).arg(QString::number(m_frameCounter++))); } } diff --git a/backends/virtual/scene_qpainter_virtual_backend.h b/backends/virtual/scene_qpainter_virtual_backend.h index 996dfe856f..53bf5f0294 100644 --- a/backends/virtual/scene_qpainter_virtual_backend.h +++ b/backends/virtual/scene_qpainter_virtual_backend.h @@ -24,8 +24,6 @@ along with this program. If not, see . #include -class QTemporaryDir; - namespace KWin { @@ -49,7 +47,6 @@ public: private: QImage m_backBuffer; VirtualBackend *m_backend; - QScopedPointer m_screenshotDir; int m_frameCounter = 0; }; diff --git a/backends/virtual/virtual_backend.cpp b/backends/virtual/virtual_backend.cpp index 601358f96b..3253801ea9 100644 --- a/backends/virtual/virtual_backend.cpp +++ b/backends/virtual/virtual_backend.cpp @@ -21,6 +21,8 @@ along with this program. If not, see . #include "scene_qpainter_virtual_backend.h" #include "screens_virtual.h" #include "wayland_server.h" +// Qt +#include // KWayland #include @@ -30,6 +32,15 @@ namespace KWin VirtualBackend::VirtualBackend(QObject *parent) : AbstractBackend(parent) { + if (qEnvironmentVariableIsSet("KWIN_WAYLAND_VIRTUAL_SCREENSHOTS")) { + m_screenshotDir.reset(new QTemporaryDir); + if (!m_screenshotDir->isValid()) { + m_screenshotDir.reset(); + } + if (!m_screenshotDir.isNull()) { + qDebug() << "Screenshots saved to: " << m_screenshotDir->path(); + } + } setSoftWareCursor(true); setSupportsPointerWarping(true); // currently only QPainter - enforce it @@ -48,6 +59,14 @@ void VirtualBackend::init() emit screensQueried(); } +QString VirtualBackend::screenshotDirPath() const +{ + if (m_screenshotDir.isNull()) { + return QString(); + } + return m_screenshotDir->path(); +} + Screens *VirtualBackend::createScreens(QObject *parent) { return new VirtualScreens(this, parent); diff --git a/backends/virtual/virtual_backend.h b/backends/virtual/virtual_backend.h index e59903c4f6..acbdbb6779 100644 --- a/backends/virtual/virtual_backend.h +++ b/backends/virtual/virtual_backend.h @@ -26,6 +26,8 @@ along with this program. If not, see . #include #include +class QTemporaryDir; + namespace KWin { @@ -44,6 +46,11 @@ public: return m_size; } + bool saveFrames() const { + return !m_screenshotDir.isNull(); + } + QString screenshotDirPath() const; + Screens *createScreens(QObject *parent = nullptr) override; QPainterBackend* createQPainterBackend() override; @@ -52,6 +59,7 @@ Q_SIGNALS: private: QSize m_size; + QScopedPointer m_screenshotDir; }; }