[platforms/fbdev] Port to AbstractOutput
Summary: To homogenize our backends and as another step to remove the Screens class use the AbstractOutput class in the framebuffer backend. Test Plan: Manually on VT enforcing the framebuffer backend. Reviewers: #kwin, davidedmundson Reviewed By: #kwin, davidedmundson Subscribers: davidedmundson, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D19199
This commit is contained in:
parent
d3ad6bc0b9
commit
2e20cac5e2
4 changed files with 93 additions and 26 deletions
|
@ -18,11 +18,12 @@ 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 "fb_backend.h"
|
||||
|
||||
#include "composite.h"
|
||||
#include "logging.h"
|
||||
#include "logind.h"
|
||||
#include "scene_qpainter_fb_backend.h"
|
||||
#include "screens.h"
|
||||
#include "outputscreens.h"
|
||||
#include "virtual_terminal.h"
|
||||
#include "udev.h"
|
||||
// system
|
||||
|
@ -51,7 +52,7 @@ FramebufferBackend::~FramebufferBackend()
|
|||
|
||||
Screens *FramebufferBackend::createScreens(QObject *parent)
|
||||
{
|
||||
return new BasicScreens(this, parent);
|
||||
return new OutputScreens(this, parent);
|
||||
}
|
||||
|
||||
QPainterBackend *FramebufferBackend::createQPainterBackend()
|
||||
|
@ -135,8 +136,11 @@ bool FramebufferBackend::handleScreenInfo()
|
|||
return false;
|
||||
}
|
||||
|
||||
m_resolution = QSize(varinfo.xres, varinfo.yres);
|
||||
m_physicalSize = QSize(varinfo.width, varinfo.height);
|
||||
auto *output = new FramebufferOutput(this);
|
||||
output->setPixelSize(QSize(varinfo.xres, varinfo.yres));
|
||||
output->setRawPhysicalSize(QSize(varinfo.width, varinfo.height));
|
||||
m_outputs << output;
|
||||
|
||||
m_id = QByteArray(fixinfo.id);
|
||||
m_red = {varinfo.red.offset, varinfo.red.length};
|
||||
m_green = {varinfo.green.offset, varinfo.green.length};
|
||||
|
@ -178,6 +182,14 @@ void FramebufferBackend::unmap()
|
|||
m_memory = nullptr;
|
||||
}
|
||||
|
||||
QSize FramebufferBackend::screenSize() const
|
||||
{
|
||||
if (m_outputs.isEmpty()) {
|
||||
return QSize();
|
||||
}
|
||||
return m_outputs[0]->pixelSize();
|
||||
}
|
||||
|
||||
QImage::Format FramebufferBackend::imageFormat() const
|
||||
{
|
||||
return m_imageFormat;
|
||||
|
@ -245,4 +257,14 @@ void FramebufferBackend::initImageFormat()
|
|||
}
|
||||
}
|
||||
|
||||
Outputs FramebufferBackend::outputs() const
|
||||
{
|
||||
return m_outputs;
|
||||
}
|
||||
|
||||
Outputs FramebufferBackend::enabledOutputs() const
|
||||
{
|
||||
return m_outputs;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org>
|
||||
Copyright 2015 Martin Gräßlin <mgraesslin@kde.org>
|
||||
Copyright 2019 Roman Gilg <subdiff@gmail.com>
|
||||
|
||||
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
|
||||
|
@ -19,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*********************************************************************/
|
||||
#ifndef KWIN_FB_BACKEND_H
|
||||
#define KWIN_FB_BACKEND_H
|
||||
#include "abstract_output.h"
|
||||
#include "platform.h"
|
||||
|
||||
#include <QImage>
|
||||
|
@ -27,6 +29,29 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
namespace KWin
|
||||
{
|
||||
|
||||
class FramebufferOutput : public AbstractOutput
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FramebufferOutput(QObject *parent = nullptr) : AbstractOutput(parent) {}
|
||||
virtual ~FramebufferOutput() = default;
|
||||
|
||||
QSize pixelSize() const override {
|
||||
return m_pixelSize;
|
||||
}
|
||||
void setPixelSize(const QSize &set) {
|
||||
m_pixelSize = set;
|
||||
}
|
||||
|
||||
void setRawPhysicalSize(const QSize &set) {
|
||||
AbstractOutput::setRawPhysicalSize(set);
|
||||
}
|
||||
|
||||
private:
|
||||
QSize m_pixelSize;
|
||||
};
|
||||
|
||||
class KWIN_EXPORT FramebufferBackend : public Platform
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -39,9 +64,7 @@ public:
|
|||
Screens *createScreens(QObject *parent = nullptr) override;
|
||||
QPainterBackend *createQPainterBackend() override;
|
||||
|
||||
QSize screenSize() const override {
|
||||
return m_resolution;
|
||||
}
|
||||
QSize screenSize() const override;
|
||||
|
||||
void init() override;
|
||||
|
||||
|
@ -49,13 +72,6 @@ public:
|
|||
return m_fd >= 0;
|
||||
}
|
||||
|
||||
QSize size() const {
|
||||
return m_resolution;
|
||||
}
|
||||
QSize physicalSize() const {
|
||||
return m_physicalSize;
|
||||
}
|
||||
|
||||
void map();
|
||||
void unmap();
|
||||
void *mappedMemory() const {
|
||||
|
@ -78,6 +94,9 @@ public:
|
|||
return m_bgr;
|
||||
}
|
||||
|
||||
Outputs outputs() const override;
|
||||
Outputs enabledOutputs() const override;
|
||||
|
||||
QVector<CompositingType> supportedCompositors() const override {
|
||||
return QVector<CompositingType>{QPainterCompositing};
|
||||
}
|
||||
|
@ -86,8 +105,9 @@ private:
|
|||
void openFrameBuffer();
|
||||
bool handleScreenInfo();
|
||||
void initImageFormat();
|
||||
QSize m_resolution;
|
||||
QSize m_physicalSize;
|
||||
|
||||
QVector<FramebufferOutput*> m_outputs;
|
||||
|
||||
QByteArray m_id;
|
||||
struct Color {
|
||||
quint32 offset;
|
||||
|
|
|
@ -31,19 +31,19 @@ namespace KWin
|
|||
FramebufferQPainterBackend::FramebufferQPainterBackend(FramebufferBackend *backend)
|
||||
: QObject()
|
||||
, QPainterBackend()
|
||||
, m_renderBuffer(backend->size(), QImage::Format_RGB32)
|
||||
, m_renderBuffer(backend->screenSize(), QImage::Format_RGB32)
|
||||
, m_backend(backend)
|
||||
, m_needsFullRepaint(true)
|
||||
{
|
||||
m_renderBuffer.fill(Qt::black);
|
||||
|
||||
m_backend->map();
|
||||
|
||||
m_backBuffer = QImage((uchar*)backend->mappedMemory(),
|
||||
backend->bytesPerLine() / (backend->bitsPerPixel() / 8),
|
||||
backend->bufferSize() / backend->bytesPerLine(),
|
||||
backend->bytesPerLine(), backend->imageFormat());
|
||||
|
||||
m_backBuffer = QImage((uchar*)m_backend->mappedMemory(),
|
||||
m_backend->bytesPerLine() / (m_backend->bitsPerPixel() / 8),
|
||||
m_backend->bufferSize() / m_backend->bytesPerLine(),
|
||||
m_backend->bytesPerLine(), m_backend->imageFormat());
|
||||
m_backBuffer.fill(Qt::black);
|
||||
|
||||
connect(VirtualTerminal::self(), &VirtualTerminal::activeChanged, this,
|
||||
[this] (bool active) {
|
||||
if (active) {
|
||||
|
@ -58,27 +58,37 @@ FramebufferQPainterBackend::FramebufferQPainterBackend(FramebufferBackend *backe
|
|||
|
||||
FramebufferQPainterBackend::~FramebufferQPainterBackend() = default;
|
||||
|
||||
QImage *FramebufferQPainterBackend::buffer()
|
||||
QImage* FramebufferQPainterBackend::buffer()
|
||||
{
|
||||
return bufferForScreen(0);
|
||||
}
|
||||
|
||||
QImage* FramebufferQPainterBackend::bufferForScreen(int screenId)
|
||||
{
|
||||
Q_UNUSED(screenId)
|
||||
return &m_renderBuffer;
|
||||
}
|
||||
|
||||
bool FramebufferQPainterBackend::needsFullRepaint() const
|
||||
{
|
||||
return false;
|
||||
return m_needsFullRepaint;
|
||||
}
|
||||
|
||||
void FramebufferQPainterBackend::prepareRenderingFrame()
|
||||
{
|
||||
m_needsFullRepaint = true;
|
||||
}
|
||||
|
||||
void FramebufferQPainterBackend::present(int mask, const QRegion &damage)
|
||||
{
|
||||
Q_UNUSED(mask)
|
||||
Q_UNUSED(damage)
|
||||
|
||||
if (!LogindIntegration::self()->isActiveSession()) {
|
||||
return;
|
||||
}
|
||||
m_needsFullRepaint = false;
|
||||
|
||||
QPainter p(&m_backBuffer);
|
||||
p.drawImage(QPoint(0, 0), m_backend->isBGR() ? m_renderBuffer.rgbSwapped() : m_renderBuffer);
|
||||
}
|
||||
|
@ -88,4 +98,9 @@ bool FramebufferQPainterBackend::usesOverlayWindow() const
|
|||
return false;
|
||||
}
|
||||
|
||||
bool FramebufferQPainterBackend::perScreenRendering() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,15 +36,25 @@ public:
|
|||
virtual ~FramebufferQPainterBackend();
|
||||
|
||||
QImage *buffer() override;
|
||||
QImage *bufferForScreen(int screenId) override;
|
||||
bool needsFullRepaint() const override;
|
||||
bool usesOverlayWindow() const override;
|
||||
void prepareRenderingFrame() override;
|
||||
void present(int mask, const QRegion &damage) override;
|
||||
bool perScreenRendering() const override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief mapped memory buffer on fb device
|
||||
*/
|
||||
QImage m_renderBuffer;
|
||||
/**
|
||||
* @brief buffer to draw into
|
||||
*/
|
||||
QImage m_backBuffer;
|
||||
|
||||
FramebufferBackend *m_backend;
|
||||
bool m_needsFullRepaint;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue