Merge pull request #26166 from ksooo/improve-plugin-ctx-menus
[xbmc.git] / xbmc / utils / IBufferObject.h
blob4588aff98105f363a649932232ff380e91cbb368
1 /*
2 * Copyright (C) 2017-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 <stdint.h>
12 #include <string>
14 /**
15 * @brief Interface to describe CBufferObjects.
17 * BufferObjects are used to abstract various memory types and present them
18 * with a generic interface. Typically on a posix system exists the concept
19 * of Direct Memory Access (DMA) which allows various systems to interact
20 * with a memory location directly without having to copy the data into
21 * userspace (ie. from kernel space). These DMA buffers are presented as
22 * file descriptors (fds) which can be passed around to gain access to
23 * the buffers memory location.
25 * In order to write to these buffer types typically the memory location has
26 * to be mapped into userspace via a call to mmap (or similar). This presents
27 * userspace with a memory location that can be initially written to (ie. by
28 * using memcpy or similar). Depending on the underlying implementation a
29 * stride might be specified if the memory type requires padding to a certain
30 * size (such as page size). The stride must be used when copying into the buffer.
32 * Some memory implementation may provide special memory layouts in which case
33 * modifiers are provided that describe tiling or compression. This should be
34 * transparent to the caller as the data copied into a BufferObject will likely
35 * be linear. The modifier will be needed when presenting the buffer via DRM or
36 * EGL even if it is linear.
39 class IBufferObject
41 public:
42 virtual ~IBufferObject() = default;
44 /**
45 * @brief Create a BufferObject based on the format, width, and height of the desired buffer
47 * @param format framebuffer pixel formats are described using the fourcc codes defined in
48 * https://github.com/torvalds/linux/blob/master/include/uapi/drm/drm_fourcc.h
49 * @param width width of the requested buffer.
50 * @param height height of the requested buffer.
51 * @return true BufferObject creation was successful.
52 * @return false BufferObject creation was unsuccessful.
54 virtual bool CreateBufferObject(uint32_t format, uint32_t width, uint32_t height) = 0;
56 /**
57 * @brief Create a BufferObject based only on the size of the desired buffer. Not all
58 * CBufferObject implementations may support this. This method is required for
59 * use with the CAddonVideoCodec as it only knows the decoded buffer size.
61 * @param size of the requested buffer.
62 * @return true BufferObject creation was successful.
63 * @return false BufferObject creation was unsuccessful.
65 virtual bool CreateBufferObject(uint64_t size) = 0;
67 /**
68 * @brief Destroy a BufferObject.
71 virtual void DestroyBufferObject() = 0;
73 /**
74 * @brief Get the Memory location of the BufferObject. This method needs to be
75 * called to be able to copy data into the BufferObject.
77 * @return uint8_t* pointer to the memory location of the BufferObject.
79 virtual uint8_t *GetMemory() = 0;
81 /**
82 * @brief Release the mapped memory of the BufferObject. After calling this the memory
83 * location pointed to by GetMemory() will be invalid.
86 virtual void ReleaseMemory() = 0;
88 /**
89 * @brief Get the File Descriptor of the BufferObject. The fd is guaranteed to be
90 * available after calling CreateBufferObject().
92 * @return int fd for the BufferObject. Invalid if -1.
94 virtual int GetFd() = 0;
96 /**
97 * @brief Get the Stride of the BufferObject. The stride is guaranteed to be
98 * available after calling GetMemory().
100 * @return uint32_t stride of the BufferObject.
102 virtual uint32_t GetStride() = 0;
105 * @brief Get the Modifier of the BufferObject. Format Modifiers further describe
106 * the buffer's format such as for tiling or compression.
107 * see https://github.com/torvalds/linux/blob/master/include/uapi/drm/drm_fourcc.h
109 * @return uint64_t modifier of the BufferObject. 0 means the layout is linear (default).
111 virtual uint64_t GetModifier() = 0;
114 * @brief Must be called before reading/writing data to the BufferObject.
117 virtual void SyncStart() = 0;
120 * @brief Must be called after reading/writing data to the BufferObject.
123 virtual void SyncEnd() = 0;
126 * @brief Get the Name of the BufferObject type in use
128 * @return std::string name of the BufferObject type in use
130 virtual std::string GetName() const = 0;