Using wl_tbm protocol when get drm fd instead wl_drm protocol 97/48997/2
authorChangyeon Lee <cyeon.lee@samsung.com>
Tue, 22 Sep 2015 08:24:18 +0000 (17:24 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Thu, 8 Oct 2015 04:58:49 +0000 (13:58 +0900)
because tbm surface isn't work if not install gl packages

Change-Id: I20fea28ac97bb31bcaf8d6215d98d2df11b40311
Signed-off-by: Changyeon Lee <cyeon.lee@samsung.com>
packaging/libtbm.spec
src/tbm_wayland.c

index 29d74101a4f0bc97140bbadb32ffd1bc386c96e3..f8af8b4b2256dcf79293e95d6979ec1bc545c460 100644 (file)
@@ -2,7 +2,7 @@
 %bcond_with wayland
 
 Name:           libtbm
-Version:        1.1.8
+Version:        1.1.9
 Release:        1
 License:        MIT
 Summary:        The library for Tizen Buffer Manager
index 062e392a54c983c19c654fed0dd976b22334d351..a2f6a571292ba41684451c52318053cbfbeadf72 100644 (file)
@@ -36,203 +36,182 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include <stdint.h>
 #include <stddef.h>
-#include "wayland-client.h"
+#include <wayland-client.h>
 
-struct wl_client;
-struct wl_resource;
+#include "wayland-util.h"
 
-struct wl_drm;
+extern const struct wl_interface wl_buffer_interface;
 
-#ifndef WL_DRM_ERROR_ENUM
-#define WL_DRM_ERROR_ENUM
-enum wl_drm_error {
-       WL_DRM_ERROR_AUTHENTICATE_FAIL = 0,
-       WL_DRM_ERROR_INVALID_FORMAT = 1,
-       WL_DRM_ERROR_INVALID_NAME = 2,
+static const struct wl_interface *types[] = {
+    NULL,
+    NULL,
+    NULL,
+    &wl_buffer_interface,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    &wl_buffer_interface,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+};
+
+static const struct wl_message wl_tbm_requests[] = {
+    { "create_buffer", "niiuiiiiiiiiiiuiuuu", types + 3 },
+    { "create_buffer_with_fd", "niiuiiiiiiiiiiuihhh", types + 22 },
+    { "get_authentication_info", "", types + 0 },
+};
+
+static const struct wl_message wl_tbm_events[] = {
+    { "authentication_info", "suh", types + 0 },
+};
+
+WL_EXPORT const struct wl_interface wl_tbm_interface = {
+    "wl_tbm", 1,
+    3, wl_tbm_requests,
+    1, wl_tbm_events,
 };
-#endif /* WL_DRM_ERROR_ENUM */
-
-
-#ifndef WL_DRM_CAPABILITY_ENUM
-#define WL_DRM_CAPABILITY_ENUM
-/**
- * wl_drm_capability - wl_drm capability bitmask
- * @WL_DRM_CAPABILITY_PRIME: wl_drm prime available
- *
- * Bitmask of capabilities.
- */
-enum wl_drm_capability {
-       WL_DRM_CAPABILITY_PRIME = 1,
+
+struct wl_buffer;
+struct wl_tbm;
+
+extern const struct wl_interface wl_tbm_interface;
+
+#ifndef WL_TBM_ERROR_ENUM
+#define WL_TBM_ERROR_ENUM
+enum wl_tbm_error {
+    WL_TBM_ERROR_AUTHENTICATE_FAIL = 0,
+    WL_TBM_ERROR_INVALID_FORMAT = 1,
+    WL_TBM_ERROR_INVALID_NAME = 2,
 };
-#endif /* WL_DRM_CAPABILITY_ENUM */
-
-struct wl_drm_listener {
-       /**
-        * device - (none)
-        * @name: (none)
-        */
-       void (*device)(void *data,
-                      struct wl_drm *wl_drm,
-                      const char *name);
-       /**
-        * format - (none)
-        * @format: (none)
-        */
-       void (*format)(void *data,
-                      struct wl_drm *wl_drm,
-                      uint32_t format);
-       /**
-        * authenticated - (none)
-        */
-       void (*authenticated)(void *data,
-                             struct wl_drm *wl_drm);
-       /**
-        * capabilities - (none)
-        * @value: (none)
-        */
-       void (*capabilities)(void *data,
-                            struct wl_drm *wl_drm,
-                            uint32_t value);
+#endif /* WL_TBM_ERROR_ENUM */
+
+struct wl_tbm_listener {
+    /**
+     * authentication_info - (none)
+     * @device_name: (none)
+     * @capabilities: (none)
+     * @auth_fd: (none)
+     */
+    void (*authentication_info)(void *data,
+                    struct wl_tbm *wl_tbm,
+                    const char *device_name,
+                    uint32_t capabilities,
+                    int32_t auth_fd);
 };
 
 static inline int
-wl_drm_add_listener(struct wl_drm *wl_drm,
-                   const struct wl_drm_listener *listener, void *data)
+wl_tbm_add_listener(struct wl_tbm *wl_tbm,
+            const struct wl_tbm_listener *listener, void *data)
 {
-       return wl_proxy_add_listener((struct wl_proxy *) wl_drm,
-                                    (void (**)(void)) listener, data);
+    return wl_proxy_add_listener((struct wl_proxy *) wl_tbm,
+                     (void (**)(void)) listener, data);
 }
 
-#define WL_DRM_AUTHENTICATE    0
+#define WL_TBM_CREATE_BUFFER    0
+#define WL_TBM_CREATE_BUFFER_WITH_FD    1
+#define WL_TBM_GET_AUTHENTICATION_INFO  2
 
 static inline void
-wl_drm_destroy(struct wl_drm *wl_drm)
+wl_tbm_set_user_data(struct wl_tbm *wl_tbm, void *user_data)
 {
-       wl_proxy_destroy((struct wl_proxy *) wl_drm);
+    wl_proxy_set_user_data((struct wl_proxy *) wl_tbm, user_data);
 }
 
-static inline void
-wl_drm_authenticate(struct wl_drm *wl_drm, uint32_t id)
+static inline void *
+wl_tbm_get_user_data(struct wl_tbm *wl_tbm)
 {
-       wl_proxy_marshal((struct wl_proxy *) wl_drm,
-                        WL_DRM_AUTHENTICATE, id);
+    return wl_proxy_get_user_data((struct wl_proxy *) wl_tbm);
 }
 
-static const struct wl_interface *types[] = {
-       NULL,
-       &wl_buffer_interface,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       &wl_buffer_interface,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       &wl_buffer_interface,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-};
-
-static const struct wl_message wl_drm_requests[] = {
-       { "authenticate", "u", types + 0 },
-       { "create_buffer", "nuiiuu", types + 1 },
-       { "create_planar_buffer", "nuiiuiiiiii", types + 7 },
-       { "create_prime_buffer", "2nhiiuiiiiii", types + 18 },
-};
-
-static const struct wl_message wl_drm_events[] = {
-       { "device", "s", types + 0 },
-       { "format", "u", types + 0 },
-       { "authenticated", "", types + 0 },
-       { "capabilities", "u", types + 0 },
-};
-
-static const struct wl_interface wl_drm_interface = {
-       "wl_drm", 2,
-       4, wl_drm_requests,
-       4, wl_drm_events,
-};
-
-#define USE_QUEUE 1
-
-struct wl_drm_info {
-#if USE_QUEUE
-   struct wl_event_queue *wl_queue;
-#endif   
-   struct wl_drm* wl_drm;
-   int authenticated;
-   int fd;
-};
-
-static void wl_client_drm_handle_device(void *data, struct wl_drm *drm, const char *device)
+static inline void
+wl_tbm_destroy(struct wl_tbm *wl_tbm)
 {
-    struct wl_drm_info *drm_info = (struct wl_drm_info *)data;
-    drm_magic_t magic;
-
-    printf("device[%s]\n", device);
-    drm_info->fd = open(device, O_RDWR | O_CLOEXEC);
-    if (drm_info->fd < 0) {
-        printf("Failed to open a device: %d (%s)\n", errno, device);
-        return;
-    }
-
-    drmGetMagic(drm_info->fd, &magic);
-    printf("magic[%x]\n", magic);
-    wl_drm_authenticate(drm_info->wl_drm, magic);
+    wl_proxy_destroy((struct wl_proxy *) wl_tbm);
 }
 
-static void wl_client_drm_handle_format(void *data, struct wl_drm *drm, uint32_t format)
+static inline void
+wl_tbm_get_authentication_info(struct wl_tbm *wl_tbm)
 {
-    /* Do nothing */
+    wl_proxy_marshal((struct wl_proxy *) wl_tbm,
+             WL_TBM_GET_AUTHENTICATION_INFO);
 }
 
-static void wl_client_drm_handle_authenticated(void *data, struct wl_drm *drm)
+struct wl_tbm_info
 {
-    struct wl_drm_info *drm_info = (struct wl_drm_info *)data;
-    drm_info->authenticated = 1;
-}
+   struct wl_display* dpy;
+   struct wl_event_queue *wl_queue;
+   struct wl_tbm* wl_tbm;
 
-static void wl_client_drm_handle_capabilities(void *data, struct wl_drm *drm, uint32_t value)
+   uint32_t capabilities;
+   char *device;
+   int32_t fd;
+};
+
+static void
+handle_tbm_authentication_info(void *data,
+                    struct wl_tbm *wl_tbm,
+                    const char *device_name,
+                    uint32_t capabilities,
+                    int32_t auth_fd)
 {
-    /* Do nothing */
+   struct wl_tbm_info *info = (struct wl_tbm_info *)data;
+
+   info->fd = auth_fd;
+   info->capabilities = capabilities;
+   if (device_name)
+      info->device = strndup(device_name, 256);
 }
 
+static const struct wl_tbm_listener wl_tbm_client_listener = {
+   handle_tbm_authentication_info
+};
 
 static void wl_client_registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version)
 {
-    struct wl_drm_info *info = (struct wl_drm_info *)data;
-    static const struct wl_drm_listener wl_drm_client_listener = {
-        wl_client_drm_handle_device,
-        wl_client_drm_handle_format,
-        wl_client_drm_handle_authenticated,
-        wl_client_drm_handle_capabilities
-    };
+    struct wl_tbm_info *info = (struct wl_tbm_info *)data;
+
+    if (!strcmp(interface, "wl_tbm"))
+    {
+        info->wl_tbm = wl_registry_bind(registry, name, &wl_tbm_interface, version);
+        if (!info->wl_tbm)
+        {
+            printf("Failed to bind wl_tbm\n");
+            return;
+        }
 
-    printf("interface[%s]\n", interface);
-    if (!strcmp(interface, "wl_drm")) {
-        info->wl_drm = wl_registry_bind(registry, name, &wl_drm_interface, (version > 2) ? 2 : version);
-#if USE_QUEUE        
-        wl_proxy_set_queue((struct wl_proxy *)info->wl_drm, info->wl_queue);
-#endif        
-        wl_drm_add_listener(info->wl_drm, &wl_drm_client_listener, data);
+        wl_tbm_add_listener(info->wl_tbm, &wl_tbm_client_listener, info);
+        wl_proxy_set_queue((struct wl_proxy *)info->wl_tbm, info->wl_queue);
     }
 }
 
@@ -240,15 +219,15 @@ static int tbm_util_get_drm_fd(void *dpy, int *fd)
 {
     struct wl_display *disp = NULL;
     struct wl_registry *wl_registry;
-    int ret = 0;
-    struct wl_drm_info info = {
-#if USE_QUEUE    
-        .wl_queue = NULL,
-#endif
-        .wl_drm = NULL,
-        .authenticated = 0,
-        .fd = -1,
-    };
+    struct wl_tbm_info info = {
+                            .dpy = NULL,
+                            .wl_queue = NULL,
+                            .wl_tbm = NULL,
+                            .capabilities = 0,
+                            .device = NULL,
+                            .fd = 0,
+                            };
+
     static const struct wl_registry_listener registry_listener = {
         wl_client_registry_handle_global,
         NULL
@@ -266,8 +245,8 @@ static int tbm_util_get_drm_fd(void *dpy, int *fd)
         }
         dpy = disp;
     }
-    
-#if USE_QUEUE
+
+    info.dpy = dpy;
     info.wl_queue = wl_display_create_queue(dpy);
     if (!info.wl_queue) {
         printf("Failed to create a WL Queue\n");
@@ -276,45 +255,36 @@ static int tbm_util_get_drm_fd(void *dpy, int *fd)
         }
         return -1;
     }
-#endif
+
     wl_registry = wl_display_get_registry(dpy);
     if (!wl_registry) {
         printf("Failed to get registry\n");
-#if USE_QUEUE        
         wl_event_queue_destroy(info.wl_queue);
-#endif
         if (disp == dpy) {
             wl_display_disconnect(disp);
         }
         return -1;
     }
-#if USE_QUEUE
     wl_proxy_set_queue((struct wl_proxy *)wl_registry, info.wl_queue);
-#endif
-    wl_registry_add_listener(wl_registry, &registry_listener, &info); 
-    wl_display_roundtrip(dpy);
-    
-    printf("Consuming Dispatch Queue begin\n");
-    while (ret != -1 && !info.authenticated) {
-#if USE_QUEUE
-        ret = wl_display_dispatch_queue(dpy, info.wl_queue);
-#else
-        ret = wl_display_dispatch(dpy);
-#endif
-        printf("Dispatch Queue consumed: %d\n", ret);
-    }
-    printf("Consuming Dispatch Queue end\n");
-    
-#if USE_QUEUE
+    wl_registry_add_listener(wl_registry, &registry_listener, &info);
+    wl_display_roundtrip_queue(dpy, info.wl_queue);
+
+    wl_tbm_get_authentication_info(info.wl_tbm);
+    wl_display_roundtrip_queue(dpy, info.wl_queue);
+
+    *fd = info.fd;
+
     wl_event_queue_destroy(info.wl_queue);
-#endif    
     wl_registry_destroy(wl_registry);
-    wl_drm_destroy(info.wl_drm);
 
-    *fd = info.fd;
+    free(info.device);
+    wl_tbm_set_user_data (info.wl_tbm, NULL);
+    wl_tbm_destroy(info.wl_tbm);
+
     if (disp == dpy) {
         wl_display_disconnect(disp);
     }
+
     return *fd >= 0 ? 0 : -1;
 }
 
@@ -322,11 +292,11 @@ int
 tbm_bufmgr_get_drm_fd_wayland()
 {
     int fd = -1;
-    
+
     if(tbm_util_get_drm_fd(NULL, &fd))
     {
         printf("Failed to get drm_fd\n");
     }
-    
+
     return fd;
-}
\ No newline at end of file
+}