common loader: build up loader infrastructure. 56/236656/4
authorHermet Park <chuneon.park@samsung.com>
Fri, 19 Jun 2020 05:49:07 +0000 (14:49 +0900)
committerHermet Park <chuneon.park@samsung.com>
Fri, 19 Jun 2020 06:46:02 +0000 (15:46 +0900)
Change-Id: I62aaed43015301ec39e414833f37d6c5485d8043

20 files changed:
.gitignore
inc/tizenvg.h
src/lib/gl_engine/meson.build
src/lib/meson.build
src/lib/sw_engine/meson.build
src/lib/tvgCommon.h
src/lib/tvgInitializer.cpp
src/lib/tvgLoader.h [new file with mode: 0644]
src/lib/tvgLoaderMgr.cpp [new file with mode: 0644]
src/lib/tvgLoaderMgr.h [new file with mode: 0644]
src/lib/tvgScene.cpp
src/lib/tvgSceneImpl.h
src/loaders/meson.build [new file with mode: 0644]
src/loaders/svg_loader/meson.build [new file with mode: 0644]
src/loaders/svg_loader/tvgSvgLoader.cpp [new file with mode: 0644]
src/loaders/svg_loader/tvgSvgLoader.h [new file with mode: 0644]
src/meson.build
test/makefile
test/testSvg.cpp
test/testSvg2.cpp [deleted file]

index af30a22..7aa8bd7 100644 (file)
@@ -18,5 +18,4 @@ testLinearGradient
 testRadialGradient
 testGradientTransform
 testSvg
-testSvg2
 testGlShape
index c62dda2..bc541b3 100644 (file)
@@ -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> 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;
index a5409a7..943fb06 100644 (file)
@@ -14,7 +14,7 @@ source_file = [
    'tvgGlShaderSrc.cpp',
 ]
 
-glraster_dep = declare_dependency(
+glengine_dep = declare_dependency(
    include_directories : include_directories('.'),
    sources : source_file
 )
index c936501..32db5f1 100644 (file)
@@ -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',
index f96fe97..8b06258 100644 (file)
@@ -10,7 +10,7 @@ source_file = [
    'tvgSwStroke.cpp',
 ]
 
-swraster_dep = declare_dependency(
+swengine_dep = declare_dependency(
    include_directories : include_directories('.'),
    sources : source_file
 )
index 49c3f96..d147521 100644 (file)
@@ -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"
index ac6ce3a..857698d 100644 (file)
@@ -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 (file)
index 0000000..8a1c918
--- /dev/null
@@ -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<Scene> 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 (file)
index 0000000..a99838b
--- /dev/null
@@ -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<Loader> LoaderMgr::loader(const char* path)
+{
+    //TODO:
+    return unique_ptr<SvgLoader>(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 (file)
index 0000000..0d37012
--- /dev/null
@@ -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> loader(const char* path);
+};
+
+#endif //_TVG_LOADER_MGR_H_
\ No newline at end of file
index c093933..41620a0 100644 (file)
@@ -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
index 5ba8d51..5e67a66 100644 (file)
@@ -28,6 +28,7 @@ struct Scene::Impl
     vector<Paint*> paints;
     RenderTransform *transform = nullptr;
     uint32_t flag = RenderUpdateFlag::None;
+    unique_ptr<Loader> 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 (file)
index 0000000..53186dd
--- /dev/null
@@ -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 (file)
index 0000000..1bd40c1
--- /dev/null
@@ -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 (file)
index 0000000..f4b8f43
--- /dev/null
@@ -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<Scene> 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 (file)
index 0000000..2b4d8b1
--- /dev/null
@@ -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<Scene> data() override;
+};
+
+
+#endif //_TVG_SVG_LOADER_H_
\ No newline at end of file
index a0ef37d..e49c9a0 100644 (file)
@@ -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(
index aca250b..501eef5 100755 (executable)
@@ -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`
index dea96a2..e918902 100644 (file)
@@ -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 (file)
index 4714db6..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-#include <tizenvg.h>
-#include <Elementary.h>
-
-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();
-}