1
/********************************************************************
2
KWin - the KDE window manager
3
This file is part of the KDE project.
5
Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org>
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program. If not, see <http://www.gnu.org/licenses/>.
19
*********************************************************************/
20
#include "fb_backend.h"
21
#include "composite.h"
24
#include "scene_qpainter_fb_backend.h"
25
#include "screens_fb.h"
26
#include "virtual_terminal.h"
30
#include <sys/ioctl.h>
38
FramebufferBackend::FramebufferBackend(QObject *parent)
39
: AbstractBackend(parent)
41
setSoftWareCursor(true);
44
FramebufferBackend::~FramebufferBackend()
52
Screens *FramebufferBackend::createScreens(QObject *parent)
54
return new FramebufferScreens(this, parent);
57
QPainterBackend *FramebufferBackend::createQPainterBackend()
59
return new FramebufferQPainterBackend(this);
62
void FramebufferBackend::init()
64
LogindIntegration *logind = LogindIntegration::self();
65
auto takeControl = [logind, this]() {
66
if (logind->hasSessionControl()) {
69
logind->takeControl();
70
connect(logind, &LogindIntegration::hasSessionControlChanged, this, &FramebufferBackend::openFrameBuffer);
73
if (logind->isConnected()) {
76
connect(logind, &LogindIntegration::connectedChanged, this, takeControl);
78
VirtualTerminal::create(this);
81
void FramebufferBackend::openFrameBuffer()
83
VirtualTerminal::self()->init();
84
int fd = LogindIntegration::self()->takeDevice(deviceIdentifier().constData());
86
qCWarning(KWIN_FB) << "Failed to open frame buffer device through logind, trying without";
88
fd = open(deviceIdentifier().constData(), O_RDWR | O_CLOEXEC);
90
qCWarning(KWIN_FB) << "failed to open frame buffer device";
96
emit screensQueried();
99
bool FramebufferBackend::queryScreenInfo()
105
fb_var_screeninfo varinfo;
106
fb_fix_screeninfo fixinfo;
108
// Probe the device for screen information.
109
if (ioctl(m_fd, FBIOGET_FSCREENINFO, &fixinfo) < 0 || ioctl(m_fd, FBIOGET_VSCREENINFO, &varinfo) < 0) {
112
m_resolution = QSize(varinfo.xres, varinfo.yres);
113
m_physicalSize = QSize(varinfo.width, varinfo.height);
114
m_id = QByteArray(fixinfo.id);
115
m_red = {varinfo.red.offset, varinfo.red.length};
116
m_green = {varinfo.green.offset, varinfo.green.length};
117
m_blue = {varinfo.blue.offset, varinfo.blue.length};
118
m_alpha = {varinfo.transp.offset, varinfo.transp.length};
119
m_bitsPerPixel = varinfo.bits_per_pixel;
120
m_bufferLength = fixinfo.smem_len;
121
m_bytesPerLine = fixinfo.line_length;
126
void FramebufferBackend::map()
136
void *mem = mmap(nullptr, m_bufferLength, PROT_WRITE, MAP_SHARED, m_fd, 0);
137
if (mem == MAP_FAILED) {
138
qCWarning(KWIN_FB) << "Failed to mmap frame buffer";
144
void FramebufferBackend::unmap()
149
if (munmap(m_memory, m_bufferLength) < 0) {
150
qCWarning(KWIN_FB) << "Failed to munmap frame buffer";
155
QImage::Format FramebufferBackend::imageFormat() const
158
return QImage::Format_Invalid;
160
if (m_alpha.length == 0 &&
162
m_green.length == 8 &&
163
m_blue.length == 8 &&
164
m_blue.offset == 0 &&
165
m_green.offset == 8 &&
166
m_red.offset == 16) {
167
return QImage::Format_RGB32;
169
return QImage::Format_Invalid;