KWin
Loading...
Searching...
No Matches
drm_egl_layer_surface.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: 2022 Xaver Hugl <xaver.hugl@gmail.com>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#pragma once
10
11#include <QHash>
12#include <QMap>
13#include <QPointer>
14#include <QRegion>
15#include <chrono>
16#include <optional>
17
18#include "core/outputlayer.h"
19#include "drm_plane.h"
20#include "opengl/gltexture.h"
21#include "utils/damagejournal.h"
23
24struct gbm_bo;
25
26namespace KWin
27{
28
29class DrmFramebuffer;
30class EglSwapchain;
31class EglSwapchainSlot;
32class QPainterSwapchain;
33class ShadowBuffer;
34class EglContext;
35class EglGbmBackend;
36class GraphicsBuffer;
37class SurfaceItem;
38class GLTexture;
39class GLRenderTimeQuery;
40class ColorTransformation;
41class GlLookUpTable;
42class IccProfile;
43class IccShader;
44
45class EglGbmLayerSurface : public QObject
46{
47 Q_OBJECT
48public:
49 enum class BufferTarget {
50 Normal,
51 Linear,
52 Dumb
53 };
54 enum class FormatOption {
57 };
60
61 std::optional<OutputLayerBeginFrameInfo> startRendering(const QSize &bufferSize, OutputTransform transformation, const QMap<uint32_t, QList<uint64_t>> &formats, const ColorDescription &colorDescription, const QVector3D &channelFactors, const std::shared_ptr<IccProfile> &iccProfile, bool enableColormanagement);
62 bool endRendering(const QRegion &damagedRegion);
63 std::chrono::nanoseconds queryRenderTime() const;
64
65 bool doesSurfaceFit(const QSize &size, const QMap<uint32_t, QList<uint64_t>> &formats) const;
66 std::shared_ptr<GLTexture> texture() const;
67 void destroyResources();
69 std::shared_ptr<DrmFramebuffer> renderTestBuffer(const QSize &bufferSize, const QMap<uint32_t, QList<uint64_t>> &formats);
70 void forgetDamage();
71
72 std::shared_ptr<DrmFramebuffer> currentBuffer() const;
74
75private:
76 enum class MultiGpuImportMode {
77 None,
78 Dmabuf,
79 LinearDmabuf,
80 Egl,
81 DumbBuffer
82 };
83 struct Surface
84 {
85 ~Surface();
86
87 std::shared_ptr<EglContext> context;
88 std::shared_ptr<EglSwapchain> gbmSwapchain;
89 std::shared_ptr<EglSwapchainSlot> currentSlot;
90 DamageJournal damageJournal;
91 std::unique_ptr<QPainterSwapchain> importDumbSwapchain;
92 std::shared_ptr<EglContext> importContext;
93 std::shared_ptr<EglSwapchain> importGbmSwapchain;
94 QHash<GraphicsBuffer *, std::shared_ptr<GLTexture>> importedTextureCache;
95 QImage cpuCopyCache;
96 MultiGpuImportMode importMode;
97 std::shared_ptr<DrmFramebuffer> currentFramebuffer;
98 BufferTarget bufferTarget;
99
100 // for color management
101 bool colormanagementEnabled = false;
102 std::shared_ptr<GLTexture> shadowTexture;
103 std::unique_ptr<GLFramebuffer> shadowBuffer;
104 ColorDescription targetColorDescription = ColorDescription::sRGB;
105 ColorDescription intermediaryColorDescription = ColorDescription::sRGB;
106 QVector3D channelFactors = {1, 1, 1};
107 std::unique_ptr<IccShader> iccShader;
108 std::shared_ptr<IccProfile> iccProfile;
109
110 // for render timing
111 std::unique_ptr<GLRenderTimeQuery> timeQuery;
112 std::unique_ptr<GLRenderTimeQuery> importTimeQuery;
113 std::chrono::steady_clock::time_point renderStart;
114 std::chrono::steady_clock::time_point renderEnd;
115 };
116 bool checkSurface(const QSize &size, const QMap<uint32_t, QList<uint64_t>> &formats);
117 bool doesSurfaceFit(Surface *surface, const QSize &size, const QMap<uint32_t, QList<uint64_t>> &formats) const;
118 std::unique_ptr<Surface> createSurface(const QSize &size, const QMap<uint32_t, QList<uint64_t>> &formats) const;
119 std::unique_ptr<Surface> createSurface(const QSize &size, uint32_t format, const QList<uint64_t> &modifiers, MultiGpuImportMode importMode, BufferTarget bufferTarget) const;
120 std::shared_ptr<EglSwapchain> createGbmSwapchain(DrmGpu *gpu, EglContext *context, const QSize &size, uint32_t format, const QList<uint64_t> &modifiers, MultiGpuImportMode importMode, BufferTarget bufferTarget) const;
121
122 std::shared_ptr<DrmFramebuffer> doRenderTestBuffer(Surface *surface) const;
123 std::shared_ptr<DrmFramebuffer> importBuffer(Surface *surface, EglSwapchainSlot *source, const FileDescriptor &readFence) const;
124 std::shared_ptr<DrmFramebuffer> importWithEgl(Surface *surface, GraphicsBuffer *sourceBuffer, const FileDescriptor &readFence) const;
125 std::shared_ptr<DrmFramebuffer> importWithCpu(Surface *surface, EglSwapchainSlot *source) const;
126
127 std::unique_ptr<Surface> m_surface;
128 std::unique_ptr<Surface> m_oldSurface;
129
130 DrmGpu *const m_gpu;
131 EglGbmBackend *const m_eglBackend;
132 const BufferTarget m_requestedBufferTarget;
133 const FormatOption m_formatOption;
134};
135
136}
static const ColorDescription sRGB
Definition colorspace.h:132
OpenGL Backend using Egl on a GBM surface.
std::optional< OutputLayerBeginFrameInfo > startRendering(const QSize &bufferSize, OutputTransform transformation, const QMap< uint32_t, QList< uint64_t > > &formats, const ColorDescription &colorDescription, const QVector3D &channelFactors, const std::shared_ptr< IccProfile > &iccProfile, bool enableColormanagement)
std::shared_ptr< GLTexture > texture() const
std::chrono::nanoseconds queryRenderTime() const
EglGbmBackend * eglBackend() const
EglGbmLayerSurface(DrmGpu *gpu, EglGbmBackend *eglBackend, BufferTarget target=BufferTarget::Normal, FormatOption formatOption=FormatOption::PreferAlpha)
const ColorDescription & colorDescription() const
bool endRendering(const QRegion &damagedRegion)
bool doesSurfaceFit(const QSize &size, const QMap< uint32_t, QList< uint64_t > > &formats) const
std::shared_ptr< DrmFramebuffer > currentBuffer() const
std::shared_ptr< DrmFramebuffer > renderTestBuffer(const QSize &bufferSize, const QMap< uint32_t, QList< uint64_t > > &formats)
GLenum format
Definition gltexture.cpp:49