File indexing completed on 2025-04-13 04:59:24
0001 /* 0002 SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "core/rendertarget.h" 0010 #include "effect/globals.h" 0011 0012 #include <QObject> 0013 0014 #include <memory> 0015 0016 namespace KWin 0017 { 0018 0019 class GraphicsBuffer; 0020 class GraphicsBufferAllocator; 0021 class Output; 0022 class OverlayWindow; 0023 class OutputLayer; 0024 class SurfacePixmap; 0025 class SurfacePixmapX11; 0026 class SurfaceTexture; 0027 class PresentationFeedback; 0028 class RenderLoop; 0029 0030 class PresentationFeedback 0031 { 0032 public: 0033 explicit PresentationFeedback() = default; 0034 PresentationFeedback(const PresentationFeedback ©) = delete; 0035 PresentationFeedback(PresentationFeedback &&move) = default; 0036 virtual ~PresentationFeedback() = default; 0037 0038 virtual void presented(std::chrono::nanoseconds refreshCycleDuration, std::chrono::nanoseconds timestamp, PresentationMode mode) = 0; 0039 }; 0040 0041 class KWIN_EXPORT OutputFrame 0042 { 0043 public: 0044 explicit OutputFrame(RenderLoop *loop); 0045 ~OutputFrame(); 0046 0047 void presented(std::chrono::nanoseconds refreshDuration, std::chrono::nanoseconds timestamp, std::chrono::nanoseconds renderTime, PresentationMode mode); 0048 void failed(); 0049 0050 void addFeedback(std::unique_ptr<PresentationFeedback> &&feedback); 0051 0052 void setContentType(ContentType type); 0053 std::optional<ContentType> contentType() const; 0054 0055 void setPresentationMode(PresentationMode mode); 0056 PresentationMode presentationMode() const; 0057 0058 private: 0059 RenderLoop *const m_loop; 0060 std::vector<std::unique_ptr<PresentationFeedback>> m_feedbacks; 0061 std::optional<ContentType> m_contentType; 0062 PresentationMode m_presentationMode = PresentationMode::VSync; 0063 }; 0064 0065 /** 0066 * The RenderBackend class is the base class for all rendering backends. 0067 */ 0068 class KWIN_EXPORT RenderBackend : public QObject 0069 { 0070 Q_OBJECT 0071 0072 public: 0073 explicit RenderBackend(QObject *parent = nullptr); 0074 0075 virtual CompositingType compositingType() const = 0; 0076 virtual OverlayWindow *overlayWindow() const; 0077 0078 virtual bool checkGraphicsReset(); 0079 0080 virtual OutputLayer *primaryLayer(Output *output) = 0; 0081 virtual OutputLayer *cursorLayer(Output *output); 0082 virtual void present(Output *output, const std::shared_ptr<OutputFrame> &frame) = 0; 0083 0084 virtual GraphicsBufferAllocator *graphicsBufferAllocator() const; 0085 0086 virtual bool testImportBuffer(GraphicsBuffer *buffer); 0087 virtual QHash<uint32_t, QList<uint64_t>> supportedFormats() const; 0088 0089 virtual std::unique_ptr<SurfaceTexture> createSurfaceTextureX11(SurfacePixmapX11 *pixmap); 0090 virtual std::unique_ptr<SurfaceTexture> createSurfaceTextureWayland(SurfacePixmap *pixmap); 0091 }; 0092 0093 } // namespace KWin