correct surface information between server & client 77/132277/1 accepted/tizen/unified/20170608.072256 submit/tizen/20170607.062251
authorBoram Park <boram1288.park@samsung.com>
Fri, 2 Jun 2017 05:21:37 +0000 (14:21 +0900)
committerBoram Park <boram1288.park@samsung.com>
Fri, 2 Jun 2017 05:21:37 +0000 (14:21 +0900)
Change-Id: If4146d1f6b15d811aef89c697eb4bf6fc4561c05

protocol/wayland-tbm.xml
src/wayland-tbm-client.c
src/wayland-tbm-int.h
src/wayland-tbm-server.c

index d572946..05f9135 100644 (file)
       <arg name="width" type="int"/>
       <arg name="height" type="int"/>
       <arg name="format" type="uint"/>
+      <arg name="bpp" type="int"/>
+      <arg name="size" type="int"/>
       <arg name="num_plane" type="int"/>
-      <arg name="buf_idx0" type="int"/>
-      <arg name="offset0" type="int"/>
-      <arg name="stride0" type="int"/>
-      <arg name="buf_idx1" type="int"/>
-      <arg name="offset1" type="int"/>
-      <arg name="stride1" type="int"/>
-      <arg name="buf_idx2" type="int"/>
-      <arg name="offset2" type="int"/>
-      <arg name="stride2" type="int"/>
+      <arg name="plane_buf_idx" type="array"/>
+      <arg name="plane_offset" type="array"/>
+      <arg name="plane_stride" type="array"/>
+      <arg name="plane_size" type="array"/>
       <arg name="flags" type="uint"/>
       <arg name="num_buf" type="int"/>
-      <arg name="buf0" type="uint"/>
-      <arg name="buf1" type="uint"/>
-      <arg name="buf2" type="uint"/>
+      <arg name="buf0" type="uint"/>
+      <arg name="buf1" type="uint"/>
+      <arg name="buf2" type="uint"/>
     </request>
 
     <request name="create_buffer_with_fd">
       <arg name="width" type="int"/>
       <arg name="height" type="int"/>
       <arg name="format" type="uint"/>
+      <arg name="bpp" type="int"/>
+      <arg name="size" type="int"/>
       <arg name="num_plane" type="int"/>
-      <arg name="buf_idx0" type="int"/>
-      <arg name="offset0" type="int"/>
-      <arg name="stride0" type="int"/>
-      <arg name="buf_idx1" type="int"/>
-      <arg name="offset1" type="int"/>
-      <arg name="stride1" type="int"/>
-      <arg name="buf_idx2" type="int"/>
-      <arg name="offset2" type="int"/>
-      <arg name="stride2" type="int"/>
+      <arg name="plane_buf_idx" type="array"/>
+      <arg name="plane_offset" type="array"/>
+      <arg name="plane_stride" type="array"/>
+      <arg name="plane_size" type="array"/>
       <arg name="flags" type="uint"/>
       <arg name="num_buf" type="int"/>
-      <arg name="buf0" type="fd"/>
-      <arg name="buf1" type="fd"/>
-      <arg name="buf2" type="fd"/>
+      <arg name="buf0" type="fd"/>
+      <arg name="buf1" type="fd"/>
+      <arg name="buf2" type="fd"/>
     </request>
 
     <!-- version 2 -->
       <arg name="width" type="int"/>
       <arg name="height" type="int"/>
       <arg name="format" type="uint"/>
+      <arg name="bpp" type="int"/>
+      <arg name="size" type="int"/>
       <arg name="num_plane" type="int"/>
-      <arg name="buf_idx0" type="int"/>
-      <arg name="offset0" type="int"/>
-      <arg name="stride0" type="int"/>
-      <arg name="buf_idx1" type="int"/>
-      <arg name="offset1" type="int"/>
-      <arg name="stride1" type="int"/>
-      <arg name="buf_idx2" type="int"/>
-      <arg name="offset2" type="int"/>
-      <arg name="stride2" type="int"/>
+      <arg name="plane_buf_idx" type="array"/>
+      <arg name="plane_offset" type="array"/>
+      <arg name="plane_stride" type="array"/>
+      <arg name="plane_size" type="array"/>
       <arg name="flags" type="uint"/>
       <arg name="num_buf" type="int"/>
-      <arg name="buf0" type="uint"/>
-      <arg name="buf1" type="uint"/>
-      <arg name="buf2" type="uint"/>
+      <arg name="buf0" type="uint"/>
+      <arg name="buf1" type="uint"/>
+      <arg name="buf2" type="uint"/>
     </event>
 
     <event name="buffer_import_with_fd">
       <arg name="width" type="int"/>
       <arg name="height" type="int"/>
       <arg name="format" type="uint"/>
+      <arg name="bpp" type="int"/>
+      <arg name="size" type="int"/>
       <arg name="num_plane" type="int"/>
-      <arg name="buf_idx0" type="int"/>
-      <arg name="offset0" type="int"/>
-      <arg name="stride0" type="int"/>
-      <arg name="buf_idx1" type="int"/>
-      <arg name="offset1" type="int"/>
-      <arg name="stride1" type="int"/>
-      <arg name="buf_idx2" type="int"/>
-      <arg name="offset2" type="int"/>
-      <arg name="stride2" type="int"/>
+      <arg name="plane_buf_idx" type="array"/>
+      <arg name="plane_offset" type="array"/>
+      <arg name="plane_stride" type="array"/>
+      <arg name="plane_size" type="array"/>
       <arg name="flags" type="uint"/>
       <arg name="num_buf" type="int"/>
-      <arg name="buf0" type="fd"/>
-      <arg name="buf1" type="fd"/>
-      <arg name="buf2" type="fd"/>
+      <arg name="buf0" type="fd"/>
+      <arg name="buf1" type="fd"/>
+      <arg name="buf2" type="fd"/>
     </event>
 
     <request name="set_sync_timeline">
index 320d08f..1ca2ff0 100644 (file)
@@ -111,16 +111,13 @@ _wayland_tbm_client_create_surface_from_param(tbm_bufmgr bufmgr,
                         int32_t width,
                         int32_t height,
                         uint32_t format,
+                        int32_t bpp,
+                        int32_t size,
                         int32_t num_plane,
-                        int32_t buf_idx0,
-                        int32_t offset0,
-                        int32_t stride0,
-                        int32_t buf_idx1,
-                        int32_t offset1,
-                        int32_t stride1,
-                        int32_t buf_idx2,
-                        int32_t offset2,
-                        int32_t stride2,
+                        struct wl_array *plane_buf_idx,
+                        struct wl_array *plane_offset,
+                        struct wl_array *plane_stride,
+                        struct wl_array *plane_size,
                         uint32_t flags,
                         int32_t num_buf,
                         uint32_t buf0,
@@ -160,16 +157,13 @@ handle_tbm_buffer_import_with_id(void *data,
                int32_t width,
                int32_t height,
                uint32_t format,
+               int32_t bpp,
+               int32_t size,
                int32_t num_plane,
-               int32_t buf_idx0,
-               int32_t offset0,
-               int32_t stride0,
-               int32_t buf_idx1,
-               int32_t offset1,
-               int32_t stride1,
-               int32_t buf_idx2,
-               int32_t offset2,
-               int32_t stride2,
+               struct wl_array *plane_buf_idx,
+               struct wl_array *plane_offset,
+               struct wl_array *plane_stride,
+               struct wl_array *plane_size,
                uint32_t flags,
                int32_t num_buf,
                uint32_t buf0,
@@ -181,11 +175,9 @@ handle_tbm_buffer_import_with_id(void *data,
        char debug_id[64] = {0, };
 
        tbm_surface = _wayland_tbm_client_create_surface_from_param(tbm_client->bufmgr, 0,
-                             width, height, format,
+                             width, height, format, bpp, size,
                              num_plane,
-                             buf_idx0, offset0, stride0,
-                             buf_idx1, offset1, stride1,
-                             buf_idx2, offset2, stride2,
+                             plane_buf_idx, plane_offset, plane_stride, plane_size,
                              0,
                              num_buf,
                              buf0, buf1, buf2);
@@ -213,16 +205,13 @@ handle_tbm_buffer_import_with_fd(void *data,
                int32_t width,
                int32_t height,
                uint32_t format,
+               int32_t bpp,
+               int32_t size,
                int32_t num_plane,
-               int32_t buf_idx0,
-               int32_t offset0,
-               int32_t stride0,
-               int32_t buf_idx1,
-               int32_t offset1,
-               int32_t stride1,
-               int32_t buf_idx2,
-               int32_t offset2,
-               int32_t stride2,
+               struct wl_array *plane_buf_idx,
+               struct wl_array *plane_offset,
+               struct wl_array *plane_stride,
+               struct wl_array *plane_size,
                uint32_t flags,
                int32_t num_buf,
                int32_t buf0,
@@ -234,11 +223,9 @@ handle_tbm_buffer_import_with_fd(void *data,
        char debug_id[64] = {0, };
 
        tbm_surface = _wayland_tbm_client_create_surface_from_param(tbm_client->bufmgr, 1,
-                             width, height, format,
+                             width, height, format, bpp, size,
                              num_plane,
-                             buf_idx0, offset0, stride0,
-                             buf_idx1, offset1, stride1,
-                             buf_idx2, offset2, stride2,
+                             plane_buf_idx, plane_offset, plane_stride, plane_size,
                              0,
                              num_buf,
                              buf0, buf1, buf2);
@@ -494,6 +481,8 @@ wayland_tbm_client_create_buffer(struct wayland_tbm_client *tbm_client,
        char debug_id[64] = {0, };
        tbm_surface_info_s info;
        uint32_t flags = 0;
+       struct wl_array plane_buf_idx, plane_offset, plane_stride, plane_size;
+       int *p;
 
        /*
         * if the surface is the attached surface from display server,
@@ -557,30 +546,41 @@ wayland_tbm_client_create_buffer(struct wayland_tbm_client *tbm_client,
                }
        }
 
+       wl_array_init(&plane_buf_idx);
+       wl_array_init(&plane_offset);
+       wl_array_init(&plane_stride);
+       wl_array_init(&plane_size);
+
+       for (i = 0; i < 3; i++) {
+               p = wl_array_add(&plane_buf_idx, sizeof(int));
+               *p = tbm_surface_internal_get_plane_bo_idx(surface, i);
+               p = wl_array_add(&plane_offset, sizeof(int));
+               *p = info.planes[i].offset;
+               p = wl_array_add(&plane_stride, sizeof(int));
+               *p = info.planes[i].stride;
+               p = wl_array_add(&plane_size, sizeof(int));
+               *p = info.planes[i].size;
+       }
+
        if (is_fd == 1)
                wl_buffer = wl_tbm_create_buffer_with_fd(tbm_client->wl_tbm,
-                               info.width, info.height, info.format, info.num_planes,
-                               tbm_surface_internal_get_plane_bo_idx(surface, 0),
-                               info.planes[0].offset, info.planes[0].stride,
-                               tbm_surface_internal_get_plane_bo_idx(surface, 1),
-                               info.planes[1].offset, info.planes[1].stride,
-                               tbm_surface_internal_get_plane_bo_idx(surface, 2),
-                               info.planes[2].offset, info.planes[2].stride,
+                               info.width, info.height, info.format, info.bpp, info.size, info.num_planes,
+                               &plane_buf_idx, &plane_offset, &plane_stride, &plane_size,
                                flags, num_buf, bufs[0],
                                (bufs[1] == -1) ? bufs[0] : bufs[1],
                                (bufs[2] == -1) ? bufs[0] : bufs[2]);
        else
                wl_buffer = wl_tbm_create_buffer(tbm_client->wl_tbm,
-                                info.width, info.height, info.format, info.num_planes,
-                                tbm_surface_internal_get_plane_bo_idx(surface, 0),
-                                info.planes[0].offset, info.planes[0].stride,
-                                tbm_surface_internal_get_plane_bo_idx(surface, 1),
-                                info.planes[1].offset, info.planes[1].stride,
-                                tbm_surface_internal_get_plane_bo_idx(surface, 2),
-                                info.planes[2].offset, info.planes[2].stride,
+                                info.width, info.height, info.format, info.bpp, info.size, info.num_planes,
+                                &plane_buf_idx, &plane_offset, &plane_stride, &plane_size,
                                 flags,
                                 num_buf, bufs[0], bufs[1], bufs[2]);
 
+       wl_array_release(&plane_buf_idx);
+       wl_array_release(&plane_offset);
+       wl_array_release(&plane_stride);
+       wl_array_release(&plane_size);
+
        if (!wl_buffer) {
                WL_TBM_LOG("Failed to create wl_buffer\n");
                goto err;
@@ -688,16 +688,13 @@ _wayland_tbm_client_create_surface_from_param(tbm_bufmgr bufmgr,
                                                         int32_t width,
                                                         int32_t height,
                                                         uint32_t format,
+                                                        int32_t bpp,
+                                                        int32_t size,
                                                         int32_t num_plane,
-                                                        int32_t buf_idx0,
-                                                        int32_t offset0,
-                                                        int32_t stride0,
-                                                        int32_t buf_idx1,
-                                                        int32_t offset1,
-                                                        int32_t stride1,
-                                                        int32_t buf_idx2,
-                                                        int32_t offset2,
-                                                        int32_t stride2,
+                                                        struct wl_array *plane_buf_idx,
+                                                        struct wl_array *plane_offset,
+                                                        struct wl_array *plane_stride,
+                                                        struct wl_array *plane_size,
                                                         uint32_t flags,
                                                         int32_t num_buf,
                                                         uint32_t buf0,
@@ -707,10 +704,9 @@ _wayland_tbm_client_create_surface_from_param(tbm_bufmgr bufmgr,
        int32_t names[TBM_SURF_PLANE_MAX] = { -1, -1, -1, -1};
        tbm_surface_info_s info = { 0, };
        tbm_bo bos[TBM_SURF_PLANE_MAX];
-       int bpp, i, numPlane, numName;
+       int i, numPlane, numName;
        tbm_surface_h tbm_surface;
 
-       bpp = tbm_surface_internal_get_bpp(format);
        numPlane = tbm_surface_internal_get_num_planes(format);
        WL_TBM_RETURN_VAL_IF_FAIL(numPlane == num_plane, NULL);
 
@@ -718,23 +714,14 @@ _wayland_tbm_client_create_surface_from_param(tbm_bufmgr bufmgr,
        info.height = height;
        info.format = format;
        info.bpp = bpp;
+       info.size = size;
        info.num_planes = numPlane;
 
        /*Fill plane info*/
-       if (numPlane > 0) {
-               info.planes[0].offset = offset0;
-               info.planes[0].stride = stride0;
-               numPlane--;
-               if (numPlane > 0) {
-                       info.planes[1].offset = offset1;
-                       info.planes[1].stride = stride1;
-                       numPlane--;
-                       if (numPlane > 0) {
-                               info.planes[2].offset = offset2;
-                               info.planes[2].stride = stride2;
-                               numPlane--;
-                       }
-               }
+       for (i = 0; i < numPlane; i++) {
+               info.planes[i].offset = *WL_TBM_ARRAY_NTH_DATA(plane_offset, int32_t, i);
+               info.planes[i].stride = *WL_TBM_ARRAY_NTH_DATA(plane_stride, int32_t, i);
+               info.planes[i].size = *WL_TBM_ARRAY_NTH_DATA(plane_size, int32_t, i);
        }
 
        /*Fill buffer*/
index 6935f5d..f77fddd 100644 (file)
@@ -112,6 +112,8 @@ extern int bDlog;
        } \
 }
 
+#define WL_TBM_ARRAY_NTH_DATA(array, type, n) (((type*)((array)->data)) + n)
+
 typedef enum {
        WL_TBM_MONITOR_COMMAND_LIST,
        WL_TBM_MONITOR_COMMAND_SHOW,
index 35ffe6e..142af37 100644 (file)
@@ -275,10 +275,10 @@ static void
 _wayland_tbm_server_impl_create_buffer(struct wl_client *client,
               struct wl_resource *wl_tbm,
               uint32_t id,
-              int32_t width, int32_t height, uint32_t format, int32_t num_plane,
-              int32_t buf_idx0, int32_t offset0, int32_t stride0,
-              int32_t buf_idx1, int32_t offset1, int32_t stride1,
-              int32_t buf_idx2, int32_t offset2, int32_t stride2,
+              int32_t width, int32_t height, uint32_t format,
+              int32_t bpp, int32_t size, int32_t num_plane,
+              struct wl_array *plane_buf_idx, struct wl_array *plane_offset,
+              struct wl_array *plane_stride, struct wl_array *plane_size,
               uint32_t flags,
               int32_t num_buf, uint32_t buf0, uint32_t buf1, uint32_t buf2)
 {
@@ -301,24 +301,15 @@ _wayland_tbm_server_impl_create_buffer(struct wl_client *client,
        info.width = width;
        info.height = height;
        info.format = format;
-       info.bpp = tbm_surface_internal_get_bpp(format);
+       info.bpp = bpp;
+       info.size = size;
        info.num_planes = numPlane;
 
        /*Fill plane info*/
-       if (numPlane > 0) {
-               info.planes[0].offset = offset0;
-               info.planes[0].stride = stride0;
-               numPlane--;
-               if (numPlane > 0) {
-                       info.planes[1].offset = offset1;
-                       info.planes[1].stride = stride1;
-                       numPlane--;
-                       if (numPlane > 0) {
-                               info.planes[2].offset = offset2;
-                               info.planes[2].stride = stride2;
-                               numPlane--;
-                       }
-               }
+       for (i = 0; i < numPlane; i++) {
+               info.planes[i].offset = *WL_TBM_ARRAY_NTH_DATA(plane_offset, int32_t, i);
+               info.planes[i].stride = *WL_TBM_ARRAY_NTH_DATA(plane_stride, int32_t, i);
+               info.planes[i].size = *WL_TBM_ARRAY_NTH_DATA(plane_size, int32_t, i);
        }
 
        /*Fill buffer*/
@@ -360,10 +351,10 @@ static void
 _wayland_tbm_server_impl_create_buffer_with_fd(struct wl_client *client,
                struct wl_resource *wl_tbm,
                uint32_t id,
-               int32_t width, int32_t height, uint32_t format, int32_t num_plane,
-               int32_t buf_idx0, int32_t offset0, int32_t stride0,
-               int32_t buf_idx1, int32_t offset1, int32_t stride1,
-               int32_t buf_idx2, int32_t offset2, int32_t stride2,
+               int32_t width, int32_t height, uint32_t format,
+               int32_t bpp, int32_t size, int32_t num_plane,
+               struct wl_array *plane_buf_idx, struct wl_array *plane_offset,
+               struct wl_array *plane_stride, struct wl_array *plane_size,
                uint32_t flags,
                int32_t num_buf, int32_t buf0, int32_t buf1, int32_t buf2)
 {
@@ -390,20 +381,10 @@ _wayland_tbm_server_impl_create_buffer_with_fd(struct wl_client *client,
        info.num_planes = numPlane;
 
        /*Fill plane info*/
-       if (numPlane > 0) {
-               info.planes[0].offset = offset0;
-               info.planes[0].stride = stride0;
-               numPlane--;
-               if (numPlane > 0) {
-                       info.planes[1].offset = offset1;
-                       info.planes[1].stride = stride1;
-                       numPlane--;
-                       if (numPlane > 0) {
-                               info.planes[2].offset = offset2;
-                               info.planes[2].stride = stride2;
-                               numPlane--;
-                       }
-               }
+       for (i = 0; i < numPlane; i++) {
+               info.planes[i].offset = *WL_TBM_ARRAY_NTH_DATA(plane_offset, int32_t, i);
+               info.planes[i].stride = *WL_TBM_ARRAY_NTH_DATA(plane_stride, int32_t, i);
+               info.planes[i].size = *WL_TBM_ARRAY_NTH_DATA(plane_size, int32_t, i);
        }
 
        /*Fill buffer*/
@@ -1019,6 +1000,8 @@ _wayland_tbm_server_export_surface(struct wl_resource *wl_tbm,
        int bufs[TBM_SURF_PLANE_MAX] = { -1, -1, -1, -1};
        int flag, i, is_fd = -1, num_buf;
        tbm_surface_info_s info;
+       struct wl_array plane_buf_idx, plane_offset, plane_stride, plane_size;
+       int *p;
 
        if (tbm_surface_get_info(surface, &info) != TBM_SURFACE_ERROR_NONE) {
                WL_TBM_S_LOG("Failed to create buffer from surface\n");
@@ -1065,33 +1048,44 @@ _wayland_tbm_server_export_surface(struct wl_resource *wl_tbm,
                }
        }
 
+       wl_array_init(&plane_buf_idx);
+       wl_array_init(&plane_offset);
+       wl_array_init(&plane_stride);
+       wl_array_init(&plane_size);
+
+       for (i = 0; i < 3; i++) {
+               p = wl_array_add(&plane_buf_idx, sizeof(int));
+               *p = tbm_surface_internal_get_plane_bo_idx(surface, i);
+               p = wl_array_add(&plane_offset, sizeof(int));
+               *p = info.planes[i].offset;
+               p = wl_array_add(&plane_stride, sizeof(int));
+               *p = info.planes[i].stride;
+               p = wl_array_add(&plane_size, sizeof(int));
+               *p = info.planes[i].size;
+       }
+
        if (is_fd == 1)
                wl_tbm_send_buffer_import_with_fd(wl_tbm,
                                wl_buffer,
-                               info.width, info.height, info.format, info.num_planes,
-                               tbm_surface_internal_get_plane_bo_idx(surface, 0),
-                               info.planes[0].offset, info.planes[0].stride,
-                               tbm_surface_internal_get_plane_bo_idx(surface, 1),
-                               info.planes[1].offset, info.planes[1].stride,
-                               tbm_surface_internal_get_plane_bo_idx(surface, 2),
-                               info.planes[2].offset, info.planes[2].stride,
+                               info.width, info.height, info.format, info.bpp, info.size, info.num_planes,
+                               &plane_buf_idx, &plane_offset, &plane_stride, &plane_size,
                                flag, num_buf, bufs[0],
                                (bufs[1] == -1) ? bufs[0] : bufs[1],
                                (bufs[2] == -1) ? bufs[0] : bufs[2]);
        else
                wl_tbm_send_buffer_import_with_id(wl_tbm,
                                wl_buffer,
-                               info.width, info.height, info.format, info.num_planes,
-                               tbm_surface_internal_get_plane_bo_idx(surface, 0),
-                               info.planes[0].offset, info.planes[0].stride,
-                               tbm_surface_internal_get_plane_bo_idx(surface, 1),
-                               info.planes[1].offset, info.planes[1].stride,
-                               tbm_surface_internal_get_plane_bo_idx(surface, 2),
-                               info.planes[2].offset, info.planes[2].stride,
+                               info.width, info.height, info.format, info.bpp, info.size, info.num_planes,
+                               &plane_buf_idx, &plane_offset, &plane_stride, &plane_size,
                                flag, num_buf, bufs[0],
                                (bufs[1] == -1) ? bufs[0] : bufs[1],
                                (bufs[2] == -1) ? bufs[0] : bufs[2]);
 
+       wl_array_release(&plane_buf_idx);
+       wl_array_release(&plane_offset);
+       wl_array_release(&plane_stride);
+       wl_array_release(&plane_size);
+
        for (i = 0; i < TBM_SURF_PLANE_MAX; i++) {
                if (is_fd == 1 && (bufs[i] >= 0))
                        close(bufs[i]);