impelement libds-tizen-screen-rotation 34/278634/1
authorSooChan Lim <sc1.lim@samsung.com>
Thu, 21 Jul 2022 08:19:58 +0000 (17:19 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Fri, 22 Jul 2022 14:00:41 +0000 (23:00 +0900)
This is the server implementation for tizen_screen_rotation protocol.

Change-Id: I5c7a71543edf8e6e12c6616cfaef8e7dec43fc01

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

diff --git a/include/libds-tizen/screen_rotation.h b/include/libds-tizen/screen_rotation.h
new file mode 100644 (file)
index 0000000..ad19b15
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef LIBDS_TIZEN_SCREEN_ROTATION_H
+#define LIBDS_TIZEN_SCREEN_ROTATION_H
+
+#include <stdint.h>
+#include <wayland-server.h>
+#include <libds/surface.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct ds_tizen_screen_rotation;
+struct ds_tizen_screen_rotation_info;
+
+struct ds_tizen_screen_rotation *
+ds_tizen_screen_rotation_create(struct wl_display *display);
+
+void
+ds_tizen_screen_rotation_add_destroy_listener(
+        struct ds_tizen_screen_rotation *screen_rotation,
+        struct wl_listener *listener);
+
+void
+ds_tizen_screen_rotation_add_get_ignore_output_transform_info_listener(
+        struct ds_tizen_screen_rotation *screen_rotation,
+        struct wl_listener *listener);
+
+void
+ds_tizen_screen_rotation_info_add_destroy_listener(
+        struct ds_tizen_screen_rotation_info *info,
+        struct wl_listener *listener);
+
+struct ds_surface *
+ds_tizen_screen_rotation_info_get_surface(
+        struct ds_tizen_screen_rotation_info *info);
+
+void
+ds_tizen_screen_rotation_send_ignore_output_transform(
+        struct ds_tizen_screen_rotation_info *info, uint32_t ignore);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index 38942c7..0dfbbd8 100644 (file)
@@ -216,6 +216,21 @@ Group:   Development/Libraries
 %description renderer-devel
 Development package for tizen renderer
 
+## libds-tizen-screen-rotation
+%package screen-rotation
+Summary: Library for tizen screen rotation
+Group:   Development/Libraries
+
+%description screen-rotation
+Library for tizen screen rotation
+
+%package screen-rotation-devel
+Summary: Development package for tizen screen rotation
+Group:   Development/Libraries
+
+%description screen-rotation-devel
+Development package for tizen screen rotation
+
 %prep
 %setup -q
 cp %{SOURCE1001} .
@@ -417,3 +432,17 @@ ninja -C builddir install
 %{_libdir}/pkgconfig/libds-tizen-renderer.pc
 %{_libdir}/libds-tizen-renderer.so
 %{_bindir}/libds-tizen-renderer-tests
+
+%files screen-rotation
+%manifest %{name}.manifest
+%defattr(-,root,root,-)
+%license LICENSE
+%{_libdir}/libds-tizen-screen-rotation.so.*
+
+%files screen-rotation-devel
+%manifest %{name}.manifest
+%defattr(-,root,root,-)
+%license LICENSE
+%{_includedir}/libds-tizen/screen_rotation.h
+%{_libdir}/pkgconfig/libds-tizen-screen-rotation.pc
+%{_libdir}/libds-tizen-screen-rotation.so
index a8df30b..4fee86e 100644 (file)
@@ -39,3 +39,4 @@ subdir('launch')
 subdir('display_policy')
 subdir('memory_flusher')
 subdir('renderer')
+subdir('screen_rotation')
diff --git a/src/screen_rotation/meson.build b/src/screen_rotation/meson.build
new file mode 100644 (file)
index 0000000..4261a97
--- /dev/null
@@ -0,0 +1,29 @@
+libds_tizen_screen_rotation_files = [
+  'screen_rotation.c',
+]
+
+libds_tizen_screen_rotation_deps = [
+  deps_libds_tizen,
+  dependency('tizen-extension-server', required: true),
+]
+
+lib_libds_tizen_screen_rotation = shared_library('ds-tizen-screen-rotation', libds_tizen_screen_rotation_files,
+  dependencies: libds_tizen_screen_rotation_deps,
+  include_directories: [ common_inc, include_directories('.'), include_directories('..') ],
+  version: meson.project_version(),
+  install: true
+)
+
+deps_libds_tizen_screen_rotation = declare_dependency(
+  link_with: lib_libds_tizen_screen_rotation,
+  dependencies: libds_tizen_screen_rotation_deps,
+  include_directories: [ common_inc, include_directories('.') ],
+)
+
+pkgconfig = import('pkgconfig')
+pkgconfig.generate(lib_libds_tizen_screen_rotation,
+  version: meson.project_version(),
+  filebase: 'libds-tizen-screen-rotation',
+  name: 'libds-tizen-screen-rotation',
+  description: 'tizen screen_rotation extension of libds-tizen for tizen platform',
+)
diff --git a/src/screen_rotation/screen_rotation.c b/src/screen_rotation/screen_rotation.c
new file mode 100644 (file)
index 0000000..e4ddb6b
--- /dev/null
@@ -0,0 +1,294 @@
+#include <assert.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <wayland-server.h>
+#include <tizen-extension-server-protocol.h>
+#include <libds/log.h>
+
+#include "util.h"
+#include "libds-tizen/screen_rotation.h"
+
+#define TIZEN_SCREEN_ROTATION_VERSION 1
+
+struct ds_tizen_screen_rotation
+{
+    struct wl_global *global;
+
+    struct wl_list clients;
+
+    struct wl_listener destroy;
+
+    struct {
+        struct wl_signal destroy;
+        struct wl_signal get_ignore_output_transfrom;
+    } events;
+};
+
+struct ds_tizen_screen_rotation_client
+{
+    struct ds_tizen_screen_rotation *screen_rotation;
+
+    struct wl_resource *resource;
+    struct wl_client *wl_client;
+
+    struct wl_list infos;
+
+    struct {
+        struct wl_signal destroy;
+    } events;
+
+    struct wl_list link; // ds_tizen_screen_rotation::clients
+};
+
+struct ds_tizen_screen_rotation_info
+{
+    struct ds_tizen_screen_rotation_client *client;
+
+    struct ds_surface *surface;
+
+    struct wl_list link; // ds_tizen_screen_rotation_client::infos
+};
+
+static void screen_rotation_handle_display_destroy(struct wl_listener *listener,
+        void *data);
+
+static void screen_rotation_bind(struct wl_client *wl_client, void *data,
+        uint32_t version, uint32_t id);
+
+static struct ds_tizen_screen_rotation_info *tizen_screen_rotation_client_find_info(
+    struct ds_tizen_screen_rotation_client *client,
+    struct ds_surface *surface);
+
+static struct ds_tizen_screen_rotation_info *tizen_screen_rotation_client_get_info(
+        struct ds_tizen_screen_rotation_client *client,
+        struct ds_surface *surface);
+
+WL_EXPORT struct ds_tizen_screen_rotation *
+ds_tizen_screen_rotation_create(struct wl_display *display)
+{
+    struct ds_tizen_screen_rotation *screen_rotation;
+
+    screen_rotation = calloc(1, sizeof *screen_rotation);
+    if (!screen_rotation) {
+        ds_err("calloc() failed.");
+        return NULL;
+    }
+
+    screen_rotation->global = wl_global_create(display,
+            &tizen_screen_rotation_interface, TIZEN_SCREEN_ROTATION_VERSION,
+            screen_rotation, screen_rotation_bind);
+    if (!screen_rotation->global) {
+        ds_err("wl_global_create() failed. tizen_screen_rotation_interface");
+        free(screen_rotation);
+        return NULL;
+    }
+
+    wl_list_init(&screen_rotation->clients);
+
+    screen_rotation->destroy.notify = screen_rotation_handle_display_destroy;
+    wl_display_add_destroy_listener(display, &screen_rotation->destroy);
+
+    wl_signal_init(&screen_rotation->events.destroy);
+    wl_signal_init(&screen_rotation->events.get_ignore_output_transfrom);
+
+       ds_inf("Global created: tizen_screen_rotation(%p)", screen_rotation);
+
+    return screen_rotation;
+}
+
+WL_EXPORT void
+ds_tizen_screen_rotation_add_destroy_listener(
+    struct ds_tizen_screen_rotation *screen_rotation,
+    struct wl_listener *listener)
+{
+    wl_signal_add(&screen_rotation->events.destroy, listener);
+}
+
+WL_EXPORT void
+ds_tizen_screen_rotation_add_get_ignore_output_transform_info_listener(
+    struct ds_tizen_screen_rotation *screen_rotation,
+    struct wl_listener *listener)
+{
+    wl_signal_add(&screen_rotation->events.get_ignore_output_transfrom,
+        listener);
+}
+
+WL_EXPORT void
+ds_tizen_screen_rotation_info_add_destroy_listener(
+        struct ds_tizen_screen_rotation_info *info,
+        struct wl_listener *listener)
+{
+    wl_signal_add(&info->client->events.destroy, listener);
+}
+
+WL_EXPORT struct ds_surface *
+ds_tizen_screen_rotation_info_get_surface(
+        struct ds_tizen_screen_rotation_info *info)
+{
+    return info->surface;
+}
+
+WL_EXPORT void
+ds_tizen_screen_rotation_send_ignore_output_transform(
+    struct ds_tizen_screen_rotation_info *info, uint32_t ignore)
+{
+    tizen_screen_rotation_send_ignore_output_transform(info->client->resource,
+        ds_surface_get_wl_resource(info->surface), ignore);
+}
+
+static struct ds_tizen_screen_rotation_info *
+tizen_screen_rotation_client_find_info(struct ds_tizen_screen_rotation_client *client,
+    struct ds_surface *surface)
+{
+    struct ds_tizen_screen_rotation_info *info;
+
+    wl_list_for_each(info, &client->infos, link) {
+        if (surface == info->surface)
+            return info;
+    }
+
+    return NULL;
+}
+
+static struct ds_tizen_screen_rotation_info *
+tizen_screen_rotation_client_get_info(struct ds_tizen_screen_rotation_client *client,
+    struct ds_surface *surface)
+{
+    struct ds_tizen_screen_rotation_info *info;
+
+    info = tizen_screen_rotation_client_find_info(client, surface);
+    if (info)
+        return info;
+
+    info = calloc(1, sizeof *info);
+    if (info == NULL) {
+        ds_err("calloc() failed. tizen_screen_rotation");
+        return NULL;
+    }
+
+    info->client = client;
+    info->surface = surface;
+
+    wl_list_insert(&client->infos, &info->link);
+
+    return info;
+}
+
+static void
+screen_rotation_handle_display_destroy(struct wl_listener *listener, void *data)
+{
+    struct ds_tizen_screen_rotation *screen_rotation;
+
+    screen_rotation = wl_container_of(listener, screen_rotation, destroy);
+
+    ds_inf("Global destroy: screen_rotation(%p)", screen_rotation);
+
+    wl_signal_emit(&screen_rotation->events.destroy, screen_rotation);
+    wl_list_remove(&screen_rotation->destroy.link);
+    wl_global_destroy(screen_rotation->global);
+    free(screen_rotation);
+}
+
+static void
+screen_rotation_handle_destroy(struct wl_client *wl_client,
+    struct wl_resource *resource)
+{
+    struct ds_tizen_screen_rotation_client *client;
+
+    client = wl_resource_get_user_data(resource);
+
+    if (!wl_list_empty(&client->infos)) {
+        ds_err("tizen_screen_rotation was destroyed before children");
+        return;
+    }
+
+    wl_resource_destroy(resource);
+}
+
+static void
+screen_rotation_handle_get_ignore_output_transfrom(struct wl_client *wl_client,
+    struct wl_resource *resource, struct wl_resource *surface_resource)
+{
+    struct ds_tizen_screen_rotation_client *client;
+    struct ds_tizen_screen_rotation_info *info;
+    struct ds_surface *surface;
+
+    ds_inf("tizen_screen_rotation: get_ignore_output_transfrom");
+
+    client = wl_resource_get_user_data(resource);
+    surface = ds_surface_from_resource(surface_resource);
+
+    info = tizen_screen_rotation_client_get_info(client, surface);
+    if (info == NULL) {
+        ds_err("tizen_screen_rotation_client_get_info() failed. tizen_screen_rotation");
+        wl_client_post_no_memory(wl_client);
+        return;
+    }
+
+    wl_signal_emit(&client->screen_rotation->events.get_ignore_output_transfrom, info);
+}
+
+static const struct tizen_screen_rotation_interface screen_rotation_impl =
+{
+   screen_rotation_handle_get_ignore_output_transfrom,
+   screen_rotation_handle_destroy,
+};
+
+static void
+_tizen_screen_rotation_client_handle_destroy(struct wl_resource *resource)
+{
+    struct ds_tizen_screen_rotation_client *client;
+    struct ds_tizen_screen_rotation_info *info, *tmp;
+
+    client = wl_resource_get_user_data(resource);
+
+    ds_inf("_tizen_screen_rotation_client_handle_destroy (client:%p)", client);
+
+    wl_list_for_each_safe(info, tmp, &client->infos, link) {
+        wl_signal_emit(&client->events.destroy, info);
+        wl_list_remove(&info->link);
+        free(info);
+    }
+
+    wl_list_remove(&client->link);
+    free(client);
+}
+
+static void
+screen_rotation_bind(struct wl_client *wl_client, void *data, uint32_t version,
+        uint32_t id)
+{
+    struct ds_tizen_screen_rotation *screen_rotation = data;
+    struct ds_tizen_screen_rotation_client *client;
+
+    client = calloc(1, sizeof *client);
+    if (client == NULL) {
+        ds_err("calloc() failed. tizen_screen_rotation");
+        wl_client_post_no_memory(wl_client);
+        return;
+    }
+
+    ds_inf("tizen_screen_rotation_client binds. (client:%p)", client);
+
+    client->screen_rotation = screen_rotation;
+    client->wl_client = wl_client;
+
+    wl_list_init(&client->infos);
+
+    client->resource = wl_resource_create(wl_client, &tizen_screen_rotation_interface,
+            MIN(version, TIZEN_SCREEN_ROTATION_VERSION), id);
+
+    if (client->resource == NULL) {
+        ds_err("tizen_screen_rotation : wl_resource_create() failed.");
+        free(client);
+        wl_client_post_no_memory(wl_client);
+        return;
+    }
+
+    wl_resource_set_implementation(client->resource, &screen_rotation_impl, client,
+            _tizen_screen_rotation_client_handle_destroy);
+
+    wl_signal_init(&client->events.destroy);
+
+    wl_list_insert(&screen_rotation->clients, &client->link);
+}