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"
|
2021-04-09 07:06:04 +00:00
|
|
|
#include "basiceglsurfacetexture_internal.h"
|
|
|
|
#include "basiceglsurfacetexture_wayland.h"
|
2015-04-10 08:44:07 +00:00
|
|
|
// kwin
|
|
|
|
#include "composite.h"
|
|
|
|
#include "drm_backend.h"
|
2021-04-28 19:12:11 +00:00
|
|
|
#include "drm_buffer_gbm.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"
|
2020-11-29 11:24:38 +00:00
|
|
|
#include "renderloop_p.h"
|
2015-04-10 08:44:07 +00:00
|
|
|
#include "screens.h"
|
2021-02-04 08:40:20 +00:00
|
|
|
#include "surfaceitem_wayland.h"
|
2020-10-05 21:05:55 +00:00
|
|
|
#include "drm_gpu.h"
|
2021-02-02 13:26:43 +00:00
|
|
|
#include "linux_dmabuf.h"
|
2021-05-04 10:19:31 +00:00
|
|
|
#include "dumb_swapchain.h"
|
2021-06-20 15:36:15 +00:00
|
|
|
#include "kwineglutils_p.h"
|
2021-06-22 00:23:17 +00:00
|
|
|
#include "shadowbuffer.h"
|
2021-05-25 22:05:17 +00:00
|
|
|
#include "drm_pipeline.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>
|
2020-11-28 17:53:41 +00:00
|
|
|
#include <unistd.h>
|
2020-11-29 18:31:49 +00:00
|
|
|
#include <errno.h>
|
2021-05-30 23:58:47 +00:00
|
|
|
#include <drm_fourcc.h>
|
2021-02-02 13:26:43 +00:00
|
|
|
// kwayland server
|
|
|
|
#include "KWaylandServer/surface_interface.h"
|
2021-07-20 19:37:03 +00:00
|
|
|
#include "KWaylandServer/linuxdmabufv1clientbuffer.h"
|
2021-05-30 23:58:47 +00:00
|
|
|
#include "KWaylandServer/clientconnection.h"
|
2015-04-10 08:44:07 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
EglGbmBackend::EglGbmBackend(DrmBackend *drmBackend, DrmGpu *gpu)
|
2020-11-28 17:53:41 +00:00
|
|
|
: AbstractEglDrmBackend(drmBackend, gpu)
|
2015-04-10 08:44:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-04-19 14:23:46 +00:00
|
|
|
EglGbmBackend::~EglGbmBackend()
|
|
|
|
{
|
|
|
|
cleanup();
|
|
|
|
}
|
|
|
|
|
2015-04-17 13:48:55 +00:00
|
|
|
void EglGbmBackend::cleanupSurfaces()
|
|
|
|
{
|
2021-05-25 17:25:55 +00:00
|
|
|
// shadow buffer needs context current for destruction
|
|
|
|
makeCurrent();
|
2017-10-05 16:58:57 +00:00
|
|
|
m_outputs.clear();
|
2015-04-24 08:05:38 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 22:05:17 +00:00
|
|
|
void EglGbmBackend::cleanupRenderData(Output::RenderData &render)
|
|
|
|
{
|
|
|
|
render.gbmSurface = nullptr;
|
|
|
|
render.importSwapchain = nullptr;
|
|
|
|
if (render.shadowBuffer) {
|
|
|
|
makeContextCurrent(render);
|
|
|
|
render.shadowBuffer = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2021-04-21 15:23:46 +00:00
|
|
|
|
|
|
|
if (!supportsSurfacelessContext()) {
|
|
|
|
setFailed("EGL_KHR_surfaceless_context extension is unavailable!");
|
2021-04-21 15:42:55 +00:00
|
|
|
return;
|
2021-04-21 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
2015-04-10 08:44:07 +00:00
|
|
|
if (!initRenderingContext()) {
|
|
|
|
setFailed("Could not initialize rendering context");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
initBufferAge();
|
2020-11-28 17:53:41 +00:00
|
|
|
// at the moment: no secondary GPU -> no OpenGL context!
|
|
|
|
if (isPrimary()) {
|
|
|
|
initKWinGL();
|
|
|
|
initWayland();
|
|
|
|
}
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool EglGbmBackend::initRenderingContext()
|
|
|
|
{
|
|
|
|
initBufferConfigs();
|
2021-04-20 10:13:58 +00:00
|
|
|
if (isPrimary()) {
|
2021-05-31 11:13:59 +00:00
|
|
|
if (!createContext() || !makeCurrent()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const auto outputs = m_gpu->outputs();
|
|
|
|
for (const auto &output : outputs) {
|
|
|
|
addOutput(output);
|
2020-11-28 17:53:41 +00:00
|
|
|
}
|
|
|
|
return true;
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
2019-12-10 00:24:45 +00:00
|
|
|
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;
|
2021-05-25 22:05:17 +00:00
|
|
|
const QSize size = drmOutput->pipeline()->sourceSize();
|
2021-01-31 00:31:15 +00:00
|
|
|
int flags = GBM_BO_USE_RENDERING;
|
|
|
|
if (drmOutput->gpu() == m_gpu) {
|
|
|
|
flags |= GBM_BO_USE_SCANOUT;
|
|
|
|
} else {
|
|
|
|
flags |= GBM_BO_USE_LINEAR;
|
|
|
|
}
|
2021-05-25 17:25:55 +00:00
|
|
|
auto gbmSurface = QSharedPointer<GbmSurface>::create(m_gpu, size, GBM_FORMAT_XRGB8888, flags);
|
2017-10-21 13:16:41 +00:00
|
|
|
if (!gbmSurface) {
|
2021-05-25 17:25:55 +00:00
|
|
|
qCCritical(KWIN_DRM) << "Creating GBM surface failed:" << strerror(errno);
|
2017-10-21 13:16:41 +00:00
|
|
|
return false;
|
2015-04-24 08:05:38 +00:00
|
|
|
}
|
2021-05-25 22:05:17 +00:00
|
|
|
cleanupRenderData(output.old);
|
|
|
|
output.old = output.current;
|
|
|
|
output.current = {};
|
|
|
|
output.current.gbmSurface = gbmSurface;
|
2020-01-02 14:55:09 +00:00
|
|
|
|
2021-06-22 00:23:17 +00:00
|
|
|
if (output.output->hardwareTransforms()) {
|
2021-05-25 22:05:17 +00:00
|
|
|
output.current.shadowBuffer = nullptr;
|
2021-06-22 00:23:17 +00:00
|
|
|
} else {
|
2021-05-25 22:05:17 +00:00
|
|
|
makeContextCurrent(output.current);
|
|
|
|
output.current.shadowBuffer = QSharedPointer<ShadowBuffer>::create(output.output->pixelSize());
|
|
|
|
if (!output.current.shadowBuffer->isComplete()) {
|
2021-06-22 00:23:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-10-21 13:16:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-23 17:45:05 +00:00
|
|
|
bool EglGbmBackend::addOutput(DrmOutput *drmOutput)
|
2017-10-21 13:16:41 +00:00
|
|
|
{
|
2020-11-28 17:53:41 +00:00
|
|
|
if (isPrimary()) {
|
|
|
|
Output newOutput;
|
2021-05-25 22:05:17 +00:00
|
|
|
if (!resetOutput(newOutput, drmOutput)) {
|
2021-05-23 17:45:05 +00:00
|
|
|
return false;
|
2020-11-28 17:53:41 +00:00
|
|
|
}
|
2021-05-25 22:05:17 +00:00
|
|
|
if (drmOutput->gpu() == m_gpu) {
|
|
|
|
m_outputs << newOutput;
|
|
|
|
} else {
|
|
|
|
m_secondaryGpuOutputs << newOutput;
|
|
|
|
}
|
2020-11-28 17:53:41 +00:00
|
|
|
} else {
|
|
|
|
Output newOutput;
|
|
|
|
newOutput.output = drmOutput;
|
2021-05-23 17:45:05 +00:00
|
|
|
if (!renderingBackend()->addOutput(drmOutput)) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-28 17:53:41 +00:00
|
|
|
m_outputs << newOutput;
|
|
|
|
}
|
2021-05-23 17:45:05 +00:00
|
|
|
return true;
|
2020-11-28 17:53:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EglGbmBackend::removeOutput(DrmOutput *drmOutput)
|
|
|
|
{
|
2020-12-01 16:58:24 +00:00
|
|
|
QVector<Output> &outputs = drmOutput->gpu() == m_gpu ? m_outputs : m_secondaryGpuOutputs;
|
|
|
|
auto it = std::find_if(outputs.begin(), outputs.end(),
|
2020-11-28 17:53:41 +00:00
|
|
|
[drmOutput] (const Output &output) {
|
|
|
|
return output.output == drmOutput;
|
|
|
|
}
|
|
|
|
);
|
2020-12-01 16:58:24 +00:00
|
|
|
if (it == outputs.end()) {
|
2020-11-28 17:53:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-12-01 16:58:24 +00:00
|
|
|
if (isPrimary()) {
|
2021-05-25 17:25:55 +00:00
|
|
|
// shadow buffer needs context current for destruction
|
|
|
|
makeCurrent();
|
2020-12-01 16:58:24 +00:00
|
|
|
} else {
|
|
|
|
renderingBackend()->removeOutput((*it).output);
|
2020-11-28 17:53:41 +00:00
|
|
|
}
|
2020-12-01 16:58:24 +00:00
|
|
|
outputs.erase(it);
|
2015-04-24 08:05:38 +00:00
|
|
|
}
|
|
|
|
|
2021-07-13 11:04:43 +00:00
|
|
|
bool EglGbmBackend::swapBuffers(DrmOutput *drmOutput, const QRegion &dirty)
|
2019-12-10 00:24:45 +00:00
|
|
|
{
|
2020-11-28 17:53:41 +00:00
|
|
|
auto it = std::find_if(m_secondaryGpuOutputs.begin(), m_secondaryGpuOutputs.end(),
|
2019-12-10 00:24:45 +00:00
|
|
|
[drmOutput] (const Output &output) {
|
|
|
|
return output.output == drmOutput;
|
|
|
|
}
|
|
|
|
);
|
2020-11-28 17:53:41 +00:00
|
|
|
if (it == m_secondaryGpuOutputs.end()) {
|
2021-05-04 10:19:31 +00:00
|
|
|
return false;
|
2020-11-28 17:53:41 +00:00
|
|
|
}
|
2021-07-13 11:04:43 +00:00
|
|
|
Output &output = *it;
|
|
|
|
renderFramebufferToSurface(output);
|
|
|
|
if (output.current.gbmSurface->swapBuffers()) {
|
|
|
|
cleanupRenderData(output.old);
|
|
|
|
updateBufferAge(output, dirty);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2021-05-04 10:19:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool EglGbmBackend::exportFramebuffer(DrmOutput *drmOutput, void *data, const QSize &size, uint32_t stride)
|
|
|
|
{
|
|
|
|
auto it = std::find_if(m_secondaryGpuOutputs.begin(), m_secondaryGpuOutputs.end(),
|
|
|
|
[drmOutput] (const Output &output) {
|
|
|
|
return output.output == drmOutput;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (it == m_secondaryGpuOutputs.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-05-25 22:05:17 +00:00
|
|
|
auto bo = it->current.gbmSurface->currentBuffer();
|
2021-05-25 17:25:55 +00:00
|
|
|
if (!bo->map(GBM_BO_TRANSFER_READ)) {
|
2021-05-04 10:19:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-05-25 17:25:55 +00:00
|
|
|
if (stride != bo->stride()) {
|
2021-05-04 10:19:31 +00:00
|
|
|
// shouldn't happen if formats are the same
|
|
|
|
return false;
|
|
|
|
}
|
2021-05-25 17:25:55 +00:00
|
|
|
return memcpy(data, bo->mappedData(), size.height() * stride);
|
2021-05-04 10:19:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int EglGbmBackend::exportFramebufferAsDmabuf(DrmOutput *output, uint32_t *format, uint32_t *stride)
|
|
|
|
{
|
|
|
|
DrmOutput *drmOutput = static_cast<DrmOutput*>(output);
|
|
|
|
auto it = std::find_if(m_secondaryGpuOutputs.begin(), m_secondaryGpuOutputs.end(),
|
|
|
|
[drmOutput] (const Output &output) {
|
|
|
|
return output.output == drmOutput;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (it == m_secondaryGpuOutputs.end()) {
|
|
|
|
return -1;
|
|
|
|
}
|
2021-05-25 22:05:17 +00:00
|
|
|
auto bo = it->current.gbmSurface->currentBuffer()->getBo();
|
2021-05-25 17:25:55 +00:00
|
|
|
int fd = gbm_bo_get_fd(bo);
|
2020-11-28 17:53:41 +00:00
|
|
|
if (fd == -1) {
|
2021-06-20 15:36:15 +00:00
|
|
|
qCWarning(KWIN_DRM) << "failed to export gbm_bo as dma-buf:" << strerror(errno);
|
2020-11-28 17:53:41 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2021-05-25 17:25:55 +00:00
|
|
|
*format = gbm_bo_get_format(bo);
|
|
|
|
*stride = gbm_bo_get_stride(bo);
|
2021-03-29 11:17:44 +00:00
|
|
|
return fd;
|
2020-11-28 17:53:41 +00:00
|
|
|
}
|
|
|
|
|
2021-05-04 10:19:31 +00:00
|
|
|
QRegion EglGbmBackend::beginFrameForSecondaryGpu(DrmOutput *drmOutput)
|
2020-11-28 17:53:41 +00:00
|
|
|
{
|
|
|
|
auto it = std::find_if(m_secondaryGpuOutputs.begin(), m_secondaryGpuOutputs.end(),
|
|
|
|
[drmOutput] (const Output &output) {
|
|
|
|
return output.output == drmOutput;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (it == m_secondaryGpuOutputs.end()) {
|
|
|
|
return QRegion();
|
|
|
|
}
|
|
|
|
return prepareRenderingForOutput(*it);
|
|
|
|
}
|
|
|
|
|
2021-07-13 11:04:43 +00:00
|
|
|
QSharedPointer<DrmBuffer> EglGbmBackend::importFramebuffer(Output &output, const QRegion &dirty) const
|
2021-05-04 10:19:31 +00:00
|
|
|
{
|
2021-07-13 11:04:43 +00:00
|
|
|
if (!renderingBackend()->swapBuffers(output.output, dirty)) {
|
2021-05-04 10:19:31 +00:00
|
|
|
qCWarning(KWIN_DRM) << "swapping buffers failed on output" << output.output;
|
2021-05-25 17:55:15 +00:00
|
|
|
return nullptr;
|
2021-05-04 10:19:31 +00:00
|
|
|
}
|
|
|
|
const auto size = output.output->modeSize();
|
2021-05-25 22:05:17 +00:00
|
|
|
if (output.current.importMode == ImportMode::Dmabuf) {
|
2021-05-04 10:19:31 +00:00
|
|
|
uint32_t stride = 0;
|
|
|
|
uint32_t format = 0;
|
|
|
|
int fd = renderingBackend()->exportFramebufferAsDmabuf(output.output, &format, &stride);
|
|
|
|
if (fd != -1) {
|
|
|
|
struct gbm_import_fd_data data = {};
|
|
|
|
data.fd = fd;
|
|
|
|
data.width = (uint32_t) size.width();
|
|
|
|
data.height = (uint32_t) size.height();
|
|
|
|
data.stride = stride;
|
|
|
|
data.format = format;
|
|
|
|
gbm_bo *importedBuffer = gbm_bo_import(m_gpu->gbmDevice(), GBM_BO_IMPORT_FD, &data, GBM_BO_USE_SCANOUT | GBM_BO_USE_LINEAR);
|
|
|
|
close(fd);
|
|
|
|
if (importedBuffer) {
|
|
|
|
auto buffer = QSharedPointer<DrmGbmBuffer>::create(m_gpu, importedBuffer, nullptr);
|
|
|
|
if (buffer->bufferId() > 0) {
|
2021-05-25 17:55:15 +00:00
|
|
|
return buffer;
|
2021-05-04 10:19:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
qCDebug(KWIN_DRM) << "import with dmabuf failed! Switching to CPU import on output" << output.output;
|
2021-05-25 22:05:17 +00:00
|
|
|
output.current.importMode = ImportMode::DumbBuffer;
|
2021-05-04 10:19:31 +00:00
|
|
|
}
|
|
|
|
// ImportMode::DumbBuffer
|
2021-05-25 22:05:17 +00:00
|
|
|
if (!output.current.importSwapchain || output.current.importSwapchain->size() != size) {
|
|
|
|
output.current.importSwapchain = QSharedPointer<DumbSwapchain>::create(m_gpu, size);
|
|
|
|
if (output.current.importSwapchain->isEmpty()) {
|
|
|
|
output.current.importSwapchain = nullptr;
|
2021-05-04 10:19:31 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-25 22:05:17 +00:00
|
|
|
if (output.current.importSwapchain) {
|
|
|
|
auto buffer = output.current.importSwapchain->acquireBuffer();
|
2021-05-04 10:19:31 +00:00
|
|
|
if (renderingBackend()->exportFramebuffer(output.output, buffer->data(), size, buffer->stride())) {
|
2021-05-25 17:55:15 +00:00
|
|
|
return buffer;
|
2021-05-04 10:19:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
qCWarning(KWIN_DRM) << "all imports failed on output" << output.output;
|
|
|
|
// TODO turn off output?
|
2021-05-25 17:55:15 +00:00
|
|
|
return nullptr;
|
2021-05-04 10:19:31 +00:00
|
|
|
}
|
|
|
|
|
2020-01-02 14:55:09 +00:00
|
|
|
void EglGbmBackend::renderFramebufferToSurface(Output &output)
|
|
|
|
{
|
2021-05-25 22:05:17 +00:00
|
|
|
if (!output.current.shadowBuffer) {
|
2020-01-02 14:55:09 +00:00
|
|
|
// No additional render target.
|
|
|
|
return;
|
|
|
|
}
|
2021-05-25 22:05:17 +00:00
|
|
|
makeContextCurrent(output.current);
|
|
|
|
output.current.shadowBuffer->render(output.output);
|
2020-01-02 14:55:09 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 22:05:17 +00:00
|
|
|
bool EglGbmBackend::makeContextCurrent(const Output::RenderData &render) const
|
2015-04-10 08:44:07 +00:00
|
|
|
{
|
2020-11-28 17:53:41 +00:00
|
|
|
Q_ASSERT(isPrimary());
|
2021-05-25 22:05:17 +00:00
|
|
|
const auto surface = render.gbmSurface;
|
2021-05-25 17:25:55 +00:00
|
|
|
if (!surface) {
|
2015-04-17 13:48:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-05-25 17:25:55 +00:00
|
|
|
if (eglMakeCurrent(eglDisplay(), surface->eglSurface(), surface->eglSurface(), context()) == EGL_FALSE) {
|
2021-06-20 15:36:15 +00:00
|
|
|
qCCritical(KWIN_DRM) << "eglMakeCurrent failed:" << getEglErrorString();
|
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)) {
|
2021-06-20 15:36:15 +00:00
|
|
|
qCCritical(KWIN_DRM) << "eglChooseConfig failed:" << getEglErrorString();
|
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
|
|
|
}
|
|
|
|
|
2020-04-24 17:11:41 +00:00
|
|
|
static QVector<EGLint> regionToRects(const QRegion ®ion, AbstractWaylandOutput *output)
|
|
|
|
{
|
|
|
|
const int height = output->modeSize().height();
|
|
|
|
|
2020-10-13 20:57:15 +00:00
|
|
|
const QMatrix4x4 matrix = DrmOutput::logicalToNativeMatrix(output->geometry(),
|
|
|
|
output->scale(),
|
|
|
|
output->transform());
|
2020-04-24 17:11:41 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-10-30 07:39:17 +00:00
|
|
|
void EglGbmBackend::aboutToStartPainting(int screenId, const QRegion &damagedRegion)
|
2020-04-24 17:11:41 +00:00
|
|
|
{
|
2020-10-30 07:39:17 +00:00
|
|
|
Q_ASSERT_X(screenId != -1, "aboutToStartPainting", "not using per screen rendering");
|
|
|
|
const Output &output = m_outputs.at(screenId);
|
2021-05-25 22:05:17 +00:00
|
|
|
if (output.current.bufferAge > 0 && !damagedRegion.isEmpty() && supportsPartialUpdate()) {
|
2020-04-24 17:11:41 +00:00
|
|
|
const QRegion region = damagedRegion & output.output->geometry();
|
|
|
|
|
|
|
|
QVector<EGLint> rects = regionToRects(region, output.output);
|
2021-05-25 22:05:17 +00:00
|
|
|
const bool correct = eglSetDamageRegionKHR(eglDisplay(), output.current.gbmSurface->eglSurface(),
|
2020-04-24 17:11:41 +00:00
|
|
|
rects.data(), rects.count()/4);
|
|
|
|
if (!correct) {
|
2021-06-20 15:36:15 +00:00
|
|
|
qCWarning(KWIN_DRM) << "eglSetDamageRegionKHR failed:" << getEglErrorString();
|
2020-04-24 17:11:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-09 07:06:04 +00:00
|
|
|
PlatformSurfaceTexture *EglGbmBackend::createPlatformSurfaceTextureInternal(SurfacePixmapInternal *pixmap)
|
2015-04-10 08:44:07 +00:00
|
|
|
{
|
2021-04-09 07:06:04 +00:00
|
|
|
return new BasicEGLSurfaceTextureInternal(this, pixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
PlatformSurfaceTexture *EglGbmBackend::createPlatformSurfaceTextureWayland(SurfacePixmapWayland *pixmap)
|
|
|
|
{
|
|
|
|
return new BasicEGLSurfaceTextureWayland(this, pixmap);
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
|
|
|
|
2019-12-10 00:24:45 +00:00
|
|
|
void EglGbmBackend::setViewport(const Output &output) const
|
|
|
|
{
|
2021-06-08 20:25:40 +00:00
|
|
|
const QSize size = output.output->pixelSize();
|
|
|
|
glViewport(0, 0, size.width(), size.height());
|
2019-12-10 00:24:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-09 14:31:26 +00:00
|
|
|
QRegion EglGbmBackend::beginFrame(int screenId)
|
2015-04-23 07:55:49 +00:00
|
|
|
{
|
2021-03-18 14:22:31 +00:00
|
|
|
Output &output = m_outputs[screenId];
|
2021-05-30 23:58:47 +00:00
|
|
|
if (output.surfaceInterface) {
|
|
|
|
qCDebug(KWIN_DRM) << "Direct scanout stopped on output" << output.output->name();
|
|
|
|
}
|
2021-03-29 11:17:44 +00:00
|
|
|
output.surfaceInterface = nullptr;
|
2020-11-28 17:53:41 +00:00
|
|
|
if (isPrimary()) {
|
2021-02-02 15:03:43 +00:00
|
|
|
return prepareRenderingForOutput(output);
|
2020-11-28 17:53:41 +00:00
|
|
|
} else {
|
2021-02-02 15:03:43 +00:00
|
|
|
return renderingBackend()->beginFrameForSecondaryGpu(output.output);
|
2020-11-28 17:53:41 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-10 00:24:45 +00:00
|
|
|
|
2021-05-25 22:05:17 +00:00
|
|
|
bool EglGbmBackend::doesRenderFit(DrmOutput *output, const Output::RenderData &render)
|
2020-11-28 17:53:41 +00:00
|
|
|
{
|
2021-05-25 22:05:17 +00:00
|
|
|
if (!render.gbmSurface) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
QSize surfaceSize = output->pipeline()->sourceSize();
|
|
|
|
if (surfaceSize != render.gbmSurface->size()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
QSize pixelSize = output->pixelSize();
|
|
|
|
bool needsTexture = surfaceSize != pixelSize;
|
|
|
|
if (needsTexture) {
|
|
|
|
return render.shadowBuffer && render.shadowBuffer->textureSize() == pixelSize;
|
|
|
|
} else {
|
|
|
|
return render.shadowBuffer == nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QRegion EglGbmBackend::prepareRenderingForOutput(Output &output)
|
|
|
|
{
|
|
|
|
// check if the current surface still fits
|
|
|
|
if (!doesRenderFit(output.output, output.current)) {
|
|
|
|
if (doesRenderFit(output.output, output.old)) {
|
|
|
|
cleanupRenderData(output.current);
|
|
|
|
output.current = output.old;
|
|
|
|
output.old = {};
|
|
|
|
} else {
|
|
|
|
resetOutput(output, output.output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
makeContextCurrent(output.current);
|
|
|
|
if (output.current.shadowBuffer) {
|
|
|
|
output.current.shadowBuffer->bind();
|
2021-06-22 00:23:17 +00:00
|
|
|
}
|
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
|
2021-05-25 22:05:17 +00:00
|
|
|
if (output.current.bufferAge > 0 && output.current.bufferAge <= output.current.damageHistory.count()) {
|
|
|
|
for (int i = 0; i < output.current.bufferAge - 1; i++)
|
|
|
|
region |= output.current.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
|
|
|
}
|
|
|
|
|
2021-07-13 11:04:43 +00:00
|
|
|
QSharedPointer<DrmBuffer> EglGbmBackend::endFrameWithBuffer(int screenId, const QRegion &dirty)
|
2021-05-25 22:05:17 +00:00
|
|
|
{
|
|
|
|
Output &output = m_outputs[screenId];
|
|
|
|
if (isPrimary()) {
|
|
|
|
renderFramebufferToSurface(output);
|
2021-07-13 11:04:43 +00:00
|
|
|
auto buffer = output.current.gbmSurface->swapBuffersForDrm();
|
|
|
|
if (buffer) {
|
|
|
|
updateBufferAge(output, dirty);
|
|
|
|
}
|
|
|
|
return buffer;
|
2021-05-25 22:05:17 +00:00
|
|
|
} else {
|
2021-07-13 11:04:43 +00:00
|
|
|
return importFramebuffer(output, dirty);
|
2021-05-25 22:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-09 14:31:26 +00:00
|
|
|
void EglGbmBackend::endFrame(int screenId, const QRegion &renderedRegion,
|
|
|
|
const QRegion &damagedRegion)
|
2015-04-10 08:44:07 +00:00
|
|
|
{
|
2020-11-29 11:24:38 +00:00
|
|
|
Q_UNUSED(renderedRegion)
|
|
|
|
|
2019-12-10 00:24:45 +00:00
|
|
|
Output &output = m_outputs[screenId];
|
2020-11-29 11:24:38 +00:00
|
|
|
DrmOutput *drmOutput = output.output;
|
2021-05-25 22:05:17 +00:00
|
|
|
cleanupRenderData(output.old);
|
2020-11-29 11:24:38 +00:00
|
|
|
|
2021-04-06 08:53:26 +00:00
|
|
|
const QRegion dirty = damagedRegion.intersected(output.output->geometry());
|
2021-07-13 11:04:43 +00:00
|
|
|
QSharedPointer<DrmBuffer> buffer = endFrameWithBuffer(screenId, dirty);
|
2021-05-25 17:55:15 +00:00
|
|
|
if (!buffer || !output.output->present(buffer, dirty)) {
|
2020-11-29 11:24:38 +00:00
|
|
|
RenderLoopPrivate *renderLoopPrivate = RenderLoopPrivate::get(drmOutput->renderLoop());
|
|
|
|
renderLoopPrivate->notifyFrameFailed();
|
|
|
|
return;
|
|
|
|
}
|
2021-07-13 11:04:43 +00:00
|
|
|
}
|
2015-04-10 08:44:07 +00:00
|
|
|
|
2021-07-13 11:04:43 +00:00
|
|
|
void EglGbmBackend::updateBufferAge(Output &output, const QRegion &dirty)
|
|
|
|
{
|
2020-10-29 21:33:06 +00:00
|
|
|
if (supportsBufferAge()) {
|
2021-05-25 22:05:17 +00:00
|
|
|
eglQuerySurface(eglDisplay(), output.current.gbmSurface->eglSurface(), EGL_BUFFER_AGE_EXT, &output.current.bufferAge);
|
|
|
|
if (output.current.damageHistory.count() > 10) {
|
|
|
|
output.current.damageHistory.removeLast();
|
2015-04-23 07:55:49 +00:00
|
|
|
}
|
2021-05-25 22:05:17 +00:00
|
|
|
output.current.damageHistory.prepend(dirty);
|
2015-04-23 07:55:49 +00:00
|
|
|
}
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
|
|
|
|
2021-02-04 08:40:20 +00:00
|
|
|
bool EglGbmBackend::scanout(int screenId, SurfaceItem *surfaceItem)
|
2021-02-02 13:26:43 +00:00
|
|
|
{
|
2021-02-04 08:40:20 +00:00
|
|
|
SurfaceItemWayland *item = qobject_cast<SurfaceItemWayland *>(surfaceItem);
|
|
|
|
if (!item) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
KWaylandServer::SurfaceInterface *surface = item->surface();
|
2021-07-20 19:37:03 +00:00
|
|
|
if (!surface) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto buffer = qobject_cast<KWaylandServer::LinuxDmaBufV1ClientBuffer *>(surface->buffer());
|
|
|
|
if (!buffer) {
|
2021-02-02 13:26:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-03-18 14:22:31 +00:00
|
|
|
Output &output = m_outputs[screenId];
|
2021-07-20 19:37:03 +00:00
|
|
|
if (buffer->size() != output.output->modeSize()) {
|
2021-02-02 13:26:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-07-20 19:37:03 +00:00
|
|
|
if (!buffer->planes().count() ||
|
|
|
|
!gbm_device_is_format_supported(m_gpu->gbmDevice(), buffer->format(), GBM_BO_USE_SCANOUT)) {
|
2021-02-02 13:26:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
gbm_bo *importedBuffer;
|
2021-07-20 19:37:03 +00:00
|
|
|
if (buffer->planes()[0].modifier != DRM_FORMAT_MOD_INVALID
|
|
|
|
|| buffer->planes()[0].offset > 0
|
|
|
|
|| buffer->planes().size() > 1) {
|
2021-06-08 14:07:57 +00:00
|
|
|
if (!m_gpu->addFB2ModifiersSupported()) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-02-02 13:26:43 +00:00
|
|
|
gbm_import_fd_modifier_data data = {};
|
2021-07-20 19:37:03 +00:00
|
|
|
data.format = buffer->format();
|
|
|
|
data.width = (uint32_t) buffer->size().width();
|
|
|
|
data.height = (uint32_t) buffer->size().height();
|
|
|
|
data.num_fds = buffer->planes().count();
|
|
|
|
data.modifier = buffer->planes()[0].modifier;
|
|
|
|
for (int i = 0; i < buffer->planes().count(); i++) {
|
|
|
|
auto plane = buffer->planes()[i];
|
2021-02-02 13:26:43 +00:00
|
|
|
data.fds[i] = plane.fd;
|
|
|
|
data.offsets[i] = plane.offset;
|
|
|
|
data.strides[i] = plane.stride;
|
|
|
|
}
|
|
|
|
importedBuffer = gbm_bo_import(m_gpu->gbmDevice(), GBM_BO_IMPORT_FD_MODIFIER, &data, GBM_BO_USE_SCANOUT);
|
|
|
|
} else {
|
2021-07-20 19:37:03 +00:00
|
|
|
auto plane = buffer->planes()[0];
|
2021-02-02 13:26:43 +00:00
|
|
|
gbm_import_fd_data data = {};
|
|
|
|
data.fd = plane.fd;
|
2021-07-20 19:37:03 +00:00
|
|
|
data.width = (uint32_t) buffer->size().width();
|
|
|
|
data.height = (uint32_t) buffer->size().height();
|
2021-02-02 13:26:43 +00:00
|
|
|
data.stride = plane.stride;
|
2021-07-20 19:37:03 +00:00
|
|
|
data.format = buffer->format();
|
2021-02-02 13:26:43 +00:00
|
|
|
importedBuffer = gbm_bo_import(m_gpu->gbmDevice(), GBM_BO_IMPORT_FD, &data, GBM_BO_USE_SCANOUT);
|
|
|
|
}
|
|
|
|
if (!importedBuffer) {
|
2021-04-24 17:46:34 +00:00
|
|
|
if (errno != EINVAL) {
|
2021-06-20 15:36:15 +00:00
|
|
|
qCWarning(KWIN_DRM) << "Importing buffer for direct scanout failed:" << strerror(errno);
|
2021-04-24 17:46:34 +00:00
|
|
|
}
|
2021-02-02 13:26:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// damage tracking for screen casting
|
|
|
|
QRegion damage;
|
2021-02-23 14:25:28 +00:00
|
|
|
if (output.surfaceInterface == surface && buffer->size() == output.output->modeSize()) {
|
2021-02-04 08:40:20 +00:00
|
|
|
QRegion trackedDamage = surfaceItem->damage();
|
|
|
|
surfaceItem->resetDamage();
|
2021-02-02 13:26:43 +00:00
|
|
|
for (const auto &rect : trackedDamage) {
|
|
|
|
auto damageRect = QRect(rect);
|
|
|
|
damageRect.translate(output.output->geometry().topLeft());
|
|
|
|
damage |= damageRect;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
damage = output.output->geometry();
|
|
|
|
}
|
2021-05-25 17:55:15 +00:00
|
|
|
auto bo = QSharedPointer<DrmGbmBuffer>::create(m_gpu, importedBuffer, buffer);
|
2021-06-07 11:45:50 +00:00
|
|
|
// ensure that a context is current like with normal presentation
|
|
|
|
makeCurrent();
|
2021-05-25 17:55:15 +00:00
|
|
|
if (output.output->present(bo, damage)) {
|
2021-05-25 22:05:17 +00:00
|
|
|
output.current.damageHistory.clear();
|
2021-05-25 17:55:15 +00:00
|
|
|
if (output.surfaceInterface != surface) {
|
2021-05-30 23:58:47 +00:00
|
|
|
auto path = surface->client()->executablePath();
|
|
|
|
qCDebug(KWIN_DRM).nospace() << "Direct scanout starting on output " << output.output->name() << " for application \"" << path << "\"";
|
|
|
|
}
|
2021-05-25 17:55:15 +00:00
|
|
|
output.surfaceInterface = surface;
|
2021-05-30 23:58:47 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2021-02-02 13:26:43 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 22:05:17 +00:00
|
|
|
QSharedPointer<DrmBuffer> EglGbmBackend::renderTestFrame(DrmOutput *output)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < m_outputs.count(); i++) {
|
|
|
|
if (m_outputs[i].output == output) {
|
|
|
|
beginFrame(i);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2021-07-13 11:04:43 +00:00
|
|
|
return endFrameWithBuffer(i, output->geometry());
|
2021-05-25 22:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-07-22 17:38:57 +00:00
|
|
|
QSharedPointer<GLTexture> EglGbmBackend::textureForOutput(AbstractOutput *abstractOutput) const
|
|
|
|
{
|
2021-05-04 10:19:31 +00:00
|
|
|
auto itOutput = std::find_if(m_outputs.begin(), m_outputs.end(),
|
2020-07-22 17:38:57 +00:00
|
|
|
[abstractOutput] (const auto &output) {
|
|
|
|
return output.output == abstractOutput;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (itOutput == m_outputs.end()) {
|
2021-05-04 10:19:31 +00:00
|
|
|
itOutput = std::find_if(m_secondaryGpuOutputs.begin(), m_secondaryGpuOutputs.end(),
|
|
|
|
[abstractOutput] (const auto &output) {
|
|
|
|
return output.output == abstractOutput;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (itOutput == m_secondaryGpuOutputs.end()) {
|
|
|
|
return {};
|
|
|
|
}
|
2020-07-22 17:38:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DrmOutput *drmOutput = itOutput->output;
|
2021-05-25 22:05:17 +00:00
|
|
|
if (itOutput->current.shadowBuffer) {
|
|
|
|
const auto glTexture = QSharedPointer<KWin::GLTexture>::create(itOutput->current.shadowBuffer->texture(), GL_RGBA8, drmOutput->pixelSize());
|
2020-07-22 17:38:57 +00:00
|
|
|
glTexture->setYInverted(true);
|
|
|
|
return glTexture;
|
|
|
|
}
|
2021-05-25 22:05:17 +00:00
|
|
|
GbmBuffer *gbmBuffer = itOutput->current.gbmSurface->currentBuffer().get();
|
2021-05-04 10:19:31 +00:00
|
|
|
if (!gbmBuffer) {
|
2021-05-25 17:55:15 +00:00
|
|
|
qCWarning(KWIN_DRM) << "Failed to record frame: No gbm buffer!";
|
2021-05-04 10:19:31 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
EGLImageKHR image = eglCreateImageKHR(eglDisplay(), nullptr, EGL_NATIVE_PIXMAP_KHR, gbmBuffer->getBo(), nullptr);
|
2020-07-22 17:38:57 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2021-02-02 13:26:43 +00:00
|
|
|
bool EglGbmBackend::directScanoutAllowed(int screen) const
|
|
|
|
{
|
2021-02-02 21:15:50 +00:00
|
|
|
return !m_backend->usesSoftwareCursor() && !m_outputs[screen].output->directScanoutInhibited();
|
2021-02-02 13:26:43 +00:00
|
|
|
}
|
|
|
|
|
2019-12-10 00:24:45 +00:00
|
|
|
}
|