diff options
author | Rob Clark | 2012-03-10 14:43:11 -0600 |
---|---|---|
committer | Rob Clark | 2012-03-10 14:43:11 -0600 |
commit | 9eff3986d49570c1b68f45e5bac639a7646f7c5f (patch) | |
tree | d75b8adbb009e1a27ab9aa55c2bed4a90b508068 | |
parent | 27386b03f0cf5baecceb768e7ca2474f8a712371 (diff) | |
download | external-libgbm-9eff3986d49570c1b68f45e5bac639a7646f7c5f.tar.gz external-libgbm-9eff3986d49570c1b68f45e5bac639a7646f7c5f.tar.xz external-libgbm-9eff3986d49570c1b68f45e5bac639a7646f7c5f.zip |
rebase on latest wayland version
-rw-r--r-- | gbm.c | 117 | ||||
-rw-r--r-- | gbmint.h | 16 |
2 files changed, 133 insertions, 0 deletions
@@ -48,6 +48,10 @@ struct gbm_device *devices[16]; | |||
48 | 48 | ||
49 | static int device_num = 0; | 49 | static int device_num = 0; |
50 | 50 | ||
51 | /** Returns the file description for the gbm device | ||
52 | * | ||
53 | * \return The fd that the struct gbm_device was created with | ||
54 | */ | ||
51 | GBM_EXPORT int | 55 | GBM_EXPORT int |
52 | gbm_device_get_fd(struct gbm_device *gbm) | 56 | gbm_device_get_fd(struct gbm_device *gbm) |
53 | { | 57 | { |
@@ -55,12 +59,29 @@ gbm_device_get_fd(struct gbm_device *gbm) | |||
55 | } | 59 | } |
56 | 60 | ||
57 | /* FIXME: maybe superfluous, use udev subclass from the fd? */ | 61 | /* FIXME: maybe superfluous, use udev subclass from the fd? */ |
62 | /** Get the backend name for the given gbm device | ||
63 | * | ||
64 | * \return The backend name string - this belongs to the device and must not | ||
65 | * be freed | ||
66 | */ | ||
58 | GBM_EXPORT const char * | 67 | GBM_EXPORT const char * |
59 | gbm_device_get_backend_name(struct gbm_device *gbm) | 68 | gbm_device_get_backend_name(struct gbm_device *gbm) |
60 | { | 69 | { |
61 | return gbm->name; | 70 | return gbm->name; |
62 | } | 71 | } |
63 | 72 | ||
73 | /** Test if a format is supported for a given set of usage flags. | ||
74 | * | ||
75 | * \param gbm The created buffer manager | ||
76 | * \param format The format to test | ||
77 | * \param usage A bitmask of the usages to test the format against | ||
78 | * \return 1 if the format is supported otherwise 0 | ||
79 | * | ||
80 | * \sa enum gbm_bo_flags for the list of flags that the format can be | ||
81 | * tested against | ||
82 | * | ||
83 | * \sa enum gbm_bo_format for the list of formats | ||
84 | */ | ||
64 | int | 85 | int |
65 | gbm_device_is_format_supported(struct gbm_device *gbm, | 86 | gbm_device_is_format_supported(struct gbm_device *gbm, |
66 | enum gbm_bo_format format, | 87 | enum gbm_bo_format format, |
@@ -69,6 +90,10 @@ gbm_device_is_format_supported(struct gbm_device *gbm, | |||
69 | return gbm->is_format_supported(gbm, format, usage); | 90 | return gbm->is_format_supported(gbm, format, usage); |
70 | } | 91 | } |
71 | 92 | ||
93 | /** Destroy the gbm device and free all resources associated with it. | ||
94 | * | ||
95 | * \param gbm The device created using gbm_create_device() | ||
96 | */ | ||
72 | GBM_EXPORT void | 97 | GBM_EXPORT void |
73 | gbm_device_destroy(struct gbm_device *gbm) | 98 | gbm_device_destroy(struct gbm_device *gbm) |
74 | { | 99 | { |
@@ -103,6 +128,18 @@ _gbm_mesa_get_device(int fd) | |||
103 | return gbm; | 128 | return gbm; |
104 | } | 129 | } |
105 | 130 | ||
131 | /** Create a gbm device for allocating buffers | ||
132 | * | ||
133 | * The file descriptor passed in is used by the backend to communicate with | ||
134 | * platform for allocating the memory. For allocations using DRI this would be | ||
135 | * the file descriptor returned when opening a device such as \c | ||
136 | * /dev/dri/card0 | ||
137 | * | ||
138 | * \param fd The file descriptor for an backend specific device | ||
139 | * \return The newly created struct gbm_device. The resources associated with | ||
140 | * the device should be freed with gbm_device_destroy() when it is no longer | ||
141 | * needed. If the creation of the device failed NULL will be returned. | ||
142 | */ | ||
106 | GBM_EXPORT struct gbm_device * | 143 | GBM_EXPORT struct gbm_device * |
107 | gbm_create_device(int fd) | 144 | gbm_create_device(int fd) |
108 | { | 145 | { |
@@ -131,36 +168,98 @@ gbm_create_device(int fd) | |||
131 | return gbm; | 168 | return gbm; |
132 | } | 169 | } |
133 | 170 | ||
171 | /** Get the width of the buffer object | ||
172 | * | ||
173 | * \param bo The buffer object | ||
174 | * \return The width of the allocated buffer object | ||
175 | * | ||
176 | */ | ||
134 | GBM_EXPORT unsigned int | 177 | GBM_EXPORT unsigned int |
135 | gbm_bo_get_width(struct gbm_bo *bo) | 178 | gbm_bo_get_width(struct gbm_bo *bo) |
136 | { | 179 | { |
137 | return bo->width; | 180 | return bo->width; |
138 | } | 181 | } |
139 | 182 | ||
183 | /** Get the height of the buffer object | ||
184 | * | ||
185 | * \param bo The buffer object | ||
186 | * \return The height of the allocated buffer object | ||
187 | */ | ||
140 | GBM_EXPORT unsigned int | 188 | GBM_EXPORT unsigned int |
141 | gbm_bo_get_height(struct gbm_bo *bo) | 189 | gbm_bo_get_height(struct gbm_bo *bo) |
142 | { | 190 | { |
143 | return bo->height; | 191 | return bo->height; |
144 | } | 192 | } |
145 | 193 | ||
194 | /** Get the stride of the buffer object | ||
195 | * | ||
196 | * This is calculated by the backend when it does the allocation in | ||
197 | * gbm_bo_create() | ||
198 | * | ||
199 | * \param bo The buffer object | ||
200 | * \return The stride of the allocated buffer object | ||
201 | */ | ||
146 | GBM_EXPORT uint32_t | 202 | GBM_EXPORT uint32_t |
147 | gbm_bo_get_pitch(struct gbm_bo *bo) | 203 | gbm_bo_get_pitch(struct gbm_bo *bo) |
148 | { | 204 | { |
149 | return bo->pitch; | 205 | return bo->pitch; |
150 | } | 206 | } |
151 | 207 | ||
208 | /** Get the format of the buffer object | ||
209 | * | ||
210 | * The format of the pixels in the buffer. | ||
211 | * | ||
212 | * \param bo The buffer object | ||
213 | * \return The format of buffer object, on of the GBM_FORMAT_* codes | ||
214 | */ | ||
215 | GBM_EXPORT uint32_t | ||
216 | gbm_bo_get_format(struct gbm_bo *bo) | ||
217 | { | ||
218 | return bo->format; | ||
219 | } | ||
220 | |||
221 | /** Get the handle of the buffer object | ||
222 | * | ||
223 | * This is stored in the platform generic union gbm_bo_handle type. However | ||
224 | * the format of this handle is platform specific. | ||
225 | * | ||
226 | * \param bo The buffer object | ||
227 | * \return Returns the handle of the allocated buffer object | ||
228 | */ | ||
152 | GBM_EXPORT union gbm_bo_handle | 229 | GBM_EXPORT union gbm_bo_handle |
153 | gbm_bo_get_handle(struct gbm_bo *bo) | 230 | gbm_bo_get_handle(struct gbm_bo *bo) |
154 | { | 231 | { |
155 | return bo->handle; | 232 | return bo->handle; |
156 | } | 233 | } |
157 | 234 | ||
235 | /** | ||
236 | * Destroys the given buffer object and frees all resources associated with | ||
237 | * it. | ||
238 | * | ||
239 | * \param bo The buffer object | ||
240 | */ | ||
158 | GBM_EXPORT void | 241 | GBM_EXPORT void |
159 | gbm_bo_destroy(struct gbm_bo *bo) | 242 | gbm_bo_destroy(struct gbm_bo *bo) |
160 | { | 243 | { |
161 | bo->gbm->bo_destroy(bo); | 244 | bo->gbm->bo_destroy(bo); |
162 | } | 245 | } |
163 | 246 | ||
247 | /** | ||
248 | * Allocate a buffer object for the given dimensions | ||
249 | * | ||
250 | * \param gbm The gbm device returned from gbm_create_device() | ||
251 | * \param width The width for the buffer | ||
252 | * \param height The height for the buffer | ||
253 | * \param format The format to use for the buffer | ||
254 | * \param usage The union of the usage flags for this buffer | ||
255 | * | ||
256 | * \return A newly allocated buffer that should be freed with gbm_bo_destroy() | ||
257 | * when no longer needed. If an error occurs during allocation %NULL will be | ||
258 | * returned. | ||
259 | * | ||
260 | * \sa enum gbm_bo_format for the list of formats | ||
261 | * \sa enum gbm_bo_flags for the list of usage flags | ||
262 | */ | ||
164 | GBM_EXPORT struct gbm_bo * | 263 | GBM_EXPORT struct gbm_bo * |
165 | gbm_bo_create(struct gbm_device *gbm, | 264 | gbm_bo_create(struct gbm_device *gbm, |
166 | uint32_t width, uint32_t height, | 265 | uint32_t width, uint32_t height, |
@@ -176,6 +275,24 @@ gbm_bo_create(struct gbm_device *gbm, | |||
176 | return gbm->bo_create(gbm, width, height, format, usage); | 275 | return gbm->bo_create(gbm, width, height, format, usage); |
177 | } | 276 | } |
178 | 277 | ||
278 | /** | ||
279 | * Create a buffer object representing the contents of an EGLImage | ||
280 | * | ||
281 | * \param gbm The gbm device returned from gbm_create_device() | ||
282 | * \param egl_dpy The EGLDisplay on which the EGLImage was created | ||
283 | * \param egl_image The EGLImage to create the buffer from | ||
284 | * \param width The width to use in the creation of the buffer object | ||
285 | * \param height The height to use in the creation of the buffer object | ||
286 | * \param usage The union of the usage flags for this buffer | ||
287 | * | ||
288 | * \return A newly allocated buffer object that should be freed with | ||
289 | * gbm_bo_destroy() when no longer needed. | ||
290 | * | ||
291 | * \sa enum gbm_bo_flags for the list of usage flags | ||
292 | * | ||
293 | * \note The expectation is that this function will use an efficient method | ||
294 | * for making the contents of the EGLImage available as a buffer object. | ||
295 | */ | ||
179 | GBM_EXPORT struct gbm_bo * | 296 | GBM_EXPORT struct gbm_bo * |
180 | gbm_bo_create_from_egl_image(struct gbm_device *gbm, | 297 | gbm_bo_create_from_egl_image(struct gbm_device *gbm, |
181 | void *egl_dpy, void *egl_image, | 298 | void *egl_dpy, void *egl_image, |
@@ -38,6 +38,16 @@ | |||
38 | #define GBM_EXPORT | 38 | #define GBM_EXPORT |
39 | #endif | 39 | #endif |
40 | 40 | ||
41 | /** | ||
42 | * \file gbmint.h | ||
43 | * \brief Internal implementation details of gbm | ||
44 | */ | ||
45 | |||
46 | /** | ||
47 | * The device used for the memory allocation. | ||
48 | * | ||
49 | * The members of this structure should be not accessed directly | ||
50 | */ | ||
41 | struct gbm_device { | 51 | struct gbm_device { |
42 | /* Hack to make a gbm_device detectable by its first element. */ | 52 | /* Hack to make a gbm_device detectable by its first element. */ |
43 | struct gbm_device *(*dummy)(int); | 53 | struct gbm_device *(*dummy)(int); |
@@ -63,11 +73,17 @@ struct gbm_device { | |||
63 | void (*bo_destroy)(struct gbm_bo *bo); | 73 | void (*bo_destroy)(struct gbm_bo *bo); |
64 | }; | 74 | }; |
65 | 75 | ||
76 | /** | ||
77 | * The allocated buffer object. | ||
78 | * | ||
79 | * The members in this structure should not be accessed directly. | ||
80 | */ | ||
66 | struct gbm_bo { | 81 | struct gbm_bo { |
67 | struct gbm_device *gbm; | 82 | struct gbm_device *gbm; |
68 | uint32_t width; | 83 | uint32_t width; |
69 | uint32_t height; | 84 | uint32_t height; |
70 | uint32_t pitch; | 85 | uint32_t pitch; |
86 | uint32_t format; | ||
71 | union gbm_bo_handle handle; | 87 | union gbm_bo_handle handle; |
72 | }; | 88 | }; |
73 | 89 | ||