diff --git a/plugins/platforms/drm/drm_object_plane.cpp b/plugins/platforms/drm/drm_object_plane.cpp index 3fdc9dc35..1dd7a7e24 100644 --- a/plugins/platforms/drm/drm_object_plane.cpp +++ b/plugins/platforms/drm/drm_object_plane.cpp @@ -1,192 +1,192 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2016 Roman Gilg This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "drm_object_plane.h" #include "drm_buffer.h" #include "drm_pointer.h" #include "logging.h" namespace KWin { DrmPlane::DrmPlane(uint32_t plane_id, int fd) : DrmObject(plane_id, fd) { } DrmPlane::~DrmPlane() { delete m_current; delete m_next; } bool DrmPlane::atomicInit() { qCDebug(KWIN_DRM) << "Atomic init for plane:" << m_id; DrmScopedPointer p(drmModeGetPlane(fd(), m_id)); if (!p) { qCWarning(KWIN_DRM) << "Failed to get kernel plane" << m_id; return false; } m_possibleCrtcs = p->possible_crtcs; int count_formats = p->count_formats; m_formats.resize(count_formats); for (int i = 0; i < count_formats; i++) { m_formats[i] = p->formats[i]; } if (!initProps()) { return false; } return true; } bool DrmPlane::atomicPopulate(drmModeAtomicReq *req) const { return doAtomicPopulate(req, 1); } bool DrmPlane::initProps() { setPropertyNames( { QByteArrayLiteral("type"), QByteArrayLiteral("SRC_X"), QByteArrayLiteral("SRC_Y"), QByteArrayLiteral("SRC_W"), QByteArrayLiteral("SRC_H"), QByteArrayLiteral("CRTC_X"), QByteArrayLiteral("CRTC_Y"), QByteArrayLiteral("CRTC_W"), QByteArrayLiteral("CRTC_H"), QByteArrayLiteral("FB_ID"), QByteArrayLiteral("CRTC_ID"), QByteArrayLiteral("rotation") }); QVector typeNames = { - QByteArrayLiteral("Primary"), - QByteArrayLiteral("Cursor"), QByteArrayLiteral("Overlay"), + QByteArrayLiteral("Primary"), + QByteArrayLiteral("Cursor") }; const QVector rotationNames{ QByteArrayLiteral("rotate-0"), QByteArrayLiteral("rotate-90"), QByteArrayLiteral("rotate-180"), QByteArrayLiteral("rotate-270"), QByteArrayLiteral("reflect-x"), QByteArrayLiteral("reflect-y") }; DrmScopedPointer properties( drmModeObjectGetProperties(fd(), m_id, DRM_MODE_OBJECT_PLANE)); if (!properties){ qCWarning(KWIN_DRM) << "Failed to get properties for plane " << m_id ; return false; } int propCount = int(PropertyIndex::Count); for (int j = 0; j < propCount; ++j) { if (j == int(PropertyIndex::Type)) { initProp(j, properties.data(), typeNames); } else if (j == int(PropertyIndex::Rotation)) { initProp(j, properties.data(), rotationNames); m_supportedTransformations = Transformations(); auto checkSupport = [j, this] (uint64_t value, Transformation t, const QString &name) { if (propHasEnum(j, value)) { qCDebug(KWIN_DRM) << name; m_supportedTransformations |= t; } }; qCDebug(KWIN_DRM).nospace() << "Supported Transformations on plane " << m_id << ":"; checkSupport(0, Transformation::Rotate0, "rotate-0"); checkSupport(1, Transformation::Rotate90, "rotate-90"); checkSupport(2, Transformation::Rotate180, "rotate-180"); checkSupport(3, Transformation::Rotate270, "rotate-270"); checkSupport(4, Transformation::ReflectX, "reflect-x"); checkSupport(5, Transformation::ReflectY, "reflect-y"); qCDebug(KWIN_DRM) << ""; } else { initProp(j, properties.data()); } } return true; } DrmPlane::TypeIndex DrmPlane::type() { auto property = m_props.at(int(PropertyIndex::Type)); if (!property) { return TypeIndex::Overlay; } int typeCount = int(TypeIndex::Count); for (int i = 0; i < typeCount; i++) { if (property->enumMap(i) == property->value()) { return TypeIndex(i); } } return TypeIndex::Overlay; } void DrmPlane::setNext(DrmBuffer *b) { if (auto property = m_props.at(int(PropertyIndex::FbId))) { property->setValue(b ? b->bufferId() : 0); } m_next = b; } void DrmPlane::setTransformation(Transformations t) { // TODO: When being pedantic, this should go through the enum mapping. Just remember // that these are the shift distance, not the shifted value. if (auto property = m_props.at(int(PropertyIndex::Rotation))) { property->setValue(int(t)); } } DrmPlane::Transformations DrmPlane::transformation() { if (auto property = m_props.at(int(PropertyIndex::Rotation))) { return Transformations(int(property->value())); } return Transformations(Transformation::Rotate0); } void DrmPlane::flipBuffer() { m_current = m_next; m_next = nullptr; } void DrmPlane::flipBufferWithDelete() { if (m_current != m_next) { delete m_current; } flipBuffer(); } } diff --git a/plugins/platforms/drm/drm_object_plane.h b/plugins/platforms/drm/drm_object_plane.h index d23b21ded..b0ad9f732 100644 --- a/plugins/platforms/drm/drm_object_plane.h +++ b/plugins/platforms/drm/drm_object_plane.h @@ -1,120 +1,120 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2016 Roman Gilg This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #pragma once #include "drm_object.h" #include namespace KWin { class DrmBuffer; class DrmPlane : public DrmObject { public: DrmPlane(uint32_t plane_id, int fd); ~DrmPlane() override; enum class PropertyIndex { Type = 0, SrcX, SrcY, SrcW, SrcH, CrtcX, CrtcY, CrtcW, CrtcH, FbId, CrtcId, Rotation, Count }; enum class TypeIndex { - Primary = 0, + Overlay = 0, + Primary, Cursor, - Overlay, Count }; enum class Transformation { Rotate0 = 1 << 0, Rotate90 = 1 << 1, Rotate180 = 1 << 2, Rotate270 = 1 << 3, ReflectX = 1 << 4, ReflectY = 1 << 5 }; Q_DECLARE_FLAGS(Transformations, Transformation); bool atomicInit() override; bool initProps() override; TypeIndex type(); bool isCrtcSupported(int resIndex) const { return (m_possibleCrtcs & (1 << resIndex)); } QVector formats() const { return m_formats; } DrmBuffer *current() const { return m_current; } DrmBuffer *next() const { return m_next; } void setCurrent(DrmBuffer *b) { m_current = b; } void setNext(DrmBuffer *b); void setTransformation(Transformations t); Transformations transformation(); void flipBuffer(); void flipBufferWithDelete(); Transformations supportedTransformations() const { return m_supportedTransformations; } bool atomicPopulate(drmModeAtomicReq *req) const override; private: DrmBuffer *m_current = nullptr; DrmBuffer *m_next = nullptr; // TODO: See weston drm_output_check_plane_format for future use of these member variables QVector m_formats; // Possible formats, which can be presented on this plane // TODO: when using overlay planes in the future: restrict possible screens / crtcs of planes uint32_t m_possibleCrtcs; Transformations m_supportedTransformations = Transformation::Rotate0; }; } Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::DrmPlane::Transformations)