2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-08-31 12:00:31 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2016 Roman Gilg <subdiff@gmail.com>
|
2016-08-31 12:00:31 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2016-08-31 12:00:31 +00:00
|
|
|
#include "drm_object_plane.h"
|
|
|
|
#include "drm_buffer.h"
|
|
|
|
#include "drm_pointer.h"
|
|
|
|
#include "logging.h"
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2017-11-12 20:00:02 +00:00
|
|
|
DrmPlane::DrmPlane(uint32_t plane_id, int fd)
|
|
|
|
: DrmObject(plane_id, fd)
|
2016-08-31 12:00:31 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-01-26 20:23:44 +00:00
|
|
|
bool DrmPlane::init()
|
2016-08-31 12:00:31 +00:00
|
|
|
{
|
2017-05-09 19:29:10 +00:00
|
|
|
qCDebug(KWIN_DRM) << "Atomic init for plane:" << m_id;
|
2019-03-20 08:32:26 +00:00
|
|
|
DrmScopedPointer<drmModePlane> p(drmModeGetPlane(fd(), m_id));
|
2016-08-31 12:00:31 +00:00
|
|
|
|
|
|
|
if (!p) {
|
|
|
|
qCWarning(KWIN_DRM) << "Failed to get kernel plane" << m_id;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_possibleCrtcs = p->possible_crtcs;
|
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
int count_formats = p->count_formats;
|
|
|
|
m_formats.resize(count_formats);
|
|
|
|
for (int i = 0; i < count_formats; i++) {
|
2016-08-31 12:00:31 +00:00
|
|
|
m_formats[i] = p->formats[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!initProps()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-12-11 16:50:07 +00:00
|
|
|
bool DrmPlane::atomicPopulate(drmModeAtomicReq *req) const
|
|
|
|
{
|
|
|
|
return doAtomicPopulate(req, 1);
|
|
|
|
}
|
|
|
|
|
2016-08-31 12:00:31 +00:00
|
|
|
bool DrmPlane::initProps()
|
|
|
|
{
|
2017-11-10 19:38:33 +00:00
|
|
|
setPropertyNames( {
|
2016-08-31 12:00:31 +00:00
|
|
|
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"),
|
2017-10-31 17:08:36 +00:00
|
|
|
QByteArrayLiteral("rotation")
|
2017-11-10 19:38:33 +00:00
|
|
|
});
|
2016-08-31 12:00:31 +00:00
|
|
|
|
|
|
|
QVector<QByteArray> typeNames = {
|
|
|
|
QByteArrayLiteral("Overlay"),
|
2019-12-11 17:16:13 +00:00
|
|
|
QByteArrayLiteral("Primary"),
|
|
|
|
QByteArrayLiteral("Cursor")
|
2016-08-31 12:00:31 +00:00
|
|
|
};
|
|
|
|
|
2017-11-03 17:35:13 +00:00
|
|
|
const QVector<QByteArray> rotationNames{
|
|
|
|
QByteArrayLiteral("rotate-0"),
|
|
|
|
QByteArrayLiteral("rotate-90"),
|
|
|
|
QByteArrayLiteral("rotate-180"),
|
|
|
|
QByteArrayLiteral("rotate-270"),
|
|
|
|
QByteArrayLiteral("reflect-x"),
|
|
|
|
QByteArrayLiteral("reflect-y")
|
|
|
|
};
|
|
|
|
|
2019-03-20 08:32:26 +00:00
|
|
|
DrmScopedPointer<drmModeObjectProperties> properties(
|
2019-02-08 19:49:11 +00:00
|
|
|
drmModeObjectGetProperties(fd(), m_id, DRM_MODE_OBJECT_PLANE));
|
2016-08-31 12:00:31 +00:00
|
|
|
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)) {
|
2019-02-08 19:49:11 +00:00
|
|
|
initProp(j, properties.data(), typeNames);
|
2017-11-03 17:35:13 +00:00
|
|
|
} else if (j == int(PropertyIndex::Rotation)) {
|
2019-02-08 19:49:11 +00:00
|
|
|
initProp(j, properties.data(), rotationNames);
|
2017-11-03 17:35:13 +00:00
|
|
|
m_supportedTransformations = Transformations();
|
2019-12-11 16:50:07 +00:00
|
|
|
|
2020-07-26 16:37:55 +00:00
|
|
|
auto checkSupport = [j, this] (uint64_t value, Transformation t) {
|
2017-11-03 17:35:13 +00:00
|
|
|
if (propHasEnum(j, value)) {
|
|
|
|
m_supportedTransformations |= t;
|
|
|
|
}
|
|
|
|
};
|
2020-07-26 16:37:55 +00:00
|
|
|
checkSupport(0, Transformation::Rotate0);
|
|
|
|
checkSupport(1, Transformation::Rotate90);
|
|
|
|
checkSupport(2, Transformation::Rotate180);
|
|
|
|
checkSupport(3, Transformation::Rotate270);
|
|
|
|
checkSupport(4, Transformation::ReflectX);
|
|
|
|
checkSupport(5, Transformation::ReflectY);
|
|
|
|
|
|
|
|
qCDebug(KWIN_DRM) << "Supported Transformations on plane" << m_id << "are" << m_supportedTransformations;
|
2016-08-31 12:00:31 +00:00
|
|
|
} else {
|
2019-02-08 19:49:11 +00:00
|
|
|
initProp(j, properties.data());
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrmPlane::TypeIndex DrmPlane::type()
|
|
|
|
{
|
2017-11-10 19:38:33 +00:00
|
|
|
auto property = m_props.at(int(PropertyIndex::Type));
|
|
|
|
if (!property) {
|
|
|
|
return TypeIndex::Overlay;
|
|
|
|
}
|
2016-08-31 12:00:31 +00:00
|
|
|
int typeCount = int(TypeIndex::Count);
|
|
|
|
for (int i = 0; i < typeCount; i++) {
|
2017-11-10 19:38:33 +00:00
|
|
|
if (property->enumMap(i) == property->value()) {
|
2016-08-31 12:00:31 +00:00
|
|
|
return TypeIndex(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TypeIndex::Overlay;
|
|
|
|
}
|
|
|
|
|
2021-03-22 14:46:09 +00:00
|
|
|
void DrmPlane::setNext(const QSharedPointer<DrmBuffer> &b)
|
2017-11-10 19:38:33 +00:00
|
|
|
{
|
|
|
|
if (auto property = m_props.at(int(PropertyIndex::FbId))) {
|
|
|
|
property->setValue(b ? b->bufferId() : 0);
|
|
|
|
}
|
2017-05-09 19:29:10 +00:00
|
|
|
m_next = b;
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 17:08:36 +00:00
|
|
|
void DrmPlane::setTransformation(Transformations t)
|
|
|
|
{
|
2019-12-11 16:50:07 +00:00
|
|
|
// TODO: When being pedantic, this should go through the enum mapping. Just remember
|
|
|
|
// that these are the shift distance, not the shifted value.
|
2017-11-10 19:38:33 +00:00
|
|
|
if (auto property = m_props.at(int(PropertyIndex::Rotation))) {
|
|
|
|
property->setValue(int(t));
|
|
|
|
}
|
2017-10-31 17:08:36 +00:00
|
|
|
}
|
|
|
|
|
2017-11-01 18:21:08 +00:00
|
|
|
DrmPlane::Transformations DrmPlane::transformation()
|
|
|
|
{
|
2017-11-10 19:38:33 +00:00
|
|
|
if (auto property = m_props.at(int(PropertyIndex::Rotation))) {
|
|
|
|
return Transformations(int(property->value()));
|
|
|
|
}
|
|
|
|
return Transformations(Transformation::Rotate0);
|
2017-11-01 18:21:08 +00:00
|
|
|
}
|
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
void DrmPlane::flipBuffer()
|
|
|
|
{
|
2021-03-20 18:18:52 +00:00
|
|
|
m_current = m_next;
|
|
|
|
m_next = nullptr;
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|