From 41ea44debf8802bfb47e1082062d27ee612ca878 Mon Sep 17 00:00:00 2001 From: Sangjin Lee Date: Sat, 10 Dec 2016 16:24:16 +0900 Subject: [PATCH] ecore-buffer: support NV12 format To support the NV12 format ecore_buffer, change ecore_buffer backend interface and change destory protocol Change-Id: I7125a4b689b914fe06f3e7e3913f49ceef3910c0 --- src/lib/ecore_buffer/Ecore_Buffer.h | 58 +++++- src/lib/ecore_buffer/bq_mgr_protocol.c | 18 +- src/lib/ecore_buffer/bq_mgr_protocol.h | 68 ++++++- src/lib/ecore_buffer/ecore_buffer.c | 57 ++++-- src/lib/ecore_buffer/ecore_buffer_consumer.c | 66 +++++-- src/lib/ecore_buffer/ecore_buffer_private.h | 3 +- src/lib/ecore_buffer/ecore_buffer_provider.c | 52 +++++- src/modules/ecore_buffer/tbm/ecore_buffer_tbm.c | 74 ++++++-- .../ecore_buffer/x11_dri2/ecore_buffer_x11_dri2.c | 195 ++++++++++++++------- .../ecore_buffer/x11_dri3/ecore_buffer_x11_dri3.c | 79 ++++++--- 10 files changed, 505 insertions(+), 165 deletions(-) diff --git a/src/lib/ecore_buffer/Ecore_Buffer.h b/src/lib/ecore_buffer/Ecore_Buffer.h index eff8a5d..508f467 100644 --- a/src/lib/ecore_buffer/Ecore_Buffer.h +++ b/src/lib/ecore_buffer/Ecore_Buffer.h @@ -422,12 +422,60 @@ typedef void (*Ecore_Buffer_Cb)(Ecore_Buffer* buf, void* data); * Types for export buffer. * @since 1.15 */ -typedef enum _Ecore_Export_Type +enum _Ecore_Export_Type { EXPORT_TYPE_INVALID, EXPORT_TYPE_ID, EXPORT_TYPE_FD -} Ecore_Export_Type; +}; + +/** + * @typedef Ecore_Buffer_Plane + * Types for plane information. + * @since 1.15 + */ +typedef struct _Ecore_Buffer_Plane Ecore_Buffer_Plane; + +/** + * @typedef Ecore_Buffer_Info + * Types for buffer information. + * @since 1.15 + */ +typedef struct _Ecore_Buffer_Info Ecore_Buffer_Info; + +/** + * @brief Definition for the maximum number of Ecore_Buffer's plane. + * @since 1.15 + */ +#define ECORE_BUFFER_PLANE_MAX 4 + +/** + * @brief Definition for the Ecore_Buffer plane struct. + * @since 1.15 + */ +struct _Ecore_Buffer_Plane +{ + int size; + int offset; + int stride; +}; + +/** + * @brief Definition for the Ecore_Buffer information struct. + * @since 1.15 + */ +struct _Ecore_Buffer_Info +{ + int width; + int height; + int bpp; + int size; + Ecore_Buffer_Format format; + + int num_planes; + Ecore_Buffer_Plane planes[ECORE_BUFFER_PLANE_MAX]; + Ecore_Pixmap pixmap; +}; /** * @struct _Ecore_Buffer_Backend @@ -450,13 +498,15 @@ struct _Ecore_Buffer_Backend int *ret_w, int *ret_h, Ecore_Buffer_Format *ret_format, unsigned int flags); /**< Create Ecore_Buffer from existed tbm_surface handle. */ + Eina_Bool (*buffer_info_get)(Ecore_Buffer_Module_Data bmdata, + Ecore_Buffer_Data bdata, + Ecore_Buffer_Info *info); void (*buffer_free)(Ecore_Buffer_Module_Data bmdata, Ecore_Buffer_Data bdata); /**< Free allocated memory */ Ecore_Export_Type (*buffer_export)(Ecore_Buffer_Module_Data bmdata, Ecore_Buffer_Data bdata, int *id); /**< Get the id or fd of Ecore_Buffer for exporting it */ Ecore_Buffer_Data (*buffer_import)(Ecore_Buffer_Module_Data bmdata, - int w, int h, - Ecore_Buffer_Format format, + Ecore_Buffer_Info *info, Ecore_Export_Type type, int export_id, unsigned int flags); /**< Import and create Ecore_Buffer from id or fd */ diff --git a/src/lib/ecore_buffer/bq_mgr_protocol.c b/src/lib/ecore_buffer/bq_mgr_protocol.c index fe8b98c..01e4689 100644 --- a/src/lib/ecore_buffer/bq_mgr_protocol.c +++ b/src/lib/ecore_buffer/bq_mgr_protocol.c @@ -85,6 +85,7 @@ WL_EXPORT const struct wl_interface bq_mgr_interface = { static const struct wl_message bq_consumer_requests[] = { { "release_buffer", "o", types + 10 }, + { "destroy", "2", types + 0 }, }; static const struct wl_message bq_consumer_events[] = { @@ -98,8 +99,8 @@ static const struct wl_message bq_consumer_events[] = { }; WL_EXPORT const struct wl_interface bq_consumer_interface = { - "bq_consumer", 1, - 1, bq_consumer_requests, + "bq_consumer", 2, + 2, bq_consumer_requests, 7, bq_consumer_events, }; @@ -109,6 +110,7 @@ static const struct wl_message bq_provider_requests[] = { { "set_buffer_fd", "ohiiiiii", types + 50 }, { "detach_buffer", "o", types + 58 }, { "enqueue_buffer", "ou", types + 59 }, + { "destroy", "2", types + 0 }, }; static const struct wl_message bq_provider_events[] = { @@ -118,14 +120,18 @@ static const struct wl_message bq_provider_events[] = { }; WL_EXPORT const struct wl_interface bq_provider_interface = { - "bq_provider", 1, - 5, bq_provider_requests, + "bq_provider", 2, + 6, bq_provider_requests, 3, bq_provider_events, }; +static const struct wl_message bq_buffer_requests[] = { + { "destroy", "2", types + 0 }, +}; + WL_EXPORT const struct wl_interface bq_buffer_interface = { - "bq_buffer", 1, - 0, NULL, + "bq_buffer", 2, + 1, bq_buffer_requests, 0, NULL, }; diff --git a/src/lib/ecore_buffer/bq_mgr_protocol.h b/src/lib/ecore_buffer/bq_mgr_protocol.h index 7cf9ad9..df1f545 100644 --- a/src/lib/ecore_buffer/bq_mgr_protocol.h +++ b/src/lib/ecore_buffer/bq_mgr_protocol.h @@ -12,10 +12,10 @@ extern "C" { struct wl_client; struct wl_resource; -struct bq_mgr; +struct bq_buffer; struct bq_consumer; +struct bq_mgr; struct bq_provider; -struct bq_buffer; extern const struct wl_interface bq_mgr_interface; extern const struct wl_interface bq_consumer_interface; @@ -34,6 +34,9 @@ enum bq_mgr_error { #define BQ_MGR_CREATE_CONSUMER 0 #define BQ_MGR_CREATE_PROVIDER 1 +#define BQ_MGR_CREATE_CONSUMER_SINCE_VERSION 1 +#define BQ_MGR_CREATE_PROVIDER_SINCE_VERSION 1 + static inline void bq_mgr_set_user_data(struct bq_mgr *bq_mgr, void *user_data) { @@ -46,6 +49,12 @@ bq_mgr_get_user_data(struct bq_mgr *bq_mgr) return wl_proxy_get_user_data((struct wl_proxy *) bq_mgr); } +static inline uint32_t +bq_mgr_get_version(struct bq_mgr *bq_mgr) +{ + return wl_proxy_get_version((struct wl_proxy *) bq_mgr); +} + static inline void bq_mgr_destroy(struct bq_mgr *bq_mgr) { @@ -171,6 +180,10 @@ bq_consumer_add_listener(struct bq_consumer *bq_consumer, } #define BQ_CONSUMER_RELEASE_BUFFER 0 +#define BQ_CONSUMER_DESTROY 1 + +#define BQ_CONSUMER_RELEASE_BUFFER_SINCE_VERSION 1 +#define BQ_CONSUMER_DESTROY_SINCE_VERSION 2 static inline void bq_consumer_set_user_data(struct bq_consumer *bq_consumer, void *user_data) @@ -184,10 +197,10 @@ bq_consumer_get_user_data(struct bq_consumer *bq_consumer) return wl_proxy_get_user_data((struct wl_proxy *) bq_consumer); } -static inline void -bq_consumer_destroy(struct bq_consumer *bq_consumer) +static inline uint32_t +bq_consumer_get_version(struct bq_consumer *bq_consumer) { - wl_proxy_destroy((struct wl_proxy *) bq_consumer); + return wl_proxy_get_version((struct wl_proxy *) bq_consumer); } static inline void @@ -197,6 +210,15 @@ bq_consumer_release_buffer(struct bq_consumer *bq_consumer, struct bq_buffer *bu BQ_CONSUMER_RELEASE_BUFFER, buffer); } +static inline void +bq_consumer_destroy(struct bq_consumer *bq_consumer) +{ + wl_proxy_marshal((struct wl_proxy *) bq_consumer, + BQ_CONSUMER_DESTROY); + + wl_proxy_destroy((struct wl_proxy *) bq_consumer); +} + #ifndef BQ_PROVIDER_ERROR_ENUM #define BQ_PROVIDER_ERROR_ENUM enum bq_provider_error { @@ -246,6 +268,14 @@ bq_provider_add_listener(struct bq_provider *bq_provider, #define BQ_PROVIDER_SET_BUFFER_FD 2 #define BQ_PROVIDER_DETACH_BUFFER 3 #define BQ_PROVIDER_ENQUEUE_BUFFER 4 +#define BQ_PROVIDER_DESTROY 5 + +#define BQ_PROVIDER_ATTACH_BUFFER_SINCE_VERSION 1 +#define BQ_PROVIDER_SET_BUFFER_ID_SINCE_VERSION 1 +#define BQ_PROVIDER_SET_BUFFER_FD_SINCE_VERSION 1 +#define BQ_PROVIDER_DETACH_BUFFER_SINCE_VERSION 1 +#define BQ_PROVIDER_ENQUEUE_BUFFER_SINCE_VERSION 1 +#define BQ_PROVIDER_DESTROY_SINCE_VERSION 2 static inline void bq_provider_set_user_data(struct bq_provider *bq_provider, void *user_data) @@ -259,10 +289,10 @@ bq_provider_get_user_data(struct bq_provider *bq_provider) return wl_proxy_get_user_data((struct wl_proxy *) bq_provider); } -static inline void -bq_provider_destroy(struct bq_provider *bq_provider) +static inline uint32_t +bq_provider_get_version(struct bq_provider *bq_provider) { - wl_proxy_destroy((struct wl_proxy *) bq_provider); + return wl_proxy_get_version((struct wl_proxy *) bq_provider); } static inline struct bq_buffer * @@ -305,6 +335,19 @@ bq_provider_enqueue_buffer(struct bq_provider *bq_provider, struct bq_buffer *bu } static inline void +bq_provider_destroy(struct bq_provider *bq_provider) +{ + wl_proxy_marshal((struct wl_proxy *) bq_provider, + BQ_PROVIDER_DESTROY); + + wl_proxy_destroy((struct wl_proxy *) bq_provider); +} + +#define BQ_BUFFER_DESTROY 0 + +#define BQ_BUFFER_DESTROY_SINCE_VERSION 2 + +static inline void bq_buffer_set_user_data(struct bq_buffer *bq_buffer, void *user_data) { wl_proxy_set_user_data((struct wl_proxy *) bq_buffer, user_data); @@ -316,9 +359,18 @@ bq_buffer_get_user_data(struct bq_buffer *bq_buffer) return wl_proxy_get_user_data((struct wl_proxy *) bq_buffer); } +static inline uint32_t +bq_buffer_get_version(struct bq_buffer *bq_buffer) +{ + return wl_proxy_get_version((struct wl_proxy *) bq_buffer); +} + static inline void bq_buffer_destroy(struct bq_buffer *bq_buffer) { + wl_proxy_marshal((struct wl_proxy *) bq_buffer, + BQ_BUFFER_DESTROY); + wl_proxy_destroy((struct wl_proxy *) bq_buffer); } diff --git a/src/lib/ecore_buffer/ecore_buffer.c b/src/lib/ecore_buffer/ecore_buffer.c index b286aa8..cad5adc 100644 --- a/src/lib/ecore_buffer/ecore_buffer.c +++ b/src/lib/ecore_buffer/ecore_buffer.c @@ -23,11 +23,9 @@ struct _Ecore_Buffer_Module struct _Ecore_Buffer { - unsigned int width; - unsigned int height; - int format; unsigned int flags; + Ecore_Buffer_Info info; Ecore_Buffer_Data buffer_data; Ecore_Buffer_Module *bm; @@ -90,7 +88,8 @@ _ecore_buffer_get_backend(const char *name) if ((!bm) || (!bm->be) || (!bm->be->init)) return NULL; - bm->data = bm->be->init(NULL, NULL); + if (!bm->data) + bm->data = bm->be->init(NULL, NULL); return bm; } @@ -266,10 +265,16 @@ ecore_buffer_new(const char *engine, unsigned int width, unsigned int height, Ec return NULL; } + if (bm->be->buffer_info_get) + bm->be->buffer_info_get(bm->data, bo_data, &bo->info); + else + { + bo->info.width = width; + bo->info.height = height; + bo->info.format = format; + } + bo->bm = bm; - bo->width = width; - bo->height = height; - bo->format = format; bo->flags = flags; bo->buffer_data = bo_data; @@ -314,12 +319,18 @@ ecore_buffer_new_with_tbm_surface(const char *engine, void *tbm_surface, unsigne return NULL; } + if (bm->be->buffer_info_get) + bm->be->buffer_info_get(bm->data, bo_data, &bo->info); + else + { + bo->info.width = w; + bo->info.height = h; + bo->info.format = format; + } + bo->bm = bm; bo->flags = flags; bo->buffer_data = bo_data; - bo->width = w; - bo->height = h; - bo->format = format; return bo; } @@ -388,8 +399,8 @@ ecore_buffer_size_get(Ecore_Buffer *buf, unsigned int *width, unsigned int *heig { EINA_SAFETY_ON_NULL_RETURN_VAL(buf, EINA_FALSE); - if (width) *width = buf->width; - if (height) *height = buf->height; + if (width) *width = buf->info.width; + if (height) *height = buf->info.height; return EINA_TRUE; } @@ -399,7 +410,7 @@ ecore_buffer_format_get(Ecore_Buffer *buf) { EINA_SAFETY_ON_NULL_RETURN_VAL(buf, 0); - return buf->format; + return buf->info.format; } EAPI unsigned int @@ -482,7 +493,7 @@ _ecore_buffer_export(Ecore_Buffer *buf, int *id) } Ecore_Buffer * -_ecore_buffer_import(const char *engine, int width, int height, Ecore_Buffer_Format format, Ecore_Export_Type type, int export_id, unsigned int flags) +_ecore_buffer_import(const char *engine, Ecore_Buffer_Info *info, Ecore_Export_Type type, int export_id, unsigned int flags) { Ecore_Buffer_Module *bm; Ecore_Buffer *bo; @@ -507,19 +518,29 @@ _ecore_buffer_import(const char *engine, int width, int height, Ecore_Buffer_For if (!bo) return NULL; - bo_data = bm->be->buffer_import(bm->data, width, height, format, type, export_id, flags); + bo_data = bm->be->buffer_import(bm->data, info, type, export_id, flags); if (!bo_data) { free(bo); return NULL; } + memcpy(&bo->info, info, sizeof(*info)); + bo->bm = bm; - bo->width = width; - bo->height = height; - bo->format = format; bo->flags = flags; bo->buffer_data = bo_data; return bo; } + +Eina_Bool +_ecore_buffer_info_get(Ecore_Buffer *buf, Ecore_Buffer_Info *info) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(buf, EINA_FALSE); + + if (info) + memcpy(info, &buf->info, sizeof(*info)); + + return EINA_TRUE; +} diff --git a/src/lib/ecore_buffer/ecore_buffer_consumer.c b/src/lib/ecore_buffer/ecore_buffer_consumer.c index 59a4a04..299b21b 100644 --- a/src/lib/ecore_buffer/ecore_buffer_consumer.c +++ b/src/lib/ecore_buffer/ecore_buffer_consumer.c @@ -28,11 +28,12 @@ static void _ecore_buffer_consumer_cb_provider_connected(void *data, struct bq_c static void _ecore_buffer_consumer_cb_provider_disconnected(void *data, struct bq_consumer *bq_consumer); static void _ecore_buffer_consumer_cb_buffer_attached(void *data, struct bq_consumer *bq_consumer, struct bq_buffer *id, const char *engine, int32_t width, int32_t height, int32_t format, uint32_t flags); static void _ecore_buffer_consumer_cb_buffer_id_set(void *data, struct bq_consumer *bq_consumer, struct bq_buffer *buffer, int32_t id, int32_t offset0, int32_t stride0, int32_t offset1, int32_t stride1, int32_t offset2, int32_t stride2); +static void _ecore_buffer_consumer_cb_buffer_pixmap_id_set(void *data, struct bq_consumer *bq_consumer, struct bq_buffer *buffer, int32_t id, int32_t offset0, int32_t stride0, int32_t offset1, int32_t stride1, int32_t offset2, int32_t stride2); static void _ecore_buffer_consumer_cb_buffer_fd_set(void *data, struct bq_consumer *bq_consumer, struct bq_buffer *buffer, int32_t fd, int32_t offset0, int32_t stride0, int32_t offset1, int32_t stride1, int32_t offset2, int32_t stride2); static void _ecore_buffer_consumer_cb_buffer_detached(void *data, struct bq_consumer *bq_consumer, struct bq_buffer *id); static void _ecore_buffer_consumer_cb_add_buffer(void *data, struct bq_consumer *bq_consumer, struct bq_buffer *buffer, uint32_t serial); static void _ecore_buffer_consumer_cb_buffer_free(Ecore_Buffer *buf, void *data); -static Eina_Bool _ecore_buffer_consumer_buffer_import(Ecore_Buffer_Consumer *consumer, Shared_Buffer *sb, int32_t seed, Ecore_Export_Type export_type); +static Eina_Bool _ecore_buffer_consumer_buffer_import(Ecore_Buffer_Consumer *consumer, Shared_Buffer *sb, int32_t seed, Ecore_Export_Type export_type, Ecore_Buffer_Info *info); struct bq_consumer_listener _ecore_buffer_consumer_listener = { @@ -64,7 +65,7 @@ ecore_buffer_consumer_new(const char *name, int32_t queue_size, int32_t w, int32 _ecore_buffer_con_init_wait(); - consumer = calloc(1, sizeof(Ecore_Buffer_Consumer)); + consumer = calloc(sizeof(Ecore_Buffer_Consumer), 1); if (!consumer) return NULL; @@ -90,6 +91,24 @@ ecore_buffer_consumer_new(const char *name, int32_t queue_size, int32_t w, int32 return consumer; } +static void +_consumer_shared_buffer_free(Ecore_Buffer_Consumer *consumer) +{ + Eina_List *clone, *shared_buffers, *l; + Shared_Buffer *sb; + + if (!consumer->ebq) + return; + + shared_buffers = _ecore_buffer_queue_shared_buffer_list_get(consumer->ebq); + clone = eina_list_clone(shared_buffers); + + EINA_LIST_FOREACH(clone, l, sb) + ecore_buffer_free(_shared_buffer_buffer_get(sb)); + + eina_list_free(clone); +} + EAPI void ecore_buffer_consumer_free(Ecore_Buffer_Consumer *consumer) { @@ -97,6 +116,8 @@ ecore_buffer_consumer_free(Ecore_Buffer_Consumer *consumer) DBG("Consumer Free"); + _consumer_shared_buffer_free(consumer); + if (consumer->ebq) _ecore_buffer_queue_free(consumer->ebq); @@ -232,8 +253,6 @@ static void _ecore_buffer_consumer_cb_provider_disconnected(void *data, struct bq_consumer *bq_consumer EINA_UNUSED) { Ecore_Buffer_Consumer *consumer = data; - Eina_List *clone, *shared_buffers, *l; - Shared_Buffer *sb; EINA_SAFETY_ON_NULL_RETURN(consumer); @@ -243,13 +262,7 @@ _ecore_buffer_consumer_cb_provider_disconnected(void *data, struct bq_consumer * CALLBACK_CALL(consumer, provider_del); - shared_buffers = _ecore_buffer_queue_shared_buffer_list_get(consumer->ebq); - clone = eina_list_clone(shared_buffers); - - EINA_LIST_FOREACH(clone, l, sb) - ecore_buffer_free(_shared_buffer_buffer_get(sb)); - - eina_list_free(clone); + _consumer_shared_buffer_free(consumer); } static void @@ -288,35 +301,50 @@ _ecore_buffer_consumer_cb_buffer_free(Ecore_Buffer *buf, void *data) _shared_buffer_free(sb); } +#define INFO_SET(I, PIX) \ + I.planes[0].offset = offset0; \ + I.planes[0].stride = stride0; \ + I.planes[1].offset = offset1; \ + I.planes[1].stride = stride1; \ + I.planes[2].offset = offset2; \ + I.planes[2].stride = stride2; \ + I.pixmap = PIX static void -_ecore_buffer_consumer_cb_buffer_id_set(void *data, struct bq_consumer *bq_consumer EINA_UNUSED, struct bq_buffer *buffer, int32_t id, int32_t offset0 EINA_UNUSED, int32_t stride0 EINA_UNUSED, int32_t offset1 EINA_UNUSED, int32_t stride1 EINA_UNUSED, int32_t offset2 EINA_UNUSED, int32_t stride2 EINA_UNUSED) +_ecore_buffer_consumer_cb_buffer_id_set(void *data, struct bq_consumer *bq_consumer EINA_UNUSED, struct bq_buffer *buffer, int32_t id, int32_t offset0, int32_t stride0, int32_t offset1, int32_t stride1, int32_t offset2, int32_t stride2) { Ecore_Buffer_Consumer *consumer = data; Shared_Buffer *sb = bq_buffer_get_user_data(buffer); + Ecore_Buffer_Info info; EINA_SAFETY_ON_NULL_RETURN(consumer); EINA_SAFETY_ON_NULL_RETURN(sb); - if (_ecore_buffer_consumer_buffer_import(consumer, sb, id, EXPORT_TYPE_ID)) + INFO_SET(info, 0); + + if (_ecore_buffer_consumer_buffer_import(consumer, sb, id, EXPORT_TYPE_ID, &info)) bq_buffer_set_user_data(buffer, sb); else ERR("Failed to import buffer - buffer resource %p", buffer); } static void -_ecore_buffer_consumer_cb_buffer_fd_set(void *data, struct bq_consumer *bq_consumer EINA_UNUSED, struct bq_buffer *buffer, int32_t fd, int32_t offset0 EINA_UNUSED, int32_t stride0 EINA_UNUSED, int32_t offset1 EINA_UNUSED, int32_t stride1 EINA_UNUSED, int32_t offset2 EINA_UNUSED, int32_t stride2 EINA_UNUSED) +_ecore_buffer_consumer_cb_buffer_fd_set(void *data, struct bq_consumer *bq_consumer EINA_UNUSED, struct bq_buffer *buffer, int32_t fd, int32_t offset0, int32_t stride0, int32_t offset1, int32_t stride1, int32_t offset2, int32_t stride2) { Ecore_Buffer_Consumer *consumer = data; Shared_Buffer *sb = bq_buffer_get_user_data(buffer); + Ecore_Buffer_Info info; EINA_SAFETY_ON_NULL_RETURN(consumer); EINA_SAFETY_ON_NULL_RETURN(sb); - if (_ecore_buffer_consumer_buffer_import(consumer, sb, fd, EXPORT_TYPE_FD)) + INFO_SET(info, 0); + + if (_ecore_buffer_consumer_buffer_import(consumer, sb, fd, EXPORT_TYPE_FD, &info)) bq_buffer_set_user_data(buffer, sb); else ERR("Failed to import buffer - buffer resource %p", buffer); } +#undef INFO_SET static void _ecore_buffer_consumer_cb_buffer_detached(void *data, struct bq_consumer *bq_consumer EINA_UNUSED, struct bq_buffer *id) @@ -377,7 +405,7 @@ _ecore_buffer_consumer_cb_add_buffer(void *data, struct bq_consumer *bq_consumer } static Eina_Bool -_ecore_buffer_consumer_buffer_import(Ecore_Buffer_Consumer *consumer, Shared_Buffer *sb, int32_t seed, Ecore_Export_Type export_type) +_ecore_buffer_consumer_buffer_import(Ecore_Buffer_Consumer *consumer, Shared_Buffer *sb, int32_t seed, Ecore_Export_Type export_type, Ecore_Buffer_Info *info) { Ecore_Buffer *buffer; const char *engine = NULL; @@ -398,7 +426,11 @@ _ecore_buffer_consumer_buffer_import(Ecore_Buffer_Consumer *consumer, Shared_Buf return EINA_FALSE; } - if (!(buffer = _ecore_buffer_import(engine, w, h, format, export_type, seed, flags))) + info->width = w; + info->height = h; + info->format = format; + + if (!(buffer = _ecore_buffer_import(engine, info, export_type, seed, flags))) { ERR("Failed to Import Buffer - size (%dx%d), foramt %d, seed %d, export_type %d", w, h, format, seed, export_type); diff --git a/src/lib/ecore_buffer/ecore_buffer_private.h b/src/lib/ecore_buffer/ecore_buffer_private.h index 4e33772..d00d85e 100644 --- a/src/lib/ecore_buffer/ecore_buffer_private.h +++ b/src/lib/ecore_buffer/ecore_buffer_private.h @@ -27,5 +27,6 @@ const char *_ecore_buffer_engine_name_get(Ecore_Buffer *buf); /* NOTE: if Ecore_Export_Type as a return value is EXPORT_TYPE_FD, * then caller should close the fd after using it. */ Ecore_Export_Type _ecore_buffer_export(Ecore_Buffer *buf, int *id); -Ecore_Buffer *_ecore_buffer_import(const char *engine, int width, int height, Ecore_Buffer_Format format, Ecore_Export_Type type, int export_id, unsigned int flags); +Ecore_Buffer *_ecore_buffer_import(const char *engine, Ecore_Buffer_Info *info, Ecore_Export_Type type, int export_id, unsigned int flags); +Eina_Bool _ecore_buffer_info_get(Ecore_Buffer *buf, Ecore_Buffer_Info *info); #endif /* _ECORE_BUFFER_PRIVATE_H_ */ diff --git a/src/lib/ecore_buffer/ecore_buffer_provider.c b/src/lib/ecore_buffer/ecore_buffer_provider.c index 53380fa..93d6e3c 100644 --- a/src/lib/ecore_buffer/ecore_buffer_provider.c +++ b/src/lib/ecore_buffer/ecore_buffer_provider.c @@ -311,12 +311,16 @@ static Shared_Buffer * _ecore_buffer_provider_shared_buffer_new(Ecore_Buffer_Provider *provider, Ecore_Buffer *buffer) { Shared_Buffer *sb; + Ecore_Export_Type export_type; + Ecore_Buffer_Info info; + Eina_Bool res; struct bq_buffer *buf_resource; unsigned int w = 0, h = 0, format = 0; - Ecore_Export_Type export_type; int export_id; const char *engine; unsigned int flags; + int offset[3] = {0,}, stride[3] = {0,}; + int i; EINA_SAFETY_ON_NULL_RETURN_VAL(provider, NULL); @@ -328,12 +332,30 @@ _ecore_buffer_provider_shared_buffer_new(Ecore_Buffer_Provider *provider, Ecore_ return NULL; } - ecore_buffer_size_get(buffer, &w, &h); - format = ecore_buffer_format_get(buffer); - export_type = _ecore_buffer_export(buffer, &export_id); engine = _ecore_buffer_engine_name_get(buffer); flags = ecore_buffer_flags_get(buffer); + res = _ecore_buffer_info_get(buffer, &info); + if (res) + { + int count; + w = info.width; + h = info.height; + format = info.format; + /* FIXME info.num_planes may be 4 */ + count = info.num_planes < 4 ? info.num_planes : 3; + for (i = 0; i < count; i++) + { + offset[i] = info.planes[i].offset; + stride[i] = info.planes[i].stride; + } + } + else + { + ecore_buffer_size_get(buffer, &w, &h); + format = ecore_buffer_format_get(buffer); + } + buf_resource = bq_provider_attach_buffer(provider->resource, engine, w, h, format, flags); if (!buf_resource) { @@ -342,15 +364,24 @@ _ecore_buffer_provider_shared_buffer_new(Ecore_Buffer_Provider *provider, Ecore_ return NULL; } + export_type = _ecore_buffer_export(buffer, &export_id); switch (export_type) { case EXPORT_TYPE_ID: - bq_provider_set_buffer_id(provider->resource, buf_resource, - export_id, 0, 0, 0, 0, 0, 0); + bq_provider_set_buffer_id(provider->resource, + buf_resource, + export_id, + offset[0], stride[0], + offset[1], stride[1], + offset[2], stride[2]); break; case EXPORT_TYPE_FD: - bq_provider_set_buffer_fd(provider->resource, buf_resource, - export_id, 0, 0, 0, 0, 0, 0); + bq_provider_set_buffer_fd(provider->resource, + buf_resource, + export_id, + offset[0], stride[0], + offset[1], stride[1], + offset[2], stride[2]); close(export_id); break; default: @@ -370,11 +401,14 @@ _ecore_buffer_provider_shared_buffer_new(Ecore_Buffer_Provider *provider, Ecore_ static void _ecore_buffer_provider_shared_buffer_free(Ecore_Buffer_Provider *provider, Shared_Buffer *sb) { - struct bq_buffer *buf_resource; + struct bq_buffer *buf_resource = _shared_buffer_resource_get(sb); EINA_SAFETY_ON_NULL_RETURN(provider); EINA_SAFETY_ON_NULL_RETURN(sb); + if (!provider->ebq) + return; + buf_resource = _shared_buffer_resource_get(sb); if (!buf_resource) return; diff --git a/src/modules/ecore_buffer/tbm/ecore_buffer_tbm.c b/src/modules/ecore_buffer/tbm/ecore_buffer_tbm.c index a7cb06f..7cd39ba 100644 --- a/src/modules/ecore_buffer/tbm/ecore_buffer_tbm.c +++ b/src/modules/ecore_buffer/tbm/ecore_buffer_tbm.c @@ -282,6 +282,41 @@ _ecore_buffer_tbm_buffer_alloc_with_tbm_surface(Ecore_Buffer_Module_Data bmdata return buf; } +static Eina_Bool +_ecore_buffer_tbm_buffer_info_get(Ecore_Buffer_Module_Data bmdata EINA_UNUSED, Ecore_Buffer_Data bdata, Ecore_Buffer_Info *info) +{ + Ecore_Buffer_Tbm_Data *buf = bdata; + tbm_surface_info_s tinfo; + int i, res; + + if (!buf->tbm_surface) + return EINA_FALSE; + + res = tbm_surface_get_info(buf->tbm_surface, &tinfo); + if (res != TBM_SURFACE_ERROR_NONE) + return EINA_FALSE; + + if (info) + { + info->width = tinfo.width; + info->height = tinfo.height; + info->format = tinfo.format; + info->bpp = tinfo.bpp; + info->size = tinfo.size; + info->num_planes = tinfo.num_planes; + info->pixmap = 0; + + for (i = 0; i < (int)tinfo.num_planes; i++) + { + info->planes[i].size = tinfo.planes[i].size; + info->planes[i].offset = tinfo.planes[i].offset; + info->planes[i].stride = tinfo.planes[i].stride; + } + } + + return EINA_TRUE; +} + static void _ecore_buffer_tbm_buffer_free(Ecore_Buffer_Module_Data bmdata EINA_UNUSED, Ecore_Buffer_Data bdata) { @@ -306,7 +341,7 @@ _ecore_buffer_tbm_buffer_export(Ecore_Buffer_Module_Data bmdata EINA_UNUSED, Eco if (!buf) return EXPORT_TYPE_INVALID; - if (_buf_get_num_planes(buf->format) != 1) + if (tbm_surface_internal_get_num_bos(buf->tbm_surface) != 1) return EXPORT_TYPE_INVALID; bo = tbm_surface_internal_get_bo(buf->tbm_surface, 0); @@ -317,13 +352,13 @@ _ecore_buffer_tbm_buffer_export(Ecore_Buffer_Module_Data bmdata EINA_UNUSED, Eco } static Ecore_Buffer_Data -_ecore_buffer_tbm_buffer_import(Ecore_Buffer_Module_Data bmdata, int w, int h, Ecore_Buffer_Format format, Ecore_Export_Type type, int export_id, unsigned int flags) +_ecore_buffer_tbm_buffer_import(Ecore_Buffer_Module_Data bmdata, Ecore_Buffer_Info *einfo, Ecore_Export_Type type, int export_id, unsigned int flags) { Ecore_Buffer_Module_Tbm_Data *bm = bmdata; Ecore_Buffer_Tbm_Data *buf; tbm_bo bo; - tbm_surface_info_s info; - int i, num_plane; + tbm_surface_info_s tinfo; + int i; if (type != EXPORT_TYPE_FD) return NULL; if (export_id < 1) return NULL; @@ -332,9 +367,10 @@ _ecore_buffer_tbm_buffer_import(Ecore_Buffer_Module_Data bmdata, int w, int h, E if (!buf) return NULL; - buf->w = w; - buf->h = h; - buf->format = format; + buf->w = einfo->width; + buf->h = einfo->height; + buf->stride = einfo->planes[0].stride; + buf->format = einfo->format; buf->flags = flags; buf->is_imported = EINA_TRUE; @@ -345,21 +381,20 @@ _ecore_buffer_tbm_buffer_import(Ecore_Buffer_Module_Data bmdata, int w, int h, E return NULL; } - num_plane = _buf_get_num_planes(format); - info.width = w; - info.height = h; - info.format = format; - info.bpp = _buf_get_bpp(format); - info.size = w * h * info.bpp; - info.num_planes = num_plane; - for ( i = 0 ; i < num_plane ; i++) + tinfo.width = einfo->width; + tinfo.height = einfo->height; + tinfo.format = einfo->format; + tinfo.bpp = _buf_get_bpp(einfo->format); + tinfo.size = einfo->height * einfo->planes[0].stride; + tinfo.num_planes = (uint32_t)_buf_get_num_planes(einfo->format); + for ( i = 0 ; i < (int)tinfo.num_planes ; i++) { - info.planes[i].size = w * h * info.bpp; - info.planes[i].stride = w * info.bpp; - info.planes[i].offset = 0; + tinfo.planes[i].size = einfo->height * einfo->planes[i].stride; + tinfo.planes[i].stride = einfo->planes[i].stride; + tinfo.planes[i].offset = einfo->planes[i].offset; } - buf->tbm_surface = tbm_surface_internal_create_with_bos(&info, &bo, 1); + buf->tbm_surface = tbm_surface_internal_create_with_bos(&tinfo, &bo, 1); if (!buf->tbm_surface) { tbm_bo_unref(bo); @@ -388,6 +423,7 @@ static Ecore_Buffer_Backend _ecore_buffer_tbm_backend = { &_ecore_buffer_tbm_shutdown, &_ecore_buffer_tbm_buffer_alloc, &_ecore_buffer_tbm_buffer_alloc_with_tbm_surface, + &_ecore_buffer_tbm_buffer_info_get, &_ecore_buffer_tbm_buffer_free, &_ecore_buffer_tbm_buffer_export, &_ecore_buffer_tbm_buffer_import, diff --git a/src/modules/ecore_buffer/x11_dri2/ecore_buffer_x11_dri2.c b/src/modules/ecore_buffer/x11_dri2/ecore_buffer_x11_dri2.c index ae7c92d..1c72c74 100644 --- a/src/modules/ecore_buffer/x11_dri2/ecore_buffer_x11_dri2.c +++ b/src/modules/ecore_buffer/x11_dri2/ecore_buffer_x11_dri2.c @@ -222,8 +222,8 @@ _ecore_buffer_x11_dri2_init(const char *context EINA_UNUSED, const char *options Ecore_X_Window root; int eb, ee; int major, minor; - char *driver_name; - char *device_name; + char *driver_name = NULL; + char *device_name = NULL; int fd = 0; drm_magic_t magic; Ecore_Buffer_Module_X11_Dri2_Data *mdata = NULL; @@ -253,14 +253,14 @@ _ecore_buffer_x11_dri2_init(const char *context EINA_UNUSED, const char *options goto on_error; if (drmGetMagic(fd, &magic) < 0) - goto on_error; + goto on_fd_error; if (!(DRI2Authenticate(xdpy, root, magic))) - goto on_error; + goto on_fd_error; mdata->tbm_mgr = tbm_bufmgr_init(fd); if (!mdata->tbm_mgr) - goto on_error; + goto on_fd_error; free(driver_name); free(device_name); @@ -268,8 +268,10 @@ _ecore_buffer_x11_dri2_init(const char *context EINA_UNUSED, const char *options return mdata; +on_fd_error: + close(fd); + on_error: - if (fd > 0) close(fd); if (driver_name) free(driver_name); if (device_name) free(device_name); if (mdata) free(mdata); @@ -348,11 +350,11 @@ _ecore_buffer_x11_dri2_buffer_alloc(Ecore_Buffer_Module_Data bmdata, int width, info.height = height; info.format = format; info.bpp = bpp; - info.size = width * bufs->pitch; + info.size = height * bufs->pitch; info.num_planes = num_plane; for ( i = 0 ; i < num_plane ; i++) { - info.planes[i].size = width * bufs->pitch; + info.planes[i].size = height * bufs->pitch; info.planes[i].stride = bufs->pitch; info.planes[i].offset = 0; } @@ -382,8 +384,7 @@ _ecore_buffer_x11_dri2_buffer_alloc_with_tbm_surface(Ecore_Buffer_Module_Data bm { Ecore_Buffer_X11_Dri2_Data *buf; - if (!tbm_surface) - return NULL; + EINA_SAFETY_ON_NULL_RETURN_VAL(tbm_surface, NULL); buf = calloc(1, sizeof(Ecore_Buffer_X11_Dri2_Data)); if (!buf) @@ -392,6 +393,7 @@ _ecore_buffer_x11_dri2_buffer_alloc_with_tbm_surface(Ecore_Buffer_Module_Data bm buf->w = tbm_surface_get_width(tbm_surface); buf->h = tbm_surface_get_height(tbm_surface); buf->format = tbm_surface_get_format(tbm_surface); + buf->pixmap = 0; buf->tbm.surface = tbm_surface; buf->tbm.owned = EINA_FALSE; buf->is_imported = EINA_FALSE; @@ -403,6 +405,41 @@ _ecore_buffer_x11_dri2_buffer_alloc_with_tbm_surface(Ecore_Buffer_Module_Data bm return buf; } +static Eina_Bool +_ecore_buffer_x11_dri2_buffer_info_get(Ecore_Buffer_Module_Data bmdata EINA_UNUSED, Ecore_Buffer_Data bdata, Ecore_Buffer_Info *info) +{ + Ecore_Buffer_X11_Dri2_Data *buf = bdata; + tbm_surface_info_s tinfo; + int i, res; + + if (!buf->tbm.surface) + return EINA_FALSE; + + res = tbm_surface_get_info(buf->tbm.surface, &tinfo); + if (res != TBM_SURFACE_ERROR_NONE) + return EINA_FALSE; + + if (info) + { + info->width = tinfo.width; + info->height = tinfo.height; + info->format = tinfo.format; + info->bpp = tinfo.bpp; + info->size = tinfo.size; + info->num_planes = tinfo.num_planes; + info->pixmap = buf->pixmap; + + for (i = 0; i < tinfo.num_planes; i++) + { + info->planes[i].size = tinfo.planes[i].size; + info->planes[i].offset = tinfo.planes[i].offset; + info->planes[i].stride = tinfo.planes[i].stride; + } + } + + return EINA_TRUE; +} + static void _ecore_buffer_x11_dri2_buffer_free(Ecore_Buffer_Module_Data bmdata EINA_UNUSED, Ecore_Buffer_Data bdata) { @@ -428,87 +465,118 @@ static Ecore_Export_Type _ecore_buffer_x11_dri2_buffer_export(Ecore_Buffer_Module_Data bmdata EINA_UNUSED, Ecore_Buffer_Data bdata, int *id) { Ecore_Buffer_X11_Dri2_Data *buf = bdata; + tbm_bo bo; - if (id) *id = buf->pixmap; + if (id) + { + if (buf->pixmap) + *id = buf->pixmap; + else + { + tbm_bo bo; + /* NOTE: constraints - cannot support more than two bos */ + bo = tbm_surface_internal_get_bo(buf->tbm.surface, 0); + *id = (int)(tbm_bo_export(bo)); + } + } return EXPORT_TYPE_ID; } -static void * -_ecore_buffer_x11_dri2_buffer_import(Ecore_Buffer_Module_Data bmdata EINA_UNUSED, int w, int h, Ecore_Buffer_Format format, Ecore_Export_Type type, int export_id, unsigned int flags EINA_UNUSED) +static tbm_bo +_x11_dri2_bo_get_from_pixmap(tbm_bufmgr tbm_mgr, Ecore_Pixmap pixmap, int width, int height) { - Ecore_Buffer_Module_X11_Dri2_Data *bm = bmdata; Ecore_X_Display *xdpy; - Ecore_X_Pixmap pixmap = (Ecore_X_Pixmap)export_id; - Ecore_Buffer_X11_Dri2_Data *buf; - int rw, rh, rx, ry; DRI2Buffer *bufs = NULL; tbm_bo bo = NULL; + int rw, rh, rx, ry; int rcount; unsigned int attachment = DRI2BufferFrontLeft; - tbm_surface_info_s info; - int num_plane,i; - if (type != EXPORT_TYPE_ID) + // Check valid pixmap + ecore_x_pixmap_geometry_get(pixmap, &rx, &ry, &rw, &rh); + if ((rw != width) || (rh != height)) return NULL; xdpy = ecore_x_display_get(); + DRI2CreateDrawable(xdpy, pixmap); + bufs = DRI2GetBuffers(xdpy, pixmap, &rw, &rh, &attachment, 1, &rcount); + if ((!bufs) || (width != rw) || (height != rh)) + goto err; - //Check valid pixmap - ecore_x_pixmap_geometry_get(pixmap, &rx, &ry, &rw, &rh); - if ((rw != w) || (rh != h)) - return NULL; + bo = tbm_bo_import(tbm_mgr, bufs->name); + free(bufs); + if (!bo) + goto err; - buf = calloc(1, sizeof(Ecore_Buffer_X11_Dri2_Data)); - if (!buf) - return NULL; + return bo; +err: + DRI2DestroyDrawable(xdpy, pixmap); + return NULL; +} - buf->w = w; - buf->h = h; - buf->format = format; - buf->pixmap = pixmap; - buf->is_imported = EINA_TRUE; +static void * +_ecore_buffer_x11_dri2_buffer_import(Ecore_Buffer_Module_Data bmdata, Ecore_Buffer_Info *einfo, Ecore_Export_Type type, int export_id, unsigned int flags EINA_UNUSED) +{ + Ecore_Buffer_Module_X11_Dri2_Data *bm = bmdata; + Ecore_Buffer_X11_Dri2_Data *buf; + tbm_bo bo = NULL; + tbm_surface_h surface; + tbm_surface_info_s tinfo; + int i; - //Get DRI2Buffer - DRI2CreateDrawable(xdpy, buf->pixmap); - bufs = DRI2GetBuffers(xdpy, buf->pixmap, &rw, &rh, &attachment, 1, &rcount); - if ((!bufs) || (buf->w != rw) || (buf->h != rh)) - goto on_error; + if (type != EXPORT_TYPE_ID) + return NULL; - buf->stride = bufs->pitch; + if (!einfo) + return NULL; + + if (einfo->pixmap) + bo = _x11_dri2_bo_get_from_pixmap(bm->tbm_mgr, einfo->pixmap, einfo->width, einfo->height); + else + bo = tbm_bo_import(bm->tbm_mgr, export_id); - //Import tbm_surface - bo = tbm_bo_import(bm->tbm_mgr, bufs->name); if (!bo) - goto on_error; + goto err; + + tinfo.width = einfo->width; + tinfo.height = einfo->height; + tinfo.format = einfo->format; + tinfo.bpp = _buf_get_bpp(einfo->format); + tinfo.size = einfo->height * einfo->planes[0].stride; + tinfo.num_planes = _buf_get_num_planes(einfo->format); + for (i = 0; i < tinfo.num_planes; i++) + { + tinfo.planes[i].size = einfo->height * einfo->planes[i].stride; + tinfo.planes[i].stride = einfo->planes[i].stride; + tinfo.planes[i].offset = einfo->planes[i].offset; + } - num_plane = _buf_get_num_planes(format); - info.width = w; - info.height = h; - info.format = format; - info.bpp = _buf_get_bpp(format); - info.size = w * bufs->pitch; - info.num_planes = num_plane; - for ( i = 0 ; i < num_plane ; i++) - { - info.planes[i].size = w * bufs->pitch; - info.planes[i].stride = bufs->pitch; - info.planes[i].offset = 0; - } + surface = tbm_surface_internal_create_with_bos(&tinfo, &bo, 1); + tbm_bo_unref(bo); + if (!surface) + goto err; - buf->tbm.surface = tbm_surface_internal_create_with_bos(&info, &bo, 1); - if (!buf->tbm.surface) - goto on_error; + buf = calloc(1, sizeof(Ecore_Buffer_X11_Dri2_Data)); + if (!buf) + goto err_alloc; + buf->w = einfo->width; + buf->h = einfo->height; + buf->format = einfo->format; + buf->pixmap = einfo->pixmap; + buf->stride = einfo->planes[0].stride; + buf->is_imported = EINA_TRUE; + buf->tbm.surface = surface; buf->tbm.owned = EINA_TRUE; - tbm_bo_unref(bo); - free(bufs); return buf; -on_error: - if (bo) tbm_bo_unref(bo); - if (bufs) free(bufs); - DRI2DestroyDrawable(xdpy, buf->pixmap); +err_alloc: + tbm_surface_internal_unref(surface); +err: + if ((bo) && (einfo->pixmap)) + DRI2DestroyDrawable(ecore_x_display_get(), einfo->pixmap); + free(buf); return NULL; @@ -545,6 +613,7 @@ static Ecore_Buffer_Backend _ecore_buffer_x11_dri2_backend = { &_ecore_buffer_x11_dri2_shutdown, &_ecore_buffer_x11_dri2_buffer_alloc, &_ecore_buffer_x11_dri2_buffer_alloc_with_tbm_surface, + &_ecore_buffer_x11_dri2_buffer_info_get, &_ecore_buffer_x11_dri2_buffer_free, &_ecore_buffer_x11_dri2_buffer_export, &_ecore_buffer_x11_dri2_buffer_import, diff --git a/src/modules/ecore_buffer/x11_dri3/ecore_buffer_x11_dri3.c b/src/modules/ecore_buffer/x11_dri3/ecore_buffer_x11_dri3.c index 0593579..cfdc2e2 100644 --- a/src/modules/ecore_buffer/x11_dri3/ecore_buffer_x11_dri3.c +++ b/src/modules/ecore_buffer/x11_dri3/ecore_buffer_x11_dri3.c @@ -43,6 +43,8 @@ struct _Ecore_Buffer_X11_Dri3_Data { Eina_Bool is_imported; }; +static Ecore_Pixmap _ecore_buffer_x11_dri3_pixmap_get(Ecore_Buffer_Module_Data bmdata, Ecore_Buffer_Data bdata); + static int _buf_get_num_planes(Ecore_Buffer_Format format) { @@ -325,8 +327,8 @@ _dri3_open(Ecore_X_Display *dpy, Ecore_X_Window root, unsigned provider) static Ecore_X_Pixmap _dri3_pixmap_from_fd(Ecore_X_Display *dpy, Ecore_X_Drawable draw, int width, int height, int depth, int fd, int bpp, int stride, int size) { - xcb_connection_t *c = XGetXCBConnection(dpy); - Ecore_X_Pixmap pixmap = xcb_generate_id(c); + xcb_connection_t *c; + Ecore_X_Pixmap pixmap; if (!dpy) return 0; @@ -431,6 +433,8 @@ _ecore_buffer_x11_dri3_buffer_alloc_with_tbm_surface(Ecore_Buffer_Module_Data bm { Ecore_Buffer_X11_Dri3_Data *buf; + EINA_SAFETY_ON_NULL_RETURN_VAL(tbm_surface, NULL); + buf = calloc(1, sizeof(Ecore_Buffer_X11_Dri3_Data)); if (!buf) return NULL; @@ -449,6 +453,41 @@ _ecore_buffer_x11_dri3_buffer_alloc_with_tbm_surface(Ecore_Buffer_Module_Data bm return buf; } +static Eina_Bool +_ecore_buffer_x11_dri3_buffer_info_get(Ecore_Buffer_Module_Data bmdata, Ecore_Buffer_Data bdata, Ecore_Buffer_Info *info) +{ + Ecore_Buffer_X11_Dri3_Data *buf = bdata; + tbm_surface_info_s tinfo; + int i, res; + + if (!buf->tbm_surface) + return EINA_FALSE; + + res = tbm_surface_get_info(buf->tbm_surface, &tinfo); + if (res != TBM_SURFACE_ERROR_NONE) + return EINA_FALSE; + + if (info) + { + info->width = tinfo.width; + info->height = tinfo.height; + info->format = tinfo.format; + info->bpp = tinfo.bpp; + info->size = tinfo.size; + info->num_planes = tinfo.num_planes; + info->pixmap = _ecore_buffer_x11_dri3_pixmap_get(bmdata, bdata); + + for (i = 0; i < tinfo.num_planes; i++) + { + info->planes[i].size = tinfo.planes[i].size; + info->planes[i].offset = tinfo.planes[i].offset; + info->planes[i].stride = tinfo.planes[i].stride; + } + } + + return EINA_TRUE; +} + static void _ecore_buffer_x11_dri3_buffer_free(Ecore_Buffer_Module_Data bmdata EINA_UNUSED, Ecore_Buffer_Data bdata) { @@ -485,13 +524,13 @@ _ecore_buffer_x11_dri3_buffer_export(Ecore_Buffer_Module_Data bmdata EINA_UNUSED } static Ecore_Buffer_Data -_ecore_buffer_x11_dri3_buffer_import(Ecore_Buffer_Module_Data bmdata, int w, int h, Ecore_Buffer_Format format, Ecore_Export_Type type, int export_id, unsigned int flags) +_ecore_buffer_x11_dri3_buffer_import(Ecore_Buffer_Module_Data bmdata, Ecore_Buffer_Info *einfo, Ecore_Export_Type type, int export_id, unsigned int flags) { Ecore_Buffer_Module_X11_Dri3_Data *bm = bmdata; Ecore_Buffer_X11_Dri3_Data *buf; tbm_bo bo; - tbm_surface_info_s info; - int i, num_plane; + tbm_surface_info_s tinfo; + int i; if (!bm) return NULL; @@ -506,9 +545,9 @@ _ecore_buffer_x11_dri3_buffer_import(Ecore_Buffer_Module_Data bmdata, int w, int if (!buf) return NULL; - buf->w = w; - buf->h = h; - buf->format = format; + buf->w = einfo->width; + buf->h = einfo->height; + buf->format = einfo->format; buf->flags = flags; buf->is_imported = EINA_TRUE; @@ -520,21 +559,20 @@ _ecore_buffer_x11_dri3_buffer_import(Ecore_Buffer_Module_Data bmdata, int w, int return NULL; } - num_plane = _buf_get_num_planes(format); - info.width = w; - info.height = h; - info.format = format; - info.bpp = _buf_get_bpp(format); - info.size = w * h * info.bpp; - info.num_planes = num_plane; - for ( i = 0 ; i < num_plane ; i++) + tinfo.width = buf->w = einfo->width; + tinfo.height = buf->h = einfo->height; + tinfo.format = buf->format = einfo->format; + tinfo.bpp = _buf_get_bpp(einfo->format); + tinfo.size = einfo->height * einfo->planes[0].stride; + tinfo.num_planes = _buf_get_num_planes(einfo->format); + for (i = 0; i < tinfo.num_planes; i++) { - info.planes[i].size = w * h * info.bpp; - info.planes[i].stride = w * info.bpp; - info.planes[i].offset = 0; + tinfo.planes[i].size = einfo->height * einfo->planes[i].stride; + tinfo.planes[i].stride = einfo->planes[i].stride; + tinfo.planes[i].offset = einfo->planes[i].offset; } - buf->tbm_surface = tbm_surface_internal_create_with_bos(&info, &bo, 1); + buf->tbm_surface = tbm_surface_internal_create_with_bos(&tinfo, &bo, 1); if (!buf->tbm_surface) { tbm_bo_unref(bo); @@ -604,6 +642,7 @@ static Ecore_Buffer_Backend _ecore_buffer_x11_dri3_backend = { &_ecore_buffer_x11_dri3_shutdown, &_ecore_buffer_x11_dri3_buffer_alloc, &_ecore_buffer_x11_dri3_buffer_alloc_with_tbm_surface, + &_ecore_buffer_x11_dri3_buffer_info_get, &_ecore_buffer_x11_dri3_buffer_free, &_ecore_buffer_x11_dri3_buffer_export, &_ecore_buffer_x11_dri3_buffer_import, -- 2.7.4