implement ds_tizen_embedded_compsitor 01/279401/1
authorSooChan Lim <sc1.lim@samsung.com>
Mon, 8 Aug 2022 01:40:04 +0000 (10:40 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Tue, 9 Aug 2022 00:28:27 +0000 (09:28 +0900)
This implement the server impelmentation for tizen_embedded_compositor
interface.

Change-Id: Icd0c42ad490397616bd91c023a3ca0661f0a3e5a

include/libds-tizen/embedded_compositor.h [new file with mode: 0644]
packaging/libds-tizen.spec
src/embedded_compositor/embedded_compositor.c [new file with mode: 0644]
src/embedded_compositor/meson.build [new file with mode: 0644]
src/meson.build

diff --git a/include/libds-tizen/embedded_compositor.h b/include/libds-tizen/embedded_compositor.h
new file mode 100644 (file)
index 0000000..adcabfa
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef LIBDS_TIZEN_EMBEDDED_COMPOSITOR_H
+#define LIBDS_TIZEN_EMBEDDED_COMPOSITOR_H
+
+#include <wayland-server.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct ds_tizen_embedded_compositor;
+
+struct ds_tizen_embedded_compositor *
+ds_tizen_embedded_compositor_create(struct wl_display *display);
+
+void
+ds_tizen_embedded_compositor_add_destroy_listener(
+        struct ds_tizen_embedded_compositor *embedded_compositor,
+        struct wl_listener *listener);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index ceb30a2..64a9b1d 100644 (file)
@@ -246,6 +246,21 @@ Group:   Development/Libraries
 %description global-resource-devel
 Development package for tizen global resource
 
+## libds-tizen-embedded-compositor
+%package embedded-compositor
+Summary: Library for tizen embedded compositor
+Group:   Development/Libraries
+
+%description embedded-compositor
+Library for tizen embedded compositor
+
+%package embedded-compositor-devel
+Summary: Development package for tizen embedded compositor
+Group:   Development/Libraries
+
+%description embedded-compositor-devel
+Development package for tizen embedded compositor
+
 %prep
 %setup -q
 cp %{SOURCE1001} .
@@ -476,3 +491,17 @@ ninja -C builddir install
 %{_libdir}/pkgconfig/libds-tizen-global-resource.pc
 %{_libdir}/libds-tizen-global-resource.so
 %{_bindir}/libds-tizen-global-resource-tests
+
+%files embedded-compositor
+%manifest %{name}.manifest
+%defattr(-,root,root,-)
+%license LICENSE
+%{_libdir}/libds-tizen-embedded-compositor.so.*
+
+%files embedded-compositor-devel
+%manifest %{name}.manifest
+%defattr(-,root,root,-)
+%license LICENSE
+%{_includedir}/libds-tizen/embedded_compositor.h
+%{_libdir}/pkgconfig/libds-tizen-embedded-compositor.pc
+%{_libdir}/libds-tizen-embedded-compositor.so
diff --git a/src/embedded_compositor/embedded_compositor.c b/src/embedded_compositor/embedded_compositor.c
new file mode 100644 (file)
index 0000000..29f3bb9
--- /dev/null
@@ -0,0 +1,180 @@
+#include <assert.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <wayland-server.h>
+#include <tizen-extension-server-protocol.h>
+#include <libds/log.h>
+
+#include "util.h"
+#include "libds-tizen/embedded_compositor.h"
+
+#define TIZEN_EMBEDDED_COMPOSITOR_VERSION 1
+
+struct ds_tizen_embedded_compositor
+{
+    struct wl_global *global;
+
+    struct wl_listener destroy;
+
+    struct {
+        struct wl_signal destroy;
+    } events;
+};
+
+struct ds_tizen_embedded_compositor_client
+{
+    struct ds_tizen_embedded_compositor *embedded_compositor;
+
+    struct wl_resource *resource;
+    struct wl_client *wl_client;
+};
+
+static void embedded_compositor_handle_display_destroy(struct wl_listener *listener,
+        void *data);
+
+static void embedded_compositor_bind(struct wl_client *wl_client, void *data,
+        uint32_t version, uint32_t id);
+
+WL_EXPORT struct ds_tizen_embedded_compositor *
+ds_tizen_embedded_compositor_create(struct wl_display *display)
+{
+    struct ds_tizen_embedded_compositor *embedded_compositor;
+
+    embedded_compositor = calloc(1, sizeof *embedded_compositor);
+    if (!embedded_compositor) {
+        ds_err("calloc() failed.");
+        return NULL;
+    }
+
+    embedded_compositor->global = wl_global_create(display, &tizen_embedded_compositor_interface,
+            TIZEN_EMBEDDED_COMPOSITOR_VERSION, embedded_compositor, embedded_compositor_bind);
+    if (!embedded_compositor->global) {
+        ds_err("wl_global_create() failed. tizen_embedded_compositor_interface");
+        free(embedded_compositor);
+        return NULL;
+    }
+
+    embedded_compositor->destroy.notify = embedded_compositor_handle_display_destroy;
+    wl_display_add_destroy_listener(display, &embedded_compositor->destroy);
+
+    wl_signal_init(&embedded_compositor->events.destroy);
+
+    ds_inf("Global created: tizen_embedded_compositor(%p)", embedded_compositor);
+
+    return embedded_compositor;
+}
+
+WL_EXPORT void
+ds_tizen_embedded_compositor_add_destroy_listener(
+        struct ds_tizen_embedded_compositor *embedded_compositor,
+        struct wl_listener *listener)
+{
+    wl_signal_add(&embedded_compositor->events.destroy, listener);
+}
+
+static void
+embedded_compositor_handle_display_destroy(struct wl_listener *listener, void *data)
+{
+    struct ds_tizen_embedded_compositor *embedded_compositor;
+
+    embedded_compositor = wl_container_of(listener, embedded_compositor, destroy);
+
+    ds_inf("Global destroy: embedded_compositor(%p)", embedded_compositor);
+
+    wl_signal_emit(&embedded_compositor->events.destroy, embedded_compositor);
+    wl_list_remove(&embedded_compositor->destroy.link);
+    wl_global_destroy(embedded_compositor->global);
+    free(embedded_compositor);
+}
+
+static void
+embedded_compositor_handle_get_socket(struct wl_client *wl_client,
+    struct wl_resource *resource)
+{
+    struct ds_tizen_embedded_compositor_client *client;
+    int sock_fd=-1;
+    pid_t pid = 0;
+
+    ds_inf("tizen_embedded_compositor: get_socket");
+
+    client = wl_resource_get_user_data(resource);
+
+    wl_client_get_credentials(client->wl_client, &pid, NULL, NULL);
+
+    sock_fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
+    if (sock_fd < 0) {
+        ds_err("Could not create socket: %m, (client=%p, pid=%d)", client, pid);
+        return;
+     }
+
+    tizen_embedded_compositor_send_socket(resource, sock_fd);
+
+    ds_inf("tizen_embedded_compositor: (sock_fd,%d) sent! (client,%p) (pid,%d)",
+        sock_fd, client, pid);
+
+    close(sock_fd);
+}
+
+static void
+embedded_compositor_handle_destroy(struct wl_client *wl_client,
+    struct wl_resource *resource)
+{
+    wl_resource_destroy(resource);
+}
+
+static const struct tizen_embedded_compositor_interface embedded_compositor_impl =
+{
+   embedded_compositor_handle_get_socket,
+   embedded_compositor_handle_destroy,
+};
+
+static void
+_tizen_embedded_compositor_client_handle_destroy(struct wl_resource *resource)
+{
+    struct ds_tizen_embedded_compositor_client *client;
+
+    client = wl_resource_get_user_data(resource);
+
+    ds_inf("_tizen_embedded_compositor_client_handle_destroy (client:%p)", client);
+
+    free(client);
+}
+
+static void
+embedded_compositor_bind(struct wl_client *wl_client, void *data, uint32_t version,
+        uint32_t id)
+{
+    struct ds_tizen_embedded_compositor *embedded_compositor = data;
+    struct ds_tizen_embedded_compositor_client *client;
+
+    client = calloc(1, sizeof *client);
+    if (client == NULL) {
+        ds_err("calloc() failed. tizen_embedded_compositor");
+        wl_client_post_no_memory(wl_client);
+        return;
+    }
+
+    ds_inf("tizen_embedded_compositor_client binds. (client:%p)", client);
+
+    client->embedded_compositor = embedded_compositor;
+    client->wl_client = wl_client;
+
+    client->resource = wl_resource_create(wl_client,
+            &tizen_embedded_compositor_interface,
+            MIN(version, TIZEN_EMBEDDED_COMPOSITOR_VERSION), id);
+
+    if (client->resource == NULL) {
+        ds_err("tizen_embedded_compositor : wl_resource_create() failed.");
+        free(client);
+        wl_client_post_no_memory(wl_client);
+        return;
+    }
+
+    wl_resource_set_implementation(client->resource, &embedded_compositor_impl,
+            client, _tizen_embedded_compositor_client_handle_destroy);
+}
diff --git a/src/embedded_compositor/meson.build b/src/embedded_compositor/meson.build
new file mode 100644 (file)
index 0000000..632d23c
--- /dev/null
@@ -0,0 +1,29 @@
+libds_tizen_embedded_compositor_files = [
+  'embedded_compositor.c',
+]
+
+libds_tizen_embedded_compositor_deps = [
+  deps_libds_tizen,
+  dependency('tizen-extension-server', required: true),
+]
+
+lib_libds_tizen_embedded_compositor = shared_library('ds-tizen-embedded-compositor', libds_tizen_embedded_compositor_files,
+  dependencies: libds_tizen_embedded_compositor_deps,
+  include_directories: [ common_inc, include_directories('.'), include_directories('..') ],
+  version: meson.project_version(),
+  install: true
+)
+
+deps_libds_tizen_embedded_compositor = declare_dependency(
+  link_with: lib_libds_tizen_embedded_compositor,
+  dependencies: libds_tizen_embedded_compositor_deps,
+  include_directories: [ common_inc, include_directories('.') ],
+)
+
+pkgconfig = import('pkgconfig')
+pkgconfig.generate(lib_libds_tizen_embedded_compositor,
+  version: meson.project_version(),
+  filebase: 'libds-tizen-embedded-compositor',
+  name: 'libds-tizen-embedded-compositor',
+  description: 'tizen memory flusher extension of libds-tizen for tizen platform',
+)
index 66f10c6..a1ba1ab 100644 (file)
@@ -41,3 +41,4 @@ subdir('memory_flusher')
 subdir('renderer')
 subdir('screen_rotation')
 subdir('global_resource')
+subdir('embedded_compositor')