core: Move dmaBufAttributesForBo() to gbmgraphicsbufferallocator.cpp

This commit is contained in:
Vlad Zahorodnii 2023-08-23 12:38:55 +03:00
parent dabf3038f0
commit 75275bbc8f
2 changed files with 39 additions and 59 deletions

View file

@ -1,58 +0,0 @@
/*
SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include "config-kwin.h"
#include "core/graphicsbuffer.h"
#include <drm_fourcc.h>
#include <gbm.h>
#include <string.h>
#include <optional>
namespace KWin
{
inline std::optional<DmaBufAttributes> dmaBufAttributesForBo(gbm_bo *bo)
{
DmaBufAttributes attributes;
attributes.planeCount = gbm_bo_get_plane_count(bo);
attributes.width = gbm_bo_get_width(bo);
attributes.height = gbm_bo_get_height(bo);
attributes.format = gbm_bo_get_format(bo);
attributes.modifier = gbm_bo_get_modifier(bo);
#if HAVE_GBM_BO_GET_FD_FOR_PLANE
for (int i = 0; i < attributes.planeCount; ++i) {
attributes.fd[i] = FileDescriptor{gbm_bo_get_fd_for_plane(bo, i)};
if (!attributes.fd[i].isValid()) {
qWarning() << "gbm_bo_get_fd_for_plane() failed:" << strerror(errno);
return std::nullopt;
}
attributes.offset[i] = gbm_bo_get_offset(bo, i);
attributes.pitch[i] = gbm_bo_get_stride_for_plane(bo, i);
}
#else
if (attributes.planeCount > 1) {
return attributes;
}
attributes.fd[0] = FileDescriptor{gbm_bo_get_fd(bo)};
if (!attributes.fd[0].isValid()) {
qWarning() << "gbm_bo_get_fd() failed:" << strerror(errno);
return std::nullopt;
}
attributes.offset[0] = gbm_bo_get_offset(bo, 0);
attributes.pitch[0] = gbm_bo_get_stride_for_plane(bo, 0);
#endif
return attributes;
}
} // namespace KWin

View file

@ -5,7 +5,9 @@
*/
#include "core/gbmgraphicsbufferallocator.h"
#include "backends/drm/gbm_dmabuf.h" // FIXME: move dmaBufAttributesForBo() elsewhere
#include <config-kwin.h>
#include "core/graphicsbuffer.h"
#include "utils/common.h"
@ -18,6 +20,42 @@
namespace KWin
{
static inline std::optional<DmaBufAttributes> dmaBufAttributesForBo(gbm_bo *bo)
{
DmaBufAttributes attributes;
attributes.planeCount = gbm_bo_get_plane_count(bo);
attributes.width = gbm_bo_get_width(bo);
attributes.height = gbm_bo_get_height(bo);
attributes.format = gbm_bo_get_format(bo);
attributes.modifier = gbm_bo_get_modifier(bo);
#if HAVE_GBM_BO_GET_FD_FOR_PLANE
for (int i = 0; i < attributes.planeCount; ++i) {
attributes.fd[i] = FileDescriptor{gbm_bo_get_fd_for_plane(bo, i)};
if (!attributes.fd[i].isValid()) {
qWarning() << "gbm_bo_get_fd_for_plane() failed:" << strerror(errno);
return std::nullopt;
}
attributes.offset[i] = gbm_bo_get_offset(bo, i);
attributes.pitch[i] = gbm_bo_get_stride_for_plane(bo, i);
}
#else
if (attributes.planeCount > 1) {
return attributes;
}
attributes.fd[0] = FileDescriptor{gbm_bo_get_fd(bo)};
if (!attributes.fd[0].isValid()) {
qWarning() << "gbm_bo_get_fd() failed:" << strerror(errno);
return std::nullopt;
}
attributes.offset[0] = gbm_bo_get_offset(bo, 0);
attributes.pitch[0] = gbm_bo_get_stride_for_plane(bo, 0);
#endif
return attributes;
}
class GbmGraphicsBuffer : public GraphicsBuffer
{
Q_OBJECT