2020-10-05 21:05:55 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
SPDX-FileCopyrightText: 2020 Xaver Hugl <xaver.hugl@gmail.com>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DRM_GPU_H
|
|
|
|
#define DRM_GPU_H
|
|
|
|
|
|
|
|
#include <qobject.h>
|
|
|
|
#include <QVector>
|
2021-02-19 11:59:43 +00:00
|
|
|
#include <QSocketNotifier>
|
2020-10-05 21:05:55 +00:00
|
|
|
|
2020-10-16 13:11:23 +00:00
|
|
|
#include <epoxy/egl.h>
|
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
#include "drm_buffer.h"
|
2021-02-15 17:28:58 +00:00
|
|
|
#include "drm_object_plane.h"
|
2020-10-05 21:05:55 +00:00
|
|
|
|
|
|
|
struct gbm_device;
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
2020-11-27 19:57:24 +00:00
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
class DrmOutput;
|
|
|
|
class DrmCrtc;
|
|
|
|
class DrmConnector;
|
|
|
|
class DrmBackend;
|
|
|
|
class AbstractEglBackend;
|
2020-11-27 19:57:24 +00:00
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
class DrmGpu : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2021-04-28 18:30:16 +00:00
|
|
|
DrmGpu(DrmBackend *backend, QByteArray devNode, int fd, dev_t deviceId);
|
2020-10-05 21:05:55 +00:00
|
|
|
~DrmGpu();
|
2020-11-27 19:57:24 +00:00
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
// getters
|
|
|
|
QVector<DrmOutput*> outputs() const {
|
|
|
|
return m_outputs;
|
|
|
|
}
|
2020-11-27 19:57:24 +00:00
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
int fd() const {
|
|
|
|
return m_fd;
|
|
|
|
}
|
2020-11-27 19:57:24 +00:00
|
|
|
|
2021-04-28 18:30:16 +00:00
|
|
|
dev_t deviceId() const {
|
|
|
|
return m_deviceId;
|
2020-10-05 21:05:55 +00:00
|
|
|
}
|
2020-11-27 19:57:24 +00:00
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
bool atomicModeSetting() const {
|
|
|
|
return m_atomicModeSetting;
|
|
|
|
}
|
2020-11-27 19:57:24 +00:00
|
|
|
|
2020-10-25 17:47:58 +00:00
|
|
|
bool useEglStreams() const {
|
|
|
|
return m_useEglStreams;
|
|
|
|
}
|
2020-11-27 19:57:24 +00:00
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
QByteArray devNode() const {
|
|
|
|
return m_devNode;
|
|
|
|
}
|
2020-11-27 19:57:24 +00:00
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
gbm_device *gbmDevice() const {
|
|
|
|
return m_gbmDevice;
|
|
|
|
}
|
2020-10-16 13:11:23 +00:00
|
|
|
|
|
|
|
EGLDisplay eglDisplay() const {
|
|
|
|
return m_eglDisplay;
|
|
|
|
}
|
2020-11-27 19:57:24 +00:00
|
|
|
|
2020-11-28 17:53:41 +00:00
|
|
|
AbstractEglBackend *eglBackend() {
|
|
|
|
return m_eglBackend;
|
|
|
|
}
|
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
void setGbmDevice(gbm_device *d) {
|
|
|
|
m_gbmDevice = d;
|
|
|
|
}
|
2020-10-16 13:11:23 +00:00
|
|
|
|
|
|
|
void setEglDisplay(EGLDisplay display) {
|
|
|
|
m_eglDisplay = display;
|
|
|
|
}
|
2020-11-27 19:57:24 +00:00
|
|
|
|
2020-11-28 17:53:41 +00:00
|
|
|
void setEglBackend(AbstractEglBackend *eglBackend) {
|
|
|
|
m_eglBackend = eglBackend;
|
|
|
|
}
|
|
|
|
|
Introduce RenderLoop
At the moment, our frame scheduling infrastructure is still heavily
based on Xinerama-style rendering. Specifically, we assume that painting
is driven by a single timer, etc.
This change introduces a new type - RenderLoop. Its main purpose is to
drive compositing on a specific output, or in case of X11, on the
overlay window.
With RenderLoop, compositing is synchronized to vblank events. It
exposes the last and the next estimated presentation timestamp. The
expected presentation timestamp can be used by effects to ensure that
animations are synchronized with the upcoming vblank event.
On Wayland, every outputs has its own render loop. On X11, per screen
rendering is not possible, therefore the platform exposes the render
loop for the overlay window. Ideally, the Scene has to expose the
RenderLoop, but as the first step towards better compositing scheduling
it's good as is for the time being.
The RenderLoop tries to minimize the latency by delaying compositing as
close as possible to the next vblank event. One tricky thing about it is
that if compositing is too close to the next vblank event, animations
may become a little bit choppy. However, increasing the latency reduces
the choppiness.
Given that, there is no any "silver bullet" solution for the choppiness
issue, a new option has been added in the Compositing KCM to specify the
amount of latency. By default, it's "Medium," but if a user is not
satisfied with the upstream default, they can tweak it.
2020-11-19 08:52:29 +00:00
|
|
|
/**
|
|
|
|
* Returns the clock from which presentation timestamps are sourced. The returned value
|
|
|
|
* can be either CLOCK_MONOTONIC or CLOCK_REALTIME.
|
|
|
|
*/
|
|
|
|
clockid_t presentationClock() const;
|
|
|
|
|
2021-03-22 10:43:24 +00:00
|
|
|
bool addFB2ModifiersSupported() const {
|
|
|
|
return m_addFB2ModifiersSupported;
|
|
|
|
}
|
|
|
|
|
2021-02-22 18:17:23 +00:00
|
|
|
void waitIdle();
|
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
Q_SIGNALS:
|
|
|
|
void outputAdded(DrmOutput *output);
|
|
|
|
void outputRemoved(DrmOutput *output);
|
|
|
|
void outputEnabled(DrmOutput *output);
|
|
|
|
void outputDisabled(DrmOutput *output);
|
2020-11-27 19:57:24 +00:00
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
protected:
|
|
|
|
friend class DrmBackend;
|
|
|
|
bool updateOutputs();
|
2020-11-27 19:57:24 +00:00
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
private:
|
2021-02-19 13:00:49 +00:00
|
|
|
void dispatchEvents();
|
2021-02-15 17:28:58 +00:00
|
|
|
DrmPlane *getCompatiblePlane(DrmPlane::TypeIndex typeIndex, DrmCrtc *crtc);
|
2020-10-05 21:05:55 +00:00
|
|
|
DrmOutput *findOutput(quint32 connector);
|
2021-04-27 11:49:53 +00:00
|
|
|
void removeOutput(DrmOutput *output);
|
2021-04-28 20:18:28 +00:00
|
|
|
void tryAMS();
|
2020-11-27 19:57:24 +00:00
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
DrmBackend* const m_backend;
|
2020-11-28 17:53:41 +00:00
|
|
|
AbstractEglBackend *m_eglBackend;
|
2020-11-27 19:57:24 +00:00
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
const QByteArray m_devNode;
|
2020-10-12 19:27:53 +00:00
|
|
|
QSize m_cursorSize;
|
2020-10-05 21:05:55 +00:00
|
|
|
const int m_fd;
|
2021-04-28 18:30:16 +00:00
|
|
|
const dev_t m_deviceId;
|
2020-10-05 21:05:55 +00:00
|
|
|
bool m_atomicModeSetting;
|
|
|
|
bool m_useEglStreams;
|
|
|
|
gbm_device* m_gbmDevice;
|
2020-10-16 13:11:23 +00:00
|
|
|
EGLDisplay m_eglDisplay = EGL_NO_DISPLAY;
|
Introduce RenderLoop
At the moment, our frame scheduling infrastructure is still heavily
based on Xinerama-style rendering. Specifically, we assume that painting
is driven by a single timer, etc.
This change introduces a new type - RenderLoop. Its main purpose is to
drive compositing on a specific output, or in case of X11, on the
overlay window.
With RenderLoop, compositing is synchronized to vblank events. It
exposes the last and the next estimated presentation timestamp. The
expected presentation timestamp can be used by effects to ensure that
animations are synchronized with the upcoming vblank event.
On Wayland, every outputs has its own render loop. On X11, per screen
rendering is not possible, therefore the platform exposes the render
loop for the overlay window. Ideally, the Scene has to expose the
RenderLoop, but as the first step towards better compositing scheduling
it's good as is for the time being.
The RenderLoop tries to minimize the latency by delaying compositing as
close as possible to the next vblank event. One tricky thing about it is
that if compositing is too close to the next vblank event, animations
may become a little bit choppy. However, increasing the latency reduces
the choppiness.
Given that, there is no any "silver bullet" solution for the choppiness
issue, a new option has been added in the Compositing KCM to specify the
amount of latency. By default, it's "Medium," but if a user is not
satisfied with the upstream default, they can tweak it.
2020-11-19 08:52:29 +00:00
|
|
|
clockid_t m_presentationClock;
|
2021-02-19 11:59:43 +00:00
|
|
|
QSocketNotifier *m_socketNotifier = nullptr;
|
2021-03-22 10:43:24 +00:00
|
|
|
bool m_addFB2ModifiersSupported = false;
|
2020-11-27 19:57:24 +00:00
|
|
|
|
2021-02-15 17:28:58 +00:00
|
|
|
// all planes: primarys, cursors and overlays
|
2020-10-05 21:05:55 +00:00
|
|
|
QVector<DrmPlane*> m_planes;
|
2021-02-15 17:28:58 +00:00
|
|
|
QVector<DrmPlane*> m_unusedPlanes;
|
2020-10-05 21:05:55 +00:00
|
|
|
// crtcs
|
|
|
|
QVector<DrmCrtc*> m_crtcs;
|
|
|
|
// connectors
|
|
|
|
QVector<DrmConnector*> m_connectors;
|
|
|
|
// active output pipelines (planes + crtc + encoder + connector)
|
|
|
|
QVector<DrmOutput*> m_outputs;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DRM_GPU_H
|