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
|
|
|
#ifndef KWIN_EGL_GBM_BACKEND_H
|
|
|
|
#define KWIN_EGL_GBM_BACKEND_H
|
2021-11-10 12:26:34 +00:00
|
|
|
#include "abstract_egl_backend.h"
|
2021-07-24 10:03:00 +00:00
|
|
|
#include "utils.h"
|
2015-04-10 08:44:07 +00:00
|
|
|
|
2021-04-09 07:06:04 +00:00
|
|
|
#include <kwinglutils.h>
|
|
|
|
|
2021-11-24 08:16:47 +00:00
|
|
|
#include <QPointer>
|
2021-03-22 14:46:09 +00:00
|
|
|
#include <QSharedPointer>
|
2021-11-10 13:47:13 +00:00
|
|
|
#include <optional>
|
2017-10-05 16:58:57 +00:00
|
|
|
|
2015-04-10 08:44:07 +00:00
|
|
|
struct gbm_surface;
|
2020-11-28 17:53:41 +00:00
|
|
|
struct gbm_bo;
|
2015-04-10 08:44:07 +00:00
|
|
|
|
2021-02-02 13:26:43 +00:00
|
|
|
namespace KWaylandServer
|
|
|
|
{
|
2021-02-04 08:40:20 +00:00
|
|
|
class SurfaceInterface;
|
2021-02-02 13:26:43 +00:00
|
|
|
}
|
|
|
|
|
2015-04-10 08:44:07 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
2020-07-22 17:38:57 +00:00
|
|
|
class AbstractOutput;
|
2021-11-10 12:26:34 +00:00
|
|
|
class DrmAbstractOutput;
|
2015-04-10 08:44:07 +00:00
|
|
|
class DrmBuffer;
|
2021-03-29 11:17:44 +00:00
|
|
|
class DrmGbmBuffer;
|
2015-04-17 13:48:55 +00:00
|
|
|
class DrmOutput;
|
2017-10-05 16:58:57 +00:00
|
|
|
class GbmSurface;
|
2021-03-29 11:17:44 +00:00
|
|
|
class GbmBuffer;
|
2021-05-04 10:19:31 +00:00
|
|
|
class DumbSwapchain;
|
2021-06-22 00:23:17 +00:00
|
|
|
class ShadowBuffer;
|
2021-11-10 12:26:34 +00:00
|
|
|
class DrmBackend;
|
|
|
|
class DrmGpu;
|
2015-04-10 08:44:07 +00:00
|
|
|
|
2021-11-10 13:47:13 +00:00
|
|
|
struct GbmFormat {
|
|
|
|
uint32_t drmFormat;
|
|
|
|
EGLint redSize;
|
|
|
|
EGLint greenSize;
|
|
|
|
EGLint blueSize;
|
|
|
|
EGLint alphaSize;
|
|
|
|
};
|
|
|
|
bool operator==(const GbmFormat &lhs, const GbmFormat &rhs);
|
|
|
|
|
2015-04-10 08:44:07 +00:00
|
|
|
/**
|
|
|
|
* @brief OpenGL Backend using Egl on a GBM surface.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2021-11-10 12:26:34 +00:00
|
|
|
class EglGbmBackend : public AbstractEglBackend
|
2015-04-10 08:44:07 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2020-10-05 21:05:55 +00:00
|
|
|
EglGbmBackend(DrmBackend *drmBackend, DrmGpu *gpu);
|
2021-04-19 14:23:46 +00:00
|
|
|
~EglGbmBackend() override;
|
2020-11-28 17:53:41 +00:00
|
|
|
|
2021-10-20 14:58:58 +00:00
|
|
|
SurfaceTexture *createSurfaceTextureInternal(SurfacePixmapInternal *pixmap) override;
|
|
|
|
SurfaceTexture *createSurfaceTextureWayland(SurfacePixmapWayland *pixmap) override;
|
2021-04-09 07:06:04 +00:00
|
|
|
|
2021-08-24 20:55:42 +00:00
|
|
|
QRegion beginFrame(AbstractOutput *output) override;
|
2021-11-11 11:24:02 +00:00
|
|
|
void endFrame(AbstractOutput *output, const QRegion &renderedRegion, const QRegion &damagedRegion) override;
|
2015-11-25 12:09:28 +00:00
|
|
|
void init() override;
|
2021-08-24 20:55:42 +00:00
|
|
|
bool scanout(AbstractOutput *output, SurfaceItem *surfaceItem) override;
|
2021-11-10 13:47:13 +00:00
|
|
|
bool prefer10bpc() const override;
|
2015-04-10 08:44:07 +00:00
|
|
|
|
2020-07-22 17:38:57 +00:00
|
|
|
QSharedPointer<GLTexture> textureForOutput(AbstractOutput *requestedOutput) const override;
|
|
|
|
|
2021-11-10 12:26:34 +00:00
|
|
|
bool hasOutput(AbstractOutput *output) const;
|
|
|
|
bool swapBuffers(DrmAbstractOutput *output, const QRegion &dirty);
|
|
|
|
bool exportFramebuffer(DrmAbstractOutput *output, void *data, const QSize &size, uint32_t stride);
|
|
|
|
bool exportFramebufferAsDmabuf(DrmAbstractOutput *output, int *fds, int *strides, int *offsets, uint32_t *num_fds, uint32_t *format, uint64_t *modifier);
|
2020-11-28 17:53:41 +00:00
|
|
|
|
2021-08-24 20:55:42 +00:00
|
|
|
bool directScanoutAllowed(AbstractOutput *output) const override;
|
2021-02-02 13:26:43 +00:00
|
|
|
|
2021-11-10 12:26:34 +00:00
|
|
|
QSharedPointer<DrmBuffer> renderTestFrame(DrmAbstractOutput *output);
|
2021-11-10 13:47:13 +00:00
|
|
|
uint32_t drmFormat(DrmAbstractOutput *output) const;
|
2021-11-10 12:26:34 +00:00
|
|
|
DrmGpu *gpu() const;
|
2021-05-25 22:05:17 +00:00
|
|
|
|
2015-04-10 08:44:07 +00:00
|
|
|
protected:
|
2015-04-17 13:48:55 +00:00
|
|
|
void cleanupSurfaces() override;
|
2021-08-24 20:55:42 +00:00
|
|
|
void aboutToStartPainting(AbstractOutput *output, const QRegion &damage) override;
|
2015-04-10 08:44:07 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool initializeEgl();
|
|
|
|
bool initBufferConfigs();
|
|
|
|
bool initRenderingContext();
|
2020-07-22 17:39:54 +00:00
|
|
|
|
2021-05-04 10:19:31 +00:00
|
|
|
enum class ImportMode {
|
|
|
|
Dmabuf,
|
|
|
|
DumbBuffer
|
|
|
|
};
|
2015-04-17 13:48:55 +00:00
|
|
|
struct Output {
|
2021-07-26 23:11:50 +00:00
|
|
|
DrmAbstractOutput *output = nullptr;
|
2021-05-25 22:05:17 +00:00
|
|
|
struct RenderData {
|
|
|
|
QSharedPointer<ShadowBuffer> shadowBuffer;
|
|
|
|
QSharedPointer<GbmSurface> gbmSurface;
|
|
|
|
int bufferAge = 0;
|
2021-07-24 10:03:00 +00:00
|
|
|
DamageJournal damageJournal;
|
2021-11-10 13:47:13 +00:00
|
|
|
GbmFormat format;
|
2021-05-25 22:05:17 +00:00
|
|
|
|
|
|
|
// for secondary GPU import
|
|
|
|
ImportMode importMode = ImportMode::Dmabuf;
|
|
|
|
QSharedPointer<DumbSwapchain> importSwapchain;
|
|
|
|
} old, current;
|
2020-11-28 17:53:41 +00:00
|
|
|
|
2021-11-24 08:16:47 +00:00
|
|
|
KWaylandServer::SurfaceInterface *scanoutSurface = nullptr;
|
2021-12-30 18:36:54 +00:00
|
|
|
struct {
|
|
|
|
QPointer<KWaylandServer::SurfaceInterface> surface;
|
|
|
|
QMap<uint32_t, QVector<uint64_t>> attemptedFormats;
|
|
|
|
} scanoutCandidate;
|
2021-11-24 08:16:47 +00:00
|
|
|
QPointer<KWaylandServer::SurfaceInterface> oldScanoutCandidate;
|
2015-04-17 13:48:55 +00:00
|
|
|
};
|
2019-12-10 00:24:45 +00:00
|
|
|
|
2021-07-26 23:11:50 +00:00
|
|
|
bool doesRenderFit(DrmAbstractOutput *output, const Output::RenderData &render);
|
2021-08-24 20:55:42 +00:00
|
|
|
bool resetOutput(Output &output);
|
2021-11-10 12:26:34 +00:00
|
|
|
bool addOutput(DrmAbstractOutput *output);
|
|
|
|
void removeOutput(DrmAbstractOutput *output);
|
2019-12-10 00:24:45 +00:00
|
|
|
|
2021-05-25 22:05:17 +00:00
|
|
|
bool makeContextCurrent(const Output::RenderData &output) const;
|
2019-12-10 00:24:45 +00:00
|
|
|
void setViewport(const Output &output) const;
|
2020-01-02 14:55:09 +00:00
|
|
|
|
|
|
|
void renderFramebufferToSurface(Output &output);
|
2021-05-25 22:05:17 +00:00
|
|
|
QRegion prepareRenderingForOutput(Output &output);
|
2021-07-13 11:04:43 +00:00
|
|
|
QSharedPointer<DrmBuffer> importFramebuffer(Output &output, const QRegion &dirty) const;
|
2021-08-24 20:55:42 +00:00
|
|
|
QSharedPointer<DrmBuffer> endFrameWithBuffer(AbstractOutput *output, const QRegion &dirty);
|
2021-07-13 11:04:43 +00:00
|
|
|
void updateBufferAge(Output &output, const QRegion &dirty);
|
2021-11-10 13:47:13 +00:00
|
|
|
std::optional<GbmFormat> chooseFormat(Output &output) const;
|
2021-05-25 22:05:17 +00:00
|
|
|
|
|
|
|
void cleanupRenderData(Output::RenderData &output);
|
2019-12-10 00:24:45 +00:00
|
|
|
|
2021-08-24 20:55:42 +00:00
|
|
|
QMap<AbstractOutput *, Output> m_outputs;
|
2021-11-10 12:26:34 +00:00
|
|
|
DrmBackend *m_backend;
|
|
|
|
DrmGpu *m_gpu;
|
2021-11-10 13:47:13 +00:00
|
|
|
QVector<GbmFormat> m_formats;
|
|
|
|
QMap<uint32_t, EGLConfig> m_configs;
|
2021-11-10 12:26:34 +00:00
|
|
|
|
|
|
|
static EglGbmBackend *renderingBackend();
|
2020-11-28 17:53:41 +00:00
|
|
|
|
2015-04-10 08:44:07 +00:00
|
|
|
friend class EglGbmTexture;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif
|