2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "utils/log.h"
15 using namespace KODI::WINDOWING::GBM
;
22 bool CGBMUtils::CreateDevice(int fd
)
24 auto device
= gbm_create_device(fd
);
27 CLog::Log(LOGERROR
, "CGBMUtils::{} - failed to create device: {}", __FUNCTION__
,
32 m_device
.reset(new CGBMDevice(device
));
37 CGBMUtils::CGBMDevice::CGBMDevice(gbm_device
* device
) : m_device(device
)
41 bool CGBMUtils::CGBMDevice::CreateSurface(
42 int width
, int height
, uint32_t format
, const uint64_t* modifiers
, const int modifiers_count
)
44 gbm_surface
* surface
{nullptr};
45 #if defined(HAS_GBM_MODIFIERS)
48 surface
= gbm_surface_create_with_modifiers(m_device
, width
, height
, format
, modifiers
,
54 surface
= gbm_surface_create(m_device
, width
, height
, format
,
55 GBM_BO_USE_SCANOUT
| GBM_BO_USE_RENDERING
);
60 CLog::Log(LOGERROR
, "CGBMUtils::{} - failed to create surface: {}", __FUNCTION__
,
65 CLog::Log(LOGDEBUG
, "CGBMUtils::{} - created surface with size {}x{}", __FUNCTION__
, width
,
68 m_surface
.reset(new CGBMSurface(surface
));
73 CGBMUtils::CGBMDevice::CGBMSurface::CGBMSurface(gbm_surface
* surface
) : m_surface(surface
)
77 CGBMUtils::CGBMDevice::CGBMSurface::CGBMSurfaceBuffer
& CGBMUtils::CGBMDevice::CGBMSurface::
80 m_buffers
.emplace(std::make_unique
<CGBMSurfaceBuffer
>(m_surface
));
82 if (!static_cast<bool>(gbm_surface_has_free_buffers(m_surface
)))
85 * We want to use call_once here because we want it to be logged the first time that
86 * we have to release buffers. This means that the maximum amount of buffers had been reached.
87 * For mesa this should be 4 buffers but it may vary across other implementations.
90 flag
, [this]() { CLog::Log(LOGDEBUG
, "CGBMUtils - using {} buffers", m_buffers
.size()); });
95 return *m_buffers
.back();
98 CGBMUtils::CGBMDevice::CGBMSurface::CGBMSurfaceBuffer::CGBMSurfaceBuffer(gbm_surface
* surface
)
99 : m_surface(surface
), m_buffer(gbm_surface_lock_front_buffer(surface
))
103 CGBMUtils::CGBMDevice::CGBMSurface::CGBMSurfaceBuffer::~CGBMSurfaceBuffer()
105 if (m_surface
&& m_buffer
)
106 gbm_surface_release_buffer(m_surface
, m_buffer
);