KWin
Loading...
Searching...
No Matches
x11_standalone_glx_backend.h
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2012 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#pragma once
10#include "core/outputlayer.h"
11#include "options.h"
14#include "utils/damagejournal.h"
15#include "x11eventfilter.h"
16
17#include <epoxy/glx.h>
18#include <fixx11h.h>
19#include <xcb/glx.h>
20
21#include "opengl/gltexture.h"
22#include "opengl/gltexture_p.h"
23
24#include <QHash>
25#include <memory>
26
27namespace KWin
28{
29
30class GlxPixmapTexturePrivate;
31class VsyncMonitor;
32class X11StandaloneBackend;
33class GlxBackend;
34class GLRenderTimeQuery;
35class GlxContext;
36
37// GLX_MESA_swap_interval
38using glXSwapIntervalMESA_func = int (*)(unsigned int interval);
40
42{
43public:
44 GLXFBConfig fbconfig;
48 int mipmap;
49};
50
51// ------------------------------------------------------------------
52
54{
55public:
56 SwapEventFilter(xcb_drawable_t drawable, xcb_glx_drawable_t glxDrawable);
57 bool event(xcb_generic_event_t *event) override;
58
59private:
60 xcb_drawable_t m_drawable;
61 xcb_glx_drawable_t m_glxDrawable;
62};
63
64class GlxLayer : public OutputLayer
65{
66public:
67 GlxLayer(GlxBackend *backend);
68
69 std::optional<OutputLayerBeginFrameInfo> beginFrame() override;
70 bool endFrame(const QRegion &renderedRegion, const QRegion &damagedRegion) override;
71 std::chrono::nanoseconds queryRenderTime() const override;
72
73private:
74 GlxBackend *const m_backend;
75};
76
81{
82 Q_OBJECT
83
84public:
86 ~GlxBackend() override;
87 std::unique_ptr<SurfaceTexture> createSurfaceTextureX11(SurfacePixmapX11 *pixmap) override;
89 void endFrame(const QRegion &renderedRegion, const QRegion &damagedRegion);
90 std::chrono::nanoseconds queryRenderTime();
91 void present(Output *output, const std::shared_ptr<OutputFrame> &frame) override;
92 bool makeCurrent() override;
93 void doneCurrent() override;
94 OverlayWindow *overlayWindow() const override;
95 void init() override;
96 OutputLayer *primaryLayer(Output *output) override;
97
99 {
100 return m_x11Display;
101 }
102
103private:
104 void vblank(std::chrono::nanoseconds timestamp);
105 void present(const QRegion &damage);
106 bool initBuffer();
107 bool checkVersion();
108 void initExtensions();
109 bool initFbConfig();
110 void initVisualDepthHashTable();
111 void setSwapInterval(int interval);
112 void screenGeometryChanged();
113
114 int visualDepth(xcb_visualid_t visual) const;
115 const FBConfigInfo &infoForVisual(xcb_visualid_t visual);
116
120 std::unique_ptr<OverlayWindow> m_overlayWindow;
121 ::Window window;
122 GLXFBConfig fbconfig;
123 GLXWindow glxWindow;
124 std::unique_ptr<GlxContext> m_context;
125 QHash<xcb_visualid_t, FBConfigInfo> m_fbconfigHash;
126 QHash<xcb_visualid_t, int> m_visualDepthHash;
127 std::unique_ptr<SwapEventFilter> m_swapEventFilter;
128 std::unique_ptr<GLFramebuffer> m_fbo;
129 DamageJournal m_damageJournal;
130 QRegion m_lastRenderedRegion;
131 int m_bufferAge;
132 bool m_haveMESACopySubBuffer = false;
133 bool m_haveMESASwapControl = false;
134 bool m_haveEXTSwapControl = false;
135 bool m_haveSGISwapControl = false;
136 ::Display *m_x11Display;
137 X11StandaloneBackend *m_backend;
138 std::unique_ptr<VsyncMonitor> m_vsyncMonitor;
139 std::unique_ptr<GlxLayer> m_layer;
140 std::unique_ptr<GLRenderTimeQuery> m_query;
142 std::shared_ptr<OutputFrame> m_frame;
143 friend class GlxPixmapTexture;
144};
145
146class GlxPixmapTexture final : public GLTexture
147{
148public:
149 explicit GlxPixmapTexture(GlxBackend *backend);
151
153
154private:
155 void onDamage() override;
156
157 GlxBackend *const m_backend;
158 GLXPixmap m_glxPixmap;
159};
160
162{
163public:
165
166 bool create() override;
167 void update(const QRegion &region) override;
168};
169
170} // namespace
GLuint texture() const
OpenGL Backend using GLX over an X overlay window.
OutputLayerBeginFrameInfo beginFrame()
GlxBackend(::Display *display, X11StandaloneBackend *backend)
std::chrono::nanoseconds queryRenderTime()
OverlayWindow * overlayWindow() const override
::Display * display() const
void present(Output *output, const std::shared_ptr< OutputFrame > &frame) override
OutputLayer * primaryLayer(Output *output) override
void endFrame(const QRegion &renderedRegion, const QRegion &damagedRegion)
std::unique_ptr< SurfaceTexture > createSurfaceTextureX11(SurfacePixmapX11 *pixmap) override
std::optional< OutputLayerBeginFrameInfo > beginFrame() override
std::chrono::nanoseconds queryRenderTime() const override
bool endFrame(const QRegion &renderedRegion, const QRegion &damagedRegion) override
GlxLayer(GlxBackend *backend)
void update(const QRegion &region) override
GlxSurfaceTextureX11(GlxBackend *backend, SurfacePixmapX11 *pixmap)
The OpenGLBackend creates and holds the OpenGL context and is responsible for Texture from Pixmap.
OpenGLBackend * backend() const
bool event(xcb_generic_event_t *event) override
SwapEventFilter(xcb_drawable_t drawable, xcb_glx_drawable_t glxDrawable)
glXSwapIntervalMESA_func glXSwapIntervalMESA
int(*)(unsigned int interval) glXSwapIntervalMESA_func
struct _XDisplay Display