diff options
author | Rob Clark | 2012-08-06 11:31:55 -0500 |
---|---|---|
committer | Rob Clark | 2012-08-06 11:31:55 -0500 |
commit | 71d604a9b6d0f50f7cb8e500a3906586987c8e89 (patch) | |
tree | 7095683294185ddf6cf4a4a992b5ade36259d7e4 | |
parent | 9eff3986d49570c1b68f45e5bac639a7646f7c5f (diff) | |
download | libgbm-71d604a9b6d0f50f7cb8e500a3906586987c8e89.tar.gz libgbm-71d604a9b6d0f50f7cb8e500a3906586987c8e89.tar.xz libgbm-71d604a9b6d0f50f7cb8e500a3906586987c8e89.zip |
sync w/ latest wayland (gbm_surface, etc)github-robclark
-rw-r--r-- | gbm.c | 207 | ||||
-rw-r--r-- | gbm.h | 203 | ||||
-rw-r--r-- | gbmint.h | 32 |
3 files changed, 404 insertions, 38 deletions
@@ -84,8 +84,7 @@ gbm_device_get_backend_name(struct gbm_device *gbm) | |||
84 | */ | 84 | */ |
85 | int | 85 | int |
86 | gbm_device_is_format_supported(struct gbm_device *gbm, | 86 | gbm_device_is_format_supported(struct gbm_device *gbm, |
87 | enum gbm_bo_format format, | 87 | uint32_t format, uint32_t usage) |
88 | uint32_t usage) | ||
89 | { | 88 | { |
90 | return gbm->is_format_supported(gbm, format, usage); | 89 | return gbm->is_format_supported(gbm, format, usage); |
91 | } | 90 | } |
@@ -197,12 +196,12 @@ gbm_bo_get_height(struct gbm_bo *bo) | |||
197 | * gbm_bo_create() | 196 | * gbm_bo_create() |
198 | * | 197 | * |
199 | * \param bo The buffer object | 198 | * \param bo The buffer object |
200 | * \return The stride of the allocated buffer object | 199 | * \return The stride of the allocated buffer object in bytes |
201 | */ | 200 | */ |
202 | GBM_EXPORT uint32_t | 201 | GBM_EXPORT uint32_t |
203 | gbm_bo_get_pitch(struct gbm_bo *bo) | 202 | gbm_bo_get_stride(struct gbm_bo *bo) |
204 | { | 203 | { |
205 | return bo->pitch; | 204 | return bo->stride; |
206 | } | 205 | } |
207 | 206 | ||
208 | /** Get the format of the buffer object | 207 | /** Get the format of the buffer object |
@@ -232,6 +231,65 @@ gbm_bo_get_handle(struct gbm_bo *bo) | |||
232 | return bo->handle; | 231 | return bo->handle; |
233 | } | 232 | } |
234 | 233 | ||
234 | /** Write data into the buffer object | ||
235 | * | ||
236 | * If the buffer object was created with the GBM_BO_USE_WRITE flag, | ||
237 | * this function can used to write data into the buffer object. The | ||
238 | * data is copied directly into the object and it's the responsiblity | ||
239 | * of the caller to make sure the data represents valid pixel data, | ||
240 | * according to the width, height, stride and format of the buffer object. | ||
241 | * | ||
242 | * \param bo The buffer object | ||
243 | * \param buf The data to write | ||
244 | * \param count The number of bytes to write | ||
245 | * \return Returns -1 on error, 0 otherwise | ||
246 | */ | ||
247 | GBM_EXPORT int | ||
248 | gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count) | ||
249 | { | ||
250 | return bo->gbm->bo_write(bo, buf, count); | ||
251 | } | ||
252 | |||
253 | /** Get the gbm device used to create the buffer object | ||
254 | * | ||
255 | * \param bo The buffer object | ||
256 | * \return Returns the gbm device with which the buffer object was created | ||
257 | */ | ||
258 | GBM_EXPORT struct gbm_device * | ||
259 | gbm_bo_get_device(struct gbm_bo *bo) | ||
260 | { | ||
261 | return bo->gbm; | ||
262 | } | ||
263 | |||
264 | /** Set the user data associated with a buffer object | ||
265 | * | ||
266 | * \param bo The buffer object | ||
267 | * \param data The data to associate to the buffer object | ||
268 | * \param destroy_user_data A callback (which may be %NULL) that will be | ||
269 | * called prior to the buffer destruction | ||
270 | */ | ||
271 | GBM_EXPORT void | ||
272 | gbm_bo_set_user_data(struct gbm_bo *bo, void *data, | ||
273 | void (*destroy_user_data)(struct gbm_bo *, void *)) | ||
274 | { | ||
275 | bo->user_data = data; | ||
276 | bo->destroy_user_data = destroy_user_data; | ||
277 | } | ||
278 | |||
279 | /** Get the user data associated with a buffer object | ||
280 | * | ||
281 | * \param bo The buffer object | ||
282 | * \return Returns the user data associated with the buffer object or %NULL | ||
283 | * if no data was associated with it | ||
284 | * | ||
285 | * \sa gbm_bo_set_user_data() | ||
286 | */ | ||
287 | GBM_EXPORT void * | ||
288 | gbm_bo_get_user_data(struct gbm_bo *bo) | ||
289 | { | ||
290 | return bo->user_data; | ||
291 | } | ||
292 | |||
235 | /** | 293 | /** |
236 | * Destroys the given buffer object and frees all resources associated with | 294 | * Destroys the given buffer object and frees all resources associated with |
237 | * it. | 295 | * it. |
@@ -241,6 +299,9 @@ gbm_bo_get_handle(struct gbm_bo *bo) | |||
241 | GBM_EXPORT void | 299 | GBM_EXPORT void |
242 | gbm_bo_destroy(struct gbm_bo *bo) | 300 | gbm_bo_destroy(struct gbm_bo *bo) |
243 | { | 301 | { |
302 | if (bo->destroy_user_data) | ||
303 | bo->destroy_user_data(bo, bo->user_data); | ||
304 | |||
244 | bo->gbm->bo_destroy(bo); | 305 | bo->gbm->bo_destroy(bo); |
245 | } | 306 | } |
246 | 307 | ||
@@ -263,7 +324,7 @@ gbm_bo_destroy(struct gbm_bo *bo) | |||
263 | GBM_EXPORT struct gbm_bo * | 324 | GBM_EXPORT struct gbm_bo * |
264 | gbm_bo_create(struct gbm_device *gbm, | 325 | gbm_bo_create(struct gbm_device *gbm, |
265 | uint32_t width, uint32_t height, | 326 | uint32_t width, uint32_t height, |
266 | enum gbm_bo_format format, uint32_t usage) | 327 | uint32_t format, uint32_t usage) |
267 | { | 328 | { |
268 | if (width == 0 || height == 0) | 329 | if (width == 0 || height == 0) |
269 | return NULL; | 330 | return NULL; |
@@ -276,32 +337,136 @@ gbm_bo_create(struct gbm_device *gbm, | |||
276 | } | 337 | } |
277 | 338 | ||
278 | /** | 339 | /** |
279 | * Create a buffer object representing the contents of an EGLImage | 340 | * Create a gbm buffer object from an foreign object |
341 | * | ||
342 | * This function imports a foreign object and creates a new gbm bo for it. | ||
343 | * This enabled using the foreign object with a display API such as KMS. | ||
344 | * Currently two types of foreign objects are supported, indicated by the type | ||
345 | * argument: | ||
346 | * | ||
347 | * GBM_BO_IMPORT_WL_BUFFER | ||
348 | * GBM_BO_IMPORT_EGL_IMAGE | ||
349 | * | ||
350 | * The the gbm bo shares the underlying pixels but its life-time is | ||
351 | * independent of the foreign object. | ||
280 | * | 352 | * |
281 | * \param gbm The gbm device returned from gbm_create_device() | 353 | * \param gbm The gbm device returned from gbm_create_device() |
282 | * \param egl_dpy The EGLDisplay on which the EGLImage was created | 354 | * \param gbm The type of object we're importing |
283 | * \param egl_image The EGLImage to create the buffer from | 355 | * \param gbm Pointer to the external object |
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 | 356 | * \param usage The union of the usage flags for this buffer |
287 | * | 357 | * |
288 | * \return A newly allocated buffer object that should be freed with | 358 | * \return A newly allocated buffer object that should be freed with |
289 | * gbm_bo_destroy() when no longer needed. | 359 | * gbm_bo_destroy() when no longer needed. |
290 | * | 360 | * |
291 | * \sa enum gbm_bo_flags for the list of usage flags | 361 | * \sa enum gbm_bo_flags for the list of usage flags |
362 | */ | ||
363 | GBM_EXPORT struct gbm_bo * | ||
364 | gbm_bo_import(struct gbm_device *gbm, | ||
365 | uint32_t type, void *buffer, uint32_t usage) | ||
366 | { | ||
367 | return gbm->bo_import(gbm, type, buffer, usage); | ||
368 | } | ||
369 | |||
370 | /** | ||
371 | * Allocate a surface object | ||
372 | * | ||
373 | * \param gbm The gbm device returned from gbm_create_device() | ||
374 | * \param width The width for the surface | ||
375 | * \param height The height for the surface | ||
376 | * \param format The format to use for the surface | ||
377 | * | ||
378 | * \return A newly allocated surface that should be freed with | ||
379 | * gbm_surface_destroy() when no longer needed. If an error occurs | ||
380 | * during allocation %NULL will be returned. | ||
381 | * | ||
382 | * \sa enum gbm_bo_format for the list of formats | ||
383 | */ | ||
384 | GBM_EXPORT struct gbm_surface * | ||
385 | gbm_surface_create(struct gbm_device *gbm, | ||
386 | uint32_t width, uint32_t height, | ||
387 | uint32_t format, uint32_t flags) | ||
388 | { | ||
389 | return gbm->surface_create(gbm, width, height, format, flags); | ||
390 | } | ||
391 | |||
392 | /** | ||
393 | * Destroys the given surface and frees all resources associated with | ||
394 | * it. | ||
395 | * | ||
396 | * All buffers locked with gbm_surface_lock_front_buffer() should be | ||
397 | * released prior to calling this function. | ||
398 | * | ||
399 | * \param surf The surface | ||
400 | */ | ||
401 | GBM_EXPORT void | ||
402 | gbm_surface_destroy(struct gbm_surface *surf) | ||
403 | { | ||
404 | surf->gbm->surface_destroy(surf); | ||
405 | } | ||
406 | |||
407 | /** | ||
408 | * Lock the surface's current front buffer | ||
409 | * | ||
410 | * Lock rendering to the surface's current front buffer until it is | ||
411 | * released with gbm_surface_release_buffer(). | ||
412 | * | ||
413 | * This function must be called exactly once after calling | ||
414 | * eglSwapBuffers. Calling it before any eglSwapBuffer has happened | ||
415 | * on the surface or two or more times after eglSwapBuffers is an | ||
416 | * error. A new bo representing the new front buffer is returned. On | ||
417 | * multiple invocations, all the returned bos must be released in | ||
418 | * order to release the actual surface buffer. | ||
292 | * | 419 | * |
293 | * \note The expectation is that this function will use an efficient method | 420 | * \param surf The surface |
294 | * for making the contents of the EGLImage available as a buffer object. | 421 | * |
422 | * \return A buffer object that should be released with | ||
423 | * gbm_surface_release_buffer() when no longer needed. The implementation | ||
424 | * is free to reuse buffers released with gbm_surface_release_buffer() so | ||
425 | * this bo should not be destroyed using gbm_bo_destroy(). If an error | ||
426 | * occurs this function returns %NULL. | ||
295 | */ | 427 | */ |
296 | GBM_EXPORT struct gbm_bo * | 428 | GBM_EXPORT struct gbm_bo * |
297 | gbm_bo_create_from_egl_image(struct gbm_device *gbm, | 429 | gbm_surface_lock_front_buffer(struct gbm_surface *surf) |
298 | void *egl_dpy, void *egl_image, | ||
299 | uint32_t width, uint32_t height, | ||
300 | uint32_t usage) | ||
301 | { | 430 | { |
302 | if (width == 0 || height == 0) | 431 | return surf->gbm->surface_lock_front_buffer(surf); |
303 | return NULL; | 432 | } |
433 | |||
434 | /** | ||
435 | * Release a locked buffer obtained with gbm_surface_lock_front_buffer() | ||
436 | * | ||
437 | * Returns the underlying buffer to the gbm surface. Releasing a bo | ||
438 | * will typically make gbm_surface_has_free_buffer() return 1 and thus | ||
439 | * allow rendering the next frame, but not always. The implementation | ||
440 | * may choose to destroy the bo immediately or reuse it, in which case | ||
441 | * the user data associated with it is unchanged. | ||
442 | * | ||
443 | * \param surf The surface | ||
444 | * \param bo The buffer object | ||
445 | */ | ||
446 | GBM_EXPORT void | ||
447 | gbm_surface_release_buffer(struct gbm_surface *surf, struct gbm_bo *bo) | ||
448 | { | ||
449 | surf->gbm->surface_release_buffer(surf, bo); | ||
450 | } | ||
304 | 451 | ||
305 | return gbm->bo_create_from_egl_image(gbm, egl_dpy, egl_image, | 452 | /** |
306 | width, height, usage); | 453 | * Return whether or not a surface has free (non-locked) buffers |
454 | * | ||
455 | * Before starting a new frame, the surface must have a buffer | ||
456 | * available for rendering. Initially, a gbm surface will have a free | ||
457 | * buffer, but after one of more buffers have been locked (\sa | ||
458 | * gbm_surface_lock_front_buffer()), the application must check for a | ||
459 | * free buffer before rendering. | ||
460 | * | ||
461 | * If a surface doesn't have a free buffer, the application must | ||
462 | * return a buffer to the surface using gbm_surface_release_buffer() | ||
463 | * and after that, the application can query for free buffers again. | ||
464 | * | ||
465 | * \param surf The surface | ||
466 | * \return 1 if the surface has free buffers, 0 otherwise | ||
467 | */ | ||
468 | GBM_EXPORT int | ||
469 | gbm_surface_has_free_buffers(struct gbm_surface *surf) | ||
470 | { | ||
471 | return surf->gbm->surface_has_free_buffers(surf); | ||
307 | } | 472 | } |
@@ -37,9 +37,29 @@ extern "C" { | |||
37 | 37 | ||
38 | #include <stdint.h> | 38 | #include <stdint.h> |
39 | 39 | ||
40 | /** | ||
41 | * \file gbm.h | ||
42 | * \brief Generic Buffer Manager | ||
43 | */ | ||
44 | |||
40 | struct gbm_device; | 45 | struct gbm_device; |
41 | struct gbm_bo; | 46 | struct gbm_bo; |
47 | struct gbm_surface; | ||
42 | 48 | ||
49 | /** | ||
50 | * \mainpage The Generic Buffer Manager | ||
51 | * | ||
52 | * This module provides an abstraction that the caller can use to request a | ||
53 | * buffer from the underlying memory management system for the platform. | ||
54 | * | ||
55 | * This allows the creation of portable code whilst still allowing access to | ||
56 | * the underlying memory manager. | ||
57 | */ | ||
58 | |||
59 | /** | ||
60 | * Abstraction representing the handle to a buffer allocated by the | ||
61 | * manager | ||
62 | */ | ||
43 | union gbm_bo_handle { | 63 | union gbm_bo_handle { |
44 | void *ptr; | 64 | void *ptr; |
45 | int32_t s32; | 65 | int32_t s32; |
@@ -48,15 +68,145 @@ union gbm_bo_handle { | |||
48 | uint64_t u64; | 68 | uint64_t u64; |
49 | }; | 69 | }; |
50 | 70 | ||
71 | /** Format of the allocated buffer */ | ||
51 | enum gbm_bo_format { | 72 | enum gbm_bo_format { |
52 | GBM_BO_FORMAT_XRGB8888, | 73 | /** RGB with 8 bits per channel in a 32 bit value */ |
53 | GBM_BO_FORMAT_ARGB8888, | 74 | GBM_BO_FORMAT_XRGB8888, |
75 | /** ARGB with 8 bits per channel in a 32 bit value */ | ||
76 | GBM_BO_FORMAT_ARGB8888 | ||
54 | }; | 77 | }; |
55 | 78 | ||
79 | #define __gbm_fourcc_code(a,b,c,d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \ | ||
80 | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24)) | ||
81 | |||
82 | #define GBM_FORMAT_BIG_ENDIAN (1<<31) /* format is big endian instead of little endian */ | ||
83 | |||
84 | /* color index */ | ||
85 | #define GBM_FORMAT_C8 __gbm_fourcc_code('C', '8', ' ', ' ') /* [7:0] C */ | ||
86 | |||
87 | /* 8 bpp RGB */ | ||
88 | #define GBM_FORMAT_RGB332 __gbm_fourcc_code('R', 'G', 'B', '8') /* [7:0] R:G:B 3:3:2 */ | ||
89 | #define GBM_FORMAT_BGR233 __gbm_fourcc_code('B', 'G', 'R', '8') /* [7:0] B:G:R 2:3:3 */ | ||
90 | |||
91 | /* 16 bpp RGB */ | ||
92 | #define GBM_FORMAT_XRGB4444 __gbm_fourcc_code('X', 'R', '1', '2') /* [15:0] x:R:G:B 4:4:4:4 little endian */ | ||
93 | #define GBM_FORMAT_XBGR4444 __gbm_fourcc_code('X', 'B', '1', '2') /* [15:0] x:B:G:R 4:4:4:4 little endian */ | ||
94 | #define GBM_FORMAT_RGBX4444 __gbm_fourcc_code('R', 'X', '1', '2') /* [15:0] R:G:B:x 4:4:4:4 little endian */ | ||
95 | #define GBM_FORMAT_BGRX4444 __gbm_fourcc_code('B', 'X', '1', '2') /* [15:0] B:G:R:x 4:4:4:4 little endian */ | ||
96 | |||
97 | #define GBM_FORMAT_ARGB4444 __gbm_fourcc_code('A', 'R', '1', '2') /* [15:0] A:R:G:B 4:4:4:4 little endian */ | ||
98 | #define GBM_FORMAT_ABGR4444 __gbm_fourcc_code('A', 'B', '1', '2') /* [15:0] A:B:G:R 4:4:4:4 little endian */ | ||
99 | #define GBM_FORMAT_RGBA4444 __gbm_fourcc_code('R', 'A', '1', '2') /* [15:0] R:G:B:A 4:4:4:4 little endian */ | ||
100 | #define GBM_FORMAT_BGRA4444 __gbm_fourcc_code('B', 'A', '1', '2') /* [15:0] B:G:R:A 4:4:4:4 little endian */ | ||
101 | |||
102 | #define GBM_FORMAT_XRGB1555 __gbm_fourcc_code('X', 'R', '1', '5') /* [15:0] x:R:G:B 1:5:5:5 little endian */ | ||
103 | #define GBM_FORMAT_XBGR1555 __gbm_fourcc_code('X', 'B', '1', '5') /* [15:0] x:B:G:R 1:5:5:5 little endian */ | ||
104 | #define GBM_FORMAT_RGBX5551 __gbm_fourcc_code('R', 'X', '1', '5') /* [15:0] R:G:B:x 5:5:5:1 little endian */ | ||
105 | #define GBM_FORMAT_BGRX5551 __gbm_fourcc_code('B', 'X', '1', '5') /* [15:0] B:G:R:x 5:5:5:1 little endian */ | ||
106 | |||
107 | #define GBM_FORMAT_ARGB1555 __gbm_fourcc_code('A', 'R', '1', '5') /* [15:0] A:R:G:B 1:5:5:5 little endian */ | ||
108 | #define GBM_FORMAT_ABGR1555 __gbm_fourcc_code('A', 'B', '1', '5') /* [15:0] A:B:G:R 1:5:5:5 little endian */ | ||
109 | #define GBM_FORMAT_RGBA5551 __gbm_fourcc_code('R', 'A', '1', '5') /* [15:0] R:G:B:A 5:5:5:1 little endian */ | ||
110 | #define GBM_FORMAT_BGRA5551 __gbm_fourcc_code('B', 'A', '1', '5') /* [15:0] B:G:R:A 5:5:5:1 little endian */ | ||
111 | |||
112 | #define GBM_FORMAT_RGB565 __gbm_fourcc_code('R', 'G', '1', '6') /* [15:0] R:G:B 5:6:5 little endian */ | ||
113 | #define GBM_FORMAT_BGR565 __gbm_fourcc_code('B', 'G', '1', '6') /* [15:0] B:G:R 5:6:5 little endian */ | ||
114 | |||
115 | /* 24 bpp RGB */ | ||
116 | #define GBM_FORMAT_RGB888 __gbm_fourcc_code('R', 'G', '2', '4') /* [23:0] R:G:B little endian */ | ||
117 | #define GBM_FORMAT_BGR888 __gbm_fourcc_code('B', 'G', '2', '4') /* [23:0] B:G:R little endian */ | ||
118 | |||
119 | /* 32 bpp RGB */ | ||
120 | #define GBM_FORMAT_XRGB8888 __gbm_fourcc_code('X', 'R', '2', '4') /* [31:0] x:R:G:B 8:8:8:8 little endian */ | ||
121 | #define GBM_FORMAT_XBGR8888 __gbm_fourcc_code('X', 'B', '2', '4') /* [31:0] x:B:G:R 8:8:8:8 little endian */ | ||
122 | #define GBM_FORMAT_RGBX8888 __gbm_fourcc_code('R', 'X', '2', '4') /* [31:0] R:G:B:x 8:8:8:8 little endian */ | ||
123 | #define GBM_FORMAT_BGRX8888 __gbm_fourcc_code('B', 'X', '2', '4') /* [31:0] B:G:R:x 8:8:8:8 little endian */ | ||
124 | |||
125 | #define GBM_FORMAT_ARGB8888 __gbm_fourcc_code('A', 'R', '2', '4') /* [31:0] A:R:G:B 8:8:8:8 little endian */ | ||
126 | #define GBM_FORMAT_ABGR8888 __gbm_fourcc_code('A', 'B', '2', '4') /* [31:0] A:B:G:R 8:8:8:8 little endian */ | ||
127 | #define GBM_FORMAT_RGBA8888 __gbm_fourcc_code('R', 'A', '2', '4') /* [31:0] R:G:B:A 8:8:8:8 little endian */ | ||
128 | #define GBM_FORMAT_BGRA8888 __gbm_fourcc_code('B', 'A', '2', '4') /* [31:0] B:G:R:A 8:8:8:8 little endian */ | ||
129 | |||
130 | #define GBM_FORMAT_XRGB2101010 __gbm_fourcc_code('X', 'R', '3', '0') /* [31:0] x:R:G:B 2:10:10:10 little endian */ | ||
131 | #define GBM_FORMAT_XBGR2101010 __gbm_fourcc_code('X', 'B', '3', '0') /* [31:0] x:B:G:R 2:10:10:10 little endian */ | ||
132 | #define GBM_FORMAT_RGBX1010102 __gbm_fourcc_code('R', 'X', '3', '0') /* [31:0] R:G:B:x 10:10:10:2 little endian */ | ||
133 | #define GBM_FORMAT_BGRX1010102 __gbm_fourcc_code('B', 'X', '3', '0') /* [31:0] B:G:R:x 10:10:10:2 little endian */ | ||
134 | |||
135 | #define GBM_FORMAT_ARGB2101010 __gbm_fourcc_code('A', 'R', '3', '0') /* [31:0] A:R:G:B 2:10:10:10 little endian */ | ||
136 | #define GBM_FORMAT_ABGR2101010 __gbm_fourcc_code('A', 'B', '3', '0') /* [31:0] A:B:G:R 2:10:10:10 little endian */ | ||
137 | #define GBM_FORMAT_RGBA1010102 __gbm_fourcc_code('R', 'A', '3', '0') /* [31:0] R:G:B:A 10:10:10:2 little endian */ | ||
138 | #define GBM_FORMAT_BGRA1010102 __gbm_fourcc_code('B', 'A', '3', '0') /* [31:0] B:G:R:A 10:10:10:2 little endian */ | ||
139 | |||
140 | /* packed YCbCr */ | ||
141 | #define GBM_FORMAT_YUYV __gbm_fourcc_code('Y', 'U', 'Y', 'V') /* [31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian */ | ||
142 | #define GBM_FORMAT_YVYU __gbm_fourcc_code('Y', 'V', 'Y', 'U') /* [31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian */ | ||
143 | #define GBM_FORMAT_UYVY __gbm_fourcc_code('U', 'Y', 'V', 'Y') /* [31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian */ | ||
144 | #define GBM_FORMAT_VYUY __gbm_fourcc_code('V', 'Y', 'U', 'Y') /* [31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian */ | ||
145 | |||
146 | #define GBM_FORMAT_AYUV __gbm_fourcc_code('A', 'Y', 'U', 'V') /* [31:0] A:Y:Cb:Cr 8:8:8:8 little endian */ | ||
147 | |||
148 | /* | ||
149 | * 2 plane YCbCr | ||
150 | * index 0 = Y plane, [7:0] Y | ||
151 | * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian | ||
152 | * or | ||
153 | * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian | ||
154 | */ | ||
155 | #define GBM_FORMAT_NV12 __gbm_fourcc_code('N', 'V', '1', '2') /* 2x2 subsampled Cr:Cb plane */ | ||
156 | #define GBM_FORMAT_NV21 __gbm_fourcc_code('N', 'V', '2', '1') /* 2x2 subsampled Cb:Cr plane */ | ||
157 | #define GBM_FORMAT_NV16 __gbm_fourcc_code('N', 'V', '1', '6') /* 2x1 subsampled Cr:Cb plane */ | ||
158 | #define GBM_FORMAT_NV61 __gbm_fourcc_code('N', 'V', '6', '1') /* 2x1 subsampled Cb:Cr plane */ | ||
159 | |||
160 | /* | ||
161 | * 3 plane YCbCr | ||
162 | * index 0: Y plane, [7:0] Y | ||
163 | * index 1: Cb plane, [7:0] Cb | ||
164 | * index 2: Cr plane, [7:0] Cr | ||
165 | * or | ||
166 | * index 1: Cr plane, [7:0] Cr | ||
167 | * index 2: Cb plane, [7:0] Cb | ||
168 | */ | ||
169 | #define GBM_FORMAT_YUV410 __gbm_fourcc_code('Y', 'U', 'V', '9') /* 4x4 subsampled Cb (1) and Cr (2) planes */ | ||
170 | #define GBM_FORMAT_YVU410 __gbm_fourcc_code('Y', 'V', 'U', '9') /* 4x4 subsampled Cr (1) and Cb (2) planes */ | ||
171 | #define GBM_FORMAT_YUV411 __gbm_fourcc_code('Y', 'U', '1', '1') /* 4x1 subsampled Cb (1) and Cr (2) planes */ | ||
172 | #define GBM_FORMAT_YVU411 __gbm_fourcc_code('Y', 'V', '1', '1') /* 4x1 subsampled Cr (1) and Cb (2) planes */ | ||
173 | #define GBM_FORMAT_YUV420 __gbm_fourcc_code('Y', 'U', '1', '2') /* 2x2 subsampled Cb (1) and Cr (2) planes */ | ||
174 | #define GBM_FORMAT_YVU420 __gbm_fourcc_code('Y', 'V', '1', '2') /* 2x2 subsampled Cr (1) and Cb (2) planes */ | ||
175 | #define GBM_FORMAT_YUV422 __gbm_fourcc_code('Y', 'U', '1', '6') /* 2x1 subsampled Cb (1) and Cr (2) planes */ | ||
176 | #define GBM_FORMAT_YVU422 __gbm_fourcc_code('Y', 'V', '1', '6') /* 2x1 subsampled Cr (1) and Cb (2) planes */ | ||
177 | #define GBM_FORMAT_YUV444 __gbm_fourcc_code('Y', 'U', '2', '4') /* non-subsampled Cb (1) and Cr (2) planes */ | ||
178 | #define GBM_FORMAT_YVU444 __gbm_fourcc_code('Y', 'V', '2', '4') /* non-subsampled Cr (1) and Cb (2) planes */ | ||
179 | |||
180 | |||
181 | /** | ||
182 | * Flags to indicate the intended use for the buffer - these are passed into | ||
183 | * gbm_bo_create(). The caller must set the union of all the flags that are | ||
184 | * appropriate | ||
185 | * | ||
186 | * \sa Use gbm_device_is_format_supported() to check if the combination of format | ||
187 | * and use flags are supported | ||
188 | */ | ||
56 | enum gbm_bo_flags { | 189 | enum gbm_bo_flags { |
190 | /** | ||
191 | * Buffer is going to be presented to the screen using an API such as KMS | ||
192 | */ | ||
57 | GBM_BO_USE_SCANOUT = (1 << 0), | 193 | GBM_BO_USE_SCANOUT = (1 << 0), |
194 | /** | ||
195 | * Buffer is going to be used as cursor - the dimensions for the buffer | ||
196 | * must be 64x64 if this flag is passed. | ||
197 | */ | ||
58 | GBM_BO_USE_CURSOR_64X64 = (1 << 1), | 198 | GBM_BO_USE_CURSOR_64X64 = (1 << 1), |
199 | /** | ||
200 | * Buffer is to be used for rendering - for example it is going to be used | ||
201 | * as the storage for a color buffer | ||
202 | */ | ||
59 | GBM_BO_USE_RENDERING = (1 << 2), | 203 | GBM_BO_USE_RENDERING = (1 << 2), |
204 | /** | ||
205 | * Buffer can be used for gbm_bo_write. This is guaranteed to work | ||
206 | * with GBM_BO_USE_CURSOR_64X64. but may not work for other | ||
207 | * combinations. | ||
208 | */ | ||
209 | GBM_BO_USE_WRITE = (1 << 3), | ||
60 | }; | 210 | }; |
61 | 211 | ||
62 | int | 212 | int |
@@ -67,8 +217,7 @@ gbm_device_get_backend_name(struct gbm_device *gbm); | |||
67 | 217 | ||
68 | int | 218 | int |
69 | gbm_device_is_format_supported(struct gbm_device *gbm, | 219 | gbm_device_is_format_supported(struct gbm_device *gbm, |
70 | enum gbm_bo_format format, | 220 | uint32_t format, uint32_t usage); |
71 | uint32_t usage); | ||
72 | 221 | ||
73 | void | 222 | void |
74 | gbm_device_destroy(struct gbm_device *gbm); | 223 | gbm_device_destroy(struct gbm_device *gbm); |
@@ -79,13 +228,14 @@ gbm_create_device(int fd); | |||
79 | struct gbm_bo * | 228 | struct gbm_bo * |
80 | gbm_bo_create(struct gbm_device *gbm, | 229 | gbm_bo_create(struct gbm_device *gbm, |
81 | uint32_t width, uint32_t height, | 230 | uint32_t width, uint32_t height, |
82 | enum gbm_bo_format format, uint32_t flags); | 231 | uint32_t format, uint32_t flags); |
232 | |||
233 | #define GBM_BO_IMPORT_WL_BUFFER 0x5501 | ||
234 | #define GBM_BO_IMPORT_EGL_IMAGE 0x5502 | ||
83 | 235 | ||
84 | struct gbm_bo * | 236 | struct gbm_bo * |
85 | gbm_bo_create_from_egl_image(struct gbm_device *gbm, | 237 | gbm_bo_import(struct gbm_device *gbm, uint32_t type, |
86 | void *egl_dpy, void *egl_img, | 238 | void *buffer, uint32_t usage); |
87 | uint32_t width, uint32_t height, | ||
88 | uint32_t usage); | ||
89 | 239 | ||
90 | uint32_t | 240 | uint32_t |
91 | gbm_bo_get_width(struct gbm_bo *bo); | 241 | gbm_bo_get_width(struct gbm_bo *bo); |
@@ -94,14 +244,47 @@ uint32_t | |||
94 | gbm_bo_get_height(struct gbm_bo *bo); | 244 | gbm_bo_get_height(struct gbm_bo *bo); |
95 | 245 | ||
96 | uint32_t | 246 | uint32_t |
97 | gbm_bo_get_pitch(struct gbm_bo *bo); | 247 | gbm_bo_get_stride(struct gbm_bo *bo); |
248 | |||
249 | uint32_t | ||
250 | gbm_bo_get_format(struct gbm_bo *bo); | ||
251 | |||
252 | struct gbm_device * | ||
253 | gbm_bo_get_device(struct gbm_bo *bo); | ||
98 | 254 | ||
99 | union gbm_bo_handle | 255 | union gbm_bo_handle |
100 | gbm_bo_get_handle(struct gbm_bo *bo); | 256 | gbm_bo_get_handle(struct gbm_bo *bo); |
101 | 257 | ||
258 | int | ||
259 | gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count); | ||
260 | |||
261 | void | ||
262 | gbm_bo_set_user_data(struct gbm_bo *bo, void *data, | ||
263 | void (*destroy_user_data)(struct gbm_bo *, void *)); | ||
264 | |||
265 | void * | ||
266 | gbm_bo_get_user_data(struct gbm_bo *bo); | ||
267 | |||
102 | void | 268 | void |
103 | gbm_bo_destroy(struct gbm_bo *bo); | 269 | gbm_bo_destroy(struct gbm_bo *bo); |
104 | 270 | ||
271 | struct gbm_surface * | ||
272 | gbm_surface_create(struct gbm_device *gbm, | ||
273 | uint32_t width, uint32_t height, | ||
274 | uint32_t format, uint32_t flags); | ||
275 | |||
276 | struct gbm_bo * | ||
277 | gbm_surface_lock_front_buffer(struct gbm_surface *surface); | ||
278 | |||
279 | void | ||
280 | gbm_surface_release_buffer(struct gbm_surface *surface, struct gbm_bo *bo); | ||
281 | |||
282 | int | ||
283 | gbm_surface_has_free_buffers(struct gbm_surface *surface); | ||
284 | |||
285 | void | ||
286 | gbm_surface_destroy(struct gbm_surface *surface); | ||
287 | |||
105 | #ifdef __cplusplus | 288 | #ifdef __cplusplus |
106 | } | 289 | } |
107 | #endif | 290 | #endif |
@@ -59,18 +59,26 @@ struct gbm_device { | |||
59 | 59 | ||
60 | void (*destroy)(struct gbm_device *gbm); | 60 | void (*destroy)(struct gbm_device *gbm); |
61 | int (*is_format_supported)(struct gbm_device *gbm, | 61 | int (*is_format_supported)(struct gbm_device *gbm, |
62 | enum gbm_bo_format format, | 62 | uint32_t format, |
63 | uint32_t usage); | 63 | uint32_t usage); |
64 | 64 | ||
65 | struct gbm_bo *(*bo_create)(struct gbm_device *gbm, | 65 | struct gbm_bo *(*bo_create)(struct gbm_device *gbm, |
66 | uint32_t width, uint32_t height, | 66 | uint32_t width, uint32_t height, |
67 | enum gbm_bo_format format, | 67 | uint32_t format, |
68 | uint32_t usage); | 68 | uint32_t usage); |
69 | struct gbm_bo *(*bo_create_from_egl_image)(struct gbm_device *gbm, | 69 | struct gbm_bo *(*bo_import)(struct gbm_device *gbm, uint32_t type, |
70 | void *egl_dpy, void *egl_img, | 70 | void *buffer, uint32_t usage); |
71 | uint32_t width, uint32_t height, | 71 | int (*bo_write)(struct gbm_bo *bo, const void *buf, size_t data); |
72 | uint32_t usage); | ||
73 | void (*bo_destroy)(struct gbm_bo *bo); | 72 | void (*bo_destroy)(struct gbm_bo *bo); |
73 | |||
74 | struct gbm_surface *(*surface_create)(struct gbm_device *gbm, | ||
75 | uint32_t width, uint32_t height, | ||
76 | uint32_t format, uint32_t flags); | ||
77 | struct gbm_bo *(*surface_lock_front_buffer)(struct gbm_surface *surface); | ||
78 | void (*surface_release_buffer)(struct gbm_surface *surface, | ||
79 | struct gbm_bo *bo); | ||
80 | int (*surface_has_free_buffers)(struct gbm_surface *surface); | ||
81 | void (*surface_destroy)(struct gbm_surface *surface); | ||
74 | }; | 82 | }; |
75 | 83 | ||
76 | /** | 84 | /** |
@@ -82,9 +90,19 @@ struct gbm_bo { | |||
82 | struct gbm_device *gbm; | 90 | struct gbm_device *gbm; |
83 | uint32_t width; | 91 | uint32_t width; |
84 | uint32_t height; | 92 | uint32_t height; |
85 | uint32_t pitch; | 93 | uint32_t stride; |
86 | uint32_t format; | 94 | uint32_t format; |
87 | union gbm_bo_handle handle; | 95 | union gbm_bo_handle handle; |
96 | void *user_data; | ||
97 | void (*destroy_user_data)(struct gbm_bo *, void *); | ||
98 | }; | ||
99 | |||
100 | struct gbm_surface { | ||
101 | struct gbm_device *gbm; | ||
102 | uint32_t width; | ||
103 | uint32_t height; | ||
104 | uint32_t format; | ||
105 | uint32_t flags; | ||
88 | }; | 106 | }; |
89 | 107 | ||
90 | struct gbm_backend { | 108 | struct gbm_backend { |