File indexing completed on 2025-04-27 11:32:59
0001 /* 0002 SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "../common/x11_common_egl_backend.h" 0010 #include "core/outputlayer.h" 0011 #include "openglsurfacetexture_x11.h" 0012 #include "utils/damagejournal.h" 0013 0014 #include <kwingltexture.h> 0015 #include <kwingltexture_p.h> 0016 0017 namespace KWin 0018 { 0019 0020 class EglPixmapTexturePrivate; 0021 class SoftwareVsyncMonitor; 0022 class X11StandaloneBackend; 0023 class EglBackend; 0024 0025 class EglLayer : public OutputLayer 0026 { 0027 public: 0028 EglLayer(EglBackend *backend); 0029 0030 std::optional<OutputLayerBeginFrameInfo> beginFrame() override; 0031 bool endFrame(const QRegion &renderedRegion, const QRegion &damagedRegion) override; 0032 0033 private: 0034 EglBackend *const m_backend; 0035 }; 0036 0037 class EglBackend : public EglOnXBackend 0038 { 0039 Q_OBJECT 0040 0041 public: 0042 EglBackend(Display *display, X11StandaloneBackend *platform); 0043 ~EglBackend() override; 0044 0045 void init() override; 0046 0047 std::unique_ptr<SurfaceTexture> createSurfaceTextureX11(SurfacePixmapX11 *texture) override; 0048 OutputLayerBeginFrameInfo beginFrame(); 0049 void endFrame(const QRegion &renderedRegion, const QRegion &damagedRegion); 0050 void present(Output *output) override; 0051 OverlayWindow *overlayWindow() const override; 0052 OutputLayer *primaryLayer(Output *output) override; 0053 0054 protected: 0055 bool createSurfaces() override; 0056 0057 private: 0058 void screenGeometryChanged(); 0059 void presentSurface(EGLSurface surface, const QRegion &damage, const QRect &screenGeometry); 0060 void vblank(std::chrono::nanoseconds timestamp); 0061 0062 X11StandaloneBackend *m_backend; 0063 std::unique_ptr<SoftwareVsyncMonitor> m_vsyncMonitor; 0064 std::unique_ptr<OverlayWindow> m_overlayWindow; 0065 DamageJournal m_damageJournal; 0066 std::unique_ptr<GLFramebuffer> m_fbo; 0067 int m_bufferAge = 0; 0068 QRegion m_lastRenderedRegion; 0069 std::unique_ptr<EglLayer> m_layer; 0070 }; 0071 0072 class EglPixmapTexture : public GLTexture 0073 { 0074 public: 0075 explicit EglPixmapTexture(EglBackend *backend); 0076 0077 bool create(SurfacePixmapX11 *texture); 0078 0079 private: 0080 Q_DECLARE_PRIVATE(EglPixmapTexture) 0081 }; 0082 0083 class EglPixmapTexturePrivate : public GLTexturePrivate 0084 { 0085 public: 0086 EglPixmapTexturePrivate(EglPixmapTexture *texture, EglBackend *backend); 0087 ~EglPixmapTexturePrivate() override; 0088 0089 bool create(SurfacePixmapX11 *texture); 0090 0091 protected: 0092 void onDamage() override; 0093 0094 private: 0095 EglPixmapTexture *q; 0096 EglBackend *m_backend; 0097 EGLImageKHR m_image = EGL_NO_IMAGE_KHR; 0098 }; 0099 0100 class EglSurfaceTextureX11 : public OpenGLSurfaceTextureX11 0101 { 0102 public: 0103 EglSurfaceTextureX11(EglBackend *backend, SurfacePixmapX11 *texture); 0104 0105 bool create() override; 0106 void update(const QRegion ®ion) override; 0107 }; 0108 0109 } // namespace KWin