2012-08-26 15:14:23 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2012 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#ifndef KWIN_GLX_BACKEND_H
|
|
|
|
#define KWIN_GLX_BACKEND_H
|
2017-09-08 20:30:18 +00:00
|
|
|
#include "backend.h"
|
|
|
|
#include "texture.h"
|
|
|
|
#include "swap_profiler.h"
|
2014-08-07 12:16:35 +00:00
|
|
|
#include "x11eventfilter.h"
|
|
|
|
|
2015-01-08 06:12:20 +00:00
|
|
|
#include <xcb/glx.h>
|
2015-10-30 10:50:31 +00:00
|
|
|
#include <epoxy/glx.h>
|
2017-09-08 20:30:18 +00:00
|
|
|
#include <fixx11h.h>
|
2014-08-07 12:16:35 +00:00
|
|
|
#include <memory>
|
2012-08-26 15:14:23 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2016-11-10 15:51:39 +00:00
|
|
|
// GLX_MESA_swap_interval
|
|
|
|
using glXSwapIntervalMESA_func = int (*)(unsigned int interval);
|
|
|
|
extern glXSwapIntervalMESA_func glXSwapIntervalMESA;
|
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
class FBConfigInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GLXFBConfig fbconfig;
|
|
|
|
int bind_texture_format;
|
|
|
|
int texture_targets;
|
|
|
|
int y_inverted;
|
|
|
|
int mipmap;
|
|
|
|
};
|
|
|
|
|
2014-08-07 12:16:35 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
class SwapEventFilter : public X11EventFilter
|
|
|
|
{
|
|
|
|
public:
|
2015-01-08 06:12:20 +00:00
|
|
|
SwapEventFilter(xcb_drawable_t drawable, xcb_glx_drawable_t glxDrawable);
|
2014-08-07 12:16:35 +00:00
|
|
|
bool event(xcb_generic_event_t *event) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
xcb_drawable_t m_drawable;
|
2015-01-08 06:12:20 +00:00
|
|
|
xcb_glx_drawable_t m_glxDrawable;
|
2014-08-07 12:16:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
/**
|
|
|
|
* @brief OpenGL Backend using GLX over an X overlay window.
|
|
|
|
**/
|
|
|
|
class GlxBackend : public OpenGLBackend
|
|
|
|
{
|
|
|
|
public:
|
2016-11-11 08:59:46 +00:00
|
|
|
GlxBackend(Display *display);
|
2012-08-26 15:14:23 +00:00
|
|
|
virtual ~GlxBackend();
|
|
|
|
virtual void screenGeometryChanged(const QSize &size);
|
2017-09-08 20:30:18 +00:00
|
|
|
virtual SceneOpenGLTexturePrivate *createBackendTexture(SceneOpenGLTexture *texture) override;
|
2013-11-21 09:39:29 +00:00
|
|
|
virtual QRegion prepareRenderingFrame();
|
2014-01-07 08:28:59 +00:00
|
|
|
virtual void endRenderingFrame(const QRegion &damage, const QRegion &damagedRegion);
|
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
|
|
|
virtual bool makeCurrent() override;
|
|
|
|
virtual void doneCurrent() override;
|
2013-06-19 10:26:34 +00:00
|
|
|
virtual OverlayWindow* overlayWindow() override;
|
|
|
|
virtual bool usesOverlayWindow() const override;
|
2015-11-25 12:09:28 +00:00
|
|
|
void init() override;
|
2012-08-26 15:14:23 +00:00
|
|
|
|
|
|
|
protected:
|
2012-10-07 11:43:31 +00:00
|
|
|
virtual void present();
|
2012-08-26 15:14:23 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool initBuffer();
|
2016-11-10 14:07:15 +00:00
|
|
|
bool checkVersion();
|
2016-11-10 14:56:36 +00:00
|
|
|
void initExtensions();
|
2012-08-26 15:14:23 +00:00
|
|
|
void waitSync();
|
|
|
|
bool initRenderingContext();
|
2013-03-11 15:16:05 +00:00
|
|
|
bool initFbConfig();
|
2014-09-03 16:43:45 +00:00
|
|
|
void initVisualDepthHashTable();
|
2012-11-13 21:19:01 +00:00
|
|
|
void setSwapInterval(int interval);
|
2016-11-11 08:59:46 +00:00
|
|
|
Display *display() const {
|
|
|
|
return m_x11Display;
|
|
|
|
}
|
2012-08-26 15:14:23 +00:00
|
|
|
|
2014-09-03 16:43:45 +00:00
|
|
|
int visualDepth(xcb_visualid_t visual) const;
|
2014-04-13 18:47:58 +00:00
|
|
|
FBConfigInfo *infoForVisual(xcb_visualid_t visual);
|
|
|
|
|
2013-06-19 10:26:34 +00:00
|
|
|
/**
|
|
|
|
* @brief The OverlayWindow used by this Backend.
|
|
|
|
**/
|
|
|
|
OverlayWindow *m_overlayWindow;
|
2013-03-11 15:27:24 +00:00
|
|
|
Window window;
|
2013-03-11 15:05:47 +00:00
|
|
|
GLXFBConfig fbconfig;
|
2013-03-11 15:27:24 +00:00
|
|
|
GLXWindow glxWindow;
|
2013-03-11 15:05:47 +00:00
|
|
|
GLXContext ctx;
|
2014-04-13 18:47:58 +00:00
|
|
|
QHash<xcb_visualid_t, FBConfigInfo *> m_fbconfigHash;
|
2014-09-03 16:43:45 +00:00
|
|
|
QHash<xcb_visualid_t, int> m_visualDepthHash;
|
2014-08-07 12:16:35 +00:00
|
|
|
std::unique_ptr<SwapEventFilter> m_swapEventFilter;
|
2013-11-21 09:44:06 +00:00
|
|
|
int m_bufferAge;
|
2015-01-12 07:54:25 +00:00
|
|
|
bool m_haveMESACopySubBuffer = false;
|
|
|
|
bool m_haveMESASwapControl = false;
|
|
|
|
bool m_haveEXTSwapControl = false;
|
|
|
|
bool m_haveSGISwapControl = false;
|
|
|
|
bool m_haveINTELSwapEvent = false;
|
|
|
|
bool haveSwapInterval = false;
|
|
|
|
bool haveWaitSync = false;
|
2016-11-11 08:59:46 +00:00
|
|
|
Display *m_x11Display;
|
2017-09-08 20:30:18 +00:00
|
|
|
SwapProfiler m_swapProfiler;
|
2012-08-26 15:14:23 +00:00
|
|
|
friend class GlxTexture;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Texture using an GLXPixmap.
|
|
|
|
**/
|
2017-09-08 20:30:18 +00:00
|
|
|
class GlxTexture : public SceneOpenGLTexturePrivate
|
2012-08-26 15:14:23 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~GlxTexture();
|
|
|
|
virtual void onDamage();
|
2015-02-11 10:00:12 +00:00
|
|
|
virtual bool loadTexture(WindowPixmap *pixmap) override;
|
2012-08-26 15:14:23 +00:00
|
|
|
virtual OpenGLBackend *backend();
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class GlxBackend;
|
2017-09-08 20:30:18 +00:00
|
|
|
GlxTexture(SceneOpenGLTexture *texture, GlxBackend *backend);
|
2015-02-11 10:00:12 +00:00
|
|
|
bool loadTexture(xcb_pixmap_t pix, const QSize &size, xcb_visualid_t visual);
|
2016-11-11 08:59:46 +00:00
|
|
|
Display *display() const {
|
|
|
|
return m_backend->m_x11Display;
|
|
|
|
}
|
2017-09-08 20:30:18 +00:00
|
|
|
SceneOpenGLTexture *q;
|
2012-08-26 15:14:23 +00:00
|
|
|
GlxBackend *m_backend;
|
|
|
|
GLXPixmap m_glxpixmap; // the glx pixmap the texture is bound to
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
#endif // KWIN_GLX_BACKEND_H
|