2010-11-21 13:01:39 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
Copyright (C) 2010, 2012 Martin Gräßlin <mgraesslin@kde.org>
|
2010-11-21 13:01:39 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
2012-08-26 15:14:23 +00:00
|
|
|
#include "eglonxbackend.h"
|
|
|
|
// kwin
|
2015-03-19 10:26:53 +00:00
|
|
|
#include "main.h"
|
2012-08-26 15:14:23 +00:00
|
|
|
#include "options.h"
|
|
|
|
#include "overlaywindow.h"
|
2015-03-19 10:26:53 +00:00
|
|
|
#include "screens.h"
|
2013-03-11 10:01:38 +00:00
|
|
|
#include "xcbutils.h"
|
2015-03-19 10:26:53 +00:00
|
|
|
#if HAVE_X11_XCB
|
2015-05-05 10:45:07 +00:00
|
|
|
#include "backends/x11/x11windowed_backend.h"
|
2015-03-19 10:26:53 +00:00
|
|
|
#endif
|
2012-08-26 15:14:23 +00:00
|
|
|
// kwin libs
|
|
|
|
#include <kwinglplatform.h>
|
2013-09-02 11:14:39 +00:00
|
|
|
// Qt
|
|
|
|
#include <QDebug>
|
Better handling for making the compositing OpenGL context current
With QtQuick2 it's possible that the scene graph rendering context either
lives in an own thread or uses the main GUI thread. In the latter case
it's the same thread as our compositing OpenGL context lives in. This
means our basic assumption that between two rendering passes the context
stays current does not hold.
The code already ensured that before we start a rendering pass the
context is made current, but there are many more possible cases. If we
use OpenGL in areas not triggered by the rendering loop but in response
to other events the context needs to be made current. This includes the
loading and unloading of effects (some effects use OpenGL in the static
effect check, in the ctor and dtor), background loading of texture data,
lazy loading after first usage invoked by shortcut, etc. etc.
To properly handle these cases new methods are added to EffectsHandler
to make the compositing OpenGL context current. These calls delegate down
into the scene. On non-OpenGL scenes they are noop, but on OpenGL they go
into the backend and make the context current. In addition they ensure
that Qt doesn't think that it's QOpenGLContext is current by calling
doneCurrent() on the QOpenGLContext::currentContext(). This unfortunately
causes an additional call to makeCurrent with a null context, but there
is no other way to tell Qt - it doesn't notice when a different context
is made current with low level API calls. In the multi-threaded
architecture this doesn't matter as ::currentContext() returns null.
A short evaluation showed that a transition to QOpenGLContext doesn't
seem feasible. Qt only supports either GLX or EGL while KWin supports
both and when entering the transition phase for Wayland, it would become
extremely tricky if our native platform is X11, but we want a Wayland
EGL context. A future solution might be to have a "KWin-QPA plugin" which
uses either xcb or Wayland and hides everything from Qt.
The API documentation is extended to describe when the effects-framework
ensures that an OpenGL context is current. The effects are changed to
make the context current in cases where it's not guaranteed. This has
been done by looking for creation or deletion of GLTextures and Shaders.
If there are other OpenGL usages outside the rendering loop, ctor/dtor
this needs to be changed, too.
2013-11-22 14:05:36 +00:00
|
|
|
#include <QOpenGLContext>
|
2013-08-29 23:30:13 +00:00
|
|
|
// system
|
|
|
|
#include <unistd.h>
|
2012-08-26 15:14:23 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
2010-11-21 13:01:39 +00:00
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
EglOnXBackend::EglOnXBackend()
|
2015-03-19 13:46:39 +00:00
|
|
|
: AbstractEglBackend()
|
2013-06-19 10:26:34 +00:00
|
|
|
, m_overlayWindow(new OverlayWindow())
|
2012-08-26 15:14:23 +00:00
|
|
|
, surfaceHasSubPost(0)
|
2013-11-21 09:44:06 +00:00
|
|
|
, m_bufferAge(0)
|
2015-03-19 10:26:53 +00:00
|
|
|
, m_usesOverlayWindow(true)
|
|
|
|
, m_connection(connection())
|
|
|
|
, m_x11Display(display())
|
|
|
|
, m_rootWindow(rootWindow())
|
|
|
|
, m_x11ScreenNumber(kwinApp()->x11ScreenNumber())
|
2012-08-26 15:14:23 +00:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
// Egl is always direct rendering
|
|
|
|
setIsDirectRendering(true);
|
|
|
|
}
|
2010-11-28 15:21:12 +00:00
|
|
|
|
2015-03-19 10:26:53 +00:00
|
|
|
#if HAVE_X11_XCB
|
|
|
|
EglOnXBackend::EglOnXBackend(X11WindowedBackend *backend)
|
2015-03-19 13:46:39 +00:00
|
|
|
: AbstractEglBackend()
|
2015-03-19 10:26:53 +00:00
|
|
|
, m_overlayWindow(nullptr)
|
|
|
|
, surfaceHasSubPost(0)
|
|
|
|
, m_bufferAge(0)
|
|
|
|
, m_usesOverlayWindow(false)
|
|
|
|
, m_x11Backend(backend)
|
|
|
|
, m_connection(backend->connection())
|
|
|
|
, m_x11Display(backend->display())
|
|
|
|
, m_rootWindow(backend->rootWindow())
|
|
|
|
, m_x11ScreenNumber(backend->screenNumer())
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
// Egl is always direct rendering
|
|
|
|
setIsDirectRendering(true);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
EglOnXBackend::~EglOnXBackend()
|
|
|
|
{
|
2015-03-19 10:26:53 +00:00
|
|
|
if (isFailed() && m_overlayWindow) {
|
2013-06-19 10:26:34 +00:00
|
|
|
m_overlayWindow->destroy();
|
|
|
|
}
|
2015-03-19 13:46:39 +00:00
|
|
|
cleanup();
|
2015-03-19 10:26:53 +00:00
|
|
|
if (m_overlayWindow) {
|
|
|
|
if (overlayWindow()->window()) {
|
|
|
|
overlayWindow()->destroy();
|
|
|
|
}
|
|
|
|
delete m_overlayWindow;
|
2012-08-26 15:14:23 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-21 13:01:39 +00:00
|
|
|
|
2013-03-28 20:52:26 +00:00
|
|
|
static bool gs_tripleBufferUndetected = true;
|
|
|
|
static bool gs_tripleBufferNeedsDetection = false;
|
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
void EglOnXBackend::init()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-08-26 15:14:23 +00:00
|
|
|
if (!initRenderingContext()) {
|
2013-07-23 05:02:52 +00:00
|
|
|
setFailed(QStringLiteral("Could not initialize rendering context"));
|
2010-11-28 15:21:12 +00:00
|
|
|
return;
|
2012-08-26 15:14:23 +00:00
|
|
|
}
|
2010-11-21 13:01:39 +00:00
|
|
|
|
2015-03-19 13:46:39 +00:00
|
|
|
initKWinGL();
|
2014-02-11 18:35:54 +00:00
|
|
|
if (!hasGLExtension(QByteArrayLiteral("EGL_KHR_image")) &&
|
|
|
|
(!hasGLExtension(QByteArrayLiteral("EGL_KHR_image_base")) ||
|
|
|
|
!hasGLExtension(QByteArrayLiteral("EGL_KHR_image_pixmap")))) {
|
2013-07-23 05:02:52 +00:00
|
|
|
setFailed(QStringLiteral("Required support for binding pixmaps to EGLImages not found, disabling compositing"));
|
2010-12-05 10:55:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-02-11 18:35:54 +00:00
|
|
|
if (!hasGLExtension(QByteArrayLiteral("GL_OES_EGL_image"))) {
|
2013-07-23 05:02:52 +00:00
|
|
|
setFailed(QStringLiteral("Required extension GL_OES_EGL_image not found, disabling compositing"));
|
2010-11-21 13:01:39 +00:00
|
|
|
return;
|
2010-12-04 11:31:18 +00:00
|
|
|
}
|
2012-03-29 20:11:28 +00:00
|
|
|
|
2013-03-22 11:18:51 +00:00
|
|
|
// check for EGL_NV_post_sub_buffer and whether it can be used on the surface
|
2014-02-11 18:35:54 +00:00
|
|
|
if (hasGLExtension(QByteArrayLiteral("EGL_NV_post_sub_buffer"))) {
|
2015-03-19 13:46:39 +00:00
|
|
|
if (eglQuerySurface(eglDisplay(), surface(), EGL_POST_SUB_BUFFER_SUPPORTED_NV, &surfaceHasSubPost) == EGL_FALSE) {
|
2013-03-22 11:18:51 +00:00
|
|
|
EGLint error = eglGetError();
|
|
|
|
if (error != EGL_SUCCESS && error != EGL_BAD_ATTRIBUTE) {
|
2013-07-23 05:02:52 +00:00
|
|
|
setFailed(QStringLiteral("query surface failed"));
|
2013-03-22 11:18:51 +00:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
surfaceHasSubPost = EGL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-21 09:44:06 +00:00
|
|
|
|
2015-03-19 13:46:39 +00:00
|
|
|
initBufferAge();
|
2013-11-21 09:44:06 +00:00
|
|
|
|
2013-03-28 20:52:26 +00:00
|
|
|
setSyncsToVBlank(false);
|
|
|
|
setBlocksForRetrace(false);
|
|
|
|
gs_tripleBufferNeedsDetection = false;
|
|
|
|
m_swapProfiler.init();
|
2013-03-22 11:18:51 +00:00
|
|
|
if (surfaceHasSubPost) {
|
2014-12-05 10:42:15 +00:00
|
|
|
qCDebug(KWIN_CORE) << "EGL implementation and surface support eglPostSubBufferNV, let's use it";
|
2013-03-22 11:18:51 +00:00
|
|
|
|
2013-04-12 12:05:19 +00:00
|
|
|
if (options->glPreferBufferSwap() != Options::NoSwapEncourage) {
|
|
|
|
// check if swap interval 1 is supported
|
|
|
|
EGLint val;
|
2015-03-19 13:46:39 +00:00
|
|
|
eglGetConfigAttrib(eglDisplay(), config(), EGL_MAX_SWAP_INTERVAL, &val);
|
2013-04-12 12:05:19 +00:00
|
|
|
if (val >= 1) {
|
2015-03-19 13:46:39 +00:00
|
|
|
if (eglSwapInterval(eglDisplay(), 1)) {
|
2014-12-05 10:42:15 +00:00
|
|
|
qCDebug(KWIN_CORE) << "Enabled v-sync";
|
2013-03-28 20:52:26 +00:00
|
|
|
setSyncsToVBlank(true);
|
|
|
|
const QByteArray tripleBuffer = qgetenv("KWIN_TRIPLE_BUFFER");
|
|
|
|
if (!tripleBuffer.isEmpty()) {
|
|
|
|
setBlocksForRetrace(qstrcmp(tripleBuffer, "0") == 0);
|
|
|
|
gs_tripleBufferUndetected = false;
|
|
|
|
}
|
|
|
|
gs_tripleBufferNeedsDetection = gs_tripleBufferUndetected;
|
2013-04-12 12:05:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-12-05 10:42:15 +00:00
|
|
|
qCWarning(KWIN_CORE) << "Cannot enable v-sync as max. swap interval is" << val;
|
2013-04-12 12:05:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// disable v-sync
|
2015-03-19 13:46:39 +00:00
|
|
|
eglSwapInterval(eglDisplay(), 0);
|
2013-03-22 11:18:51 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* In the GLX backend, we fall back to using glCopyPixels if we have no extension providing support for partial screen updates.
|
|
|
|
* However, that does not work in EGL - glCopyPixels with glDrawBuffer(GL_FRONT); does nothing.
|
|
|
|
* Hence we need EGL to preserve the backbuffer for us, so that we can draw the partial updates on it and call
|
|
|
|
* eglSwapBuffers() for each frame. eglSwapBuffers() then does the copy (no page flip possible in this mode),
|
|
|
|
* which means it is slow and not synced to the v-blank. */
|
2014-12-05 10:42:15 +00:00
|
|
|
qCWarning(KWIN_CORE) << "eglPostSubBufferNV not supported, have to enable buffer preservation - which breaks v-sync and performance";
|
2015-03-19 13:46:39 +00:00
|
|
|
eglSurfaceAttrib(eglDisplay(), surface(), EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED);
|
2012-03-29 20:11:28 +00:00
|
|
|
}
|
2015-03-19 13:46:39 +00:00
|
|
|
|
|
|
|
initWayland();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-11-21 13:01:39 +00:00
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
bool EglOnXBackend::initRenderingContext()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2015-03-19 13:46:39 +00:00
|
|
|
initClientExtensions();
|
|
|
|
EGLDisplay dpy;
|
2014-07-22 15:16:29 +00:00
|
|
|
|
|
|
|
// Use eglGetPlatformDisplayEXT() to get the display pointer
|
|
|
|
// if the implementation supports it.
|
2015-03-19 13:46:39 +00:00
|
|
|
const bool havePlatformBase = hasClientExtension(QByteArrayLiteral("EGL_EXT_platform_base"));
|
2014-07-22 15:16:29 +00:00
|
|
|
if (havePlatformBase) {
|
|
|
|
// Make sure that the X11 platform is supported
|
2015-03-19 13:46:39 +00:00
|
|
|
if (!hasClientExtension(QByteArrayLiteral("EGL_EXT_platform_x11")))
|
2014-07-22 15:16:29 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
const int attribs[] = {
|
2015-03-19 10:26:53 +00:00
|
|
|
EGL_PLATFORM_X11_SCREEN_EXT, m_x11ScreenNumber,
|
2014-07-22 15:16:29 +00:00
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
2015-03-19 10:26:53 +00:00
|
|
|
dpy = eglGetPlatformDisplayEXT(EGL_PLATFORM_X11_EXT, m_x11Display, attribs);
|
2014-07-22 15:16:29 +00:00
|
|
|
} else {
|
2015-03-19 10:26:53 +00:00
|
|
|
dpy = eglGetDisplay(m_x11Display);
|
2014-07-22 15:16:29 +00:00
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (dpy == EGL_NO_DISPLAY)
|
2010-11-28 15:21:12 +00:00
|
|
|
return false;
|
2015-03-19 13:46:39 +00:00
|
|
|
setEglDisplay(dpy);
|
|
|
|
initEglAPI();
|
2013-03-13 15:28:45 +00:00
|
|
|
|
2010-11-28 15:21:12 +00:00
|
|
|
initBufferConfigs();
|
2013-03-13 15:28:45 +00:00
|
|
|
|
2015-03-19 10:26:53 +00:00
|
|
|
if (m_usesOverlayWindow) {
|
|
|
|
if (!overlayWindow()->create()) {
|
|
|
|
qCCritical(KWIN_CORE) << "Could not get overlay window";
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
overlayWindow()->setup(None);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_window_t window = XCB_WINDOW_NONE;
|
|
|
|
if (m_overlayWindow) {
|
|
|
|
window = m_overlayWindow->window();
|
|
|
|
}
|
|
|
|
#if HAVE_X11_XCB
|
|
|
|
else if (m_x11Backend) {
|
|
|
|
window = m_x11Backend->window();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (window == XCB_WINDOW_NONE) {
|
2010-11-28 15:21:12 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2013-03-13 15:28:45 +00:00
|
|
|
|
2015-03-19 13:46:39 +00:00
|
|
|
EGLSurface surface = EGL_NO_SURFACE;
|
2014-07-22 15:16:29 +00:00
|
|
|
if (havePlatformBase) {
|
|
|
|
// Note: Window is 64 bits on a 64-bit architecture whereas xcb_window_t is
|
|
|
|
// always 32 bits. eglCreatePlatformWindowSurfaceEXT() expects the
|
|
|
|
// native_window parameter to be pointer to a Window, so this variable
|
|
|
|
// cannot be an xcb_window_t.
|
2015-03-19 13:46:39 +00:00
|
|
|
surface = eglCreatePlatformWindowSurfaceEXT(dpy, config(), (void *) &window, nullptr);
|
2014-07-22 15:16:29 +00:00
|
|
|
} else {
|
2015-03-19 13:46:39 +00:00
|
|
|
surface = eglCreateWindowSurface(dpy, config(), window, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (surface == EGL_NO_SURFACE) {
|
|
|
|
return false;
|
2014-07-22 15:16:29 +00:00
|
|
|
}
|
2015-03-19 13:46:39 +00:00
|
|
|
setSurface(surface);
|
2010-11-28 15:21:12 +00:00
|
|
|
|
2015-03-19 13:46:39 +00:00
|
|
|
EGLContext ctx = EGL_NO_CONTEXT;
|
2012-09-29 11:19:35 +00:00
|
|
|
#ifdef KWIN_HAVE_OPENGLES
|
2013-03-13 15:30:16 +00:00
|
|
|
const EGLint context_attribs[] = {
|
2010-11-28 15:21:12 +00:00
|
|
|
EGL_CONTEXT_CLIENT_VERSION, 2,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
2015-03-19 13:46:39 +00:00
|
|
|
ctx = eglCreateContext(dpy, config(), EGL_NO_CONTEXT, context_attribs);
|
2013-03-13 15:30:16 +00:00
|
|
|
#else
|
|
|
|
const EGLint context_attribs_31_core[] = {
|
|
|
|
EGL_CONTEXT_MAJOR_VERSION_KHR, 3,
|
|
|
|
EGL_CONTEXT_MINOR_VERSION_KHR, 1,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
const EGLint context_attribs_legacy[] = {
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
const QByteArray eglExtensions = eglQueryString(dpy, EGL_EXTENSIONS);
|
|
|
|
const QList<QByteArray> extensions = eglExtensions.split(' ');
|
|
|
|
|
|
|
|
// Try to create a 3.1 core context
|
|
|
|
if (options->glCoreProfile() && extensions.contains("EGL_KHR_create_context"))
|
2015-03-19 13:46:39 +00:00
|
|
|
ctx = eglCreateContext(dpy, config(), EGL_NO_CONTEXT, context_attribs_31_core);
|
2013-03-13 15:30:16 +00:00
|
|
|
|
|
|
|
if (ctx == EGL_NO_CONTEXT)
|
2015-03-19 13:46:39 +00:00
|
|
|
ctx = eglCreateContext(dpy, config(), EGL_NO_CONTEXT, context_attribs_legacy);
|
2013-03-13 15:30:16 +00:00
|
|
|
#endif
|
2013-03-13 15:28:45 +00:00
|
|
|
|
2012-09-29 11:19:35 +00:00
|
|
|
if (ctx == EGL_NO_CONTEXT) {
|
2014-12-05 10:42:15 +00:00
|
|
|
qCCritical(KWIN_CORE) << "Create Context failed";
|
2010-11-28 15:21:12 +00:00
|
|
|
return false;
|
2012-09-29 11:19:35 +00:00
|
|
|
}
|
2015-03-19 13:46:39 +00:00
|
|
|
setContext(ctx);
|
2013-03-13 15:28:45 +00:00
|
|
|
|
2012-09-29 11:19:35 +00:00
|
|
|
if (eglMakeCurrent(dpy, surface, surface, ctx) == EGL_FALSE) {
|
2014-12-05 10:42:15 +00:00
|
|
|
qCCritical(KWIN_CORE) << "Make Context Current failed";
|
2010-11-28 15:21:12 +00:00
|
|
|
return false;
|
2012-09-29 11:19:35 +00:00
|
|
|
}
|
2013-03-13 15:28:45 +00:00
|
|
|
|
2010-11-28 15:21:12 +00:00
|
|
|
EGLint error = eglGetError();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (error != EGL_SUCCESS) {
|
2014-12-05 10:42:15 +00:00
|
|
|
qCWarning(KWIN_CORE) << "Error occurred while creating context " << error;
|
2010-11-28 15:21:12 +00:00
|
|
|
return false;
|
2010-11-21 13:01:39 +00:00
|
|
|
}
|
2013-03-13 15:28:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-11-21 13:01:39 +00:00
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
bool EglOnXBackend::initBufferConfigs()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-11-28 15:21:12 +00:00
|
|
|
const EGLint config_attribs[] = {
|
2011-12-01 09:00:38 +00:00
|
|
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT|EGL_SWAP_BEHAVIOR_PRESERVED_BIT,
|
2010-11-28 15:21:12 +00:00
|
|
|
EGL_RED_SIZE, 1,
|
|
|
|
EGL_GREEN_SIZE, 1,
|
|
|
|
EGL_BLUE_SIZE, 1,
|
|
|
|
EGL_ALPHA_SIZE, 0,
|
2012-09-29 11:19:35 +00:00
|
|
|
#ifdef KWIN_HAVE_OPENGLES
|
2010-11-28 15:21:12 +00:00
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
2012-09-29 11:19:35 +00:00
|
|
|
#else
|
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
|
|
|
|
#endif
|
2010-11-28 15:21:12 +00:00
|
|
|
EGL_CONFIG_CAVEAT, EGL_NONE,
|
|
|
|
EGL_NONE,
|
|
|
|
};
|
|
|
|
|
|
|
|
EGLint count;
|
|
|
|
EGLConfig configs[1024];
|
2015-03-19 13:46:39 +00:00
|
|
|
if (eglChooseConfig(eglDisplay(), config_attribs, configs, 1024, &count) == EGL_FALSE) {
|
2014-12-05 10:42:15 +00:00
|
|
|
qCCritical(KWIN_CORE) << "choose config failed";
|
2012-09-29 11:19:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-11-28 15:21:12 +00:00
|
|
|
|
2015-03-19 10:26:53 +00:00
|
|
|
ScopedCPointer<xcb_get_window_attributes_reply_t> attribs(xcb_get_window_attributes_reply(m_connection,
|
|
|
|
xcb_get_window_attributes_unchecked(m_connection, m_rootWindow),
|
|
|
|
nullptr));
|
2013-03-11 10:01:38 +00:00
|
|
|
if (!attribs) {
|
2014-12-05 10:42:15 +00:00
|
|
|
qCCritical(KWIN_CORE) << "Failed to get window attributes of root window";
|
2013-03-11 10:01:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-11-28 15:21:12 +00:00
|
|
|
|
2015-03-19 13:46:39 +00:00
|
|
|
setConfig(configs[0]);
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0; i < count; i++) {
|
2010-11-28 15:21:12 +00:00
|
|
|
EGLint val;
|
2015-03-19 13:46:39 +00:00
|
|
|
if (eglGetConfigAttrib(eglDisplay(), configs[i], EGL_NATIVE_VISUAL_ID, &val) == EGL_FALSE) {
|
2014-12-05 10:42:15 +00:00
|
|
|
qCCritical(KWIN_CORE) << "egl get config attrib failed";
|
2012-09-29 11:19:35 +00:00
|
|
|
}
|
2013-03-11 10:01:38 +00:00
|
|
|
if (uint32_t(val) == attribs->visual) {
|
2015-03-19 13:46:39 +00:00
|
|
|
setConfig(configs[i]);
|
2010-11-28 15:21:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-11-21 13:01:39 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-11-21 13:01:39 +00:00
|
|
|
|
2012-10-07 11:43:31 +00:00
|
|
|
void EglOnXBackend::present()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2013-03-28 21:26:47 +00:00
|
|
|
if (lastDamage().isEmpty())
|
|
|
|
return;
|
|
|
|
|
2015-03-19 10:26:53 +00:00
|
|
|
const QSize screenSize = screens()->size();
|
|
|
|
const QRegion displayRegion(0, 0, screenSize.width(), screenSize.height());
|
2014-01-24 21:29:30 +00:00
|
|
|
const bool fullRepaint = supportsBufferAge() || (lastDamage() == displayRegion);
|
2013-03-22 11:18:51 +00:00
|
|
|
|
|
|
|
if (fullRepaint || !surfaceHasSubPost) {
|
2013-03-28 20:52:26 +00:00
|
|
|
if (gs_tripleBufferNeedsDetection) {
|
|
|
|
eglWaitGL();
|
|
|
|
m_swapProfiler.begin();
|
|
|
|
}
|
2013-03-22 11:18:51 +00:00
|
|
|
// the entire screen changed, or we cannot do partial updates (which implies we enabled surface preservation)
|
2015-03-19 13:46:39 +00:00
|
|
|
eglSwapBuffers(eglDisplay(), surface());
|
2013-03-28 20:52:26 +00:00
|
|
|
if (gs_tripleBufferNeedsDetection) {
|
|
|
|
eglWaitGL();
|
|
|
|
if (char result = m_swapProfiler.end()) {
|
|
|
|
gs_tripleBufferUndetected = gs_tripleBufferNeedsDetection = false;
|
2013-07-23 20:34:41 +00:00
|
|
|
if (result == 'd' && GLPlatform::instance()->driver() == Driver_NVidia) {
|
|
|
|
// TODO this is a workaround, we should get __GL_YIELD set before libGL checks it
|
|
|
|
if (qstrcmp(qgetenv("__GL_YIELD"), "USLEEP")) {
|
|
|
|
options->setGlPreferBufferSwap(0);
|
2015-03-19 13:46:39 +00:00
|
|
|
eglSwapInterval(eglDisplay(), 0);
|
2014-12-05 10:42:15 +00:00
|
|
|
qCWarning(KWIN_CORE) << "\nIt seems you are using the nvidia driver without triple buffering\n"
|
2013-07-23 20:34:41 +00:00
|
|
|
"You must export __GL_YIELD=\"USLEEP\" to prevent large CPU overhead on synced swaps\n"
|
|
|
|
"Preferably, enable the TripleBuffer Option in the xorg.conf Device\n"
|
|
|
|
"For this reason, the tearing prevention has been disabled.\n"
|
|
|
|
"See https://bugs.kde.org/show_bug.cgi?id=322060\n";
|
|
|
|
}
|
|
|
|
}
|
2013-03-28 20:52:26 +00:00
|
|
|
setBlocksForRetrace(result == 'd');
|
|
|
|
}
|
|
|
|
}
|
2014-01-24 21:29:30 +00:00
|
|
|
if (supportsBufferAge()) {
|
2015-03-19 13:46:39 +00:00
|
|
|
eglQuerySurface(eglDisplay(), surface(), EGL_BUFFER_AGE_EXT, &m_bufferAge);
|
2014-01-24 21:29:30 +00:00
|
|
|
}
|
2013-02-18 22:17:46 +00:00
|
|
|
} else {
|
2013-03-22 11:18:51 +00:00
|
|
|
// a part of the screen changed, and we can use eglPostSubBufferNV to copy the updated area
|
|
|
|
foreach (const QRect & r, lastDamage().rects()) {
|
2015-03-19 13:46:39 +00:00
|
|
|
eglPostSubBufferNV(eglDisplay(), surface(), r.left(), screenSize.height() - r.bottom() - 1, r.width(), r.height());
|
2013-03-22 11:18:51 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2011-10-29 15:09:26 +00:00
|
|
|
|
2013-03-22 11:18:51 +00:00
|
|
|
setLastDamage(QRegion());
|
2014-01-24 21:29:30 +00:00
|
|
|
if (!supportsBufferAge()) {
|
|
|
|
eglWaitGL();
|
2015-03-19 10:26:53 +00:00
|
|
|
xcb_flush(m_connection);
|
2014-01-24 21:29:30 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-11-21 13:01:39 +00:00
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
void EglOnXBackend::screenGeometryChanged(const QSize &size)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-08-26 15:14:23 +00:00
|
|
|
Q_UNUSED(size)
|
2013-11-21 09:44:06 +00:00
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
// TODO: base implementation in OpenGLBackend
|
2013-11-21 09:44:06 +00:00
|
|
|
|
|
|
|
// The back buffer contents are now undefined
|
|
|
|
m_bufferAge = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-11-21 13:01:39 +00:00
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
SceneOpenGL::TexturePrivate *EglOnXBackend::createBackendTexture(SceneOpenGL::Texture *texture)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-08-26 15:14:23 +00:00
|
|
|
return new EglTexture(texture, this);
|
|
|
|
}
|
2011-10-16 08:09:16 +00:00
|
|
|
|
2013-11-21 09:39:29 +00:00
|
|
|
QRegion EglOnXBackend::prepareRenderingFrame()
|
2012-08-26 15:14:23 +00:00
|
|
|
{
|
2013-11-21 09:44:06 +00:00
|
|
|
QRegion repaint;
|
|
|
|
|
2013-08-29 23:30:13 +00:00
|
|
|
if (gs_tripleBufferNeedsDetection) {
|
|
|
|
// the composite timer floors the repaint frequency. This can pollute our triple buffering
|
|
|
|
// detection because the glXSwapBuffers call for the new frame has to wait until the pending
|
|
|
|
// one scanned out.
|
|
|
|
// So we compensate for that by waiting an extra milisecond to give the driver the chance to
|
|
|
|
// fllush the buffer queue
|
|
|
|
usleep(1000);
|
|
|
|
}
|
2013-11-21 09:39:29 +00:00
|
|
|
|
2013-03-28 21:26:47 +00:00
|
|
|
present();
|
2013-11-21 09:44:06 +00:00
|
|
|
|
|
|
|
if (supportsBufferAge())
|
|
|
|
repaint = accumulatedDamageHistory(m_bufferAge);
|
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
startRenderTimer();
|
2013-03-28 21:26:47 +00:00
|
|
|
eglWaitNative(EGL_CORE_NATIVE_ENGINE);
|
2013-11-21 09:39:29 +00:00
|
|
|
|
2013-11-21 09:44:06 +00:00
|
|
|
return repaint;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-11-21 13:01:39 +00:00
|
|
|
|
2013-11-21 09:39:29 +00:00
|
|
|
void EglOnXBackend::endRenderingFrame(const QRegion &renderedRegion, const QRegion &damagedRegion)
|
2011-11-26 15:15:46 +00:00
|
|
|
{
|
2013-11-21 09:44:06 +00:00
|
|
|
if (damagedRegion.isEmpty()) {
|
|
|
|
setLastDamage(QRegion());
|
|
|
|
|
|
|
|
// If the damaged region of a window is fully occluded, the only
|
|
|
|
// rendering done, if any, will have been to repair a reused back
|
|
|
|
// buffer, making it identical to the front buffer.
|
|
|
|
//
|
|
|
|
// In this case we won't post the back buffer. Instead we'll just
|
|
|
|
// set the buffer age to 1, so the repaired regions won't be
|
|
|
|
// rendered again in the next frame.
|
|
|
|
if (!renderedRegion.isEmpty())
|
|
|
|
glFlush();
|
|
|
|
|
|
|
|
m_bufferAge = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-21 09:39:29 +00:00
|
|
|
setLastDamage(renderedRegion);
|
2013-11-21 09:38:16 +00:00
|
|
|
|
2013-03-28 21:26:47 +00:00
|
|
|
if (!blocksForRetrace()) {
|
2013-11-21 09:38:16 +00:00
|
|
|
// This also sets lastDamage to empty which prevents the frame from
|
|
|
|
// being posted again when prepareRenderingFrame() is called.
|
|
|
|
present();
|
|
|
|
} else {
|
|
|
|
// Make sure that the GPU begins processing the command stream
|
|
|
|
// now and not the next time prepareRenderingFrame() is called.
|
|
|
|
glFlush();
|
2013-03-28 21:26:47 +00:00
|
|
|
}
|
2012-08-26 15:14:23 +00:00
|
|
|
|
2015-03-19 10:26:53 +00:00
|
|
|
if (m_overlayWindow && overlayWindow()->window()) // show the window only after the first pass,
|
2012-08-26 15:14:23 +00:00
|
|
|
overlayWindow()->show(); // since that pass may take long
|
2013-11-21 09:44:06 +00:00
|
|
|
|
|
|
|
// Save the damaged region to history
|
|
|
|
if (supportsBufferAge())
|
|
|
|
addToDamageHistory(damagedRegion);
|
2011-11-26 15:15:46 +00:00
|
|
|
}
|
|
|
|
|
2013-06-19 10:26:34 +00:00
|
|
|
bool EglOnXBackend::usesOverlayWindow() const
|
|
|
|
{
|
2015-03-19 10:26:53 +00:00
|
|
|
return m_usesOverlayWindow;
|
2013-06-19 10:26:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OverlayWindow* EglOnXBackend::overlayWindow()
|
|
|
|
{
|
|
|
|
return m_overlayWindow;
|
|
|
|
}
|
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
/************************************************
|
|
|
|
* EglTexture
|
|
|
|
************************************************/
|
2010-11-21 13:01:39 +00:00
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
EglTexture::EglTexture(KWin::SceneOpenGL::Texture *texture, KWin::EglOnXBackend *backend)
|
2015-03-19 13:46:39 +00:00
|
|
|
: AbstractEglTexture(texture, backend)
|
2012-08-26 15:14:23 +00:00
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-11-21 13:01:39 +00:00
|
|
|
|
2015-03-19 13:46:39 +00:00
|
|
|
EglTexture::~EglTexture() = default;
|
2015-02-11 10:00:12 +00:00
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
void KWin::EglTexture::onDamage()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-02-20 09:25:13 +00:00
|
|
|
if (options->isGlStrictBinding()) {
|
2011-12-01 09:00:38 +00:00
|
|
|
// This is just implemented to be consistent with
|
|
|
|
// the example in mesa/demos/src/egl/opengles1/texture_from_pixmap.c
|
|
|
|
eglWaitNative(EGL_CORE_NATIVE_ENGINE);
|
2015-03-19 13:46:39 +00:00
|
|
|
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES) image());
|
2011-12-01 09:00:38 +00:00
|
|
|
}
|
2012-01-07 11:12:29 +00:00
|
|
|
GLTexturePrivate::onDamage();
|
|
|
|
}
|
2012-08-26 15:14:23 +00:00
|
|
|
|
|
|
|
} // namespace
|