Shell implementation
authorjunghoon13.son <jh13.son@samsung.com>
Mon, 6 Apr 2015 05:37:25 +0000 (14:37 +0900)
committerTaekyun Kim <tkq.kim@samsung.com>
Fri, 19 Jun 2015 09:06:39 +0000 (18:06 +0900)
    - initial version
    - partially implemented
    - wl_shell and wl_shell_surface protocol APIs are added

Change-Id: If1be160154e9ca40fad315260baf24dbe93af9ce

src/compositor.c
src/pepper-internal.h
src/shell.c
src/surface.c

index 7c2b32f..4036429 100644 (file)
@@ -75,6 +75,13 @@ pepper_compositor_create(const char *socket_name)
                      compositor_bind);
     wl_list_init(&compositor->surfaces);
 
+    compositor->shell = pepper_shell_create(compositor);
+    if (!compositor->shell)
+    {
+        PEPPER_ERROR("Failed to create shell\n");
+        goto error;
+    }
+
     if (wl_display_init_shm(compositor->display) != 0)
     {
         PEPPER_ERROR("Failed to initialze shm.\n");
@@ -93,6 +100,9 @@ error:
 PEPPER_API void
 pepper_compositor_destroy(pepper_compositor_t *compositor)
 {
+    if (compositor->shell)
+        pepper_shell_destroy(compositor->shell);
+
     if (compositor->display)
         wl_display_destroy(compositor->display);
 
index 3f7e5bb..698fd32 100644 (file)
@@ -10,6 +10,8 @@ typedef struct pepper_region        pepper_region_t;
 typedef struct pepper_surface       pepper_surface_t;
 typedef struct pepper_surface_state pepper_surface_state_t;
 typedef struct pepper_buffer        pepper_buffer_t;
+typedef struct pepper_shell         pepper_shell_t;
+typedef struct pepper_shell_surface pepper_shell_surface_t;
 
 /* compositor */
 struct pepper_compositor
@@ -19,6 +21,8 @@ struct pepper_compositor
     struct wl_list      surfaces;
     struct wl_list      regions;
     struct wl_list      seat_list;
+
+    pepper_shell_t     *shell;
 };
 
 struct pepper_output
@@ -92,6 +96,7 @@ struct pepper_surface
     pixman_region32_t       input_region;
 
     struct wl_list          frame_callbacks;
+    struct wl_signal        destroy_signal;
 };
 
 struct pepper_region
@@ -172,4 +177,32 @@ struct pepper_touch
     struct wl_list              resources;
 };
 
+/* Shell */
+struct pepper_shell
+{
+    pepper_compositor_t    *compositor;
+
+    struct wl_global       *global;
+    struct wl_list          resources;      /* FIXME */
+    struct wl_list          shell_surfaces; /* FIXME */
+
+    /* TODO */
+
+};
+
+struct pepper_shell_surface
+{
+    pepper_surface_t        *surface;
+    struct wl_resource      *resource;
+
+    struct wl_list          link;   /* FIXME */
+    struct wl_listener      surface_destroy_listener;
+
+    /* TODO */
+
+};
+
+pepper_shell_t *
+pepper_shell_create(pepper_compositor_t *compositor);
+
 #endif /* PEPPER_INTERNAL_H */
index aded7fb..45e275e 100644 (file)
@@ -1 +1,218 @@
 #include "pepper-internal.h"
+
+static void
+shell_surface_pong(struct wl_client *client, struct wl_resource *resource, uint32_t serial)
+{
+    /* TODO */
+}
+
+static void
+shell_surface_move(struct wl_client *client, struct wl_resource *resource,
+                   struct wl_resource *seat, uint32_t serial)
+{
+    /* TODO */
+}
+
+static void
+shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
+                     struct wl_resource *seat, uint32_t serial, uint32_t edges)
+{
+    /* TODO */
+}
+
+static void
+shell_surface_set_toplevel(struct wl_client *client, struct wl_resource *resource)
+{
+    /* TODO */
+}
+
+static void
+shell_surface_set_transient(struct wl_client *client, struct wl_resource *resource,
+                            struct wl_resource *parent, int32_t x, int32_t y, uint32_t flags)
+{
+    /* TODO */
+}
+
+static void
+shell_surface_set_fullscreen(struct wl_client *client, struct wl_resource *resource,
+                             uint32_t method, uint32_t framerate, struct wl_resource *output)
+{
+    /* TODO */
+}
+
+static void
+shell_surface_set_popup(struct wl_client *client, struct wl_resource *resource,
+                        struct wl_resource *seat, uint32_t serial, struct wl_resource *parent,
+                        int32_t x, int32_t y, uint32_t flags)
+{
+    /* TODO */
+}
+
+static void
+shell_surface_set_maximized(struct wl_client *client, struct wl_resource *resource,
+                            struct wl_resource *output)
+{
+    /* TODO */
+}
+
+static void
+shell_surface_set_title(struct wl_client *client, struct wl_resource *resource,
+                        const char *title)
+{
+    /* TODO */
+}
+
+static void
+shell_surface_set_class(struct wl_client *client, struct wl_resource *resource,
+                        const char *class_)
+{
+    /* TODO */
+}
+
+static const struct wl_shell_surface_interface shell_surface_implementation =
+{
+    shell_surface_pong,
+    shell_surface_move,
+    shell_surface_resize,
+    shell_surface_set_toplevel,
+    shell_surface_set_transient,
+    shell_surface_set_fullscreen,
+    shell_surface_set_popup,
+    shell_surface_set_maximized,
+    shell_surface_set_title,
+    shell_surface_set_class,
+};
+
+static void
+handle_surface_destroy(struct wl_listener *listener, void *data)
+{
+    pepper_shell_surface_t  *shell_surface = wl_container_of(listener, shell_surface,
+                                                             surface_destroy_listener);
+    wl_list_remove(&shell_surface->link);
+    wl_resource_destroy(shell_surface->resource);
+    pepper_free(shell_surface);
+
+    return;
+}
+
+/* TODO */
+static void
+shell_get_shell_surface(struct wl_client *client, struct wl_resource *resource,
+                        uint32_t id, struct wl_resource *surface_resource)
+{
+    pepper_surface_t        *surface = (pepper_surface_t *)
+                                        wl_resource_get_user_data(surface_resource);
+    pepper_shell_t          *shell = (pepper_shell_t *)wl_resource_get_user_data(resource);
+    pepper_shell_surface_t  *shell_surface;
+    struct wl_resource      *r;
+
+    shell_surface = (pepper_shell_surface_t *)pepper_calloc(1, sizeof(pepper_shell_surface_t));
+    if (!shell_surface)
+    {
+        PEPPER_ERROR("Failed to allocate memory in %s\n", __FUNCTION__);
+        goto error;
+    }
+
+    r = wl_resource_create(client, &wl_shell_surface_interface, 1/* FIXME */, id);
+    if (!r)
+    {
+        PEPPER_ERROR("Failed to create a wl_resource object in %s\n", __FUNCTION__);
+        goto error;
+    }
+
+    shell_surface->surface = surface;
+    shell_surface->resource = r;
+    wl_list_insert(&shell->shell_surfaces, &shell_surface->link);
+
+    wl_resource_set_implementation(r, &shell_surface_implementation, shell_surface, NULL);
+
+    shell_surface->surface_destroy_listener.notify = handle_surface_destroy;
+    wl_signal_add(&surface->destroy_signal, &shell_surface->surface_destroy_listener);
+
+    /* TODO */
+
+    return;
+
+error:
+    if (shell_surface)
+        pepper_free(shell_surface);
+
+    wl_resource_post_no_memory(resource);
+
+    return;
+}
+
+static const struct wl_shell_interface shell_implementation =
+{
+    shell_get_shell_surface,
+};
+
+static void
+bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
+{
+    pepper_shell_t      *shell = (pepper_shell_t *)data;
+    struct wl_resource  *resource;
+
+    resource = wl_resource_create(client, &wl_shell_interface, 1/* FIXME */, id);
+    if (!resource)
+    {
+        PEPPER_ERROR("Failed to create a wl_resource object in %s\n", __FUNCTION__);
+        wl_client_post_no_memory(client);
+        return;
+    }
+
+    wl_list_insert(&shell->resources, wl_resource_get_link(resource));
+    wl_resource_set_implementation(resource, &shell_implementation, shell, NULL);
+
+    return;
+}
+
+pepper_shell_t *
+pepper_shell_create(pepper_compositor_t *compositor)
+{
+    pepper_shell_t  *shell;
+
+    shell = (pepper_shell_t *)pepper_calloc(1, sizeof(pepper_shell_t));
+    if (!shell)
+    {
+        PEPPER_ERROR("Failed to allocate memory in %s\n", __FUNCTION__);
+        goto error;
+    }
+
+    wl_list_init(&shell->resources);
+    wl_list_init(&shell->shell_surfaces);
+
+    shell->global = wl_global_create(compositor->display, &wl_shell_interface, 1, shell,
+                                     bind_shell);
+    if (!shell->global)
+    {
+        PEPPER_ERROR("Failed to create wl_global in %s\n", __FUNCTION__);
+        goto error;
+    }
+
+    /* TODO */
+
+    return shell;
+
+error:
+    if (shell)
+        pepper_free(shell);
+
+    return NULL;
+}
+
+void
+pepper_shell_destroy(pepper_shell_t *shell)
+{
+    struct wl_resource  *resource;
+
+    wl_resource_for_each(resource, &shell->resources)
+    {
+        wl_list_remove(wl_resource_get_link(resource));
+        wl_resource_destroy(resource);
+    }
+
+    wl_global_destroy(shell->global);
+    pepper_free(shell);
+    return;
+}
index 13d1d00..f9b5f58 100644 (file)
@@ -260,6 +260,7 @@ pepper_surface_create(pepper_compositor_t *compositor,
     pixman_region32_init(&surface->input_region);
 
     wl_list_init(&surface->frame_callbacks);
+    wl_signal_init(&surface->destroy_signal);
 
     return surface;
 }
@@ -269,6 +270,8 @@ pepper_surface_destroy(pepper_surface_t *surface)
 {
     struct wl_resource *callback, *next;
 
+    wl_signal_emit(&surface->destroy_signal, NULL /* FIXME */);
+
     pepper_surface_state_fini(&surface->pending);
 
     if (surface->buffer)