2015-05-05 13:23:53 +00:00
|
|
|
/********************************************************************
|
|
|
|
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_x11_backend.h"
|
|
|
|
#include "x11windowed_backend.h"
|
2015-11-24 08:34:56 +00:00
|
|
|
#include "screens.h"
|
2015-05-05 13:23:53 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
X11WindowedQPainterBackend::X11WindowedQPainterBackend(X11WindowedBackend *backend)
|
|
|
|
: QPainterBackend()
|
|
|
|
, m_backend(backend)
|
|
|
|
{
|
2015-11-24 08:34:56 +00:00
|
|
|
connect(screens(), &Screens::changed, this, &X11WindowedQPainterBackend::createOutputs);
|
|
|
|
createOutputs();
|
2015-05-05 13:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
X11WindowedQPainterBackend::~X11WindowedQPainterBackend()
|
|
|
|
{
|
2015-11-24 08:34:56 +00:00
|
|
|
qDeleteAll(m_outputs);
|
2015-05-05 13:23:53 +00:00
|
|
|
if (m_gc) {
|
|
|
|
xcb_free_gc(m_backend->connection(), m_gc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-24 08:34:56 +00:00
|
|
|
void X11WindowedQPainterBackend::createOutputs()
|
|
|
|
{
|
|
|
|
qDeleteAll(m_outputs);
|
|
|
|
m_outputs.clear();
|
|
|
|
for (int i = 0; i < screens()->count(); ++i) {
|
|
|
|
Output *output = new Output;
|
|
|
|
output->window = m_backend->windowForScreen(i);
|
2016-11-04 16:53:09 +00:00
|
|
|
output->buffer = QImage(screens()->size(i) * screens()->scale(i), QImage::Format_RGB32);
|
2015-11-24 08:34:56 +00:00
|
|
|
output->buffer.fill(Qt::black);
|
|
|
|
m_outputs << output;
|
|
|
|
}
|
|
|
|
m_needsFullRepaint = true;
|
|
|
|
}
|
|
|
|
|
2015-05-05 13:23:53 +00:00
|
|
|
QImage *X11WindowedQPainterBackend::buffer()
|
|
|
|
{
|
2015-11-24 08:34:56 +00:00
|
|
|
return bufferForScreen(0);
|
2015-05-05 13:23:53 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 08:34:56 +00:00
|
|
|
QImage *X11WindowedQPainterBackend::bufferForScreen(int screen)
|
2015-05-05 13:23:53 +00:00
|
|
|
{
|
2015-11-24 08:34:56 +00:00
|
|
|
return &m_outputs.at(screen)->buffer;
|
2015-05-05 13:23:53 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 08:34:56 +00:00
|
|
|
bool X11WindowedQPainterBackend::needsFullRepaint() const
|
2015-05-05 13:23:53 +00:00
|
|
|
{
|
2015-11-24 08:34:56 +00:00
|
|
|
return m_needsFullRepaint;
|
2015-05-05 13:23:53 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 08:34:56 +00:00
|
|
|
void X11WindowedQPainterBackend::prepareRenderingFrame()
|
2015-05-05 13:23:53 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11WindowedQPainterBackend::present(int mask, const QRegion &damage)
|
|
|
|
{
|
|
|
|
Q_UNUSED(mask)
|
|
|
|
Q_UNUSED(damage)
|
|
|
|
xcb_connection_t *c = m_backend->connection();
|
|
|
|
const xcb_window_t window = m_backend->window();
|
|
|
|
if (m_gc == XCB_NONE) {
|
|
|
|
m_gc = xcb_generate_id(c);
|
|
|
|
xcb_create_gc(c, m_gc, window, 0, nullptr);
|
|
|
|
}
|
2015-11-24 08:34:56 +00:00
|
|
|
for (auto it = m_outputs.constBegin(); it != m_outputs.constEnd(); ++it) {
|
|
|
|
// TODO: only update changes?
|
|
|
|
const QImage &buffer = (*it)->buffer;
|
|
|
|
xcb_put_image(c, XCB_IMAGE_FORMAT_Z_PIXMAP, (*it)->window, m_gc,
|
|
|
|
buffer.width(), buffer.height(), 0, 0, 0, 24,
|
2019-07-09 21:10:56 +00:00
|
|
|
buffer.sizeInBytes(), buffer.constBits());
|
2015-11-24 08:34:56 +00:00
|
|
|
}
|
2015-05-05 13:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool X11WindowedQPainterBackend::usesOverlayWindow() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-24 08:34:56 +00:00
|
|
|
bool X11WindowedQPainterBackend::perScreenRendering() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-05 13:23:53 +00:00
|
|
|
}
|