File indexing completed on 2025-04-20 10:57:34
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 #include "abstract_egl_backend.h" 0011 #include "drm_render_backend.h" 0012 0013 #include <kwinglutils.h> 0014 0015 #include <QHash> 0016 #include <QPointer> 0017 #include <optional> 0018 0019 struct gbm_surface; 0020 struct gbm_bo; 0021 0022 namespace KWaylandServer 0023 { 0024 class SurfaceInterface; 0025 } 0026 0027 namespace KWin 0028 { 0029 0030 struct DmaBufAttributes; 0031 class Output; 0032 class DrmAbstractOutput; 0033 class DrmBuffer; 0034 class DrmGbmBuffer; 0035 class DrmOutput; 0036 class GbmSurface; 0037 class GbmBuffer; 0038 class DumbSwapchain; 0039 class ShadowBuffer; 0040 class DrmBackend; 0041 class DrmGpu; 0042 class EglGbmLayer; 0043 class DrmOutputLayer; 0044 class DrmPipeline; 0045 0046 struct GbmFormat 0047 { 0048 uint32_t drmFormat = 0; 0049 uint32_t bpp; 0050 EGLint alphaSize = -1; 0051 }; 0052 bool operator==(const GbmFormat &lhs, const GbmFormat &rhs); 0053 0054 /** 0055 * @brief OpenGL Backend using Egl on a GBM surface. 0056 */ 0057 class EglGbmBackend : public AbstractEglBackend, public DrmRenderBackend 0058 { 0059 Q_OBJECT 0060 public: 0061 EglGbmBackend(DrmBackend *drmBackend); 0062 ~EglGbmBackend() override; 0063 0064 std::unique_ptr<SurfaceTexture> createSurfaceTextureInternal(SurfacePixmapInternal *pixmap) override; 0065 std::unique_ptr<SurfaceTexture> createSurfaceTextureWayland(SurfacePixmapWayland *pixmap) override; 0066 0067 void present(Output *output) override; 0068 OutputLayer *primaryLayer(Output *output) override; 0069 0070 void init() override; 0071 bool prefer10bpc() const override; 0072 std::shared_ptr<DrmPipelineLayer> createPrimaryLayer(DrmPipeline *pipeline) override; 0073 std::shared_ptr<DrmOverlayLayer> createCursorLayer(DrmPipeline *pipeline) override; 0074 std::shared_ptr<DrmOutputLayer> createLayer(DrmVirtualOutput *output) override; 0075 0076 std::shared_ptr<GLTexture> textureForOutput(Output *requestedOutput) const override; 0077 0078 std::shared_ptr<DrmBuffer> testBuffer(DrmAbstractOutput *output); 0079 EGLConfig config(uint32_t format) const; 0080 std::optional<GbmFormat> gbmFormatForDrmFormat(uint32_t format) const; 0081 DrmGpu *gpu() const; 0082 0083 EGLImageKHR importBufferObjectAsImage(gbm_bo *bo); 0084 std::shared_ptr<GLTexture> importBufferObjectAsTexture(gbm_bo *bo); 0085 0086 private: 0087 bool initializeEgl(); 0088 bool initBufferConfigs(); 0089 bool initRenderingContext(); 0090 0091 DrmBackend *m_backend; 0092 QHash<uint32_t, GbmFormat> m_formats; 0093 QHash<uint32_t, EGLConfig> m_configs; 0094 0095 friend class EglGbmTexture; 0096 }; 0097 0098 } // namespace