/* KWin - the KDE window manager This file is part of the KDE project. SPDX-FileCopyrightText: 2023 Xaver Hugl SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once #include #include #include #include #include #include #include "core/renderloop.h" #include "drm_pointer.h" #include "drm_property.h" namespace KWin { class DrmBlob; class DrmConnector; class DrmConnectorMode; class DrmCrtc; class DrmFramebuffer; class DrmGpu; class DrmPlane; class DrmProperty; class DrmPipeline; class OutputFrame; class DrmCommit { public: virtual ~DrmCommit(); DrmGpu *gpu() const; virtual void pageFlipped(std::chrono::nanoseconds timestamp) = 0; protected: DrmCommit(DrmGpu *gpu); DrmGpu *const m_gpu; }; class DrmAtomicCommit : public DrmCommit { public: explicit DrmAtomicCommit(DrmGpu *gpu); explicit DrmAtomicCommit(const QList &pipelines); explicit DrmAtomicCommit(const DrmAtomicCommit ©) = default; void addProperty(const DrmProperty &prop, uint64_t value); template void addEnum(const DrmEnumProperty &prop, T enumValue) { addProperty(prop, prop.valueForEnum(enumValue)); } void addBlob(const DrmProperty &prop, const std::shared_ptr &blob); void addBuffer(DrmPlane *plane, const std::shared_ptr &buffer, const std::shared_ptr &frame); void setVrr(DrmCrtc *crtc, bool vrr); void setPresentationMode(PresentationMode mode); bool test(); bool testAllowModeset(); bool commit(); bool commitModeset(); void pageFlipped(std::chrono::nanoseconds timestamp) override; bool areBuffersReadable() const; void setDeadline(std::chrono::steady_clock::time_point deadline); std::optional isVrr() const; const std::unordered_set &modifiedPlanes() const; void merge(DrmAtomicCommit *onTop); void setCursorOnly(bool cursor); bool isCursorOnly() const; std::optional targetPageflipTime() const; bool isReadyFor(std::chrono::steady_clock::time_point pageflipTarget) const; bool isTearing() const; private: bool doCommit(uint32_t flags); const QList m_pipelines; std::optional m_targetPageflipTime; std::unordered_map> m_blobs; std::unordered_map> m_buffers; std::unordered_map> m_frames; std::unordered_set m_planes; std::optional m_vrr; std::unordered_map> m_properties; bool m_cursorOnly = false; bool m_modeset = false; PresentationMode m_mode = PresentationMode::VSync; }; class DrmLegacyCommit : public DrmCommit { public: DrmLegacyCommit(DrmPipeline *pipeline, const std::shared_ptr &buffer, const std::shared_ptr &frame); bool doModeset(DrmConnector *connector, DrmConnectorMode *mode); bool doPageflip(PresentationMode mode); void pageFlipped(std::chrono::nanoseconds timestamp) override; private: DrmPipeline *const m_pipeline; DrmCrtc *const m_crtc; const std::shared_ptr m_buffer; std::shared_ptr m_frame; PresentationMode m_mode = PresentationMode::VSync; }; }