From c20274aaf84846a8ded2817633c2e120cb1e8e34 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Tue, 24 Mar 2020 15:07:51 +0900 Subject: [PATCH 2/5] + Initial draft Introduce project skeleton such as build envrionment and interfaces to build up code further cooperatively. Change-Id: Ie9ac38991f609d33637283134906d7cc3f2ac19e --- .gitignore | 4 + AUTHORS | 1 + LICENSE | 202 +++++++++++++++++++++++++++++++++++++++++++++++ README | 7 ++ inc/meson.build | 3 + inc/tizenvg.h | 67 ++++++++++++++++ meson.build | 31 ++++++++ pc/tizenvg.pc.in | 10 +++ src/examples/main.cpp | 27 +++++++ src/examples/meson.build | 1 + src/lib/TvgEngine.cpp | 61 ++++++++++++++ src/lib/meson.build | 8 ++ src/meson.build | 31 ++++++++ test/makefile | 2 + test/test.cpp | 12 +++ tizenvg.manifest | 5 ++ 16 files changed, 472 insertions(+) create mode 100644 .gitignore create mode 100644 AUTHORS create mode 100644 LICENSE create mode 100644 README create mode 100644 inc/meson.build create mode 100644 inc/tizenvg.h create mode 100644 meson.build create mode 100644 pc/tizenvg.pc.in create mode 100644 src/examples/main.cpp create mode 100644 src/examples/meson.build create mode 100644 src/lib/TvgEngine.cpp create mode 100644 src/lib/meson.build create mode 100644 src/meson.build create mode 100644 test/makefile create mode 100644 test/test.cpp create mode 100644 tizenvg.manifest diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a6c4662 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +build +.vscode +*.swp +test diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..13ce511 --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ +Hermet Park diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8a7fbe4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2016 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README b/README new file mode 100644 index 0000000..72cf83d --- /dev/null +++ b/README @@ -0,0 +1,7 @@ +Tizen Vector Graphics 0.1.0 + +****************************************************************************** + + FOR ANY ISSUES PLEASE EMAIL: + +****************************************************************************** diff --git a/inc/meson.build b/inc/meson.build new file mode 100644 index 0000000..4046844 --- /dev/null +++ b/inc/meson.build @@ -0,0 +1,3 @@ +install_headers([ + 'tizenvg.h', + ]) diff --git a/inc/tizenvg.h b/inc/tizenvg.h new file mode 100644 index 0000000..a8597ad --- /dev/null +++ b/inc/tizenvg.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef _TIZENVG_H_ +#define _TIZENVG_H_ + +#include + +#ifdef TIZENVG_BUILD + #define TIZENVG_EXPORT __attribute__ ((visibility ("default"))) +#else + #define TIZENVG_EXPORT +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +namespace tizenvg +{ + +/** + * @class Engine + * + * @ingroup TizenVG + * + * @brief description... + * + */ +class TIZENVG_EXPORT Engine final +{ +public: + /** + * @brief ... + * + * @param[in] arg ... + * + * @note ... + * + * @return ... + * + * @see ... + */ + static int init() noexcept; + static int term() noexcept; +}; + +} //namespace + +#ifdef __cplusplus +} +#endif + +#endif //_TIZENVG_H_ diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..32dd23b --- /dev/null +++ b/meson.build @@ -0,0 +1,31 @@ +project('tizenvg', + 'cpp', + default_options : ['buildtype=debugoptimized', 'werror=false', 'cpp_std=c++14'], + version : '0.1.0', + license : 'Apache-2.0') + +config_h = configuration_data() + +configure_file( + output: 'config.h', + configuration: config_h +) + +headers = [include_directories('inc')] + +subdir('inc') +subdir('src') + +summary = ''' + +Summary: + tizenvg version : @0@ + Build type : @1@ + Prefix : @2@ +'''.format( + meson.project_version(), + get_option('buildtype'), + get_option('prefix'), + ) + +message(summary) diff --git a/pc/tizenvg.pc.in b/pc/tizenvg.pc.in new file mode 100644 index 0000000..631bc2a --- /dev/null +++ b/pc/tizenvg.pc.in @@ -0,0 +1,10 @@ +prefix=@PREFIX@ +libdir=@LIBDIR@ +includedir=@INCDIR@ + +Name: Tizen Vector Graphics +Description: Tizen Vector Graphics Library +Version: @VERSION@ +Requires: +Libs: -L${libdir} -ltizenvg +Cflags: -I${includedir}/tizenvg diff --git a/src/examples/main.cpp b/src/examples/main.cpp new file mode 100644 index 0000000..4b9154b --- /dev/null +++ b/src/examples/main.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include + +using namespace std; + +int +main(int argc, char *argv[]) +{ + cout << "test tizenvg!" << endl; + + return 0; +} diff --git a/src/examples/meson.build b/src/examples/meson.build new file mode 100644 index 0000000..8954536 --- /dev/null +++ b/src/examples/meson.build @@ -0,0 +1 @@ +executable('tizenvg_sample', 'main.cpp') diff --git a/src/lib/TvgEngine.cpp b/src/lib/TvgEngine.cpp new file mode 100644 index 0000000..08f6bc1 --- /dev/null +++ b/src/lib/TvgEngine.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef _TVG_ENGINE_CPP_ +#define _TVG_ENGINE_CPP_ + +#include +#include +#include "tizenvg.h" + +using namespace std; +using namespace tizenvg; + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ +namespace tizenvg +{ + +class EngineImpl +{ + public: + static int init() { + return 0; + } + + static int term() { + return 0; + } +}; + +} + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +int Engine::init() noexcept +{ + return EngineImpl::init(); +} + +int Engine::term() noexcept +{ + return EngineImpl::term(); +} + +#endif /* _TVG_ENGINE_CPP_ */ diff --git a/src/lib/meson.build b/src/lib/meson.build new file mode 100644 index 0000000..1facacb --- /dev/null +++ b/src/lib/meson.build @@ -0,0 +1,8 @@ +source_file = [ + 'TvgEngine.cpp' +] + +src_dep = declare_dependency( + include_directories : include_directories('.'), + sources : source_file +) diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..d3fde4d --- /dev/null +++ b/src/meson.build @@ -0,0 +1,31 @@ +compiler_flags = ['-DTIZENVG_BUILD'] + +subdir('lib') +subdir('examples') + +tizenvg_lib_dep = [ src_dep ] + +tizenvg_lib = library( + 'tizenvg', + include_directories : headers, + version : meson.project_version(), + dependencies : tizenvg_lib_dep, + install : true, + cpp_args : compiler_flags, + gnu_symbol_visibility : 'hidden', +) + +tizenvg_dep = declare_dependency( + include_directories: headers, + link_with : tizenvg_lib +) + +pkg_mod = import('pkgconfig') + +pkg_mod.generate( + libraries : tizenvg_lib, + version : meson.project_version(), + name : 'libtizenvg', + filebase : 'tizenvg', + description : 'A Tizen library for rendering vector graphics' +) diff --git a/test/makefile b/test/makefile new file mode 100644 index 0000000..4dc9135 --- /dev/null +++ b/test/makefile @@ -0,0 +1,2 @@ +all: + gcc -o test test.cpp -g -lstdc++ `pkg-config --cflags --libs tizenvg` diff --git a/test/test.cpp b/test/test.cpp new file mode 100644 index 0000000..6c95358 --- /dev/null +++ b/test/test.cpp @@ -0,0 +1,12 @@ +#include + +using namespace std; + +int main(int argc, char **argv) +{ + tizenvg::Engine::init(); + + //... + + tizenvg::Engine::term(); +} diff --git a/tizenvg.manifest b/tizenvg.manifest new file mode 100644 index 0000000..97e8c31 --- /dev/null +++ b/tizenvg.manifest @@ -0,0 +1,5 @@ + + + + + -- 2.7.4 From df94be1d9d9648804bb1ebe18a2db60c47512f30 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Wed, 25 Mar 2020 13:54:29 +0900 Subject: [PATCH 3/5] build up base infra code for prototype. Change-Id: I117a798caf4d9fedfe5c467471dee2f0150c2630 --- inc/tizenvg.h | 137 ++++++++++++++++++++++++++++++- src/lib/meson.build | 8 +- src/lib/tvgCanvasBase.h | 46 +++++++++++ src/lib/tvgCommon.h | 29 +++++++ src/lib/{TvgEngine.cpp => tvgEngine.cpp} | 27 +----- src/lib/tvgGlCanvas.cpp | 71 ++++++++++++++++ src/lib/tvgSceneNode.cpp | 66 +++++++++++++++ src/lib/tvgShapeNode.cpp | 104 +++++++++++++++++++++++ src/lib/tvgSwCanvas.cpp | 102 +++++++++++++++++++++++ test/makefile | 2 +- test/test.cpp | 12 --- test/tvgDrawShape.cpp | 30 +++++++ test/tvgGradient.cpp | 55 +++++++++++++ test/tvgMultipleShapes.cpp | 36 ++++++++ test/tvgPath.cpp | 39 +++++++++ test/tvgScene.cpp | 49 +++++++++++ test/tvgStroke.cpp | 39 +++++++++ test/tvgUpdate.cpp | 49 +++++++++++ 18 files changed, 863 insertions(+), 38 deletions(-) create mode 100644 src/lib/tvgCanvasBase.h create mode 100644 src/lib/tvgCommon.h rename src/lib/{TvgEngine.cpp => tvgEngine.cpp} (79%) create mode 100644 src/lib/tvgGlCanvas.cpp create mode 100644 src/lib/tvgSceneNode.cpp create mode 100644 src/lib/tvgShapeNode.cpp create mode 100644 src/lib/tvgSwCanvas.cpp delete mode 100644 test/test.cpp create mode 100644 test/tvgDrawShape.cpp create mode 100644 test/tvgGradient.cpp create mode 100644 test/tvgMultipleShapes.cpp create mode 100644 test/tvgPath.cpp create mode 100644 test/tvgScene.cpp create mode 100644 test/tvgStroke.cpp create mode 100644 test/tvgUpdate.cpp diff --git a/inc/tizenvg.h b/inc/tizenvg.h index a8597ad..cc334e0 100644 --- a/inc/tizenvg.h +++ b/inc/tizenvg.h @@ -25,12 +25,145 @@ #define TIZENVG_EXPORT #endif +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "TIZENVG" + + #ifdef __cplusplus extern "C" { #endif -namespace tizenvg +#define _TIZENVG_DECLARE_PRIVATE(A) \ +private: \ + struct Impl; \ + std::unique_ptr pImpl; \ + A(const A&) = delete; \ + const A& operator=(const A&) = delete; \ + A() + +#define _TIZENVG_DISABLE_CTOR(A) \ + A() = delete; \ + ~A() = delete + +namespace tvg +{ + +class SceneNode; + + +/** + * @class PaintNode + * + * @ingroup TizenVG + * + * @brief description... + * + */ +class TIZENVG_EXPORT PaintNode +{ +public: + virtual ~PaintNode() {} + virtual int prepare() = 0; +}; + + +/** + * @class ShapeNode + * + * @ingroup TizenVG + * + * @brief description... + * + */ +class TIZENVG_EXPORT ShapeNode final : public PaintNode +{ +public: + ~ShapeNode(); + + int prepare() noexcept override; + + static std::unique_ptr gen(); + + _TIZENVG_DECLARE_PRIVATE(ShapeNode); +}; + + +/** + * @class SceneNode + * + * @ingroup TizenVG + * + * @brief description... + * + */ +class TIZENVG_EXPORT SceneNode final : public PaintNode +{ +public: + ~SceneNode(); + + int push(std::unique_ptr shape) noexcept; + int prepare() noexcept override; + + static std::unique_ptr gen() noexcept; + + _TIZENVG_DECLARE_PRIVATE(SceneNode); +}; + + +/** + * @class SwCanvas + * + * @ingroup TizenVG + * + @brief description... + * + */ +class TIZENVG_EXPORT SwCanvas final { +public: + ~SwCanvas(); + + int push(std::unique_ptr paint) noexcept; + int clear() noexcept; + + int draw(bool async = true) noexcept; + int drawSync() noexcept; + + int target(uint32_t* buffer, size_t stride, size_t height) noexcept; + + static std::unique_ptr gen(uint32_t* buffer = nullptr, size_t stride = 0, size_t height = 0) noexcept; + + _TIZENVG_DECLARE_PRIVATE(SwCanvas); +}; + + +/** + * @class GlCanvas + * + * @ingroup TizenVG + * + * @brief description... + * + */ +class TIZENVG_EXPORT GlCanvas final +{ +public: + ~GlCanvas(); + + int push(std::unique_ptr paint) noexcept; + int clear() noexcept; + + //TODO: Gl Specific methods. Need gl backend configuration methods as well. + int draw(bool async = true) noexcept { return 0; } + int drawSync() noexcept { return 0; } + + static std::unique_ptr gen() noexcept; + + _TIZENVG_DECLARE_PRIVATE(GlCanvas); +}; + /** * @class Engine @@ -56,6 +189,8 @@ public: */ static int init() noexcept; static int term() noexcept; + + _TIZENVG_DISABLE_CTOR(Engine); }; } //namespace diff --git a/src/lib/meson.build b/src/lib/meson.build index 1facacb..fb856bf 100644 --- a/src/lib/meson.build +++ b/src/lib/meson.build @@ -1,5 +1,11 @@ source_file = [ - 'TvgEngine.cpp' + 'tvgCommon.h', + 'tvgEngine.cpp', + 'tvgCanvasBase.h', + 'tvgSwCanvas.cpp', + 'tvgGlCanvas.cpp', + 'tvgSceneNode.cpp', + 'tvgShapeNode.cpp' ] src_dep = declare_dependency( diff --git a/src/lib/tvgCanvasBase.h b/src/lib/tvgCanvasBase.h new file mode 100644 index 0000000..83607bf --- /dev/null +++ b/src/lib/tvgCanvasBase.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef _TVG_CANVAS_CPP_ +#define _TVG_CANVAS_CPP_ + +#include "tvgCommon.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +struct CanvasBase +{ + + int push(unique_ptr paint) + { + return 0; + } + + int clear() + { + return 0; + } + +}; + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +#endif /* _TVG_CANVAS_CPP_ */ diff --git a/src/lib/tvgCommon.h b/src/lib/tvgCommon.h new file mode 100644 index 0000000..f69af00 --- /dev/null +++ b/src/lib/tvgCommon.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef _TVG_COMMON_H_ +#define _TVG_COMMON_H_ + +#include +#include +#include +#include "tizenvg.h" + +using namespace std; +using namespace tvg; +using var = float; + +#endif //_TVG_COMMON_H_ diff --git a/src/lib/TvgEngine.cpp b/src/lib/tvgEngine.cpp similarity index 79% rename from src/lib/TvgEngine.cpp rename to src/lib/tvgEngine.cpp index 08f6bc1..838f4ca 100644 --- a/src/lib/TvgEngine.cpp +++ b/src/lib/tvgEngine.cpp @@ -17,32 +17,12 @@ #ifndef _TVG_ENGINE_CPP_ #define _TVG_ENGINE_CPP_ -#include -#include -#include "tizenvg.h" - -using namespace std; -using namespace tizenvg; +#include "tvgCommon.h" /************************************************************************/ /* Internal Class Implementation */ /************************************************************************/ -namespace tizenvg -{ - -class EngineImpl -{ - public: - static int init() { - return 0; - } - static int term() { - return 0; - } -}; - -} /************************************************************************/ /* External Class Implementation */ @@ -50,12 +30,13 @@ class EngineImpl int Engine::init() noexcept { - return EngineImpl::init(); + return 0; } + int Engine::term() noexcept { - return EngineImpl::term(); + return 0; } #endif /* _TVG_ENGINE_CPP_ */ diff --git a/src/lib/tvgGlCanvas.cpp b/src/lib/tvgGlCanvas.cpp new file mode 100644 index 0000000..573600e --- /dev/null +++ b/src/lib/tvgGlCanvas.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef _TVG_GLCANVAS_CPP_ +#define _TVG_GLCANVAS_CPP_ + +#include "tvgCommon.h" +#include "tvgCanvasBase.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +struct GlCanvas::Impl : CanvasBase +{ + //... +}; + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +GlCanvas::GlCanvas() : pImpl(make_unique()) +{ +} + + +GlCanvas::~GlCanvas() +{ + cout << "GlCanvas(" << this << ") destroyed!" << endl; +} + + +unique_ptr GlCanvas::gen() noexcept +{ + auto canvas = unique_ptr(new GlCanvas); + assert(canvas); + + return canvas; +} + + +int GlCanvas::push(unique_ptr paint) noexcept +{ + auto impl = pImpl.get(); + assert(impl); + return impl->push(move(paint)); +} + +int GlCanvas::clear() noexcept +{ + auto impl = pImpl.get(); + assert(impl); + return impl->clear(); +} + +#endif /* _TVG_GLCANVAS_CPP_ */ diff --git a/src/lib/tvgSceneNode.cpp b/src/lib/tvgSceneNode.cpp new file mode 100644 index 0000000..8da41fc --- /dev/null +++ b/src/lib/tvgSceneNode.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef _TVG_SCENE_NODE_CPP_ +#define _TVG_SCENE_NODE_CPP_ + +#include "tvgCommon.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +struct SceneNode::Impl +{ + +}; + + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +SceneNode :: SceneNode() : pImpl(make_unique()) +{ + +} + + +SceneNode :: ~SceneNode() +{ + cout << "SceneNode(" << this << ") destroyed!" << endl; +} + + +unique_ptr SceneNode::gen() noexcept +{ + return unique_ptr(new SceneNode); +} + +int SceneNode :: push(unique_ptr shape) noexcept +{ + return 0; +} + + +int SceneNode :: prepare() noexcept +{ + + return 0; +} + +#endif /* _TVG_SCENE_NODE_CPP_ */ diff --git a/src/lib/tvgShapeNode.cpp b/src/lib/tvgShapeNode.cpp new file mode 100644 index 0000000..4fb4b10 --- /dev/null +++ b/src/lib/tvgShapeNode.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef _TVG_SHAPE_NODE_CPP_ +#define _TVG_SHAPE_NODE_CPP_ + +#include "tvgCommon.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +struct ShapeFill +{ +}; + + +struct ShapeStroke +{ +}; + + +struct ShapePath +{ +}; + + +struct ShapeTransform +{ + var e[4*4]; +}; + + +struct ShapeChildren +{ + vector> v; +}; + + +struct ShapeNode::Impl +{ + ShapeChildren *children = nullptr; + ShapeTransform *transform = nullptr; + ShapeFill *fill = nullptr; + ShapeStroke *stroke = nullptr; + ShapePath *path = nullptr; + uint32_t color = 0; + uint32_t id = 0; + + + ~Impl() + { + if (path) delete(path); + if (stroke) delete(stroke); + if (fill) delete(fill); + if (transform) delete(transform); + if (children) delete(children); + } + +}; + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +ShapeNode :: ShapeNode() : pImpl(make_unique()) +{ + +} + + +ShapeNode :: ~ShapeNode() +{ + cout << "ShapeNode(" << this << ") destroyed!" << endl; +} + + +unique_ptr ShapeNode::gen() +{ + return unique_ptr(new ShapeNode); +} + + +int ShapeNode :: prepare() noexcept +{ + return 0; +} + + +#endif //_TVG_SHAPE_NODE_CPP_ diff --git a/src/lib/tvgSwCanvas.cpp b/src/lib/tvgSwCanvas.cpp new file mode 100644 index 0000000..05296cd --- /dev/null +++ b/src/lib/tvgSwCanvas.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef _TVG_SWCANVAS_CPP_ +#define _TVG_SWCANVAS_CPP_ + +#include "tvgCommon.h" +#include "tvgCanvasBase.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +struct SwCanvas::Impl : CanvasBase +{ + uint32_t* buffer = nullptr; + int stride = 0; + int height = 0; +}; + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +int SwCanvas::target(uint32_t* buffer, size_t stride, size_t height) noexcept +{ + auto impl = pImpl.get(); + assert(impl); + + impl->buffer = buffer; + impl->stride = stride; + impl->height = height; + + return 0; +} + + +int SwCanvas::draw(bool async) noexcept +{ + return 0; +} + + +int SwCanvas::drawSync() noexcept +{ + return 0; +} + + +int SwCanvas::push(unique_ptr paint) noexcept +{ + auto impl = pImpl.get(); + assert(impl); + return impl->push(move(paint)); +} + + +int SwCanvas::clear() noexcept +{ + auto impl = pImpl.get(); + assert(impl); + return impl->clear(); +} + + +SwCanvas::SwCanvas() : pImpl(make_unique()) +{ +} + + +SwCanvas::~SwCanvas() +{ + cout << "SwCanvas(" << this << ") destroyed!" << endl; +} + + +unique_ptr SwCanvas::gen(uint32_t* buffer, size_t stride, size_t height) noexcept +{ + auto canvas = unique_ptr(new SwCanvas); + assert(canvas); + + int ret = canvas.get()->target(buffer, stride, height); + if (ret > 0) return nullptr; + + return canvas; +} + +#endif /* _TVG_SWCANVAS_CPP_ */ diff --git a/test/makefile b/test/makefile index 4dc9135..0f89da0 100644 --- a/test/makefile +++ b/test/makefile @@ -1,2 +1,2 @@ all: - gcc -o test test.cpp -g -lstdc++ `pkg-config --cflags --libs tizenvg` + gcc -o tvgDrawShape tvgDrawShape.cpp -g -lstdc++ `pkg-config --cflags --libs tizenvg` diff --git a/test/test.cpp b/test/test.cpp deleted file mode 100644 index 6c95358..0000000 --- a/test/test.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include - -using namespace std; - -int main(int argc, char **argv) -{ - tizenvg::Engine::init(); - - //... - - tizenvg::Engine::term(); -} diff --git a/test/tvgDrawShape.cpp b/test/tvgDrawShape.cpp new file mode 100644 index 0000000..34f4dc9 --- /dev/null +++ b/test/tvgDrawShape.cpp @@ -0,0 +1,30 @@ +#include + +using namespace std; + +#define WIDTH 800 +#define HEIGHT 800 + +static uint32_t buffer[WIDTH * HEIGHT]; + +int main(int argc, char **argv) +{ + //Initialize TizenVG Engine + tvg::Engine::init(); + + //Create a Canvas + auto canvas = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT); + + //Prepare a Shape + auto shape1 = tvg::ShapeNode::gen(); + shape1->rect(0, 0, 400, 400, 0.1); //x, y, w, h, corner_radius + shape1->fill(0, 255, 0, 255); + + //Draw the Shape onto the Canvas + canvas->push(move(shape1)); + canvas->draw(); + canvas->sync(); + + //Terminate TizenVG Engine + tvg::Engine::term(); +} diff --git a/test/tvgGradient.cpp b/test/tvgGradient.cpp new file mode 100644 index 0000000..2bf2824 --- /dev/null +++ b/test/tvgGradient.cpp @@ -0,0 +1,55 @@ +#include + +using namespace std; + +#define WIDTH 800 +#define HEIGHT 800 + +static uint32_t buffer[WIDTH * HEIGHT]; + +int main(int argc, char **argv) +{ + //Initialize TizenVG Engine + tvg::Engine::init(); + + //Create a Canvas + auto canvas = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT); + + //Prepare a Shape + auto shape1 = tvg::ShapeNode::gen(); + shape1->rect(0, 0, 400, 400, 0.1); //x, y, w, h, corner_radius + + //Linear Gradient Fill + auto fill1 = tvg::LinearFill::gen(); + fill1->range(fill1, 0, 0, 400, 400); //from(x, y), to(x, y) + fill1->color(0, 255, 0, 0, 255); //color Stop 0: Red + fill1->color(0.5, 0, 255, 0, 255); //color Stop 1: Green + fill1->color(1, 0, 0, 255, 255); //color Stop 2: Blue + shape1.fill(fill1); + + //Draw the Shape onto the Canvas + canvas->push(move(shape1)); + + //Prepare Circle + auto shape2 = tvg::ShapeNode::gen(); + shape2->circle(400, 400, 200); //cx, cy, radius + shape2->fill(255, 255, 0, 255); //r, g, b, a + canvas->push(move(shape2)); + + //Radial Gradient Fill + auto fill2 = tvg::RadialFill::gen(); + fill2->range(400, 400, 200); //center(x, y), radius + fill2->color(0, 255, 0, 0, 255); //color Stop 0: Red + fill2->color(0.5, 0, 255, 0, 255); //color Stop 1: Green + fill2->color(1, 0, 0, 255, 255); //color Stop 2: Blue + shape2.fill(fill2); + + //Draw the Shape onto the Canvas + canvas->push(move(shape2)); + + canvas->draw(); + canvas->sync(); + + //Terminate TizenVG Engine + tvg::Engine::term(); +} diff --git a/test/tvgMultipleShapes.cpp b/test/tvgMultipleShapes.cpp new file mode 100644 index 0000000..fd7ea81 --- /dev/null +++ b/test/tvgMultipleShapes.cpp @@ -0,0 +1,36 @@ +#include + +using namespace std; + +#define WIDTH 800 +#define HEIGHT 800 + +static uint32_t buffer[WIDTH * HEIGHT]; + +int main(int argc, char **argv) +{ + //Initialize TizenVG Engine + tvg::Engine::init(); + + //Create a Canvas + auto canvas = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT); + + //Prepare Rectangle + auto shape1 = tvg::ShapeNode::gen(); + shape1->rect(0, 0, 400, 400, 0.1); //x, y, w, h, corner_radius + shape1->fill(0, 255, 0, 255); //r, g, b, a + canvas->push(move(shape1)); + + //Prepare Circle + auto shape2 = tvg::ShapeNode::gen(); + shape2->circle(400, 400, 200); //cx, cy, radius + shape2->fill(255, 255, 0, 255); //r, g, b, a + canvas->push(move(shape2)); + + //Draw the Shapes onto the Canvas + canvas->draw(); + canvas->sync(); + + //Terminate TizenVG Engine + tvg::Engine::term(); +} diff --git a/test/tvgPath.cpp b/test/tvgPath.cpp new file mode 100644 index 0000000..68f0998 --- /dev/null +++ b/test/tvgPath.cpp @@ -0,0 +1,39 @@ +#include + +using namespace std; + +#define WIDTH 800 +#define HEIGHT 800 + +static uint32_t buffer[WIDTH * HEIGHT]; + +int main(int argc, char **argv) +{ + //Initialize TizenVG Engine + tvg::Engine::init(); + + //Create a Canvas + auto canvas = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT); + + //Prepare Path + auto path = tvg::Path::gen(); + path.reserve(cmdCnt, ptCnt); //command count, points count + path.moveTo(...); + path.lineTo(...); + path.cubicTo(...); + path.close(); + + //Prepare a Shape + auto shape1 = tvg::ShapeNode::gen(); + shape1->path(move(path)); //propagate owner + shape1->path(path.get()); //copy data directly + shape1->fill(0, 255, 0, 255); + + //Draw the Shape onto the Canvas + canvas->push(move(shape1)); + canvas->draw(); + canvas->sync(); + + //Terminate TizenVG Engine + tvg::Engine::term(); +} diff --git a/test/tvgScene.cpp b/test/tvgScene.cpp new file mode 100644 index 0000000..56a9a6c --- /dev/null +++ b/test/tvgScene.cpp @@ -0,0 +1,49 @@ +#include + +using namespace std; + +#define WIDTH 800 +#define HEIGHT 800 + +static uint32_t buffer[WIDTH * HEIGHT]; + +int main(int argc, char **argv) +{ + //Initialize TizenVG Engine + tvg::Engine::init(); + + //Create a Canvas + auto canvas = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT); + + //Create a Scene + auto scene = tvg::SceneNode::gen(3); //reserve 3 shape nodes (optional) + + //Shape1 + auto shape1 = tvg::ShapeNode::gen(); + shape1->rect(0, 0, 400, 400, 0.1); + shape1->fill(255, 0, 0, 255); + shape1->rotate(0, 0, 45); //axis x, y, z + scene->push(move(shape1)); + + //Shape2 + auto shape2 = tvg::ShapeNode::gen(); + shape2->rect(0, 0, 400, 400, 0.1); + shape2->fill(0, 255, 0, 255); + shape2->transform(matrix); //by matrix (var matrix[4 * 4];) + scene->push(move(shape2)); + + //Shape3 + auto shape3 = tvg::ShapeNode::gen(); + shape3->rect(0, 0, 400, 400, 0.1); + shape3->fill(0, 0, 255, 255); + shape3->origin(100, 100); //offset + scene->push(move(shape3)); + + //Draw the Scene onto the Canvas + canvas->push(move(scene)); + canvas->draw(); + canvas->sync(); + + //Terminate TizenVG Engine + tvg::Engine::term(); +} diff --git a/test/tvgStroke.cpp b/test/tvgStroke.cpp new file mode 100644 index 0000000..6b90cda --- /dev/null +++ b/test/tvgStroke.cpp @@ -0,0 +1,39 @@ +#include + +using namespace std; + +#define WIDTH 800 +#define HEIGHT 800 + +static uint32_t buffer[WIDTH * HEIGHT]; + +int main(int argc, char **argv) +{ + //Initialize TizenVG Engine + tvg::Engine::init(); + + //Create a Canvas + auto canvas = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT); + + //Prepare a Shape + auto shape1 = tvg::ShapeNode::gen(); + shape1->rect(0, 0, 400, 400, 0.1); //x, y, w, h, corner_radius + shape1->fill(0, 255, 0, 255); + + //Stroke Style + shape1->strokeColor(0, 0, 0, 255); //r, g, b, a + shape1->strokeWidth(1); //1px + shape1->strokeJoin(tvg::StrokeJoin::Miter); + shape1->strokeLineCap(tvg::StrokeLineCap::Butt); + + uint32_t dash[] = {3, 1, 5, 1}; + shape1->strokeDash(dash, 4); + + //Draw the Shape onto the Canvas + canvas->push(move(shape1)); + canvas->draw(); + canvas->sync(); + + //Terminate TizenVG Engine + tvg::Engine::term(); +} diff --git a/test/tvgUpdate.cpp b/test/tvgUpdate.cpp new file mode 100644 index 0000000..5bef2b9 --- /dev/null +++ b/test/tvgUpdate.cpp @@ -0,0 +1,49 @@ +#include + +using namespace std; + +#define WIDTH 800 +#define HEIGHT 800 + +static uint32_t buffer[WIDTH * HEIGHT]; + +int main(int argc, char **argv) +{ + //Initialize TizenVG Engine + tvg::Engine::init(); + + //Create a Canvas + auto canvas = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT); + + //Create a Scene + auto scene = tvg::SceneNode::gen(); + + //Shape1 + auto shape1 = tvg::ShapeNode::gen(); + auto pshape1 = shape1->get(); //acquire shape1 pointer to access directly + shape1->rect(0, 0, 400, 400, 0.1); + shape1->fill(255, 0, 0, 255); + shape1->rotate(0, 0, 45); //axis x, y, z + scene->push(move(shape1)); + + //Draw the Scene onto the Canvas + canvas->push(move(scene)); + + //Draw frame 1 + canvas->draw(); + canvas->sync(); + + //Clear previous shape path + pshape1->clear(); + pshape1->rect(0, 0, 300, 300, 0.1); + + //Prepapre for drawing + pshape1->update(); + + //Draw frame 2 + canvas->draw(); + canvas->sync(); + + //Terminate TizenVG Engine + tvg::Engine::term(); +} -- 2.7.4 From bf056606666ac0dd1443fae5bcc0fb924f47e104 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Mon, 30 Mar 2020 20:51:26 +0900 Subject: [PATCH 4/5] Update sample prototypes. This is still a hard work and under the intensive settle up stage. Change-Id: Ibfbeaabe8a51dc5edeeccf8fe75e65e60b91f703 --- inc/tizenvg.h | 4 ++-- src/lib/tvgSwCanvas.cpp | 2 +- test/tvgComposition.cpp | 35 +++++++++++++++++++++++++++++++++++ test/tvgDrawShape.cpp | 12 ++++++++---- test/tvgGradient.cpp | 5 +---- test/tvgMultipleShapes.cpp | 1 + test/tvgPath.cpp | 4 ++-- test/tvgScene.cpp | 3 ++- test/tvgStroke.cpp | 2 +- test/tvgUpdate.cpp | 22 ++++++++++++++-------- 10 files changed, 67 insertions(+), 23 deletions(-) create mode 100644 test/tvgComposition.cpp diff --git a/inc/tizenvg.h b/inc/tizenvg.h index cc334e0..e790ea1 100644 --- a/inc/tizenvg.h +++ b/inc/tizenvg.h @@ -129,7 +129,7 @@ public: int clear() noexcept; int draw(bool async = true) noexcept; - int drawSync() noexcept; + int sync() noexcept; int target(uint32_t* buffer, size_t stride, size_t height) noexcept; @@ -157,7 +157,7 @@ public: //TODO: Gl Specific methods. Need gl backend configuration methods as well. int draw(bool async = true) noexcept { return 0; } - int drawSync() noexcept { return 0; } + int sync() noexcept { return 0; } static std::unique_ptr gen() noexcept; diff --git a/src/lib/tvgSwCanvas.cpp b/src/lib/tvgSwCanvas.cpp index 05296cd..13e91f3 100644 --- a/src/lib/tvgSwCanvas.cpp +++ b/src/lib/tvgSwCanvas.cpp @@ -55,7 +55,7 @@ int SwCanvas::draw(bool async) noexcept } -int SwCanvas::drawSync() noexcept +int SwCanvas::sync() noexcept { return 0; } diff --git a/test/tvgComposition.cpp b/test/tvgComposition.cpp new file mode 100644 index 0000000..cf5ed26 --- /dev/null +++ b/test/tvgComposition.cpp @@ -0,0 +1,35 @@ +#include + +using namespace std; + +#define WIDTH 800 +#define HEIGHT 800 + +static uint32_t buffer[WIDTH * HEIGHT]; + +int main(int argc, char **argv) +{ + //Initialize TizenVG Engine + tvg::Engine::init(); + + //Create a Composition Source Canvas + auto canvas1 = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT); + + //Draw something onto the Canvas and leaving sync to the target. + canvas1->draw(); + + //Create a Main Canvas + auto canvas2 = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT); + + //Create a Shape + auto shape = tvg::ShapeNode::gen(); + shape->composite(canvas, tvg::CompMaskAdd); + + //Draw the Scene onto the Canvas + canvas2->push(move(shape)); + canvas2->draw(); + canvas2->sync(); + + //Terminate TizenVG Engine + tvg::Engine::term(); +} diff --git a/test/tvgDrawShape.cpp b/test/tvgDrawShape.cpp index 34f4dc9..7aaba5b 100644 --- a/test/tvgDrawShape.cpp +++ b/test/tvgDrawShape.cpp @@ -15,13 +15,17 @@ int main(int argc, char **argv) //Create a Canvas auto canvas = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT); - //Prepare a Shape + //Prepare a Shape (Rectangle) auto shape1 = tvg::ShapeNode::gen(); - shape1->rect(0, 0, 400, 400, 0.1); //x, y, w, h, corner_radius - shape1->fill(0, 255, 0, 255); +// shape1->rect(0, 0, 400, 400, 0.1); //x, y, w, h, corner_radius +// shape1->fill(0, 255, 0, 255); //r, g, b, a - //Draw the Shape onto the Canvas + /* Push the shape into the Canvas drawing list + When this shape is into the canvas list, the shape could update & prepare + internal data asynchronously for coming rendering. + Canvas keeps this shape node unless user call canvas->clear() */ canvas->push(move(shape1)); + canvas->draw(); canvas->sync(); diff --git a/test/tvgGradient.cpp b/test/tvgGradient.cpp index 2bf2824..a696839 100644 --- a/test/tvgGradient.cpp +++ b/test/tvgGradient.cpp @@ -27,14 +27,11 @@ int main(int argc, char **argv) fill1->color(1, 0, 0, 255, 255); //color Stop 2: Blue shape1.fill(fill1); - //Draw the Shape onto the Canvas canvas->push(move(shape1)); //Prepare Circle auto shape2 = tvg::ShapeNode::gen(); shape2->circle(400, 400, 200); //cx, cy, radius - shape2->fill(255, 255, 0, 255); //r, g, b, a - canvas->push(move(shape2)); //Radial Gradient Fill auto fill2 = tvg::RadialFill::gen(); @@ -44,9 +41,9 @@ int main(int argc, char **argv) fill2->color(1, 0, 0, 255, 255); //color Stop 2: Blue shape2.fill(fill2); - //Draw the Shape onto the Canvas canvas->push(move(shape2)); + //Draw the Shapes onto the Canvas canvas->draw(); canvas->sync(); diff --git a/test/tvgMultipleShapes.cpp b/test/tvgMultipleShapes.cpp index fd7ea81..feeb964 100644 --- a/test/tvgMultipleShapes.cpp +++ b/test/tvgMultipleShapes.cpp @@ -14,6 +14,7 @@ int main(int argc, char **argv) //Create a Canvas auto canvas = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT); + canvas->reserve(2); //reserve 2 shape nodes (optional) //Prepare Rectangle auto shape1 = tvg::ShapeNode::gen(); diff --git a/test/tvgPath.cpp b/test/tvgPath.cpp index 68f0998..e260682 100644 --- a/test/tvgPath.cpp +++ b/test/tvgPath.cpp @@ -25,8 +25,8 @@ int main(int argc, char **argv) //Prepare a Shape auto shape1 = tvg::ShapeNode::gen(); - shape1->path(move(path)); //propagate owner - shape1->path(path.get()); //copy data directly + shape1->path(move(path)); //migrate owner otherwise, + shape1->path(path.get()); //copy raw data directly for performance shape1->fill(0, 255, 0, 255); //Draw the Shape onto the Canvas diff --git a/test/tvgScene.cpp b/test/tvgScene.cpp index 56a9a6c..f3010dc 100644 --- a/test/tvgScene.cpp +++ b/test/tvgScene.cpp @@ -16,7 +16,8 @@ int main(int argc, char **argv) auto canvas = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT); //Create a Scene - auto scene = tvg::SceneNode::gen(3); //reserve 3 shape nodes (optional) + auto scene = tvg::SceneNode::gen(); + scene->reserve(3); //reserve 3 shape nodes (optional) //Shape1 auto shape1 = tvg::ShapeNode::gen(); diff --git a/test/tvgStroke.cpp b/test/tvgStroke.cpp index 6b90cda..6a51412 100644 --- a/test/tvgStroke.cpp +++ b/test/tvgStroke.cpp @@ -26,7 +26,7 @@ int main(int argc, char **argv) shape1->strokeJoin(tvg::StrokeJoin::Miter); shape1->strokeLineCap(tvg::StrokeLineCap::Butt); - uint32_t dash[] = {3, 1, 5, 1}; + uint32_t dash[] = {3, 1, 5, 1}; //dash pattern shape1->strokeDash(dash, 4); //Draw the Shape onto the Canvas diff --git a/test/tvgUpdate.cpp b/test/tvgUpdate.cpp index 5bef2b9..3a81289 100644 --- a/test/tvgUpdate.cpp +++ b/test/tvgUpdate.cpp @@ -20,30 +20,36 @@ int main(int argc, char **argv) //Shape1 auto shape1 = tvg::ShapeNode::gen(); - auto pshape1 = shape1->get(); //acquire shape1 pointer to access directly + + /* Acquire shape1 pointer to access directly later. + instead, you should consider not to interrupt this pointer life-cycle. */ + auto pshape1 = shape1->get(); + shape1->rect(0, 0, 400, 400, 0.1); shape1->fill(255, 0, 0, 255); shape1->rotate(0, 0, 45); //axis x, y, z - scene->push(move(shape1)); - //Draw the Scene onto the Canvas + scene->push(move(shape1)); canvas->push(move(scene)); - //Draw frame 1 + //Draw first frame canvas->draw(); canvas->sync(); - //Clear previous shape path - pshape1->clear(); + /* Clear the previous shape path and Prepare a new shape path. + You can call clear() to explicitly clear path data. */ pshape1->rect(0, 0, 300, 300, 0.1); - //Prepapre for drawing + //Prepapre for drawing (this may work asynchronously) pshape1->update(); - //Draw frame 2 + //Draw second frame canvas->draw(); canvas->sync(); + //Explicitly clear all retained paint nodes. + canvas->clear(); + //Terminate TizenVG Engine tvg::Engine::term(); } -- 2.7.4 From 02b2d812e4754b1432edea53c4ddb43f4004529c Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Wed, 1 Apr 2020 19:48:37 +0900 Subject: [PATCH 5/5] implement basic interfaces major functions are added for Path specification. added backend engine infra skeleton. Change-Id: Ia923b02649cff545fa768ab8538ad7187195826f --- .gitignore | 2 +- inc/tizenvg.h | 15 ++- src/lib/gl_engine/meson.build | 9 ++ src/lib/gl_engine/tvgGlRaster.cpp | 61 +++++++++ src/lib/gl_engine/tvgGlRaster.h | 38 ++++++ src/lib/meson.build | 5 + src/lib/sw_engine/meson.build | 9 ++ src/lib/sw_engine/tvgSwRaster.cpp | 61 +++++++++ src/lib/sw_engine/tvgSwRaster.h | 38 ++++++ src/lib/tvgCanvasBase.h | 50 ++++++- src/lib/tvgCommon.h | 20 ++- src/lib/tvgEngine.cpp | 16 ++- src/lib/tvgGlCanvas.cpp | 3 +- src/lib/tvgSceneNode.cpp | 2 +- src/lib/tvgShapeNode.cpp | 86 +++++++++--- src/lib/tvgShapePath.h | 149 +++++++++++++++++++++ src/lib/tvgSwCanvas.cpp | 5 + src/meson.build | 2 +- test/makefile | 2 +- test/{tvgComposition.cpp => testComposition.cpp} | 0 test/{tvgGradient.cpp => testGradient.cpp} | 0 ...vgMultipleShapes.cpp => testMultipleShapes.cpp} | 0 test/{tvgPath.cpp => testPath.cpp} | 0 test/{tvgScene.cpp => testScene.cpp} | 0 test/{tvgDrawShape.cpp => testShape.cpp} | 4 +- test/{tvgStroke.cpp => testStroke.cpp} | 0 test/{tvgUpdate.cpp => testUpdate.cpp} | 0 27 files changed, 541 insertions(+), 36 deletions(-) create mode 100644 src/lib/gl_engine/meson.build create mode 100644 src/lib/gl_engine/tvgGlRaster.cpp create mode 100644 src/lib/gl_engine/tvgGlRaster.h create mode 100644 src/lib/sw_engine/meson.build create mode 100644 src/lib/sw_engine/tvgSwRaster.cpp create mode 100644 src/lib/sw_engine/tvgSwRaster.h create mode 100644 src/lib/tvgShapePath.h rename test/{tvgComposition.cpp => testComposition.cpp} (100%) rename test/{tvgGradient.cpp => testGradient.cpp} (100%) rename test/{tvgMultipleShapes.cpp => testMultipleShapes.cpp} (100%) rename test/{tvgPath.cpp => testPath.cpp} (100%) rename test/{tvgScene.cpp => testScene.cpp} (100%) rename test/{tvgDrawShape.cpp => testShape.cpp} (85%) rename test/{tvgStroke.cpp => testStroke.cpp} (100%) rename test/{tvgUpdate.cpp => testUpdate.cpp} (100%) diff --git a/.gitignore b/.gitignore index a6c4662..45329ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ build .vscode *.swp -test +testShape diff --git a/inc/tizenvg.h b/inc/tizenvg.h index e790ea1..aeea75f 100644 --- a/inc/tizenvg.h +++ b/inc/tizenvg.h @@ -50,7 +50,7 @@ private: \ namespace tvg { -class SceneNode; +enum class TIZENVG_EXPORT PathCommand { Close, MoveTo, LineTo, CubicTo }; /** @@ -65,7 +65,7 @@ class TIZENVG_EXPORT PaintNode { public: virtual ~PaintNode() {} - virtual int prepare() = 0; + virtual int update() = 0; }; @@ -82,7 +82,12 @@ class TIZENVG_EXPORT ShapeNode final : public PaintNode public: ~ShapeNode(); - int prepare() noexcept override; + int update() noexcept override; + + int appendRect(float x, float y, float w, float h, float radius) noexcept; + int appendCircle(float cx, float cy, float radius) noexcept; + int fill(uint32_t r, uint32_t g, uint32_t b, uint32_t a) noexcept; + int clear() noexcept; static std::unique_ptr gen(); @@ -103,8 +108,9 @@ class TIZENVG_EXPORT SceneNode final : public PaintNode public: ~SceneNode(); + int update() noexcept override; + int push(std::unique_ptr shape) noexcept; - int prepare() noexcept override; static std::unique_ptr gen() noexcept; @@ -128,6 +134,7 @@ public: int push(std::unique_ptr paint) noexcept; int clear() noexcept; + int update(PaintNode* node) noexcept; int draw(bool async = true) noexcept; int sync() noexcept; diff --git a/src/lib/gl_engine/meson.build b/src/lib/gl_engine/meson.build new file mode 100644 index 0000000..2c3fe06 --- /dev/null +++ b/src/lib/gl_engine/meson.build @@ -0,0 +1,9 @@ +source_file = [ + 'tvgGlRaster.h', + 'tvgGlRaster.cpp', +] + +glraster_dep = declare_dependency( + include_directories : include_directories('.'), + sources : source_file +) diff --git a/src/lib/gl_engine/tvgGlRaster.cpp b/src/lib/gl_engine/tvgGlRaster.cpp new file mode 100644 index 0000000..eca8c47 --- /dev/null +++ b/src/lib/gl_engine/tvgGlRaster.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef _TVG_GL_RASTER_CPP_ +#define _TVG_GL_RASTER_CPP_ + +#include "tvgCommon.h" +#include "tvgGlRaster.h" + + +static GlRaster* pInst = nullptr; + +int GlRaster::prepare(ShapeNode *shape) +{ + cout << "GlRaster prepare!!" << endl; + + return 0; +} + + +int GlRaster::init() +{ + if (pInst) return -1; + pInst = new GlRaster(); + assert(pInst); + + return 0; +} + + +int GlRaster::term() +{ + if (!pInst) return -1; + cout << "GlRaster(" << pInst << ") destroyed!" << endl; + delete(pInst); + pInst = nullptr; + return 0; +} + + +GlRaster* GlRaster::inst() +{ + assert(pInst); + return pInst; +} + + +#endif /* _TVG_GL_RASTER_CPP_ */ diff --git a/src/lib/gl_engine/tvgGlRaster.h b/src/lib/gl_engine/tvgGlRaster.h new file mode 100644 index 0000000..10c4462 --- /dev/null +++ b/src/lib/gl_engine/tvgGlRaster.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef _TVG_GL_RASTER_H_ +#define _TVG_GL_RASTER_H_ + +namespace tvg +{ + +class GlRaster : public RasterMethod +{ +public: + int prepare(ShapeNode *shape) override; + static GlRaster* inst(); + static int init(); + static int term(); + +private: + GlRaster(){}; + ~GlRaster(){}; +}; + +} + +#endif /* _TVG_GL_RASTER_H_ */ diff --git a/src/lib/meson.build b/src/lib/meson.build index fb856bf..b2243fe 100644 --- a/src/lib/meson.build +++ b/src/lib/meson.build @@ -1,7 +1,11 @@ +subdir('sw_engine') +subdir('gl_engine') + source_file = [ 'tvgCommon.h', 'tvgEngine.cpp', 'tvgCanvasBase.h', + 'tvgShapePath.h', 'tvgSwCanvas.cpp', 'tvgGlCanvas.cpp', 'tvgSceneNode.cpp', @@ -12,3 +16,4 @@ src_dep = declare_dependency( include_directories : include_directories('.'), sources : source_file ) + diff --git a/src/lib/sw_engine/meson.build b/src/lib/sw_engine/meson.build new file mode 100644 index 0000000..0a29e22 --- /dev/null +++ b/src/lib/sw_engine/meson.build @@ -0,0 +1,9 @@ +source_file = [ + 'tvgSwRaster.h', + 'tvgSwRaster.cpp', +] + +swraster_dep = declare_dependency( + include_directories : include_directories('.'), + sources : source_file +) diff --git a/src/lib/sw_engine/tvgSwRaster.cpp b/src/lib/sw_engine/tvgSwRaster.cpp new file mode 100644 index 0000000..fa9a845 --- /dev/null +++ b/src/lib/sw_engine/tvgSwRaster.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef _TVG_SW_RASTER_CPP_ +#define _TVG_SW_RASTER_CPP_ + +#include "tvgCommon.h" +#include "tvgSwRaster.h" + + +static SwRaster* pInst = nullptr; + +int SwRaster::prepare(ShapeNode *shape) +{ + cout << "SWRaster prepare!!" << endl; + + return 0; +} + + +int SwRaster::init() +{ + if (pInst) return -1; + pInst = new SwRaster(); + assert(pInst); + + return 0; +} + + +int SwRaster::term() +{ + if (!pInst) return -1; + cout << "SwRaster(" << pInst << ") destroyed!" << endl; + delete(pInst); + pInst = nullptr; + return 0; +} + + +SwRaster* SwRaster::inst() +{ + assert(pInst); + return pInst; +} + + +#endif /* _TVG_SW_RASTER_CPP_ */ diff --git a/src/lib/sw_engine/tvgSwRaster.h b/src/lib/sw_engine/tvgSwRaster.h new file mode 100644 index 0000000..e79f628 --- /dev/null +++ b/src/lib/sw_engine/tvgSwRaster.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef _TVG_SW_RASTER_H_ +#define _TVG_SW_RASTER_H_ + +namespace tvg +{ + +class SwRaster : public RasterMethod +{ +public: + int prepare(ShapeNode *shape) override; + static SwRaster* inst(); + static int init(); + static int term(); + +private: + SwRaster(){}; + ~SwRaster(){}; +}; + +} + +#endif /* _TVG_SW_RASTER_H_ */ diff --git a/src/lib/tvgCanvasBase.h b/src/lib/tvgCanvasBase.h index 83607bf..2a4632e 100644 --- a/src/lib/tvgCanvasBase.h +++ b/src/lib/tvgCanvasBase.h @@ -14,8 +14,8 @@ * limitations under the License. * */ -#ifndef _TVG_CANVAS_CPP_ -#define _TVG_CANVAS_CPP_ +#ifndef _TVG_CANVAS_BASE_CPP_ +#define _TVG_CANVAS_BASE_CPP_ #include "tvgCommon.h" @@ -25,17 +25,59 @@ struct CanvasBase { + vector nodes; + RasterMethod* raster; - int push(unique_ptr paint) + CanvasBase(RasterMethod *pRaster):raster(pRaster) + { + + } + + ~CanvasBase() { + clear(); + } + + int reserve(size_t n) + { + nodes.reserve(n); + return 0; } int clear() { + for (auto node : nodes) { + delete(node); + } + nodes.clear(); + return 0; } + int push(unique_ptr paint) + { + PaintNode *node = paint.release(); + assert(node); + + nodes.push_back(node); + + int ret = node->update(); + if (ret) return ret; + + if (SceneNode *scene = dynamic_cast(node)) { + + //TODO: + + } else if (ShapeNode *shape = dynamic_cast(node)) { + return raster->prepare(shape); + } + + cout << "What type of PaintNode? = " << node << endl; + + return -1; + } + }; @@ -43,4 +85,4 @@ struct CanvasBase /* External Class Implementation */ /************************************************************************/ -#endif /* _TVG_CANVAS_CPP_ */ +#endif /* _TVG_CANVAS_BASE_CPP_ */ diff --git a/src/lib/tvgCommon.h b/src/lib/tvgCommon.h index f69af00..0140cc8 100644 --- a/src/lib/tvgCommon.h +++ b/src/lib/tvgCommon.h @@ -24,6 +24,24 @@ using namespace std; using namespace tvg; -using var = float; + +namespace tvg +{ + +struct Point +{ + float x, y; +}; + +class RasterMethod +{ +public: + virtual ~RasterMethod() {} + virtual int prepare(ShapeNode *shape) = 0; +}; + + +} + #endif //_TVG_COMMON_H_ diff --git a/src/lib/tvgEngine.cpp b/src/lib/tvgEngine.cpp index 838f4ca..5f8f533 100644 --- a/src/lib/tvgEngine.cpp +++ b/src/lib/tvgEngine.cpp @@ -18,6 +18,8 @@ #define _TVG_ENGINE_CPP_ #include "tvgCommon.h" +#include "tvgSwRaster.h" +#include "tvgGlRaster.h" /************************************************************************/ /* Internal Class Implementation */ @@ -30,13 +32,23 @@ int Engine::init() noexcept { - return 0; + //TODO: Initialize Raster engines by configuration. + + int ret = 0; + ret |= SwRaster::init(); + ret |= GlRaster::init(); + + return ret; } int Engine::term() noexcept { - return 0; + int ret = 0; + ret |= SwRaster::term(); + ret |= GlRaster::term(); + + return ret; } #endif /* _TVG_ENGINE_CPP_ */ diff --git a/src/lib/tvgGlCanvas.cpp b/src/lib/tvgGlCanvas.cpp index 573600e..49828ac 100644 --- a/src/lib/tvgGlCanvas.cpp +++ b/src/lib/tvgGlCanvas.cpp @@ -19,6 +19,7 @@ #include "tvgCommon.h" #include "tvgCanvasBase.h" +#include "tvgGlRaster.h" /************************************************************************/ /* Internal Class Implementation */ @@ -26,7 +27,7 @@ struct GlCanvas::Impl : CanvasBase { - //... + Impl() : CanvasBase(GlRaster::inst()) {} }; diff --git a/src/lib/tvgSceneNode.cpp b/src/lib/tvgSceneNode.cpp index 8da41fc..68ddbc9 100644 --- a/src/lib/tvgSceneNode.cpp +++ b/src/lib/tvgSceneNode.cpp @@ -57,7 +57,7 @@ int SceneNode :: push(unique_ptr shape) noexcept } -int SceneNode :: prepare() noexcept +int SceneNode :: update() noexcept { return 0; diff --git a/src/lib/tvgShapeNode.cpp b/src/lib/tvgShapeNode.cpp index 4fb4b10..59b40a7 100644 --- a/src/lib/tvgShapeNode.cpp +++ b/src/lib/tvgShapeNode.cpp @@ -18,6 +18,7 @@ #define _TVG_SHAPE_NODE_CPP_ #include "tvgCommon.h" +#include "tvgShapePath.h" /************************************************************************/ /* Internal Class Implementation */ @@ -33,33 +34,25 @@ struct ShapeStroke }; -struct ShapePath -{ -}; - - struct ShapeTransform { - var e[4*4]; -}; - - -struct ShapeChildren -{ - vector> v; + float e[4*4]; }; struct ShapeNode::Impl { - ShapeChildren *children = nullptr; ShapeTransform *transform = nullptr; ShapeFill *fill = nullptr; ShapeStroke *stroke = nullptr; ShapePath *path = nullptr; - uint32_t color = 0; - uint32_t id = 0; + uint8_t color[4] = {0, 0, 0, 0}; //r, g, b, a + + Impl() : path(new ShapePath) + { + + } ~Impl() { @@ -67,9 +60,7 @@ struct ShapeNode::Impl if (stroke) delete(stroke); if (fill) delete(fill); if (transform) delete(transform); - if (children) delete(children); } - }; @@ -95,10 +86,69 @@ unique_ptr ShapeNode::gen() } -int ShapeNode :: prepare() noexcept +int ShapeNode :: update() noexcept { + auto impl = pImpl.get(); + assert(impl); + return 0; } +int ShapeNode :: clear() noexcept +{ + auto impl = pImpl.get(); + assert(impl); + + return impl->path->clear(); +} + + +int ShapeNode ::appendCircle(float cx, float cy, float radius) noexcept +{ + return 0; +} + + +int ShapeNode :: appendRect(float x, float y, float w, float h, float radius) noexcept +{ + auto impl = pImpl.get(); + assert(impl); + + //clamping radius by minimum size + auto min = (w < h ? w : h) * 0.5f; + if (radius > min) radius = min; + + //rectangle + if (radius == 0) { + impl->path->reserve(5, 4); + impl->path->moveTo(x, y); + impl->path->lineTo(x + w, y); + impl->path->lineTo(x + w, y + h); + impl->path->lineTo(x, y + h); + impl->path->close(); + //circle + } else if (w == h && radius * 2 == w) { + appendCircle(x + (w * 0.5f), y + (h * 0.5f), radius); + } else { + //... + } + + return 0; +} + + +int ShapeNode :: fill(uint32_t r, uint32_t g, uint32_t b, uint32_t a) noexcept +{ + auto impl = pImpl.get(); + assert(impl); + + impl->color[0] = r; + impl->color[1] = g; + impl->color[2] = b; + impl->color[3] = a; + + return 0; +} + #endif //_TVG_SHAPE_NODE_CPP_ diff --git a/src/lib/tvgShapePath.h b/src/lib/tvgShapePath.h new file mode 100644 index 0000000..eb3849e --- /dev/null +++ b/src/lib/tvgShapePath.h @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef _TVG_SHAPE_PATH_CPP_ +#define _TVG_SHAPE_PATH_CPP_ + +#include "tvgCommon.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +struct ShapePath +{ + PathCommand* cmds = nullptr; + uint32_t cmdCnt = 0; + uint32_t reservedCmdCnt = 0; + + Point *pts = nullptr; + uint32_t ptsCnt = 0; + uint32_t reservedPtsCnt = 0; + + + ~ShapePath() + { + if (cmds) delete(cmds); + if (pts) delete(pts); + } + + int reserveCmd(uint32_t cmdCnt) + { + if (cmdCnt > reservedCmdCnt) { + reservedCmdCnt = cmdCnt; + cmds = static_cast(realloc(cmds, sizeof(PathCommand) * reservedCmdCnt)); + assert(cmds); + } + return 0; + } + + int reservePts(uint32_t ptsCnt) + { + if (ptsCnt > reservedPtsCnt) { + reservedPtsCnt = ptsCnt; + pts = static_cast(realloc(pts, sizeof(Point) * reservedPtsCnt)); + assert(pts); + } + return 0; + } + + int reserve(uint32_t cmdCnt, uint32_t ptsCnt) + { + reserveCmd(cmdCnt); + reservePts(ptsCnt); + + return 0; + } + + int clear() + { + cmdCnt = 0; + ptsCnt = 0; + + return 0; + } + + int moveTo(float x, float y) + { + if (cmdCnt + 1 > reservedCmdCnt) reserveCmd((cmdCnt + 1) * 2); + if (ptsCnt + 2 > reservedPtsCnt) reservePts((ptsCnt + 2) * 2); + + cmds[cmdCnt++] = PathCommand::MoveTo; + pts[ptsCnt++] = {x, y}; + + return 0; + } + + int lineTo(float x, float y) + { + if (cmdCnt + 1 > reservedCmdCnt) reserveCmd((cmdCnt + 1) * 2); + if (ptsCnt + 2 > reservedPtsCnt) reservePts((ptsCnt + 2) * 2); + + cmds[cmdCnt++] = PathCommand::LineTo; + pts[ptsCnt++] = {x, y}; + + return 0; + } + + int cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) + { + if (cmdCnt + 1 > reservedCmdCnt) reserveCmd((cmdCnt + 1) * 2); + if (ptsCnt + 3 > reservedPtsCnt) reservePts((ptsCnt + 3) * 2); + + cmds[cmdCnt++] = PathCommand::CubicTo; + pts[ptsCnt++] = {cx1, cy1}; + pts[ptsCnt++] = {cx2, cy2}; + pts[ptsCnt++] = {x, y}; + + return 0; + } + + int close() + { + if (cmdCnt + 1 > reservedCmdCnt) reserveCmd((cmdCnt + 1) * 2); + cmds[cmdCnt++] = PathCommand::Close; + + return 0; + } + + int bounds(float& x, float& y, float& w, float& h) + { + if (ptsCnt == 0) return -1; + + Point min = { pts[0].x, pts[0].y }; + Point max = { pts[0].x, pts[0].y }; + + for(uint32_t i = 1; i <= ptsCnt; ++i) { + if (pts[i].x < min.x) min.x = pts[i].x; + if (pts[i].y < min.y) min.y = pts[i].y; + if (pts[i].x > max.x) max.x = pts[i].x; + if (pts[i].y > max.y) max.y = pts[i].y; + } + + x = min.x; + y = min.y; + w = max.x - min.x; + h = max.y - min.y; + + return 0; + } +}; + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +#endif //_TVG_SHAPE_PATH_CPP_ diff --git a/src/lib/tvgSwCanvas.cpp b/src/lib/tvgSwCanvas.cpp index 13e91f3..00338ef 100644 --- a/src/lib/tvgSwCanvas.cpp +++ b/src/lib/tvgSwCanvas.cpp @@ -19,6 +19,8 @@ #include "tvgCommon.h" #include "tvgCanvasBase.h" +#include "tvgSwRaster.h" + /************************************************************************/ /* Internal Class Implementation */ @@ -29,6 +31,8 @@ struct SwCanvas::Impl : CanvasBase uint32_t* buffer = nullptr; int stride = 0; int height = 0; + + Impl() : CanvasBase(SwRaster::inst()) {} }; @@ -65,6 +69,7 @@ int SwCanvas::push(unique_ptr paint) noexcept { auto impl = pImpl.get(); assert(impl); + return impl->push(move(paint)); } diff --git a/src/meson.build b/src/meson.build index d3fde4d..495e4c7 100644 --- a/src/meson.build +++ b/src/meson.build @@ -3,7 +3,7 @@ compiler_flags = ['-DTIZENVG_BUILD'] subdir('lib') subdir('examples') -tizenvg_lib_dep = [ src_dep ] +tizenvg_lib_dep = [ src_dep, swraster_dep, glraster_dep ] tizenvg_lib = library( 'tizenvg', diff --git a/test/makefile b/test/makefile index 0f89da0..5fdc45c 100644 --- a/test/makefile +++ b/test/makefile @@ -1,2 +1,2 @@ all: - gcc -o tvgDrawShape tvgDrawShape.cpp -g -lstdc++ `pkg-config --cflags --libs tizenvg` + gcc -o testShape testShape.cpp -g -lstdc++ `pkg-config --cflags --libs tizenvg` diff --git a/test/tvgComposition.cpp b/test/testComposition.cpp similarity index 100% rename from test/tvgComposition.cpp rename to test/testComposition.cpp diff --git a/test/tvgGradient.cpp b/test/testGradient.cpp similarity index 100% rename from test/tvgGradient.cpp rename to test/testGradient.cpp diff --git a/test/tvgMultipleShapes.cpp b/test/testMultipleShapes.cpp similarity index 100% rename from test/tvgMultipleShapes.cpp rename to test/testMultipleShapes.cpp diff --git a/test/tvgPath.cpp b/test/testPath.cpp similarity index 100% rename from test/tvgPath.cpp rename to test/testPath.cpp diff --git a/test/tvgScene.cpp b/test/testScene.cpp similarity index 100% rename from test/tvgScene.cpp rename to test/testScene.cpp diff --git a/test/tvgDrawShape.cpp b/test/testShape.cpp similarity index 85% rename from test/tvgDrawShape.cpp rename to test/testShape.cpp index 7aaba5b..64603ae 100644 --- a/test/tvgDrawShape.cpp +++ b/test/testShape.cpp @@ -17,8 +17,8 @@ int main(int argc, char **argv) //Prepare a Shape (Rectangle) auto shape1 = tvg::ShapeNode::gen(); -// shape1->rect(0, 0, 400, 400, 0.1); //x, y, w, h, corner_radius -// shape1->fill(0, 255, 0, 255); //r, g, b, a + shape1->appendRect(0, 0, 400, 400, 0); //x, y, w, h, corner_radius + shape1->fill(0, 255, 0, 255); //r, g, b, a /* Push the shape into the Canvas drawing list When this shape is into the canvas list, the shape could update & prepare diff --git a/test/tvgStroke.cpp b/test/testStroke.cpp similarity index 100% rename from test/tvgStroke.cpp rename to test/testStroke.cpp diff --git a/test/tvgUpdate.cpp b/test/testUpdate.cpp similarity index 100% rename from test/tvgUpdate.cpp rename to test/testUpdate.cpp -- 2.7.4