/* KWin - the KDE window manager This file is part of the KDE project. SPDX-FileCopyrightText: 2016 Roman Gilg SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once #include #include #include // drm #include #include "drm_pointer.h" #include "drm_property.h" namespace KWin { class DrmBackend; class DrmGpu; class DrmOutput; class DrmObject { public: virtual ~DrmObject(); /** * Must be called to query necessary data directly after creation. * @return true when initializing was successful */ virtual bool init() = 0; /** * Set the properties in such a way that this resource won't be used anymore */ virtual void disable() = 0; uint32_t id() const; DrmGpu *gpu() const; uint32_t type() const; QString typeName() const; QVector properties(); void commit(); void commitPending(); void rollbackPending(); bool atomicPopulate(drmModeAtomicReq *req) const; bool needsCommit() const; virtual bool needsModeset() const = 0; virtual bool updateProperties(); template bool setPending(T prop, uint64_t new_value) { if (auto &property = m_props.at(static_cast(prop))) { property->setPending(new_value); return true; } return false; } template bool propHasEnum(T prop, uint64_t value) const { const auto &property = m_props.at(static_cast(prop)); return property ? property->hasEnum(value) : false; } template DrmProperty *getProp(T propIndex) const { return m_props[static_cast(propIndex)]; } protected: enum class Requirement { Required, RequiredForLegacy, Optional, }; struct PropertyDefinition { PropertyDefinition(const QByteArray &name, Requirement requirement, const QVector &&enumNames = {}) : name(name) , requirement(requirement) , enumNames(enumNames) { } QByteArray name; Requirement requirement; QVector enumNames; }; DrmObject(DrmGpu *gpu, uint32_t objectId, const QVector &&vector, uint32_t objectType); bool initProps(); template void deleteProp(T prop) { delete m_props[static_cast(prop)]; m_props[static_cast(prop)] = nullptr; } QVector m_props; private: DrmGpu *m_gpu; const uint32_t m_id; const uint32_t m_objectType; const QVector m_propertyDefinitions; }; } QDebug operator<<(QDebug stream, const KWin::DrmObject*);