/* 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; void setCurrent(uint64_t value); uint64_t current() const; uint64_t minValue() const; uint64_t maxValue() const; void commit(); void commitPending(); void rollbackPending(); bool needsCommit() const; bool setPropertyLegacy(uint64_t value); template bool setEnumLegacy(T value) { if (hasEnum(static_cast(value))) { return setPropertyLegacy(m_enumMap[static_cast(value)]); } return false; } 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; // the value that will be m_current after the next atomic commit // and has been tested to work uint64_t m_next = 0; // the value currently set for or by the kernel uint64_t m_current = 0; uint64_t m_minValue = -1; uint64_t m_maxValue = -1; QMap m_enumMap; QVector m_enumNames; const bool m_immutable; bool m_legacy = false; const DrmObject *m_obj; }; }