[videodb] remove unused seasons table from episode_view
[xbmc.git] / xbmc / windowing / gbm / GBMUtils.h
blob031283461992ebe167fb6c65a5e893d3788a5cdf
1 /*
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.
7 */
9 #pragma once
11 #include <memory>
12 #include <queue>
14 #include <gbm.h>
16 namespace KODI
18 namespace WINDOWING
20 namespace GBM
23 /**
24 * @brief A wrapper for gbm c classes to allow OOP and RAII.
27 class CGBMUtils
29 public:
30 CGBMUtils(const CGBMUtils&) = delete;
31 CGBMUtils& operator=(const CGBMUtils&) = delete;
32 CGBMUtils() = default;
33 ~CGBMUtils() = default;
35 /**
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);
44 /**
45 * @brief A wrapper for gbm_device to allow OOP and RAII
48 class CGBMDevice
50 public:
51 CGBMDevice(const CGBMDevice&) = delete;
52 CGBMDevice& operator=(const CGBMDevice&) = delete;
53 explicit CGBMDevice(gbm_device* device);
54 ~CGBMDevice() = default;
56 /**
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,
68 int height,
69 uint32_t format,
70 const uint64_t* modifiers,
71 const int modifiers_count);
73 /**
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; }
80 /**
81 * @brief A wrapper for gbm_surface to allow OOP and RAII
84 class CGBMSurface
86 public:
87 CGBMSurface(const CGBMSurface&) = delete;
88 CGBMSurface& operator=(const CGBMSurface&) = delete;
89 explicit CGBMSurface(gbm_surface* surface);
90 ~CGBMSurface() = default;
92 /**
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; }
99 /**
100 * @brief A wrapper for gbm_bo to allow OOP and RAII
103 class CGBMSurfaceBuffer
105 public:
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; }
118 private:
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();
130 private:
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; }
142 private:
143 gbm_device* m_device{nullptr};
145 struct CGBMSurfaceDeleter
147 void operator()(CGBMSurface* p) const
149 if (p)
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; }
163 private:
164 struct CGBMDeviceDeleter
166 void operator()(CGBMDevice* p) const
168 if (p)
169 gbm_device_destroy(p->Get());
172 std::unique_ptr<CGBMDevice, CGBMDeviceDeleter> m_device;