build: support features toggling in meson option.

Change-Id: Id1ebda70fe8380aaa913f79af26e5c39893a6df5
This commit is contained in:
Hermet Park 2020-07-08 13:08:28 +09:00
parent 84af527a27
commit 99428ee80a
33 changed files with 492 additions and 297 deletions

View file

@ -6,12 +6,24 @@ project('thorvg',
config_h = configuration_data()
if get_option('engines').contains('sw') == true
config_h.set10('THORVG_SW_RASTER_SUPPORT', true)
endif
if get_option('engines').contains('gl') == true
config_h.set10('THORVG_GL_RASTER_SUPPORT', true)
endif
if get_option('loaders').contains('svg') == true
config_h.set10('THORVG_SVG_LOADER_SUPPORT', true)
endif
configure_file(
output: 'config.h',
configuration: config_h
)
headers = [include_directories('inc')]
headers = [include_directories('inc'), include_directories('.')]
subdir('inc')
subdir('src')

11
meson_options.txt Normal file
View file

@ -0,0 +1,11 @@
option('engines',
type: 'array',
choices: ['sw', 'gl'],
value: ['sw', 'gl'],
description: 'Enable Rasterizer Engine in thorvg')
option('loaders',
type: 'array',
choices: ['svg'],
value: ['svg'],
description: 'Enable Vector File Loader in thorvg')

View file

@ -18,8 +18,8 @@ egl_dep = meson.get_compiler('cpp').find_library('EGL')
gles_dep = meson.get_compiler('cpp').find_library('GLESv2')
external_dep = [egl_dep, gles_dep]
glengine_dep = declare_dependency(
engine_dep += [declare_dependency(
dependencies : external_dep,
include_directories : include_directories('.'),
sources : source_file,
)
)]

View file

@ -1,5 +1,12 @@
engine_dep = []
if get_option('engines').contains('sw') == true
subdir('sw_engine')
endif
if get_option('engines').contains('gl') == true
subdir('gl_engine')
endif
source_file = [
'tvgCanvasImpl.h',
@ -25,8 +32,6 @@ source_file = [
'tvgSwCanvas.cpp',
]
engine_dep = [swengine_dep, glengine_dep]
common_dep = declare_dependency(
dependencies : engine_dep,
include_directories : include_directories('.'),

View file

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

View file

@ -17,6 +17,8 @@
#ifndef _TVG_COMMON_H_
#define _TVG_COMMON_H_
#include "config.h"
#include <iostream>
#include <cassert>
#include <vector>

View file

@ -18,9 +18,17 @@
#define _TVG_GLCANVAS_CPP_
#include "tvgCommon.h"
#include "tvgGlRenderer.h"
#include "tvgCanvasImpl.h"
#ifdef THORVG_GL_RASTER_SUPPORT
#include "tvgGlRenderer.h"
#else
class GlRenderer : public RenderMethod
{
//Non Supported. Dummy Class */
};
#endif
/************************************************************************/
/* Internal Class Implementation */
/************************************************************************/
@ -35,11 +43,16 @@ struct GlCanvas::Impl
/* External Class Implementation */
/************************************************************************/
#ifdef THORVG_GL_RASTER_SUPPORT
GlCanvas::GlCanvas() : Canvas(GlRenderer::inst()), pImpl(make_unique<Impl>())
#else
GlCanvas::GlCanvas() : Canvas(nullptr), pImpl(make_unique<Impl>())
#endif
{
}
GlCanvas::~GlCanvas()
{
}
@ -47,6 +60,7 @@ GlCanvas::~GlCanvas()
Result GlCanvas::target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h) noexcept
{
#ifdef THORVG_GL_RASTER_SUPPORT
//We know renderer type, avoid dynamic_cast for performance.
auto renderer = static_cast<GlRenderer*>(Canvas::pImpl.get()->renderer);
if (!renderer) return Result::MemoryCorruption;
@ -54,15 +68,20 @@ Result GlCanvas::target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t
if (!renderer->target(buffer, stride, w, h)) return Result::Unknown;
return Result::Success;
#endif
return Result::NonSupport;
}
unique_ptr<GlCanvas> GlCanvas::gen() noexcept
{
#ifdef THORVG_GL_RASTER_SUPPORT
auto canvas = unique_ptr<GlCanvas>(new GlCanvas);
assert(canvas);
return canvas;
#endif
return unique_ptr<GlCanvas>(nullptr);
}

View file

@ -18,10 +18,17 @@
#define _TVG_INITIALIZER_CPP_
#include "tvgCommon.h"
#include "tvgSwRenderer.h"
#include "tvgGlRenderer.h"
#include "tvgLoaderMgr.h"
#ifdef THORVG_SW_RASTER_SUPPORT
#include "tvgSwRenderer.h"
#endif
#ifdef THORVG_GL_RASTER_SUPPORT
#include "tvgGlRenderer.h"
#endif
/************************************************************************/
/* Internal Class Implementation */
/************************************************************************/
@ -32,14 +39,24 @@
Result Initializer::init(CanvasEngine engine) noexcept
{
auto nonSupport = true;
if (engine == CanvasEngine::Sw) {
#ifdef THORVG_SW_RASTER_SUPPORT
if (!SwRenderer::init()) return Result::InsufficientCondition;
nonSupport = false;
#endif
} else if (engine == CanvasEngine::Gl) {
#ifdef THORVG_GL_RASTER_SUPPORT
if (!GlRenderer::init()) return Result::InsufficientCondition;
nonSupport = false;
#endif
} else {
return Result::InvalidArguments;
}
if (nonSupport) return Result::NonSupport;
if (!LoaderMgr::init()) return Result::Unknown;
return Result::Success;
@ -48,16 +65,24 @@ Result Initializer::init(CanvasEngine engine) noexcept
Result Initializer::term(CanvasEngine engine) noexcept
{
//TODO: deinitialize modules
auto nonSupport = true;
if (engine == CanvasEngine::Sw) {
#ifdef THORVG_SW_RASTER_SUPPORT
if (!SwRenderer::term()) return Result::InsufficientCondition;
nonSupport = false;
#endif
} else if (engine == CanvasEngine::Gl) {
#ifdef THORVG_GL_RASTER_SUPPORT
if (!GlRenderer::term()) return Result::InsufficientCondition;
nonSupport = false;
#endif
} else {
return Result::InvalidArguments;
}
if (nonSupport) return Result::NonSupport;
if (!LoaderMgr::term()) return Result::Unknown;
return Result::Success;

View file

@ -18,8 +18,10 @@
#define _TVG_LOADER_MGR_CPP_
#include "tvgCommon.h"
#include "tvgSvgLoader.h"
#ifdef THORVG_SVG_LOADER_SUPPORT
#include "tvgSvgLoader.h"
#endif
static int initCnt = 0;
@ -45,8 +47,11 @@ bool LoaderMgr::term()
unique_ptr<Loader> LoaderMgr::loader(const char* path)
{
//TODO:
#ifdef THORVG_SVG_LOADER_SUPPORT
return unique_ptr<SvgLoader>(new SvgLoader);
#endif
cout << "Non supported format: " << path << endl;
return unique_ptr<Loader>(nullptr);
}
#endif //_TVG_LOADER_MGR_CPP_

View file

@ -51,15 +51,15 @@ class RenderMethod
{
public:
virtual ~RenderMethod() {}
virtual void* prepare(const Shape& shape, void* data, const RenderTransform* transform, RenderUpdateFlag flags) = 0;
virtual bool dispose(const Shape& shape, void *data) = 0;
virtual bool preRender() = 0;
virtual bool render(const Shape& shape, void *data) = 0;
virtual bool postRender() = 0;
virtual bool clear() = 0;
virtual bool flush() = 0;
virtual uint32_t ref() = 0;
virtual uint32_t unref() = 0;
virtual void* prepare(const Shape& shape, void* data, const RenderTransform* transform, RenderUpdateFlag flags) { return nullptr; }
virtual bool dispose(const Shape& shape, void *data) { return false; }
virtual bool preRender() { return false; }
virtual bool render(const Shape& shape, void *data) { return false; }
virtual bool postRender() { return false; }
virtual bool clear() { return false; }
virtual bool flush() { return false; }
virtual uint32_t ref() { return 0; }
virtual uint32_t unref() { return 0; }
};
struct RenderInitializer

View file

@ -18,9 +18,16 @@
#define _TVG_SWCANVAS_CPP_
#include "tvgCommon.h"
#include "tvgSwRenderer.h"
#include "tvgCanvasImpl.h"
#ifdef THORVG_SW_RASTER_SUPPORT
#include "tvgSwRenderer.h"
#else
class SwRenderer : public RenderMethod
{
//Non Supported. Dummy Class */
};
#endif
/************************************************************************/
/* Internal Class Implementation */
@ -36,7 +43,11 @@ struct SwCanvas::Impl
/* External Class Implementation */
/************************************************************************/
#ifdef THORVG_SW_RASTER_SUPPORT
SwCanvas::SwCanvas() : Canvas(SwRenderer::inst()), pImpl(make_unique<Impl>())
#else
SwCanvas::SwCanvas() : Canvas(nullptr), pImpl(make_unique<Impl>())
#endif
{
}
@ -48,6 +59,7 @@ SwCanvas::~SwCanvas()
Result SwCanvas::target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h) noexcept
{
#ifdef THORVG_SW_RASTER_SUPPORT
//We know renderer type, avoid dynamic_cast for performance.
auto renderer = static_cast<SwRenderer*>(Canvas::pImpl.get()->renderer);
if (!renderer) return Result::MemoryCorruption;
@ -55,15 +67,20 @@ Result SwCanvas::target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t
if (!renderer->target(buffer, stride, w, h)) return Result::InvalidArguments;
return Result::Success;
#endif
return Result::NonSupport;
}
unique_ptr<SwCanvas> SwCanvas::gen() noexcept
{
#ifdef THORVG_SW_RASTER_SUPPORT
auto canvas = unique_ptr<SwCanvas>(new SwCanvas);
assert(canvas);
return canvas;
#endif
return unique_ptr<SwCanvas>(nullptr);
}
#endif /* _TVG_SWCANVAS_CPP_ */

View file

@ -1,6 +1,10 @@
subloader_dep = []
if get_option('loaders').contains('svg') == true
subdir('svg_loader')
endif
loader_dep = declare_dependency(
dependencies : svgloader_dep,
dependencies: subloader_dep,
include_directories : include_directories('.'),
)

View file

@ -10,7 +10,7 @@ source_file = [
'tvgSvgSceneBuilder.cpp',
]
svgloader_dep = declare_dependency(
subloader_dep += [declare_dependency(
include_directories : include_directories('.'),
sources : source_file
)
)]

View file

@ -156,7 +156,7 @@ int main(int argc, char **argv)
}
//Initialize ThorVG Engine
tvg::Initializer::init(tvgEngine);
if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
elm_init(argc, argv);
@ -174,4 +174,9 @@ int main(int argc, char **argv)
//Terminate ThorVG Engine
tvg::Initializer::term(tvgEngine);
} else {
cout << "engine is not supported" << endl;
}
return 0;
}

View file

@ -136,7 +136,7 @@ int main(int argc, char **argv)
}
//Initialize ThorVG Engine
tvg::Initializer::init(tvgEngine);
if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
elm_init(argc, argv);
@ -151,4 +151,9 @@ int main(int argc, char **argv)
//Terminate ThorVG Engine
tvg::Initializer::term(tvgEngine);
} else {
cout << "engine is not supported" << endl;
}
return 0;
}

View file

@ -125,7 +125,7 @@ int main(int argc, char **argv)
}
//Initialize ThorVG Engine
tvg::Initializer::init(tvgEngine);
if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
elm_init(argc, argv);
@ -140,4 +140,9 @@ int main(int argc, char **argv)
//Terminate ThorVG Engine
tvg::Initializer::term(tvgEngine);
} else {
cout << "engine is not supported" << endl;
}
return 0;
}

View file

@ -179,7 +179,7 @@ int main(int argc, char **argv)
}
//Initialize ThorVG Engine
tvg::Initializer::init(tvgEngine);
if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
elm_init(argc, argv);
@ -203,4 +203,9 @@ int main(int argc, char **argv)
//Terminate ThorVG Engine
tvg::Initializer::term(tvgEngine);
} else {
cout << "engine is not supported" << endl;
}
return 0;
}

View file

@ -142,7 +142,7 @@ int main(int argc, char **argv)
}
//Initialize ThorVG Engine
tvg::Initializer::init(tvgEngine);
if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
elm_init(argc, argv);
@ -166,4 +166,9 @@ int main(int argc, char **argv)
//Terminate ThorVG Engine
tvg::Initializer::term(tvgEngine);
} else {
cout << "engine is not supported" << endl;
}
return 0;
}

View file

@ -207,7 +207,7 @@ int main(int argc, char **argv)
}
//Initialize ThorVG Engine
tvg::Initializer::init(tvgEngine);
if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
elm_init(argc, argv);
@ -231,4 +231,9 @@ int main(int argc, char **argv)
//Terminate ThorVG Engine
tvg::Initializer::term(tvgEngine);
} else {
cout << "engine is not supported" << endl;
}
return 0;
}

View file

@ -154,7 +154,7 @@ int main(int argc, char **argv)
}
//Initialize ThorVG Engine
tvg::Initializer::init(tvgEngine);
if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
elm_init(argc, argv);
@ -169,4 +169,9 @@ int main(int argc, char **argv)
//Terminate ThorVG Engine
tvg::Initializer::term(tvgEngine);
} else {
cout << "engine is not supported" << endl;
}
return 0;
}

View file

@ -114,7 +114,7 @@ int main(int argc, char **argv)
}
//Initialize ThorVG Engine
tvg::Initializer::init(tvgEngine);
if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
elm_init(argc, argv);
@ -129,4 +129,9 @@ int main(int argc, char **argv)
//Terminate ThorVG Engine
tvg::Initializer::term(tvgEngine);
} else {
cout << "engine is not supported" << endl;
}
return 0;
}

View file

@ -131,7 +131,7 @@ int main(int argc, char **argv)
}
//Initialize ThorVG Engine
tvg::Initializer::init(tvgEngine);
if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
elm_init(argc, argv);
@ -146,4 +146,9 @@ int main(int argc, char **argv)
//Terminate ThorVG Engine
tvg::Initializer::term(tvgEngine);
} else {
cout << "engine is not supported" << endl;
}
return 0;
}

View file

@ -168,7 +168,7 @@ int main(int argc, char **argv)
}
//Initialize ThorVG Engine
tvg::Initializer::init(tvgEngine);
if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
elm_init(argc, argv);
@ -183,4 +183,9 @@ int main(int argc, char **argv)
//Terminate ThorVG Engine
tvg::Initializer::term(tvgEngine);
} else {
cout << "engine is not supported" << endl;
}
return 0;
}

View file

@ -154,7 +154,7 @@ int main(int argc, char **argv)
}
//Initialize ThorVG Engine
tvg::Initializer::init(tvgEngine);
if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
elm_init(argc, argv);
@ -169,4 +169,9 @@ int main(int argc, char **argv)
//Terminate ThorVG Engine
tvg::Initializer::term(tvgEngine);
} else {
cout << "engine is not supported" << endl;
}
return 0;
}

View file

@ -161,7 +161,7 @@ int main(int argc, char **argv)
}
//Initialize ThorVG Engine
tvg::Initializer::init(tvgEngine);
if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
elm_init(argc, argv);
@ -176,4 +176,9 @@ int main(int argc, char **argv)
//Terminate ThorVG Engine
tvg::Initializer::term(tvgEngine);
} else {
cout << "engine is not supported" << endl;
}
return 0;
}

View file

@ -203,7 +203,7 @@ int main(int argc, char **argv)
}
//Initialize ThorVG Engine
tvg::Initializer::init(tvgEngine);
if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
elm_init(argc, argv);
@ -227,4 +227,9 @@ int main(int argc, char **argv)
//Terminate ThorVG Engine
tvg::Initializer::term(tvgEngine);
} else {
cout << "engine is not supported" << endl;
}
return 0;
}

View file

@ -104,7 +104,7 @@ int main(int argc, char **argv)
}
//Initialize ThorVG Engine
tvg::Initializer::init(tvgEngine);
if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
elm_init(argc, argv);
@ -119,4 +119,9 @@ int main(int argc, char **argv)
//Terminate ThorVG Engine
tvg::Initializer::term(tvgEngine);
} else {
cout << "engine is not supported" << endl;
}
return 0;
}

View file

@ -151,7 +151,7 @@ int main(int argc, char **argv)
}
//Initialize ThorVG Engine
tvg::Initializer::init(tvgEngine);
if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
elm_init(argc, argv);
@ -166,4 +166,9 @@ int main(int argc, char **argv)
//Terminate ThorVG Engine
tvg::Initializer::term(tvgEngine);
} else {
cout << "engine is not supported" << endl;
}
return 0;
}

View file

@ -188,7 +188,7 @@ int main(int argc, char **argv)
}
//Initialize ThorVG Engine
tvg::Initializer::init(tvgEngine);
if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
elm_init(argc, argv);
@ -203,4 +203,9 @@ int main(int argc, char **argv)
//Terminate ThorVG Engine
tvg::Initializer::term(tvgEngine);
} else {
cout << "engine is not supported" << endl;
}
return 0;
}

View file

@ -128,7 +128,7 @@ int main(int argc, char **argv)
}
//Initialize ThorVG Engine
tvg::Initializer::init(tvgEngine);
if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
elm_init(argc, argv);
@ -143,4 +143,9 @@ int main(int argc, char **argv)
//Terminate ThorVG Engine
tvg::Initializer::term(tvg::CanvasEngine::Sw);
} else {
cout << "engine is not supported" << endl;
}
return 0;
}

View file

@ -170,7 +170,7 @@ int main(int argc, char **argv)
}
//Initialize ThorVG Engine
tvg::Initializer::init(tvgEngine);
if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
elm_init(argc, argv);
@ -194,4 +194,9 @@ int main(int argc, char **argv)
//Terminate ThorVG Engine
tvg::Initializer::term(tvgEngine);
} else {
cout << "engine is not supported" << endl;
}
return 0;
}

View file

@ -131,7 +131,7 @@ int main(int argc, char **argv)
}
//Initialize ThorVG Engine
tvg::Initializer::init(tvgEngine);
if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
elm_init(argc, argv);
@ -155,4 +155,9 @@ int main(int argc, char **argv)
//Terminate ThorVG Engine
tvg::Initializer::term(tvgEngine);
} else {
cout << "engine is not supported" << endl;
}
return 0;
}