[wayland] Move DrmQPainterBackend into backends/drm
parent
72db1e63a3
commit
06d8206192
|
@ -453,6 +453,7 @@ if(HAVE_WAYLAND)
|
||||||
${kwin_KDEINIT_SRCS}
|
${kwin_KDEINIT_SRCS}
|
||||||
backends/drm/drm_backend.cpp
|
backends/drm/drm_backend.cpp
|
||||||
backends/drm/screens_drm.cpp
|
backends/drm/screens_drm.cpp
|
||||||
|
backends/drm/scene_qpainter_drm_backend.cpp
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
if(HAVE_GBM)
|
if(HAVE_GBM)
|
||||||
|
|
|
@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#include "composite.h"
|
#include "composite.h"
|
||||||
#include "cursor.h"
|
#include "cursor.h"
|
||||||
#include "logind.h"
|
#include "logind.h"
|
||||||
#include "scene_qpainter.h"
|
#include "scene_qpainter_drm_backend.h"
|
||||||
#include "screens_drm.h"
|
#include "screens_drm.h"
|
||||||
#include "udev.h"
|
#include "udev.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
|
@ -0,0 +1,122 @@
|
||||||
|
/********************************************************************
|
||||||
|
KWin - the KDE window manager
|
||||||
|
This file is part of the KDE project.
|
||||||
|
|
||||||
|
Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*********************************************************************/
|
||||||
|
#include "scene_qpainter_drm_backend.h"
|
||||||
|
#include "drm_backend.h"
|
||||||
|
#include "virtual_terminal.h"
|
||||||
|
|
||||||
|
namespace KWin
|
||||||
|
{
|
||||||
|
|
||||||
|
DrmQPainterBackend::DrmQPainterBackend(DrmBackend *backend)
|
||||||
|
: QObject()
|
||||||
|
, QPainterBackend()
|
||||||
|
, m_backend(backend)
|
||||||
|
{
|
||||||
|
const auto outputs = m_backend->outputs();
|
||||||
|
for (auto output: outputs) {
|
||||||
|
initOutput(output);
|
||||||
|
}
|
||||||
|
connect(m_backend, &DrmBackend::outputAdded, this, &DrmQPainterBackend::initOutput);
|
||||||
|
connect(m_backend, &DrmBackend::outputRemoved, this,
|
||||||
|
[this] (DrmOutput *o) {
|
||||||
|
auto it = std::find_if(m_outputs.begin(), m_outputs.end(),
|
||||||
|
[o] (const Output &output) {
|
||||||
|
return output.output == o;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (it == m_outputs.end()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
delete (*it).buffer[0];
|
||||||
|
delete (*it).buffer[1];
|
||||||
|
m_outputs.erase(it);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
DrmQPainterBackend::~DrmQPainterBackend()
|
||||||
|
{
|
||||||
|
for (auto it = m_outputs.begin(); it != m_outputs.end(); ++it) {
|
||||||
|
delete (*it).buffer[0];
|
||||||
|
delete (*it).buffer[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrmQPainterBackend::initOutput(DrmOutput *output)
|
||||||
|
{
|
||||||
|
Output o;
|
||||||
|
auto initBuffer = [&o, output, this] (int index) {
|
||||||
|
o.buffer[index] = m_backend->createBuffer(output->size());
|
||||||
|
o.buffer[index]->map();
|
||||||
|
o.buffer[index]->image()->fill(Qt::black);
|
||||||
|
};
|
||||||
|
initBuffer(0);
|
||||||
|
initBuffer(1);
|
||||||
|
o.output = output;
|
||||||
|
m_outputs << o;
|
||||||
|
}
|
||||||
|
|
||||||
|
QImage *DrmQPainterBackend::buffer()
|
||||||
|
{
|
||||||
|
return bufferForScreen(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
QImage *DrmQPainterBackend::bufferForScreen(int screenId)
|
||||||
|
{
|
||||||
|
const Output &o = m_outputs.at(screenId);
|
||||||
|
return o.buffer[o.index]->image();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DrmQPainterBackend::needsFullRepaint() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrmQPainterBackend::prepareRenderingFrame()
|
||||||
|
{
|
||||||
|
for (auto it = m_outputs.begin(); it != m_outputs.end(); ++it) {
|
||||||
|
(*it).index = ((*it).index + 1) % 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrmQPainterBackend::present(int mask, const QRegion &damage)
|
||||||
|
{
|
||||||
|
Q_UNUSED(mask)
|
||||||
|
Q_UNUSED(damage)
|
||||||
|
if (!VirtualTerminal::self()->isActive()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (auto it = m_outputs.begin(); it != m_outputs.end(); ++it) {
|
||||||
|
const Output &o = *it;
|
||||||
|
m_backend->present(o.buffer[o.index], o.output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DrmQPainterBackend::usesOverlayWindow() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DrmQPainterBackend::perScreenRendering() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
/********************************************************************
|
||||||
|
KWin - the KDE window manager
|
||||||
|
This file is part of the KDE project.
|
||||||
|
|
||||||
|
Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*********************************************************************/
|
||||||
|
#ifndef KWIN_SCENE_QPAINTER_DRM_BACKEND_H
|
||||||
|
#define KWIN_SCENE_QPAINTER_DRM_BACKEND_H
|
||||||
|
#include "scene_qpainter.h"
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
namespace KWin
|
||||||
|
{
|
||||||
|
|
||||||
|
class DrmBackend;
|
||||||
|
class DrmBuffer;
|
||||||
|
class DrmOutput;
|
||||||
|
|
||||||
|
class DrmQPainterBackend : public QObject, public QPainterBackend
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
DrmQPainterBackend(DrmBackend *backend);
|
||||||
|
virtual ~DrmQPainterBackend();
|
||||||
|
|
||||||
|
QImage *buffer() override;
|
||||||
|
QImage *bufferForScreen(int screenId);
|
||||||
|
bool needsFullRepaint() const override;
|
||||||
|
bool usesOverlayWindow() const override;
|
||||||
|
void prepareRenderingFrame() override;
|
||||||
|
void present(int mask, const QRegion &damage) override;
|
||||||
|
bool perScreenRendering() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void initOutput(DrmOutput *output);
|
||||||
|
struct Output {
|
||||||
|
DrmBuffer *buffer[2];
|
||||||
|
DrmOutput *output;
|
||||||
|
int index = 0;
|
||||||
|
};
|
||||||
|
QVector<Output> m_outputs;
|
||||||
|
DrmBackend *m_backend;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -28,9 +28,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#include "screens.h"
|
#include "screens.h"
|
||||||
#include "toplevel.h"
|
#include "toplevel.h"
|
||||||
#if HAVE_WAYLAND
|
#if HAVE_WAYLAND
|
||||||
#if HAVE_DRM
|
|
||||||
#include "backends/drm/drm_backend.h"
|
|
||||||
#endif
|
|
||||||
#include "backends/fbdev/fb_backend.h"
|
#include "backends/fbdev/fb_backend.h"
|
||||||
#include "virtual_terminal.h"
|
#include "virtual_terminal.h"
|
||||||
#include "backends/wayland/wayland_backend.h"
|
#include "backends/wayland/wayland_backend.h"
|
||||||
|
@ -347,107 +344,6 @@ void FramebufferQPainterBackend::renderCursor(QPainter *painter)
|
||||||
m_backend->markCursorAsRendered();
|
m_backend->markCursorAsRendered();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HAVE_DRM
|
|
||||||
//****************************************
|
|
||||||
// DrmQPainterBackend
|
|
||||||
//****************************************
|
|
||||||
DrmQPainterBackend::DrmQPainterBackend(DrmBackend *backend)
|
|
||||||
: QObject()
|
|
||||||
, QPainterBackend()
|
|
||||||
, m_backend(backend)
|
|
||||||
{
|
|
||||||
const auto outputs = m_backend->outputs();
|
|
||||||
for (auto output: outputs) {
|
|
||||||
initOutput(output);
|
|
||||||
}
|
|
||||||
connect(m_backend, &DrmBackend::outputAdded, this, &DrmQPainterBackend::initOutput);
|
|
||||||
connect(m_backend, &DrmBackend::outputRemoved, this,
|
|
||||||
[this] (DrmOutput *o) {
|
|
||||||
auto it = std::find_if(m_outputs.begin(), m_outputs.end(),
|
|
||||||
[o] (const Output &output) {
|
|
||||||
return output.output == o;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
if (it == m_outputs.end()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
delete (*it).buffer[0];
|
|
||||||
delete (*it).buffer[1];
|
|
||||||
m_outputs.erase(it);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
DrmQPainterBackend::~DrmQPainterBackend()
|
|
||||||
{
|
|
||||||
for (auto it = m_outputs.begin(); it != m_outputs.end(); ++it) {
|
|
||||||
delete (*it).buffer[0];
|
|
||||||
delete (*it).buffer[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrmQPainterBackend::initOutput(DrmOutput *output)
|
|
||||||
{
|
|
||||||
Output o;
|
|
||||||
auto initBuffer = [&o, output, this] (int index) {
|
|
||||||
o.buffer[index] = m_backend->createBuffer(output->size());
|
|
||||||
o.buffer[index]->map();
|
|
||||||
o.buffer[index]->image()->fill(Qt::black);
|
|
||||||
};
|
|
||||||
initBuffer(0);
|
|
||||||
initBuffer(1);
|
|
||||||
o.output = output;
|
|
||||||
m_outputs << o;
|
|
||||||
}
|
|
||||||
|
|
||||||
QImage *DrmQPainterBackend::buffer()
|
|
||||||
{
|
|
||||||
return bufferForScreen(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
QImage *DrmQPainterBackend::bufferForScreen(int screenId)
|
|
||||||
{
|
|
||||||
const Output &o = m_outputs.at(screenId);
|
|
||||||
return o.buffer[o.index]->image();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DrmQPainterBackend::needsFullRepaint() const
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrmQPainterBackend::prepareRenderingFrame()
|
|
||||||
{
|
|
||||||
for (auto it = m_outputs.begin(); it != m_outputs.end(); ++it) {
|
|
||||||
(*it).index = ((*it).index + 1) % 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrmQPainterBackend::present(int mask, const QRegion &damage)
|
|
||||||
{
|
|
||||||
Q_UNUSED(mask)
|
|
||||||
Q_UNUSED(damage)
|
|
||||||
if (!VirtualTerminal::self()->isActive()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (auto it = m_outputs.begin(); it != m_outputs.end(); ++it) {
|
|
||||||
const Output &o = *it;
|
|
||||||
m_backend->present(o.buffer[o.index], o.output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DrmQPainterBackend::usesOverlayWindow() const
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DrmQPainterBackend::perScreenRendering() const
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//****************************************
|
//****************************************
|
||||||
|
|
|
@ -44,9 +44,6 @@ namespace Wayland
|
||||||
{
|
{
|
||||||
class WaylandBackend;
|
class WaylandBackend;
|
||||||
}
|
}
|
||||||
class DrmBackend;
|
|
||||||
class DrmBuffer;
|
|
||||||
class DrmOutput;
|
|
||||||
class FramebufferBackend;
|
class FramebufferBackend;
|
||||||
class X11WindowedBackend;
|
class X11WindowedBackend;
|
||||||
|
|
||||||
|
@ -190,34 +187,6 @@ private:
|
||||||
FramebufferBackend *m_backend;
|
FramebufferBackend *m_backend;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if HAVE_DRM
|
|
||||||
class DrmQPainterBackend : public QObject, public QPainterBackend
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
DrmQPainterBackend(DrmBackend *backend);
|
|
||||||
virtual ~DrmQPainterBackend();
|
|
||||||
|
|
||||||
QImage *buffer() override;
|
|
||||||
QImage *bufferForScreen(int screenId);
|
|
||||||
bool needsFullRepaint() const override;
|
|
||||||
bool usesOverlayWindow() const override;
|
|
||||||
void prepareRenderingFrame() override;
|
|
||||||
void present(int mask, const QRegion &damage) override;
|
|
||||||
bool perScreenRendering() const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void initOutput(DrmOutput *output);
|
|
||||||
struct Output {
|
|
||||||
DrmBuffer *buffer[2];
|
|
||||||
DrmOutput *output;
|
|
||||||
int index = 0;
|
|
||||||
};
|
|
||||||
QVector<Output> m_outputs;
|
|
||||||
DrmBackend *m_backend;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class SceneQPainter : public Scene
|
class SceneQPainter : public Scene
|
||||||
|
|
Loading…
Reference in New Issue