add the code for supporting the tbm_fd 22/28222/1
authorRoman Marchenko <r.marchenko@samsung.com>
Tue, 30 Sep 2014 13:28:59 +0000 (16:28 +0300)
committerRoman Marchenko <r.marchenko@samsung.com>
Tue, 30 Sep 2014 13:29:24 +0000 (16:29 +0300)
Change-Id: I77215dcb8b1cc748de135ab8c7a5f02d330bea42
Signed-off-by: Roman Marchenko <r.marchenko@samsung.com>
src/tbm_bufmgr.c [changed mode: 0755->0644]
src/tbm_bufmgr.h
src/tbm_bufmgr_backend.h

old mode 100755 (executable)
new mode 100644 (file)
index 733ded3..7867998
@@ -1176,7 +1176,44 @@ tbm_bo_import (tbm_bufmgr bufmgr, unsigned int key)
 tbm_bo
 tbm_bo_import_fd  (tbm_bufmgr bufmgr, tbm_fd fd)
 {
+    TBM_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
+
     tbm_bo bo = NULL;
+    void * bo_priv = NULL;
+
+    bo = calloc (1, sizeof(struct _tbm_bo));
+    if(!bo)
+        return NULL;
+
+    bo->bufmgr = bufmgr;
+
+    pthread_mutex_lock (&bufmgr->lock);
+
+    bo_priv = bufmgr->backend->bo_import_fd(bo, fd);
+    if (!bo_priv)
+    {
+        free (bo);
+        pthread_mutex_unlock (&bufmgr->lock);
+        return NULL;
+    }
+
+    bo->ref_cnt = 1;
+    bo->tgl_key = INITIAL_KEY;
+    bo->priv = bo_priv;
+
+    /* init bo state */
+    if (!_tbm_bo_init_state (bo, CACHE_OP_IMPORT))
+    {
+        _tbm_bo_unref (bo);
+        pthread_mutex_unlock (&bufmgr->lock);
+        return NULL;
+    }
+
+    LIST_INITHEAD (&bo->user_data_list);
+
+    LIST_ADD (&bo->item_link, &bufmgr->bo_list);
+
+    pthread_mutex_unlock (&bufmgr->lock);
 
     return bo;
 }
@@ -1201,9 +1238,18 @@ tbm_bo_export (tbm_bo bo)
 tbm_fd
 tbm_bo_export_fd (tbm_bo bo)
 {
-    tbm_fd fd = 0;
+    TBM_RETURN_VAL_IF_FAIL (_tbm_bo_is_valid(bo), 0);
+
+    tbm_bufmgr bufmgr;
+    int ret;
 
-    return fd;
+    bufmgr = bo->bufmgr;
+
+    pthread_mutex_lock (&bufmgr->lock);
+    ret = bufmgr->backend->bo_export_fd (bo);
+    pthread_mutex_unlock (&bufmgr->lock);
+
+    return ret;
 }
 
 
index 83bdc54..d8e18db 100755 (executable)
@@ -524,7 +524,7 @@ tbm_bo        tbm_bo_import     (tbm_bufmgr bufmgr, tbm_key key);
    ...
 
    bufmgr = tbm_bufmgr_init (bufmgr_fd);
-   bo = tbm_bo_import (bo_fd);
+   bo = tbm_bo_import_fd (bo_fd);
 
    ...
 
index fe4d3a7..3e3150f 100755 (executable)
@@ -235,6 +235,21 @@ struct _tbm_bufmgr_backend
     */
     int           (*surface_get_plane_data)   (tbm_surface_h surface, int width, int height, tbm_format format, int plane_idx, uint32_t *size, uint32_t *offset, uint32_t *pitch);
 
+    /**
+    * @brief import the buffer object associated with the prime fd.
+    * @param[in] bo : the buffer object
+    * @param[in] fd : the prime fd associated with the buffer object
+    * @return pointer of the bo private.
+    */
+    void *       (*bo_import_fd)         (tbm_bo bo, tbm_fd fd);
+
+    /**
+    * @brief export the buffer object
+    * @param[in] bo : the buffer object
+    * @return tbm_fd associated with the buffer object
+    */
+    tbm_fd             (*bo_export_fd)         (tbm_bo bo);
+
     /* Padding for future extension */
     void (*reserved1)    (void);
     void (*reserved2)    (void);
@@ -242,8 +257,6 @@ struct _tbm_bufmgr_backend
     void (*reserved4)    (void);
     void (*reserved5)    (void);
     void (*reserved6)    (void);
-    void (*reserved7)    (void);
-    void (*reserved8)    (void);
 };
 
 /**