common: Implementation starting point
authorTaekyun Kim <tkq.kim@samsung.com>
Mon, 2 Mar 2015 10:51:06 +0000 (19:51 +0900)
committerTaekyun Kim <tkq.kim@samsung.com>
Fri, 19 Jun 2015 09:06:39 +0000 (18:06 +0900)
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
src/client.c [new file with mode: 0644]
src/common.h [new file with mode: 0644]
src/compositor.c
src/output.c [new file with mode: 0644]
src/pepper.h
src/pepper_internal.h [new file with mode: 0644]
src/server/server.c
src/surface.c [new file with mode: 0644]

index 4f81c1d..e5c763f 100644 (file)
@@ -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 (file)
index 0000000..7c36364
--- /dev/null
@@ -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 (file)
index 0000000..133b230
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef COMMON_H
+#define COMMON_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* TODO: Change logging destination. */
+
+#define PEPPER_ERROR(fmt, ...)                     \
+    do {                                           \
+       printf(fmt, ##__VA_ARGS__);                 \
+    } while (0)
+
+
+#endif /* COMMON_H */
index e69de29..2ac148e 100644 (file)
@@ -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 (file)
index 0000000..4576756
--- /dev/null
@@ -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;
+}
index e69de29..742c0a2 100644 (file)
@@ -0,0 +1,71 @@
+#ifndef PEPPER_H
+#define PEPPER_H
+
+#include <stdint.h>
+
+#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 (file)
index 0000000..59a9214
--- /dev/null
@@ -0,0 +1,34 @@
+#ifndef PEPPER_INTERNAL_H
+#define PEPPER_INTERNAL_H
+
+#include "common.h"
+#include "pepper.h"
+#include <wayland-server.h>
+
+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 */
index 00aff83..cc2343e 100644 (file)
@@ -1,8 +1,19 @@
-#include <stdio.h>
-#include <stdlib.h>
+#include "../common.h"
+#include <pepper.h>
 
 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 (file)
index 0000000..75d1c0c
--- /dev/null
@@ -0,0 +1,7 @@
+#include "pepper_internal.h"
+
+void *
+pepper_surface_get_buffer(pepper_surface_t *surface)
+{
+    return surface->buffer;
+}