2015-04-10 08:44:07 +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 "egl_gbm_backend.h"
|
|
|
|
// kwin
|
|
|
|
#include "composite.h"
|
|
|
|
#include "drm_backend.h"
|
2016-03-21 14:11:17 +00:00
|
|
|
#include "drm_output.h"
|
2017-10-05 16:58:57 +00:00
|
|
|
#include "gbm_surface.h"
|
2015-05-05 15:27:03 +00:00
|
|
|
#include "logging.h"
|
2015-04-10 08:44:07 +00:00
|
|
|
#include "options.h"
|
|
|
|
#include "screens.h"
|
|
|
|
// kwin libs
|
|
|
|
#include <kwinglplatform.h>
|
|
|
|
// Qt
|
|
|
|
#include <QOpenGLContext>
|
|
|
|
// system
|
|
|
|
#include <gbm.h>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
EglGbmBackend::EglGbmBackend(DrmBackend *b)
|
2017-09-03 08:26:20 +00:00
|
|
|
: AbstractEglBackend()
|
2015-04-10 08:44:07 +00:00
|
|
|
, m_backend(b)
|
|
|
|
{
|
|
|
|
// Egl is always direct rendering
|
|
|
|
setIsDirectRendering(true);
|
2015-07-17 18:39:37 +00:00
|
|
|
setSyncsToVBlank(true);
|
2015-04-24 08:05:38 +00:00
|
|
|
connect(m_backend, &DrmBackend::outputAdded, this, &EglGbmBackend::createOutput);
|
|
|
|
connect(m_backend, &DrmBackend::outputRemoved, this,
|
|
|
|
[this] (DrmOutput *output) {
|
|
|
|
auto it = std::find_if(m_outputs.begin(), m_outputs.end(),
|
|
|
|
[output] (const Output &o) {
|
|
|
|
return o.output == output;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (it == m_outputs.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cleanupOutput(*it);
|
|
|
|
m_outputs.erase(it);
|
|
|
|
}
|
|
|
|
);
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EglGbmBackend::~EglGbmBackend()
|
|
|
|
{
|
|
|
|
cleanup();
|
|
|
|
}
|
|
|
|
|
2015-04-17 13:48:55 +00:00
|
|
|
void EglGbmBackend::cleanupSurfaces()
|
|
|
|
{
|
|
|
|
for (auto it = m_outputs.constBegin(); it != m_outputs.constEnd(); ++it) {
|
2015-04-24 08:05:38 +00:00
|
|
|
cleanupOutput(*it);
|
|
|
|
}
|
2017-10-05 16:58:57 +00:00
|
|
|
m_outputs.clear();
|
2015-04-24 08:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EglGbmBackend::cleanupOutput(const Output &o)
|
|
|
|
{
|
[DRM plugin] Remember static kernel objects, amplify use of DrmCrtc
To get an image from KWin to the screen in the DRM pipeline we combine a CRTC,
an encoder and a connector. These objects are static in the sense, that they
represent real hardware on the graphics card, which doesn't change in a
session. See here for more details:
https://01.org/linuxgraphics/gfx-docs/drm/gpu/drm-kms.html
Until now we used DrmOutput as the main representation for such an active
rendering pipeline. I.e. it gets created and destroyed on hot plug events of
displays. On the other side we had no fixed representation of the static kernel
objects throughout the lifetime of KWin. This has several disadvantages:
* We always need to query all available static objects on an hot plug event.
* We can't manipulate the frame buffer of a CRTC after an output has been
disconnected
* Adding functionality for driving multiple displays on a single CRTC (i.e.
cloning) would be difficult
* We can't destroy the last frame buffer on display disconnect because the CRTC
still accesses it and have therefore a memory leak on every display disconnect
This patch solves these issues by storing representations of all available CRTC
and Connector objects in DrmBackend on init via DrmCrtc and DrmConnector
instances. On an hotplug event these vectors are looped for a fitting CRTC and
Connector combinations. Buffer handling is moved to the respective CRTC
instance. All changes in overview:
* Query all available CRTCs and Connectors and save for subsequent hotplug
events
* Fix logic errors in `queryResources()`
* Move framebuffers, buffer flip and blank logic in DrmCrtc
* Remove `restoreSaved()`. It isn't necessary and is dangerous if the old
framebuffer was deleted in the meantime. Also could reveal sensitive user
info from old session.
Test Plan:
Login, logout, VT switching, connect and disconnect external monitor, energy
saving mode.
Reviewers: #kwin
Subscribers: kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D5118
2017-05-09 18:02:49 +00:00
|
|
|
o.output->releaseGbm();
|
2017-03-17 19:31:06 +00:00
|
|
|
|
2015-04-24 08:05:38 +00:00
|
|
|
if (o.eglSurface != EGL_NO_SURFACE) {
|
|
|
|
eglDestroySurface(eglDisplay(), o.eglSurface);
|
|
|
|
}
|
2015-04-17 13:48:55 +00:00
|
|
|
}
|
|
|
|
|
2015-04-10 08:44:07 +00:00
|
|
|
bool EglGbmBackend::initializeEgl()
|
|
|
|
{
|
|
|
|
initClientExtensions();
|
2016-07-18 08:27:56 +00:00
|
|
|
EGLDisplay display = m_backend->sceneEglDisplay();
|
2015-04-10 08:44:07 +00:00
|
|
|
|
|
|
|
// Use eglGetPlatformDisplayEXT() to get the display pointer
|
|
|
|
// if the implementation supports it.
|
2016-07-18 08:27:56 +00:00
|
|
|
if (display == EGL_NO_DISPLAY) {
|
check for EGL_KHR_platform_gbm extension as well
Summary:
some drivers, like Mali have EGL_KHR_platform_gbm
but not EGL_MESA_platform_gbm
Test Plan: pending a test on rock64 board
Reviewers: #kwin, #plasma, davidedmundson, graesslin
Reviewed By: #kwin, #plasma, graesslin
Subscribers: graesslin, garg, davidedmundson, plasma-devel, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D10346
2018-02-15 10:41:10 +00:00
|
|
|
const bool hasMesaGBM = hasClientExtension(QByteArrayLiteral("EGL_MESA_platform_gbm"));
|
|
|
|
const bool hasKHRGBM = hasClientExtension(QByteArrayLiteral("EGL_KHR_platform_gbm"));
|
|
|
|
const GLenum platform = hasMesaGBM ? EGL_PLATFORM_GBM_MESA : EGL_PLATFORM_GBM_KHR;
|
|
|
|
|
2016-07-18 08:27:56 +00:00
|
|
|
if (!hasClientExtension(QByteArrayLiteral("EGL_EXT_platform_base")) ||
|
check for EGL_KHR_platform_gbm extension as well
Summary:
some drivers, like Mali have EGL_KHR_platform_gbm
but not EGL_MESA_platform_gbm
Test Plan: pending a test on rock64 board
Reviewers: #kwin, #plasma, davidedmundson, graesslin
Reviewed By: #kwin, #plasma, graesslin
Subscribers: graesslin, garg, davidedmundson, plasma-devel, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D10346
2018-02-15 10:41:10 +00:00
|
|
|
(!hasMesaGBM && !hasKHRGBM)) {
|
|
|
|
setFailed("missing one or more extensions between EGL_EXT_platform_base, EGL_MESA_platform_gbm, EGL_KHR_platform_gbm");
|
2016-07-18 08:27:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-04-10 08:44:07 +00:00
|
|
|
|
2016-08-19 14:09:18 +00:00
|
|
|
auto device = gbm_create_device(m_backend->fd());
|
|
|
|
if (!device) {
|
2016-07-18 08:27:56 +00:00
|
|
|
setFailed("Could not create gbm device");
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-19 14:09:18 +00:00
|
|
|
m_backend->setGbmDevice(device);
|
2015-04-10 08:44:07 +00:00
|
|
|
|
check for EGL_KHR_platform_gbm extension as well
Summary:
some drivers, like Mali have EGL_KHR_platform_gbm
but not EGL_MESA_platform_gbm
Test Plan: pending a test on rock64 board
Reviewers: #kwin, #plasma, davidedmundson, graesslin
Reviewed By: #kwin, #plasma, graesslin
Subscribers: graesslin, garg, davidedmundson, plasma-devel, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D10346
2018-02-15 10:41:10 +00:00
|
|
|
display = eglGetPlatformDisplayEXT(platform, device, nullptr);
|
2016-07-18 08:27:56 +00:00
|
|
|
}
|
2015-04-10 08:44:07 +00:00
|
|
|
|
|
|
|
if (display == EGL_NO_DISPLAY)
|
|
|
|
return false;
|
|
|
|
setEglDisplay(display);
|
|
|
|
return initEglAPI();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EglGbmBackend::init()
|
|
|
|
{
|
2015-11-25 12:09:28 +00:00
|
|
|
if (!initializeEgl()) {
|
|
|
|
setFailed("Could not initialize egl");
|
|
|
|
return;
|
|
|
|
}
|
2015-04-10 08:44:07 +00:00
|
|
|
if (!initRenderingContext()) {
|
|
|
|
setFailed("Could not initialize rendering context");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
initKWinGL();
|
|
|
|
initBufferAge();
|
|
|
|
initWayland();
|
GBM remote access support for KWin
Summary:
Implements a KWayland protocol to pass GBM fd from KWin to KRfb and
addictions to relevant projects from both sides.
Note that this patch does not affect default behaviour of mentioned projects. It can be used
only with KWIN_REMOTE=1 in env from KWin side and with preferredFrameBufferPlugin=gbm in krfbrc from
KRfb side. In all other aspects app behaviour remains unchanged.
Test Plan: Launched KWin in Wayland mode, launched KRfb in it, launched KRDC on a laptop, connected in read-only mode, observed a correctly retrieved desktop with Krfb window
Reviewers: graesslin, davidedmundson, romangg, #kwin
Reviewed By: davidedmundson, romangg, #kwin
Subscribers: kossebau, jgrulich, romangg, ngraham, alexeymin, aacid, kwin, #kwin, davidedmundson, plasma-devel
Tags: #plasma_on_wayland, #kwin
Maniphest Tasks: T5653, T7785
Differential Revision: https://phabricator.kde.org/D1230
2016-04-30 23:01:44 +00:00
|
|
|
initRemotePresent();
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool EglGbmBackend::initRenderingContext()
|
|
|
|
{
|
|
|
|
initBufferConfigs();
|
|
|
|
|
2015-11-13 07:29:49 +00:00
|
|
|
if (!createContext()) {
|
|
|
|
return false;
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
|
|
|
|
2015-04-17 13:48:55 +00:00
|
|
|
const auto outputs = m_backend->outputs();
|
|
|
|
for (DrmOutput *drmOutput: outputs) {
|
2015-04-24 08:05:38 +00:00
|
|
|
createOutput(drmOutput);
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
2015-04-17 13:48:55 +00:00
|
|
|
if (m_outputs.isEmpty()) {
|
2015-05-05 15:27:03 +00:00
|
|
|
qCCritical(KWIN_DRM) << "Create Window Surfaces failed";
|
2015-04-10 08:44:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-04-17 13:48:55 +00:00
|
|
|
// set our first surface as the one for the abstract backend, just to make it happy
|
|
|
|
setSurface(m_outputs.first().eglSurface);
|
2015-04-10 08:44:07 +00:00
|
|
|
|
2015-04-17 13:48:55 +00:00
|
|
|
return makeContextCurrent(m_outputs.first());
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
|
|
|
|
GBM remote access support for KWin
Summary:
Implements a KWayland protocol to pass GBM fd from KWin to KRfb and
addictions to relevant projects from both sides.
Note that this patch does not affect default behaviour of mentioned projects. It can be used
only with KWIN_REMOTE=1 in env from KWin side and with preferredFrameBufferPlugin=gbm in krfbrc from
KRfb side. In all other aspects app behaviour remains unchanged.
Test Plan: Launched KWin in Wayland mode, launched KRfb in it, launched KRDC on a laptop, connected in read-only mode, observed a correctly retrieved desktop with Krfb window
Reviewers: graesslin, davidedmundson, romangg, #kwin
Reviewed By: davidedmundson, romangg, #kwin
Subscribers: kossebau, jgrulich, romangg, ngraham, alexeymin, aacid, kwin, #kwin, davidedmundson, plasma-devel
Tags: #plasma_on_wayland, #kwin
Maniphest Tasks: T5653, T7785
Differential Revision: https://phabricator.kde.org/D1230
2016-04-30 23:01:44 +00:00
|
|
|
void EglGbmBackend::initRemotePresent()
|
|
|
|
{
|
|
|
|
if (qEnvironmentVariableIsSet("KWIN_NO_REMOTE")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qCDebug(KWIN_DRM) << "Support for remote access enabled";
|
|
|
|
m_remoteaccessManager.reset(new RemoteAccessManager);
|
|
|
|
}
|
|
|
|
|
2017-10-21 13:16:41 +00:00
|
|
|
bool EglGbmBackend::resetOutput(Output &o, DrmOutput *drmOutput)
|
2015-04-24 08:05:38 +00:00
|
|
|
{
|
|
|
|
o.output = drmOutput;
|
2016-11-24 20:48:21 +00:00
|
|
|
auto size = drmOutput->pixelSize();
|
|
|
|
|
2017-10-21 13:16:41 +00:00
|
|
|
auto gbmSurface = std::make_shared<GbmSurface>(m_backend->gbmDevice(), size.width(), size.height(),
|
2015-04-24 08:05:38 +00:00
|
|
|
GBM_FORMAT_XRGB8888, GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
|
2017-10-21 13:16:41 +00:00
|
|
|
if (!gbmSurface) {
|
2015-05-05 15:27:03 +00:00
|
|
|
qCCritical(KWIN_DRM) << "Create gbm surface failed";
|
2017-10-21 13:16:41 +00:00
|
|
|
return false;
|
2015-04-24 08:05:38 +00:00
|
|
|
}
|
2017-10-21 13:16:41 +00:00
|
|
|
auto eglSurface = eglCreatePlatformWindowSurfaceEXT(eglDisplay(), config(), (void *)(gbmSurface->surface()), nullptr);
|
|
|
|
if (eglSurface == EGL_NO_SURFACE) {
|
2015-05-05 15:27:03 +00:00
|
|
|
qCCritical(KWIN_DRM) << "Create Window Surface failed";
|
2017-10-21 13:16:41 +00:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
// destroy previous surface
|
|
|
|
if (o.eglSurface != EGL_NO_SURFACE) {
|
2017-11-10 19:38:33 +00:00
|
|
|
if (surface() == o.eglSurface) {
|
|
|
|
setSurface(eglSurface);
|
|
|
|
}
|
2017-10-31 16:05:26 +00:00
|
|
|
eglDestroySurface(eglDisplay(), o.eglSurface);
|
2017-10-21 13:16:41 +00:00
|
|
|
}
|
|
|
|
o.eglSurface = eglSurface;
|
|
|
|
o.gbmSurface = gbmSurface;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EglGbmBackend::createOutput(DrmOutput *drmOutput)
|
|
|
|
{
|
|
|
|
Output o;
|
|
|
|
if (resetOutput(o, drmOutput)) {
|
|
|
|
connect(drmOutput, &DrmOutput::modeChanged, this,
|
|
|
|
[drmOutput, this] {
|
|
|
|
auto it = std::find_if(m_outputs.begin(), m_outputs.end(),
|
|
|
|
[drmOutput] (const auto &o) {
|
|
|
|
return o.output == drmOutput;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (it == m_outputs.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resetOutput(*it, drmOutput);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
m_outputs << o;
|
2015-04-24 08:05:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-17 13:48:55 +00:00
|
|
|
bool EglGbmBackend::makeContextCurrent(const Output &output)
|
2015-04-10 08:44:07 +00:00
|
|
|
{
|
2015-04-17 13:48:55 +00:00
|
|
|
const EGLSurface surface = output.eglSurface;
|
|
|
|
if (surface == EGL_NO_SURFACE) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (eglMakeCurrent(eglDisplay(), surface, surface, context()) == EGL_FALSE) {
|
2015-05-05 15:27:03 +00:00
|
|
|
qCCritical(KWIN_DRM) << "Make Context Current failed";
|
2015-04-10 08:44:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLint error = eglGetError();
|
|
|
|
if (error != EGL_SUCCESS) {
|
2015-05-05 15:27:03 +00:00
|
|
|
qCWarning(KWIN_DRM) << "Error occurred while creating context " << error;
|
2015-04-10 08:44:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-04-17 13:48:55 +00:00
|
|
|
// TODO: ensure the viewport is set correctly each time
|
|
|
|
const QSize &overall = screens()->size();
|
|
|
|
const QRect &v = output.output->geometry();
|
|
|
|
// TODO: are the values correct?
|
2016-11-24 20:48:21 +00:00
|
|
|
|
|
|
|
qreal scale = output.output->scale();
|
|
|
|
|
2017-10-25 17:03:22 +00:00
|
|
|
glViewport(-v.x() * scale, (v.height() - overall.height() + v.y()) * scale,
|
2016-11-24 20:48:21 +00:00
|
|
|
overall.width() * scale, overall.height() * scale);
|
2015-04-10 08:44:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EglGbmBackend::initBufferConfigs()
|
|
|
|
{
|
|
|
|
const EGLint config_attribs[] = {
|
|
|
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
|
|
|
EGL_RED_SIZE, 1,
|
|
|
|
EGL_GREEN_SIZE, 1,
|
|
|
|
EGL_BLUE_SIZE, 1,
|
|
|
|
EGL_ALPHA_SIZE, 0,
|
2015-10-30 11:56:03 +00:00
|
|
|
EGL_RENDERABLE_TYPE, isOpenGLES() ? EGL_OPENGL_ES2_BIT : EGL_OPENGL_BIT,
|
2015-04-10 08:44:07 +00:00
|
|
|
EGL_CONFIG_CAVEAT, EGL_NONE,
|
|
|
|
EGL_NONE,
|
|
|
|
};
|
|
|
|
|
|
|
|
EGLint count;
|
|
|
|
EGLConfig configs[1024];
|
drm backend: choose correct EGL config with mesa-18
Summary:
Do not blindly select first EGL config from returned list, but choose the one that matches GBM surfaces, that will be created later.
GBM surfaces are created with GBM_FORMAT_XRGB8888 format, so choose the config that matches it.
With wrong format EglGbmBackend::resetOutput() will later fail with error EGL_BAD_MATCH.
Test Plan: Compile, run startplasmacompositor. Verify that OpenGL compositing is used, either by kwin debug console, or by kwin support information.
Reviewers: graesslin, davidedmundson, #kwin, #plasma_on_wayland, bshah
Reviewed By: davidedmundson
Subscribers: zzag, kwin, #kwin
Tags: #kwin, #plasma_on_wayland
Differential Revision: https://phabricator.kde.org/D11758
2018-04-04 22:20:46 +00:00
|
|
|
if (!eglChooseConfig(eglDisplay(), config_attribs, configs, sizeof(configs)/sizeof(EGLConfig), &count)) {
|
2015-05-05 15:27:03 +00:00
|
|
|
qCCritical(KWIN_DRM) << "choose config failed";
|
2015-04-10 08:44:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
drm backend: choose correct EGL config with mesa-18
Summary:
Do not blindly select first EGL config from returned list, but choose the one that matches GBM surfaces, that will be created later.
GBM surfaces are created with GBM_FORMAT_XRGB8888 format, so choose the config that matches it.
With wrong format EglGbmBackend::resetOutput() will later fail with error EGL_BAD_MATCH.
Test Plan: Compile, run startplasmacompositor. Verify that OpenGL compositing is used, either by kwin debug console, or by kwin support information.
Reviewers: graesslin, davidedmundson, #kwin, #plasma_on_wayland, bshah
Reviewed By: davidedmundson
Subscribers: zzag, kwin, #kwin
Tags: #kwin, #plasma_on_wayland
Differential Revision: https://phabricator.kde.org/D11758
2018-04-04 22:20:46 +00:00
|
|
|
|
|
|
|
qCDebug(KWIN_DRM) << "EGL buffer configs count:" << count;
|
|
|
|
|
|
|
|
// loop through all configs, chosing the first one that has suitable format
|
|
|
|
for (EGLint i = 0; i < count; i++) {
|
|
|
|
EGLint gbmFormat;
|
|
|
|
// query some configuration parameters, to show in debug log
|
|
|
|
eglGetConfigAttrib(eglDisplay(), configs[i], EGL_NATIVE_VISUAL_ID, &gbmFormat);
|
|
|
|
|
|
|
|
if (KWIN_DRM().isDebugEnabled()) {
|
|
|
|
// GBM formats are declared as FOURCC code (integer from ASCII chars, so use this fact)
|
|
|
|
char gbmFormatStr[sizeof(EGLint) + 1] = {0};
|
|
|
|
memcpy(gbmFormatStr, &gbmFormat, sizeof(EGLint));
|
|
|
|
// query number of bits for color channel
|
|
|
|
EGLint blueSize, redSize, greenSize, alphaSize;
|
|
|
|
eglGetConfigAttrib(eglDisplay(), configs[i], EGL_RED_SIZE, &redSize);
|
|
|
|
eglGetConfigAttrib(eglDisplay(), configs[i], EGL_GREEN_SIZE, &greenSize);
|
|
|
|
eglGetConfigAttrib(eglDisplay(), configs[i], EGL_BLUE_SIZE, &blueSize);
|
|
|
|
eglGetConfigAttrib(eglDisplay(), configs[i], EGL_ALPHA_SIZE, &alphaSize);
|
|
|
|
qCDebug(KWIN_DRM) << " EGL config #" << i << " has GBM FOURCC format:" << gbmFormatStr
|
|
|
|
<< "; color sizes (RGBA order):" << redSize << greenSize << blueSize << alphaSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((gbmFormat == GBM_FORMAT_XRGB8888) || (gbmFormat == GBM_FORMAT_ARGB8888)) {
|
|
|
|
setConfig(configs[i]);
|
|
|
|
return true;
|
|
|
|
}
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
|
|
|
|
drm backend: choose correct EGL config with mesa-18
Summary:
Do not blindly select first EGL config from returned list, but choose the one that matches GBM surfaces, that will be created later.
GBM surfaces are created with GBM_FORMAT_XRGB8888 format, so choose the config that matches it.
With wrong format EglGbmBackend::resetOutput() will later fail with error EGL_BAD_MATCH.
Test Plan: Compile, run startplasmacompositor. Verify that OpenGL compositing is used, either by kwin debug console, or by kwin support information.
Reviewers: graesslin, davidedmundson, #kwin, #plasma_on_wayland, bshah
Reviewed By: davidedmundson
Subscribers: zzag, kwin, #kwin
Tags: #kwin, #plasma_on_wayland
Differential Revision: https://phabricator.kde.org/D11758
2018-04-04 22:20:46 +00:00
|
|
|
qCCritical(KWIN_DRM) << "choose EGL config did not return a suitable config" << count;
|
|
|
|
return false;
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EglGbmBackend::present()
|
|
|
|
{
|
2015-04-17 13:48:55 +00:00
|
|
|
for (auto &o: m_outputs) {
|
|
|
|
makeContextCurrent(o);
|
2015-04-23 07:55:49 +00:00
|
|
|
presentOnOutput(o);
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-23 07:55:49 +00:00
|
|
|
void EglGbmBackend::presentOnOutput(EglGbmBackend::Output &o)
|
|
|
|
{
|
|
|
|
eglSwapBuffers(eglDisplay(), o.eglSurface);
|
|
|
|
o.buffer = m_backend->createBuffer(o.gbmSurface);
|
GBM remote access support for KWin
Summary:
Implements a KWayland protocol to pass GBM fd from KWin to KRfb and
addictions to relevant projects from both sides.
Note that this patch does not affect default behaviour of mentioned projects. It can be used
only with KWIN_REMOTE=1 in env from KWin side and with preferredFrameBufferPlugin=gbm in krfbrc from
KRfb side. In all other aspects app behaviour remains unchanged.
Test Plan: Launched KWin in Wayland mode, launched KRfb in it, launched KRDC on a laptop, connected in read-only mode, observed a correctly retrieved desktop with Krfb window
Reviewers: graesslin, davidedmundson, romangg, #kwin
Reviewed By: davidedmundson, romangg, #kwin
Subscribers: kossebau, jgrulich, romangg, ngraham, alexeymin, aacid, kwin, #kwin, davidedmundson, plasma-devel
Tags: #plasma_on_wayland, #kwin
Maniphest Tasks: T5653, T7785
Differential Revision: https://phabricator.kde.org/D1230
2016-04-30 23:01:44 +00:00
|
|
|
if(m_remoteaccessManager && gbm_surface_has_free_buffers(o.gbmSurface->surface())) {
|
|
|
|
// GBM surface is released on page flip so
|
|
|
|
// we should pass the buffer before it's presented
|
|
|
|
m_remoteaccessManager->passBuffer(o.output, o.buffer);
|
|
|
|
}
|
2015-04-23 07:55:49 +00:00
|
|
|
m_backend->present(o.buffer, o.output);
|
GBM remote access support for KWin
Summary:
Implements a KWayland protocol to pass GBM fd from KWin to KRfb and
addictions to relevant projects from both sides.
Note that this patch does not affect default behaviour of mentioned projects. It can be used
only with KWIN_REMOTE=1 in env from KWin side and with preferredFrameBufferPlugin=gbm in krfbrc from
KRfb side. In all other aspects app behaviour remains unchanged.
Test Plan: Launched KWin in Wayland mode, launched KRfb in it, launched KRDC on a laptop, connected in read-only mode, observed a correctly retrieved desktop with Krfb window
Reviewers: graesslin, davidedmundson, romangg, #kwin
Reviewed By: davidedmundson, romangg, #kwin
Subscribers: kossebau, jgrulich, romangg, ngraham, alexeymin, aacid, kwin, #kwin, davidedmundson, plasma-devel
Tags: #plasma_on_wayland, #kwin
Maniphest Tasks: T5653, T7785
Differential Revision: https://phabricator.kde.org/D1230
2016-04-30 23:01:44 +00:00
|
|
|
|
2015-04-23 07:55:49 +00:00
|
|
|
if (supportsBufferAge()) {
|
|
|
|
eglQuerySurface(eglDisplay(), o.eglSurface, EGL_BUFFER_AGE_EXT, &o.bufferAge);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-10 08:44:07 +00:00
|
|
|
void EglGbmBackend::screenGeometryChanged(const QSize &size)
|
|
|
|
{
|
|
|
|
Q_UNUSED(size)
|
|
|
|
// TODO, create new buffer?
|
|
|
|
}
|
|
|
|
|
2017-09-08 20:30:18 +00:00
|
|
|
SceneOpenGLTexturePrivate *EglGbmBackend::createBackendTexture(SceneOpenGLTexture *texture)
|
2015-04-10 08:44:07 +00:00
|
|
|
{
|
|
|
|
return new EglGbmTexture(texture, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
QRegion EglGbmBackend::prepareRenderingFrame()
|
|
|
|
{
|
2015-04-23 07:55:49 +00:00
|
|
|
startRenderTimer();
|
|
|
|
return QRegion();
|
|
|
|
}
|
|
|
|
|
|
|
|
QRegion EglGbmBackend::prepareRenderingForScreen(int screenId)
|
|
|
|
{
|
|
|
|
const Output &o = m_outputs.at(screenId);
|
|
|
|
makeContextCurrent(o);
|
2015-04-17 13:48:55 +00:00
|
|
|
if (supportsBufferAge()) {
|
2015-04-23 07:55:49 +00:00
|
|
|
QRegion region;
|
|
|
|
|
|
|
|
// Note: An age of zero means the buffer contents are undefined
|
|
|
|
if (o.bufferAge > 0 && o.bufferAge <= o.damageHistory.count()) {
|
|
|
|
for (int i = 0; i < o.bufferAge - 1; i++)
|
|
|
|
region |= o.damageHistory[i];
|
|
|
|
} else {
|
|
|
|
region = o.output->geometry();
|
2015-04-17 13:48:55 +00:00
|
|
|
}
|
2015-04-23 07:55:49 +00:00
|
|
|
|
|
|
|
return region;
|
2015-04-17 13:48:55 +00:00
|
|
|
}
|
2015-04-23 07:55:49 +00:00
|
|
|
return QRegion();
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
|
|
|
|
2015-04-23 07:55:49 +00:00
|
|
|
void EglGbmBackend::endRenderingFrame(const QRegion &renderedRegion, const QRegion &damagedRegion)
|
2015-04-17 13:48:55 +00:00
|
|
|
{
|
2015-04-23 07:55:49 +00:00
|
|
|
Q_UNUSED(renderedRegion)
|
|
|
|
Q_UNUSED(damagedRegion)
|
2015-04-17 13:48:55 +00:00
|
|
|
}
|
|
|
|
|
2015-04-23 07:55:49 +00:00
|
|
|
void EglGbmBackend::endRenderingFrameForScreen(int screenId, const QRegion &renderedRegion, const QRegion &damagedRegion)
|
2015-04-10 08:44:07 +00:00
|
|
|
{
|
2015-04-23 07:55:49 +00:00
|
|
|
Output &o = m_outputs[screenId];
|
|
|
|
if (damagedRegion.intersected(o.output->geometry()).isEmpty() && screenId == 0) {
|
2015-04-10 08:44:07 +00:00
|
|
|
|
|
|
|
// If the damaged region of a window is fully occluded, the only
|
|
|
|
// rendering done, if any, will have been to repair a reused back
|
|
|
|
// buffer, making it identical to the front buffer.
|
|
|
|
//
|
|
|
|
// In this case we won't post the back buffer. Instead we'll just
|
|
|
|
// set the buffer age to 1, so the repaired regions won't be
|
|
|
|
// rendered again in the next frame.
|
2015-04-23 07:55:49 +00:00
|
|
|
if (!renderedRegion.intersected(o.output->geometry()).isEmpty())
|
2015-04-10 08:44:07 +00:00
|
|
|
glFlush();
|
|
|
|
|
2015-04-17 13:48:55 +00:00
|
|
|
for (auto &o: m_outputs) {
|
|
|
|
o.bufferAge = 1;
|
|
|
|
}
|
2015-04-10 08:44:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-04-23 07:55:49 +00:00
|
|
|
presentOnOutput(o);
|
2015-04-10 08:44:07 +00:00
|
|
|
|
|
|
|
// Save the damaged region to history
|
2015-04-23 07:55:49 +00:00
|
|
|
// Note: damage history is only collected for the first screen. For any other screen full repaints
|
|
|
|
// are triggered. This is due to a limitation in Scene::paintGenericScreen which resets the Toplevel's
|
|
|
|
// repaint. So multiple calls to Scene::paintScreen as it's done in multi-output rendering only
|
|
|
|
// have correct damage information for the first screen. If we try to track damage nevertheless,
|
|
|
|
// it creates artifacts. So for the time being we work around the problem by only supporting buffer
|
|
|
|
// age on the first output. To properly support buffer age on all outputs the rendering needs to
|
|
|
|
// be refactored in general.
|
|
|
|
if (supportsBufferAge() && screenId == 0) {
|
|
|
|
if (o.damageHistory.count() > 10) {
|
|
|
|
o.damageHistory.removeLast();
|
|
|
|
}
|
|
|
|
|
|
|
|
o.damageHistory.prepend(damagedRegion.intersected(o.output->geometry()));
|
|
|
|
}
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool EglGbmBackend::usesOverlayWindow() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-17 13:48:55 +00:00
|
|
|
bool EglGbmBackend::perScreenRendering() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-10 08:44:07 +00:00
|
|
|
/************************************************
|
|
|
|
* EglTexture
|
|
|
|
************************************************/
|
|
|
|
|
2017-09-08 20:30:18 +00:00
|
|
|
EglGbmTexture::EglGbmTexture(KWin::SceneOpenGLTexture *texture, EglGbmBackend *backend)
|
2015-04-10 08:44:07 +00:00
|
|
|
: AbstractEglTexture(texture, backend)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
EglGbmTexture::~EglGbmTexture() = default;
|
|
|
|
|
|
|
|
} // namespace
|