From 5e75d607c61189756b73b9c61c842ba1596a0d6b Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Fri, 3 Apr 2015 16:14:56 +0200 Subject: [PATCH] ector: initial introduction. Idea for this library is to become a retained mode drawing library that use Eo/Eolian for its API and take a lot of the good design from Enesim by Jorge Zapata and Jose Gonzalez (http://enesim.org/). --- configure.ac | 43 +++++++++++ pc/.gitignore | 1 + pc/ector.pc.in | 12 ++++ src/Makefile.am | 1 + src/Makefile_Ector.am | 55 ++++++++++++++ src/lib/ector/Ector.h | 135 +++++++++++++++++++++++++++++++++++ src/lib/ector/ector_main.c | 81 +++++++++++++++++++++ src/lib/ector/ector_private.h | 39 ++++++++++ src/tests/ector/cxx_compile_test.cxx | 34 +++++++++ src/tests/ector/ector_suite.c | 113 +++++++++++++++++++++++++++++ src/tests/ector/ector_suite.h | 8 +++ src/tests/ector/ector_test_init.c | 38 ++++++++++ 12 files changed, 560 insertions(+) create mode 100644 pc/ector.pc.in create mode 100644 src/Makefile_Ector.am create mode 100644 src/lib/ector/Ector.h create mode 100644 src/lib/ector/ector_main.c create mode 100644 src/lib/ector/ector_private.h create mode 100644 src/tests/ector/cxx_compile_test.cxx create mode 100644 src/tests/ector/ector_suite.c create mode 100644 src/tests/ector/ector_suite.h create mode 100644 src/tests/ector/ector_test_init.c diff --git a/configure.ac b/configure.ac index 8c27ca4..afad51b 100644 --- a/configure.ac +++ b/configure.ac @@ -2094,6 +2094,47 @@ EFL_ADD_FEATURE([EVAS], [dither-mask], [${build_evas_dither_mask}]) EFL_LIB_END([Evas]) #### End of Evas +#### Ector + +EFL_LIB_START([Ector]) + + +### Default values + +### Additional options to configure + +### Checks for programs + +### Checks for libraries + +## Compatibility layers + +EFL_PLATFORM_DEPEND([ECTOR], [evil]) + +EFL_INTERNAL_DEPEND_PKG([ECTOR], [eina]) +EFL_INTERNAL_DEPEND_PKG([ECTOR], [eo]) +EFL_INTERNAL_DEPEND_PKG([ECTOR], [evas]) + +EFL_EVAL_PKGS([ECTOR]) + +### Checks for header files + +### Checks for types + +### Checks for structures + +### Checks for compiler characteristics + +### Checks for linker characteristics + +### Checks for library functions + +### Check availability + +EFL_LIB_END([ECTOR]) + +#### End of Ector + #### Edje CXX EFL_LIB_START([Evas_Cxx]) @@ -4524,6 +4565,7 @@ pc/ecore-imf-evas.pc pc/ecore-audio.pc pc/ecore-audio-cxx.pc pc/ecore-avahi.pc +pc/ector.pc pc/embryo.pc pc/eio.pc pc/eldbus.pc @@ -4691,6 +4733,7 @@ fi echo "Ecore_Audio.....: ${efl_lib_optional_ecore_audio} (${features_ecore_audio})" echo "Ecore_Avahi.....: yes (${features_ecore_avahi})" echo "Ecore_Evas......: yes (${features_ecore_evas})" +echo "Ector...........: yes" echo "Eeze............: ${efl_lib_optional_eeze} (${features_eeze})" echo "EPhysics........: ${efl_lib_optional_ephysics}" echo "Edje............: yes (${features_edje})" diff --git a/pc/.gitignore b/pc/.gitignore index 4aaaa13..25049d8 100644 --- a/pc/.gitignore +++ b/pc/.gitignore @@ -17,6 +17,7 @@ /ecore-win32.pc /ecore-x.pc /ecore.pc +/ector.pc /edje.pc /eet.pc /eeze.pc diff --git a/pc/ector.pc.in b/pc/ector.pc.in new file mode 100644 index 0000000..43d2db1 --- /dev/null +++ b/pc/ector.pc.in @@ -0,0 +1,12 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: ector +Description: Enlightenned retained mode drawing library +Requires.private: @requirements_pc_ector@ +Version: @VERSION@ +Libs: -L${libdir} -lector +Libs.private: @requirements_libs_ector@ +Cflags: -I${includedir}/efl-@VMAJ@ -I${includedir}/ector-@VMAJ@ diff --git a/src/Makefile.am b/src/Makefile.am index 580911a..924d7f8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -55,6 +55,7 @@ include Makefile_Ecore_Evas.am include Makefile_Ecore_Audio.am include Makefile_Ecore_Audio_Cxx.am include Makefile_Ecore_Avahi.am +include Makefile_Ector.am include Makefile_Embryo.am include Makefile_Eio.am include Makefile_Eldbus.am diff --git a/src/Makefile_Ector.am b/src/Makefile_Ector.am new file mode 100644 index 0000000..2589379 --- /dev/null +++ b/src/Makefile_Ector.am @@ -0,0 +1,55 @@ + +### Library + +lib_LTLIBRARIES += lib/ector/libector.la + +installed_ectormainheadersdir = $(includedir)/ector-@VMAJ@ +dist_installed_ectormainheaders_DATA = \ +lib/ector/Ector.h + +lib_ector_libector_la_SOURCES = \ +lib/ector/ector_main.c + +lib_ector_libector_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl \ +@ECTOR_CFLAGS@ \ +-DPACKAGE_BIN_DIR=\"$(bindir)\" \ +-DPACKAGE_LIB_DIR=\"$(libdir)\" \ +-DPACKAGE_DATA_DIR=\"$(datadir)/ector\" \ +@VALGRIND_CFLAGS@ + +lib_ector_libector_la_LIBADD = @ECTOR_LIBS@ @DL_LIBS@ +lib_ector_libector_la_DEPENDENCIES = @ECTOR_INTERNAL_LIBS@ @DL_INTERNAL_LIBS@ +lib_ector_libector_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@ + +### Unit tests + +if EFL_ENABLE_TESTS + +check_PROGRAMS += tests/ector/ector_suite tests/ector/cxx_compile_test +TESTS += tests/ector/ector_suite + +tests_ector_ector_suite_SOURCES = \ +tests/ector/ector_suite.c \ +tests/ector/ector_suite.h \ +tests/ector/ector_test_init.c + +tests_ector_cxx_compile_test_SOURCES = tests/ector/cxx_compile_test.cxx +tests_ector_cxx_compile_test_CPPFLAGS = -I$(top_builddir)/src/lib/efl @ECTOR_CFLAGS@ +tests_ector_cxx_compile_test_LDADD = @USE_ECTOR_LIBS@ +tests_ector_cxx_compile_test_DEPENDENCIES = @USE_ECTOR_INTERNAL_LIBS@ + + +tests_ector_ector_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \ +-DTESTS_WD=\"`pwd`\" \ +-DTESTS_SRC_DIR=\"$(top_srcdir)/src/tests/ector\" \ +-DPACKAGE_BUILD_DIR=\"$(abs_top_builddir)/src/tests/ector\" \ +-DTESTS_BUILD_DIR=PACKAGE_BUILD_DIR \ +@CHECK_CFLAGS@ \ +@ECTOR_CFLAGS@ +tests_ector_ector_suite_LDADD = @CHECK_LIBS@ @USE_ECTOR_LIBS@ +tests_ector_ector_suite_DEPENDENCIES = @USE_ECTOR_INTERNAL_LIBS@ + +endif + +EXTRA_DIST += \ +src/lib/ector/ector_private.h diff --git a/src/lib/ector/Ector.h b/src/lib/ector/Ector.h new file mode 100644 index 0000000..833f113 --- /dev/null +++ b/src/lib/ector/Ector.h @@ -0,0 +1,135 @@ +#ifndef ECTOR_H_ +#define ECTOR_H_ + +#include +#include + +#ifdef EAPI +# undef EAPI +#endif + +#ifdef _WIN32 +# ifdef EFL_ECTOR_BUILD +# ifdef DLL_EXPORT +# define EAPI __declspec(dllexport) +# else +# define EAPI +# endif /* ! DLL_EXPORT */ +# else +# define EAPI __declspec(dllimport) +# endif /* ! EFL_EO_BUILD */ +#else +# ifdef __GNUC__ +# if __GNUC__ >= 4 +# define EAPI __attribute__ ((visibility("default"))) +# else +# define EAPI +# endif +# else +# define EAPI +# endif +#endif /* ! _WIN32 */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @page ector_main Ector + * + * @date 2014 (created) + * + * @section toc Table of Contents + * + * @li @ref ector_main_intro + * @li @ref ector_main_compiling + * @li @ref ector_main_next_steps + * @li @ref ector_main_intro_example + * + * @section ector_main_intro Introduction + * + * Ector is a retained mode drawing library that is designed to work + * for and with an scenegraph like Evas. + * + * @section ector_main_compiling How to compile + * + * Ector is a library your application links to. The procedure for this is + * very simple. You simply have to compile your application with the + * appropriate compiler flags that the @c pkg-config script outputs. For + * example: + * + * Compiling C or C++ files into object files: + * + * @verbatim + gcc -c -o main.o main.c `pkg-config --cflags ector` + @endverbatim + * + * Linking object files into a binary executable: + * + * @verbatim + gcc -o my_application main.o `pkg-config --libs ector` + @endverbatim + * + * See @ref pkgconfig + * + * @section ector_main_next_steps Next Steps + * + * After you understood what Ector is and installed it in your system + * you should proceed understanding the programming interface. + * + * Recommended reading: + * + * @li @ref Ector_Surface + * @li @ref Ector_Renderer + * + * @section ector_main_intro_example Introductory Example + * + * @ref Ector_Tutorial + * + * + * @addtogroup Ector + * @{ + */ + +/** + * @typedef Ector_Surface + * The base type to render content into. + */ +typedef Eo Ector_Surface; + +/** + * @typedef Ector_Renderer + * The base type describing what to render. + */ +typedef Eo Ector_Renderer; + +#ifdef EFL_BETA_API_SUPPORT + +/** + * @brief Init the ector subsystem + * @return @c EINA_TRUE on success. + * + * @see ector_shutfown() + */ +EAPI int ector_init(void); + +/** + * @brief Shutdown the ector subsystem + * @return @c EINA_TRUE on success. + * + * @see ector_init() + */ +EAPI int ector_shutdown(void); + +#endif + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/lib/ector/ector_main.c b/src/lib/ector/ector_main.c new file mode 100644 index 0000000..5f09214 --- /dev/null +++ b/src/lib/ector/ector_main.c @@ -0,0 +1,81 @@ +/* ECTOR - EFL retained mode drawing library + * Copyright (C) 2014 Cedric Bail + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include "ector_private.h" + +int _ector_log_dom = 0; + +static int _ector_main_count = 0; + +EAPI int +ector_init(void) +{ + if (EINA_LIKELY(_ector_main_count > 0)) + return ++_ector_main_count; + + eina_init(); + eo_init(); + + _ector_log_dom = eina_log_domain_register("ector", ECTOR_DEFAULT_LOG_COLOR); + if (_ector_log_dom < 0) + { + EINA_LOG_ERR("Could not register log domain: ector"); + goto on_error; + } + + _ector_main_count = 1; + + eina_log_timing(_ector_log_dom, EINA_LOG_STATE_STOP, EINA_LOG_STATE_INIT); + + return _ector_main_count; + + on_error: + eo_shutdown(); + eina_shutdown(); + + return 0; +} + +EAPI int +ector_shutdown(void) +{ + if (_ector_main_count <= 0) + { + EINA_LOG_ERR("Init count not greater than 0 in shutdown of ector."); + return 0; + } + + _ector_main_count--; + if (EINA_LIKELY(_ector_main_count > 0)) + return _ector_main_count; + + eina_log_timing(_ector_log_dom, + EINA_LOG_STATE_START, + EINA_LOG_STATE_SHUTDOWN); + + eo_shutdown(); + + eina_log_domain_unregister(_ector_log_dom); + + eina_shutdown(); + return _ector_main_count; +} diff --git a/src/lib/ector/ector_private.h b/src/lib/ector/ector_private.h new file mode 100644 index 0000000..b41e1ef --- /dev/null +++ b/src/lib/ector/ector_private.h @@ -0,0 +1,39 @@ +#ifndef ECTOR_PRIVATE_H_ +#define ECTOR_PRIVATE_H_ + +/* + * variable and macros used for the eina_log module + */ +extern int _ector_log_dom_global; + +/* + * Macros that are used everywhere + * + * the first four macros are the general macros for the lib + */ +#ifdef ECTOR_DEFAULT_LOG_COLOR +# undef ECTOR_DEFAULT_LOG_COLOR +#endif /* ifdef ECTOR_DEFAULT_LOG_COLOR */ +#define ECTOR_DEFAULT_LOG_COLOR EINA_COLOR_CYAN +#ifdef ERR +# undef ERR +#endif /* ifdef ERR */ +#define ERR(...) EINA_LOG_DOM_ERR(_ector_log_dom_global, __VA_ARGS__) +#ifdef DBG +# undef DBG +#endif /* ifdef DBG */ +#define DBG(...) EINA_LOG_DOM_DBG(_ector_log_dom_global, __VA_ARGS__) +#ifdef INF +# undef INF +#endif /* ifdef INF */ +#define INF(...) EINA_LOG_DOM_INFO(_ector_log_dom_global, __VA_ARGS__) +#ifdef WRN +# undef WRN +#endif /* ifdef WRN */ +#define WRN(...) EINA_LOG_DOM_WARN(_ector_log_dom_global, __VA_ARGS__) +#ifdef CRI +# undef CRI +#endif /* ifdef CRI */ +#define CRI(...) EINA_LOG_DOM_CRIT(_ector_log_dom_global, __VA_ARGS__) + +#endif diff --git a/src/tests/ector/cxx_compile_test.cxx b/src/tests/ector/cxx_compile_test.cxx new file mode 100644 index 0000000..091757a --- /dev/null +++ b/src/tests/ector/cxx_compile_test.cxx @@ -0,0 +1,34 @@ +/* EINA - EFL data type library + * Copyright (C) 2012 ProFUSION embedded systems + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "Ector.h" + +#include +using namespace std; + +int main() +{ + ector_init(); + cout << "Ector compiles with C++!"; + ector_shutdown(); + return 0; +} diff --git a/src/tests/ector/ector_suite.c b/src/tests/ector/ector_suite.c new file mode 100644 index 0000000..fbae22c --- /dev/null +++ b/src/tests/ector/ector_suite.c @@ -0,0 +1,113 @@ +/* ECTOR - EFL retained mode drawing library + * Copyright (C) 2014 Cedric Bail + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#ifdef HAVE_CONFIG_H +# include +#endif /* ifdef HAVE_CONFIG_H */ + +#include +#include + +#include + +#include "Eina.h" + +#include "ector_suite.h" + +typedef struct _Ector_Test_Case Ector_Test_Case; +struct _Ector_Test_Case +{ + const char *test_case; + void (*build)(TCase *tc); +}; + +static const Ector_Test_Case etc[] = { + { "init", ector_test_init }, + { NULL, NULL } +}; + +static void +_list_tests(void) +{ + const Ector_Test_Case *itr = etc; + fputs("Available Test Cases:\n", stderr); + for (; itr->test_case; itr++) + fprintf(stderr, "\t%s\n", itr->test_case); +} + +static Eina_Bool +_use_test(int argc, const char **argv, const char *test_case) +{ + if (argc < 1) + return 1; + + for (; argc > 0; argc--, argv++) + if (strcmp(test_case, *argv) == 0) + return 1; + + return 0; +} + +int +main(int argc, char *argv[]) +{ + TCase *tc; + Suite *s; + SRunner *sr; + int failed_count, i; + + for (i = 1; i < argc; i++) + if ((strcmp(argv[i], "-h") == 0) || + (strcmp(argv[i], "--help") == 0)) + { + fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", + argv[0]); + _list_tests(); + return 0; + } + else if ((strcmp(argv[i], "-l") == 0) || + (strcmp(argv[i], "--list") == 0)) + { + _list_tests(); + return 0; + } + + putenv("EFL_RUN_IN_TREE=1"); + + s = suite_create("Ector"); + + for (i = 0; etc[i].test_case; ++i) + { + if (!_use_test(argc - 1, (const char **) argv + 1, etc[i].test_case)) + continue; + + tc = tcase_create(etc[i].test_case); + tcase_set_timeout(tc, 0); + + etc[i].build(tc); + suite_add_tcase(s, tc); + } + + sr = srunner_create(s); + srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); + srunner_run_all(sr, CK_ENV); + failed_count = srunner_ntests_failed(sr); + srunner_free(sr); + + return (failed_count == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/src/tests/ector/ector_suite.h b/src/tests/ector/ector_suite.h new file mode 100644 index 0000000..176a838 --- /dev/null +++ b/src/tests/ector/ector_suite.h @@ -0,0 +1,8 @@ +#ifndef ECTOR_SUITE_H +#define ECTOR_SUITE_H + +#include + +void ector_test_init(TCase *tc); + +#endif diff --git a/src/tests/ector/ector_test_init.c b/src/tests/ector/ector_test_init.c new file mode 100644 index 0000000..1c36e40 --- /dev/null +++ b/src/tests/ector/ector_test_init.c @@ -0,0 +1,38 @@ +/* ECTOR - EFL retained mode drawing library + * Copyright (C) 2014 Cedric Bail + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "ector_suite.h" + +#include "Ector.h" + +START_TEST(ector_init_simple) +{ + fail_if(ector_init() != 1); + fail_if(ector_shutdown() != 0); +} +END_TEST + +void +ector_test_init(TCase *tc) +{ + tcase_add_test(tc, ector_init_simple); +} -- 2.7.4