From 75275bbc8f04e4de699eebe790ba851db8f79b56 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Wed, 23 Aug 2023 12:38:55 +0300 Subject: [PATCH] core: Move dmaBufAttributesForBo() to gbmgraphicsbufferallocator.cpp --- src/backends/drm/gbm_dmabuf.h | 58 ------------------------- src/core/gbmgraphicsbufferallocator.cpp | 40 ++++++++++++++++- 2 files changed, 39 insertions(+), 59 deletions(-) delete mode 100644 src/backends/drm/gbm_dmabuf.h diff --git a/src/backends/drm/gbm_dmabuf.h b/src/backends/drm/gbm_dmabuf.h deleted file mode 100644 index f2dc071a49..0000000000 --- a/src/backends/drm/gbm_dmabuf.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez - - SPDX-License-Identifier: LGPL-2.0-or-later -*/ - -#pragma once - -#include "config-kwin.h" - -#include "core/graphicsbuffer.h" - -#include -#include -#include - -#include - -namespace KWin -{ - -inline std::optional 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 diff --git a/src/core/gbmgraphicsbufferallocator.cpp b/src/core/gbmgraphicsbufferallocator.cpp index c108cf2421..431eed74a6 100644 --- a/src/core/gbmgraphicsbufferallocator.cpp +++ b/src/core/gbmgraphicsbufferallocator.cpp @@ -5,7 +5,9 @@ */ #include "core/gbmgraphicsbufferallocator.h" -#include "backends/drm/gbm_dmabuf.h" // FIXME: move dmaBufAttributesForBo() elsewhere + +#include + #include "core/graphicsbuffer.h" #include "utils/common.h" @@ -18,6 +20,42 @@ namespace KWin { +static inline std::optional 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