From 5ec24d41364bb5476d6e80e496d925ee7365fe67 Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Mon, 8 May 2017 15:11:20 +0900 Subject: [PATCH] tpl_wayland_egl_thread: Separated the file for testing worker thread. Change-Id: Ie00ad8ca16d88b6cecccbd8ba3e86f116d21d6c2 Signed-off-by: joonbum.ko --- Makefile | 14 ++-- packaging/libtpl-egl.spec | 27 +++--- src/tpl_utils.h | 11 +++ src/tpl_wayland_egl_thread.c | 114 +------------------------ worker_test/Makefile | 39 +++++++++ worker_test/worker_test.c | 194 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 266 insertions(+), 133 deletions(-) create mode 100644 worker_test/Makefile create mode 100644 worker_test/worker_test.c diff --git a/Makefile b/Makefile index e7a334f..3747cd6 100644 --- a/Makefile +++ b/Makefile @@ -58,6 +58,8 @@ ifneq ($(call is-feature-enabled,arm_atomic_operation),) CFLAGS += -DARM_ATOMIC_OPERATION endif +WAYLAND_EGL_OBJ_PATH = ../src/wayland-egl/wayland-egl.o + TPL_HEADERS += $(SRC_DIR)/tpl.h TPL_HEADERS += $(SRC_DIR)/tpl_internal.h TPL_HEADERS += $(SRC_DIR)/tpl_utils.h @@ -102,7 +104,7 @@ endif OBJS = $(TPL_SRCS:%.c=%.o) ################################################################################ -all: $(BIN_NAME) glib_wl_test +all: $(BIN_NAME) $(BIN_NAME) : $(OBJS) $(TPL_HEADERS) $(CC) -o $@ $(OBJS) -shared -Wl,-soname,$(SO_NAME) $(CFLAGS) $(LDFLAGS) @@ -111,19 +113,19 @@ $(BIN_NAME) : $(OBJS) $(TPL_HEADERS) $(CC) -c -o $@ $< $(CFLAGS) #Make for test file -glib_wl_test : $(OBJS) $(TPL_HEADERS) - $(CC) -o glib_wl_test $(SRC_DIR)/tpl_wayland_egl_thread.c -O0 $(CFLAGS) -DWORKER_TEST_ONLY $(LDFLAGS) +#glib_wl_test : $(OBJS) $(WAYLAND_EGL_OBJ_PATH) $(TPL_HEADERS) +# $(CC) -o glib_wl_test $(SRC_DIR)/tpl_wayland_egl_thread.c -O0 $(CFLAGS) $(LDFLAGS) clean: find . -name "*.o" -exec rm -vf {} \; find . -name "*~" -exec rm -vf {} \; rm -vf $(BIN_NAME) - rm -vf glib_wl_test +# rm -vf glib_wl_test install: all cp -va $(BIN_NAME) $(INST_DIR)/ - cp glib_wl_test $(bindir)/ +# cp glib_wl_test $(bindir)/ uninstall: rm -f $(INST_DIR)/$(BIN_NAME) - rm -f $(bindir)/glib_wl_test +# rm -f $(bindir)/glib_wl_test diff --git a/packaging/libtpl-egl.spec b/packaging/libtpl-egl.spec index 0e87da9..49c626d 100644 --- a/packaging/libtpl-egl.spec +++ b/packaging/libtpl-egl.spec @@ -158,10 +158,6 @@ TPL_OPTIONS=${TPL_OPTIONS}-default_dump TPL_OPTIONS=${TPL_OPTIONS}-object_hash_check %endif -%if "%{ENABLE_WORKER_TEST_ONLY}" == "1" -TPL_OPTIONS=${TPL_OPTIONS}-worker_test -%endif - %ifarch %arm aarch64 TPL_OPTIONS=${TPL_OPTIONS}-arm_atomic_operation %endif @@ -190,6 +186,12 @@ make cd ../../ %endif +%if "%{ENABLE_WORKER_TEST_ONLY}" == "1" +cd worker_test/ +make +cd ../ +%endif + #tpl-test build %if "%{ENABLE_TPL_TEST}" == "1" cd tc/ @@ -208,21 +210,13 @@ mkdir -p %{buildroot} mkdir -p %{buildroot}%{_libdir} mkdir -p %{buildroot}%{_includedir} mkdir -p %{buildroot}%{_libdir}/pkgconfig -%if "%{ENABLE_WORKER_TEST_ONLY}" == "1" -mkdir -p %{buildroot}%{_bindir} -%endif export TPL_VER_MAJOR=%{TPL_VER_MAJOR} export TPL_VER_MINOR=%{TPL_VER_MINOR} export TPL_RELEASE=%{TPL_RELEASE} -%if "%{ENABLE_WORKER_TEST_ONLY}" == "1" -make install libdir=%{buildroot}%{_libdir} bindir=%{buildroot}%{_bindir} -%endif - -%if "%{ENABLE_WORKER_TEST_ONLY}" == "0" make install libdir=%{buildroot}%{_libdir} -%endif + ln -sf libtpl-egl.so.%{TPL_VER_FULL} %{buildroot}%{_libdir}/libtpl-egl.so.%{TPL_VERSION} ln -sf libtpl-egl.so.%{TPL_VERSION} %{buildroot}%{_libdir}/libtpl-egl.so.%{TPL_VER_MAJOR} ln -sf libtpl-egl.so.%{TPL_VER_MAJOR} %{buildroot}%{_libdir}/libtpl-egl.so @@ -244,6 +238,11 @@ cd src/wayland-vulkan cd - %endif +%if "%{ENABLE_WORKER_TEST_ONLY}" == "1" +mkdir -p %{buildroot}%{_bindir} +cp -arp ./worker_test/worker_test %{buildroot}%{_bindir}/worker_test +%endif + #tpl-test install %if "%{ENABLE_TPL_TEST}" == "1" mkdir -p %{buildroot}/opt/usr/tpl-test @@ -272,7 +271,7 @@ cp -a %{_builddir}/%{buildsubdir}/tc/libs/gtest/googletest/LICENSE %{buildroot}/ %{_libdir}/libtpl-egl.so.%{TPL_VER_FULL} %if "%{ENABLE_WORKER_TEST_ONLY}" == "1" -%{_bindir}/glib_wl_test +%{_bindir}/worker_test %endif #tpl-test files diff --git a/src/tpl_utils.h b/src/tpl_utils.h index f4bdb47..11aad8c 100644 --- a/src/tpl_utils.h +++ b/src/tpl_utils.h @@ -149,6 +149,17 @@ extern unsigned int tpl_dump_lvl; tpl_log_b("[TPL_" b "]", f, ##x); \ } +#define TPL_LOG_T(b, f, x...) \ + { \ + LOG_INIT(); \ + if (tpl_log_lvl > 1 && tpl_log_lvl < 4) { \ + if ((int)getpid() != (int)syscall(SYS_gettid)) \ + tpl_log_t("[TPL_" b "_T]", f, ##x); \ + else \ + tpl_log_b("[TPL_" b "]", f, ##x); \ + } \ + } + #define TPL_DEBUG(f, x...) \ { \ LOG_INIT(); \ diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index c45fcad..9022870 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -8,27 +8,10 @@ #include #include -#ifndef WORKER_TEST_ONLY -#define WORKER_TEST_ONLY -#endif - -#ifdef WORKER_TEST_ONLY -#include -#include "wayland-egl/wayland-egl-priv.h" -#include "tpl.h" #include "tpl_utils.h" - -typedef struct _twe_thread twe_thread; -typedef struct _twe_thread_context twe_thread_context; -typedef void* twe_display_h; -typedef void* twe_surface_h; -typedef void* twe_buffer_h; - -#else #include "wayland-egl/wayland-egl-priv.h" #include "tpl_wayland_egl_thread.h" #include "tpl_utils.h" -#endif static int buffer_info_key; #define KEY_BUFFER_INFO (unsigned long)(&buffer_info_key) @@ -608,7 +591,7 @@ _twe_thread_wl_surface_dispatch(GSource *source, GSourceFunc cb, gpointer date) ssize_t s; uint64_t u; - TPL_LOG_T("WL_EGL", "finalize| gsource(%p) read event_fd(%d)", + TPL_LOG_T("WL_EGL", "dispatch| gsource(%p) read event_fd(%d)", wl_surf_source, wl_surf_source->event_fd); s = read(wl_surf_source->event_fd, &u, sizeof(uint64_t)); if (s != sizeof(uint64_t)) @@ -1074,98 +1057,3 @@ twe_surface_set_damage_region(tbm_surface_h tbm_surface, return TPL_ERROR_NONE; } -#ifdef WORKER_TEST_ONLY -static void reg_global(void *data, - struct wl_registry *wl_registry, - uint32_t name, - const char *interface, - uint32_t version) -{ - TPL_LOG_T("WL_EGL", "reg_global: %s_v_%d\n", interface, version); -} - - -static void reg_global_remove(void *data, - struct wl_registry *wl_registry, - uint32_t name) -{ -} - - -static const struct wl_registry_listener registry_listener = { - reg_global, - reg_global_remove -}; - -static gboolean -timeout_cb(gpointer data) -{ - static int count = 0; - TPL_DEBUG("TIMEOUT count:%d", ++count); - return TRUE; -} - -static GSource* -_twe_test_add_timeout(twe_thread *thread, struct wl_display *display) -{ - GSource *timeout; - timeout = g_timeout_source_new(1000); - g_source_set_callback(timeout, timeout_cb, display, NULL); - g_source_attach(timeout, g_main_loop_get_context(thread->ctx->twe_loop)); - g_source_unref(timeout); - - return timeout; -} - -static void -_twe_test_del_timeout(GSource *timeout) -{ - g_source_destroy(timeout); - g_source_unref(timeout); -} - -void -main(void) -{ - struct wl_display *display; - struct wl_registry *registry; - struct wl_event_queue *ev_queue; - int count = 0; - GSource *timeout; - twe_display_h twe_display = NULL; - - twe_thread *t_thread = NULL; - - TPL_DEBUG("[[GLIB_WL_THREAD_TEST]]"); - - /*Create the twe_thread*/ - t_thread = twe_thread_create(); - - /*Add the wl_display to twe_thread*/ - display = wl_display_connect(NULL); - ev_queue = wl_display_create_queue(display); - - wl_proxy_set_queue((struct wl_proxy *)display, ev_queue); - - registry = wl_display_get_registry(display); - wl_registry_add_listener(registry, ®istry_listener, NULL); - - twe_display = twe_display_add(t_thread, display); - - while (1) { - sleep(1); - count++; - - if (count == 3) { - TPL_DEBUG("#### PRE_DEL"); - twe_display_del(twe_display); - TPL_DEBUG("#### DEL"); - } - } - - _twe_test_del_timeout(timeout); - twe_thread_destroy(t_thread); -} - -#endif - diff --git a/worker_test/Makefile b/worker_test/Makefile new file mode 100644 index 0000000..62e1a8c --- /dev/null +++ b/worker_test/Makefile @@ -0,0 +1,39 @@ +BIN_NAME := worker_test + +SRC_DIR = . + +CC ?= gcc + +CFLAGS += -Wall -fPIC -I$(SRC_DIR) +LDFLAGS += + +CFLAGS += -I../src + +CFLAGS += `pkg-config --cflags libtbm glib-2.0 wayland-tbm-client libtdm-client` +LDFLAGS += `pkg-config --libs libtbm glib-2.0 wayland-tbm-client libtdm-client` + +WAYLAND_EGL_OBJ_PATH = ../src/wayland-egl/wayland-egl.o + +SRCS += $(SRC_DIR)/worker_test.c +SRCS += ../src/tpl.c +SRCS += ../src/tpl_utils_hlist.c +SRCS += ../src/tpl_utils_map.c +SRCS += ../src/wayland-egl/wayland-egl.c +SRCS += ../src/tpl_wayland_egl_thread.c +HEADERS += ../src/tpl_wayland_egl_thread.h +HEADERS += ../src/tpl_utils.h +HEADERS += ../src/tpl.h + +OBJS = $(SRCS:%.c=%.o) + +all : $(BIN_NAME) + +%.o: %.c + $(CC) -c -o $@ $< $(CFLAGS) $(LDFLAGS) + +$(BIN_NAME) : $(OBJS) $(WAYLAND_EGL_OBJ_PATH) ${SRCS} $(HEADERS) + $(CC) ${SRCS} -o $@ $(CFLAGS) $(LDFLAGS) + +clean: + rm -vf $(BIN_NAME) + diff --git a/worker_test/worker_test.c b/worker_test/worker_test.c new file mode 100644 index 0000000..a91be37 --- /dev/null +++ b/worker_test/worker_test.c @@ -0,0 +1,194 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef LOG_DEFAULT_ENABLE +#define LOG_DEFAULT_ENABLE 1 +#endif + +#include "../src/tpl_utils.h" +#include "../src/tpl_wayland_egl_thread.h" + +struct Display { + struct wl_display *display; + struct wl_registry *registry; + struct wl_compositor *compositor; +}; + +struct Window { + struct Display *display; + struct wl_surface *surface; + struct wl_egl_window *wl_egl_window; +}; + +static void reg_global(void *data, + struct wl_registry *wl_registry, + uint32_t name, + const char *interface, + uint32_t version) +{ + struct Display *d = (struct Display *)data; + + if (strcmp(interface, "wl_compositor") == 0) { + d->compositor = wl_registry_bind(d->registry, name, &wl_compositor_interface, + version); + } + + printf("reg_global: %s_v_%d\n", interface, version); +} + +static void reg_global_remove(void *data, + struct wl_registry *wl_registry, + uint32_t name) +{ +} + + +static const struct wl_registry_listener registry_listener = { + reg_global, + reg_global_remove +}; + +#if 0 +static gboolean +timeout_cb(gpointer data) +{ + static int count = 0; + printf("TIMEOUT count:%d", ++count); + return TRUE; +} + +static GSource* +_twe_test_add_timeout(twe_thread *thread, struct wl_display *display) +{ + GSource *timeout; + timeout = g_timeout_source_new(1000); + g_source_set_callback(timeout, timeout_cb, display, NULL); + g_source_attach(timeout, g_main_loop_get_context(thread->ctx->twe_loop)); + g_source_unref(timeout); + + return timeout; +} + +static void +_twe_test_del_timeout(GSource *timeout) +{ + g_source_destroy(timeout); + g_source_unref(timeout); +} + +#endif + + +#define MAX_COUNT 100 +#define WIDTH 400 +#define HEIGHT 400 + +void +_paint_color(tbm_surface_h tbm_surface) +{ + tbm_surface_info_s info; + int height, stride; + unsigned char *ptr; + int i, j; + + tbm_surface_map(tbm_surface, TBM_SURF_OPTION_WRITE|TBM_SURF_OPTION_READ, + &info); + ptr = info.planes[0].ptr; + stride = info.planes[0].stride / 4; + height = tbm_surface_get_height(tbm_surface); + + for (i = 0; i < height; i++) { + for (j = 0; j < stride; j++) { + ptr[0] = 255; + ptr[1] = 0; + ptr[2] = 0; + ptr[3] = 255; + ptr += 4; + } + } + + tbm_surface_unmap(tbm_surface); +} + +void +main(void) +{ + struct wl_event_queue *ev_queue; + struct Display wl_disp = { 0 }; + struct Window wl_surf = { 0 }; + int count = 0; + twe_display_h twe_display = NULL; + twe_surface_h twe_surface = NULL; + tbm_surface_queue_h tbm_queue = NULL; + tbm_surface_h tbm_surface = NULL; + twe_thread *t_thread = NULL; + + printf("[[GLIB_WL_THREAD_TEST]]"); + + /*Create the twe_thread*/ + t_thread = twe_thread_create(); + + /*Add the wl_display to twe_thread*/ + wl_disp.display = wl_display_connect(NULL); + ev_queue = wl_display_create_queue(wl_disp.display); + + wl_proxy_set_queue((struct wl_proxy *)wl_disp.display, ev_queue); + + wl_disp.registry = wl_display_get_registry(wl_disp.display); + wl_registry_add_listener(wl_disp.registry, ®istry_listener, &wl_disp); + + wl_display_roundtrip_queue(wl_disp.display, ev_queue); + + twe_display = twe_display_add(t_thread, wl_disp.display); + + /* wl_egl_window creation */ + wl_surf.display = &wl_disp; + wl_surf.surface = wl_compositor_create_surface(wl_disp.compositor); + + wl_surf.wl_egl_window = wl_egl_window_create(wl_surf.surface, + WIDTH, HEIGHT); + + twe_surface = twe_surface_add(t_thread, twe_display, wl_surf.wl_egl_window); + + tbm_queue = twe_surface_get_tbm_queue(twe_surface); + + while (count < MAX_COUNT) { + //sleep(1); + count++; + + if (tbm_surface_queue_can_dequeue(tbm_queue, 1)) + tbm_surface_queue_dequeue(tbm_queue, &tbm_surface); + else + printf("[TEST] Failed to dequeue"); + + twe_surface_set_buffer(twe_surface, tbm_surface); + + if (tbm_surface) { + tbm_surface_internal_ref(tbm_surface); + + _paint_color(tbm_surface); + + tbm_surface_queue_enqueue(tbm_queue, tbm_surface); + + tbm_surface_internal_unref(tbm_surface); + tbm_surface = NULL; + } + } + + twe_surface_del(twe_surface); + twe_display_del(twe_display); + + twe_thread_destroy(t_thread); +} + + -- 2.7.4