2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2015-11-25 12:33:40 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
|
2015-11-25 12:33:40 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2015-11-25 12:33:40 +00:00
|
|
|
#include "egl_x11_backend.h"
|
|
|
|
// kwin
|
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
|
|
|
#include "main.h"
|
2015-11-25 12:33:40 +00:00
|
|
|
#include "screens.h"
|
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
|
|
|
#include "softwarevsyncmonitor.h"
|
2015-11-25 12:33:40 +00:00
|
|
|
#include "x11windowed_backend.h"
|
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
|
|
|
#include "x11windowed_output.h"
|
2015-11-25 12:33:40 +00:00
|
|
|
// kwin libs
|
|
|
|
#include <kwinglplatform.h>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
EglX11Backend::EglX11Backend(X11WindowedBackend *backend)
|
|
|
|
: EglOnXBackend(backend->connection(), backend->display(), backend->rootWindow(), backend->screenNumer(), XCB_WINDOW_NONE)
|
|
|
|
, m_backend(backend)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
EglX11Backend::~EglX11Backend() = default;
|
|
|
|
|
2020-11-30 10:27:33 +00:00
|
|
|
void EglX11Backend::init()
|
|
|
|
{
|
|
|
|
EglOnXBackend::init();
|
|
|
|
|
|
|
|
if (!isFailed()) {
|
|
|
|
initWayland();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-25 12:33:40 +00:00
|
|
|
void EglX11Backend::cleanupSurfaces()
|
|
|
|
{
|
|
|
|
for (auto it = m_surfaces.begin(); it != m_surfaces.end(); ++it) {
|
|
|
|
eglDestroySurface(eglDisplay(), *it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EglX11Backend::createSurfaces()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < screens()->count(); ++i) {
|
|
|
|
EGLSurface s = createSurface(m_backend->windowForScreen(i));
|
|
|
|
if (s == EGL_NO_SURFACE) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
m_surfaces << s;
|
|
|
|
}
|
|
|
|
if (m_surfaces.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
setSurface(m_surfaces.first());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EglX11Backend::usesOverlayWindow() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-09 14:31:26 +00:00
|
|
|
QRegion EglX11Backend::beginFrame(int screenId)
|
2015-11-25 12:33:40 +00:00
|
|
|
{
|
|
|
|
makeContextCurrent(m_surfaces.at(screenId));
|
|
|
|
setupViewport(screenId);
|
|
|
|
return screens()->geometry(screenId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EglX11Backend::setupViewport(int screenId)
|
|
|
|
{
|
|
|
|
// TODO: ensure the viewport is set correctly each time
|
|
|
|
const QSize &overall = screens()->size();
|
|
|
|
const QRect &v = screens()->geometry(screenId);
|
|
|
|
// TODO: are the values correct?
|
2016-11-09 03:47:13 +00:00
|
|
|
|
|
|
|
qreal scale = screens()->scale(screenId);
|
2017-10-25 17:03:22 +00:00
|
|
|
glViewport(-v.x(), v.height() - overall.height() + v.y(), overall.width() * scale, overall.height() * scale);
|
2015-11-25 12:33:40 +00:00
|
|
|
}
|
|
|
|
|
2020-11-09 14:31:26 +00:00
|
|
|
void EglX11Backend::endFrame(int screenId, const QRegion &renderedRegion, const QRegion &damagedRegion)
|
2015-11-25 12:33:40 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(damagedRegion)
|
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
|
|
|
|
|
|
|
X11WindowedOutput *output = static_cast<X11WindowedOutput *>(kwinApp()->platform()->findOutput(screenId));
|
|
|
|
output->vsyncMonitor()->arm();
|
|
|
|
|
2015-11-25 12:33:40 +00:00
|
|
|
const QRect &outputGeometry = screens()->geometry(screenId);
|
|
|
|
presentSurface(m_surfaces.at(screenId), renderedRegion, outputGeometry);
|
|
|
|
}
|
|
|
|
|
2020-11-30 10:27:33 +00:00
|
|
|
void EglX11Backend::presentSurface(EGLSurface surface, const QRegion &damage, const QRect &screenGeometry)
|
|
|
|
{
|
|
|
|
if (damage.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const bool fullRepaint = supportsBufferAge() || (damage == screenGeometry);
|
|
|
|
|
|
|
|
if (fullRepaint || !havePostSubBuffer()) {
|
|
|
|
// the entire screen changed, or we cannot do partial updates (which implies we enabled surface preservation)
|
|
|
|
eglSwapBuffers(eglDisplay(), surface);
|
|
|
|
} else {
|
|
|
|
// a part of the screen changed, and we can use eglPostSubBufferNV to copy the updated area
|
|
|
|
for (const QRect &r : damage) {
|
|
|
|
eglPostSubBufferNV(eglDisplay(), surface, r.left(), screenGeometry.height() - r.bottom() - 1, r.width(), r.height());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SceneOpenGLTexturePrivate *EglX11Backend::createBackendTexture(SceneOpenGLTexture *texture)
|
|
|
|
{
|
|
|
|
return new EglX11Texture(texture, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EglX11Backend::screenGeometryChanged(const QSize &size)
|
|
|
|
{
|
|
|
|
Q_UNUSED(size)
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
* EglX11Texture
|
|
|
|
************************************************/
|
|
|
|
|
|
|
|
EglX11Texture::EglX11Texture(KWin::SceneOpenGLTexture *texture, EglX11Backend *backend)
|
|
|
|
: AbstractEglTexture(texture, backend)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
EglX11Texture::~EglX11Texture()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-11-25 12:33:40 +00:00
|
|
|
} // namespace
|