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.
24 * @brief A wrapper for gbm c classes to allow OOP and RAII.
30 CGBMUtils(const CGBMUtils
&) = delete;
31 CGBMUtils
& operator=(const CGBMUtils
&) = delete;
32 CGBMUtils() = default;
33 ~CGBMUtils() = default;
36 * @brief Create a gbm device for allocating buffers
38 * @param fd The file descriptor for a backend device
39 * @return true The device creation succeeded
40 * @return false The device creation failed
42 bool CreateDevice(int fd
);
45 * @brief A wrapper for gbm_device to allow OOP and RAII
51 CGBMDevice(const CGBMDevice
&) = delete;
52 CGBMDevice
& operator=(const CGBMDevice
&) = delete;
53 explicit CGBMDevice(gbm_device
* device
);
54 ~CGBMDevice() = default;
57 * @brief Create a gbm surface
59 * @param width The width to use for the surface
60 * @param height The height to use for the surface
61 * @param format The format to use for the surface
62 * @param modifiers The modifiers to use for the surface
63 * @param modifiers_count The amount of modifiers in the modifiers param
64 * @return true The surface creation succeeded
65 * @return false The surface creation failed
67 bool CreateSurface(int width
,
70 const uint64_t* modifiers
,
71 const int modifiers_count
);
74 * @brief Get the underlying gbm_device
76 * @return gbm_device* A pointer to the underlying gbm_device
78 gbm_device
* Get() const { return m_device
; }
81 * @brief A wrapper for gbm_surface to allow OOP and RAII
87 CGBMSurface(const CGBMSurface
&) = delete;
88 CGBMSurface
& operator=(const CGBMSurface
&) = delete;
89 explicit CGBMSurface(gbm_surface
* surface
);
90 ~CGBMSurface() = default;
93 * @brief Get the underlying gbm_surface
95 * @return gbm_surface* A pointer to the underlying gbm_surface
97 gbm_surface
* Get() const { return m_surface
; }
100 * @brief A wrapper for gbm_bo to allow OOP and RAII
103 class CGBMSurfaceBuffer
106 CGBMSurfaceBuffer(const CGBMSurfaceBuffer
&) = delete;
107 CGBMSurfaceBuffer
& operator=(const CGBMSurfaceBuffer
&) = delete;
108 explicit CGBMSurfaceBuffer(gbm_surface
* surface
);
109 ~CGBMSurfaceBuffer();
112 * @brief Get the underlying gbm_bo
114 * @return gbm_bo* A pointer to the underlying gbm_bo
116 gbm_bo
* Get() const { return m_buffer
; }
119 gbm_surface
* m_surface
{nullptr};
120 gbm_bo
* m_buffer
{nullptr};
124 * @brief Lock the surface's current front buffer.
126 * @return CGBMSurfaceBuffer* A pointer to a CGBMSurfaceBuffer object
128 CGBMSurfaceBuffer
& LockFrontBuffer();
131 gbm_surface
* m_surface
{nullptr};
132 std::queue
<std::unique_ptr
<CGBMSurfaceBuffer
>> m_buffers
;
136 * @brief Get the CGBMSurface object
138 * @return CGBMSurface* A pointer to the CGBMSurface object
140 CGBMDevice::CGBMSurface
& GetSurface() const { return *m_surface
; }
143 gbm_device
* m_device
{nullptr};
145 struct CGBMSurfaceDeleter
147 void operator()(CGBMSurface
* p
) const
150 gbm_surface_destroy(p
->Get());
153 std::unique_ptr
<CGBMSurface
, CGBMSurfaceDeleter
> m_surface
;
157 * @brief Get the CGBMDevice object
159 * @return CGBMDevice* A pointer to the CGBMDevice object
161 CGBMUtils::CGBMDevice
& GetDevice() const { return *m_device
; }
164 struct CGBMDeviceDeleter
166 void operator()(CGBMDevice
* p
) const
169 gbm_device_destroy(p
->Get());
172 std::unique_ptr
<CGBMDevice
, CGBMDeviceDeleter
> m_device
;