/* KWin - the KDE window manager This file is part of the KDE project. SPDX-FileCopyrightText: 2016 Roman Gilg SPDX-FileCopyrightText: 2021 Xaver Hugl SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once #include #include #include #include namespace KWin { class DrmObject; class DrmProperty { public: DrmProperty(DrmObject *obj, drmModePropertyRes *prop, uint64_t val, const QVector &enumNames); virtual ~DrmProperty(); void initEnumMap(drmModePropertyRes *prop); QVector enumNames() const; bool hasEnum(uint64_t value) const; bool hasAllEnums() const; template T enumForValue(uint64_t value) const { return static_cast(m_enumMap[value]); } template bool setEnum(T index) { if (hasEnum(static_cast(index))) { setPending(m_enumMap[static_cast(index)]); return true; } return false; } uint32_t propId() const; const QByteArray &name() const; bool isImmutable() const; bool isLegacy() const; /** * Makes this property be ignored by DrmObject::atomicPopulate */ void setLegacy(); void setPending(uint64_t value); uint64_t pending() const; bool setPendingBlob(void *blob, size_t length); drmModePropertyBlobRes *pendingBlob() const; void setCurrent(uint64_t value); uint64_t current() const; void setCurrentBlob(drmModePropertyBlobRes *blob); drmModePropertyBlobRes *currentBlob() const; void commit(); void commitPending(); void rollbackPending(); bool needsCommit() const; bool setPropertyLegacy(uint64_t value); private: uint32_t m_propId = 0; QByteArray m_propName; // the value that will be m_next after the property has been committed // has not necessarily been tested to work uint64_t m_pending = 0; drmModePropertyBlobRes *m_pendingBlob = nullptr; // the value that will be m_current after the next atomic commit // and has been tested to work uint64_t m_next = 0; drmModePropertyBlobRes *m_nextBlob = nullptr; // the value currently set for or by the kernel uint64_t m_current = 0; drmModePropertyBlobRes *m_currentBlob = nullptr; QMap m_enumMap; QVector m_enumNames; const bool m_immutable; bool m_legacy = false; const DrmObject *m_obj; }; }