diff --git a/.gitignore b/.gitignore index af30a22a..7aa8bd7f 100644 --- a/.gitignore +++ b/.gitignore @@ -18,5 +18,4 @@ testLinearGradient testRadialGradient testGradientTransform testSvg -testSvg2 testGlShape diff --git a/inc/tizenvg.h b/inc/tizenvg.h index c62dda2f..bc541b31 100644 --- a/inc/tizenvg.h +++ b/inc/tizenvg.h @@ -64,7 +64,7 @@ class Scene; class Canvas; -enum class TVG_EXPORT Result { Success = 0, InvalidArguments, InsufficientCondition, FailedAllocation, MemoryCorruption, Unknown }; +enum class TVG_EXPORT Result { Success = 0, InvalidArguments, InsufficientCondition, FailedAllocation, MemoryCorruption, NonSupport, Unknown }; enum class TVG_EXPORT PathCommand { Close = 0, MoveTo, LineTo, CubicTo }; enum class TVG_EXPORT StrokeCap { Square = 0, Round, Butt }; enum class TVG_EXPORT StrokeJoin { Bevel = 0, Round, Miter }; @@ -283,8 +283,7 @@ public: Result push(std::unique_ptr paint) noexcept; Result reserve(uint32_t size) noexcept; - Result load(const std::string& path, float w, float h, bool lazy = false) noexcept; - Result save(const std::string& path) noexcept; + Result load(const std::string& path) noexcept; Result rotate(float degree) noexcept override; Result scale(float factor) noexcept override; diff --git a/src/lib/gl_engine/meson.build b/src/lib/gl_engine/meson.build index a5409a74..943fb067 100644 --- a/src/lib/gl_engine/meson.build +++ b/src/lib/gl_engine/meson.build @@ -14,7 +14,7 @@ source_file = [ 'tvgGlShaderSrc.cpp', ] -glraster_dep = declare_dependency( +glengine_dep = declare_dependency( include_directories : include_directories('.'), sources : source_file ) diff --git a/src/lib/meson.build b/src/lib/meson.build index c936501b..32db5f10 100644 --- a/src/lib/meson.build +++ b/src/lib/meson.build @@ -4,6 +4,8 @@ subdir('gl_engine') source_file = [ 'tvgCanvasImpl.h', 'tvgCommon.h', + 'tvgLoader.h', + 'tvgLoaderMgr.h', 'tvgRenderCommon.h', 'tvgSceneImpl.h', 'tvgShapePath.h', @@ -13,6 +15,7 @@ source_file = [ 'tvgGlCanvas.cpp', 'tvgInitializer.cpp', 'tvgLinearGradient.cpp', + 'tvgLoaderMgr.cpp', 'tvgRadialGradient.cpp', 'tvgScene.cpp', 'tvgShape.cpp', diff --git a/src/lib/sw_engine/meson.build b/src/lib/sw_engine/meson.build index f96fe970..8b062587 100644 --- a/src/lib/sw_engine/meson.build +++ b/src/lib/sw_engine/meson.build @@ -10,7 +10,7 @@ source_file = [ 'tvgSwStroke.cpp', ] -swraster_dep = declare_dependency( +swengine_dep = declare_dependency( include_directories : include_directories('.'), sources : source_file ) diff --git a/src/lib/tvgCommon.h b/src/lib/tvgCommon.h index 49c3f968..d147521b 100644 --- a/src/lib/tvgCommon.h +++ b/src/lib/tvgCommon.h @@ -37,6 +37,8 @@ using namespace tvg; #define FILL_ID_LINEAR 0 #define FILL_ID_RADIAL 1 +#include "tvgLoader.h" +#include "tvgLoaderMgr.h" #include "tvgRenderCommon.h" #include "tvgShapePath.h" #include "tvgShapeImpl.h" diff --git a/src/lib/tvgInitializer.cpp b/src/lib/tvgInitializer.cpp index ac6ce3ab..857698d2 100644 --- a/src/lib/tvgInitializer.cpp +++ b/src/lib/tvgInitializer.cpp @@ -20,6 +20,7 @@ #include "tvgCommon.h" #include "tvgSwRenderer.h" #include "tvgGlRenderer.h" +#include "tvgLoaderMgr.h" /************************************************************************/ /* Internal Class Implementation */ @@ -39,9 +40,7 @@ Result Initializer::init(CanvasEngine engine) noexcept return Result::InvalidArguments; } - //TODO: check modules then enable them - //1. TVG - //2. SVG + if (!LoaderMgr::init()) return Result::Unknown; return Result::Success; } @@ -59,6 +58,8 @@ Result Initializer::term(CanvasEngine engine) noexcept return Result::InvalidArguments; } + if (!LoaderMgr::term()) return Result::Unknown; + return Result::Success; } diff --git a/src/lib/tvgLoader.h b/src/lib/tvgLoader.h new file mode 100644 index 00000000..8a1c9184 --- /dev/null +++ b/src/lib/tvgLoader.h @@ -0,0 +1,36 @@ +/* + * 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_LOADER_H_ +#define _TVG_LOADER_H_ + +namespace tvg +{ + +class Loader +{ +public: + virtual ~Loader() {} + + virtual bool open(const char* path) = 0; + virtual bool read() = 0; + virtual bool close() = 0; + virtual unique_ptr data() = 0; +}; + +} + +#endif //_TVG_LOADER_H_ \ No newline at end of file diff --git a/src/lib/tvgLoaderMgr.cpp b/src/lib/tvgLoaderMgr.cpp new file mode 100644 index 00000000..a99838b7 --- /dev/null +++ b/src/lib/tvgLoaderMgr.cpp @@ -0,0 +1,52 @@ +/* + * 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_LOADER_MGR_CPP_ +#define _TVG_LOADER_MGR_CPP_ + +#include "tvgCommon.h" +#include "tvgSvgLoader.h" + + +static int initCnt = 0; + +bool LoaderMgr::init() +{ + if (initCnt > 0) return true; + ++initCnt; + + //TODO: + + return true; +} + +bool LoaderMgr::term() +{ + --initCnt; + if (initCnt > 0) return true; + + //TODO: + + return true; +} + +unique_ptr LoaderMgr::loader(const char* path) +{ + //TODO: + return unique_ptr(new SvgLoader); +} + +#endif //_TVG_LOADER_MGR_CPP_ \ No newline at end of file diff --git a/src/lib/tvgLoaderMgr.h b/src/lib/tvgLoaderMgr.h new file mode 100644 index 00000000..0d37012f --- /dev/null +++ b/src/lib/tvgLoaderMgr.h @@ -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. + * + */ +#ifndef _TVG_LOADER_MGR_H_ +#define _TVG_LOADER_MGR_H_ + +struct LoaderMgr +{ + static bool init(); + static bool term(); + static unique_ptr loader(const char* path); +}; + +#endif //_TVG_LOADER_MGR_H_ \ No newline at end of file diff --git a/src/lib/tvgScene.cpp b/src/lib/tvgScene.cpp index c0939332..41620a0b 100644 --- a/src/lib/tvgScene.cpp +++ b/src/lib/tvgScene.cpp @@ -108,26 +108,14 @@ Result Scene::bounds(float* x, float* y, float* w, float* h) const noexcept } -Result Scene::load(const std::string& path, float w, float h, bool lazy) noexcept +Result Scene::load(const std::string& path) noexcept { if (path.empty()) return Result::InvalidArguments; auto impl = pImpl.get(); if (!impl) return Result::MemoryCorruption; - return impl->load(path, w, h, lazy); + return impl->load(path); } - -Result Scene::save(const std::string& path) noexcept -{ - if (path.empty()) return Result::InvalidArguments; - - auto impl = pImpl.get(); - if (!impl) return Result::MemoryCorruption; - - return impl->save(path); -} - - #endif /* _TVG_SCENE_CPP_ */ \ No newline at end of file diff --git a/src/lib/tvgSceneImpl.h b/src/lib/tvgSceneImpl.h index 5ba8d510..5e67a666 100644 --- a/src/lib/tvgSceneImpl.h +++ b/src/lib/tvgSceneImpl.h @@ -28,6 +28,7 @@ struct Scene::Impl vector paints; RenderTransform *transform = nullptr; uint32_t flag = RenderUpdateFlag::None; + unique_ptr loader = nullptr; ~Impl() { @@ -71,6 +72,15 @@ struct Scene::Impl bool update(RenderMethod &renderer, const RenderTransform* pTransform = nullptr, uint32_t pFlag = 0) { + if (loader) { + auto scene = loader->data(); + auto p = scene.release(); + if (!p) return false; + paints.push_back(p); + loader->close(); + loader.reset(nullptr); + } + if (flag & RenderUpdateFlag::Transform) { if (!transform) return false; if (!transform->update()) { @@ -192,13 +202,12 @@ struct Scene::Impl return true; } - Result load(const string& path, float w, float h, bool lazy) - { - return Result::Success; - } - - Result save(const string& path) + Result load(const string& path) { + if (loader) loader->close(); + loader = LoaderMgr::loader(path.c_str()); + if (!loader || !loader->open(path.c_str())) return Result::NonSupport; + if (!loader->read()) return Result::Unknown; return Result::Success; } }; diff --git a/src/loaders/meson.build b/src/loaders/meson.build new file mode 100644 index 00000000..53186ddb --- /dev/null +++ b/src/loaders/meson.build @@ -0,0 +1 @@ +subdir('svg_loader') diff --git a/src/loaders/svg_loader/meson.build b/src/loaders/svg_loader/meson.build new file mode 100644 index 00000000..1bd40c10 --- /dev/null +++ b/src/loaders/svg_loader/meson.build @@ -0,0 +1,9 @@ +source_file = [ + 'tvgSvgLoader.h', + 'tvgSvgLoader.cpp', +] + +svgloader_dep = declare_dependency( + include_directories : include_directories('.'), + sources : source_file +) diff --git a/src/loaders/svg_loader/tvgSvgLoader.cpp b/src/loaders/svg_loader/tvgSvgLoader.cpp new file mode 100644 index 00000000..f4b8f43b --- /dev/null +++ b/src/loaders/svg_loader/tvgSvgLoader.cpp @@ -0,0 +1,80 @@ +/* + * 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_SVG_LOADER_CPP_ +#define _TVG_SVG_LOADER_CPP_ + +#include "tvgSvgLoader.h" + + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +SvgLoader::SvgLoader() +{ + cout << "SvgLoader()" << endl; +} + + +SvgLoader::~SvgLoader() +{ + cout << "~SvgLoader()" << endl; +} + + +bool SvgLoader::open(const char* path) +{ + //TODO: + cout << "SvgLoader::open()" << endl; + + return false; +} + + +bool SvgLoader::read() +{ + //TODO: + cout << "SvgLoader::read()" << endl; + + return false; +} + + +bool SvgLoader::close() +{ + //TODO: + cout << "SvgLoader::close()" << endl; + + return false; +} + + +unique_ptr SvgLoader::data() +{ + //TODO: + cout << "SvgLoader::data()" << endl; + + return nullptr; +} + +#endif //_TVG_SVG_LOADER_CPP_ \ No newline at end of file diff --git a/src/loaders/svg_loader/tvgSvgLoader.h b/src/loaders/svg_loader/tvgSvgLoader.h new file mode 100644 index 00000000..2b4d8b16 --- /dev/null +++ b/src/loaders/svg_loader/tvgSvgLoader.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_SVG_LOADER_H_ +#define _TVG_SVG_LOADER_H_ + +#include "tvgCommon.h" + +class SvgLoader : public Loader +{ +private: + //TODO: + +public: + SvgLoader(); + ~SvgLoader(); + + bool open(const char* path) override; + bool read() override; + bool close() override; + unique_ptr data() override; +}; + + +#endif //_TVG_SVG_LOADER_H_ \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index a0ef37db..e49c9a0d 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,12 +1,14 @@ compiler_flags = ['-DTVG_BUILD'] subdir('lib') +subdir('loaders') subdir('examples') + m_dep = meson.get_compiler('cpp').find_library('m') egl_dep = meson.get_compiler('cpp').find_library('EGL') -gl_dep = meson.get_compiler('cpp').find_library('GLESv2') +gles_dep = meson.get_compiler('cpp').find_library('GLESv2') -tizenvg_lib_dep = [ src_dep, swraster_dep, glraster_dep, m_dep, egl_dep, gl_dep] +tizenvg_lib_dep = [ src_dep, swengine_dep, glengine_dep, m_dep, egl_dep, gles_dep, svgloader_dep] tizenvg_lib = library( diff --git a/test/makefile b/test/makefile index aca250bf..501eef58 100755 --- a/test/makefile +++ b/test/makefile @@ -15,6 +15,5 @@ all: gcc -o testLinearGradient testLinearGradient.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg` gcc -o testRadialGradient testRadialGradient.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg` gcc -o testGradientTransform testGradientTransform.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg` -# gcc -o testSvg testSvg.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg` -# gcc -o testSvg2 testSvg2.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg` + gcc -o testSvg testSvg.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg` gcc -o testGlShape testGlShape.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg` diff --git a/test/testSvg.cpp b/test/testSvg.cpp index dea96a2e..e9189023 100644 --- a/test/testSvg.cpp +++ b/test/testSvg.cpp @@ -17,9 +17,7 @@ void tvgtest() auto canvas = tvg::SwCanvas::gen(); canvas->target(buffer, WIDTH, WIDTH, HEIGHT); - /* Create a SVG scene, keep original size, - You can pass 0 x 0 size for lazying loading in this case. - scene->load("sample.svg", 0, 0, true); */ + // Create a SVG scene, request the original size, auto scene = tvg::Scene::gen(); scene->load("sample.svg"); canvas->push(move(scene)); diff --git a/test/testSvg2.cpp b/test/testSvg2.cpp deleted file mode 100644 index 4714db6b..00000000 --- a/test/testSvg2.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include -#include - -using namespace std; - -#define WIDTH 800 -#define HEIGHT 800 - -static uint32_t buffer[WIDTH * HEIGHT]; - -void tvgtest() -{ - //Initialize TizenVG Engine - tvg::Initializer::init(tvg::CanvasEngine::Sw); - - //Create a Canvas - auto canvas = tvg::SwCanvas::gen(); - canvas->target(buffer, WIDTH, WIDTH, HEIGHT); - - //Create a SVG scene, keep aspect ratio to width/2 with lazy loading - auto scene = tvg::Scene::gen(); - scene->load("sample.svg", WIDTH/2, 0, true); - canvas->push(move(scene)); - - //Create a SVG scene, keep aspect ratio to height/2 with lazy loading - auto scene2 = tvg::Scene::gen(); - scene2->load("sample.svg", 0, HEIGHT/2, true); - scene2->translate(WIDTH/2, HEIGHT/2); - canvas->push(move(scene2)); - - canvas->draw(); - canvas->sync(); - - //Terminate TizenVG Engine - tvg::Initializer::term(tvg::CanvasEngine::Sw); -} - -void -win_del(void *data, Evas_Object *o, void *ev) -{ - elm_exit(); -} - - -int main(int argc, char **argv) -{ - tvgtest(); - - //Show the result using EFL... - elm_init(argc, argv); - - Eo* win = elm_win_util_standard_add(NULL, "TizenVG Test"); - evas_object_smart_callback_add(win, "delete,request", win_del, 0); - - Eo* img = evas_object_image_filled_add(evas_object_evas_get(win)); - evas_object_image_size_set(img, WIDTH, HEIGHT); - evas_object_image_data_set(img, buffer); - evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_show(img); - - elm_win_resize_object_add(win, img); - evas_object_geometry_set(win, 0, 0, WIDTH, HEIGHT); - evas_object_show(win); - - elm_run(); - elm_shutdown(); -}