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-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;
|
|
|
|
}
|
|
|
|
|
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;
|
2020-07-22 17:38:57 +00:00
|
|
|
class DrmSurfaceBuffer;
|
2015-04-17 13:48:55 +00:00
|
|
|
class DrmOutput;
|
2017-10-05 16:58:57 +00:00
|
|
|
class GbmSurface;
|
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);
|
2020-11-28 17:53:41 +00:00
|
|
|
|
2017-09-08 20:30:18 +00:00
|
|
|
SceneOpenGLTexturePrivate *createBackendTexture(SceneOpenGLTexture *texture) 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-02 13:26:43 +00:00
|
|
|
bool scanout(int screenId, KWaylandServer::SurfaceInterface *surface) 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();
|
|
|
|
}
|
|
|
|
|
2020-12-01 16:58:24 +00:00
|
|
|
void addOutput(DrmOutput *output) override;
|
|
|
|
void removeOutput(DrmOutput *output) override;
|
2020-11-28 17:53:41 +00:00
|
|
|
int getDmabufForSecondaryGpuOutput(AbstractOutput *output, uint32_t *format, uint32_t *stride) override;
|
|
|
|
QRegion beginFrameForSecondaryGpu(AbstractOutput *output) override;
|
|
|
|
|
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
|
|
|
|
2015-04-17 13:48:55 +00:00
|
|
|
struct Output {
|
|
|
|
DrmOutput *output = nullptr;
|
2021-03-22 14:46:09 +00:00
|
|
|
QSharedPointer<DrmSurfaceBuffer> buffer;
|
|
|
|
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
|
|
|
|
|
|
|
int dmabufFd = 0;
|
|
|
|
gbm_bo *secondaryGbmBo = nullptr;
|
2021-02-02 13:26:43 +00:00
|
|
|
gbm_bo *directScanoutBuffer = nullptr;
|
|
|
|
KWaylandServer::SurfaceInterface *surfaceInterface = nullptr;
|
|
|
|
KWaylandServer::BufferInterface *bufferInterface = nullptr;
|
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;
|
2020-01-02 14:55:09 +00:00
|
|
|
|
2020-11-29 11:24:38 +00:00
|
|
|
bool presentOnOutput(Output &output, const QRegion &damagedRegion);
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Texture using an EGLImageKHR.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2015-04-10 08:44:07 +00:00
|
|
|
class EglGbmTexture : public AbstractEglTexture
|
|
|
|
{
|
|
|
|
public:
|
Run clang-tidy with modernize-use-override check
Summary:
Currently code base of kwin can be viewed as two pieces. One is very
ancient, and the other one is more modern, which uses new C++ features.
The main problem with the ancient code is that it was written before
C++11 era. So, no override or final keywords, lambdas, etc.
Quite recently, KDE compiler settings were changed to show a warning if
a virtual method has missing override keyword. As you might have already
guessed, this fired back at us because of that ancient code. We had
about 500 new compiler warnings.
A "solution" was proposed to that problem - disable -Wno-suggest-override
and the other similar warning for clang. It's hard to call a solution
because those warnings are disabled not only for the old code, but also
for new. This is not what we want!
The main argument for not actually fixing the problem was that git
history will be screwed as well because of human factor. While good git
history is a very important thing, we should not go crazy about it and
block every change that somehow alters git history. git blame allows to
specify starting revision for a reason.
The other argument (human factor) can be easily solved by using tools
such as clang-tidy. clang-tidy is a clang-based linter for C++. It can
be used for various things, e.g. fixing coding style(e.g. add missing
braces to if statements, readability-braces-around-statements check),
or in our case add missing override keywords.
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, apol, romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D22371
2019-07-22 16:52:26 +00:00
|
|
|
~EglGbmTexture() override;
|
2015-04-10 08:44:07 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class EglGbmBackend;
|
2017-09-08 20:30:18 +00:00
|
|
|
EglGbmTexture(SceneOpenGLTexture *texture, EglGbmBackend *backend);
|
2015-04-10 08:44:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif
|