Skip to content

Commit

Permalink
ThorVG: update from v0.12.3 to v0.12.4
Browse files Browse the repository at this point in the history
https://github.com/thorvg/thorvg/releases/tag/v0.12.4

+ Full Changelog:
  thorvg/thorvg@v0.12.3...v0.12.4

Godot-related SVG bug fixes:

+ loader/svg: Apply specification of out-of-range elliptical arc parameters,
  fix zero check of arc's rx and ry.
    thorvg/thorvg#1938
  • Loading branch information
capnm committed Feb 2, 2024
1 parent 10e1114 commit da42124
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 142 deletions.
2 changes: 1 addition & 1 deletion thirdparty/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ instead of `miniz.h` as an external dependency.
## thorvg

- Upstream: https://github.com/thorvg/thorvg
- Version: 0.12.3 (9d79f0ccef632fd3b43b8ea02def529b6a8d2288, 2024)
- Version: 0.12.4 (331839d49368e19ca15f35abee5ac541dbf23637, 2024)
- License: MIT

Files extracted from upstream source:
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/thorvg/inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
// For internal debugging:
//#define THORVG_LOG_ENABLED

#define THORVG_VERSION_STRING "0.12.3"
#define THORVG_VERSION_STRING "0.12.4"
#endif
15 changes: 11 additions & 4 deletions thirdparty/thorvg/src/loaders/svg/tvgSvgPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
#define _USE_MATH_DEFINES //Math Constants are not defined in Standard C/C++.

#include <cstring>
#include <math.h>
#include <ctype.h>
#include "tvgMath.h"
#include "tvgShape.h"
#include "tvgSvgLoaderCommon.h"
#include "tvgSvgPath.h"
Expand Down Expand Up @@ -471,9 +471,16 @@ static bool _processCommand(Array<PathCommand>* cmds, Array<Point>* pts, char cm
}
case 'a':
case 'A': {
_pathAppendArcTo(cmds, pts, cur, curCtl, arr[5], arr[6], arr[0], arr[1], arr[2], arr[3], arr[4]);
*cur = *curCtl = {arr[5], arr[6]};
*isQuadratic = false;
if (mathZero(arr[0]) || mathZero(arr[1])) {
Point p = {arr[5], arr[6]};
cmds->push(PathCommand::LineTo);
pts->push(p);
*cur = {arr[5], arr[6]};
} else if (!mathEqual(cur->x, arr[5]) || !mathEqual(cur->y, arr[6])) {
_pathAppendArcTo(cmds, pts, cur, curCtl, arr[5], arr[6], fabsf(arr[0]), fabsf(arr[1]), arr[2], arr[3], arr[4]);
*cur = *curCtl = {arr[5], arr[6]};
*isQuadratic = false;
}
break;
}
default: {
Expand Down
17 changes: 6 additions & 11 deletions thirdparty/thorvg/src/renderer/sw_engine/tvgSwRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct SwTask : Task
return region;
}

virtual bool dispose() = 0;
virtual void dispose() = 0;
virtual bool clip(SwRleData* target) = 0;
virtual SwRleData* rle() = 0;

Expand Down Expand Up @@ -196,10 +196,9 @@ struct SwShapeTask : SwTask
shapeDelOutline(&shape, mpool, tid);
}

bool dispose() override
void dispose() override
{
shapeFree(&shape);
return true;
}
};

Expand Down Expand Up @@ -250,10 +249,9 @@ struct SwSceneTask : SwTask
}
}

bool dispose() override
void dispose() override
{
rleFree(sceneRle);
return true;
}
};

Expand Down Expand Up @@ -318,10 +316,9 @@ struct SwImageTask : SwTask
imageDelOutline(&image, mpool, tid);
}

bool dispose() override
void dispose() override
{
imageFree(&image);
return true;
}
};

Expand Down Expand Up @@ -703,17 +700,15 @@ ColorSpace SwRenderer::colorSpace()
}


bool SwRenderer::dispose(RenderData data)
void SwRenderer::dispose(RenderData data)
{
auto task = static_cast<SwTask*>(data);
if (!task) return true;
if (!task) return;
task->done();
task->dispose();

if (task->pushed) task->disposed = true;
else delete(task);

return true;
}


Expand Down
2 changes: 1 addition & 1 deletion thirdparty/thorvg/src/renderer/sw_engine/tvgSwRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SwRenderer : public RenderMethod
bool renderShape(RenderData data) override;
bool renderImage(RenderData data) override;
bool postRender() override;
bool dispose(RenderData data) override;
void dispose(RenderData data) override;
RenderRegion region(RenderData data) override;
RenderRegion viewport() override;
bool viewport(const RenderRegion& vp) override;
Expand Down
8 changes: 6 additions & 2 deletions thirdparty/thorvg/src/renderer/sw_engine/tvgSwShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ static void _dashLineTo(SwDashStroke& dash, const Point* to, const Matrix* trans
Line cur = {dash.ptCur, *to};
auto len = _lineLength(cur.pt1, cur.pt2);

if (len < dash.curLen) {
if (mathZero(len)) {
_outlineMoveTo(*dash.outline, &dash.ptCur, transform);
} else if (len < dash.curLen) {
dash.curLen -= len;
if (!dash.curOpGap) {
if (dash.move) {
Expand Down Expand Up @@ -179,7 +181,9 @@ static void _dashCubicTo(SwDashStroke& dash, const Point* ctrl1, const Point* ct
Bezier cur = {dash.ptCur, *ctrl1, *ctrl2, *to};
auto len = bezLength(cur);

if (len < dash.curLen) {
if (mathZero(len)) {
_outlineMoveTo(*dash.outline, &dash.ptCur, transform);
} else if (len < dash.curLen) {
dash.curLen -= len;
if (!dash.curOpGap) {
if (dash.move) {
Expand Down
39 changes: 24 additions & 15 deletions thirdparty/thorvg/src/renderer/tvgCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,30 @@ struct Canvas::Impl
bool refresh = false; //if all paints should be updated by force.
bool drawing = false; //on drawing condition?

Impl(RenderMethod* pRenderer):renderer(pRenderer)
Impl(RenderMethod* pRenderer) : renderer(pRenderer)
{
renderer->ref();
}

~Impl()
{
clear(true);
delete(renderer);
//make it sure any deffered jobs
if (renderer) {
renderer->sync();
renderer->clear();
}

clearPaints();

if (renderer && (renderer->unref() == 0)) delete(renderer);
}

void clearPaints()
{
for (auto paint : paints) {
if (P(paint)->unref() == 0) delete(paint);
}
paints.clear();
}

Result push(unique_ptr<Paint> paint)
Expand All @@ -62,15 +78,8 @@ struct Canvas::Impl
if (!renderer || !renderer->clear()) return Result::InsufficientCondition;

//Free paints
if (free) {
for (auto paint : paints) {
P(paint)->unref();
if (paint->pImpl->dispose(*renderer) && P(paint)->refCnt == 0) {
delete(paint);
}
}
paints.clear();
}
if (free) clearPaints();

drawing = false;

return Result::Success;
Expand All @@ -94,15 +103,15 @@ struct Canvas::Impl
//Optimize Me: Can we skip the searching?
for (auto paint2 : paints) {
if (paint2 == paint) {
paint->pImpl->update(*renderer, nullptr, clips, 255, flag);
paint->pImpl->update(renderer, nullptr, clips, 255, flag);
return Result::Success;
}
}
return Result::InvalidArguments;
//Update all retained paint nodes
} else {
for (auto paint : paints) {
paint->pImpl->update(*renderer, nullptr, clips, 255, flag);
paint->pImpl->update(renderer, nullptr, clips, 255, flag);
}
}

Expand All @@ -117,7 +126,7 @@ struct Canvas::Impl

bool rendered = false;
for (auto paint : paints) {
if (paint->pImpl->render(*renderer)) rendered = true;
if (paint->pImpl->render(renderer)) rendered = true;
}

if (!rendered || !renderer->postRender()) return Result::InsufficientCondition;
Expand Down
38 changes: 17 additions & 21 deletions thirdparty/thorvg/src/renderer/tvgPaint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,14 @@ static bool _compFastTrack(Paint* cmpTarget, const RenderTransform* pTransform,
}


RenderRegion Paint::Impl::bounds(RenderMethod& renderer) const
RenderRegion Paint::Impl::bounds(RenderMethod* renderer) const
{
RenderRegion ret;
PAINT_METHOD(ret, bounds(renderer));
return ret;
}


bool Paint::Impl::dispose(RenderMethod& renderer)
{
if (compData) compData->target->pImpl->dispose(renderer);

bool ret;
PAINT_METHOD(ret, dispose(renderer));
return ret;
}


Iterator* Paint::Impl::iterator()
{
Iterator* ret;
Expand Down Expand Up @@ -198,7 +188,7 @@ bool Paint::Impl::translate(float x, float y)
}


bool Paint::Impl::render(RenderMethod& renderer)
bool Paint::Impl::render(RenderMethod* renderer)
{
Compositor* cmp = nullptr;

Expand All @@ -210,27 +200,33 @@ bool Paint::Impl::render(RenderMethod& renderer)

if (MASK_REGION_MERGING(compData->method)) region.add(P(compData->target)->bounds(renderer));
if (region.w == 0 || region.h == 0) return true;
cmp = renderer.target(region, COMPOSITE_TO_COLORSPACE(renderer, compData->method));
if (renderer.beginComposite(cmp, CompositeMethod::None, 255)) {
cmp = renderer->target(region, COMPOSITE_TO_COLORSPACE(renderer, compData->method));
if (renderer->beginComposite(cmp, CompositeMethod::None, 255)) {
compData->target->pImpl->render(renderer);
}
}

if (cmp) renderer.beginComposite(cmp, compData->method, compData->target->pImpl->opacity);
if (cmp) renderer->beginComposite(cmp, compData->method, compData->target->pImpl->opacity);

renderer.blend(blendMethod);
renderer->blend(blendMethod);

bool ret;
PAINT_METHOD(ret, render(renderer));

if (cmp) renderer.endComposite(cmp);
if (cmp) renderer->endComposite(cmp);

return ret;
}


RenderData Paint::Impl::update(RenderMethod& renderer, const RenderTransform* pTransform, Array<RenderData>& clips, uint8_t opacity, RenderUpdateFlag pFlag, bool clipper)
RenderData Paint::Impl::update(RenderMethod* renderer, const RenderTransform* pTransform, Array<RenderData>& clips, uint8_t opacity, RenderUpdateFlag pFlag, bool clipper)
{
if (this->renderer != renderer) {
if (this->renderer) TVGERR("RENDERER", "paint's renderer has been changed!");
renderer->ref();
this->renderer = renderer;
}

if (renderFlag & RenderUpdateFlag::Transform) {
if (!rTransform) return nullptr;
rTransform->update();
Expand Down Expand Up @@ -265,9 +261,9 @@ RenderData Paint::Impl::update(RenderMethod& renderer, const RenderTransform* pT
if (tryFastTrack) {
RenderRegion viewport2;
if ((compFastTrack = _compFastTrack(target, pTransform, target->pImpl->rTransform, viewport2))) {
viewport = renderer.viewport();
viewport = renderer->viewport();
viewport2.intersect(viewport);
renderer.viewport(viewport2);
renderer->viewport(viewport2);
target->pImpl->ctxFlag |= ContextFlag::FastTrack;
}
}
Expand All @@ -289,7 +285,7 @@ RenderData Paint::Impl::update(RenderMethod& renderer, const RenderTransform* pT
PAINT_METHOD(rd, update(renderer, &outTransform, clips, opacity, newFlag, clipper));

/* 3. Composition Post Processing */
if (compFastTrack) renderer.viewport(viewport);
if (compFastTrack) renderer->viewport(viewport);
else if (childClipper) clips.pop();

return rd;
Expand Down
21 changes: 10 additions & 11 deletions thirdparty/thorvg/src/renderer/tvgPaint.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,15 @@ namespace tvg
Paint* paint = nullptr;
RenderTransform* rTransform = nullptr;
Composite* compData = nullptr;
BlendMethod blendMethod = BlendMethod::Normal; //uint8_t
RenderMethod* renderer = nullptr;
BlendMethod blendMethod = BlendMethod::Normal; //uint8_t
uint8_t renderFlag = RenderUpdateFlag::None;
uint8_t ctxFlag = ContextFlag::Invalid;
uint8_t id;
uint8_t opacity = 255;
uint8_t refCnt = 0;
uint8_t refCnt = 0; //reference count

Impl(Paint* pnt) : paint(pnt)
{
}
Impl(Paint* pnt) : paint(pnt) {}

~Impl()
{
Expand All @@ -68,18 +67,19 @@ namespace tvg
free(compData);
}
delete(rTransform);
if (renderer && (renderer->unref() == 0)) delete(renderer);
}

uint8_t ref()
{
if (refCnt == 255) TVGERR("RENDERER", "Corrupted reference count!");
return (++refCnt);
return ++refCnt;
}

uint8_t unref()
{
if (refCnt == 0) TVGERR("RENDERER", "Corrupted reference count!");
return (--refCnt);
return --refCnt;
}

bool transform(const Matrix& m)
Expand Down Expand Up @@ -131,15 +131,14 @@ namespace tvg
return true;
}

RenderRegion bounds(RenderMethod& renderer) const;
bool dispose(RenderMethod& renderer);
RenderRegion bounds(RenderMethod* renderer) const;
Iterator* iterator();
bool rotate(float degree);
bool scale(float factor);
bool translate(float x, float y);
bool bounds(float* x, float* y, float* w, float* h, bool transformed, bool stroking);
RenderData update(RenderMethod& renderer, const RenderTransform* pTransform, Array<RenderData>& clips, uint8_t opacity, RenderUpdateFlag pFlag, bool clipper = false);
bool render(RenderMethod& renderer);
RenderData update(RenderMethod* renderer, const RenderTransform* pTransform, Array<RenderData>& clips, uint8_t opacity, RenderUpdateFlag pFlag, bool clipper = false);
bool render(RenderMethod* renderer);
Paint* duplicate();
};
}
Expand Down
Loading

0 comments on commit da42124

Please sign in to comment.