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"
|
2021-04-01 11:15:42 +00:00
|
|
|
#include "drm_gpu.h"
|
2016-08-31 12:00:31 +00:00
|
|
|
#include "drm_pointer.h"
|
|
|
|
#include "logging.h"
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2021-04-01 11:21:37 +00:00
|
|
|
DrmPlane::DrmPlane(DrmGpu *gpu, uint32_t planeId)
|
|
|
|
: DrmObject(gpu, planeId)
|
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
|
|
|
{
|
2021-04-01 11:19:48 +00:00
|
|
|
qCDebug(KWIN_DRM) << "Atomic init for plane:" << id();
|
|
|
|
DrmScopedPointer<drmModePlane> p(drmModeGetPlane(gpu()->fd(), id()));
|
2016-08-31 12:00:31 +00:00
|
|
|
|
|
|
|
if (!p) {
|
2021-04-01 11:19:48 +00:00
|
|
|
qCWarning(KWIN_DRM) << "Failed to get kernel plane" << id();
|
2016-08-31 12:00:31 +00:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2021-03-10 21:04:32 +00:00
|
|
|
bool success = initProps({
|
|
|
|
PropertyDefinition(QByteArrayLiteral("type"), {
|
|
|
|
QByteArrayLiteral("Overlay"),
|
|
|
|
QByteArrayLiteral("Primary"),
|
|
|
|
QByteArrayLiteral("Cursor")}),
|
|
|
|
PropertyDefinition(QByteArrayLiteral("SRC_X")),
|
|
|
|
PropertyDefinition(QByteArrayLiteral("SRC_Y")),
|
|
|
|
PropertyDefinition(QByteArrayLiteral("SRC_W")),
|
|
|
|
PropertyDefinition(QByteArrayLiteral("SRC_H")),
|
|
|
|
PropertyDefinition(QByteArrayLiteral("CRTC_X")),
|
|
|
|
PropertyDefinition(QByteArrayLiteral("CRTC_Y")),
|
|
|
|
PropertyDefinition(QByteArrayLiteral("CRTC_W")),
|
|
|
|
PropertyDefinition(QByteArrayLiteral("CRTC_H")),
|
|
|
|
PropertyDefinition(QByteArrayLiteral("FB_ID")),
|
|
|
|
PropertyDefinition(QByteArrayLiteral("CRTC_ID")),
|
|
|
|
PropertyDefinition(QByteArrayLiteral("rotation"), {
|
|
|
|
QByteArrayLiteral("rotate-0"),
|
|
|
|
QByteArrayLiteral("rotate-90"),
|
|
|
|
QByteArrayLiteral("rotate-180"),
|
|
|
|
QByteArrayLiteral("rotate-270"),
|
|
|
|
QByteArrayLiteral("reflect-x"),
|
|
|
|
QByteArrayLiteral("reflect-y")}),
|
|
|
|
}, DRM_MODE_OBJECT_PLANE
|
|
|
|
);
|
|
|
|
if (success) {
|
|
|
|
m_supportedTransformations = Transformations();
|
|
|
|
auto checkSupport = [this] (uint64_t value, Transformation t) {
|
|
|
|
if (propHasEnum(PropertyIndex::Rotation, value)) {
|
|
|
|
m_supportedTransformations |= t;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
checkSupport(0, Transformation::Rotate0);
|
|
|
|
checkSupport(1, Transformation::Rotate90);
|
|
|
|
checkSupport(2, Transformation::Rotate180);
|
|
|
|
checkSupport(3, Transformation::Rotate270);
|
|
|
|
checkSupport(4, Transformation::ReflectX);
|
|
|
|
checkSupport(5, Transformation::ReflectY);
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
2021-03-10 21:04:32 +00:00
|
|
|
return success;
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DrmPlane::TypeIndex DrmPlane::type()
|
|
|
|
{
|
2021-03-10 21:04:32 +00:00
|
|
|
auto property = m_props.at(static_cast<uint32_t>(PropertyIndex::Type));
|
2017-11-10 19:38:33 +00:00
|
|
|
if (!property) {
|
|
|
|
return TypeIndex::Overlay;
|
|
|
|
}
|
2021-03-10 21:04:32 +00:00
|
|
|
for (uint32_t i = 0; i < static_cast<uint32_t>(TypeIndex::Count); i++) {
|
|
|
|
if (property->enumMap(i) == property->value()) {
|
|
|
|
return TypeIndex(i);
|
|
|
|
}
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2021-03-10 21:04:32 +00:00
|
|
|
setValue(PropertyIndex::FbId, 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)
|
|
|
|
{
|
2021-03-10 21:04:32 +00:00
|
|
|
setValue(PropertyIndex::Rotation, t);
|
2017-10-31 17:08:36 +00:00
|
|
|
}
|
|
|
|
|
2017-11-01 18:21:08 +00:00
|
|
|
DrmPlane::Transformations DrmPlane::transformation()
|
|
|
|
{
|
2021-03-10 21:04:32 +00:00
|
|
|
if (auto property = m_props.at(static_cast<uint32_t>(PropertyIndex::Rotation))) {
|
|
|
|
return Transformations(static_cast<uint32_t>(property->value()));
|
2017-11-10 19:38:33 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|