2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2015-04-10 08:44:07 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
|
2015-04-10 08:44:07 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2015-04-10 08:44:07 +00:00
|
|
|
#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"
|
2020-10-05 21:05:55 +00:00
|
|
|
#include "drm_gpu.h"
|
2015-04-10 08:44:07 +00:00
|
|
|
// kwin libs
|
|
|
|
#include <kwinglplatform.h>
|
2020-07-22 17:38:57 +00:00
|
|
|
#include <kwineglimagetexture.h>
|
2015-04-10 08:44:07 +00:00
|
|
|
// system
|
|
|
|
#include <gbm.h>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
EglGbmBackend::EglGbmBackend(DrmBackend *drmBackend, DrmGpu *gpu)
|
2017-09-03 08:26:20 +00:00
|
|
|
: AbstractEglBackend()
|
2019-12-10 00:24:45 +00:00
|
|
|
, m_backend(drmBackend)
|
2020-10-05 21:05:55 +00:00
|
|
|
, m_gpu(gpu)
|
2015-04-10 08:44:07 +00:00
|
|
|
{
|
2019-12-10 00:24:45 +00:00
|
|
|
// Egl is always direct rendering.
|
2015-04-10 08:44:07 +00:00
|
|
|
setIsDirectRendering(true);
|
2020-01-09 17:18:22 +00:00
|
|
|
setSyncsToVBlank(true);
|
2020-10-05 21:05:55 +00:00
|
|
|
connect(m_gpu, &DrmGpu::outputEnabled, this, &EglGbmBackend::createOutput);
|
|
|
|
connect(m_gpu, &DrmGpu::outputDisabled, this, &EglGbmBackend::removeOutput);
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EglGbmBackend::~EglGbmBackend()
|
|
|
|
{
|
|
|
|
cleanup();
|
|
|
|
}
|
|
|
|
|
2015-04-17 13:48:55 +00:00
|
|
|
void EglGbmBackend::cleanupSurfaces()
|
|
|
|
{
|
2020-01-02 14:55:09 +00:00
|
|
|
for (auto it = m_outputs.begin(); it != m_outputs.end(); ++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
|
|
|
}
|
|
|
|
|
2020-01-02 14:55:09 +00:00
|
|
|
void EglGbmBackend::cleanupFramebuffer(Output &output)
|
2015-04-24 08:05:38 +00:00
|
|
|
{
|
2020-01-02 14:55:09 +00:00
|
|
|
if (!output.render.framebuffer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
glDeleteTextures(1, &output.render.texture);
|
|
|
|
output.render.texture = 0;
|
|
|
|
glDeleteFramebuffers(1, &output.render.framebuffer);
|
|
|
|
output.render.framebuffer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EglGbmBackend::cleanupOutput(Output &output)
|
|
|
|
{
|
|
|
|
cleanupFramebuffer(output);
|
2019-12-10 00:24:45 +00:00
|
|
|
output.output->releaseGbm();
|
2017-03-17 19:31:06 +00:00
|
|
|
|
2019-12-10 00:24:45 +00:00
|
|
|
if (output.eglSurface != EGL_NO_SURFACE) {
|
|
|
|
eglDestroySurface(eglDisplay(), output.eglSurface);
|
2015-04-24 08:05:38 +00:00
|
|
|
}
|
2015-04-17 13:48:55 +00:00
|
|
|
}
|
|
|
|
|
2015-04-10 08:44:07 +00:00
|
|
|
bool EglGbmBackend::initializeEgl()
|
|
|
|
{
|
|
|
|
initClientExtensions();
|
2020-10-16 13:11:23 +00:00
|
|
|
EGLDisplay display = m_gpu->eglDisplay();
|
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)) {
|
2019-12-10 00:24:45 +00:00
|
|
|
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
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
auto device = gbm_create_device(m_gpu->fd());
|
2016-08-19 14:09:18 +00:00
|
|
|
if (!device) {
|
2016-07-18 08:27:56 +00:00
|
|
|
setFailed("Could not create gbm device");
|
|
|
|
return false;
|
|
|
|
}
|
2020-10-05 21:05:55 +00:00
|
|
|
m_gpu->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);
|
2020-10-16 13:11:23 +00:00
|
|
|
m_gpu->setEglDisplay(display);
|
2016-07-18 08:27:56 +00:00
|
|
|
}
|
2015-04-10 08:44:07 +00:00
|
|
|
|
2019-12-10 00:24:45 +00:00
|
|
|
if (display == EGL_NO_DISPLAY) {
|
2015-04-10 08:44:07 +00:00
|
|
|
return false;
|
2019-12-10 00:24:45 +00:00
|
|
|
}
|
2015-04-10 08:44:07 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EglGbmBackend::initRenderingContext()
|
|
|
|
{
|
|
|
|
initBufferConfigs();
|
2015-11-13 07:29:49 +00:00
|
|
|
if (!createContext()) {
|
|
|
|
return false;
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 23:27:21 +00:00
|
|
|
const auto outputs = m_backend->drmOutputs();
|
2019-12-10 00:24:45 +00:00
|
|
|
|
2015-04-17 13:48:55 +00:00
|
|
|
for (DrmOutput *drmOutput: outputs) {
|
2015-04-24 08:05:38 +00:00
|
|
|
createOutput(drmOutput);
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
2019-12-10 00:24:45 +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;
|
|
|
|
}
|
2019-12-10 00:24:45 +00:00
|
|
|
|
|
|
|
// Set our first surface as the one for the abstract backend, just to make it happy.
|
2015-04-17 13:48:55 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-12-10 00:24:45 +00:00
|
|
|
std::shared_ptr<GbmSurface> EglGbmBackend::createGbmSurface(const QSize &size) const
|
|
|
|
{
|
2020-10-05 21:05:55 +00:00
|
|
|
auto gbmSurface = std::make_shared<GbmSurface>(m_gpu->gbmDevice(),
|
2019-12-10 00:24:45 +00:00
|
|
|
size.width(), size.height(),
|
|
|
|
GBM_FORMAT_XRGB8888,
|
|
|
|
GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
|
|
|
|
if (!gbmSurface) {
|
|
|
|
qCCritical(KWIN_DRM) << "Creating GBM surface failed";
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return gbmSurface;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLSurface EglGbmBackend::createEglSurface(std::shared_ptr<GbmSurface> gbmSurface) const
|
|
|
|
{
|
|
|
|
auto eglSurface = eglCreatePlatformWindowSurfaceEXT(eglDisplay(), config(),
|
|
|
|
(void *)(gbmSurface->surface()), nullptr);
|
|
|
|
if (eglSurface == EGL_NO_SURFACE) {
|
|
|
|
qCCritical(KWIN_DRM) << "Creating EGL surface failed";
|
|
|
|
return EGL_NO_SURFACE;
|
|
|
|
}
|
|
|
|
return eglSurface;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EglGbmBackend::resetOutput(Output &output, DrmOutput *drmOutput)
|
2015-04-24 08:05:38 +00:00
|
|
|
{
|
2019-12-10 00:24:45 +00:00
|
|
|
output.output = drmOutput;
|
2020-01-02 14:55:09 +00:00
|
|
|
const QSize size = drmOutput->hardwareTransforms() ? drmOutput->pixelSize() :
|
|
|
|
drmOutput->modeSize();
|
2016-11-24 20:48:21 +00:00
|
|
|
|
2019-12-10 00:24:45 +00:00
|
|
|
auto gbmSurface = createGbmSurface(size);
|
2017-10-21 13:16:41 +00:00
|
|
|
if (!gbmSurface) {
|
|
|
|
return false;
|
2015-04-24 08:05:38 +00:00
|
|
|
}
|
2019-12-10 00:24:45 +00:00
|
|
|
auto eglSurface = createEglSurface(gbmSurface);
|
2017-10-21 13:16:41 +00:00
|
|
|
if (eglSurface == EGL_NO_SURFACE) {
|
|
|
|
return false;
|
2019-12-10 00:24:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// destroy previous surface
|
|
|
|
if (output.eglSurface != EGL_NO_SURFACE) {
|
|
|
|
if (surface() == output.eglSurface) {
|
|
|
|
setSurface(eglSurface);
|
2017-10-21 13:16:41 +00:00
|
|
|
}
|
2019-12-10 00:24:45 +00:00
|
|
|
eglDestroySurface(eglDisplay(), output.eglSurface);
|
2017-10-21 13:16:41 +00:00
|
|
|
}
|
2019-12-10 00:24:45 +00:00
|
|
|
output.eglSurface = eglSurface;
|
|
|
|
output.gbmSurface = gbmSurface;
|
2020-01-02 14:55:09 +00:00
|
|
|
|
|
|
|
resetFramebuffer(output);
|
2017-10-21 13:16:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EglGbmBackend::createOutput(DrmOutput *drmOutput)
|
|
|
|
{
|
2019-12-10 00:24:45 +00:00
|
|
|
Output newOutput;
|
|
|
|
if (resetOutput(newOutput, drmOutput)) {
|
2017-10-21 13:16:41 +00:00
|
|
|
connect(drmOutput, &DrmOutput::modeChanged, this,
|
|
|
|
[drmOutput, this] {
|
|
|
|
auto it = std::find_if(m_outputs.begin(), m_outputs.end(),
|
2019-12-10 00:24:45 +00:00
|
|
|
[drmOutput] (const auto &output) {
|
|
|
|
return output.output == drmOutput;
|
2017-10-21 13:16:41 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
if (it == m_outputs.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resetOutput(*it, drmOutput);
|
|
|
|
}
|
|
|
|
);
|
2019-12-10 00:24:45 +00:00
|
|
|
m_outputs << newOutput;
|
2015-04-24 08:05:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-10 00:24:45 +00:00
|
|
|
void EglGbmBackend::removeOutput(DrmOutput *drmOutput)
|
|
|
|
{
|
|
|
|
auto it = std::find_if(m_outputs.begin(), m_outputs.end(),
|
|
|
|
[drmOutput] (const Output &output) {
|
|
|
|
return output.output == drmOutput;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (it == m_outputs.end()) {
|
|
|
|
return;
|
|
|
|
}
|
2020-07-22 17:38:57 +00:00
|
|
|
|
2019-12-10 00:24:45 +00:00
|
|
|
cleanupOutput(*it);
|
|
|
|
m_outputs.erase(it);
|
|
|
|
}
|
|
|
|
|
2020-01-02 14:55:09 +00:00
|
|
|
const float vertices[] = {
|
|
|
|
-1.0f, 1.0f,
|
|
|
|
-1.0f, -1.0f,
|
|
|
|
1.0f, -1.0f,
|
|
|
|
|
|
|
|
-1.0f, 1.0f,
|
|
|
|
1.0f, -1.0f,
|
|
|
|
1.0f, 1.0f,
|
|
|
|
};
|
|
|
|
|
|
|
|
const float texCoords[] = {
|
|
|
|
0.0f, 1.0f,
|
|
|
|
0.0f, 0.0f,
|
|
|
|
1.0f, 0.0f,
|
|
|
|
|
|
|
|
0.0f, 1.0f,
|
|
|
|
1.0f, 0.0f,
|
|
|
|
1.0f, 1.0f
|
|
|
|
};
|
|
|
|
|
|
|
|
bool EglGbmBackend::resetFramebuffer(Output &output)
|
|
|
|
{
|
|
|
|
cleanupFramebuffer(output);
|
|
|
|
|
|
|
|
if (output.output->hardwareTransforms()) {
|
|
|
|
// No need for an extra render target.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
makeContextCurrent(output);
|
|
|
|
|
|
|
|
glGenFramebuffers(1, &output.render.framebuffer);
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, output.render.framebuffer);
|
|
|
|
GLRenderTarget::setKWinFramebuffer(output.render.framebuffer);
|
|
|
|
|
|
|
|
glGenTextures(1, &output.render.texture);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, output.render.texture);
|
|
|
|
|
|
|
|
const QSize texSize = output.output->pixelSize();
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texSize.width(), texSize.height(),
|
|
|
|
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
|
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
|
|
|
output.render.texture, 0);
|
|
|
|
|
|
|
|
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
|
|
|
qCWarning(KWIN_DRM) << "Error: framebuffer not complete";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
|
|
GLRenderTarget::setKWinFramebuffer(0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-28 12:22:35 +00:00
|
|
|
void EglGbmBackend::initRenderTarget(Output &output)
|
2020-01-02 14:55:09 +00:00
|
|
|
{
|
2020-02-28 12:22:35 +00:00
|
|
|
if (output.render.vbo) {
|
2020-01-02 14:55:09 +00:00
|
|
|
// Already initialized.
|
2020-02-28 12:22:35 +00:00
|
|
|
return;
|
2020-01-02 14:55:09 +00:00
|
|
|
}
|
|
|
|
std::shared_ptr<GLVertexBuffer> vbo(new GLVertexBuffer(KWin::GLVertexBuffer::Static));
|
|
|
|
vbo->setData(6, 2, vertices, texCoords);
|
|
|
|
output.render.vbo = vbo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EglGbmBackend::renderFramebufferToSurface(Output &output)
|
|
|
|
{
|
|
|
|
if (!output.render.framebuffer) {
|
|
|
|
// No additional render target.
|
|
|
|
return;
|
|
|
|
}
|
2020-02-28 12:22:35 +00:00
|
|
|
initRenderTarget(output);
|
2020-01-02 14:55:09 +00:00
|
|
|
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
|
|
GLRenderTarget::setKWinFramebuffer(0);
|
|
|
|
|
|
|
|
const auto size = output.output->modeSize();
|
|
|
|
glViewport(0, 0, size.width(), size.height());
|
|
|
|
|
2020-02-28 12:22:35 +00:00
|
|
|
auto shader = ShaderManager::instance()->pushShader(ShaderTrait::MapTexture);
|
|
|
|
|
2020-01-02 14:55:09 +00:00
|
|
|
QMatrix4x4 rotationMatrix;
|
|
|
|
rotationMatrix.rotate(output.output->rotation(), 0, 0, 1);
|
2020-02-28 12:22:35 +00:00
|
|
|
shader->setUniform(GLShader::ModelViewProjectionMatrix, rotationMatrix);
|
2020-01-02 14:55:09 +00:00
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, output.render.texture);
|
|
|
|
output.render.vbo->render(GL_TRIANGLES);
|
2020-02-28 12:22:35 +00:00
|
|
|
ShaderManager::instance()->popShader();
|
2020-01-02 14:55:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EglGbmBackend::prepareRenderFramebuffer(const Output &output) const
|
|
|
|
{
|
|
|
|
// When render.framebuffer is 0 we may just reset to the screen framebuffer.
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, output.render.framebuffer);
|
|
|
|
GLRenderTarget::setKWinFramebuffer(output.render.framebuffer);
|
|
|
|
}
|
|
|
|
|
2019-12-10 00:24:45 +00:00
|
|
|
bool EglGbmBackend::makeContextCurrent(const Output &output) const
|
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) {
|
2020-09-23 00:03:45 +00:00
|
|
|
qCCritical(KWIN_DRM) << "Make Context Current failed" << eglGetError();
|
2015-04-10 08:44:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
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];
|
2019-12-10 00:24:45 +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;
|
|
|
|
|
2019-12-10 00:24:45 +00:00
|
|
|
// Loop through all configs, choosing the first one that has suitable format.
|
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
|
|
|
for (EGLint i = 0; i < count; i++) {
|
|
|
|
EGLint gbmFormat;
|
2019-12-10 00:24:45 +00:00
|
|
|
// Query some configuration parameters, to show in debug log.
|
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
|
|
|
eglGetConfigAttrib(eglDisplay(), configs[i], EGL_NATIVE_VISUAL_ID, &gbmFormat);
|
|
|
|
|
|
|
|
if (KWIN_DRM().isDebugEnabled()) {
|
2019-12-10 00:24:45 +00:00
|
|
|
// GBM formats are declared as FOURCC code (integer from ASCII chars, so use this fact).
|
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
|
|
|
char gbmFormatStr[sizeof(EGLint) + 1] = {0};
|
|
|
|
memcpy(gbmFormatStr, &gbmFormat, sizeof(EGLint));
|
2019-12-10 00:24:45 +00:00
|
|
|
|
|
|
|
// Query number of bits for color channel.
|
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
|
|
|
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
|
2019-12-10 00:24:45 +00:00
|
|
|
<< "; color sizes (RGBA order):"
|
|
|
|
<< redSize << greenSize << blueSize << alphaSize;
|
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 ((gbmFormat == GBM_FORMAT_XRGB8888) || (gbmFormat == GBM_FORMAT_ARGB8888)) {
|
|
|
|
setConfig(configs[i]);
|
|
|
|
return true;
|
|
|
|
}
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
|
|
|
|
2019-12-10 00:24:45 +00:00
|
|
|
qCCritical(KWIN_DRM) << "Choosing EGL config did not return a suitable config. There were"
|
|
|
|
<< count << "configs.";
|
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
|
|
|
return false;
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EglGbmBackend::present()
|
|
|
|
{
|
2019-12-10 00:24:45 +00:00
|
|
|
Q_UNREACHABLE();
|
|
|
|
// Not in use. This backend does per-screen rendering.
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 17:11:41 +00:00
|
|
|
static QVector<EGLint> regionToRects(const QRegion ®ion, AbstractWaylandOutput *output)
|
|
|
|
{
|
|
|
|
const int height = output->modeSize().height();
|
|
|
|
|
|
|
|
const QMatrix4x4 matrix = output->transformation();
|
|
|
|
|
|
|
|
QVector<EGLint> rects;
|
|
|
|
rects.reserve(region.rectCount() * 4);
|
|
|
|
for (const QRect &_rect : region) {
|
|
|
|
const QRect rect = matrix.mapRect(_rect);
|
|
|
|
|
|
|
|
rects << rect.left();
|
|
|
|
rects << height - (rect.y() + rect.height());
|
|
|
|
rects << rect.width();
|
|
|
|
rects << rect.height();
|
|
|
|
}
|
|
|
|
return rects;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EglGbmBackend::aboutToStartPainting(const QRegion &damagedRegion)
|
|
|
|
{
|
|
|
|
// See EglGbmBackend::endRenderingFrameForScreen comment for the reason why we only support screenId=0
|
|
|
|
if (m_outputs.count() > 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Output &output = m_outputs.at(0);
|
|
|
|
if (output.bufferAge > 0 && !damagedRegion.isEmpty() && supportsPartialUpdate()) {
|
|
|
|
const QRegion region = damagedRegion & output.output->geometry();
|
|
|
|
|
|
|
|
QVector<EGLint> rects = regionToRects(region, output.output);
|
|
|
|
const bool correct = eglSetDamageRegionKHR(eglDisplay(), output.eglSurface,
|
|
|
|
rects.data(), rects.count()/4);
|
|
|
|
if (!correct) {
|
|
|
|
qCWarning(KWIN_DRM) << "failed eglSetDamageRegionKHR" << eglGetError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-22 17:38:57 +00:00
|
|
|
void EglGbmBackend::presentOnOutput(Output &output, const QRegion &damagedRegion)
|
2015-04-23 07:55:49 +00:00
|
|
|
{
|
2020-04-24 17:11:41 +00:00
|
|
|
if (supportsSwapBuffersWithDamage()) {
|
|
|
|
QVector<EGLint> rects = regionToRects(output.damageHistory.constFirst(), output.output);
|
|
|
|
eglSwapBuffersWithDamageEXT(eglDisplay(), output.eglSurface,
|
|
|
|
rects.data(), rects.count()/4);
|
|
|
|
} else {
|
|
|
|
eglSwapBuffers(eglDisplay(), output.eglSurface);
|
|
|
|
}
|
2020-10-05 21:05:55 +00:00
|
|
|
output.buffer = new DrmSurfaceBuffer(m_gpu->fd(), output.gbmSurface);
|
2019-12-10 00:24:45 +00:00
|
|
|
|
2020-07-22 17:38:57 +00:00
|
|
|
Q_EMIT output.output->outputChange(damagedRegion);
|
2019-12-10 00:24:45 +00:00
|
|
|
m_backend->present(output.buffer, output.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()) {
|
2019-12-10 00:24:45 +00:00
|
|
|
eglQuerySurface(eglDisplay(), output.eglSurface, EGL_BUFFER_AGE_EXT, &output.bufferAge);
|
2015-04-23 07:55:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2019-12-10 00:24:45 +00:00
|
|
|
void EglGbmBackend::setViewport(const Output &output) const
|
|
|
|
{
|
|
|
|
const QSize &overall = screens()->size();
|
|
|
|
const QRect &v = output.output->geometry();
|
|
|
|
qreal scale = output.output->scale();
|
|
|
|
|
|
|
|
glViewport(-v.x() * scale, (v.height() - overall.height() + v.y()) * scale,
|
|
|
|
overall.width() * scale, overall.height() * scale);
|
|
|
|
}
|
|
|
|
|
2015-04-23 07:55:49 +00:00
|
|
|
QRegion EglGbmBackend::prepareRenderingForScreen(int screenId)
|
|
|
|
{
|
2019-12-10 00:24:45 +00:00
|
|
|
const Output &output = m_outputs.at(screenId);
|
|
|
|
|
|
|
|
makeContextCurrent(output);
|
2020-01-02 14:55:09 +00:00
|
|
|
prepareRenderFramebuffer(output);
|
2019-12-10 00:24:45 +00:00
|
|
|
setViewport(output);
|
|
|
|
|
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
|
2019-12-10 00:24:45 +00:00
|
|
|
if (output.bufferAge > 0 && output.bufferAge <= output.damageHistory.count()) {
|
|
|
|
for (int i = 0; i < output.bufferAge - 1; i++)
|
|
|
|
region |= output.damageHistory[i];
|
2015-04-23 07:55:49 +00:00
|
|
|
} else {
|
2019-12-10 00:24:45 +00:00
|
|
|
region = output.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
|
|
|
}
|
2020-06-20 00:42:02 +00:00
|
|
|
return output.output->geometry();
|
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
|
|
|
}
|
|
|
|
|
2019-12-10 00:24:45 +00:00
|
|
|
void EglGbmBackend::endRenderingFrameForScreen(int screenId,
|
|
|
|
const QRegion &renderedRegion,
|
|
|
|
const QRegion &damagedRegion)
|
2015-04-10 08:44:07 +00:00
|
|
|
{
|
2019-12-10 00:24:45 +00:00
|
|
|
Output &output = m_outputs[screenId];
|
2020-01-02 14:55:09 +00:00
|
|
|
renderFramebufferToSurface(output);
|
2019-12-10 00:24:45 +00:00
|
|
|
|
|
|
|
if (damagedRegion.intersected(output.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.
|
2019-12-10 00:24:45 +00:00
|
|
|
if (!renderedRegion.intersected(output.output->geometry()).isEmpty())
|
2015-04-10 08:44:07 +00:00
|
|
|
glFlush();
|
|
|
|
|
2019-12-10 00:24:45 +00:00
|
|
|
for (auto &output: m_outputs) {
|
|
|
|
output.bufferAge = 1;
|
2015-04-17 13:48:55 +00:00
|
|
|
}
|
2015-04-10 08:44:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-07-22 17:38:57 +00:00
|
|
|
presentOnOutput(output, damagedRegion);
|
2015-04-10 08:44:07 +00:00
|
|
|
|
|
|
|
// Save the damaged region to history
|
2019-12-10 00:24:45 +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.
|
2015-04-23 07:55:49 +00:00
|
|
|
if (supportsBufferAge() && screenId == 0) {
|
2019-12-10 00:24:45 +00:00
|
|
|
if (output.damageHistory.count() > 10) {
|
|
|
|
output.damageHistory.removeLast();
|
2015-04-23 07:55:49 +00:00
|
|
|
}
|
2019-12-10 00:24:45 +00:00
|
|
|
output.damageHistory.prepend(damagedRegion.intersected(output.output->geometry()));
|
2015-04-23 07:55:49 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2020-07-22 17:38:57 +00:00
|
|
|
QSharedPointer<GLTexture> EglGbmBackend::textureForOutput(AbstractOutput *abstractOutput) const
|
|
|
|
{
|
|
|
|
const QVector<KWin::EglGbmBackend::Output>::const_iterator itOutput = std::find_if(m_outputs.begin(), m_outputs.end(),
|
|
|
|
[abstractOutput] (const auto &output) {
|
|
|
|
return output.output == abstractOutput;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (itOutput == m_outputs.end()) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
DrmOutput *drmOutput = itOutput->output;
|
|
|
|
if (!drmOutput->hardwareTransforms()) {
|
|
|
|
const auto glTexture = QSharedPointer<KWin::GLTexture>::create(itOutput->render.texture, GL_RGBA8, drmOutput->pixelSize());
|
|
|
|
glTexture->setYInverted(true);
|
|
|
|
return glTexture;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLImageKHR image = eglCreateImageKHR(eglDisplay(), nullptr, EGL_NATIVE_PIXMAP_KHR, itOutput->buffer->getBo(), nullptr);
|
|
|
|
if (image == EGL_NO_IMAGE_KHR) {
|
|
|
|
qCWarning(KWIN_DRM) << "Failed to record frame: Error creating EGLImageKHR - " << glGetError();
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return QSharedPointer<EGLImageTexture>::create(eglDisplay(), image, GL_RGBA8, drmOutput->modeSize());
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2019-12-10 00:24:45 +00:00
|
|
|
}
|