[backends/virtual] Move save screenshot functionality to the backend

Allows code reusability when adding an OpenGL backend.
This commit is contained in:
Martin Gräßlin 2015-10-08 15:53:03 +02:00
parent 29b2082daa
commit 2e888da70e
4 changed files with 29 additions and 16 deletions

View file

@ -21,9 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "virtual_backend.h"
#include "cursor.h"
#include <QDebug>
#include <QPainter>
#include <QTemporaryDir>
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++)));
}
}

View file

@ -24,8 +24,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QObject>
class QTemporaryDir;
namespace KWin
{
@ -49,7 +47,6 @@ public:
private:
QImage m_backBuffer;
VirtualBackend *m_backend;
QScopedPointer<QTemporaryDir> m_screenshotDir;
int m_frameCounter = 0;
};

View file

@ -21,6 +21,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "scene_qpainter_virtual_backend.h"
#include "screens_virtual.h"
#include "wayland_server.h"
// Qt
#include <QTemporaryDir>
// KWayland
#include <KWayland/Server/seat_interface.h>
@ -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);

View file

@ -26,6 +26,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QObject>
#include <QSize>
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<QTemporaryDir> m_screenshotDir;
};
}