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
|
2020-11-28 17:53:41 +00:00
|
|
|
#include "abstract_egl_drm_backend.h"
|
2015-04-10 08:44:07 +00:00
|
|
|
|
2021-04-09 07:06:04 +00:00
|
|
|
#include <kwinglutils.h>
|
|
|
|
|
2021-03-22 14:46:09 +00:00
|
|
|
#include <QSharedPointer>
|
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
|
|
|
|
{
|
|
|
|
class BufferInterface;
|
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;
|
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;
|
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
|
|
|
*/
|
2020-11-28 17:53:41 +00:00
|
|
|
class EglGbmBackend : public AbstractEglDrmBackend
|
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-04-09 07:06:04 +00:00
|
|
|
PlatformSurfaceTexture *createPlatformSurfaceTextureInternal(SurfacePixmapInternal *pixmap) override;
|
|
|
|
PlatformSurfaceTexture *createPlatformSurfaceTextureWayland(SurfacePixmapWayland *pixmap) override;
|
|
|
|
|
2020-11-09 14:31:26 +00:00
|
|
|
QRegion beginFrame(int screenId) override;
|
|
|
|
void endFrame(int screenId, const QRegion &damage, const QRegion &damagedRegion) override;
|
2015-11-25 12:09:28 +00:00
|
|
|
void init() override;
|
2021-02-04 08:40:20 +00:00
|
|
|
bool scanout(int screenId, SurfaceItem *surfaceItem) override;
|
2015-04-10 08:44:07 +00:00
|
|
|
|
2020-07-22 17:38:57 +00:00
|
|
|
QSharedPointer<GLTexture> textureForOutput(AbstractOutput *requestedOutput) const override;
|
|
|
|
|
2020-11-28 17:53:41 +00:00
|
|
|
int screenCount() const override {
|
|
|
|
return m_outputs.count();
|
|
|
|
}
|
|
|
|
|
2021-05-23 17:45:05 +00:00
|
|
|
bool addOutput(DrmOutput *output) override;
|
2020-12-01 16:58:24 +00:00
|
|
|
void removeOutput(DrmOutput *output) override;
|
2021-05-04 10:19:31 +00:00
|
|
|
bool swapBuffers(DrmOutput *output) override;
|
|
|
|
bool exportFramebuffer(DrmOutput *output, void *data, const QSize &size, uint32_t stride) override;
|
|
|
|
int exportFramebufferAsDmabuf(DrmOutput *output, uint32_t *format, uint32_t *stride) override;
|
|
|
|
QRegion beginFrameForSecondaryGpu(DrmOutput *output) override;
|
2020-11-28 17:53:41 +00:00
|
|
|
|
2021-02-02 13:26:43 +00:00
|
|
|
bool directScanoutAllowed(int screen) const override;
|
|
|
|
|
2015-04-10 08:44:07 +00:00
|
|
|
protected:
|
2015-04-17 13:48:55 +00:00
|
|
|
void cleanupSurfaces() override;
|
2020-10-30 07:39:17 +00:00
|
|
|
void aboutToStartPainting(int screenId, 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 {
|
|
|
|
DrmOutput *output = nullptr;
|
2021-05-04 10:19:31 +00:00
|
|
|
QSharedPointer<DrmBuffer> buffer;
|
2021-03-29 11:17:44 +00:00
|
|
|
QSharedPointer<GbmBuffer> secondaryBuffer;
|
2021-03-22 14:46:09 +00:00
|
|
|
QSharedPointer<GbmSurface> gbmSurface;
|
2015-04-17 13:48:55 +00:00
|
|
|
EGLSurface eglSurface = EGL_NO_SURFACE;
|
|
|
|
int bufferAge = 0;
|
2015-04-23 07:55:49 +00:00
|
|
|
/**
|
2019-02-02 18:17:44 +00:00
|
|
|
* @brief The damage history for the past 10 frames.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2015-04-23 07:55:49 +00:00
|
|
|
QList<QRegion> damageHistory;
|
2020-01-02 14:55:09 +00:00
|
|
|
|
|
|
|
struct {
|
|
|
|
GLuint framebuffer = 0;
|
|
|
|
GLuint texture = 0;
|
2021-03-22 14:46:09 +00:00
|
|
|
QSharedPointer<GLVertexBuffer> vbo;
|
2020-01-02 14:55:09 +00:00
|
|
|
} render;
|
2020-11-28 17:53:41 +00:00
|
|
|
|
2021-02-02 13:26:43 +00:00
|
|
|
KWaylandServer::SurfaceInterface *surfaceInterface = nullptr;
|
2021-05-04 10:19:31 +00:00
|
|
|
ImportMode importMode = ImportMode::Dmabuf;
|
|
|
|
QSharedPointer<DumbSwapchain> importSwapchain;
|
2015-04-17 13:48:55 +00:00
|
|
|
};
|
2019-12-10 00:24:45 +00:00
|
|
|
|
2017-10-21 13:16:41 +00:00
|
|
|
bool resetOutput(Output &output, DrmOutput *drmOutput);
|
2021-03-22 14:46:09 +00:00
|
|
|
EGLSurface createEglSurface(QSharedPointer<GbmSurface> gbmSurface) const;
|
2019-12-10 00:24:45 +00:00
|
|
|
|
|
|
|
bool makeContextCurrent(const Output &output) const;
|
|
|
|
void setViewport(const Output &output) const;
|
2020-01-02 14:55:09 +00:00
|
|
|
|
|
|
|
bool resetFramebuffer(Output &output);
|
2020-02-28 12:22:35 +00:00
|
|
|
void initRenderTarget(Output &output);
|
2020-01-02 14:55:09 +00:00
|
|
|
|
|
|
|
void prepareRenderFramebuffer(const Output &output) const;
|
|
|
|
void renderFramebufferToSurface(Output &output);
|
2021-02-02 13:26:43 +00:00
|
|
|
QRegion prepareRenderingForOutput(Output &output) const;
|
2021-05-04 10:19:31 +00:00
|
|
|
void importFramebuffer(Output &output) const;
|
2020-01-02 14:55:09 +00:00
|
|
|
|
2020-11-29 11:24:38 +00:00
|
|
|
bool presentOnOutput(Output &output, const QRegion &damagedRegion);
|
2021-03-29 11:17:44 +00:00
|
|
|
bool directScanoutActive(const Output &output);
|
2019-12-10 00:24:45 +00:00
|
|
|
|
2020-01-02 14:55:09 +00:00
|
|
|
void cleanupOutput(Output &output);
|
|
|
|
void cleanupFramebuffer(Output &output);
|
2019-12-10 00:24:45 +00:00
|
|
|
|
2015-04-17 13:48:55 +00:00
|
|
|
QVector<Output> m_outputs;
|
2020-11-28 17:53:41 +00:00
|
|
|
QVector<Output> m_secondaryGpuOutputs;
|
|
|
|
|
2015-04-10 08:44:07 +00:00
|
|
|
friend class EglGbmTexture;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif
|