From 36b8bcc34d0da92c487365f91f40d56c7593844b Mon Sep 17 00:00:00 2001 From: "jaehoon01.jeong" Date: Tue, 3 Mar 2015 17:26:00 +0900 Subject: [PATCH] add global object creation and handler codes for basic functionality - remove white-space - remove 'pepper_' prefix in internal static functions - modify function names and fn table names - bind_xxx - xxx_implementation Change-Id: I89aa27a312964986e8a3245b8e3667dbfe5a411b --- src/Makefile.am | 1 + src/common.h | 3 + src/compositor.c | 93 ++++++++++++++++++++++- src/pepper.h | 1 + src/pepper_internal.h | 9 ++- src/shell.c | 204 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/surface.c | 113 ++++++++++++++++++++++++++++ 7 files changed, 422 insertions(+), 2 deletions(-) create mode 100644 src/shell.c diff --git a/src/Makefile.am b/src/Makefile.am index e5c763f..94d2a03 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,6 +11,7 @@ libpepper_la_SOURCES = pepper.h \ compositor.c \ output.c \ client.c \ + shell.c \ surface.c # Pepper server executable diff --git a/src/common.h b/src/common.h index 133b230..2b5fce7 100644 --- a/src/common.h +++ b/src/common.h @@ -13,4 +13,7 @@ } while (0) + +#define PEPPER_TRACE PEPPER_ERROR + #endif /* COMMON_H */ diff --git a/src/compositor.c b/src/compositor.c index 2ac148e..1e29cb3 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -1,5 +1,84 @@ #include "pepper_internal.h" +extern const struct wl_surface_interface surface_implementation; + +void +bind_shell(struct wl_client *, void *, uint32_t, uint32_t); + + +/* compositor interface */ +static void +compositor_create_surface(struct wl_client *client, + struct wl_resource *resource, + uint32_t id) +{ + pepper_compositor_t *compositor = wl_resource_get_user_data(resource); + pepper_surface_t *surface; + + PEPPER_TRACE("%s\n", __FUNCTION__); + + surface = (pepper_surface_t *)calloc(1, sizeof(pepper_surface_t)); + if (!surface) + { + PEPPER_ERROR("%s Surface memory allocation failed\n", __FUNCTION__); + wl_resource_post_no_memory(resource); + } + + surface->resource = wl_resource_create(client, &wl_surface_interface, + wl_resource_get_version(resource), id); + if (!surface->resource) + { + PEPPER_ERROR("%s wl_resource_create failed\n", __FUNCTION__); + free(surface); + wl_resource_post_no_memory(resource); + return ; + } + + wl_resource_set_implementation(surface->resource, &surface_implementation, surface, NULL); +} + + +static void +compositor_create_region(struct wl_client *client, + struct wl_resource *resource, + uint32_t id) +{ + PEPPER_TRACE("%s\n", __FUNCTION__); +} + + +static const struct wl_compositor_interface compositor_interface = +{ + compositor_create_surface, + compositor_create_region +}; + +static void +bind_compositor(struct wl_client *client, + void *data, + uint32_t version, + uint32_t id) +{ + pepper_compositor_t *compositor = (pepper_compositor_t *)data; + struct wl_resource *resource; + + PEPPER_TRACE("%s\n", __FUNCTION__); + + resource = wl_resource_create(client, &wl_compositor_interface, version, id); + if (!resource) + { + PEPPER_ERROR("%s wl_resource_create failed\n", __FUNCTION__); + + wl_client_post_no_memory(client); + return; + } + PEPPER_TRACE("%s wl_resource_create success\n", __FUNCTION__); + + wl_resource_set_implementation(resource, &compositor_interface, compositor, NULL); +} + + + pepper_compositor_t * pepper_compositor_create(const char *socket_name, const char *backend_name, @@ -32,8 +111,16 @@ pepper_compositor_create(const char *socket_name, goto error; } + wl_global_create(compositor->display, &wl_compositor_interface, 3, compositor, + bind_compositor); + /* TODO: Load modules. */ + wl_global_create(compositor->display, &wl_shell_interface, 1, compositor, + bind_shell); + + wl_display_init_shm(compositor->display); + return compositor; error: @@ -108,5 +195,9 @@ pepper_compositor_get_output(pepper_compositor_t *compositor, int index) void pepper_compositor_frame(pepper_compositor_t *compositor) { - /* TODO: */ + if (compositor) + { + wl_display_flush_clients(compositor->display); + wl_event_loop_dispatch(wl_display_get_event_loop(compositor->display), -1); + } } diff --git a/src/pepper.h b/src/pepper.h index 742c0a2..cb4075b 100644 --- a/src/pepper.h +++ b/src/pepper.h @@ -13,6 +13,7 @@ typedef struct pepper_output pepper_output_t; typedef struct pepper_output_info pepper_output_info_t; typedef struct pepper_client pepper_client_t; typedef struct pepper_surface pepper_surface_t; +typedef struct pepper_shell_surface pepper_shell_surface_t; struct pepper_output_info { diff --git a/src/pepper_internal.h b/src/pepper_internal.h index 59a9214..f0514ee 100644 --- a/src/pepper_internal.h +++ b/src/pepper_internal.h @@ -28,7 +28,14 @@ struct pepper_client struct pepper_surface { - void *buffer; + struct wl_resource *resource; + void *buffer; +}; + +struct pepper_shell_surface +{ + struct wl_resource *resource; + pepper_surface_t *surface; }; #endif /* PEPPER_INTERNAL_H */ diff --git a/src/shell.c b/src/shell.c new file mode 100644 index 0000000..a96491c --- /dev/null +++ b/src/shell.c @@ -0,0 +1,204 @@ +#include "pepper_internal.h" + + +/* shell surface interface */ +static void +shell_surface_pong(struct wl_client *client, + struct wl_resource *resource, + uint32_t serial) +{ + pepper_shell_surface_t *shsurface = wl_resource_get_user_data(resource); + + PEPPER_TRACE("%s\n", __FUNCTION__); +} + +static void +shell_surface_move(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *seat, + uint32_t serial) +{ + pepper_shell_surface_t *shsurface = wl_resource_get_user_data(resource); + + PEPPER_TRACE("%s\n", __FUNCTION__); +} + +static void +shell_surface_resize(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *seat, + uint32_t serial, + uint32_t edges) +{ + pepper_shell_surface_t *shsurface = wl_resource_get_user_data(resource); + + PEPPER_TRACE("%s\n", __FUNCTION__); +} + + + +static void +shell_surface_set_toplevel(struct wl_client *client, + struct wl_resource *resource) +{ + pepper_shell_surface_t *shsurface = wl_resource_get_user_data(resource); + + PEPPER_TRACE("%s\n", __FUNCTION__); +} + + + +static void +shell_surface_set_transient(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *parent_resource, + int x, + int y, + uint32_t flags) +{ + pepper_shell_surface_t *shsurface = wl_resource_get_user_data(resource); + + PEPPER_TRACE("%s\n", __FUNCTION__); +} + +static void +shell_surface_set_fullscreen(struct wl_client *client, + struct wl_resource *resource, + uint32_t method, + uint32_t framerate, + struct wl_resource *output_resource) +{ + pepper_shell_surface_t *shsurface = wl_resource_get_user_data(resource); + + PEPPER_TRACE("%s\n", __FUNCTION__); +} + +static void +shell_surface_set_popup(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *seat_resource, + uint32_t serial, + struct wl_resource *parent_resource, + int32_t x, + int32_t y, + uint32_t flags) +{ + pepper_shell_surface_t *shsurface = wl_resource_get_user_data(resource); + + PEPPER_TRACE("%s\n", __FUNCTION__); +} + +static void +shell_surface_set_maximized(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *output_resource) +{ + pepper_shell_surface_t *shsurface = wl_resource_get_user_data(resource); + + PEPPER_TRACE("%s\n", __FUNCTION__); +} + + +static void +shell_surface_set_title(struct wl_client *client, + struct wl_resource *resource, + const char *title) +{ + pepper_shell_surface_t *shsurface = wl_resource_get_user_data(resource); + + PEPPER_TRACE("%s\n", __FUNCTION__); +} + +static void +shell_surface_set_class(struct wl_client *client, + struct wl_resource *resource, + const char *class) +{ + pepper_shell_surface_t *shsurface = wl_resource_get_user_data(resource); + + PEPPER_TRACE("%s\n", __FUNCTION__); +} + + + +static const struct wl_shell_surface_interface pepper_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 +}; + + + +/* shell interface */ +static void +shell_get_shell_surface(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + struct wl_resource *surface_resource) +{ + pepper_compositor_t *compositor = wl_resource_get_user_data(resource); + pepper_surface_t *surface = wl_resource_get_user_data(surface_resource); + pepper_shell_surface_t *shsurface; + + PEPPER_TRACE("%s\n", __FUNCTION__); + + shsurface = (pepper_shell_surface_t *)calloc(1, sizeof(pepper_shell_surface_t)); + + if (!shsurface) + { + PEPPER_ERROR("%s Shell surface memory allocation failed\n", __FUNCTION__); + wl_client_post_no_memory(client); + return ; + } + + shsurface->resource = wl_resource_create(client, &wl_shell_surface_interface, + wl_resource_get_version(resource), id); + if (!shsurface->resource) + { + PEPPER_ERROR("%s wl_resource_create failed\n", __FUNCTION__); + free(shsurface); + wl_client_post_no_memory(client); + return ; + } + + wl_resource_set_implementation(shsurface->resource, &pepper_shell_surface_implementation, + shsurface, NULL); + +} + + +static const struct wl_shell_interface shell_implementation = +{ + shell_get_shell_surface +}; + + +void +bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) +{ + pepper_compositor_t *compositor = (pepper_compositor_t *)data; + struct wl_resource *resource; + + PEPPER_TRACE("%s\n", __FUNCTION__); + + resource = wl_resource_create(client, &wl_shell_interface, version, id); + if (!resource) + { + PEPPER_ERROR("%s wl_resource_create failed\n", __FUNCTION__); + + wl_client_post_no_memory(client); + return; + } + + wl_resource_set_implementation(resource, &shell_implementation, compositor, NULL); +} + + diff --git a/src/surface.c b/src/surface.c index 75d1c0c..bd7c9f6 100644 --- a/src/surface.c +++ b/src/surface.c @@ -1,7 +1,120 @@ #include "pepper_internal.h" + void * pepper_surface_get_buffer(pepper_surface_t *surface) { return surface->buffer; } + + + +/* surface interface */ +static void +surface_destroy(struct wl_client *client, struct wl_resource *resource) +{ + PEPPER_TRACE("%s\n", __FUNCTION__); + + wl_resource_destroy(resource); +} + +static void +surface_attach(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *buffer, + int32_t x, + int32_t y) +{ + pepper_surface_t *surface = wl_resource_get_user_data(resource); + + PEPPER_TRACE("%s\n", __FUNCTION__); +} + +static void +surface_damage(struct wl_client *client, + struct wl_resource *resource, + int32_t x, + int32_t y, + int32_t width, + int32_t height) +{ + pepper_surface_t *surface = wl_resource_get_user_data(resource); + + PEPPER_TRACE("%s\n", __FUNCTION__); +} + + +static void +surface_frame(struct wl_client *client, + struct wl_resource *resource, + uint32_t callback) +{ + pepper_surface_t *surface = wl_resource_get_user_data(resource); + + PEPPER_TRACE("%s\n", __FUNCTION__); +} + +static void +surface_set_opaque_region(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *region) +{ + pepper_surface_t *surface = wl_resource_get_user_data(resource); + + PEPPER_TRACE("%s\n", __FUNCTION__); +} + +static void +surface_set_input_region(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *region) +{ + pepper_surface_t *surface = wl_resource_get_user_data(resource); + + PEPPER_TRACE("%s\n", __FUNCTION__); +} + + +static void +surface_commit(struct wl_client *client, struct wl_resource *resource) +{ + pepper_surface_t *surface = wl_resource_get_user_data(resource); + + PEPPER_TRACE("%s\n", __FUNCTION__); +} + +static void +surface_set_buffer_transform(struct wl_client *client, + struct wl_resource *resource, + int transform) +{ + pepper_surface_t *surface = wl_resource_get_user_data(resource); + + PEPPER_TRACE("%s\n", __FUNCTION__); +} + +static void +surface_set_buffer_scale(struct wl_client *client, + struct wl_resource *resource, + int32_t scale) +{ + pepper_surface_t *surface = wl_resource_get_user_data(resource); + + PEPPER_TRACE("%s\n", __FUNCTION__); +} + +const struct wl_surface_interface surface_implementation = +{ + surface_destroy, + surface_attach, + surface_damage, + surface_frame, + surface_set_opaque_region, + surface_set_input_region, + surface_commit, + surface_set_buffer_transform, + surface_set_buffer_scale +}; + + + -- 2.7.4