backends/drm: use FileDescriptor class for drm buffer fds
This commit is contained in:
parent
6cd4d69644
commit
1464028934
3 changed files with 14 additions and 25 deletions
|
@ -34,19 +34,9 @@ DrmGpuBuffer::DrmGpuBuffer(DrmGpu *gpu, QSize size, uint32_t format, uint64_t mo
|
|||
, m_strides(strides)
|
||||
, m_offsets(offsets)
|
||||
, m_planeCount(planeCount)
|
||||
, m_fds({-1, -1, -1, -1})
|
||||
{
|
||||
}
|
||||
|
||||
DrmGpuBuffer::~DrmGpuBuffer()
|
||||
{
|
||||
for (uint32_t i = 0; i < m_planeCount; i++) {
|
||||
if (m_fds[i] != -1) {
|
||||
close(m_fds[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DrmGpu *DrmGpuBuffer::gpu() const
|
||||
{
|
||||
return m_gpu;
|
||||
|
@ -67,9 +57,9 @@ QSize DrmGpuBuffer::size() const
|
|||
return m_size;
|
||||
}
|
||||
|
||||
std::array<int, 4> DrmGpuBuffer::fds()
|
||||
const std::array<FileDescriptor, 4> &DrmGpuBuffer::fds()
|
||||
{
|
||||
if (m_fds[0] == -1) {
|
||||
if (!m_fds[0].isValid()) {
|
||||
createFds();
|
||||
}
|
||||
return m_fds;
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include "utils/filedescriptor.h"
|
||||
|
||||
#include <QImage>
|
||||
#include <QSize>
|
||||
#include <array>
|
||||
|
@ -25,13 +27,13 @@ class DrmGpuBuffer
|
|||
{
|
||||
public:
|
||||
DrmGpuBuffer(DrmGpu *gpu, QSize size, uint32_t format, uint64_t modifier, const std::array<uint32_t, 4> &handles, const std::array<uint32_t, 4> &strides, const std::array<uint32_t, 4> &offsets, uint32_t planeCount);
|
||||
virtual ~DrmGpuBuffer();
|
||||
virtual ~DrmGpuBuffer() = default;
|
||||
|
||||
DrmGpu *gpu() const;
|
||||
uint32_t format() const;
|
||||
uint64_t modifier() const;
|
||||
QSize size() const;
|
||||
std::array<int, 4> fds();
|
||||
const std::array<FileDescriptor, 4> &fds();
|
||||
std::array<uint32_t, 4> handles() const;
|
||||
std::array<uint32_t, 4> strides() const;
|
||||
std::array<uint32_t, 4> offsets() const;
|
||||
|
@ -48,7 +50,7 @@ protected:
|
|||
const std::array<uint32_t, 4> m_strides;
|
||||
const std::array<uint32_t, 4> m_offsets;
|
||||
const uint32_t m_planeCount;
|
||||
std::array<int, 4> m_fds;
|
||||
std::array<FileDescriptor, 4> m_fds;
|
||||
};
|
||||
|
||||
class DrmFramebuffer
|
||||
|
|
|
@ -132,12 +132,9 @@ void GbmBuffer::createFds()
|
|||
{
|
||||
#if HAVE_GBM_BO_GET_FD_FOR_PLANE
|
||||
for (uint32_t i = 0; i < m_planeCount; i++) {
|
||||
m_fds[i] = gbm_bo_get_fd_for_plane(m_bo, i);
|
||||
if (m_fds[i] == -1) {
|
||||
for (uint32_t i2 = 0; i2 < i; i2++) {
|
||||
close(m_fds[i2]);
|
||||
m_fds[i2] = -1;
|
||||
}
|
||||
m_fds[i] = FileDescriptor(gbm_bo_get_fd_for_plane(m_bo, i));
|
||||
if (!m_fds[i].isValid()) {
|
||||
m_fds = {};
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -146,7 +143,7 @@ void GbmBuffer::createFds()
|
|||
if (m_planeCount > 1) {
|
||||
return;
|
||||
}
|
||||
m_fds[0] = gbm_bo_get_fd(m_bo);
|
||||
m_fds[0] = FileDescriptor(gbm_bo_get_fd(m_bo));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -185,8 +182,8 @@ std::shared_ptr<GbmBuffer> GbmBuffer::importBuffer(DrmGpu *gpu, KWaylandServer::
|
|||
|
||||
std::shared_ptr<GbmBuffer> GbmBuffer::importBuffer(DrmGpu *gpu, GbmBuffer *buffer, uint32_t flags)
|
||||
{
|
||||
const auto fds = buffer->fds();
|
||||
if (fds[0] == -1) {
|
||||
const auto &fds = buffer->fds();
|
||||
if (!fds[0].isValid()) {
|
||||
return nullptr;
|
||||
}
|
||||
const auto strides = buffer->strides();
|
||||
|
@ -202,7 +199,7 @@ std::shared_ptr<GbmBuffer> GbmBuffer::importBuffer(DrmGpu *gpu, GbmBuffer *buffe
|
|||
.modifier = buffer->modifier(),
|
||||
};
|
||||
for (uint32_t i = 0; i < data.num_fds; i++) {
|
||||
data.fds[i] = fds[i];
|
||||
data.fds[i] = fds[i].get();
|
||||
data.strides[i] = strides[i];
|
||||
data.offsets[i] = offsets[i];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue