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"
|
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-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
|
|
|
|
{
|
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;
|
2021-06-22 00:23:17 +00:00
|
|
|
class ShadowBuffer;
|
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-07-26 23:11:50 +00:00
|
|
|
bool addOutput(DrmAbstractOutput *output) override;
|
|
|
|
void removeOutput(DrmAbstractOutput *output) override;
|
|
|
|
bool swapBuffers(DrmAbstractOutput *output, const QRegion &dirty) override;
|
|
|
|
bool exportFramebuffer(DrmAbstractOutput *output, void *data, const QSize &size, uint32_t stride) override;
|
2021-08-24 22:45:43 +00:00
|
|
|
bool exportFramebufferAsDmabuf(DrmAbstractOutput *output, int *fds, int *strides, int *offsets, uint32_t *num_fds, uint32_t *format, uint64_t *modifier) override;
|
2021-07-26 23:11:50 +00:00
|
|
|
QRegion beginFrameForSecondaryGpu(DrmAbstractOutput *output) override;
|
2020-11-28 17:53:41 +00:00
|
|
|
|
2021-02-02 13:26:43 +00:00
|
|
|
bool directScanoutAllowed(int screen) const override;
|
|
|
|
|
2021-07-26 23:11:50 +00:00
|
|
|
QSharedPointer<DrmBuffer> renderTestFrame(DrmAbstractOutput *output) override;
|
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;
|
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 {
|
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-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-02-02 13:26:43 +00:00
|
|
|
KWaylandServer::SurfaceInterface *surfaceInterface = nullptr;
|
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);
|
|
|
|
bool resetOutput(Output &output, DrmAbstractOutput *drmOutput);
|
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;
|
|
|
|
QSharedPointer<DrmBuffer> endFrameWithBuffer(int screenId, const QRegion &dirty);
|
|
|
|
void updateBufferAge(Output &output, const QRegion &dirty);
|
2021-05-25 22:05:17 +00:00
|
|
|
|
|
|
|
void cleanupRenderData(Output::RenderData &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;
|
2021-07-31 13:32:50 +00:00
|
|
|
uint32_t m_gbmFormat;
|
2020-11-28 17:53:41 +00:00
|
|
|
|
2015-04-10 08:44:07 +00:00
|
|
|
friend class EglGbmTexture;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif
|