File indexing completed on 2024-11-10 04:56:32
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #pragma once 0010 0011 #include "core/outputlayer.h" 0012 #include "platformsupport/scenes/opengl/abstract_egl_backend.h" 0013 #include <chrono> 0014 #include <memory> 0015 0016 namespace KWin 0017 { 0018 0019 class EglSwapchainSlot; 0020 class EglSwapchain; 0021 class GraphicsBufferAllocator; 0022 class VirtualBackend; 0023 class GLFramebuffer; 0024 class GLTexture; 0025 class VirtualEglBackend; 0026 class GLRenderTimeQuery; 0027 0028 class VirtualEglLayer : public OutputLayer 0029 { 0030 public: 0031 VirtualEglLayer(Output *output, VirtualEglBackend *backend); 0032 0033 std::optional<OutputLayerBeginFrameInfo> beginFrame() override; 0034 bool endFrame(const QRegion &renderedRegion, const QRegion &damagedRegion) override; 0035 0036 std::shared_ptr<GLTexture> texture() const; 0037 std::chrono::nanoseconds queryRenderTime() const override; 0038 0039 private: 0040 VirtualEglBackend *const m_backend; 0041 Output *m_output; 0042 std::shared_ptr<EglSwapchain> m_swapchain; 0043 std::shared_ptr<EglSwapchainSlot> m_current; 0044 std::unique_ptr<GLRenderTimeQuery> m_query; 0045 }; 0046 0047 /** 0048 * @brief OpenGL Backend using Egl on a GBM surface. 0049 */ 0050 class VirtualEglBackend : public AbstractEglBackend 0051 { 0052 Q_OBJECT 0053 0054 public: 0055 VirtualEglBackend(VirtualBackend *b); 0056 ~VirtualEglBackend() override; 0057 std::unique_ptr<SurfaceTexture> createSurfaceTextureWayland(SurfacePixmap *pixmap) override; 0058 std::pair<std::shared_ptr<KWin::GLTexture>, ColorDescription> textureForOutput(Output *output) const override; 0059 OutputLayer *primaryLayer(Output *output) override; 0060 void present(Output *output, const std::shared_ptr<OutputFrame> &frame) override; 0061 void init() override; 0062 0063 VirtualBackend *backend() const; 0064 GraphicsBufferAllocator *graphicsBufferAllocator() const override; 0065 0066 private: 0067 bool initializeEgl(); 0068 bool initRenderingContext(); 0069 0070 void addOutput(Output *output); 0071 void removeOutput(Output *output); 0072 0073 VirtualBackend *m_backend; 0074 std::unique_ptr<GraphicsBufferAllocator> m_allocator; 0075 std::map<Output *, std::unique_ptr<VirtualEglLayer>> m_outputs; 0076 }; 0077 0078 } // namespace KWin