From 16968a8add56a6b49eb7e1406d22aa82c87d3253 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Fri, 18 Sep 2020 16:34:12 +0900 Subject: [PATCH 01/16] common: binary optimization. (#65) removed unique_ptr usages from pImpl pattern. that increased binary size. 2204082 -> 2045672 Change-Id: Idb2c25769704b246d51dce6da5bf85b240787205 --- inc/thorvg.h | 3 +- src/lib/tvgCanvas.cpp | 15 ++-- src/lib/tvgCanvasImpl.h | 8 +- src/lib/tvgCommon.h | 2 - src/lib/tvgFill.cpp | 29 +++---- src/lib/tvgGlCanvas.cpp | 8 +- src/lib/tvgLinearGradient.cpp | 24 +++--- src/lib/tvgPaint.cpp | 15 ++-- src/lib/tvgPicture.cpp | 11 +-- src/lib/tvgPictureImpl.h | 8 +- src/lib/tvgRadialGradient.cpp | 19 ++-- src/lib/tvgScene.cpp | 9 +- src/lib/tvgSceneImpl.h | 8 +- src/lib/tvgShape.cpp | 195 ++++++++++++++++++++---------------------- src/lib/tvgShapeImpl.h | 2 +- src/lib/tvgSwCanvas.cpp | 8 +- 16 files changed, 179 insertions(+), 185 deletions(-) diff --git a/inc/thorvg.h b/inc/thorvg.h index efeaab1..7d5062c 100644 --- a/inc/thorvg.h +++ b/inc/thorvg.h @@ -23,7 +23,7 @@ extern "C" { #define _TVG_DECLARE_PRIVATE(A) \ protected: \ struct Impl; \ - std::unique_ptr pImpl; \ + Impl* pImpl; \ A(const A&) = delete; \ const A& operator=(const A&) = delete; \ A() @@ -91,7 +91,6 @@ public: Result translate(float x, float y) noexcept; Result transform(const Matrix& m) noexcept; Result bounds(float* x, float* y, float* w, float* h) const noexcept; - std::unique_ptr duplicate() const noexcept; _TVG_DECLARE_ACCESSOR(); diff --git a/src/lib/tvgCanvas.cpp b/src/lib/tvgCanvas.cpp index 957940c..0720e04 100644 --- a/src/lib/tvgCanvas.cpp +++ b/src/lib/tvgCanvas.cpp @@ -26,50 +26,51 @@ /* External Class Implementation */ /************************************************************************/ -Canvas::Canvas(RenderMethod *pRenderer):pImpl(make_unique(pRenderer)) +Canvas::Canvas(RenderMethod *pRenderer):pImpl(new Impl(pRenderer)) { } Canvas::~Canvas() { + delete(pImpl); } Result Canvas::reserve(uint32_t n) noexcept { - IMPL->paints.reserve(n); + pImpl->paints.reserve(n); return Result::Success; } Result Canvas::push(unique_ptr paint) noexcept { - return IMPL->push(move(paint)); + return pImpl->push(move(paint)); } Result Canvas::clear() noexcept { - return IMPL->clear(); + return pImpl->clear(); } Result Canvas::draw() noexcept { - return IMPL->draw(); + return pImpl->draw(); } Result Canvas::update(Paint* paint) noexcept { - return IMPL->update(paint); + return pImpl->update(paint); } Result Canvas::sync() noexcept { - if (IMPL->renderer->flush()) return Result::Success; + if (pImpl->renderer->flush()) return Result::Success; return Result::InsufficientCondition; } \ No newline at end of file diff --git a/src/lib/tvgCanvasImpl.h b/src/lib/tvgCanvasImpl.h index d5b1b76..ebac74d 100644 --- a/src/lib/tvgCanvasImpl.h +++ b/src/lib/tvgCanvasImpl.h @@ -60,7 +60,7 @@ struct Canvas::Impl if (!renderer->clear()) return Result::InsufficientCondition; for (auto paint : paints) { - paint->IMPL->dispose(*renderer); + paint->pImpl->dispose(*renderer); delete(paint); } paints.clear(); @@ -74,13 +74,13 @@ struct Canvas::Impl //Update single paint node if (paint) { - if (!paint->IMPL->update(*renderer, nullptr, RenderUpdateFlag::None)) { + if (!paint->pImpl->update(*renderer, nullptr, RenderUpdateFlag::None)) { return Result::InsufficientCondition; } //Update retained all paint nodes } else { for(auto paint: paints) { - if (!paint->IMPL->update(*renderer, nullptr, RenderUpdateFlag::None)) { + if (!paint->pImpl->update(*renderer, nullptr, RenderUpdateFlag::None)) { return Result::InsufficientCondition; } } @@ -95,7 +95,7 @@ struct Canvas::Impl if (!renderer->preRender()) return Result::InsufficientCondition; for(auto paint: paints) { - if(!paint->IMPL->render(*renderer)) return Result::InsufficientCondition; + if(!paint->pImpl->render(*renderer)) return Result::InsufficientCondition; } if (!renderer->postRender()) return Result::InsufficientCondition; diff --git a/src/lib/tvgCommon.h b/src/lib/tvgCommon.h index c07a4ca..3ed4544 100644 --- a/src/lib/tvgCommon.h +++ b/src/lib/tvgCommon.h @@ -37,8 +37,6 @@ using namespace std; using namespace tvg; -#define IMPL pImpl.get() - #define FILL_ID_LINEAR 0 #define FILL_ID_RADIAL 1 diff --git a/src/lib/tvgFill.cpp b/src/lib/tvgFill.cpp index cc1a13b..4594e84 100644 --- a/src/lib/tvgFill.cpp +++ b/src/lib/tvgFill.cpp @@ -43,35 +43,34 @@ struct Fill::Impl /* External Class Implementation */ /************************************************************************/ -Fill::Fill():pImpl(make_unique()) +Fill::Fill():pImpl(new Impl()) { } Fill::~Fill() { + delete(pImpl); } Result Fill::colorStops(const ColorStop* colorStops, uint32_t cnt) noexcept { - auto impl = pImpl.get(); - if (cnt == 0) { - if (impl->colorStops) { - free(impl->colorStops); - impl->colorStops = nullptr; - impl->cnt = cnt; + if (pImpl->colorStops) { + free(pImpl->colorStops); + pImpl->colorStops = nullptr; + pImpl->cnt = cnt; } return Result::Success; } - if (impl->cnt != cnt) { - impl->colorStops = static_cast(realloc(impl->colorStops, cnt * sizeof(ColorStop))); + if (pImpl->cnt != cnt) { + pImpl->colorStops = static_cast(realloc(pImpl->colorStops, cnt * sizeof(ColorStop))); } - impl->cnt = cnt; - memcpy(impl->colorStops, colorStops, cnt * sizeof(ColorStop)); + pImpl->cnt = cnt; + memcpy(pImpl->colorStops, colorStops, cnt * sizeof(ColorStop)); return Result::Success; } @@ -79,15 +78,15 @@ Result Fill::colorStops(const ColorStop* colorStops, uint32_t cnt) noexcept uint32_t Fill::colorStops(const ColorStop** colorStops) const noexcept { - if (colorStops) *colorStops = IMPL->colorStops; + if (colorStops) *colorStops = pImpl->colorStops; - return IMPL->cnt; + return pImpl->cnt; } Result Fill::spread(FillSpread s) noexcept { - IMPL->spread = s; + pImpl->spread = s; return Result::Success; } @@ -95,5 +94,5 @@ Result Fill::spread(FillSpread s) noexcept FillSpread Fill::spread() const noexcept { - return IMPL->spread; + return pImpl->spread; } \ No newline at end of file diff --git a/src/lib/tvgGlCanvas.cpp b/src/lib/tvgGlCanvas.cpp index b425da0..85bcd1d 100644 --- a/src/lib/tvgGlCanvas.cpp +++ b/src/lib/tvgGlCanvas.cpp @@ -37,7 +37,6 @@ struct GlCanvas::Impl { - Impl() {} }; @@ -46,9 +45,9 @@ struct GlCanvas::Impl /************************************************************************/ #ifdef THORVG_GL_RASTER_SUPPORT -GlCanvas::GlCanvas() : Canvas(GlRenderer::gen()), pImpl(make_unique()) +GlCanvas::GlCanvas() : Canvas(GlRenderer::gen()), pImpl(new Impl) #else -GlCanvas::GlCanvas() : Canvas(nullptr), pImpl(make_unique()) +GlCanvas::GlCanvas() : Canvas(nullptr), pImpl(new Impl) #endif { } @@ -57,6 +56,7 @@ GlCanvas::GlCanvas() : Canvas(nullptr), pImpl(make_unique()) GlCanvas::~GlCanvas() { + delete(pImpl); } @@ -64,7 +64,7 @@ Result GlCanvas::target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t { #ifdef THORVG_GL_RASTER_SUPPORT //We know renderer type, avoid dynamic_cast for performance. - auto renderer = static_cast(Canvas::pImpl.get()->renderer); + auto renderer = static_cast(Canvas::pImpl->renderer); if (!renderer) return Result::MemoryCorruption; if (!renderer->target(buffer, stride, w, h)) return Result::Unknown; diff --git a/src/lib/tvgLinearGradient.cpp b/src/lib/tvgLinearGradient.cpp index 29837c4..1d67c17 100644 --- a/src/lib/tvgLinearGradient.cpp +++ b/src/lib/tvgLinearGradient.cpp @@ -27,14 +27,17 @@ struct LinearGradient::Impl { - float x1, y1, x2, y2; + float x1 = 0; + float y1 = 0; + float x2 = 0; + float y2 = 0; }; /************************************************************************/ /* External Class Implementation */ /************************************************************************/ -LinearGradient::LinearGradient():pImpl(make_unique()) +LinearGradient::LinearGradient():pImpl(new Impl()) { _id = FILL_ID_LINEAR; } @@ -42,6 +45,7 @@ LinearGradient::LinearGradient():pImpl(make_unique()) LinearGradient::~LinearGradient() { + delete(pImpl); } @@ -50,10 +54,10 @@ Result LinearGradient::linear(float x1, float y1, float x2, float y2) noexcept if (fabsf(x2 - x1) < FLT_EPSILON && fabsf(y2 - y1) < FLT_EPSILON) return Result::InvalidArguments; - IMPL->x1 = x1; - IMPL->y1 = y1; - IMPL->x2 = x2; - IMPL->y2 = y2; + pImpl->x1 = x1; + pImpl->y1 = y1; + pImpl->x2 = x2; + pImpl->y2 = y2; return Result::Success; } @@ -61,10 +65,10 @@ Result LinearGradient::linear(float x1, float y1, float x2, float y2) noexcept Result LinearGradient::linear(float* x1, float* y1, float* x2, float* y2) const noexcept { - if (x1) *x1 = IMPL->x1; - if (x2) *x2 = IMPL->x2; - if (y1) *y1 = IMPL->y1; - if (y2) *y2 = IMPL->y2; + if (x1) *x1 = pImpl->x1; + if (x2) *x2 = pImpl->x2; + if (y1) *y1 = pImpl->y1; + if (y2) *y2 = pImpl->y2; return Result::Success; } diff --git a/src/lib/tvgPaint.cpp b/src/lib/tvgPaint.cpp index 43edcc7..55e0d75 100644 --- a/src/lib/tvgPaint.cpp +++ b/src/lib/tvgPaint.cpp @@ -25,13 +25,14 @@ /* Internal Class Implementation */ /************************************************************************/ -Paint :: Paint() : pImpl(make_unique()) +Paint :: Paint() : pImpl(new Impl()) { } Paint :: ~Paint() { + delete(pImpl); } @@ -41,39 +42,39 @@ Paint :: ~Paint() Result Paint::rotate(float degree) noexcept { - if (IMPL->rotate(degree)) return Result::Success; + if (pImpl->rotate(degree)) return Result::Success; return Result::FailedAllocation; } Result Paint::scale(float factor) noexcept { - if (IMPL->scale(factor)) return Result::Success; + if (pImpl->scale(factor)) return Result::Success; return Result::FailedAllocation; } Result Paint::translate(float x, float y) noexcept { - if (IMPL->translate(x, y)) return Result::Success; + if (pImpl->translate(x, y)) return Result::Success; return Result::FailedAllocation; } Result Paint::transform(const Matrix& m) noexcept { - if (IMPL->transform(m)) return Result::Success; + if (pImpl->transform(m)) return Result::Success; return Result::FailedAllocation; } Result Paint::bounds(float* x, float* y, float* w, float* h) const noexcept { - if (IMPL->bounds(x, y, w, h)) return Result::Success; + if (pImpl->bounds(x, y, w, h)) return Result::Success; return Result::InsufficientCondition; } unique_ptr Paint::duplicate() const noexcept { - return IMPL->duplicate(); + return pImpl->duplicate(); } \ No newline at end of file diff --git a/src/lib/tvgPicture.cpp b/src/lib/tvgPicture.cpp index 7c20a37..a4ac3ee 100644 --- a/src/lib/tvgPicture.cpp +++ b/src/lib/tvgPicture.cpp @@ -25,14 +25,15 @@ /* External Class Implementation */ /************************************************************************/ -Picture::Picture() : pImpl(make_unique()) +Picture::Picture() : pImpl(new Impl()) { - Paint::IMPL->method(new PaintMethod(IMPL)); + Paint::pImpl->method(new PaintMethod(pImpl)); } Picture::~Picture() { + delete(pImpl); } @@ -46,7 +47,7 @@ Result Picture::load(const std::string& path) noexcept { if (path.empty()) return Result::InvalidArguments; - return IMPL->load(path); + return pImpl->load(path); } @@ -54,12 +55,12 @@ Result Picture::load(const char* data, uint32_t size) noexcept { if (!data || size <= 0) return Result::InvalidArguments; - return IMPL->load(data, size); + return pImpl->load(data, size); } Result Picture::viewbox(float* x, float* y, float* w, float* h) const noexcept { - if (IMPL->viewbox(x, y, w, h)) return Result::Success; + if (pImpl->viewbox(x, y, w, h)) return Result::Success; return Result::InsufficientCondition; } \ No newline at end of file diff --git a/src/lib/tvgPictureImpl.h b/src/lib/tvgPictureImpl.h index e98c6b7..e96384d 100644 --- a/src/lib/tvgPictureImpl.h +++ b/src/lib/tvgPictureImpl.h @@ -37,7 +37,7 @@ struct Picture::Impl { if (!paint) return false; - paint->IMPL->dispose(renderer); + paint->pImpl->dispose(renderer); delete(paint); return true; @@ -56,13 +56,13 @@ struct Picture::Impl if (!paint) return false; - return paint->IMPL->update(renderer, transform, flag); + return paint->pImpl->update(renderer, transform, flag); } bool render(RenderMethod &renderer) { if (!paint) return false; - return paint->IMPL->render(renderer); + return paint->pImpl->render(renderer); } bool viewbox(float* x, float* y, float* w, float* h) @@ -78,7 +78,7 @@ struct Picture::Impl bool bounds(float* x, float* y, float* w, float* h) { if (!paint) return false; - return paint->IMPL->bounds(x, y, w, h); + return paint->pImpl->bounds(x, y, w, h); } Result load(const string& path) diff --git a/src/lib/tvgRadialGradient.cpp b/src/lib/tvgRadialGradient.cpp index 92e934e..d91ebba 100644 --- a/src/lib/tvgRadialGradient.cpp +++ b/src/lib/tvgRadialGradient.cpp @@ -27,7 +27,9 @@ struct RadialGradient::Impl { - float cx, cy, radius; + float cx = 0; + float cy = 0; + float radius = 0; }; @@ -35,7 +37,7 @@ struct RadialGradient::Impl /* External Class Implementation */ /************************************************************************/ -RadialGradient::RadialGradient():pImpl(make_unique()) +RadialGradient::RadialGradient():pImpl(new Impl()) { _id = FILL_ID_RADIAL; } @@ -43,6 +45,7 @@ RadialGradient::RadialGradient():pImpl(make_unique()) RadialGradient::~RadialGradient() { + delete(pImpl); } @@ -50,9 +53,9 @@ Result RadialGradient::radial(float cx, float cy, float radius) noexcept { if (radius < FLT_EPSILON) return Result::InvalidArguments; - IMPL->cx = cx; - IMPL->cy = cy; - IMPL->radius = radius; + pImpl->cx = cx; + pImpl->cy = cy; + pImpl->radius = radius; return Result::Success; } @@ -60,9 +63,9 @@ Result RadialGradient::radial(float cx, float cy, float radius) noexcept Result RadialGradient::radial(float* cx, float* cy, float* radius) const noexcept { - if (cx) *cx = IMPL->cx; - if (cy) *cy = IMPL->cy; - if (radius) *radius = IMPL->radius; + if (cx) *cx = pImpl->cx; + if (cy) *cy = pImpl->cy; + if (radius) *radius = pImpl->radius; return Result::Success; } diff --git a/src/lib/tvgScene.cpp b/src/lib/tvgScene.cpp index df7362f..cf982a5 100644 --- a/src/lib/tvgScene.cpp +++ b/src/lib/tvgScene.cpp @@ -25,14 +25,15 @@ /* External Class Implementation */ /************************************************************************/ -Scene::Scene() : pImpl(make_unique()) +Scene::Scene() : pImpl(new Impl()) { - Paint::IMPL->method(new PaintMethod(IMPL)); + Paint::pImpl->method(new PaintMethod(pImpl)); } Scene::~Scene() { + delete(pImpl); } @@ -46,7 +47,7 @@ Result Scene::push(unique_ptr paint) noexcept { auto p = paint.release(); if (!p) return Result::MemoryCorruption; - IMPL->paints.push_back(p); + pImpl->paints.push_back(p); return Result::Success; } @@ -54,7 +55,7 @@ Result Scene::push(unique_ptr paint) noexcept Result Scene::reserve(uint32_t size) noexcept { - IMPL->paints.reserve(size); + pImpl->paints.reserve(size); return Result::Success; } \ No newline at end of file diff --git a/src/lib/tvgSceneImpl.h b/src/lib/tvgSceneImpl.h index 4d30592..b1b2898 100644 --- a/src/lib/tvgSceneImpl.h +++ b/src/lib/tvgSceneImpl.h @@ -35,7 +35,7 @@ struct Scene::Impl bool dispose(RenderMethod& renderer) { for (auto paint : paints) { - paint->IMPL->dispose(renderer); + paint->pImpl->dispose(renderer); delete(paint); } paints.clear(); @@ -46,7 +46,7 @@ struct Scene::Impl bool update(RenderMethod &renderer, const RenderTransform* transform, RenderUpdateFlag flag) { for(auto paint: paints) { - if (!paint->IMPL->update(renderer, transform, static_cast(flag))) return false; + if (!paint->pImpl->update(renderer, transform, static_cast(flag))) return false; } return true; } @@ -54,7 +54,7 @@ struct Scene::Impl bool render(RenderMethod &renderer) { for(auto paint: paints) { - if(!paint->IMPL->render(renderer)) return false; + if(!paint->pImpl->render(renderer)) return false; } return true; } @@ -72,7 +72,7 @@ struct Scene::Impl auto w2 = 0.0f; auto h2 = 0.0f; - if (paint->IMPL->bounds(&x2, &y2, &w2, &h2)) return false; + if (paint->pImpl->bounds(&x2, &y2, &w2, &h2)) return false; //Merge regions if (x2 < x) x = x2; diff --git a/src/lib/tvgShape.cpp b/src/lib/tvgShape.cpp index 92da1d5..a68c085 100644 --- a/src/lib/tvgShape.cpp +++ b/src/lib/tvgShape.cpp @@ -32,14 +32,15 @@ constexpr auto PATH_KAPPA = 0.552284f; /* External Class Implementation */ /************************************************************************/ -Shape :: Shape() : pImpl(make_unique(this)) +Shape :: Shape() : pImpl(new Impl(this)) { - Paint::IMPL->method(new PaintMethod(IMPL)); + Paint::pImpl->method(new PaintMethod(pImpl)); } Shape :: ~Shape() { + delete(pImpl); } @@ -51,9 +52,9 @@ unique_ptr Shape::gen() noexcept Result Shape::reset() noexcept { - IMPL->path->reset(); + pImpl->path->reset(); - IMPL->flag |= RenderUpdateFlag::Path; + pImpl->flag |= RenderUpdateFlag::Path; return Result::Success; } @@ -63,9 +64,9 @@ uint32_t Shape::pathCommands(const PathCommand** cmds) const noexcept { if (!cmds) return 0; - *cmds = IMPL->path->cmds; + *cmds = pImpl->path->cmds; - return IMPL->path->cmdCnt; + return pImpl->path->cmdCnt; } @@ -73,9 +74,9 @@ uint32_t Shape::pathCoords(const Point** pts) const noexcept { if (!pts) return 0; - *pts = IMPL->path->pts; + *pts = pImpl->path->pts; - return IMPL->path->ptsCnt; + return pImpl->path->ptsCnt; } @@ -83,10 +84,10 @@ Result Shape::appendPath(const PathCommand *cmds, uint32_t cmdCnt, const Point* { if (cmdCnt == 0 || ptsCnt == 0 || !pts || !ptsCnt) return Result::InvalidArguments; - IMPL->path->grow(cmdCnt, ptsCnt); - IMPL->path->append(cmds, cmdCnt, pts, ptsCnt); + pImpl->path->grow(cmdCnt, ptsCnt); + pImpl->path->append(cmds, cmdCnt, pts, ptsCnt); - IMPL->flag |= RenderUpdateFlag::Path; + pImpl->flag |= RenderUpdateFlag::Path; return Result::Success; } @@ -94,9 +95,9 @@ Result Shape::appendPath(const PathCommand *cmds, uint32_t cmdCnt, const Point* Result Shape::moveTo(float x, float y) noexcept { - IMPL->path->moveTo(x, y); + pImpl->path->moveTo(x, y); - IMPL->flag |= RenderUpdateFlag::Path; + pImpl->flag |= RenderUpdateFlag::Path; return Result::Success; } @@ -104,9 +105,9 @@ Result Shape::moveTo(float x, float y) noexcept Result Shape::lineTo(float x, float y) noexcept { - IMPL->path->lineTo(x, y); + pImpl->path->lineTo(x, y); - IMPL->flag |= RenderUpdateFlag::Path; + pImpl->flag |= RenderUpdateFlag::Path; return Result::Success; } @@ -114,9 +115,9 @@ Result Shape::lineTo(float x, float y) noexcept Result Shape::cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) noexcept { - IMPL->path->cubicTo(cx1, cy1, cx2, cy2, x, y); + pImpl->path->cubicTo(cx1, cy1, cx2, cy2, x, y); - IMPL->flag |= RenderUpdateFlag::Path; + pImpl->flag |= RenderUpdateFlag::Path; return Result::Success; } @@ -124,9 +125,9 @@ Result Shape::cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float Result Shape::close() noexcept { - IMPL->path->close(); + pImpl->path->close(); - IMPL->flag |= RenderUpdateFlag::Path; + pImpl->flag |= RenderUpdateFlag::Path; return Result::Success; } @@ -134,20 +135,18 @@ Result Shape::close() noexcept Result Shape::appendCircle(float cx, float cy, float rx, float ry) noexcept { - auto impl = pImpl.get(); - auto rxKappa = rx * PATH_KAPPA; auto ryKappa = ry * PATH_KAPPA; - impl->path->grow(6, 13); - impl->path->moveTo(cx, cy - ry); - impl->path->cubicTo(cx + rxKappa, cy - ry, cx + rx, cy - ryKappa, cx + rx, cy); - impl->path->cubicTo(cx + rx, cy + ryKappa, cx + rxKappa, cy + ry, cx, cy + ry); - impl->path->cubicTo(cx - rxKappa, cy + ry, cx - rx, cy + ryKappa, cx - rx, cy); - impl->path->cubicTo(cx - rx, cy - ryKappa, cx - rxKappa, cy - ry, cx, cy - ry); - impl->path->close(); + pImpl->path->grow(6, 13); + pImpl->path->moveTo(cx, cy - ry); + pImpl->path->cubicTo(cx + rxKappa, cy - ry, cx + rx, cy - ryKappa, cx + rx, cy); + pImpl->path->cubicTo(cx + rx, cy + ryKappa, cx + rxKappa, cy + ry, cx, cy + ry); + pImpl->path->cubicTo(cx - rxKappa, cy + ry, cx - rx, cy + ryKappa, cx - rx, cy); + pImpl->path->cubicTo(cx - rx, cy - ryKappa, cx - rxKappa, cy - ry, cx, cy - ry); + pImpl->path->close(); - impl->flag |= RenderUpdateFlag::Path; + pImpl->flag |= RenderUpdateFlag::Path; return Result::Success; } @@ -159,8 +158,6 @@ Result Shape::appendArc(float cx, float cy, float radius, float startAngle, floa //just circle if (sweep >= 360) return appendCircle(cx, cy, radius, radius); - auto impl = pImpl.get(); - startAngle = (startAngle * M_PI) / 180; sweep = sweep * M_PI / 180; @@ -172,10 +169,10 @@ Result Shape::appendArc(float cx, float cy, float radius, float startAngle, floa Point start = {radius * cos(startAngle), radius * sin(startAngle)}; if (pie) { - impl->path->moveTo(cx, cy); - impl->path->lineTo(start.x + cx, start.y + cy); + pImpl->path->moveTo(cx, cy); + pImpl->path->lineTo(start.x + cx, start.y + cy); }else { - impl->path->moveTo(start.x + cx, start.y + cy); + pImpl->path->moveTo(start.x + cx, start.y + cy); } for (int i = 0; i < nCurves; ++i) { @@ -203,17 +200,17 @@ Result Shape::appendArc(float cx, float cy, float radius, float startAngle, floa Point ctrl1 = {ax - k2 * ay + cx, ay + k2 * ax + cy}; Point ctrl2 = {bx + k2 * by + cx, by - k2 * bx + cy}; - impl->path->cubicTo(ctrl1.x, ctrl1.y, ctrl2.x, ctrl2.y, end.x, end.y); + pImpl->path->cubicTo(ctrl1.x, ctrl1.y, ctrl2.x, ctrl2.y, end.x, end.y); startAngle = endAngle; } if (pie) { - impl->path->moveTo(cx, cy); - impl->path->close(); + pImpl->path->moveTo(cx, cy); + pImpl->path->close(); } - IMPL->flag |= RenderUpdateFlag::Path; + pImpl->flag |= RenderUpdateFlag::Path; return Result::Success; } @@ -221,8 +218,6 @@ Result Shape::appendArc(float cx, float cy, float radius, float startAngle, floa Result Shape::appendRect(float x, float y, float w, float h, float rx, float ry) noexcept { - auto impl = pImpl.get(); - auto halfW = w * 0.5f; auto halfH = h * 0.5f; @@ -232,32 +227,32 @@ Result Shape::appendRect(float x, float y, float w, float h, float rx, float ry) //rectangle if (rx == 0 && ry == 0) { - impl->path->grow(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(); + pImpl->path->grow(5, 4); + pImpl->path->moveTo(x, y); + pImpl->path->lineTo(x + w, y); + pImpl->path->lineTo(x + w, y + h); + pImpl->path->lineTo(x, y + h); + pImpl->path->close(); //circle } else if (fabsf(rx - halfW) < FLT_EPSILON && fabsf(ry - halfH) < FLT_EPSILON) { return appendCircle(x + (w * 0.5f), y + (h * 0.5f), rx, ry); } else { auto hrx = rx * 0.5f; auto hry = ry * 0.5f; - impl->path->grow(10, 17); - impl->path->moveTo(x + rx, y); - impl->path->lineTo(x + w - rx, y); - impl->path->cubicTo(x + w - rx + hrx, y, x + w, y + ry - hry, x + w, y + ry); - impl->path->lineTo(x + w, y + h - ry); - impl->path->cubicTo(x + w, y + h - ry + hry, x + w - rx + hrx, y + h, x + w - rx, y + h); - impl->path->lineTo(x + rx, y + h); - impl->path->cubicTo(x + rx - hrx, y + h, x, y + h - ry + hry, x, y + h - ry); - impl->path->lineTo(x, y + ry); - impl->path->cubicTo(x, y + ry - hry, x + rx - hrx, y, x + rx, y); - impl->path->close(); + pImpl->path->grow(10, 17); + pImpl->path->moveTo(x + rx, y); + pImpl->path->lineTo(x + w - rx, y); + pImpl->path->cubicTo(x + w - rx + hrx, y, x + w, y + ry - hry, x + w, y + ry); + pImpl->path->lineTo(x + w, y + h - ry); + pImpl->path->cubicTo(x + w, y + h - ry + hry, x + w - rx + hrx, y + h, x + w - rx, y + h); + pImpl->path->lineTo(x + rx, y + h); + pImpl->path->cubicTo(x + rx - hrx, y + h, x, y + h - ry + hry, x, y + h - ry); + pImpl->path->lineTo(x, y + ry); + pImpl->path->cubicTo(x, y + ry - hry, x + rx - hrx, y, x + rx, y); + pImpl->path->close(); } - impl->flag |= RenderUpdateFlag::Path; + pImpl->flag |= RenderUpdateFlag::Path; return Result::Success; } @@ -265,18 +260,16 @@ Result Shape::appendRect(float x, float y, float w, float h, float rx, float ry) Result Shape::fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept { - auto impl = pImpl.get(); - - impl->color[0] = r; - impl->color[1] = g; - impl->color[2] = b; - impl->color[3] = a; - impl->flag |= RenderUpdateFlag::Color; - - if (impl->fill) { - delete(impl->fill); - impl->fill = nullptr; - impl->flag |= RenderUpdateFlag::Gradient; + pImpl->color[0] = r; + pImpl->color[1] = g; + pImpl->color[2] = b; + pImpl->color[3] = a; + pImpl->flag |= RenderUpdateFlag::Color; + + if (pImpl->fill) { + delete(pImpl->fill); + pImpl->fill = nullptr; + pImpl->flag |= RenderUpdateFlag::Gradient; } return Result::Success; @@ -285,14 +278,12 @@ Result Shape::fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept Result Shape::fill(unique_ptr f) noexcept { - auto impl = pImpl.get(); - auto p = f.release(); if (!p) return Result::MemoryCorruption; - if (impl->fill && impl->fill != p) delete(impl->fill); - impl->fill = p; - impl->flag |= RenderUpdateFlag::Gradient; + if (pImpl->fill && pImpl->fill != p) delete(pImpl->fill); + pImpl->fill = p; + pImpl->flag |= RenderUpdateFlag::Gradient; return Result::Success; } @@ -300,25 +291,23 @@ Result Shape::fill(unique_ptr f) noexcept Result Shape::fill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept { - auto impl = pImpl.get(); - - if (r) *r = impl->color[0]; - if (g) *g = impl->color[1]; - if (b) *b = impl->color[2]; - if (a) *a = impl->color[3]; + if (r) *r = pImpl->color[0]; + if (g) *g = pImpl->color[1]; + if (b) *b = pImpl->color[2]; + if (a) *a = pImpl->color[3]; return Result::Success; } const Fill* Shape::fill() const noexcept { - return IMPL->fill; + return pImpl->fill; } Result Shape::stroke(float width) noexcept { - if (!IMPL->strokeWidth(width)) return Result::FailedAllocation; + if (!pImpl->strokeWidth(width)) return Result::FailedAllocation; return Result::Success; } @@ -326,14 +315,14 @@ Result Shape::stroke(float width) noexcept float Shape::strokeWidth() const noexcept { - if (!IMPL->stroke) return 0; - return IMPL->stroke->width; + if (!pImpl->stroke) return 0; + return pImpl->stroke->width; } Result Shape::stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept { - if (!IMPL->strokeColor(r, g, b, a)) return Result::FailedAllocation; + if (!pImpl->strokeColor(r, g, b, a)) return Result::FailedAllocation; return Result::Success; } @@ -341,14 +330,12 @@ Result Shape::stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept Result Shape::strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept { - auto impl = pImpl.get(); - - if (!impl->stroke) return Result::InsufficientCondition; + if (!pImpl->stroke) return Result::InsufficientCondition; - if (r) *r = impl->stroke->color[0]; - if (g) *g = impl->stroke->color[1]; - if (b) *b = impl->stroke->color[2]; - if (a) *a = impl->stroke->color[3]; + if (r) *r = pImpl->stroke->color[0]; + if (g) *g = pImpl->stroke->color[1]; + if (b) *b = pImpl->stroke->color[2]; + if (a) *a = pImpl->stroke->color[3]; return Result::Success; } @@ -358,7 +345,7 @@ Result Shape::stroke(const float* dashPattern, uint32_t cnt) noexcept { if (cnt < 2 || !dashPattern) return Result::InvalidArguments; - if (!IMPL->strokeDash(dashPattern, cnt)) return Result::FailedAllocation; + if (!pImpl->strokeDash(dashPattern, cnt)) return Result::FailedAllocation; return Result::Success; } @@ -366,16 +353,16 @@ Result Shape::stroke(const float* dashPattern, uint32_t cnt) noexcept uint32_t Shape::strokeDash(const float** dashPattern) const noexcept { - if (!IMPL->stroke) return 0; + if (!pImpl->stroke) return 0; - if (dashPattern) *dashPattern = IMPL->stroke->dashPattern; - return IMPL->stroke->dashCnt; + if (dashPattern) *dashPattern = pImpl->stroke->dashPattern; + return pImpl->stroke->dashCnt; } Result Shape::stroke(StrokeCap cap) noexcept { - if (!IMPL->strokeCap(cap)) return Result::FailedAllocation; + if (!pImpl->strokeCap(cap)) return Result::FailedAllocation; return Result::Success; } @@ -383,7 +370,7 @@ Result Shape::stroke(StrokeCap cap) noexcept Result Shape::stroke(StrokeJoin join) noexcept { - if (!IMPL->strokeJoin(join)) return Result::FailedAllocation; + if (!pImpl->strokeJoin(join)) return Result::FailedAllocation; return Result::Success; } @@ -391,15 +378,15 @@ Result Shape::stroke(StrokeJoin join) noexcept StrokeCap Shape::strokeCap() const noexcept { - if (!IMPL->stroke) return StrokeCap::Square; + if (!pImpl->stroke) return StrokeCap::Square; - return IMPL->stroke->cap; + return pImpl->stroke->cap; } StrokeJoin Shape::strokeJoin() const noexcept { - if (!IMPL->stroke) return StrokeJoin::Bevel; + if (!pImpl->stroke) return StrokeJoin::Bevel; - return IMPL->stroke->join; -} + return pImpl->stroke->join; +} \ No newline at end of file diff --git a/src/lib/tvgShapeImpl.h b/src/lib/tvgShapeImpl.h index 2281573..d9481a2 100644 --- a/src/lib/tvgShapeImpl.h +++ b/src/lib/tvgShapeImpl.h @@ -181,7 +181,7 @@ struct Shape::Impl auto ret = Shape::gen(); if (!ret) return nullptr; - auto dup = ret.get()->pImpl.get(); + auto dup = ret.get()->pImpl; //Color memcpy(dup->color, color, sizeof(color)); diff --git a/src/lib/tvgSwCanvas.cpp b/src/lib/tvgSwCanvas.cpp index 5e6af44..1a2261a 100644 --- a/src/lib/tvgSwCanvas.cpp +++ b/src/lib/tvgSwCanvas.cpp @@ -37,7 +37,6 @@ struct SwCanvas::Impl { - Impl() {} }; @@ -46,9 +45,9 @@ struct SwCanvas::Impl /************************************************************************/ #ifdef THORVG_SW_RASTER_SUPPORT -SwCanvas::SwCanvas() : Canvas(SwRenderer::gen()), pImpl(make_unique()) +SwCanvas::SwCanvas() : Canvas(SwRenderer::gen()), pImpl(new Impl) #else -SwCanvas::SwCanvas() : Canvas(nullptr), pImpl(make_unique()) +SwCanvas::SwCanvas() : Canvas(nullptr), pImpl(new Impl) #endif { } @@ -56,6 +55,7 @@ SwCanvas::SwCanvas() : Canvas(nullptr), pImpl(make_unique()) SwCanvas::~SwCanvas() { + delete(pImpl); } @@ -63,7 +63,7 @@ Result SwCanvas::target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t { #ifdef THORVG_SW_RASTER_SUPPORT //We know renderer type, avoid dynamic_cast for performance. - auto renderer = static_cast(Canvas::pImpl.get()->renderer); + auto renderer = static_cast(Canvas::pImpl->renderer); if (!renderer) return Result::MemoryCorruption; if (!renderer->target(buffer, stride, w, h, cs)) return Result::InvalidArguments; -- 2.7.4 From 6235592afa3351ad8a0b9c48330eec547e47db98 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Fri, 18 Sep 2020 23:36:33 +0900 Subject: [PATCH 02/16] bindings/capi: fix c compatibility warnings. Change-Id: Idcd5736851950459ea7ad4af96662ea64013be75 warning: empty struct has size 0 in C, size 1 in C++ [-Wextern-c-compat] --- src/bindings/capi/tvgCapi.cpp | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/bindings/capi/tvgCapi.cpp b/src/bindings/capi/tvgCapi.cpp index 7e3ab47..03ee907 100644 --- a/src/bindings/capi/tvgCapi.cpp +++ b/src/bindings/capi/tvgCapi.cpp @@ -32,21 +32,6 @@ using namespace tvg; extern "C" { #endif -struct _Tvg_Canvas -{ - //Dummy for Direct Casting -}; - -struct _Tvg_Paint -{ - //Dummy for Direct Casting -}; - -struct _Tvg_Gradient -{ - //Dummy for Direct Casting -}; - /************************************************************************/ /* Engine API */ @@ -144,7 +129,7 @@ TVG_EXPORT Tvg_Result tvg_canvas_sync(Tvg_Canvas* canvas) TVG_EXPORT Tvg_Result tvg_paint_del(Tvg_Paint* paint) { if (!paint) return TVG_RESULT_INVALID_ARGUMENT; - delete(paint); + delete(reinterpret_cast(paint)); return TVG_RESULT_SUCCESS; } @@ -422,7 +407,7 @@ TVG_EXPORT Tvg_Gradient* tvg_radial_gradient_new() TVG_EXPORT Tvg_Result tvg_gradient_del(Tvg_Gradient* grad) { if (!grad) return TVG_RESULT_INVALID_ARGUMENT; - delete(grad); + delete(reinterpret_cast(grad)); return TVG_RESULT_SUCCESS; } -- 2.7.4 From a000a1441da3d01a32c6c06663452963b45175b4 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Sat, 19 Sep 2020 00:34:46 +0900 Subject: [PATCH 03/16] examples: move tests to src/examples tests is now officially placed in src/examples, default is turned off, only necessaries turn it on. ex) meson . build -Dexamples=true + this examples are required efl 'elementary' package. Change-Id: I60be4a45d520eab138e25212fbc4de3691bf1127 --- meson.build | 2 ++ meson_options.txt | 7 ++++- src/bin/meson.build | 1 + src/examples/main.cpp | 11 ------- src/examples/meson.build | 37 +++++++++++++++++++++++- {test => src/examples}/svgs/batman1.svg | 0 {test => src/examples}/svgs/bojo.svg | 0 {test => src/examples}/svgs/bzrfeed.svg | 0 {test => src/examples}/svgs/cartman.svg | 0 {test => src/examples}/svgs/dst.svg | 0 {test => src/examples}/svgs/duke.svg | 0 {test => src/examples}/svgs/eee.svg | 0 {test => src/examples}/svgs/favorite_on.svg | 0 {test => src/examples}/svgs/google.svg | 0 {test => src/examples}/svgs/ibm.svg | 0 {test => src/examples}/svgs/lineargrad1.svg | 0 {test => src/examples}/svgs/radialgrad1.svg | 0 {test => src/examples}/svgs/scion.svg | 0 {test => src/examples}/svgs/tiger.svg | 0 {test => src/examples}/svgs/yadis.svg | 0 {test => src/examples}/svgs/yinyang.svg | 0 {test => src/examples}/testArc.cpp | 0 {test => src/examples}/testAsync.cpp | 0 {test => src/examples}/testBlending.cpp | 0 {test => src/examples}/testBoundary.cpp | 0 test/testCapi.c => src/examples/testCapi.cpp | 4 +-- {test => src/examples}/testCommon.h | 0 {test => src/examples}/testCustomTransform.cpp | 0 {test => src/examples}/testDirectUpdate.cpp | 0 {test => src/examples}/testDuplicate.cpp | 0 {test => src/examples}/testGradientTransform.cpp | 0 {test => src/examples}/testLinearGradient.cpp | 0 {test => src/examples}/testMultiCanvas.cpp | 6 ++-- {test => src/examples}/testMultiShapes.cpp | 0 {test => src/examples}/testPath.cpp | 0 {test => src/examples}/testPathCopy.cpp | 0 {test => src/examples}/testRadialGradient.cpp | 0 {test => src/examples}/testScene.cpp | 0 {test => src/examples}/testSceneTransform.cpp | 0 {test => src/examples}/testShape.cpp | 0 {test => src/examples}/testStroke.cpp | 0 {test => src/examples}/testStrokeLine.cpp | 0 {test => src/examples}/testSvg.cpp | 6 ++-- {test => src/examples}/testSvg2.cpp | 0 {test => src/examples}/testTransform.cpp | 0 {test => src/examples}/testUpdate.cpp | 0 src/meson.build | 9 ++++-- test/makefile | 25 ---------------- 48 files changed, 59 insertions(+), 49 deletions(-) delete mode 100644 src/examples/main.cpp rename {test => src/examples}/svgs/batman1.svg (100%) rename {test => src/examples}/svgs/bojo.svg (100%) rename {test => src/examples}/svgs/bzrfeed.svg (100%) rename {test => src/examples}/svgs/cartman.svg (100%) rename {test => src/examples}/svgs/dst.svg (100%) rename {test => src/examples}/svgs/duke.svg (100%) rename {test => src/examples}/svgs/eee.svg (100%) rename {test => src/examples}/svgs/favorite_on.svg (100%) rename {test => src/examples}/svgs/google.svg (100%) rename {test => src/examples}/svgs/ibm.svg (100%) rename {test => src/examples}/svgs/lineargrad1.svg (100%) rename {test => src/examples}/svgs/radialgrad1.svg (100%) rename {test => src/examples}/svgs/scion.svg (100%) rename {test => src/examples}/svgs/tiger.svg (100%) rename {test => src/examples}/svgs/yadis.svg (100%) rename {test => src/examples}/svgs/yinyang.svg (100%) rename {test => src/examples}/testArc.cpp (100%) rename {test => src/examples}/testAsync.cpp (100%) rename {test => src/examples}/testBlending.cpp (100%) rename {test => src/examples}/testBoundary.cpp (100%) rename test/testCapi.c => src/examples/testCapi.cpp (95%) rename {test => src/examples}/testCommon.h (100%) rename {test => src/examples}/testCustomTransform.cpp (100%) rename {test => src/examples}/testDirectUpdate.cpp (100%) rename {test => src/examples}/testDuplicate.cpp (100%) rename {test => src/examples}/testGradientTransform.cpp (100%) rename {test => src/examples}/testLinearGradient.cpp (100%) rename {test => src/examples}/testMultiCanvas.cpp (97%) rename {test => src/examples}/testMultiShapes.cpp (100%) rename {test => src/examples}/testPath.cpp (100%) rename {test => src/examples}/testPathCopy.cpp (100%) rename {test => src/examples}/testRadialGradient.cpp (100%) rename {test => src/examples}/testScene.cpp (100%) rename {test => src/examples}/testSceneTransform.cpp (100%) rename {test => src/examples}/testShape.cpp (100%) rename {test => src/examples}/testStroke.cpp (100%) rename {test => src/examples}/testStrokeLine.cpp (100%) rename {test => src/examples}/testSvg.cpp (96%) rename {test => src/examples}/testSvg2.cpp (100%) rename {test => src/examples}/testTransform.cpp (100%) rename {test => src/examples}/testUpdate.cpp (100%) delete mode 100644 test/makefile diff --git a/meson.build b/meson.build index 981e753..8cff0aa 100644 --- a/meson.build +++ b/meson.build @@ -6,6 +6,8 @@ project('thorvg', config_h = configuration_data() +add_project_arguments('-DEXAMPLE_DIR="@0@/src/examples/svgs"'.format(meson.current_source_dir()), language : 'cpp') + if get_option('engines').contains('sw') == true config_h.set10('THORVG_SW_RASTER_SUPPORT', true) endif diff --git a/meson_options.txt b/meson_options.txt index 14a31ed..d784bb2 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -26,4 +26,9 @@ option('tools', type: 'array', choices: ['', 'svg2png'], value: [''], - description: 'Enable building ThorVG Tools') + description: 'Enable building thorvg tools') + +option('examples', + type: 'boolean', + value: false, + description: 'Enable building examples') diff --git a/src/bin/meson.build b/src/bin/meson.build index fa68f84..9ee39e9 100644 --- a/src/bin/meson.build +++ b/src/bin/meson.build @@ -1,4 +1,5 @@ if get_option('tools').contains('svg2png') == true + message('Enable Tools: svg2png') subdir('svg2png') endif diff --git a/src/examples/main.cpp b/src/examples/main.cpp deleted file mode 100644 index 8bd265a..0000000 --- a/src/examples/main.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include - -using namespace std; - -int -main(int argc, char *argv[]) -{ - cout << "test thorvg!" << endl; - - return 0; -} diff --git a/src/examples/meson.build b/src/examples/meson.build index 4ba6e9b..4c40890 100644 --- a/src/examples/meson.build +++ b/src/examples/meson.build @@ -1 +1,36 @@ -executable('thorvg_sample', 'main.cpp') +examples_dep = dependency('elementary', required : true) + +source_file = [ + 'testArc.cpp', + 'testAsync.cpp', + 'testBlending.cpp', + 'testBoundary.cpp', + 'testCapi.cpp', + 'testCustomTransform.cpp', + 'testDirectUpdate.cpp', + 'testDuplicate.cpp', + 'testGradientTransform.cpp', + 'testLinearGradient.cpp', + 'testMultiCanvas.cpp', + 'testMultiShapes.cpp', + 'testPathCopy.cpp', + 'testPath.cpp', + 'testRadialGradient.cpp', + 'testScene.cpp', + 'testSceneTransform.cpp', + 'testShape.cpp', + 'testStroke.cpp', + 'testStrokeLine.cpp', + 'testSvg2.cpp', + 'testSvg.cpp', + 'testTransform.cpp', + 'testUpdate.cpp', +] + +foreach current_file : source_file + name = current_file.split('.')[0] + executable(name, current_file, + include_directories : headers, + link_with : thorvg_lib, + dependencies : examples_dep) +endforeach diff --git a/test/svgs/batman1.svg b/src/examples/svgs/batman1.svg similarity index 100% rename from test/svgs/batman1.svg rename to src/examples/svgs/batman1.svg diff --git a/test/svgs/bojo.svg b/src/examples/svgs/bojo.svg similarity index 100% rename from test/svgs/bojo.svg rename to src/examples/svgs/bojo.svg diff --git a/test/svgs/bzrfeed.svg b/src/examples/svgs/bzrfeed.svg similarity index 100% rename from test/svgs/bzrfeed.svg rename to src/examples/svgs/bzrfeed.svg diff --git a/test/svgs/cartman.svg b/src/examples/svgs/cartman.svg similarity index 100% rename from test/svgs/cartman.svg rename to src/examples/svgs/cartman.svg diff --git a/test/svgs/dst.svg b/src/examples/svgs/dst.svg similarity index 100% rename from test/svgs/dst.svg rename to src/examples/svgs/dst.svg diff --git a/test/svgs/duke.svg b/src/examples/svgs/duke.svg similarity index 100% rename from test/svgs/duke.svg rename to src/examples/svgs/duke.svg diff --git a/test/svgs/eee.svg b/src/examples/svgs/eee.svg similarity index 100% rename from test/svgs/eee.svg rename to src/examples/svgs/eee.svg diff --git a/test/svgs/favorite_on.svg b/src/examples/svgs/favorite_on.svg similarity index 100% rename from test/svgs/favorite_on.svg rename to src/examples/svgs/favorite_on.svg diff --git a/test/svgs/google.svg b/src/examples/svgs/google.svg similarity index 100% rename from test/svgs/google.svg rename to src/examples/svgs/google.svg diff --git a/test/svgs/ibm.svg b/src/examples/svgs/ibm.svg similarity index 100% rename from test/svgs/ibm.svg rename to src/examples/svgs/ibm.svg diff --git a/test/svgs/lineargrad1.svg b/src/examples/svgs/lineargrad1.svg similarity index 100% rename from test/svgs/lineargrad1.svg rename to src/examples/svgs/lineargrad1.svg diff --git a/test/svgs/radialgrad1.svg b/src/examples/svgs/radialgrad1.svg similarity index 100% rename from test/svgs/radialgrad1.svg rename to src/examples/svgs/radialgrad1.svg diff --git a/test/svgs/scion.svg b/src/examples/svgs/scion.svg similarity index 100% rename from test/svgs/scion.svg rename to src/examples/svgs/scion.svg diff --git a/test/svgs/tiger.svg b/src/examples/svgs/tiger.svg similarity index 100% rename from test/svgs/tiger.svg rename to src/examples/svgs/tiger.svg diff --git a/test/svgs/yadis.svg b/src/examples/svgs/yadis.svg similarity index 100% rename from test/svgs/yadis.svg rename to src/examples/svgs/yadis.svg diff --git a/test/svgs/yinyang.svg b/src/examples/svgs/yinyang.svg similarity index 100% rename from test/svgs/yinyang.svg rename to src/examples/svgs/yinyang.svg diff --git a/test/testArc.cpp b/src/examples/testArc.cpp similarity index 100% rename from test/testArc.cpp rename to src/examples/testArc.cpp diff --git a/test/testAsync.cpp b/src/examples/testAsync.cpp similarity index 100% rename from test/testAsync.cpp rename to src/examples/testAsync.cpp diff --git a/test/testBlending.cpp b/src/examples/testBlending.cpp similarity index 100% rename from test/testBlending.cpp rename to src/examples/testBlending.cpp diff --git a/test/testBoundary.cpp b/src/examples/testBoundary.cpp similarity index 100% rename from test/testBoundary.cpp rename to src/examples/testBoundary.cpp diff --git a/test/testCapi.c b/src/examples/testCapi.cpp similarity index 95% rename from test/testCapi.c rename to src/examples/testCapi.cpp index 82df1f5..bdcc349 100644 --- a/test/testCapi.c +++ b/src/examples/testCapi.cpp @@ -126,13 +126,13 @@ void testCapi() tvg_shape_get_path_commands(shape, &cmds, &cmdCnt); printf("---- First Shape Commands(%u) ----\n", cmdCnt); - for(int i=0; i < cmdCnt; ++i) { + for(uint32_t i = 0; i < cmdCnt; ++i) { printf("%d\n", cmds[i]); } tvg_shape_get_path_coords(shape, &pts, &ptsCnt); printf("---- First Shape Points(%u) ----\n", ptsCnt); - for(int i=0; i < ptsCnt; ++i) { + for(uint32_t i = 0; i < ptsCnt; ++i) { printf("(%.2lf, %.2lf)\n", pts[i].x, pts[i].y); } diff --git a/test/testCommon.h b/src/examples/testCommon.h similarity index 100% rename from test/testCommon.h rename to src/examples/testCommon.h diff --git a/test/testCustomTransform.cpp b/src/examples/testCustomTransform.cpp similarity index 100% rename from test/testCustomTransform.cpp rename to src/examples/testCustomTransform.cpp diff --git a/test/testDirectUpdate.cpp b/src/examples/testDirectUpdate.cpp similarity index 100% rename from test/testDirectUpdate.cpp rename to src/examples/testDirectUpdate.cpp diff --git a/test/testDuplicate.cpp b/src/examples/testDuplicate.cpp similarity index 100% rename from test/testDuplicate.cpp rename to src/examples/testDuplicate.cpp diff --git a/test/testGradientTransform.cpp b/src/examples/testGradientTransform.cpp similarity index 100% rename from test/testGradientTransform.cpp rename to src/examples/testGradientTransform.cpp diff --git a/test/testLinearGradient.cpp b/src/examples/testLinearGradient.cpp similarity index 100% rename from test/testLinearGradient.cpp rename to src/examples/testLinearGradient.cpp diff --git a/test/testMultiCanvas.cpp b/src/examples/testMultiCanvas.cpp similarity index 97% rename from test/testMultiCanvas.cpp rename to src/examples/testMultiCanvas.cpp index d39898c..e8739af 100644 --- a/test/testMultiCanvas.cpp +++ b/src/examples/testMultiCanvas.cpp @@ -216,9 +216,9 @@ int main(int argc, char **argv) evas_object_smart_callback_add(win, "delete,request", win_del, 0); if (tvgEngine == tvg::CanvasEngine::Sw) { - eina_file_dir_list("./svgs", EINA_TRUE, tvgSwTest, win); + eina_file_dir_list(EXAMPLE_DIR, EINA_TRUE, tvgSwTest, win); } else { - eina_file_dir_list("./svgs", EINA_TRUE, tvgGlTest, win); + eina_file_dir_list(EXAMPLE_DIR, EINA_TRUE, tvgGlTest, win); } evas_object_geometry_set(win, 0, 0, WIDTH, HEIGHT); @@ -234,4 +234,4 @@ int main(int argc, char **argv) cout << "engine is not supported" << endl; } return 0; -} \ No newline at end of file +} diff --git a/test/testMultiShapes.cpp b/src/examples/testMultiShapes.cpp similarity index 100% rename from test/testMultiShapes.cpp rename to src/examples/testMultiShapes.cpp diff --git a/test/testPath.cpp b/src/examples/testPath.cpp similarity index 100% rename from test/testPath.cpp rename to src/examples/testPath.cpp diff --git a/test/testPathCopy.cpp b/src/examples/testPathCopy.cpp similarity index 100% rename from test/testPathCopy.cpp rename to src/examples/testPathCopy.cpp diff --git a/test/testRadialGradient.cpp b/src/examples/testRadialGradient.cpp similarity index 100% rename from test/testRadialGradient.cpp rename to src/examples/testRadialGradient.cpp diff --git a/test/testScene.cpp b/src/examples/testScene.cpp similarity index 100% rename from test/testScene.cpp rename to src/examples/testScene.cpp diff --git a/test/testSceneTransform.cpp b/src/examples/testSceneTransform.cpp similarity index 100% rename from test/testSceneTransform.cpp rename to src/examples/testSceneTransform.cpp diff --git a/test/testShape.cpp b/src/examples/testShape.cpp similarity index 100% rename from test/testShape.cpp rename to src/examples/testShape.cpp diff --git a/test/testStroke.cpp b/src/examples/testStroke.cpp similarity index 100% rename from test/testStroke.cpp rename to src/examples/testStroke.cpp diff --git a/test/testStrokeLine.cpp b/src/examples/testStrokeLine.cpp similarity index 100% rename from test/testStrokeLine.cpp rename to src/examples/testStrokeLine.cpp diff --git a/test/testSvg.cpp b/src/examples/testSvg.cpp similarity index 96% rename from test/testSvg.cpp rename to src/examples/testSvg.cpp index 7e3d775..7086127 100644 --- a/test/testSvg.cpp +++ b/src/examples/testSvg.cpp @@ -14,12 +14,10 @@ static std::vector> pictures; void svgDirCallback(const char* name, const char* path, void* data) { - tvg::Canvas* canvas = static_cast(data); - auto picture = tvg::Picture::gen(); char buf[PATH_MAX]; - sprintf(buf,"%s/%s", path, name); + sprintf(buf, "/%s/%s", path, name); if (picture->load(buf) != tvg::Result::Success) return; @@ -61,7 +59,7 @@ void tvgDrawCmds(tvg::Canvas* canvas) if (canvas->push(move(shape)) != tvg::Result::Success) return; - eina_file_dir_list("./svgs", EINA_TRUE, svgDirCallback, canvas); + eina_file_dir_list(EXAMPLE_DIR, EINA_TRUE, svgDirCallback, canvas); /* This showcase shows you asynchrounous loading of svg. For this, pushing pictures at a certian sync time. diff --git a/test/testSvg2.cpp b/src/examples/testSvg2.cpp similarity index 100% rename from test/testSvg2.cpp rename to src/examples/testSvg2.cpp diff --git a/test/testTransform.cpp b/src/examples/testTransform.cpp similarity index 100% rename from test/testTransform.cpp rename to src/examples/testTransform.cpp diff --git a/test/testUpdate.cpp b/src/examples/testUpdate.cpp similarity index 100% rename from test/testUpdate.cpp rename to src/examples/testUpdate.cpp diff --git a/src/meson.build b/src/meson.build index c32a993..8741ef2 100644 --- a/src/meson.build +++ b/src/meson.build @@ -29,8 +29,6 @@ thorvg_lib = library( gnu_symbol_visibility : 'hidden', ) -subdir('bin') - thorvg_dep = declare_dependency( include_directories: headers, link_with : thorvg_lib @@ -45,3 +43,10 @@ pkg_mod.generate( filebase : 'thorvg', description : 'A Thor library for rendering vector graphics' ) + +subdir('bin') + +if get_option('examples') == true + message('Enable Examples') + subdir('examples') +endif diff --git a/test/makefile b/test/makefile deleted file mode 100644 index b5028b1..0000000 --- a/test/makefile +++ /dev/null @@ -1,25 +0,0 @@ -all: - gcc -o testShape testShape.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testMultiShapes testMultiShapes.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testBoundary testBoundary.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testPath testPath.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testPathCopy testPathCopy.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testBlending testBlending.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testUpdate testUpdate.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testDirectUpdate testDirectUpdate.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testScene testScene.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testTransform testTransform.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testCustomTransform testCustomTransform.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testSceneTransform testSceneTransform.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testStroke testStroke.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testStrokeLine testStrokeLine.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testLinearGradient testLinearGradient.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testRadialGradient testRadialGradient.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testGradientTransform testGradientTransform.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testSvg testSvg.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testSvg2 testSvg2.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testAsync testAsync.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testArc testArc.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testMultiCanvas testMultiCanvas.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testDuplicate testDuplicate.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg` - gcc -o testCapi testCapi.c -g `pkg-config --cflags --libs elementary thorvg` -- 2.7.4 From 1fdd155888f5de6956027a26d5a2fb376f88fb18 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Sat, 19 Sep 2020 01:04:34 +0900 Subject: [PATCH 04/16] Update README.md Add examples section. Change-Id: I0f6a954caebad0051490f894b3ea89e6fa26760b --- README.md | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3b80035..ba4618c 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ ThorVG is a platform independent lightweight standalone C++ library for drawing ## Contents - [Building ThorVG](#building-thorvg) - [Meson Build](#meson-build) +- [Quick Start](#quick-start) - [Examples](#examples) - [Tools](#tools) - [SVG to PNG](#svg-to-png) @@ -22,10 +23,10 @@ ThorVG is a platform independent lightweight standalone C++ library for drawing [](#contents)
## Building ThorVG -thorvg supports [meson](https://mesonbuild.com/) build system. +Basically, ThorVG supports [meson](https://mesonbuild.com/) build system.
### Meson Build -install [meson](http://mesonbuild.com/Getting-meson.html) and [ninja](https://ninja-build.org/) if not already installed. +Install [meson](http://mesonbuild.com/Getting-meson.html) and [ninja](https://ninja-build.org/) if not already installed. Run meson to configure ThorVG. ``` @@ -38,10 +39,10 @@ ninja -C build install [Back to contents](#contents)

-## Examples -ThorVG renders vector shapes on a given canvas buffer. +## Quick Start +ThorVG renders vector shapes on a given canvas buffer. Here shows quick start to learn basic API usages. -You can initialize ThorVG engine first: +First, You can initialize ThorVG engine. ```cpp tvg::Initializer::init(tvg::CanvasEngine::Sw, 0); //engine method, thread count @@ -153,6 +154,18 @@ tvg::Initializer::term(tvg::CanvasEngine::Sw); [Back to contents](#contents)

+## Examples +There are various examples to understand ThorVG APIs, Please check sample code in `thorvg/src/examples` + +To execute examples, you can build them with this meson option. +``` +meson -Dexamples=true . build +``` +Note that these examples are required EFL `elementary` package for launching. If you're using Linux-based OS, you could easily install its package from your OS distribution server. Otherwise, please visit the official [EFL page](https://enlightenment.org/) for more information. + +[Back to contents](#contents) +
+
## Tools ### SVG to PNG ThorVG provides an executable `svg2png` converter which generate a PNG file from a SVG file. @@ -173,13 +186,12 @@ Examples: $ svg2png input.svg 200x200 $ svg2png input.svg 200x200 ff00ff ``` - [Back to contents](#contents)

## API Bindings Our main development APIs are written in C++ but ThorVG also provides API bindings such as: C. -
+ [Back to contents](#contents)

-- 2.7.4 From d5272050a828a7a9a87e086bee5cc8467e245836 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Mon, 21 Sep 2020 19:20:51 +0900 Subject: [PATCH 05/16] common fill: implement duplicate() method. Change-Id: Ia47a13d4a124d91f84bd5ed755b831ea5c35e3ff --- inc/thorvg.h | 3 +- src/bindings/capi/tvgCapi.cpp | 2 +- src/lib/meson.build | 1 + src/lib/tvgCanvasImpl.h | 2 +- src/lib/tvgCommon.h | 1 - src/lib/tvgFill.cpp | 23 +++++-------- src/lib/tvgFill.h | 80 +++++++++++++++++++++++++++++++++++++++++++ src/lib/tvgLinearGradient.cpp | 16 ++++++++- src/lib/tvgPaint.cpp | 4 +-- src/lib/tvgPaint.h | 6 ++-- src/lib/tvgPicture.cpp | 1 + src/lib/tvgPictureImpl.h | 2 +- src/lib/tvgRadialGradient.cpp | 15 +++++++- src/lib/tvgSceneImpl.h | 2 +- src/lib/tvgShapeImpl.h | 7 ++-- 15 files changed, 136 insertions(+), 29 deletions(-) create mode 100644 src/lib/tvgFill.h diff --git a/inc/thorvg.h b/inc/thorvg.h index 7d5062c..e4f45a7 100644 --- a/inc/thorvg.h +++ b/inc/thorvg.h @@ -91,7 +91,7 @@ public: Result translate(float x, float y) noexcept; Result transform(const Matrix& m) noexcept; Result bounds(float* x, float* y, float* w, float* h) const noexcept; - std::unique_ptr duplicate() const noexcept; + Paint* duplicate() const noexcept; _TVG_DECLARE_ACCESSOR(); _TVG_DECLARE_PRIVATE(Paint); @@ -122,6 +122,7 @@ public: uint32_t colorStops(const ColorStop** colorStops) const noexcept; FillSpread spread() const noexcept; + std::unique_ptr duplicate() const noexcept; _TVG_DECALRE_IDENTIFIER(); _TVG_DECLARE_PRIVATE(Fill); diff --git a/src/bindings/capi/tvgCapi.cpp b/src/bindings/capi/tvgCapi.cpp index 03ee907..b58f0ff 100644 --- a/src/bindings/capi/tvgCapi.cpp +++ b/src/bindings/capi/tvgCapi.cpp @@ -166,7 +166,7 @@ TVG_EXPORT Tvg_Result tvg_paint_transform(Tvg_Paint* paint, const Tvg_Matrix* m) TVG_EXPORT Tvg_Paint* tvg_paint_duplicate(Tvg_Paint* paint) { if (!paint) return NULL; - return (Tvg_Paint*) reinterpret_cast(paint)->duplicate().release(); + return (Tvg_Paint*) reinterpret_cast(paint)->duplicate(); } diff --git a/src/lib/meson.build b/src/lib/meson.build index bc0d959..0b1b90a 100644 --- a/src/lib/meson.build +++ b/src/lib/meson.build @@ -14,6 +14,7 @@ source_file = [ 'tvgCanvasImpl.h', 'tvgCommon.h', 'tvgBezier.h', + 'tvgFill.h', 'tvgLoader.h', 'tvgLoaderMgr.h', 'tvgPictureImpl.h', diff --git a/src/lib/tvgCanvasImpl.h b/src/lib/tvgCanvasImpl.h index ebac74d..8131284 100644 --- a/src/lib/tvgCanvasImpl.h +++ b/src/lib/tvgCanvasImpl.h @@ -22,7 +22,7 @@ #ifndef _TVG_CANVAS_IMPL_H_ #define _TVG_CANVAS_IMPL_H_ -#include "tvgCommon.h" +#include "tvgPaint.h" /************************************************************************/ /* Internal Class Implementation */ diff --git a/src/lib/tvgCommon.h b/src/lib/tvgCommon.h index 3ed4544..ecacc82 100644 --- a/src/lib/tvgCommon.h +++ b/src/lib/tvgCommon.h @@ -46,7 +46,6 @@ using namespace tvg; #include "tvgLoader.h" #include "tvgLoaderMgr.h" #include "tvgRender.h" -#include "tvgPaint.h" #include "tvgTaskScheduler.h" #endif //_TVG_COMMON_H_ diff --git a/src/lib/tvgFill.cpp b/src/lib/tvgFill.cpp index 4594e84..c9d3f1c 100644 --- a/src/lib/tvgFill.cpp +++ b/src/lib/tvgFill.cpp @@ -19,25 +19,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include "tvgCommon.h" - +#include "tvgFill.h" /************************************************************************/ /* Internal Class Implementation */ /************************************************************************/ -struct Fill::Impl -{ - ColorStop* colorStops = nullptr; - uint32_t cnt = 0; - FillSpread spread; - - ~Impl() - { - if (colorStops) free(colorStops); - } -}; - /************************************************************************/ /* External Class Implementation */ @@ -95,4 +82,10 @@ Result Fill::spread(FillSpread s) noexcept FillSpread Fill::spread() const noexcept { return pImpl->spread; -} \ No newline at end of file +} + + +unique_ptr Fill::duplicate() const noexcept +{ + return pImpl->duplicate(); +} diff --git a/src/lib/tvgFill.h b/src/lib/tvgFill.h new file mode 100644 index 0000000..07af49c --- /dev/null +++ b/src/lib/tvgFill.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef _TVG_FILL_H_ +#define _TVG_FILL_H_ + +#include "tvgCommon.h" + +template +struct DuplicateMethod +{ + virtual ~DuplicateMethod(){} + virtual unique_ptr duplicate() = 0; +}; + +template +struct FillDup : DuplicateMethod +{ + T* inst = nullptr; + + FillDup(T* _inst) : inst(_inst) {} + ~FillDup(){} + + unique_ptr duplicate() override + { + return inst->duplicate(); + } +}; + +struct Fill::Impl +{ + ColorStop* colorStops = nullptr; + uint32_t cnt = 0; + FillSpread spread; + DuplicateMethod* dup = nullptr; + + ~Impl() + { + if (dup) delete(dup); + if (colorStops) free(colorStops); + } + + void method(DuplicateMethod* dup) + { + this->dup = dup; + } + + unique_ptr duplicate() + { + auto ret = dup->duplicate(); + if (!ret) return nullptr; + + ret->pImpl->cnt = cnt; + ret->pImpl->spread = spread; + ret->pImpl->colorStops = static_cast(malloc(sizeof(ColorStop) * cnt)); + memcpy(ret->pImpl->colorStops, colorStops, sizeof(ColorStop) * cnt); + + return ret; + } +}; + +#endif //_TVG_FILL_H_ \ No newline at end of file diff --git a/src/lib/tvgLinearGradient.cpp b/src/lib/tvgLinearGradient.cpp index 1d67c17..5258b33 100644 --- a/src/lib/tvgLinearGradient.cpp +++ b/src/lib/tvgLinearGradient.cpp @@ -19,7 +19,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include "tvgCommon.h" +#include "tvgFill.h" /************************************************************************/ /* Internal Class Implementation */ @@ -31,6 +31,19 @@ struct LinearGradient::Impl float y1 = 0; float x2 = 0; float y2 = 0; + + unique_ptr duplicate() + { + auto ret = LinearGradient::gen(); + if (!ret) return nullptr; + + ret->pImpl->x1 = x1; + ret->pImpl->y1 = y1; + ret->pImpl->x2 = x2; + ret->pImpl->y2 = y2; + + return ret; + } }; /************************************************************************/ @@ -40,6 +53,7 @@ struct LinearGradient::Impl LinearGradient::LinearGradient():pImpl(new Impl()) { _id = FILL_ID_LINEAR; + Fill::pImpl->method(new FillDup(pImpl)); } diff --git a/src/lib/tvgPaint.cpp b/src/lib/tvgPaint.cpp index 55e0d75..7c490ba 100644 --- a/src/lib/tvgPaint.cpp +++ b/src/lib/tvgPaint.cpp @@ -19,7 +19,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include "tvgCommon.h" +#include "tvgPaint.h" /************************************************************************/ /* Internal Class Implementation */ @@ -74,7 +74,7 @@ Result Paint::bounds(float* x, float* y, float* w, float* h) const noexcept return Result::InsufficientCondition; } -unique_ptr Paint::duplicate() const noexcept +Paint* Paint::duplicate() const noexcept { return pImpl->duplicate(); } \ No newline at end of file diff --git a/src/lib/tvgPaint.h b/src/lib/tvgPaint.h index 0fd3a79..63c0849 100644 --- a/src/lib/tvgPaint.h +++ b/src/lib/tvgPaint.h @@ -22,6 +22,8 @@ #ifndef _TVG_PAINT_H_ #define _TVG_PAINT_H_ +#include "tvgCommon.h" + namespace tvg { struct StrategyMethod @@ -146,9 +148,9 @@ namespace tvg return smethod->render(renderer); } - unique_ptr duplicate() + Paint* duplicate() { - return smethod->duplicate(); + return smethod->duplicate().release(); } }; diff --git a/src/lib/tvgPicture.cpp b/src/lib/tvgPicture.cpp index a4ac3ee..0860ff4 100644 --- a/src/lib/tvgPicture.cpp +++ b/src/lib/tvgPicture.cpp @@ -19,6 +19,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ + #include "tvgPictureImpl.h" /************************************************************************/ diff --git a/src/lib/tvgPictureImpl.h b/src/lib/tvgPictureImpl.h index e96384d..b1e4fb1 100644 --- a/src/lib/tvgPictureImpl.h +++ b/src/lib/tvgPictureImpl.h @@ -22,7 +22,7 @@ #ifndef _TVG_PICTURE_IMPL_H_ #define _TVG_PICTURE_IMPL_H_ -#include "tvgCommon.h" +#include "tvgPaint.h" /************************************************************************/ /* Internal Class Implementation */ diff --git a/src/lib/tvgRadialGradient.cpp b/src/lib/tvgRadialGradient.cpp index d91ebba..d02d2e0 100644 --- a/src/lib/tvgRadialGradient.cpp +++ b/src/lib/tvgRadialGradient.cpp @@ -19,7 +19,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include "tvgCommon.h" +#include "tvgFill.h" /************************************************************************/ /* Internal Class Implementation */ @@ -30,6 +30,18 @@ struct RadialGradient::Impl float cx = 0; float cy = 0; float radius = 0; + + unique_ptr duplicate() + { + auto ret = RadialGradient::gen(); + if (!ret) return nullptr; + + ret->pImpl->cx = cx; + ret->pImpl->cy = cy; + ret->pImpl->radius = radius; + + return ret; + } }; @@ -40,6 +52,7 @@ struct RadialGradient::Impl RadialGradient::RadialGradient():pImpl(new Impl()) { _id = FILL_ID_RADIAL; + Fill::pImpl->method(new FillDup(pImpl)); } diff --git a/src/lib/tvgSceneImpl.h b/src/lib/tvgSceneImpl.h index b1b2898..00f2ccc 100644 --- a/src/lib/tvgSceneImpl.h +++ b/src/lib/tvgSceneImpl.h @@ -22,7 +22,7 @@ #ifndef _TVG_SCENE_IMPL_H_ #define _TVG_SCENE_IMPL_H_ -#include "tvgCommon.h" +#include "tvgPaint.h" /************************************************************************/ /* Internal Class Implementation */ diff --git a/src/lib/tvgShapeImpl.h b/src/lib/tvgShapeImpl.h index d9481a2..5186003 100644 --- a/src/lib/tvgShapeImpl.h +++ b/src/lib/tvgShapeImpl.h @@ -22,7 +22,7 @@ #ifndef _TVG_SHAPE_IMPL_H_ #define _TVG_SHAPE_IMPL_H_ -#include "tvgCommon.h" +#include "tvgPaint.h" #include "tvgShapePath.h" /************************************************************************/ @@ -199,7 +199,10 @@ struct Shape::Impl dup->flag |= RenderUpdateFlag::Stroke; } - //TODO: Fill + if (fill) { + dup->fill = fill->duplicate().release(); + dup->flag |= RenderUpdateFlag::Gradient; + } return ret; } -- 2.7.4 From a9e384d870a9bcb0ad99cdeb284e5896069ea5f8 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Mon, 21 Sep 2020 19:22:47 +0900 Subject: [PATCH 06/16] examples: update testDuplicate. Added shape gradient fill to check duplication feature. Change-Id: If2bbfb35d2a6cb4241bfcc8923788cd42512e733 --- src/examples/testDuplicate.cpp | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/examples/testDuplicate.cpp b/src/examples/testDuplicate.cpp index 47fed10..ba889e3 100644 --- a/src/examples/testDuplicate.cpp +++ b/src/examples/testDuplicate.cpp @@ -21,24 +21,39 @@ void tvgDrawCmds(tvg::Canvas* canvas) shape1->fill(255, 0, 0, 255); //Create second shape and duplicate parameters - auto shape2 = shape1->duplicate(); + auto shape2 = unique_ptr(static_cast(shape1->duplicate())); //Create third shape, duplicate from first and add some new parameters - auto shape3 = shape1->duplicate(); + auto shape3 = unique_ptr(static_cast(shape1->duplicate())); - //Get access to valid derived class type - tvg::Shape* shapePtr = reinterpret_cast(shape3.get()); - - //move shape3 to new postion to don't cover second shape + //Move shape3 to new postion to don't cover second shape shape3->translate(0, 220); - //append new paths - shapePtr->appendRect(340, 10, 100, 100, 0, 0); - shapePtr->fill(0, 0, 255, 255); + //Append New paths + shape3->appendRect(340, 10, 100, 100, 0, 0); + + //Fill shap3 with Linear Gradient + auto fill = tvg::LinearGradient::gen(); + fill->linear(10, 10, 440, 200); + + //Gradient Color Stops + tvg::Fill::ColorStop colorStops[2]; + colorStops[0] = {0, 0, 0, 0, 255}; + colorStops[1] = {1, 255, 255, 255, 255}; + + fill->colorStops(colorStops, 2); + + shape3->fill(move(fill)); + + //Create fourth shape, duplicate from third and move position + auto shape4 = unique_ptr(static_cast(shape3->duplicate())); + + //Move shape3 to new postion to don't cover second shape + shape4->translate(0, 440); - //TODO: test gradient canvas->push(move(shape2)); canvas->push(move(shape3)); + canvas->push(move(shape4)); } -- 2.7.4 From 25735b762483b8803caa83ac8259d5690f2dc06d Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Tue, 22 Sep 2020 10:56:53 +0900 Subject: [PATCH 07/16] common fill: code refactoring removed unique_ptr in the interface because it's hard to get polymorphism benefits in programming perspective. Change-Id: I1c1fc0a0b5047f365efb17ece3645291a4719224 --- inc/thorvg.h | 2 +- src/lib/tvgFill.cpp | 2 +- src/lib/tvgFill.h | 6 +++--- src/lib/tvgLinearGradient.cpp | 4 ++-- src/lib/tvgPaint.h | 6 +++--- src/lib/tvgPictureImpl.h | 2 +- src/lib/tvgRadialGradient.cpp | 4 ++-- src/lib/tvgSceneImpl.h | 2 +- src/lib/tvgShapeImpl.h | 6 +++--- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/inc/thorvg.h b/inc/thorvg.h index e4f45a7..71f6b49 100644 --- a/inc/thorvg.h +++ b/inc/thorvg.h @@ -122,7 +122,7 @@ public: uint32_t colorStops(const ColorStop** colorStops) const noexcept; FillSpread spread() const noexcept; - std::unique_ptr duplicate() const noexcept; + Fill* duplicate() const noexcept; _TVG_DECALRE_IDENTIFIER(); _TVG_DECLARE_PRIVATE(Fill); diff --git a/src/lib/tvgFill.cpp b/src/lib/tvgFill.cpp index c9d3f1c..f89ba8b 100644 --- a/src/lib/tvgFill.cpp +++ b/src/lib/tvgFill.cpp @@ -85,7 +85,7 @@ FillSpread Fill::spread() const noexcept } -unique_ptr Fill::duplicate() const noexcept +Fill* Fill::duplicate() const noexcept { return pImpl->duplicate(); } diff --git a/src/lib/tvgFill.h b/src/lib/tvgFill.h index 07af49c..5036337 100644 --- a/src/lib/tvgFill.h +++ b/src/lib/tvgFill.h @@ -28,7 +28,7 @@ template struct DuplicateMethod { virtual ~DuplicateMethod(){} - virtual unique_ptr duplicate() = 0; + virtual T* duplicate() = 0; }; template @@ -39,7 +39,7 @@ struct FillDup : DuplicateMethod FillDup(T* _inst) : inst(_inst) {} ~FillDup(){} - unique_ptr duplicate() override + Fill* duplicate() override { return inst->duplicate(); } @@ -63,7 +63,7 @@ struct Fill::Impl this->dup = dup; } - unique_ptr duplicate() + Fill* duplicate() { auto ret = dup->duplicate(); if (!ret) return nullptr; diff --git a/src/lib/tvgLinearGradient.cpp b/src/lib/tvgLinearGradient.cpp index 5258b33..f647d44 100644 --- a/src/lib/tvgLinearGradient.cpp +++ b/src/lib/tvgLinearGradient.cpp @@ -32,7 +32,7 @@ struct LinearGradient::Impl float x2 = 0; float y2 = 0; - unique_ptr duplicate() + Fill* duplicate() { auto ret = LinearGradient::gen(); if (!ret) return nullptr; @@ -42,7 +42,7 @@ struct LinearGradient::Impl ret->pImpl->x2 = x2; ret->pImpl->y2 = y2; - return ret; + return ret.release(); } }; diff --git a/src/lib/tvgPaint.h b/src/lib/tvgPaint.h index 63c0849..3bdba81 100644 --- a/src/lib/tvgPaint.h +++ b/src/lib/tvgPaint.h @@ -34,7 +34,7 @@ namespace tvg virtual bool update(RenderMethod& renderer, const RenderTransform* transform, RenderUpdateFlag pFlag) = 0; virtual bool render(RenderMethod& renderer) = 0; virtual bool bounds(float* x, float* y, float* w, float* h) const = 0; - virtual unique_ptr duplicate() = 0; + virtual Paint* duplicate() = 0; }; struct Paint::Impl @@ -150,7 +150,7 @@ namespace tvg Paint* duplicate() { - return smethod->duplicate().release(); + return smethod->duplicate(); } }; @@ -183,7 +183,7 @@ namespace tvg return inst->render(renderer); } - unique_ptr duplicate() override + Paint* duplicate() override { return inst->duplicate(); } diff --git a/src/lib/tvgPictureImpl.h b/src/lib/tvgPictureImpl.h index b1e4fb1..b4c5ed5 100644 --- a/src/lib/tvgPictureImpl.h +++ b/src/lib/tvgPictureImpl.h @@ -105,7 +105,7 @@ struct Picture::Impl return Result::Success; } - unique_ptr duplicate() + Paint* duplicate() { //TODO: return nullptr; diff --git a/src/lib/tvgRadialGradient.cpp b/src/lib/tvgRadialGradient.cpp index d02d2e0..03164ae 100644 --- a/src/lib/tvgRadialGradient.cpp +++ b/src/lib/tvgRadialGradient.cpp @@ -31,7 +31,7 @@ struct RadialGradient::Impl float cy = 0; float radius = 0; - unique_ptr duplicate() + Fill* duplicate() { auto ret = RadialGradient::gen(); if (!ret) return nullptr; @@ -40,7 +40,7 @@ struct RadialGradient::Impl ret->pImpl->cy = cy; ret->pImpl->radius = radius; - return ret; + return ret.release(); } }; diff --git a/src/lib/tvgSceneImpl.h b/src/lib/tvgSceneImpl.h index 00f2ccc..d9d6094 100644 --- a/src/lib/tvgSceneImpl.h +++ b/src/lib/tvgSceneImpl.h @@ -89,7 +89,7 @@ struct Scene::Impl return true; } - unique_ptr duplicate() + Paint* duplicate() { //TODO: return nullptr; diff --git a/src/lib/tvgShapeImpl.h b/src/lib/tvgShapeImpl.h index 5186003..7dc1811 100644 --- a/src/lib/tvgShapeImpl.h +++ b/src/lib/tvgShapeImpl.h @@ -176,7 +176,7 @@ struct Shape::Impl return true; } - unique_ptr duplicate() + Paint* duplicate() { auto ret = Shape::gen(); if (!ret) return nullptr; @@ -200,11 +200,11 @@ struct Shape::Impl } if (fill) { - dup->fill = fill->duplicate().release(); + dup->fill = fill->duplicate(); dup->flag |= RenderUpdateFlag::Gradient; } - return ret; + return ret.release(); } }; -- 2.7.4 From d6a9a9eab53e211df0a6c3b3393b9359bedc0c01 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Tue, 22 Sep 2020 13:20:13 +0900 Subject: [PATCH 08/16] common scene: implement duplicate() method. Change-Id: I132776aa42a4f170bd3dd0c36a02dbdeaa9613f7 --- src/examples/testDuplicate.cpp | 90 ++++++++++++++++++++++++++---------------- src/lib/tvgPaint.h | 13 +++++- src/lib/tvgSceneImpl.h | 13 +++++- 3 files changed, 80 insertions(+), 36 deletions(-) diff --git a/src/examples/testDuplicate.cpp b/src/examples/testDuplicate.cpp index ba889e3..b963abf 100644 --- a/src/examples/testDuplicate.cpp +++ b/src/examples/testDuplicate.cpp @@ -8,52 +8,76 @@ void tvgDrawCmds(tvg::Canvas* canvas) { if (!canvas) return; - //Prepare first shape, which will not be drawn - auto shape1 = tvg::Shape::gen(); - shape1->appendRect(10, 10, 200, 200, 0, 0); - shape1->appendRect(220, 10, 100, 100, 0, 0); + //Duplicate Shapes + { + //Original Shape + auto shape1 = tvg::Shape::gen(); + shape1->appendRect(10, 10, 200, 200, 0, 0); + shape1->appendRect(220, 10, 100, 100, 0, 0); - shape1->stroke(3); - shape1->stroke(0, 255, 0, 255); + shape1->stroke(3); + shape1->stroke(0, 255, 0, 255); - float dashPattern[2] = {4, 4}; - shape1->stroke(dashPattern, 2); - shape1->fill(255, 0, 0, 255); + float dashPattern[2] = {4, 4}; + shape1->stroke(dashPattern, 2); + shape1->fill(255, 0, 0, 255); - //Create second shape and duplicate parameters - auto shape2 = unique_ptr(static_cast(shape1->duplicate())); + //Duplicate Shape, Switch fill method + auto shape2 = unique_ptr(static_cast(shape1->duplicate())); + shape2->translate(0, 220); - //Create third shape, duplicate from first and add some new parameters - auto shape3 = unique_ptr(static_cast(shape1->duplicate())); + auto fill = tvg::LinearGradient::gen(); + fill->linear(10, 10, 440, 200); - //Move shape3 to new postion to don't cover second shape - shape3->translate(0, 220); + tvg::Fill::ColorStop colorStops[2]; + colorStops[0] = {0, 0, 0, 0, 255}; + colorStops[1] = {1, 255, 255, 255, 255}; + fill->colorStops(colorStops, 2); - //Append New paths - shape3->appendRect(340, 10, 100, 100, 0, 0); + shape2->fill(move(fill)); - //Fill shap3 with Linear Gradient - auto fill = tvg::LinearGradient::gen(); - fill->linear(10, 10, 440, 200); + //Duplicate Shape 2 + auto shape3 = unique_ptr(static_cast(shape2->duplicate())); + shape3->translate(0, 440); - //Gradient Color Stops - tvg::Fill::ColorStop colorStops[2]; - colorStops[0] = {0, 0, 0, 0, 255}; - colorStops[1] = {1, 255, 255, 255, 255}; + canvas->push(move(shape1)); + canvas->push(move(shape2)); + canvas->push(move(shape3)); + } + + //Duplicate Scene + { + //Create a Scene1 + auto scene1 = tvg::Scene::gen(); + scene1->reserve(3); + + auto shape1 = tvg::Shape::gen(); + shape1->appendRect(0, 0, 400, 400, 50, 50); + shape1->fill(0, 255, 0, 255); + scene1->push(move(shape1)); - fill->colorStops(colorStops, 2); + auto shape2 = tvg::Shape::gen(); + shape2->appendCircle(400, 400, 200, 200); + shape2->fill(255, 255, 0, 255); + scene1->push(move(shape2)); - shape3->fill(move(fill)); + auto shape3 = tvg::Shape::gen(); + shape3->appendCircle(600, 600, 150, 100); + shape3->fill(0, 255, 255, 255); + scene1->push(move(shape3)); - //Create fourth shape, duplicate from third and move position - auto shape4 = unique_ptr(static_cast(shape3->duplicate())); + scene1->scale(0.25); + scene1->translate(400, 0); + + //Duplicate Scene1 + auto scene2 = unique_ptr(static_cast(scene1->duplicate())); + scene2->translate(600, 200); + + canvas->push(move(scene1)); + canvas->push(move(scene2)); + } - //Move shape3 to new postion to don't cover second shape - shape4->translate(0, 440); - canvas->push(move(shape2)); - canvas->push(move(shape3)); - canvas->push(move(shape4)); } diff --git a/src/lib/tvgPaint.h b/src/lib/tvgPaint.h index 3bdba81..d47ba28 100644 --- a/src/lib/tvgPaint.h +++ b/src/lib/tvgPaint.h @@ -150,7 +150,18 @@ namespace tvg Paint* duplicate() { - return smethod->duplicate(); + auto ret = smethod->duplicate(); + + //duplicate Transform + if (rTransform) { + ret->pImpl->rTransform = new RenderTransform(); + if (ret->pImpl->rTransform) { + *ret->pImpl->rTransform = *rTransform; + ret->pImpl->flag |= RenderUpdateFlag::Transform; + } + } + + return ret; } }; diff --git a/src/lib/tvgSceneImpl.h b/src/lib/tvgSceneImpl.h index d9d6094..8073a70 100644 --- a/src/lib/tvgSceneImpl.h +++ b/src/lib/tvgSceneImpl.h @@ -91,8 +91,17 @@ struct Scene::Impl Paint* duplicate() { - //TODO: - return nullptr; + auto ret = Scene::gen(); + if (!ret) return nullptr; + auto dup = ret.get()->pImpl; + + dup->paints.reserve(paints.size()); + + for (auto paint: paints) { + dup->paints.push_back(paint->duplicate()); + } + + return ret.release(); } }; -- 2.7.4 From e1ce66200d46b804e7befebbc8162f236e5fbe16 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Tue, 22 Sep 2020 13:47:23 +0900 Subject: [PATCH 09/16] common picture: implement duplicate() method. Change-Id: I2fae44b8981560cefd6430e068bf3221535090a5 --- src/examples/testDuplicate.cpp | 12 ++++++++++++ src/lib/tvgPaint.h | 2 +- src/lib/tvgPictureImpl.h | 25 +++++++++++++++++++------ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/examples/testDuplicate.cpp b/src/examples/testDuplicate.cpp index b963abf..86fea2c 100644 --- a/src/examples/testDuplicate.cpp +++ b/src/examples/testDuplicate.cpp @@ -77,7 +77,19 @@ void tvgDrawCmds(tvg::Canvas* canvas) canvas->push(move(scene2)); } + //Duplicate Picture + { + auto picture1 = tvg::Picture::gen(); + picture1->load(EXAMPLE_DIR"/tiger.svg"); + picture1->translate(370, 370); + picture1->scale(0.25); + + auto picture2 = unique_ptr(static_cast(picture1->duplicate())); + picture2->translate(550, 550); + canvas->push(move(picture1)); + canvas->push(move(picture2)); + } } diff --git a/src/lib/tvgPaint.h b/src/lib/tvgPaint.h index d47ba28..071a45f 100644 --- a/src/lib/tvgPaint.h +++ b/src/lib/tvgPaint.h @@ -153,7 +153,7 @@ namespace tvg auto ret = smethod->duplicate(); //duplicate Transform - if (rTransform) { + if (ret && rTransform) { ret->pImpl->rTransform = new RenderTransform(); if (ret->pImpl->rTransform) { *ret->pImpl->rTransform = *rTransform; diff --git a/src/lib/tvgPictureImpl.h b/src/lib/tvgPictureImpl.h index b4c5ed5..9b742aa 100644 --- a/src/lib/tvgPictureImpl.h +++ b/src/lib/tvgPictureImpl.h @@ -43,16 +43,22 @@ struct Picture::Impl return true; } - bool update(RenderMethod &renderer, const RenderTransform* transform, RenderUpdateFlag flag) + void reload() { - if (loader) { + if (loader && !paint) { auto scene = loader->data(); if (scene) { - this->paint = scene.release(); - if (!this->paint) return false; + paint = scene.release(); + if (!paint) return; loader->close(); } } + } + + + bool update(RenderMethod &renderer, const RenderTransform* transform, RenderUpdateFlag flag) + { + reload(); if (!paint) return false; @@ -107,8 +113,15 @@ struct Picture::Impl Paint* duplicate() { - //TODO: - return nullptr; + reload(); + + if (!paint) return nullptr; + auto ret = Picture::gen(); + if (!ret) return nullptr; + auto dup = ret.get()->pImpl; + dup->paint = paint->duplicate(); + + return ret.release(); } }; -- 2.7.4 From 5775133bb4097a2d7bdfa317d0c0d83712fd5601 Mon Sep 17 00:00:00 2001 From: JunsuChoi Date: Tue, 22 Sep 2020 14:28:51 +0900 Subject: [PATCH 10/16] SvgPath: When path end(Z,z), Current point are returned to starting point(M,m) When path ends with 'z' or 'Z' command, if 'm' comes as next command, the current point is incorrectly referenced. Since 'Z', 'z' means to close the path, so, Save point and reuse it when 'M' or 'm' is called. Change-Id: I6b47ec0d424dbc7dfc3bcf1344cf2ae4c15a1081 --- src/loaders/svg/tvgSvgPath.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/loaders/svg/tvgSvgPath.cpp b/src/loaders/svg/tvgSvgPath.cpp index 2e3edab..e3ea03e 100644 --- a/src/loaders/svg/tvgSvgPath.cpp +++ b/src/loaders/svg/tvgSvgPath.cpp @@ -280,7 +280,7 @@ static int _numberCount(char cmd) } -static void _processCommand(vector* cmds, vector* pts, char cmd, float* arr, int count, Point* cur, Point* curCtl, bool *isQuadratic) +static void _processCommand(vector* cmds, vector* pts, char cmd, float* arr, int count, Point* cur, Point* curCtl, Point* startPoint, bool *isQuadratic) { int i; switch (cmd) { @@ -321,6 +321,7 @@ static void _processCommand(vector* cmds, vector* pts, char cmds->push_back(PathCommand::MoveTo); pts->push_back(p); *cur = {arr[0] ,arr[1]}; + *startPoint = {arr[0] ,arr[1]}; break; } case 'l': @@ -432,6 +433,7 @@ static void _processCommand(vector* cmds, vector* pts, char case 'z': case 'Z': { cmds->push_back(PathCommand::Close); + *cur = *startPoint; break; } case 'a': @@ -503,6 +505,7 @@ tuple, vector> svgPathToTvgPath(const char* svgPath) int numberCount = 0; Point cur = { 0, 0 }; Point curCtl = { 0, 0 }; + Point startPoint = { 0, 0 }; char cmd = 0; bool isQuadratic = false; char* path = (char*)svgPath; @@ -515,7 +518,7 @@ tuple, vector> svgPathToTvgPath(const char* svgPath) while ((path[0] != '\0')) { path = _nextCommand(path, &cmd, numberArray, &numberCount); if (!path) break; - _processCommand(&cmds, &pts, cmd, numberArray, numberCount, &cur, &curCtl, &isQuadratic); + _processCommand(&cmds, &pts, cmd, numberArray, numberCount, &cur, &curCtl, &startPoint, &isQuadratic); } setlocale(LC_NUMERIC, curLocale); -- 2.7.4 From b79362ce0e17105783095e8c077a853371741d46 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Wed, 23 Sep 2020 11:59:44 +0900 Subject: [PATCH 11/16] examples: added stress test. Change-Id: I2e48dada86608b5494bc56bcc9fbec1f98936642 --- .gitignore | 1 + src/examples/meson.build | 1 + src/examples/testAsync.cpp | 6 +- src/examples/testStress.cpp | 223 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 228 insertions(+), 3 deletions(-) create mode 100644 src/examples/testStress.cpp diff --git a/.gitignore b/.gitignore index 30ce20b..8229869 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ testCapi testArc testMultiCanvas testDuplicate +testStress diff --git a/src/examples/meson.build b/src/examples/meson.build index 4c40890..d50e4f9 100644 --- a/src/examples/meson.build +++ b/src/examples/meson.build @@ -19,6 +19,7 @@ source_file = [ 'testScene.cpp', 'testSceneTransform.cpp', 'testShape.cpp', + 'testStress.cpp', 'testStroke.cpp', 'testStrokeLine.cpp', 'testSvg2.cpp', diff --git a/src/examples/testAsync.cpp b/src/examples/testAsync.cpp index 7635e5d..ddb8271 100644 --- a/src/examples/testAsync.cpp +++ b/src/examples/testAsync.cpp @@ -54,6 +54,9 @@ bool tvgUpdateCmds(tvg::Canvas* canvas) t3 = ecore_time_get(); + //Drawing task can be performed asynchronously. + if (canvas->draw() != tvg::Result::Success) return false; + return true; } @@ -75,9 +78,6 @@ Eina_Bool animSwCb(void* data) { if (!tvgUpdateCmds(swCanvas.get())) return ECORE_CALLBACK_RENEW; - //Drawing task can be performed asynchronously. - if (swCanvas->draw() != tvg::Result::Success) return false; - //Update Efl Canvas Eo* img = (Eo*) data; evas_object_image_pixels_dirty_set(img, EINA_TRUE); diff --git a/src/examples/testStress.cpp b/src/examples/testStress.cpp new file mode 100644 index 0000000..2f95639 --- /dev/null +++ b/src/examples/testStress.cpp @@ -0,0 +1,223 @@ +#include +#include "testCommon.h" + +/************************************************************************/ +/* Drawing Commands */ +/************************************************************************/ + +#define NUM_PER_LINE 16 +#define SIZE 50 + +static int count = 0; +static int frame = 0; +static std::vector pictures; +static double t1, t2, t3, t4; + +void svgDirCallback(const char* name, const char* path, void* data) +{ + auto picture = tvg::Picture::gen(); + + char buf[PATH_MAX]; + sprintf(buf, "/%s/%s", path, name); + + if (picture->load(buf) != tvg::Result::Success) return; + + float x, y, w, h; + picture->viewbox(&x, &y, &w, &h); + + float rate = (SIZE/(w > h ? w : h)); + picture->scale(rate); + + x *= rate; + y *= rate; + w *= rate; + h *= rate; + + //Center Align ? + if (w > h) { + y -= (SIZE - h) * 0.5f; + } else { + x -= (SIZE - w) * 0.5f; + } + + picture->translate((count % NUM_PER_LINE) * SIZE - x, SIZE * (count / NUM_PER_LINE) - y); + ++count; + + //Duplicates + for (int i = 0; i < NUM_PER_LINE - 1; i++) { + tvg::Picture* dup = static_cast(picture->duplicate()); + dup->translate((count % NUM_PER_LINE) * SIZE - x, SIZE * (count / NUM_PER_LINE) - y); + pictures.push_back(dup); + ++count; + } + + cout << "SVG: " << buf << endl; + pictures.push_back(picture.release()); +} + +void tvgDrawCmds(tvg::Canvas* canvas) +{ + if (!canvas) return; + + //Background + auto shape = tvg::Shape::gen(); + shape->appendRect(0, 0, WIDTH, HEIGHT, 0, 0); //x, y, w, h, rx, ry + shape->fill(255, 255, 255, 255); //r, g, b, a + + if (canvas->push(move(shape)) != tvg::Result::Success) return; + + eina_file_dir_list(EXAMPLE_DIR, EINA_TRUE, svgDirCallback, canvas); + + /* This showcase shows you asynchrounous loading of svg. + For this, pushing pictures at a certian sync time. + This means it earns the time to finish loading svg resources, + otherwise you can push pictures immediately. */ + for (auto picture : pictures) { + canvas->push(unique_ptr(picture)); + } +} + + +/************************************************************************/ +/* Sw Engine Test Code */ +/************************************************************************/ + +static unique_ptr swCanvas; + +void tvgSwTest(uint32_t* buffer) +{ + //Create a Canvas + swCanvas = tvg::SwCanvas::gen(); + swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888); + + /* 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() */ + tvgDrawCmds(swCanvas.get()); +} + +void drawSwView(void* data, Eo* obj) +{ + t3 = ecore_time_get(); + + //Drawing task can be performed asynchronously. + if (swCanvas->draw() == tvg::Result::Success) { + swCanvas->sync(); + } + + t4 = ecore_time_get(); + printf("[%5d]: total[%fs] update[%fs], render[%fs]\n", ++frame, t4 - t1, t2 - t1, t4 - t3); +} + +void transitSwCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress) +{ + t1 = ecore_time_get(); + + for (auto picture : pictures) { + picture->rotate(progress * 360); + swCanvas->update(picture); + } + + t2 = ecore_time_get(); + + //Update Efl Canvas + auto img = (Eo*) effect; + evas_object_image_pixels_dirty_set(img, EINA_TRUE); + evas_object_image_data_update_add(img, 0, 0, WIDTH, HEIGHT); +} + + +/************************************************************************/ +/* GL Engine Test Code */ +/************************************************************************/ + +static unique_ptr glCanvas; + +void initGLview(Evas_Object *obj) +{ + static constexpr auto BPP = 4; + + //Create a Canvas + glCanvas = tvg::GlCanvas::gen(); + glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT); + + /* 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() */ + tvgDrawCmds(glCanvas.get()); +} + +void drawGLview(Evas_Object *obj) +{ + auto gl = elm_glview_gl_api_get(obj); + gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + gl->glClear(GL_COLOR_BUFFER_BIT); + + if (glCanvas->draw() == tvg::Result::Success) { + glCanvas->sync(); + } +} + +void transitGlCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress) +{ + for (auto picture : pictures) { + picture->rotate(progress * 360); + glCanvas->update(picture); + } +} + + +/************************************************************************/ +/* Main Code */ +/************************************************************************/ + +int main(int argc, char **argv) +{ + tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw; + + if (argc > 1) { + if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl; + } + + //Initialize ThorVG Engine + if (tvgEngine == tvg::CanvasEngine::Sw) { + cout << "tvg engine: software" << endl; + } else { + cout << "tvg engine: opengl" << endl; + } + + //Threads Count + auto threads = std::thread::hardware_concurrency(); + + //Initialize ThorVG Engine + if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) { + + elm_init(argc, argv); + + Elm_Transit *transit = elm_transit_add(); + + if (tvgEngine == tvg::CanvasEngine::Sw) { + auto view = createSwView(); + elm_transit_effect_add(transit, transitSwCb, view, nullptr); + } else { + auto view = createGlView(); + elm_transit_effect_add(transit, transitGlCb, view, nullptr); + } + + elm_transit_duration_set(transit, 2); + elm_transit_repeat_times_set(transit, -1); + elm_transit_go(transit); + + elm_run(); + elm_shutdown(); + + //Terminate ThorVG Engine + tvg::Initializer::term(tvg::CanvasEngine::Sw); + + } else { + cout << "engine is not supported" << endl; + } + return 0; +} \ No newline at end of file -- 2.7.4 From 6d1ff8067ec3d66964462562180af721efcfc07f Mon Sep 17 00:00:00 2001 From: mmaciola <71131832+mmaciola@users.noreply.github.com> Date: Wed, 23 Sep 2020 08:09:08 +0200 Subject: [PATCH 12/16] bindings/capi: Added gradient getter Change-Id: Ia109c48cb4d3cf9bc753d52bbf486ad8e7233fa6 Co-authored-by: Michal Maciola --- inc/thorvg_capi.h | 6 +++++- src/bindings/capi/tvgCapi.cpp | 26 ++++++++++++++++++++++++++ src/examples/testCapi.cpp | 20 +++++++++++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/inc/thorvg_capi.h b/inc/thorvg_capi.h index 5231d26..7a2d536 100644 --- a/inc/thorvg_capi.h +++ b/inc/thorvg_capi.h @@ -159,9 +159,13 @@ TVG_EXPORT Tvg_Result tvg_shape_get_gradient(const Tvg_Paint* paint, Tvg_Gradien TVG_EXPORT Tvg_Gradient* tvg_linear_gradient_new(); TVG_EXPORT Tvg_Gradient* tvg_radial_gradient_new(); TVG_EXPORT Tvg_Result tvg_linear_gradient_set(Tvg_Gradient* grad, float x1, float y1, float x2, float y2); +TVG_EXPORT Tvg_Result tvg_linear_gradient_get(Tvg_Gradient* grad, float* x1, float* y1, float* x2, float* y2); TVG_EXPORT Tvg_Result tvg_radial_gradient_set(Tvg_Gradient* grad, float cx, float cy, float radius); +TVG_EXPORT Tvg_Result tvg_radial_gradient_get(Tvg_Gradient* grad, float* cx, float* cy, float* radius); TVG_EXPORT Tvg_Result tvg_gradient_set_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop* color_stop, uint32_t cnt); -TVG_EXPORT Tvg_Result tvg_gradient_set_spread(Tvg_Gradient* grad, const Tvg_Stroke_Fill); +TVG_EXPORT Tvg_Result tvg_gradient_get_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop** color_stop, uint32_t* cnt); +TVG_EXPORT Tvg_Result tvg_gradient_set_spread(Tvg_Gradient* grad, const Tvg_Stroke_Fill spread); +TVG_EXPORT Tvg_Result tvg_gradient_get_spread(Tvg_Gradient* grad, Tvg_Stroke_Fill* spread); TVG_EXPORT Tvg_Result tvg_gradient_del(Tvg_Gradient* grad); diff --git a/src/bindings/capi/tvgCapi.cpp b/src/bindings/capi/tvgCapi.cpp index b58f0ff..783efd8 100644 --- a/src/bindings/capi/tvgCapi.cpp +++ b/src/bindings/capi/tvgCapi.cpp @@ -417,24 +417,50 @@ TVG_EXPORT Tvg_Result tvg_linear_gradient_set(Tvg_Gradient* grad, float x1, floa return (Tvg_Result) reinterpret_cast(grad)->linear(x1, y1, x2, y2); } +TVG_EXPORT Tvg_Result tvg_linear_gradient_get(Tvg_Gradient* grad, float* x1, float* y1, float* x2, float* y2) +{ + if (!grad) return TVG_RESULT_INVALID_ARGUMENT; + return (Tvg_Result) reinterpret_cast(grad)->linear(x1, y1, x2, y2); +} + TVG_EXPORT Tvg_Result tvg_radial_gradient_set(Tvg_Gradient* grad, float cx, float cy, float radius) { if (!grad) return TVG_RESULT_INVALID_ARGUMENT; return (Tvg_Result) reinterpret_cast(grad)->radial(cx, cy, radius); } +TVG_EXPORT Tvg_Result tvg_radial_gradient_get(Tvg_Gradient* grad, float* cx, float* cy, float* radius) +{ + if (!grad) return TVG_RESULT_INVALID_ARGUMENT; + return (Tvg_Result) reinterpret_cast(grad)->radial(cx, cy, radius); +} + TVG_EXPORT Tvg_Result tvg_gradient_set_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop* color_stop, uint32_t cnt) { if (!grad) return TVG_RESULT_INVALID_ARGUMENT; return (Tvg_Result) reinterpret_cast(grad)->colorStops(reinterpret_cast(color_stop), cnt); } +TVG_EXPORT Tvg_Result tvg_gradient_get_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop** color_stop, uint32_t* cnt) +{ + if (!grad) return TVG_RESULT_INVALID_ARGUMENT; + *cnt = reinterpret_cast(grad)->colorStops(reinterpret_cast(color_stop)); + return TVG_RESULT_SUCCESS; +} + TVG_EXPORT Tvg_Result tvg_gradient_set_spread(Tvg_Gradient* grad, const Tvg_Stroke_Fill spread) { if (!grad) return TVG_RESULT_INVALID_ARGUMENT; return (Tvg_Result) reinterpret_cast(grad)->spread((FillSpread)spread); } +TVG_EXPORT Tvg_Result tvg_gradient_get_spread(Tvg_Gradient* grad, Tvg_Stroke_Fill* spread) +{ + if (!grad) return TVG_RESULT_INVALID_ARGUMENT; + *spread = (Tvg_Stroke_Fill) reinterpret_cast(grad)->spread(); + return TVG_RESULT_SUCCESS; +} + #ifdef __cplusplus } diff --git a/src/examples/testCapi.cpp b/src/examples/testCapi.cpp index bdcc349..809d367 100644 --- a/src/examples/testCapi.cpp +++ b/src/examples/testCapi.cpp @@ -135,7 +135,25 @@ void testCapi() for(uint32_t i = 0; i < ptsCnt; ++i) { printf("(%.2lf, %.2lf)\n", pts[i].x, pts[i].y); } - + + float x1, y1, x2, y2, radius; + tvg_linear_gradient_get(grad, &x1, &y1, &x2, &y2); + printf("Gradient linear get: %f/%f/%f/%f\n", x1, y1, x2, y2); + tvg_radial_gradient_get(grad6, &x1, &y1, &radius); + printf("Gradient radial get: %f/%f, %f\n", x1, y1, radius); + + uint32_t cnt; + const Tvg_Color_Stop* color_stops_get; + tvg_gradient_get_color_stops(grad5, &color_stops_get, &cnt); + printf("Gradient stops get:\n"); + for(uint32_t i = 0; i < cnt; i++) { + printf("\t[%d] offset: %f, rgb: %d/%d/%d, alpha: %d\n", i, color_stops_get[i].offset, color_stops_get[i].r, color_stops_get[i].g, color_stops_get[i].b, color_stops_get[i].a); + } + + Tvg_Stroke_Fill spread; + tvg_gradient_get_spread(grad, &spread); + printf("Gradient spread: %d\n", (int)spread); + //Origin paint for duplicated Tvg_Paint* org = tvg_shape_new(); tvg_shape_append_rect(org, 550, 10, 100, 100, 0, 0); -- 2.7.4 From 96e735f2d2bc786c1cd1006abaa9a0c0418cd410 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Wed, 23 Sep 2020 20:51:40 +0900 Subject: [PATCH 13/16] optimization: cut off file dependencies. we should avoid code insertion during file dependencies, such as #include "xxx.h" which has implementations. This could increase binary size, we can avoid it as possible. Current patch improves binary size like this: From: file(2059008) = text(120360) data(8096) bss(80) dec(128536) To : file(1921832) = text(118429) data(7872) bss(56) dec(126357) More additional patches will come in to optmize binary size. Change-Id: Iae826752bc80c161c075b5980a485fd27f42e896 --- src/lib/sw_engine/tvgSwCommon.h | 1 + src/lib/sw_engine/tvgSwFill.cpp | 2 ++ src/lib/sw_engine/tvgSwRaster.cpp | 1 + src/lib/sw_engine/tvgSwRenderer.cpp | 1 + src/lib/sw_engine/tvgSwRenderer.h | 3 +++ src/lib/sw_engine/tvgSwRle.cpp | 1 + src/lib/sw_engine/tvgSwShape.cpp | 2 ++ src/lib/sw_engine/tvgSwStroke.cpp | 2 ++ src/lib/tvgBezier.cpp | 5 +++-- src/lib/tvgBezier.h | 2 ++ src/lib/tvgCanvas.cpp | 1 - src/lib/tvgCanvasImpl.h | 1 + src/lib/tvgCommon.h | 15 --------------- src/lib/tvgFill.h | 1 + src/lib/tvgGlCanvas.cpp | 1 - src/lib/tvgInitializer.cpp | 1 + src/lib/tvgLinearGradient.cpp | 2 ++ src/lib/tvgLoader.h | 2 ++ src/lib/tvgLoaderMgr.cpp | 2 +- src/lib/tvgLoaderMgr.h | 2 ++ src/lib/tvgPaint.h | 4 +++- src/lib/tvgPictureImpl.h | 1 + src/lib/tvgRadialGradient.cpp | 1 + src/lib/tvgRender.cpp | 4 +++- src/lib/tvgRender.h | 2 ++ src/lib/tvgSceneImpl.h | 1 + src/lib/tvgShape.cpp | 1 - src/lib/tvgShapePath.h | 1 + src/lib/tvgSwCanvas.cpp | 1 - src/lib/tvgTaskScheduler.cpp | 3 ++- src/lib/tvgTaskScheduler.h | 1 + src/loaders/svg/tvgSimpleXmlParser.cpp | 4 ++++ src/loaders/svg/tvgSimpleXmlParser.h | 4 +--- src/loaders/svg/tvgSvgLoader.cpp | 6 +++++- src/loaders/svg/tvgSvgLoader.h | 2 +- src/loaders/svg/tvgSvgLoaderCommon.h | 1 - src/loaders/svg/tvgSvgPath.cpp | 3 ++- src/loaders/svg/tvgSvgPath.h | 3 ++- src/loaders/svg/tvgSvgSceneBuilder.cpp | 2 ++ src/loaders/svg/tvgSvgSceneBuilder.h | 1 - 40 files changed, 60 insertions(+), 34 deletions(-) diff --git a/src/lib/sw_engine/tvgSwCommon.h b/src/lib/sw_engine/tvgSwCommon.h index 37a40c5..f90f44b 100644 --- a/src/lib/sw_engine/tvgSwCommon.h +++ b/src/lib/sw_engine/tvgSwCommon.h @@ -23,6 +23,7 @@ #define _TVG_SW_COMMON_H_ #include "tvgCommon.h" +#include "tvgRender.h" #ifdef THORVG_AVX_VECTOR_SUPPORT #include diff --git a/src/lib/sw_engine/tvgSwFill.cpp b/src/lib/sw_engine/tvgSwFill.cpp index ecb3394..c421371 100644 --- a/src/lib/sw_engine/tvgSwFill.cpp +++ b/src/lib/sw_engine/tvgSwFill.cpp @@ -19,6 +19,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#include +#include #include "tvgSwCommon.h" diff --git a/src/lib/sw_engine/tvgSwRaster.cpp b/src/lib/sw_engine/tvgSwRaster.cpp index 7b5b986..d75bc2b 100644 --- a/src/lib/sw_engine/tvgSwRaster.cpp +++ b/src/lib/sw_engine/tvgSwRaster.cpp @@ -20,6 +20,7 @@ * SOFTWARE. */ #include "tvgSwCommon.h" +#include "tvgRender.h" /************************************************************************/ /* Internal Class Implementation */ diff --git a/src/lib/sw_engine/tvgSwRenderer.cpp b/src/lib/sw_engine/tvgSwRenderer.cpp index ff1055f..8c6ee95 100644 --- a/src/lib/sw_engine/tvgSwRenderer.cpp +++ b/src/lib/sw_engine/tvgSwRenderer.cpp @@ -20,6 +20,7 @@ * SOFTWARE. */ #include "tvgSwCommon.h" +#include "tvgTaskScheduler.h" #include "tvgSwRenderer.h" /************************************************************************/ diff --git a/src/lib/sw_engine/tvgSwRenderer.h b/src/lib/sw_engine/tvgSwRenderer.h index 016e444..5b39990 100644 --- a/src/lib/sw_engine/tvgSwRenderer.h +++ b/src/lib/sw_engine/tvgSwRenderer.h @@ -22,6 +22,9 @@ #ifndef _TVG_SW_RENDERER_H_ #define _TVG_SW_RENDERER_H_ +#include +#include "tvgRender.h" + struct SwSurface; struct SwTask; diff --git a/src/lib/sw_engine/tvgSwRle.cpp b/src/lib/sw_engine/tvgSwRle.cpp index 545237d..de20d61 100644 --- a/src/lib/sw_engine/tvgSwRle.cpp +++ b/src/lib/sw_engine/tvgSwRle.cpp @@ -22,6 +22,7 @@ #include #include #include + #include "tvgSwCommon.h" /************************************************************************/ diff --git a/src/lib/sw_engine/tvgSwShape.cpp b/src/lib/sw_engine/tvgSwShape.cpp index 49bcd12..0c6391c 100644 --- a/src/lib/sw_engine/tvgSwShape.cpp +++ b/src/lib/sw_engine/tvgSwShape.cpp @@ -19,7 +19,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#include #include "tvgSwCommon.h" +#include "tvgBezier.h" /************************************************************************/ /* Internal Class Implementation */ diff --git a/src/lib/sw_engine/tvgSwStroke.cpp b/src/lib/sw_engine/tvgSwStroke.cpp index e87ec4c..9f2dfe1 100644 --- a/src/lib/sw_engine/tvgSwStroke.cpp +++ b/src/lib/sw_engine/tvgSwStroke.cpp @@ -19,6 +19,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#include +#include #include "tvgSwCommon.h" diff --git a/src/lib/tvgBezier.cpp b/src/lib/tvgBezier.cpp index db4d58b..4129e71 100644 --- a/src/lib/tvgBezier.cpp +++ b/src/lib/tvgBezier.cpp @@ -19,8 +19,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include "tvgCommon.h" - +#include +#include +#include "tvgBezier.h" /************************************************************************/ /* Internal Class Implementation */ diff --git a/src/lib/tvgBezier.h b/src/lib/tvgBezier.h index df21719..89c8049 100644 --- a/src/lib/tvgBezier.h +++ b/src/lib/tvgBezier.h @@ -22,6 +22,8 @@ #ifndef _TVG_BEZIER_H_ #define _TVG_BEZIER_H_ +#include "tvgCommon.h" + namespace tvg { diff --git a/src/lib/tvgCanvas.cpp b/src/lib/tvgCanvas.cpp index 0720e04..eb08768 100644 --- a/src/lib/tvgCanvas.cpp +++ b/src/lib/tvgCanvas.cpp @@ -19,7 +19,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include "tvgCommon.h" #include "tvgCanvasImpl.h" /************************************************************************/ diff --git a/src/lib/tvgCanvasImpl.h b/src/lib/tvgCanvasImpl.h index 8131284..e2de033 100644 --- a/src/lib/tvgCanvasImpl.h +++ b/src/lib/tvgCanvasImpl.h @@ -22,6 +22,7 @@ #ifndef _TVG_CANVAS_IMPL_H_ #define _TVG_CANVAS_IMPL_H_ +#include #include "tvgPaint.h" /************************************************************************/ diff --git a/src/lib/tvgCommon.h b/src/lib/tvgCommon.h index ecacc82..5eb5743 100644 --- a/src/lib/tvgCommon.h +++ b/src/lib/tvgCommon.h @@ -23,15 +23,6 @@ #define _TVG_COMMON_H_ #include "config.h" - -#include -#include -#include -#include -#include -#include -#include - #include "thorvg.h" using namespace std; @@ -42,10 +33,4 @@ using namespace tvg; #define TVG_UNUSED __attribute__ ((__unused__)) -#include "tvgBezier.h" -#include "tvgLoader.h" -#include "tvgLoaderMgr.h" -#include "tvgRender.h" -#include "tvgTaskScheduler.h" - #endif //_TVG_COMMON_H_ diff --git a/src/lib/tvgFill.h b/src/lib/tvgFill.h index 5036337..a0db584 100644 --- a/src/lib/tvgFill.h +++ b/src/lib/tvgFill.h @@ -22,6 +22,7 @@ #ifndef _TVG_FILL_H_ #define _TVG_FILL_H_ +#include #include "tvgCommon.h" template diff --git a/src/lib/tvgGlCanvas.cpp b/src/lib/tvgGlCanvas.cpp index 85bcd1d..416ed44 100644 --- a/src/lib/tvgGlCanvas.cpp +++ b/src/lib/tvgGlCanvas.cpp @@ -19,7 +19,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include "tvgCommon.h" #include "tvgCanvasImpl.h" #ifdef THORVG_GL_RASTER_SUPPORT diff --git a/src/lib/tvgInitializer.cpp b/src/lib/tvgInitializer.cpp index 7dcc8b9..bc0a65f 100644 --- a/src/lib/tvgInitializer.cpp +++ b/src/lib/tvgInitializer.cpp @@ -20,6 +20,7 @@ * SOFTWARE. */ #include "tvgCommon.h" +#include "tvgTaskScheduler.h" #include "tvgLoaderMgr.h" #ifdef THORVG_SW_RASTER_SUPPORT diff --git a/src/lib/tvgLinearGradient.cpp b/src/lib/tvgLinearGradient.cpp index f647d44..ffd9a00 100644 --- a/src/lib/tvgLinearGradient.cpp +++ b/src/lib/tvgLinearGradient.cpp @@ -19,6 +19,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#include +#include #include "tvgFill.h" /************************************************************************/ diff --git a/src/lib/tvgLoader.h b/src/lib/tvgLoader.h index 9c7279e..c02baff 100644 --- a/src/lib/tvgLoader.h +++ b/src/lib/tvgLoader.h @@ -22,6 +22,8 @@ #ifndef _TVG_LOADER_H_ #define _TVG_LOADER_H_ +#include "tvgCommon.h" + namespace tvg { diff --git a/src/lib/tvgLoaderMgr.cpp b/src/lib/tvgLoaderMgr.cpp index 6ec3213..6ed2d3e 100644 --- a/src/lib/tvgLoaderMgr.cpp +++ b/src/lib/tvgLoaderMgr.cpp @@ -19,7 +19,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include "tvgCommon.h" +#include "tvgLoaderMgr.h" #ifdef THORVG_SVG_LOADER_SUPPORT #include "tvgSvgLoader.h" diff --git a/src/lib/tvgLoaderMgr.h b/src/lib/tvgLoaderMgr.h index 95a0676..81623f2 100644 --- a/src/lib/tvgLoaderMgr.h +++ b/src/lib/tvgLoaderMgr.h @@ -22,6 +22,8 @@ #ifndef _TVG_LOADER_MGR_H_ #define _TVG_LOADER_MGR_H_ +#include "tvgLoader.h" + struct LoaderMgr { static bool init(); diff --git a/src/lib/tvgPaint.h b/src/lib/tvgPaint.h index 071a45f..4b49520 100644 --- a/src/lib/tvgPaint.h +++ b/src/lib/tvgPaint.h @@ -22,7 +22,9 @@ #ifndef _TVG_PAINT_H_ #define _TVG_PAINT_H_ -#include "tvgCommon.h" +#include +#include +#include "tvgRender.h" namespace tvg { diff --git a/src/lib/tvgPictureImpl.h b/src/lib/tvgPictureImpl.h index 9b742aa..0f07ed1 100644 --- a/src/lib/tvgPictureImpl.h +++ b/src/lib/tvgPictureImpl.h @@ -23,6 +23,7 @@ #define _TVG_PICTURE_IMPL_H_ #include "tvgPaint.h" +#include "tvgLoaderMgr.h" /************************************************************************/ /* Internal Class Implementation */ diff --git a/src/lib/tvgRadialGradient.cpp b/src/lib/tvgRadialGradient.cpp index 03164ae..7353350 100644 --- a/src/lib/tvgRadialGradient.cpp +++ b/src/lib/tvgRadialGradient.cpp @@ -19,6 +19,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#include #include "tvgFill.h" /************************************************************************/ diff --git a/src/lib/tvgRender.cpp b/src/lib/tvgRender.cpp index 10a23e8..84413f0 100644 --- a/src/lib/tvgRender.cpp +++ b/src/lib/tvgRender.cpp @@ -19,7 +19,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include "tvgCommon.h" +#include +#include +#include "tvgRender.h" /************************************************************************/ /* Internal Class Implementation */ diff --git a/src/lib/tvgRender.h b/src/lib/tvgRender.h index 9beb72b..f710a0f 100644 --- a/src/lib/tvgRender.h +++ b/src/lib/tvgRender.h @@ -22,6 +22,8 @@ #ifndef _TVG_RENDER_H_ #define _TVG_RENDER_H_ +#include "tvgCommon.h" + namespace tvg { diff --git a/src/lib/tvgSceneImpl.h b/src/lib/tvgSceneImpl.h index 8073a70..c384d8c 100644 --- a/src/lib/tvgSceneImpl.h +++ b/src/lib/tvgSceneImpl.h @@ -22,6 +22,7 @@ #ifndef _TVG_SCENE_IMPL_H_ #define _TVG_SCENE_IMPL_H_ +#include #include "tvgPaint.h" /************************************************************************/ diff --git a/src/lib/tvgShape.cpp b/src/lib/tvgShape.cpp index a68c085..0a0a622 100644 --- a/src/lib/tvgShape.cpp +++ b/src/lib/tvgShape.cpp @@ -20,7 +20,6 @@ * SOFTWARE. */ #include - #include "tvgShapeImpl.h" /************************************************************************/ diff --git a/src/lib/tvgShapePath.h b/src/lib/tvgShapePath.h index f3b1f6e..bfbdcf5 100644 --- a/src/lib/tvgShapePath.h +++ b/src/lib/tvgShapePath.h @@ -22,6 +22,7 @@ #ifndef _TVG_SHAPE_PATH_H_ #define _TVG_SHAPE_PATH_H_ +#include #include "tvgCommon.h" /************************************************************************/ diff --git a/src/lib/tvgSwCanvas.cpp b/src/lib/tvgSwCanvas.cpp index 1a2261a..03337a7 100644 --- a/src/lib/tvgSwCanvas.cpp +++ b/src/lib/tvgSwCanvas.cpp @@ -19,7 +19,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include "tvgCommon.h" #include "tvgCanvasImpl.h" #ifdef THORVG_SW_RASTER_SUPPORT diff --git a/src/lib/tvgTaskScheduler.cpp b/src/lib/tvgTaskScheduler.cpp index bdf6edc..d4c21f1 100644 --- a/src/lib/tvgTaskScheduler.cpp +++ b/src/lib/tvgTaskScheduler.cpp @@ -21,7 +21,8 @@ */ #include #include -#include "tvgCommon.h" +#include +#include "tvgTaskScheduler.h" /************************************************************************/ /* Internal Class Implementation */ diff --git a/src/lib/tvgTaskScheduler.h b/src/lib/tvgTaskScheduler.h index 31d1ee1..d94a318 100644 --- a/src/lib/tvgTaskScheduler.h +++ b/src/lib/tvgTaskScheduler.h @@ -22,6 +22,7 @@ #ifndef _TVG_TASK_SCHEDULER_H_ #define _TVG_TASK_SCHEDULER_H_ +#include #include "tvgCommon.h" namespace tvg diff --git a/src/loaders/svg/tvgSimpleXmlParser.cpp b/src/loaders/svg/tvgSimpleXmlParser.cpp index d287ba7..3918af1 100644 --- a/src/loaders/svg/tvgSimpleXmlParser.cpp +++ b/src/loaders/svg/tvgSimpleXmlParser.cpp @@ -20,6 +20,10 @@ * SOFTWARE. */ +#include +#include +#include + #include "tvgSimpleXmlParser.h" static const char* _simpleXmlFindWhiteSpace(const char* itr, const char* itrEnd) diff --git a/src/loaders/svg/tvgSimpleXmlParser.h b/src/loaders/svg/tvgSimpleXmlParser.h index a9f999d..9c19547 100644 --- a/src/loaders/svg/tvgSimpleXmlParser.h +++ b/src/loaders/svg/tvgSimpleXmlParser.h @@ -23,9 +23,7 @@ #ifndef _TVG_SIMPLE_XML_PARSER_H_ #define _TVG_SIMPLE_XML_PARSER_H_ -#include -#include -#include +#include "tvgSvgLoaderCommon.h" enum class SimpleXMLType { diff --git a/src/loaders/svg/tvgSvgLoader.cpp b/src/loaders/svg/tvgSvgLoader.cpp index f86f9df..3495fca 100644 --- a/src/loaders/svg/tvgSvgLoader.cpp +++ b/src/loaders/svg/tvgSvgLoader.cpp @@ -21,9 +21,13 @@ */ #include #include +#include +#include +#include +#include "tvgLoaderMgr.h" +#include "tvgSimpleXmlParser.h" #include "tvgSvgLoader.h" - /************************************************************************/ /* Internal Class Implementation */ /************************************************************************/ diff --git a/src/loaders/svg/tvgSvgLoader.h b/src/loaders/svg/tvgSvgLoader.h index 3cf4cf2..cd04d7d 100644 --- a/src/loaders/svg/tvgSvgLoader.h +++ b/src/loaders/svg/tvgSvgLoader.h @@ -22,7 +22,7 @@ #ifndef _TVG_SVG_LOADER_H_ #define _TVG_SVG_LOADER_H_ -#include "tvgSvgLoaderCommon.h" +#include "tvgTaskScheduler.h" #include "tvgSvgSceneBuilder.h" class SvgLoader : public Loader, public Task diff --git a/src/loaders/svg/tvgSvgLoaderCommon.h b/src/loaders/svg/tvgSvgLoaderCommon.h index 91896bc..3cbe22d 100644 --- a/src/loaders/svg/tvgSvgLoaderCommon.h +++ b/src/loaders/svg/tvgSvgLoaderCommon.h @@ -23,7 +23,6 @@ #define _TVG_SVG_LOADER_COMMON_H_ #include "tvgCommon.h" -#include "tvgSimpleXmlParser.h" enum class SvgNodeType { diff --git a/src/loaders/svg/tvgSvgPath.cpp b/src/loaders/svg/tvgSvgPath.cpp index e3ea03e..3ede0e0 100644 --- a/src/loaders/svg/tvgSvgPath.cpp +++ b/src/loaders/svg/tvgSvgPath.cpp @@ -19,9 +19,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#include +#include #include "tvgSvgPath.h" - static char* _skipComma(const char* content) { while (*content && isspace(*content)) { diff --git a/src/loaders/svg/tvgSvgPath.h b/src/loaders/svg/tvgSvgPath.h index 9d853d1..5324a04 100644 --- a/src/loaders/svg/tvgSvgPath.h +++ b/src/loaders/svg/tvgSvgPath.h @@ -23,7 +23,8 @@ #ifndef _TVG_SVG_PATH_H_ #define _TVG_SVG_PATH_H_ -#include "tvgCommon.h" +#include +#include "tvgSvgLoaderCommon.h" tuple, vector> svgPathToTvgPath(const char* svg_path_data); diff --git a/src/loaders/svg/tvgSvgSceneBuilder.cpp b/src/loaders/svg/tvgSvgSceneBuilder.cpp index 0f1f80b..f3922cb 100644 --- a/src/loaders/svg/tvgSvgSceneBuilder.cpp +++ b/src/loaders/svg/tvgSvgSceneBuilder.cpp @@ -19,7 +19,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#include #include "tvgSvgSceneBuilder.h" +#include "tvgSvgPath.h" unique_ptr _applyLinearGradientProperty(SvgStyleGradient* g, Shape* vg, float rx, float ry, float rw, float rh) { diff --git a/src/loaders/svg/tvgSvgSceneBuilder.h b/src/loaders/svg/tvgSvgSceneBuilder.h index 0f93d96..79f111b 100644 --- a/src/loaders/svg/tvgSvgSceneBuilder.h +++ b/src/loaders/svg/tvgSvgSceneBuilder.h @@ -24,7 +24,6 @@ #define _TVG_SVG_SCENE_BUILDER_H_ #include "tvgSvgLoaderCommon.h" -#include "tvgSvgPath.h" class SvgSceneBuilder { -- 2.7.4 From 8d54977f9161834b3e46775a8c73f58cdd518749 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Thu, 24 Sep 2020 17:05:25 +0900 Subject: [PATCH 14/16] common: code refactoring. Merge shape internal bodies to one (ShapePath => ShapeImpl), for keeping less files. Change-Id: I98ed3c032524f45189e1d30b4a7015410343984a --- src/lib/meson.build | 1 - src/lib/tvgShapeImpl.h | 134 +++++++++++++++++++++++++++++++++++++++- src/lib/tvgShapePath.h | 163 ------------------------------------------------- 3 files changed, 133 insertions(+), 165 deletions(-) delete mode 100644 src/lib/tvgShapePath.h diff --git a/src/lib/meson.build b/src/lib/meson.build index 0b1b90a..6968eb9 100644 --- a/src/lib/meson.build +++ b/src/lib/meson.build @@ -20,7 +20,6 @@ source_file = [ 'tvgPictureImpl.h', 'tvgRender.h', 'tvgSceneImpl.h', - 'tvgShapePath.h', 'tvgShapeImpl.h', 'tvgTaskScheduler.h', 'tvgBezier.cpp', diff --git a/src/lib/tvgShapeImpl.h b/src/lib/tvgShapeImpl.h index 7dc1811..18e58e6 100644 --- a/src/lib/tvgShapeImpl.h +++ b/src/lib/tvgShapeImpl.h @@ -22,8 +22,8 @@ #ifndef _TVG_SHAPE_IMPL_H_ #define _TVG_SHAPE_IMPL_H_ +#include #include "tvgPaint.h" -#include "tvgShapePath.h" /************************************************************************/ /* Internal Class Implementation */ @@ -58,6 +58,138 @@ struct ShapeStroke }; +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) free(cmds); + if (pts) free(pts); + } + + ShapePath() {} + + ShapePath(const ShapePath* src) + { + cmdCnt = src->cmdCnt; + reservedCmdCnt = src->reservedCmdCnt; + ptsCnt = src->ptsCnt; + reservedPtsCnt = src->reservedPtsCnt; + + cmds = static_cast(malloc(sizeof(PathCommand) * reservedCmdCnt)); + if (!cmds) return; + memcpy(cmds, src->cmds, sizeof(PathCommand) * cmdCnt); + + pts = static_cast(malloc(sizeof(Point) * reservedPtsCnt)); + if (!pts) { + free(cmds); + return; + } + memcpy(pts, src->pts, sizeof(Point) * ptsCnt); + } + + void reserveCmd(uint32_t cmdCnt) + { + if (cmdCnt <= reservedCmdCnt) return; + reservedCmdCnt = cmdCnt; + cmds = static_cast(realloc(cmds, sizeof(PathCommand) * reservedCmdCnt)); + } + + void reservePts(uint32_t ptsCnt) + { + if (ptsCnt <= reservedPtsCnt) return; + reservedPtsCnt = ptsCnt; + pts = static_cast(realloc(pts, sizeof(Point) * reservedPtsCnt)); + } + + void grow(uint32_t cmdCnt, uint32_t ptsCnt) + { + reserveCmd(this->cmdCnt + cmdCnt); + reservePts(this->ptsCnt + ptsCnt); + } + + void reset() + { + cmdCnt = 0; + ptsCnt = 0; + } + + void append(const PathCommand* cmds, uint32_t cmdCnt, const Point* pts, uint32_t ptsCnt) + { + memcpy(this->cmds + this->cmdCnt, cmds, sizeof(PathCommand) * cmdCnt); + memcpy(this->pts + this->ptsCnt, pts, sizeof(Point) * ptsCnt); + this->cmdCnt += cmdCnt; + this->ptsCnt += ptsCnt; + } + + void 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}; + } + + void 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}; + } + + void 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}; + } + + void close() + { + if (cmdCnt > 0 && cmds[cmdCnt - 1] == PathCommand::Close) return; + + if (cmdCnt + 1 > reservedCmdCnt) reserveCmd((cmdCnt + 1) * 2); + cmds[cmdCnt++] = PathCommand::Close; + } + + bool bounds(float* x, float* y, float* w, float* h) + { + if (ptsCnt == 0) return false; + + 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; + } + + if (x) *x = min.x; + if (y) *y = min.y; + if (w) *w = max.x - min.x; + if (h) *h = max.y - min.y; + + return true; + } +}; + + struct Shape::Impl { ShapePath *path = nullptr; diff --git a/src/lib/tvgShapePath.h b/src/lib/tvgShapePath.h deleted file mode 100644 index bfbdcf5..0000000 --- a/src/lib/tvgShapePath.h +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. - - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef _TVG_SHAPE_PATH_H_ -#define _TVG_SHAPE_PATH_H_ - -#include -#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) free(cmds); - if (pts) free(pts); - } - - ShapePath() {} - - ShapePath(const ShapePath* src) - { - cmdCnt = src->cmdCnt; - reservedCmdCnt = src->reservedCmdCnt; - ptsCnt = src->ptsCnt; - reservedPtsCnt = src->reservedPtsCnt; - - cmds = static_cast(malloc(sizeof(PathCommand) * reservedCmdCnt)); - if (!cmds) return; - memcpy(cmds, src->cmds, sizeof(PathCommand) * cmdCnt); - - pts = static_cast(malloc(sizeof(Point) * reservedPtsCnt)); - if (!pts) { - free(cmds); - return; - } - memcpy(pts, src->pts, sizeof(Point) * ptsCnt); - } - - void reserveCmd(uint32_t cmdCnt) - { - if (cmdCnt <= reservedCmdCnt) return; - reservedCmdCnt = cmdCnt; - cmds = static_cast(realloc(cmds, sizeof(PathCommand) * reservedCmdCnt)); - } - - void reservePts(uint32_t ptsCnt) - { - if (ptsCnt <= reservedPtsCnt) return; - reservedPtsCnt = ptsCnt; - pts = static_cast(realloc(pts, sizeof(Point) * reservedPtsCnt)); - } - - void grow(uint32_t cmdCnt, uint32_t ptsCnt) - { - reserveCmd(this->cmdCnt + cmdCnt); - reservePts(this->ptsCnt + ptsCnt); - } - - void reset() - { - cmdCnt = 0; - ptsCnt = 0; - } - - void append(const PathCommand* cmds, uint32_t cmdCnt, const Point* pts, uint32_t ptsCnt) - { - memcpy(this->cmds + this->cmdCnt, cmds, sizeof(PathCommand) * cmdCnt); - memcpy(this->pts + this->ptsCnt, pts, sizeof(Point) * ptsCnt); - this->cmdCnt += cmdCnt; - this->ptsCnt += ptsCnt; - } - - void 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}; - } - - void 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}; - } - - void 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}; - } - - void close() - { - if (cmdCnt > 0 && cmds[cmdCnt - 1] == PathCommand::Close) return; - - if (cmdCnt + 1 > reservedCmdCnt) reserveCmd((cmdCnt + 1) * 2); - cmds[cmdCnt++] = PathCommand::Close; - } - - bool bounds(float* x, float* y, float* w, float* h) - { - if (ptsCnt == 0) return false; - - 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; - } - - if (x) *x = min.x; - if (y) *y = min.y; - if (w) *w = max.x - min.x; - if (h) *h = max.y - min.y; - - return true; - } -}; - -#endif //_TVG_SHAPE_PATH_H_ -- 2.7.4 From 69617dc8b1eae69896a47389b495d476e49741d1 Mon Sep 17 00:00:00 2001 From: Michal Szczecinski Date: Wed, 23 Sep 2020 11:41:32 +0200 Subject: [PATCH 15/16] gradient: Fixed radial gradient setter. Removed check for gradient radius. Because of check, x and y values was ignored when radius equals 0 and api was not usable in integration with external libs which sets gradient center and radius in separeted functions. Change-Id: I6af9ca489d158636db7f24f971a625b1d1813cb4 --- src/lib/tvgRadialGradient.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/tvgRadialGradient.cpp b/src/lib/tvgRadialGradient.cpp index 7353350..46c4fc4 100644 --- a/src/lib/tvgRadialGradient.cpp +++ b/src/lib/tvgRadialGradient.cpp @@ -65,7 +65,7 @@ RadialGradient::~RadialGradient() Result RadialGradient::radial(float cx, float cy, float radius) noexcept { - if (radius < FLT_EPSILON) return Result::InvalidArguments; + if (radius < 0) return Result::InvalidArguments; pImpl->cx = cx; pImpl->cy = cy; @@ -88,4 +88,4 @@ Result RadialGradient::radial(float* cx, float* cy, float* radius) const noexcep unique_ptr RadialGradient::gen() noexcept { return unique_ptr(new RadialGradient); -} \ No newline at end of file +} -- 2.7.4 From e9529ecb92d8a1bef57ff993f009dda790cc017e Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Fri, 25 Sep 2020 13:56:47 +0900 Subject: [PATCH 16/16] gl_engine: fix compile error. After refactoring header includsion, gl_engine has a break at file dependencies. now this fixes it. Change-Id: I876e552392bd330b0c5dfe1821d7bfa046b50af8 --- src/lib/gl_engine/tvgGlCommon.h | 4 +++- src/lib/gl_engine/tvgGlGeometry.cpp | 4 +--- src/lib/gl_engine/tvgGlGeometry.h | 2 ++ src/lib/gl_engine/tvgGlGpuBuffer.cpp | 5 +++-- src/lib/gl_engine/tvgGlGpuBuffer.h | 3 +-- src/lib/gl_engine/tvgGlProgram.cpp | 10 +++++++-- src/lib/gl_engine/tvgGlProgram.h | 4 +--- src/lib/gl_engine/tvgGlPropertyInterface.cpp | 32 +++++++++++++++++++++++++++- src/lib/gl_engine/tvgGlPropertyInterface.h | 26 ++++++++++++++++++---- src/lib/gl_engine/tvgGlRenderTask.cpp | 31 ++++++++++++++++++++++----- src/lib/gl_engine/tvgGlRenderTask.h | 28 ++++++++++++++++++------ src/lib/gl_engine/tvgGlRenderer.cpp | 6 +++--- src/lib/gl_engine/tvgGlRenderer.h | 2 -- src/lib/gl_engine/tvgGlRendererProperties.h | 30 ++++++++++++++++++++------ src/lib/gl_engine/tvgGlShader.cpp | 6 ++++-- src/lib/gl_engine/tvgGlShader.h | 2 +- src/lib/gl_engine/tvgGlShaderSrc.cpp | 3 +-- 17 files changed, 153 insertions(+), 45 deletions(-) diff --git a/src/lib/gl_engine/tvgGlCommon.h b/src/lib/gl_engine/tvgGlCommon.h index 6acee47..7c5ba2e 100644 --- a/src/lib/gl_engine/tvgGlCommon.h +++ b/src/lib/gl_engine/tvgGlCommon.h @@ -23,8 +23,10 @@ #ifndef _TVG_GL_COMMON_H_ #define _TVG_GL_COMMON_H_ -#include "tvgCommon.h" #include +#include +#include "tvgCommon.h" +#include "tvgRender.h" #define GL_CHECK(x) \ diff --git a/src/lib/gl_engine/tvgGlGeometry.cpp b/src/lib/gl_engine/tvgGlGeometry.cpp index e940f26..7af492e 100644 --- a/src/lib/gl_engine/tvgGlGeometry.cpp +++ b/src/lib/gl_engine/tvgGlGeometry.cpp @@ -20,11 +20,9 @@ * SOFTWARE. */ +#include #include "tvgGlGpuBuffer.h" #include "tvgGlGeometry.h" -#include "tvgGlCommon.h" - -#include uint32_t GlGeometry::getPrimitiveCount() diff --git a/src/lib/gl_engine/tvgGlGeometry.h b/src/lib/gl_engine/tvgGlGeometry.h index 68dc99d..2fb83f5 100644 --- a/src/lib/gl_engine/tvgGlGeometry.h +++ b/src/lib/gl_engine/tvgGlGeometry.h @@ -23,6 +23,8 @@ #ifndef _TVG_GL_GEOMETRY_H_ #define _TVG_GL_GEOMETRY_H_ +#include +#include #include "tvgGlCommon.h" class GlPoint diff --git a/src/lib/gl_engine/tvgGlGpuBuffer.cpp b/src/lib/gl_engine/tvgGlGpuBuffer.cpp index f402425..9ca680c 100644 --- a/src/lib/gl_engine/tvgGlGpuBuffer.cpp +++ b/src/lib/gl_engine/tvgGlGpuBuffer.cpp @@ -20,10 +20,11 @@ * SOFTWARE. */ -#include "tvgGlCommon.h" #include "tvgGlGpuBuffer.h" -#include +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ GlGpuBuffer::GlGpuBuffer() { diff --git a/src/lib/gl_engine/tvgGlGpuBuffer.h b/src/lib/gl_engine/tvgGlGpuBuffer.h index e3ed97c..bf42941 100644 --- a/src/lib/gl_engine/tvgGlGpuBuffer.h +++ b/src/lib/gl_engine/tvgGlGpuBuffer.h @@ -23,8 +23,7 @@ #ifndef _TVG_GL_GPU_BUFFER_H_ #define _TVG_GL_GPU_BUFFER_H_ -#include -#include +#include "tvgGlCommon.h" class GlGpuBuffer { diff --git a/src/lib/gl_engine/tvgGlProgram.cpp b/src/lib/gl_engine/tvgGlProgram.cpp index 38ed3e1..63ee42b 100644 --- a/src/lib/gl_engine/tvgGlProgram.cpp +++ b/src/lib/gl_engine/tvgGlProgram.cpp @@ -20,15 +20,21 @@ * SOFTWARE. */ -#include "tvgGlCommon.h" +#include #include "tvgGlProgram.h" -#include +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ uint32_t GlProgram::mCurrentProgram = 0; +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + unique_ptr GlProgram::gen(std::shared_ptr shader) { return make_unique(shader); diff --git a/src/lib/gl_engine/tvgGlProgram.h b/src/lib/gl_engine/tvgGlProgram.h index 730274f..173c5cd 100644 --- a/src/lib/gl_engine/tvgGlProgram.h +++ b/src/lib/gl_engine/tvgGlProgram.h @@ -23,10 +23,8 @@ #ifndef _TVG_GL_PROGRAM_H_ #define _TVG_GL_PROGRAM_H_ -#include "tvgGlShader.h" - -#include #include +#include "tvgGlShader.h" class GlProgram { diff --git a/src/lib/gl_engine/tvgGlPropertyInterface.cpp b/src/lib/gl_engine/tvgGlPropertyInterface.cpp index ebb1c57..af011eb 100644 --- a/src/lib/gl_engine/tvgGlPropertyInterface.cpp +++ b/src/lib/gl_engine/tvgGlPropertyInterface.cpp @@ -1,8 +1,38 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + #include "tvgGlPropertyInterface.h" -#include "tvgGlRenderTask.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ VertexProperty PropertyInterface::mEmptyProperty; + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + VertexProperty& PropertyInterface::addProperty(GlRenderTask* rTask, std::shared_ptr prog, std::string name, uint32_t propFormatSize, VertexProperty::PropertyType propType) { std::map* vertexProperty = nullptr; diff --git a/src/lib/gl_engine/tvgGlPropertyInterface.h b/src/lib/gl_engine/tvgGlPropertyInterface.h index c8f309c..6c09e6d 100644 --- a/src/lib/gl_engine/tvgGlPropertyInterface.h +++ b/src/lib/gl_engine/tvgGlPropertyInterface.h @@ -1,12 +1,30 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + #ifndef _TVG_GL_PROPERTY_INTERFACE_H_ #define _TVG_GL_PROPERTY_INTERFACE_H_ -#include "tvgGlRendererProperties.h" #include "tvgGlRenderTask.h" -#include -#include -#include #define ADD_ATTRIBUTE_PROPERTY(var, rtask, prog, varName, formatSize, location) \ var = &PropertyInterface::addProperty(rtask, prog, varName, formatSize, VertexProperty::PropertyType::ATTRIBUTE); \ diff --git a/src/lib/gl_engine/tvgGlRenderTask.cpp b/src/lib/gl_engine/tvgGlRenderTask.cpp index accb957..fc47416 100644 --- a/src/lib/gl_engine/tvgGlRenderTask.cpp +++ b/src/lib/gl_engine/tvgGlRenderTask.cpp @@ -1,12 +1,33 @@ -#include "tvgGlCommon.h" -#include "tvgGlShaderSrc.h" +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + #include "tvgGlRenderTask.h" +#include "tvgGlShaderSrc.h" #include "tvgGlPropertyInterface.h" -#include -#include -#include +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ GlRenderTask::GlRenderTask(RenderTypes renderType, shared_ptr shader) { diff --git a/src/lib/gl_engine/tvgGlRenderTask.h b/src/lib/gl_engine/tvgGlRenderTask.h index d4b28e5..d753bcc 100644 --- a/src/lib/gl_engine/tvgGlRenderTask.h +++ b/src/lib/gl_engine/tvgGlRenderTask.h @@ -1,14 +1,30 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + #ifndef _TVG_GL_RENDER_TASK_H_ #define _TVG_GL_RENDER_TASK_H_ -#include "tvgGlShader.h" -#include "tvgGlProgram.h" #include "tvgGlRendererProperties.h" -#include -#include -#include - #define MAX_GRADIENT_STOPS 4 class GlRenderTask diff --git a/src/lib/gl_engine/tvgGlRenderer.cpp b/src/lib/gl_engine/tvgGlRenderer.cpp index 9e63e24..896a80b 100644 --- a/src/lib/gl_engine/tvgGlRenderer.cpp +++ b/src/lib/gl_engine/tvgGlRenderer.cpp @@ -19,11 +19,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include "tvgGlShaderSrc.h" + +#include "tvgGlRenderer.h" #include "tvgGlGpuBuffer.h" #include "tvgGlGeometry.h" -#include "tvgGlCommon.h" -#include "tvgGlRenderer.h" #include "tvgGlPropertyInterface.h" /************************************************************************/ @@ -32,6 +31,7 @@ static bool initEngine = false; static uint32_t rendererCnt = 0; + static void _termEngine() { if (rendererCnt > 0) return; diff --git a/src/lib/gl_engine/tvgGlRenderer.h b/src/lib/gl_engine/tvgGlRenderer.h index 79addd6..7d63c5a 100644 --- a/src/lib/gl_engine/tvgGlRenderer.h +++ b/src/lib/gl_engine/tvgGlRenderer.h @@ -23,8 +23,6 @@ #ifndef _TVG_GL_RENDERER_H_ #define _TVG_GL_RENDERER_H_ -#include "tvgGlCommon.h" -#include "tvgGlProgram.h" #include "tvgGlRenderTask.h" class GlRenderer : public RenderMethod diff --git a/src/lib/gl_engine/tvgGlRendererProperties.h b/src/lib/gl_engine/tvgGlRendererProperties.h index dd00923..9aa56df 100644 --- a/src/lib/gl_engine/tvgGlRendererProperties.h +++ b/src/lib/gl_engine/tvgGlRendererProperties.h @@ -1,13 +1,31 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + #ifndef _TVG_GL_RENDER_PROPERTIES_H_ #define _TVG_GL_RENDER_PROPERTIES_H_ -#include "tvgGlShader.h" -#include "tvgGlProgram.h" - -#include -#include #include -#include +#include "tvgGlCommon.h" +#include "tvgGlProgram.h" class PropertyValue { diff --git a/src/lib/gl_engine/tvgGlShader.cpp b/src/lib/gl_engine/tvgGlShader.cpp index 9838393..4d94d91 100644 --- a/src/lib/gl_engine/tvgGlShader.cpp +++ b/src/lib/gl_engine/tvgGlShader.cpp @@ -20,11 +20,13 @@ * SOFTWARE. */ -#include "tvgGlCommon.h" +#include #include "tvgGlShader.h" -#include +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ shared_ptr GlShader::gen(const char* vertSrc, const char* fragSrc) { diff --git a/src/lib/gl_engine/tvgGlShader.h b/src/lib/gl_engine/tvgGlShader.h index 60793e1..4cb29b6 100644 --- a/src/lib/gl_engine/tvgGlShader.h +++ b/src/lib/gl_engine/tvgGlShader.h @@ -23,7 +23,7 @@ #ifndef _TVG_GL_SHADER_H_ #define _TVG_GL_SHADER_H_ -#include +#include "tvgGlCommon.h" class GlShader { diff --git a/src/lib/gl_engine/tvgGlShaderSrc.cpp b/src/lib/gl_engine/tvgGlShaderSrc.cpp index 91c31de..63d796e 100644 --- a/src/lib/gl_engine/tvgGlShaderSrc.cpp +++ b/src/lib/gl_engine/tvgGlShaderSrc.cpp @@ -20,9 +20,8 @@ * SOFTWARE. */ -#include "tvgGlShaderSrc.h" - #include +#include "tvgGlShaderSrc.h" #define TVG_COMPOSE_SHADER(shader) #shader -- 2.7.4