common loader: build up loader infrastructure.

Change-Id: I62aaed43015301ec39e414833f37d6c5485d8043
This commit is contained in:
Hermet Park 2020-06-19 14:49:07 +09:00
parent 0e25879d12
commit 01e52c7c7a
20 changed files with 279 additions and 103 deletions

1
.gitignore vendored
View file

@ -18,5 +18,4 @@ testLinearGradient
testRadialGradient
testGradientTransform
testSvg
testSvg2
testGlShape

View 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;

View file

@ -14,7 +14,7 @@ source_file = [
'tvgGlShaderSrc.cpp',
]
glraster_dep = declare_dependency(
glengine_dep = declare_dependency(
include_directories : include_directories('.'),
sources : source_file
)

View 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',

View file

@ -10,7 +10,7 @@ source_file = [
'tvgSwStroke.cpp',
]
swraster_dep = declare_dependency(
swengine_dep = declare_dependency(
include_directories : include_directories('.'),
sources : source_file
)

View 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"

View 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;
}

36
src/lib/tvgLoader.h Normal file
View file

@ -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_

52
src/lib/tvgLoaderMgr.cpp Normal file
View file

@ -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_

27
src/lib/tvgLoaderMgr.h Normal file
View file

@ -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_

View 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_ */

View 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;
}
};

1
src/loaders/meson.build Normal file
View file

@ -0,0 +1 @@
subdir('svg_loader')

View file

@ -0,0 +1,9 @@
source_file = [
'tvgSvgLoader.h',
'tvgSvgLoader.cpp',
]
svgloader_dep = declare_dependency(
include_directories : include_directories('.'),
sources : source_file
)

View file

@ -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_

View file

@ -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_

View 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(

View file

@ -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`

View 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));

View file

@ -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();
}