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"
|
2021-07-31 13:32:50 +00:00
|
|
|
#include "config-kwin.h"
|
|
|
|
|
2021-08-26 16:36:52 +00:00
|
|
|
#include <drm_fourcc.h>
|
2016-08-31 12:00:31 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2021-04-01 11:21:37 +00:00
|
|
|
DrmPlane::DrmPlane(DrmGpu *gpu, uint32_t planeId)
|
2021-06-03 13:50:37 +00:00
|
|
|
: DrmObject(gpu, planeId, {
|
2021-03-10 21:04:32 +00:00
|
|
|
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")}),
|
2021-07-31 13:32:50 +00:00
|
|
|
PropertyDefinition(QByteArrayLiteral("IN_FORMATS")),
|
2021-06-03 13:50:37 +00:00
|
|
|
}, DRM_MODE_OBJECT_PLANE)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmPlane::init()
|
|
|
|
{
|
|
|
|
DrmScopedPointer<drmModePlane> p(drmModeGetPlane(gpu()->fd(), id()));
|
|
|
|
|
|
|
|
if (!p) {
|
|
|
|
qCWarning(KWIN_DRM) << "Failed to get kernel plane" << id();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_possibleCrtcs = p->possible_crtcs;
|
|
|
|
|
|
|
|
bool success = initProps();
|
2021-03-10 21:04:32 +00:00
|
|
|
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);
|
2021-07-31 13:32:50 +00:00
|
|
|
|
|
|
|
// read formats from blob if available and if modifiers are supported, and from the plane object if not
|
|
|
|
if (auto formatProp = getProp(PropertyIndex::In_Formats); formatProp && qEnvironmentVariableIsSet("KWIN_DRM_NO_MODIFIERS") && gpu()->addFB2ModifiersSupported()) {
|
|
|
|
auto blob = static_cast<drm_format_modifier_blob*>(formatProp->currentBlob()->data);
|
|
|
|
auto modifiers = reinterpret_cast<drm_format_modifier*>(reinterpret_cast<uint8_t*>(blob) + blob->modifiers_offset);
|
|
|
|
uint32_t *formatarr = reinterpret_cast<uint32_t*>(reinterpret_cast<uint8_t*>(blob) + blob->formats_offset);
|
|
|
|
|
|
|
|
for (uint32_t f = 0; f < blob->count_formats; f++) {
|
|
|
|
auto format = formatarr[f];
|
|
|
|
QVector<uint64_t> mods;
|
|
|
|
for (uint32_t m = 0; m < blob->count_modifiers; m++) {
|
|
|
|
auto modifier = &modifiers[m];
|
|
|
|
// The modifier advertisement blob is partitioned into groups of 64 formats
|
|
|
|
if (m < modifier->offset || m > modifier->offset + 63) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!(modifier->formats & (1 << (f - modifier->offset)))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
mods << modifier->modifier;
|
|
|
|
}
|
|
|
|
m_supportedFormats.insert(format, mods);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (uint32_t i = 0; i < p->count_formats; i++) {
|
|
|
|
m_supportedFormats.insert(p->formats[i], {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_supportedFormats.isEmpty()) {
|
|
|
|
qCWarning(KWIN_DRM) << "Driver doesn't advertise any formats for this plane. Falling back to XRGB8888 and ARGB8888 without modifiers";
|
2021-08-26 16:36:52 +00:00
|
|
|
m_supportedFormats.insert(DRM_FORMAT_XRGB8888, {});
|
|
|
|
m_supportedFormats.insert(DRM_FORMAT_ARGB8888, {});
|
2021-07-31 13:32:50 +00:00
|
|
|
}
|
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-05-25 22:05:17 +00:00
|
|
|
auto property = getProp(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++) {
|
2021-08-22 20:25:03 +00:00
|
|
|
if (property->enumMap()[i] == property->current()) {
|
2021-03-10 21:04:32 +00:00
|
|
|
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
|
|
|
{
|
2017-05-09 19:29:10 +00:00
|
|
|
m_next = b;
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 22:05:17 +00:00
|
|
|
bool DrmPlane::setTransformation(Transformations t)
|
2017-10-31 17:08:36 +00:00
|
|
|
{
|
2021-05-25 22:05:17 +00:00
|
|
|
if (m_supportedTransformations & t) {
|
|
|
|
return setPending(PropertyIndex::Rotation, t);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-31 17:08:36 +00:00
|
|
|
}
|
|
|
|
|
2017-11-01 18:21:08 +00:00
|
|
|
DrmPlane::Transformations DrmPlane::transformation()
|
|
|
|
{
|
2021-05-25 22:05:17 +00:00
|
|
|
if (auto property = getProp(PropertyIndex::Rotation)) {
|
|
|
|
return Transformations(static_cast<uint32_t>(property->pending()));
|
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
|
|
|
}
|
|
|
|
|
2021-05-25 22:05:17 +00:00
|
|
|
void DrmPlane::set(const QPoint &srcPos, const QSize &srcSize, const QPoint &dstPos, const QSize &dstSize)
|
|
|
|
{
|
|
|
|
// Src* are in 16.16 fixed point format
|
|
|
|
setPending(PropertyIndex::SrcX, srcPos.x() << 16);
|
|
|
|
setPending(PropertyIndex::SrcY, srcPos.y() << 16);
|
|
|
|
setPending(PropertyIndex::SrcW, srcSize.width() << 16);
|
|
|
|
setPending(PropertyIndex::SrcH, srcSize.height() << 16);
|
|
|
|
setPending(PropertyIndex::CrtcX, dstPos.x());
|
|
|
|
setPending(PropertyIndex::CrtcY, dstPos.y());
|
|
|
|
setPending(PropertyIndex::CrtcW, dstSize.width());
|
|
|
|
setPending(PropertyIndex::CrtcH, dstSize.height());
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrmPlane::setBuffer(DrmBuffer *buffer)
|
|
|
|
{
|
|
|
|
setPending(PropertyIndex::FbId, buffer ? buffer->bufferId() : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmPlane::needsModeset() const
|
|
|
|
{
|
2021-07-12 12:28:38 +00:00
|
|
|
auto rotation = getProp(PropertyIndex::Rotation);
|
|
|
|
if (rotation && rotation->needsCommit()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return getProp(PropertyIndex::CrtcId)->needsCommit();
|
2021-05-25 22:05:17 +00:00
|
|
|
}
|
|
|
|
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|