diff options
Diffstat (limited to 'src/gbm/main')
-rw-r--r-- | src/gbm/main/gbm.c | 80 | ||||
-rw-r--r-- | src/gbm/main/gbm.h | 19 | ||||
-rw-r--r-- | src/gbm/main/gbmint.h | 3 |
3 files changed, 94 insertions, 8 deletions
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c index 79ba65051f2..3994f86aafc 100644 --- a/src/gbm/main/gbm.c +++ b/src/gbm/main/gbm.c @@ -231,6 +231,65 @@ gbm_bo_get_handle(struct gbm_bo *bo) return bo->handle; } +/** Write data into the buffer object + * + * If the buffer object was created with the GBM_BO_USE_WRITE flag, + * this function can used to write data into the buffer object. The + * data is copied directly into the object and it's the responsiblity + * of the caller to make sure the data represents valid pixel data, + * according to the width, height, stride and format of the buffer object. + * + * \param bo The buffer object + * \param buf The data to write + * \param count The number of bytes to write + * \return Returns -1 on error, 0 otherwise + */ +GBM_EXPORT int +gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count) +{ + return bo->gbm->bo_write(bo, buf, count); +} + +/** Get the gbm device used to create the buffer object + * + * \param bo The buffer object + * \return Returns the gbm device with which the buffer object was created + */ +GBM_EXPORT struct gbm_device * +gbm_bo_get_device(struct gbm_bo *bo) +{ + return bo->gbm; +} + +/** Set the user data associated with a buffer object + * + * \param bo The buffer object + * \param data The data to associate to the buffer object + * \param destroy_user_data A callback (which may be %NULL) that will be + * called prior to the buffer destruction + */ +GBM_EXPORT void +gbm_bo_set_user_data(struct gbm_bo *bo, void *data, + void (*destroy_user_data)(struct gbm_bo *, void *)) +{ + bo->user_data = data; + bo->destroy_user_data = destroy_user_data; +} + +/** Get the user data associated with a buffer object + * + * \param bo The buffer object + * \return Returns the user data associated with the buffer object or %NULL + * if no data was associated with it + * + * \sa gbm_bo_set_user_data() + */ +GBM_EXPORT void * +gbm_bo_get_user_data(struct gbm_bo *bo) +{ + return bo->user_data; +} + /** * Destroys the given buffer object and frees all resources associated with * it. @@ -240,6 +299,9 @@ gbm_bo_get_handle(struct gbm_bo *bo) GBM_EXPORT void gbm_bo_destroy(struct gbm_bo *bo) { + if (bo->destroy_user_data) + bo->destroy_user_data(bo, bo->user_data); + bo->gbm->bo_destroy(bo); } @@ -357,10 +419,11 @@ gbm_surface_destroy(struct gbm_surface *surf) * * \param surf The surface * - * \return A newly allocated buffer object that should be released - * with gbm_surface_release_buffer() when no longer needed. This bo - * should not be destroyed using gbm_bo_destroy(). If an error occurs - * this function returns %NULL. + * \return A buffer object that should be released with + * gbm_surface_release_buffer() when no longer needed. The implementation + * is free to reuse buffers released with gbm_surface_release_buffer() so + * this bo should not be destroyed using gbm_bo_destroy(). If an error + * occurs this function returns %NULL. */ GBM_EXPORT struct gbm_bo * gbm_surface_lock_front_buffer(struct gbm_surface *surf) @@ -371,10 +434,11 @@ gbm_surface_lock_front_buffer(struct gbm_surface *surf) /** * Release a locked buffer obtained with gbm_surface_lock_front_buffer() * - * The bo is destroyed after a call to this function and returns the - * underlying buffer to the gbm surface. Releasing a bo will - * typically make gbm_surface_has_free_buffer() return 1 and thus - * allow rendering the next frame, but not always. + * Returns the underlying buffer to the gbm surface. Releasing a bo + * will typically make gbm_surface_has_free_buffer() return 1 and thus + * allow rendering the next frame, but not always. The implementation + * may choose to destroy the bo immediately or reuse it, in which case + * the user data associated with it is unchanged. * * \param surf The surface * \param bo The buffer object diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h index 6748752d8f1..af5dc5aee8c 100644 --- a/src/gbm/main/gbm.h +++ b/src/gbm/main/gbm.h @@ -201,6 +201,12 @@ enum gbm_bo_flags { * as the storage for a color buffer */ GBM_BO_USE_RENDERING = (1 << 2), + /** + * Buffer can be used for gbm_bo_write. This is guaranteed to work + * with GBM_BO_USE_CURSOR_64X64. but may not work for other + * combinations. + */ + GBM_BO_USE_WRITE = (1 << 3), }; int @@ -242,9 +248,22 @@ gbm_bo_get_pitch(struct gbm_bo *bo); uint32_t gbm_bo_get_format(struct gbm_bo *bo); +struct gbm_device * +gbm_bo_get_device(struct gbm_bo *bo); + union gbm_bo_handle gbm_bo_get_handle(struct gbm_bo *bo); +int +gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count); + +void +gbm_bo_set_user_data(struct gbm_bo *bo, void *data, + void (*destroy_user_data)(struct gbm_bo *, void *)); + +void * +gbm_bo_get_user_data(struct gbm_bo *bo); + void gbm_bo_destroy(struct gbm_bo *bo); diff --git a/src/gbm/main/gbmint.h b/src/gbm/main/gbmint.h index 53d73f40df6..8eb8671aeb2 100644 --- a/src/gbm/main/gbmint.h +++ b/src/gbm/main/gbmint.h @@ -70,6 +70,7 @@ struct gbm_device { void *egl_dpy, void *egl_img, uint32_t width, uint32_t height, uint32_t usage); + int (*bo_write)(struct gbm_bo *bo, const void *buf, size_t data); void (*bo_destroy)(struct gbm_bo *bo); struct gbm_surface *(*surface_create)(struct gbm_device *gbm, @@ -94,6 +95,8 @@ struct gbm_bo { uint32_t pitch; uint32_t format; union gbm_bo_handle handle; + void *user_data; + void (*destroy_user_data)(struct gbm_bo *, void *); }; struct gbm_surface { |