From f2ff37c3e93a4979a0a81798fe4eeceafc9a88f7 Mon Sep 17 00:00:00 2001 From: Taekyun Kim Date: Mon, 2 Mar 2015 19:51:06 +0900 Subject: [PATCH] common: Implementation starting point APIs for pepper library are located in pepper.h API implementations should go to their object files. (ex. output.c) Utilities, macros and other stuffs should go to common.h Internal structures and functions should go to pepper_internal.h Change-Id: I6cf48d256cc3a2e5c4ac0424558ec3738e35688a --- src/Makefile.am | 7 +++- src/client.c | 8 ++++ src/common.h | 16 ++++++++ src/compositor.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/output.c | 37 +++++++++++++++++ src/pepper.h | 71 ++++++++++++++++++++++++++++++++ src/pepper_internal.h | 34 +++++++++++++++ src/server/server.c | 17 ++++++-- src/surface.c | 7 ++++ 9 files changed, 305 insertions(+), 4 deletions(-) create mode 100644 src/client.c create mode 100644 src/common.h create mode 100644 src/output.c create mode 100644 src/pepper_internal.h create mode 100644 src/surface.c diff --git a/src/Makefile.am b/src/Makefile.am index 4f81c1d..e5c763f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,7 +6,12 @@ lib_LTLIBRARIES += libpepper.la libpepper_la_CFLAGS = $(PEPPER_CFLAGS) libpepper_la_LIBADD = $(PEPPER_LIBS) libpepper_la_SOURCES = pepper.h \ - compositor.c + pepper_internal.h \ + common.h \ + compositor.c \ + output.c \ + client.c \ + surface.c # Pepper server executable bin_PROGRAMS += pepper diff --git a/src/client.c b/src/client.c new file mode 100644 index 0000000..7c36364 --- /dev/null +++ b/src/client.c @@ -0,0 +1,8 @@ +#include "pepper_internal.h" + +pepper_surface_t * +pepper_client_get_surface(pepper_client_t *client, int index) +{ + /* TODO:*/ + return NULL; +} diff --git a/src/common.h b/src/common.h new file mode 100644 index 0000000..133b230 --- /dev/null +++ b/src/common.h @@ -0,0 +1,16 @@ +#ifndef COMMON_H +#define COMMON_H + +#include +#include +#include + +/* TODO: Change logging destination. */ + +#define PEPPER_ERROR(fmt, ...) \ + do { \ + printf(fmt, ##__VA_ARGS__); \ + } while (0) + + +#endif /* COMMON_H */ diff --git a/src/compositor.c b/src/compositor.c index e69de29..2ac148e 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -0,0 +1,112 @@ +#include "pepper_internal.h" + +pepper_compositor_t * +pepper_compositor_create(const char *socket_name, + const char *backend_name, + const char *input_name, + const char *shell_name, + const char *renderer_name) +{ + pepper_compositor_t *compositor = NULL; + + compositor = (pepper_compositor_t *)calloc(1, sizeof (pepper_compositor_t)); + + if (!compositor) + { + PEPPER_ERROR("Memory allocation failed!!!\n"); + goto error; + } + + compositor->display = wl_display_create(); + + if (!compositor->display) + { + PEPPER_ERROR("Failed to create wayland display object.\n"); + goto error; + } + + if (wl_display_add_socket(compositor->display, socket_name) != 0) + { + PEPPER_ERROR("Failed to add socket display = %p socket_name = %s\n", + compositor->display, socket_name); + goto error; + } + + /* TODO: Load modules. */ + + return compositor; + +error: + if (compositor) + pepper_compositor_destroy(compositor); + + return NULL; +} + +void +pepper_compositor_destroy(pepper_compositor_t *compositor) +{ + if (compositor->display) + wl_display_destroy(compositor->display); + + free(compositor); +} + +pepper_output_t * +pepper_compositor_add_output(pepper_compositor_t *compositor, + pepper_output_info_t *info) +{ + pepper_output_t *output = NULL; + + output = (pepper_output_t *)calloc(1, sizeof (pepper_output_t)); + + if (!output) + { + PEPPER_ERROR("Memory allocation failed!!!\n"); + goto error; + } + + /* TODO: Backend-size output initialization. */ + + output->x = info->x; + output->y = info->y; + output->w = info->w; + output->h = info->h; + + /* TODO: Add to compositor's output list. */ + + return output; + +error: + if (output) + pepper_output_destroy(output); + + return NULL; +} + +pepper_client_t * +pepper_compositor_get_client(pepper_compositor_t *compositor, int index) +{ + /* TODO: */ + return NULL; +} + +int +pepper_compositor_get_output_count(pepper_compositor_t *compositor) +{ + /* TODO: */ + return 0; +} + +pepper_output_t * +pepper_compositor_get_output(pepper_compositor_t *compositor, int index) +{ + /* TODO: */ + return NULL; +} + +void +pepper_compositor_frame(pepper_compositor_t *compositor) +{ + /* TODO: */ +} diff --git a/src/output.c b/src/output.c new file mode 100644 index 0000000..4576756 --- /dev/null +++ b/src/output.c @@ -0,0 +1,37 @@ +#include "pepper_internal.h" + +pepper_bool_t +pepper_output_move(pepper_output_t *output, int x, int y, int w, int h) +{ + /* TODO: */ + return PEPPER_FALSE; +} + +void +pepper_output_get_geometry(pepper_output_t *output, int *x, int *y, int *w, int *h) +{ + if (x) + *x = output->x; + + if (y) + *y = output->y; + + if (w) + *w = output->w; + + if (h) + *h = output->h; +} + +pepper_compositor_t * +pepper_output_get_compositor(pepper_output_t *output) +{ + return output->compositor; +} + +pepper_bool_t +pepper_output_destroy(pepper_output_t *output) +{ + /* TODO: */ + return PEPPER_FALSE; +} diff --git a/src/pepper.h b/src/pepper.h index e69de29..742c0a2 100644 --- a/src/pepper.h +++ b/src/pepper.h @@ -0,0 +1,71 @@ +#ifndef PEPPER_H +#define PEPPER_H + +#include + +#define PEPPER_FALSE 0 +#define PEPPER_TRUE 1 + +typedef uint32_t pepper_bool_t; + +typedef struct pepper_compositor pepper_compositor_t; +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; + +struct pepper_output_info +{ + int x, y, w, h; + void *data; +}; + +/* Compositor functions. */ +pepper_compositor_t * +pepper_compositor_create(const char *socket_name, + const char *backend_name, + const char *input_name, + const char *shell_name, + const char *renderer_name); + +void +pepper_compositor_destroy(pepper_compositor_t *compositor); + +pepper_output_t * +pepper_compositor_add_output(pepper_compositor_t *compositor, + pepper_output_info_t *info); + +int +pepper_compositor_get_output_count(pepper_compositor_t *compositor); + +pepper_output_t * +pepper_compositor_get_output(pepper_compositor_t *compositor, int index); + +pepper_client_t * +pepper_compositor_get_client(pepper_compositor_t *compositor, int index); + +void +pepper_compositor_frame(pepper_compositor_t *compositor); + +/* Output functions. */ +pepper_bool_t +pepper_output_move(pepper_output_t *output, int x, int y, int w, int h); + +void +pepper_output_get_geometry(pepper_output_t *output, int *x, int *y, int *w, int *h); + +pepper_compositor_t * +pepper_output_get_compositor(pepper_output_t *output); + +pepper_bool_t +pepper_output_destroy(pepper_output_t *output); + +/* Client functions. */ +pepper_surface_t * +pepper_client_get_surface(pepper_client_t *client, int index); + +/* Surface functions. */ +void * +pepper_surface_get_buffer(pepper_surface_t *surface); + +#endif /* PEPPER_H */ diff --git a/src/pepper_internal.h b/src/pepper_internal.h new file mode 100644 index 0000000..59a9214 --- /dev/null +++ b/src/pepper_internal.h @@ -0,0 +1,34 @@ +#ifndef PEPPER_INTERNAL_H +#define PEPPER_INTERNAL_H + +#include "common.h" +#include "pepper.h" +#include + +struct pepper_compositor +{ + char *socket_name; + struct wl_display *display; +}; + +struct pepper_output +{ + pepper_compositor_t *compositor; + + int x; + int y; + int w; + int h; +}; + +struct pepper_client +{ + pepper_compositor_t *compositor; +}; + +struct pepper_surface +{ + void *buffer; +}; + +#endif /* PEPPER_INTERNAL_H */ diff --git a/src/server/server.c b/src/server/server.c index 00aff83..cc2343e 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -1,8 +1,19 @@ -#include -#include +#include "../common.h" +#include int main(int argc, char **argv) { - return 0; + pepper_compositor_t *compositor; + + compositor = pepper_compositor_create("wayland-0", NULL, NULL, NULL, NULL); + + while (1) + { + pepper_compositor_frame(compositor); + } + + pepper_compositor_destroy(compositor); + + return 0; } diff --git a/src/surface.c b/src/surface.c new file mode 100644 index 0000000..75d1c0c --- /dev/null +++ b/src/surface.c @@ -0,0 +1,7 @@ +#include "pepper_internal.h" + +void * +pepper_surface_get_buffer(pepper_surface_t *surface) +{ + return surface->buffer; +} -- 2.7.4