From: Seunghun Lee Date: Fri, 6 Dec 2024 03:26:49 +0000 (+0900) Subject: Rename global resource to surface exporter X-Git-Tag: accepted/tizen/unified/20241210.105106~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=00615172e57183be3ee1d4da63f1a1639f98948c;p=platform%2Fcore%2Fuifw%2Flibds-tizen.git Rename global resource to surface exporter Change-Id: I03f9a5e20b88684cb3617ab19531f223a6e3b3d0 --- diff --git a/include/libds-tizen/global_resource.h b/include/libds-tizen/global_resource.h deleted file mode 100644 index 0f6ca27..0000000 --- a/include/libds-tizen/global_resource.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef LIBDS_TIZEN_GLOBAL_RESOURCE_H -#define LIBDS_TIZEN_GLOBAL_RESOURCE_H - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct ds_tizen_global_resource; - -struct ds_tizen_global_resource_surface; - -struct ds_tizen_global_resource *ds_tizen_global_resource_create(struct wl_display *display); - -void ds_tizen_global_resource_add_destroy_listener(struct ds_tizen_global_resource *global_resource, struct wl_listener *listener); - -void ds_tizen_global_resource_add_new_surface_listener(struct ds_tizen_global_resource *global_resource, struct wl_listener *listener); - -struct ds_tizen_global_resource_surface *ds_tizen_global_resource_get_or_create_surface(struct ds_tizen_global_resource *global_resource, struct ds_surface *ds_surface); - -void ds_tizen_global_resource_surface_add_destroy_listener(struct ds_tizen_global_resource_surface *surface, struct wl_listener *listener); - -struct ds_surface *ds_tizen_global_resource_surface_get_ds_surface(struct ds_tizen_global_resource_surface *surface); - -uint32_t ds_tizen_global_resource_surface_get_id(struct ds_tizen_global_resource_surface *surface); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/libds-tizen/surface_exporter.h b/include/libds-tizen/surface_exporter.h new file mode 100644 index 0000000..e4c994a --- /dev/null +++ b/include/libds-tizen/surface_exporter.h @@ -0,0 +1,34 @@ +#ifndef LIBDS_TIZEN_SURFACE_EXPORTER_H +#define LIBDS_TIZEN_SURFACE_EXPORTER_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct ds_tizen_surface_exporter; + +struct ds_tizen_exported_surface; + +struct ds_tizen_surface_exporter *ds_tizen_surface_exporter_create(struct wl_display *display); + +void ds_tizen_surface_exporter_add_destroy_listener(struct ds_tizen_surface_exporter *exporter, struct wl_listener *listener); + +void ds_tizen_surface_exporter_add_new_surface_listener(struct ds_tizen_surface_exporter *exporter, struct wl_listener *listener); + +struct ds_tizen_exported_surface *ds_tizen_surface_exporter_export_surface(struct ds_tizen_surface_exporter *exporter, struct ds_surface *ds_surface); + +void ds_tizen_exported_surface_add_destroy_listener(struct ds_tizen_exported_surface *surface, struct wl_listener *listener); + +struct ds_surface *ds_tizen_exported_surface_get_surface(struct ds_tizen_exported_surface *surface); + +uint32_t ds_tizen_exported_surface_get_id(struct ds_tizen_exported_surface *surface); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/packaging/libds-tizen.spec b/packaging/libds-tizen.spec index 0de56b1..5b77335 100644 --- a/packaging/libds-tizen.spec +++ b/packaging/libds-tizen.spec @@ -255,20 +255,20 @@ Group: Development/Libraries %description screen-rotation-devel Development package for tizen screen rotation -## libds-tizen-global-resource -%package global-resource -Summary: Library for tizen global resource +## libds-tizen-surface-exporter +%package surface-exporter +Summary: Library for tizen surface exporter Group: Development/Libraries -%description global-resource -Library for tizen global resource +%description surface-exporter +Library for tizen surface exporter -%package global-resource-devel -Summary: Development package for tizen global resource +%package surface-exporter-devel +Summary: Development package for tizen surface exporter Group: Development/Libraries -%description global-resource-devel -Development package for tizen global resource +%description surface-exporter-devel +Development package for tizen surface exporter ## libds-tizen-embedded-compositor %package embedded-compositor @@ -675,20 +675,20 @@ ninja -C builddir install %{_libdir}/libds-tizen-screen-rotation.so %{_bindir}/libds-tizen-screen-rotation-tests -%files global-resource +%files surface-exporter %manifest %{name}.manifest %defattr(-,root,root,-) %license LICENSE -%{_libdir}/libds-tizen-global-resource.so.* +%{_libdir}/libds-tizen-surface-exporter.so.* -%files global-resource-devel +%files surface-exporter-devel %manifest %{name}.manifest %defattr(-,root,root,-) %license LICENSE -%{_includedir}/libds-tizen/global_resource.h -%{_libdir}/pkgconfig/libds-tizen-global-resource.pc -%{_libdir}/libds-tizen-global-resource.so -%{_bindir}/libds-tizen-global-resource-tests +%{_includedir}/libds-tizen/surface_exporter.h +%{_libdir}/pkgconfig/libds-tizen-surface-exporter.pc +%{_libdir}/libds-tizen-surface-exporter.so +%{_bindir}/libds-tizen-surface-exporter-tests %files embedded-compositor %manifest %{name}.manifest diff --git a/src/global_resource/global_resource.c b/src/global_resource/global_resource.c deleted file mode 100644 index 5960d04..0000000 --- a/src/global_resource/global_resource.c +++ /dev/null @@ -1,260 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "util.h" - -#define TIZEN_SURFACE_VERSION 1 - -struct ds_tizen_global_resource { - struct wl_global *global; - - struct wl_list surfaces; - struct wl_listener display_destroy; - - uint32_t id_pool; - - struct { - struct wl_signal destroy; - struct wl_signal new_surface; - } events; -}; - -struct ds_tizen_global_resource_surface { - struct ds_tizen_global_resource *global_resource; - struct ds_surface *surface; - - struct wl_list link; - struct wl_listener surface_destroy; - - uint32_t id; - - struct { - struct wl_signal destroy; - } events; -}; - -static void global_resource_handle_display_destroy(struct wl_listener *listener, void *data); -static void global_resource_bind(struct wl_client *wl_client, void *data, uint32_t version, uint32_t id); -static struct ds_tizen_global_resource_surface *surface_try_from_ds_surface(struct ds_surface *ds_surface); -static struct ds_tizen_global_resource_surface *surface_get_or_create(struct ds_tizen_global_resource *global_resource, struct ds_surface *ds_surface); -static void surface_destroy(struct ds_tizen_global_resource_surface *surface); - -WL_EXPORT struct ds_tizen_global_resource * -ds_tizen_global_resource_create(struct wl_display *display) -{ - struct ds_tizen_global_resource *global_resource; - - global_resource = calloc(1, sizeof *global_resource); - if (!global_resource) - return NULL; - - global_resource->global = wl_global_create(display, &tizen_surface_interface, TIZEN_SURFACE_VERSION, global_resource, global_resource_bind); - if (!global_resource->global) { - free(global_resource); - return NULL; - } - - global_resource->id_pool = 1; // start from 1. 0 is reserved for invalid id. - - wl_signal_init(&global_resource->events.destroy); - wl_signal_init(&global_resource->events.new_surface); - - wl_list_init(&global_resource->surfaces); - - global_resource->display_destroy.notify = global_resource_handle_display_destroy; - wl_display_add_destroy_listener(display, &global_resource->display_destroy); - - ds_inf("Create ds_tizen_global_resource(%p)", global_resource); - - return global_resource; -} - -WL_EXPORT void -ds_tizen_global_resource_add_destroy_listener(struct ds_tizen_global_resource *global_resource, struct wl_listener *listener) -{ - wl_signal_add(&global_resource->events.destroy, listener); -} - -WL_EXPORT void -ds_tizen_global_resource_add_new_surface_listener(struct ds_tizen_global_resource *global_resource, struct wl_listener *listener) -{ - wl_signal_add(&global_resource->events.new_surface, listener); -} - -WL_EXPORT struct ds_tizen_global_resource_surface * -ds_tizen_global_resource_get_or_create_surface(struct ds_tizen_global_resource *global_resource, struct ds_surface *ds_surface) -{ - return surface_get_or_create(global_resource, ds_surface); -} - -WL_EXPORT void -ds_tizen_global_resource_surface_add_destroy_listener(struct ds_tizen_global_resource_surface *surface, struct wl_listener *listener) -{ - wl_signal_add(&surface->events.destroy, listener); -} - -WL_EXPORT struct ds_surface * -ds_tizen_global_resource_surface_get_ds_surface(struct ds_tizen_global_resource_surface *surface) -{ - return surface->surface; -} - -WL_EXPORT uint32_t -ds_tizen_global_resource_surface_get_id(struct ds_tizen_global_resource_surface *surface) -{ - return surface->id; -} - -static void -global_resource_handle_display_destroy(struct wl_listener *listener, void *data) -{ - struct ds_tizen_global_resource *global_resource = wl_container_of(listener, global_resource, display_destroy); - struct ds_tizen_global_resource_surface *surface, *tmp; - - ds_inf("Destroy ds_tizen_global_resource(%p)", global_resource); - - wl_signal_emit(&global_resource->events.destroy, global_resource); - - wl_list_for_each_safe(surface, tmp, &global_resource->surfaces, link) - surface_destroy(surface); - - wl_global_destroy(global_resource->global); - wl_list_remove(&global_resource->display_destroy.link); - free(global_resource); -} - -static void -tizen_resource_handle_destroy(struct wl_client *wl_client, struct wl_resource *resource) -{ - wl_resource_destroy(resource); -} - -static const struct tizen_resource_interface tizen_resource_impl = { - tizen_resource_handle_destroy, -}; - -static void -surface_destroy(struct ds_tizen_global_resource_surface *surface) -{ - ds_inf("Destroy ds_tizen_global_resource_surface(%p) id(%d)", surface, surface->id); - - wl_signal_emit(&surface->events.destroy, surface); - - wl_list_remove(&surface->link); - wl_list_remove(&surface->surface_destroy.link); - free(surface); -} - -static void -surface_handle_ds_surface_destroy(struct wl_listener *listener, void *data) -{ - struct ds_tizen_global_resource_surface *surface = wl_container_of(listener, surface, surface_destroy); - - surface_destroy(surface); -} - -static struct ds_tizen_global_resource_surface * -surface_try_from_ds_surface(struct ds_surface *ds_surface) -{ - struct ds_tizen_global_resource_surface *surface; - struct wl_listener *listener; - - listener = ds_surface_get_destroy_listener(ds_surface, surface_handle_ds_surface_destroy); - if (!listener) - return NULL; - - return wl_container_of(listener, surface, surface_destroy); -} - -static struct ds_tizen_global_resource_surface * -surface_create(struct ds_tizen_global_resource *global_resource, struct ds_surface *ds_surface) -{ - struct ds_tizen_global_resource_surface *surface; - - surface = calloc(1, sizeof(*surface)); - if (!surface) - return NULL; - - wl_signal_init(&surface->events.destroy); - - surface->id = global_resource->id_pool++; - - surface->global_resource = global_resource; - surface->surface = ds_surface; - - surface->surface_destroy.notify = surface_handle_ds_surface_destroy; - ds_surface_add_destroy_listener(ds_surface, &surface->surface_destroy); - - ds_inf("Create ds_tizen_global_resource_surface(%p) id(%p)", surface, surface->id); - - wl_list_insert(&global_resource->surfaces, &surface->link); - wl_signal_emit(&global_resource->events.new_surface, surface); - - return surface; -} - -static struct ds_tizen_global_resource_surface * -surface_get_or_create(struct ds_tizen_global_resource *global_resource, struct ds_surface *ds_surface) -{ - struct ds_tizen_global_resource_surface *surface = surface_try_from_ds_surface(ds_surface); - - if (!surface) - surface = surface_create(global_resource, ds_surface); - - return surface; -} - -static void -tizen_surface_handle_get_tizen_global_resource(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface_resource) -{ - struct ds_tizen_global_resource *global_resource = wl_resource_get_user_data(resource); - struct ds_surface *ds_surface = ds_surface_from_resource(surface_resource); - struct ds_tizen_global_resource_surface *surface; - struct wl_resource *new_resource; - - surface = surface_get_or_create(global_resource, ds_surface); - if (!surface) { - wl_resource_post_no_memory(resource); - return; - } - - new_resource = wl_resource_create(client, &tizen_resource_interface, wl_resource_get_version(resource), id); - if (!new_resource) { - wl_resource_post_no_memory(resource); - return; - } - wl_resource_set_implementation(new_resource, &tizen_resource_impl, NULL, NULL); - - tizen_resource_send_resource_id(new_resource, surface->id); -} - -static void -tizen_surface_handle_destroy(struct wl_client *wl_client, struct wl_resource *resource) -{ - wl_resource_destroy(resource); -} - -static const struct tizen_surface_interface tizen_surface_impl = { - tizen_surface_handle_get_tizen_global_resource, - tizen_surface_handle_destroy, -}; - -static void -global_resource_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id) -{ - struct ds_tizen_global_resource *global_resource = data; - struct wl_resource *resource; - - resource = wl_resource_create(client, &tizen_surface_interface, MIN(version, TIZEN_SURFACE_VERSION), id); - if (!resource) { - wl_client_post_no_memory(client); - return; - } - - wl_resource_set_implementation(resource, &tizen_surface_impl, global_resource, NULL); -} diff --git a/src/global_resource/meson.build b/src/global_resource/meson.build deleted file mode 100644 index 13d5d7a..0000000 --- a/src/global_resource/meson.build +++ /dev/null @@ -1,30 +0,0 @@ -libds_tizen_global_resource_files = [ - 'global_resource.c', -] - -libds_tizen_global_resource_deps = [ - deps_libds_tizen, - dependency('tizen-extension-server', required: true), -] - -lib_libds_tizen_global_resource = shared_library('ds-tizen-global-resource', - libds_tizen_global_resource_files, - dependencies: libds_tizen_global_resource_deps, - include_directories: [ common_inc, include_directories('.'), include_directories('..') ], - version: meson.project_version(), - install: true -) - -deps_libds_tizen_global_resource = declare_dependency( - link_with: lib_libds_tizen_global_resource, - dependencies: libds_tizen_global_resource_deps, - include_directories: [ common_inc, include_directories('.') ], -) - -pkgconfig = import('pkgconfig') -pkgconfig.generate(lib_libds_tizen_global_resource, - version: meson.project_version(), - filebase: 'libds-tizen-global-resource', - name: 'libds-tizen-global-resource', - description: 'tizen resource extension of libds-tizen for tizen platform', -) diff --git a/src/meson.build b/src/meson.build index 2e0d09d..6f46363 100644 --- a/src/meson.build +++ b/src/meson.build @@ -45,7 +45,7 @@ subdir('display_policy') subdir('memory_flusher') subdir('renderer') subdir('screen_rotation') -subdir('global_resource') +subdir('surface_exporter') subdir('embedded_compositor') subdir('input_method') subdir('text_input') @@ -82,7 +82,7 @@ libds_tizen_files = [ 'input_devicemgr/input_devicemgr.c', 'clipboard/clipboard.c', 'memory_flusher/memory_flusher.c', - 'global_resource/global_resource.c', + 'surface_exporter/surface_exporter.c', 'policy/policy.c', 'keyrouter/keyrouter_grab.c', 'keyrouter/keyrouter.c', diff --git a/src/surface_exporter/meson.build b/src/surface_exporter/meson.build new file mode 100644 index 0000000..627b358 --- /dev/null +++ b/src/surface_exporter/meson.build @@ -0,0 +1,30 @@ +libds_tizen_surface_exporter_files = [ + 'surface_exporter.c', +] + +libds_tizen_surface_exporter_deps = [ + deps_libds_tizen, + dependency('tizen-extension-server', required: true), +] + +lib_libds_tizen_surface_exporter = shared_library('ds-tizen-surface-exporter', + libds_tizen_surface_exporter_files, + dependencies: libds_tizen_surface_exporter_deps, + include_directories: [ common_inc, include_directories('.'), include_directories('..') ], + version: meson.project_version(), + install: true +) + +deps_libds_tizen_surface_exporter = declare_dependency( + link_with: lib_libds_tizen_surface_exporter, + dependencies: libds_tizen_surface_exporter_deps, + include_directories: [ common_inc, include_directories('.') ], +) + +pkgconfig = import('pkgconfig') +pkgconfig.generate(lib_libds_tizen_surface_exporter, + version: meson.project_version(), + filebase: 'libds-tizen-surface-exporter', + name: 'libds-tizen-surface-exporter', + description: 'tizen resource extension of libds-tizen for tizen platform', +) diff --git a/src/surface_exporter/surface_exporter.c b/src/surface_exporter/surface_exporter.c new file mode 100644 index 0000000..be6b570 --- /dev/null +++ b/src/surface_exporter/surface_exporter.c @@ -0,0 +1,260 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "util.h" + +#define TIZEN_SURFACE_VERSION 1 + +struct ds_tizen_surface_exporter { + struct wl_global *global; + + struct wl_list surfaces; + struct wl_listener display_destroy; + + uint32_t id_pool; + + struct { + struct wl_signal destroy; + struct wl_signal new_surface; + } events; +}; + +struct ds_tizen_exported_surface { + struct ds_tizen_surface_exporter *exporter; + struct ds_surface *surface; + + struct wl_list link; + struct wl_listener surface_destroy; + + uint32_t id; + + struct { + struct wl_signal destroy; + } events; +}; + +static void exporter_handle_display_destroy(struct wl_listener *listener, void *data); +static void exporter_bind(struct wl_client *wl_client, void *data, uint32_t version, uint32_t id); +static struct ds_tizen_exported_surface *surface_try_from_ds_surface(struct ds_surface *ds_surface); +static struct ds_tizen_exported_surface *surface_get_or_create(struct ds_tizen_surface_exporter *exporter, struct ds_surface *ds_surface); +static void surface_destroy(struct ds_tizen_exported_surface *surface); + +WL_EXPORT struct ds_tizen_surface_exporter * +ds_tizen_surface_exporter_create(struct wl_display *display) +{ + struct ds_tizen_surface_exporter *exporter; + + exporter = calloc(1, sizeof *exporter); + if (!exporter) + return NULL; + + exporter->global = wl_global_create(display, &tizen_surface_interface, TIZEN_SURFACE_VERSION, exporter, exporter_bind); + if (!exporter->global) { + free(exporter); + return NULL; + } + + exporter->id_pool = 1; // start from 1. 0 is reserved for invalid id. + + wl_signal_init(&exporter->events.destroy); + wl_signal_init(&exporter->events.new_surface); + + wl_list_init(&exporter->surfaces); + + exporter->display_destroy.notify = exporter_handle_display_destroy; + wl_display_add_destroy_listener(display, &exporter->display_destroy); + + ds_inf("Create ds_tizen_surface_exporter(%p)", exporter); + + return exporter; +} + +WL_EXPORT void +ds_tizen_surface_exporter_add_destroy_listener(struct ds_tizen_surface_exporter *exporter, struct wl_listener *listener) +{ + wl_signal_add(&exporter->events.destroy, listener); +} + +WL_EXPORT void +ds_tizen_surface_exporter_add_new_surface_listener(struct ds_tizen_surface_exporter *exporter, struct wl_listener *listener) +{ + wl_signal_add(&exporter->events.new_surface, listener); +} + +WL_EXPORT struct ds_tizen_exported_surface * +ds_tizen_surface_exporter_export_surface(struct ds_tizen_surface_exporter *exporter, struct ds_surface *ds_surface) +{ + return surface_get_or_create(exporter, ds_surface); +} + +WL_EXPORT void +ds_tizen_exported_surface_add_destroy_listener(struct ds_tizen_exported_surface *surface, struct wl_listener *listener) +{ + wl_signal_add(&surface->events.destroy, listener); +} + +WL_EXPORT struct ds_surface * +ds_tizen_exported_surface_get_surface(struct ds_tizen_exported_surface *surface) +{ + return surface->surface; +} + +WL_EXPORT uint32_t +ds_tizen_exported_surface_get_id(struct ds_tizen_exported_surface *surface) +{ + return surface->id; +} + +static void +exporter_handle_display_destroy(struct wl_listener *listener, void *data) +{ + struct ds_tizen_surface_exporter *exporter = wl_container_of(listener, exporter, display_destroy); + struct ds_tizen_exported_surface *surface, *tmp; + + ds_inf("Destroy ds_tizen_surface_exporter(%p)", exporter); + + wl_signal_emit(&exporter->events.destroy, exporter); + + wl_list_for_each_safe(surface, tmp, &exporter->surfaces, link) + surface_destroy(surface); + + wl_global_destroy(exporter->global); + wl_list_remove(&exporter->display_destroy.link); + free(exporter); +} + +static void +tizen_resource_handle_destroy(struct wl_client *wl_client, struct wl_resource *resource) +{ + wl_resource_destroy(resource); +} + +static const struct tizen_resource_interface tizen_resource_impl = { + tizen_resource_handle_destroy, +}; + +static void +surface_destroy(struct ds_tizen_exported_surface *surface) +{ + ds_inf("Destroy ds_tizen_exported_surface(%p) id(%d)", surface, surface->id); + + wl_signal_emit(&surface->events.destroy, surface); + + wl_list_remove(&surface->link); + wl_list_remove(&surface->surface_destroy.link); + free(surface); +} + +static void +surface_handle_ds_surface_destroy(struct wl_listener *listener, void *data) +{ + struct ds_tizen_exported_surface *surface = wl_container_of(listener, surface, surface_destroy); + + surface_destroy(surface); +} + +static struct ds_tizen_exported_surface * +surface_try_from_ds_surface(struct ds_surface *ds_surface) +{ + struct ds_tizen_exported_surface *surface; + struct wl_listener *listener; + + listener = ds_surface_get_destroy_listener(ds_surface, surface_handle_ds_surface_destroy); + if (!listener) + return NULL; + + return wl_container_of(listener, surface, surface_destroy); +} + +static struct ds_tizen_exported_surface * +surface_create(struct ds_tizen_surface_exporter *exporter, struct ds_surface *ds_surface) +{ + struct ds_tizen_exported_surface *surface; + + surface = calloc(1, sizeof(*surface)); + if (!surface) + return NULL; + + wl_signal_init(&surface->events.destroy); + + surface->id = exporter->id_pool++; + + surface->exporter = exporter; + surface->surface = ds_surface; + + surface->surface_destroy.notify = surface_handle_ds_surface_destroy; + ds_surface_add_destroy_listener(ds_surface, &surface->surface_destroy); + + ds_inf("Create ds_tizen_exported_surface(%p) id(%p)", surface, surface->id); + + wl_list_insert(&exporter->surfaces, &surface->link); + wl_signal_emit(&exporter->events.new_surface, surface); + + return surface; +} + +static struct ds_tizen_exported_surface * +surface_get_or_create(struct ds_tizen_surface_exporter *exporter, struct ds_surface *ds_surface) +{ + struct ds_tizen_exported_surface *surface = surface_try_from_ds_surface(ds_surface); + + if (!surface) + surface = surface_create(exporter, ds_surface); + + return surface; +} + +static void +tizen_surface_handle_get_tizen_exporter(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface_resource) +{ + struct ds_tizen_surface_exporter *exporter = wl_resource_get_user_data(resource); + struct ds_surface *ds_surface = ds_surface_from_resource(surface_resource); + struct ds_tizen_exported_surface *surface; + struct wl_resource *new_resource; + + surface = surface_get_or_create(exporter, ds_surface); + if (!surface) { + wl_resource_post_no_memory(resource); + return; + } + + new_resource = wl_resource_create(client, &tizen_resource_interface, wl_resource_get_version(resource), id); + if (!new_resource) { + wl_resource_post_no_memory(resource); + return; + } + wl_resource_set_implementation(new_resource, &tizen_resource_impl, NULL, NULL); + + tizen_resource_send_resource_id(new_resource, surface->id); +} + +static void +tizen_surface_handle_destroy(struct wl_client *wl_client, struct wl_resource *resource) +{ + wl_resource_destroy(resource); +} + +static const struct tizen_surface_interface tizen_surface_impl = { + tizen_surface_handle_get_tizen_exporter, + tizen_surface_handle_destroy, +}; + +static void +exporter_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id) +{ + struct ds_tizen_surface_exporter *exporter = data; + struct wl_resource *resource; + + resource = wl_resource_create(client, &tizen_surface_interface, MIN(version, TIZEN_SURFACE_VERSION), id); + if (!resource) { + wl_client_post_no_memory(client); + return; + } + + wl_resource_set_implementation(resource, &tizen_surface_impl, exporter, NULL); +} diff --git a/tests/meson.build b/tests/meson.build index 59201d4..58b8449 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -187,20 +187,20 @@ executable('libds-tizen-screen-rotation-tests', install : true ) -## global-resource tests -tc_global_resource_files = [ +## surface-exporter tests +tc_surface_exporter_files = [ 'tc_main.cpp', - 'tc_global_resource.cpp', + 'tc_surface_exporter.cpp', ] -executable('libds-tizen-global-resource-tests', +executable('libds-tizen-surface-exporter-tests', [ tc_mock_files, - tc_global_resource_files + tc_surface_exporter_files ], dependencies: [ deps_test_common, - deps_libds_tizen_global_resource, + deps_libds_tizen_surface_exporter, dependency('libdrm', required: true), dependency('tizen-extension-client', required: true), ], diff --git a/tests/tc_global_resource.cpp b/tests/tc_global_resource.cpp deleted file mode 100644 index ddf1c84..0000000 --- a/tests/tc_global_resource.cpp +++ /dev/null @@ -1,336 +0,0 @@ -#include "tc_main.h" -#include "mockclient.h" -#include "mockcompositor.h" -#include -#include - -#define TIZEN_SURFACE_VERSION 1 - -class MockGlobalResourceCompositor : public MockCompositor -{ -public: - MockGlobalResourceCompositor() - : MockCompositor(&MockGlobalResourceCompositor::TestSetup, this) - { - // initialize the flags to check - bSurfaceDestroyed = false; - - bDestroyed = false; - } - - ~MockGlobalResourceCompositor() - { - } - - struct ds_surface *GetSurface() const { return mSurface; } - struct ds_tizen_global_resource *GetGlobalResource() const { return mGlobalResource; } - - static void TestSetup(void *data) - { - MockGlobalResourceCompositor *mockComp = - static_cast(data); - Compositor *comp = mockComp->compositor; - - // new surface listener - mockComp->mNewSurfaceListener.notify = - MockGlobalResourceCompositor::NewSurfaceCallback; - mockComp->mNewSurfaceListener.parent = mockComp; - ds_compositor_add_new_surface_listener(comp->compositor, - &mockComp->mNewSurfaceListener); - - mockComp->mGlobalResource = - ds_tizen_global_resource_create(comp->display); - - // destroy listener - mockComp->mDestroyListener.notify = - MockGlobalResourceCompositor::DestroyCallback; - mockComp->mDestroyListener.parent = mockComp; - ds_tizen_global_resource_add_destroy_listener(mockComp->mGlobalResource, - &mockComp->mDestroyListener); - } - - static void NewSurfaceCallback(struct wl_listener *listener, void *data) - { - MockGlobalResourceCompositor *mockComp = - reinterpret_cast(listener)->parent; - struct ds_surface *surface = static_cast(data); - - mockComp->mSurface = surface; - } - - static void DestroyCallback(struct wl_listener *listener, void *data) - { - MockGlobalResourceCompositor *mockComp = - reinterpret_cast(listener)->parent; - - mockComp->bDestroyed = true; - } - -public: - bool bSurfaceDestroyed; - bool bDestroyed; - -private: - struct ds_surface *mSurface; - - struct NewSurfaceListener : ::wl_listener { - MockGlobalResourceCompositor *parent; - }; - NewSurfaceListener mNewSurfaceListener; - - struct DelSurfaceListener : ::wl_listener { - MockGlobalResourceCompositor *parent; - }; - DelSurfaceListener mDelSurfaceListener; - - struct ds_tizen_global_resource *mGlobalResource; - - struct DestroyListener : ::wl_listener { - MockGlobalResourceCompositor *parent; - }; - DestroyListener mDestroyListener; -}; - -class MockGlobalResourceClient : public MockClient -{ -public: - MockGlobalResourceClient() - : compositor_res(nullptr), - tizen_surface_res(nullptr) - {} - MockGlobalResourceClient(const struct wl_registry_listener *listener) - : MockClient(listener, this) - { - } - ~MockGlobalResourceClient() - { - } - - void SetWlCompositor(struct wl_compositor *global_res) - { - compositor_res = global_res; - } - - struct wl_compositor *GetWlCompositor() - { - return compositor_res; - } - - void SetTizenSurface(struct tizen_surface *global_res) - { - tizen_surface_res = global_res; - } - - struct tizen_surface *GetTizenSurface() - { - return tizen_surface_res; - } - -private: - struct wl_compositor *compositor_res; - struct tizen_surface *tizen_surface_res; -}; - -static void -client_registry_cb_global(void *data, struct wl_registry *registry, - uint32_t name, const char *interface, uint32_t version) -{ - MockGlobalResourceClient *client = static_cast(data); - struct wl_compositor *compositor_res; - struct tizen_surface *tizen_surface_res; - - if (!strcmp(interface, "wl_compositor")) { - compositor_res = (struct wl_compositor *)wl_registry_bind(registry, - name, &wl_compositor_interface, 1); - if (compositor_res == nullptr) { - ds_err("wl_registry_bind() failed. wl_compositor resource."); - return; - } - client->SetWlCompositor(compositor_res); - } else if (!strcmp(interface, "tizen_surface")) { - tizen_surface_res = (struct tizen_surface *)wl_registry_bind(registry, - name, &tizen_surface_interface, TIZEN_SURFACE_VERSION); - if (tizen_surface_res == nullptr) { - ds_err("wl_registry_bind() failed. tizen_surface resource."); - return; - } - client->SetTizenSurface(tizen_surface_res); - } -} - -static void -client_registry_cb_global_remove(void *data, struct wl_registry *registry, - uint32_t name) -{ - // This blank line is left intentionally. -} - -static const struct wl_registry_listener registry_listener = { - .global = client_registry_cb_global, - .global_remove = client_registry_cb_global_remove -}; - -static void -tizen_resource_cb_resoruce_id(void *data, struct tizen_resource *resource_res, uint32_t id) -{ - uint32_t *ret = static_cast(data); - - *ret = id; -} - -static const struct -tizen_resource_listener tizen_resource_cb_listener = { - .resource_id = tizen_resource_cb_resoruce_id, -}; - -class GlobalResourceTest : public ::testing::Test -{ -public: - void SetUp(void) override; - void TearDown(void) override; - - MockGlobalResourceCompositor *comp; - MockGlobalResourceClient *client; -}; - -void -GlobalResourceTest::SetUp(void) -{ - comp = new MockGlobalResourceCompositor(); - - client = new MockGlobalResourceClient(®istry_listener); - client->RoundTrip(); - - ASSERT_NE(client->GetWlCompositor(), nullptr); - ASSERT_NE(client->GetTizenSurface(), nullptr); -} - -void -GlobalResourceTest::TearDown(void) -{ - tizen_surface_destroy(client->GetTizenSurface()); - wl_compositor_destroy(client->GetWlCompositor()); - - delete client; - delete comp; -} - -TEST_F(GlobalResourceTest, CheckGlobalResourceIDCreatedByClient) -{ - struct wl_compositor *compositor = client->GetWlCompositor(); - struct tizen_surface *tizen_surface = client->GetTizenSurface(); - struct wl_surface *s1, *s2, *s3; - struct tizen_resource *tizen_resource; - uint32_t sid1 = 0, sid2 = 0, sid3 = 0; - - s1 = wl_compositor_create_surface(compositor); - tizen_resource = tizen_surface_get_tizen_resource(tizen_surface, s1); - tizen_resource_add_listener(tizen_resource, &tizen_resource_cb_listener, &sid1); - client->RoundTrip(); - tizen_resource_destroy(tizen_resource); - - s2 = wl_compositor_create_surface(compositor); - tizen_resource = tizen_surface_get_tizen_resource(tizen_surface, s2); - tizen_resource_add_listener(tizen_resource, &tizen_resource_cb_listener, &sid2); - client->RoundTrip(); - tizen_resource_destroy(tizen_resource); - - ASSERT_EQ(sid1, 1); // first surface id should be 1. - ASSERT_EQ(sid2, 2); // second surface id should be 2. - - wl_surface_destroy(s1); // destroy s1 and get next surface id. - - s3 = wl_compositor_create_surface(compositor); - tizen_resource = tizen_surface_get_tizen_resource(tizen_surface, s3); - tizen_resource_add_listener(tizen_resource, &tizen_resource_cb_listener, &sid3); - client->RoundTrip(); - tizen_resource_destroy(tizen_resource); - - ASSERT_EQ(sid3, 3); // third surface id should be 3. - - wl_surface_destroy(s2); - wl_surface_destroy(s3); -} - -TEST_F(GlobalResourceTest, CheckGlobalResourceIDCreatedByClientWithSameSurface) -{ - struct wl_compositor *compositor = client->GetWlCompositor(); - struct tizen_surface *tizen_surface = client->GetTizenSurface(); - struct wl_surface *surface; - struct tizen_resource *tizen_resource; - uint32_t sid1 = 0, sid2 = 0; - - surface = wl_compositor_create_surface(compositor); - - tizen_resource = tizen_surface_get_tizen_resource(tizen_surface, surface); - tizen_resource_add_listener(tizen_resource, &tizen_resource_cb_listener, &sid1); - client->RoundTrip(); - tizen_resource_destroy(tizen_resource); - - tizen_resource = tizen_surface_get_tizen_resource(tizen_surface, surface); - tizen_resource_add_listener(tizen_resource, &tizen_resource_cb_listener, &sid2); - client->RoundTrip(); - tizen_resource_destroy(tizen_resource); - - ASSERT_EQ(sid1, sid2); - - wl_surface_destroy(surface); -} - -TEST_F(GlobalResourceTest, CheckGlobalResourceIDCreatedByCompositor) -{ - struct wl_compositor *compositor = client->GetWlCompositor(); - struct wl_surface *surface; - struct ds_tizen_global_resource_surface *global_resource_surface; - - surface = wl_compositor_create_surface(compositor); - client->RoundTrip(); - - ASSERT_NE(comp->GetSurface(), nullptr); - - global_resource_surface = ds_tizen_global_resource_get_or_create_surface(comp->GetGlobalResource(), comp->GetSurface()); - ASSERT_NE(global_resource_surface, nullptr); - ASSERT_EQ(ds_tizen_global_resource_surface_get_id(global_resource_surface), 1); - ASSERT_EQ(ds_tizen_global_resource_get_or_create_surface(comp->GetGlobalResource(), comp->GetSurface()), global_resource_surface); - - wl_surface_destroy(surface); -} - -TEST_F(GlobalResourceTest, CheckGlobalResourceIDCreatedByCompositorAndClient) -{ - struct wl_compositor *compositor = client->GetWlCompositor(); - struct tizen_surface *tizen_surface = client->GetTizenSurface(); - struct wl_surface *s1, *s2, *s3; - struct tizen_resource *tizen_resource; - uint32_t sid1 = 0, sid3 = 0; - - s1 = wl_compositor_create_surface(compositor); - tizen_resource = tizen_surface_get_tizen_resource(tizen_surface, s1); - tizen_resource_add_listener(tizen_resource, &tizen_resource_cb_listener, &sid1); - client->RoundTrip(); - tizen_resource_destroy(tizen_resource); - - ASSERT_EQ(sid1, 1); // first surface id should be 1. - - s2 = wl_compositor_create_surface(compositor); - client->RoundTrip(); - - ASSERT_NE(comp->GetSurface(), nullptr); - - struct ds_tizen_global_resource_surface *global_resource_surface = ds_tizen_global_resource_get_or_create_surface(comp->GetGlobalResource(), comp->GetSurface()); - ASSERT_NE(global_resource_surface, nullptr); - ASSERT_EQ(ds_tizen_global_resource_surface_get_id(global_resource_surface), 2); // second surface id should be 2. - - wl_surface_destroy(s2); - - s3 = wl_compositor_create_surface(compositor); - tizen_resource = tizen_surface_get_tizen_resource(tizen_surface, s3); - tizen_resource_add_listener(tizen_resource, &tizen_resource_cb_listener, &sid3); - client->RoundTrip(); - tizen_resource_destroy(tizen_resource); - - ASSERT_EQ(sid3, 3); // third surface id should be 3. - - wl_surface_destroy(s1); - wl_surface_destroy(s3); -} diff --git a/tests/tc_surface_exporter.cpp b/tests/tc_surface_exporter.cpp new file mode 100644 index 0000000..8553a28 --- /dev/null +++ b/tests/tc_surface_exporter.cpp @@ -0,0 +1,336 @@ +#include "tc_main.h" +#include "mockclient.h" +#include "mockcompositor.h" +#include +#include + +#define TIZEN_SURFACE_VERSION 1 + +class MockSurfaceExporterCompositor : public MockCompositor +{ +public: + MockSurfaceExporterCompositor() + : MockCompositor(&MockSurfaceExporterCompositor::TestSetup, this) + { + // initialize the flags to check + bSurfaceDestroyed = false; + + bDestroyed = false; + } + + ~MockSurfaceExporterCompositor() + { + } + + struct ds_surface *GetSurface() const { return mSurface; } + struct ds_tizen_surface_exporter *GetSurfaceExporter() const { return mSurfaceExporter; } + + static void TestSetup(void *data) + { + MockSurfaceExporterCompositor *mockComp = + static_cast(data); + Compositor *comp = mockComp->compositor; + + // new surface listener + mockComp->mNewSurfaceListener.notify = + MockSurfaceExporterCompositor::NewSurfaceCallback; + mockComp->mNewSurfaceListener.parent = mockComp; + ds_compositor_add_new_surface_listener(comp->compositor, + &mockComp->mNewSurfaceListener); + + mockComp->mSurfaceExporter = + ds_tizen_surface_exporter_create(comp->display); + + // destroy listener + mockComp->mDestroyListener.notify = + MockSurfaceExporterCompositor::DestroyCallback; + mockComp->mDestroyListener.parent = mockComp; + ds_tizen_surface_exporter_add_destroy_listener(mockComp->mSurfaceExporter, + &mockComp->mDestroyListener); + } + + static void NewSurfaceCallback(struct wl_listener *listener, void *data) + { + MockSurfaceExporterCompositor *mockComp = + reinterpret_cast(listener)->parent; + struct ds_surface *surface = static_cast(data); + + mockComp->mSurface = surface; + } + + static void DestroyCallback(struct wl_listener *listener, void *data) + { + MockSurfaceExporterCompositor *mockComp = + reinterpret_cast(listener)->parent; + + mockComp->bDestroyed = true; + } + +public: + bool bSurfaceDestroyed; + bool bDestroyed; + +private: + struct ds_surface *mSurface; + + struct NewSurfaceListener : ::wl_listener { + MockSurfaceExporterCompositor *parent; + }; + NewSurfaceListener mNewSurfaceListener; + + struct DelSurfaceListener : ::wl_listener { + MockSurfaceExporterCompositor *parent; + }; + DelSurfaceListener mDelSurfaceListener; + + struct ds_tizen_surface_exporter *mSurfaceExporter; + + struct DestroyListener : ::wl_listener { + MockSurfaceExporterCompositor *parent; + }; + DestroyListener mDestroyListener; +}; + +class MockSurfaceExporterClient : public MockClient +{ +public: + MockSurfaceExporterClient() + : compositor_res(nullptr), + tizen_surface_res(nullptr) + {} + MockSurfaceExporterClient(const struct wl_registry_listener *listener) + : MockClient(listener, this) + { + } + ~MockSurfaceExporterClient() + { + } + + void SetWlCompositor(struct wl_compositor *global_res) + { + compositor_res = global_res; + } + + struct wl_compositor *GetWlCompositor() + { + return compositor_res; + } + + void SetTizenSurface(struct tizen_surface *global_res) + { + tizen_surface_res = global_res; + } + + struct tizen_surface *GetTizenSurface() + { + return tizen_surface_res; + } + +private: + struct wl_compositor *compositor_res; + struct tizen_surface *tizen_surface_res; +}; + +static void +client_registry_cb_global(void *data, struct wl_registry *registry, + uint32_t name, const char *interface, uint32_t version) +{ + MockSurfaceExporterClient *client = static_cast(data); + struct wl_compositor *compositor_res; + struct tizen_surface *tizen_surface_res; + + if (!strcmp(interface, "wl_compositor")) { + compositor_res = (struct wl_compositor *)wl_registry_bind(registry, + name, &wl_compositor_interface, 1); + if (compositor_res == nullptr) { + ds_err("wl_registry_bind() failed. wl_compositor resource."); + return; + } + client->SetWlCompositor(compositor_res); + } else if (!strcmp(interface, "tizen_surface")) { + tizen_surface_res = (struct tizen_surface *)wl_registry_bind(registry, + name, &tizen_surface_interface, TIZEN_SURFACE_VERSION); + if (tizen_surface_res == nullptr) { + ds_err("wl_registry_bind() failed. tizen_surface resource."); + return; + } + client->SetTizenSurface(tizen_surface_res); + } +} + +static void +client_registry_cb_global_remove(void *data, struct wl_registry *registry, + uint32_t name) +{ + // This blank line is left intentionally. +} + +static const struct wl_registry_listener registry_listener = { + .global = client_registry_cb_global, + .global_remove = client_registry_cb_global_remove +}; + +static void +tizen_resource_cb_resoruce_id(void *data, struct tizen_resource *resource_res, uint32_t id) +{ + uint32_t *ret = static_cast(data); + + *ret = id; +} + +static const struct +tizen_resource_listener tizen_resource_cb_listener = { + .resource_id = tizen_resource_cb_resoruce_id, +}; + +class SurfaceExporterTest : public ::testing::Test +{ +public: + void SetUp(void) override; + void TearDown(void) override; + + MockSurfaceExporterCompositor *comp; + MockSurfaceExporterClient *client; +}; + +void +SurfaceExporterTest::SetUp(void) +{ + comp = new MockSurfaceExporterCompositor(); + + client = new MockSurfaceExporterClient(®istry_listener); + client->RoundTrip(); + + ASSERT_NE(client->GetWlCompositor(), nullptr); + ASSERT_NE(client->GetTizenSurface(), nullptr); +} + +void +SurfaceExporterTest::TearDown(void) +{ + tizen_surface_destroy(client->GetTizenSurface()); + wl_compositor_destroy(client->GetWlCompositor()); + + delete client; + delete comp; +} + +TEST_F(SurfaceExporterTest, CheckSurfaceExporterIDCreatedByClient) +{ + struct wl_compositor *compositor = client->GetWlCompositor(); + struct tizen_surface *tizen_surface = client->GetTizenSurface(); + struct wl_surface *s1, *s2, *s3; + struct tizen_resource *tizen_resource; + uint32_t sid1 = 0, sid2 = 0, sid3 = 0; + + s1 = wl_compositor_create_surface(compositor); + tizen_resource = tizen_surface_get_tizen_resource(tizen_surface, s1); + tizen_resource_add_listener(tizen_resource, &tizen_resource_cb_listener, &sid1); + client->RoundTrip(); + tizen_resource_destroy(tizen_resource); + + s2 = wl_compositor_create_surface(compositor); + tizen_resource = tizen_surface_get_tizen_resource(tizen_surface, s2); + tizen_resource_add_listener(tizen_resource, &tizen_resource_cb_listener, &sid2); + client->RoundTrip(); + tizen_resource_destroy(tizen_resource); + + ASSERT_EQ(sid1, 1); // first surface id should be 1. + ASSERT_EQ(sid2, 2); // second surface id should be 2. + + wl_surface_destroy(s1); // destroy s1 and get next surface id. + + s3 = wl_compositor_create_surface(compositor); + tizen_resource = tizen_surface_get_tizen_resource(tizen_surface, s3); + tizen_resource_add_listener(tizen_resource, &tizen_resource_cb_listener, &sid3); + client->RoundTrip(); + tizen_resource_destroy(tizen_resource); + + ASSERT_EQ(sid3, 3); // third surface id should be 3. + + wl_surface_destroy(s2); + wl_surface_destroy(s3); +} + +TEST_F(SurfaceExporterTest, CheckSurfaceExporterIDCreatedByClientWithSameSurface) +{ + struct wl_compositor *compositor = client->GetWlCompositor(); + struct tizen_surface *tizen_surface = client->GetTizenSurface(); + struct wl_surface *surface; + struct tizen_resource *tizen_resource; + uint32_t sid1 = 0, sid2 = 0; + + surface = wl_compositor_create_surface(compositor); + + tizen_resource = tizen_surface_get_tizen_resource(tizen_surface, surface); + tizen_resource_add_listener(tizen_resource, &tizen_resource_cb_listener, &sid1); + client->RoundTrip(); + tizen_resource_destroy(tizen_resource); + + tizen_resource = tizen_surface_get_tizen_resource(tizen_surface, surface); + tizen_resource_add_listener(tizen_resource, &tizen_resource_cb_listener, &sid2); + client->RoundTrip(); + tizen_resource_destroy(tizen_resource); + + ASSERT_EQ(sid1, sid2); + + wl_surface_destroy(surface); +} + +TEST_F(SurfaceExporterTest, CheckSurfaceExporterIDCreatedByCompositor) +{ + struct wl_compositor *compositor = client->GetWlCompositor(); + struct wl_surface *surface; + struct ds_tizen_exported_surface *exported_surface; + + surface = wl_compositor_create_surface(compositor); + client->RoundTrip(); + + ASSERT_NE(comp->GetSurface(), nullptr); + + exported_surface = ds_tizen_surface_exporter_export_surface(comp->GetSurfaceExporter(), comp->GetSurface()); + ASSERT_NE(exported_surface, nullptr); + ASSERT_EQ(ds_tizen_exported_surface_get_id(exported_surface), 1); + ASSERT_EQ(ds_tizen_surface_exporter_export_surface(comp->GetSurfaceExporter(), comp->GetSurface()), exported_surface); + + wl_surface_destroy(surface); +} + +TEST_F(SurfaceExporterTest, CheckSurfaceExporterIDCreatedByCompositorAndClient) +{ + struct wl_compositor *compositor = client->GetWlCompositor(); + struct tizen_surface *tizen_surface = client->GetTizenSurface(); + struct wl_surface *s1, *s2, *s3; + struct tizen_resource *tizen_resource; + uint32_t sid1 = 0, sid3 = 0; + + s1 = wl_compositor_create_surface(compositor); + tizen_resource = tizen_surface_get_tizen_resource(tizen_surface, s1); + tizen_resource_add_listener(tizen_resource, &tizen_resource_cb_listener, &sid1); + client->RoundTrip(); + tizen_resource_destroy(tizen_resource); + + ASSERT_EQ(sid1, 1); // first surface id should be 1. + + s2 = wl_compositor_create_surface(compositor); + client->RoundTrip(); + + ASSERT_NE(comp->GetSurface(), nullptr); + + struct ds_tizen_exported_surface *exported_surface = ds_tizen_surface_exporter_export_surface(comp->GetSurfaceExporter(), comp->GetSurface()); + ASSERT_NE(exported_surface, nullptr); + ASSERT_EQ(ds_tizen_exported_surface_get_id(exported_surface), 2); // second surface id should be 2. + + wl_surface_destroy(s2); + + s3 = wl_compositor_create_surface(compositor); + tizen_resource = tizen_surface_get_tizen_resource(tizen_surface, s3); + tizen_resource_add_listener(tizen_resource, &tizen_resource_cb_listener, &sid3); + client->RoundTrip(); + tizen_resource_destroy(tizen_resource); + + ASSERT_EQ(sid3, 3); // third surface id should be 3. + + wl_surface_destroy(s1); + wl_surface_destroy(s3); +}