Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thorvg: Update to 0.13.5 + hotfix for GCC x86_32 build #92567

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion thirdparty/thorvg/inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
// For internal debugging:
//#define THORVG_LOG_ENABLED

#define THORVG_VERSION_STRING "0.13.3"
#define THORVG_VERSION_STRING "0.13.5"
#endif
32 changes: 31 additions & 1 deletion thirdparty/thorvg/inc/thorvg.h
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,30 @@ class TVG_API Canvas
*/
virtual Result draw() noexcept;

/**
* @brief Sets the drawing region in the canvas.
*
* This function defines the rectangular area of the canvas that will be used for drawing operations.
* The specified viewport is used to clip the rendering output to the boundaries of the rectangle.
*
* @param[in] x The x-coordinate of the upper-left corner of the rectangle.
* @param[in] y The y-coordinate of the upper-left corner of the rectangle.
* @param[in] w The width of the rectangle.
* @param[in] h The height of the rectangle.
*
* @retval Result::Success when succeed, Result::InsufficientCondition otherwise.
*
* @see SwCanvas::target()
* @see GlCanvas::target()
* @see WgCanvas::target()
*
* @warning It's not allowed to change the viewport during Canvas::push() - Canvas::sync() or Canvas::update() - Canvas::sync().
*
* @note When resetting the target, the viewport will also be reset to the target size.
* @note Experimental API
*/
virtual Result viewport(int32_t x, int32_t y, int32_t w, int32_t h) noexcept;

/**
* @brief Guarantees that drawing task is finished.
*
Expand Down Expand Up @@ -1660,7 +1684,9 @@ class TVG_API SwCanvas final : public Canvas
* @retval Result::InvalidArguments In case no valid pointer is provided or the width, or the height or the stride is zero.
* @retval Result::NonSupport In case the software engine is not supported.
*
* @warning Do not access @p buffer during Canvas::draw() - Canvas::sync(). It should not be accessed while TVG is writing on it.
* @warning Do not access @p buffer during Canvas::push() - Canvas::sync(). It should not be accessed while the engine is writing on it.
*
* @see Canvas::viewport()
*/
Result target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, Colorspace cs) noexcept;

Expand Down Expand Up @@ -1726,6 +1752,8 @@ class TVG_API GlCanvas final : public Canvas
* @warning This API is experimental and not officially supported. It may be modified or removed in future versions.
* @warning Drawing on the main surface is currently not permitted. If the identifier (@p id) is set to @c 0, the operation will be aborted.
*
* @see Canvas::viewport()
*
* @note Currently, this only allows the GL_RGBA8 color space format.
* @note Experimental API
*/
Expand Down Expand Up @@ -1764,6 +1792,7 @@ class TVG_API WgCanvas final : public Canvas
* @warning Please do not use it, this API is not official one. It could be modified in the next version.
*
* @note Experimental API
* @see Canvas::viewport()
*/
Result target(void* window, uint32_t w, uint32_t h) noexcept;

Expand Down Expand Up @@ -1856,6 +1885,7 @@ class TVG_API Animation
*
* @note For efficiency, ThorVG ignores updates to the new frame value if the difference from the current frame value
* is less than 0.001. In such cases, it returns @c Result::InsufficientCondition.
* Values less than 0.001 may be disregarded and may not be accurately retained by the Animation.
*
* @see totalFrame()
*
Expand Down
21 changes: 17 additions & 4 deletions thirdparty/thorvg/src/common/tvgMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#define MATH_PI 3.14159265358979323846f
#define MATH_PI2 1.57079632679489661923f
#define FLOAT_EPSILON 1.0e-06f //1.192092896e-07f
#define PATH_KAPPA 0.552284f

#define mathMin(x, y) (((x) < (y)) ? (x) : (y))
Expand Down Expand Up @@ -58,13 +59,19 @@ static inline float mathRad2Deg(float radian)

static inline bool mathZero(float a)
{
return (fabsf(a) < FLT_EPSILON) ? true : false;
return (fabsf(a) <= FLOAT_EPSILON) ? true : false;
}


static inline bool mathZero(const Point& p)
{
return mathZero(p.x) && mathZero(p.y);
}


static inline bool mathEqual(float a, float b)
{
return (fabsf(a - b) < FLT_EPSILON);
return mathZero(a - b);
}


Expand All @@ -82,14 +89,14 @@ static inline bool mathEqual(const Matrix& a, const Matrix& b)
static inline bool mathRightAngle(const Matrix* m)
{
auto radian = fabsf(atan2f(m->e21, m->e11));
if (radian < FLT_EPSILON || mathEqual(radian, MATH_PI2) || mathEqual(radian, MATH_PI)) return true;
if (radian < FLOAT_EPSILON || mathEqual(radian, MATH_PI2) || mathEqual(radian, MATH_PI)) return true;
return false;
}


static inline bool mathSkewed(const Matrix* m)
{
return (fabsf(m->e21 + m->e12) > FLT_EPSILON);
return !mathZero(m->e21 + m->e12);
}


Expand Down Expand Up @@ -169,6 +176,12 @@ static inline float mathLength(const Point* a, const Point* b)
}


static inline float mathLength(const Point& a)
{
return sqrtf(a.x * a.x + a.y * a.y);
}


static inline Point operator-(const Point& lhs, const Point& rhs)
{
return {lhs.x - rhs.x, lhs.y - rhs.y};
Expand Down
10 changes: 5 additions & 5 deletions thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ static bool _toColor(const char* str, uint8_t* r, uint8_t* g, uint8_t* b, char**
*ref = _idFromUrl((const char*)(str + 3));
return true;
} else if (len >= 10 && (str[0] == 'h' || str[0] == 'H') && (str[1] == 's' || str[1] == 'S') && (str[2] == 'l' || str[2] == 'L') && str[3] == '(' && str[len - 1] == ')') {
float_t th, ts, tb;
float th, ts, tb;
const char *content, *hue, *satuation, *brightness;
content = str + 4;
content = _skipSpace(content, nullptr);
Expand Down Expand Up @@ -988,7 +988,7 @@ static bool _attrParseSvgNode(void* data, const char* key, const char* value)
} else if (!strcmp(key, "style")) {
return simpleXmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader);
#ifdef THORVG_LOG_ENABLED
} else if ((!strcmp(key, "x") || !strcmp(key, "y")) && fabsf(strToFloat(value, nullptr)) > FLT_EPSILON) {
} else if ((!strcmp(key, "x") || !strcmp(key, "y")) && fabsf(strToFloat(value, nullptr)) > FLOAT_EPSILON) {
TVGLOG("SVG", "Unsupported attributes used [Elements type: Svg][Attribute: %s][Value: %s]", key, value);
#endif
} else {
Expand Down Expand Up @@ -1824,8 +1824,8 @@ static bool _attrParseRectNode(void* data, const char* key, const char* value)
if (!strncmp(rectTags[i].tag, "rx", sz)) rect->hasRx = true;
if (!strncmp(rectTags[i].tag, "ry", sz)) rect->hasRy = true;

if ((rect->rx >= FLT_EPSILON) && (rect->ry < FLT_EPSILON) && rect->hasRx && !rect->hasRy) rect->ry = rect->rx;
if ((rect->ry >= FLT_EPSILON) && (rect->rx < FLT_EPSILON) && !rect->hasRx && rect->hasRy) rect->rx = rect->ry;
if ((rect->rx >= FLOAT_EPSILON) && (rect->ry < FLOAT_EPSILON) && rect->hasRx && !rect->hasRy) rect->ry = rect->rx;
if ((rect->ry >= FLOAT_EPSILON) && (rect->rx < FLOAT_EPSILON) && !rect->hasRx && rect->hasRy) rect->rx = rect->ry;
return ret;
}
}
Expand Down Expand Up @@ -3708,7 +3708,7 @@ SvgLoader::~SvgLoader()
void SvgLoader::run(unsigned tid)
{
//According to the SVG standard the value of the width/height of the viewbox set to 0 disables rendering
if ((viewFlag & SvgViewFlag::Viewbox) && (fabsf(vw) <= FLT_EPSILON || fabsf(vh) <= FLT_EPSILON)) {
if ((viewFlag & SvgViewFlag::Viewbox) && (fabsf(vw) <= FLOAT_EPSILON || fabsf(vh) <= FLOAT_EPSILON)) {
TVGLOG("SVG", "The <viewBox> width and/or height set to 0 - rendering disabled.");
root = Scene::gen().release();
return;
Expand Down
6 changes: 3 additions & 3 deletions thirdparty/thorvg/src/loaders/svg/tvgXmlParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

#include "tvgSvgLoaderCommon.h"

#define NUMBER_OF_XML_ENTITIES 8
const char* const xmlEntity[] = {"&quot;", "&nbsp;", "&apos;", "&amp;", "&lt;", "&gt;", "&#035;", "&#039;"};
const int xmlEntityLength[] = {6, 6, 6, 5, 4, 4, 6, 6};
#define NUMBER_OF_XML_ENTITIES 9
const char* const xmlEntity[] = {"&#10;", "&quot;", "&nbsp;", "&apos;", "&amp;", "&lt;", "&gt;", "&#035;", "&#039;"};
const int xmlEntityLength[] = {5, 6, 6, 6, 5, 4, 4, 6, 6};

enum class SimpleXMLType
{
Expand Down
4 changes: 2 additions & 2 deletions thirdparty/thorvg/src/renderer/sw_engine/tvgSwFill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ bool _prepareLinear(SwFill* fill, const LinearGradient* linear, const Matrix* tr
fill->linear.dy = y2 - y1;
fill->linear.len = fill->linear.dx * fill->linear.dx + fill->linear.dy * fill->linear.dy;

if (fill->linear.len < FLT_EPSILON) return true;
if (fill->linear.len < FLOAT_EPSILON) return true;

fill->linear.dx /= fill->linear.len;
fill->linear.dy /= fill->linear.len;
Expand Down Expand Up @@ -182,7 +182,7 @@ bool _prepareRadial(SwFill* fill, const RadialGradient* radial, const Matrix* tr
auto fy = P(radial)->fy;
auto fr = P(radial)->fr;

if (r < FLT_EPSILON) return true;
if (r < FLOAT_EPSILON) return true;

fill->radial.dr = r - fr;
fill->radial.dx = cx - fx;
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/thorvg/src/renderer/sw_engine/tvgSwRaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,7 @@ static bool _rasterSolidGradientRect(SwSurface* surface, const SwBBox& region, c

static bool _rasterLinearGradientRect(SwSurface* surface, const SwBBox& region, const SwFill* fill)
{
if (fill->linear.len < FLT_EPSILON) return false;
if (fill->linear.len < FLOAT_EPSILON) return false;

if (_compositing(surface)) {
if (_matting(surface)) return _rasterGradientMattedRect<FillLinear>(surface, region, fill);
Expand Down
10 changes: 6 additions & 4 deletions thirdparty/thorvg/src/renderer/sw_engine/tvgSwRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,6 @@ bool SwRenderer::target(pixel_t* data, uint32_t stride, uint32_t w, uint32_t h,
surface->channelSize = CHANNEL_SIZE(cs);
surface->premultiplied = true;

vport.x = vport.y = 0;
vport.w = surface->w;
vport.h = surface->h;

return rasterCompositor(surface);
}

Expand Down Expand Up @@ -607,6 +603,12 @@ bool SwRenderer::mempool(bool shared)
}


const Surface* SwRenderer::mainSurface()
{
return surface;
}


Compositor* SwRenderer::target(const RenderRegion& region, ColorSpace cs)
{
auto x = region.x;
Expand Down
1 change: 1 addition & 0 deletions thirdparty/thorvg/src/renderer/sw_engine/tvgSwRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class SwRenderer : public RenderMethod
bool viewport(const RenderRegion& vp) override;
bool blend(BlendMethod method) override;
ColorSpace colorSpace() override;
const Surface* mainSurface() override;

bool clear() override;
bool sync() override;
Expand Down
4 changes: 2 additions & 2 deletions thirdparty/thorvg/src/renderer/sw_engine/tvgSwShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static void _dashLineTo(SwDashStroke& dash, const Point* to, const Matrix* trans
len -= dash.curLen;
lineSplitAt(cur, dash.curLen, left, right);
if (!dash.curOpGap) {
if (dash.move || dash.pattern[dash.curIdx] - dash.curLen < FLT_EPSILON) {
if (dash.move || dash.pattern[dash.curIdx] - dash.curLen < FLOAT_EPSILON) {
_outlineMoveTo(*dash.outline, &left.pt1, transform);
dash.move = false;
}
Expand Down Expand Up @@ -185,7 +185,7 @@ static void _dashCubicTo(SwDashStroke& dash, const Point* ctrl1, const Point* ct
len -= dash.curLen;
bezSplitAt(cur, dash.curLen, left, right);
if (!dash.curOpGap) {
if (dash.move || dash.pattern[dash.curIdx] - dash.curLen < FLT_EPSILON) {
if (dash.move || dash.pattern[dash.curIdx] - dash.curLen < FLOAT_EPSILON) {
_outlineMoveTo(*dash.outline, &left.start, transform);
dash.move = false;
}
Expand Down
6 changes: 6 additions & 0 deletions thirdparty/thorvg/src/renderer/tvgCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ Result Canvas::update(Paint* paint) noexcept
}


Result Canvas::viewport(int32_t x, int32_t y, int32_t w, int32_t h) noexcept
{
return pImpl->viewport(x, y, w, h);
}


Result Canvas::sync() noexcept
{
return pImpl->sync();
Expand Down
48 changes: 33 additions & 15 deletions thirdparty/thorvg/src/renderer/tvgCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@

struct Canvas::Impl
{
enum Status : uint8_t {Synced = 0, Updating, Drawing};

list<Paint*> paints;
RenderMethod* renderer;
RenderRegion vport = {0, 0, INT32_MAX, INT32_MAX};
Status status = Status::Synced;

bool refresh = false; //if all paints should be updated by force.
bool drawing = false; //on drawing condition?

Impl(RenderMethod* pRenderer) : renderer(pRenderer)
{
Expand All @@ -41,14 +45,12 @@ struct Canvas::Impl
~Impl()
{
//make it sure any deffered jobs
if (renderer) {
renderer->sync();
renderer->clear();
}
renderer->sync();
renderer->clear();

clearPaints();

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

void clearPaints()
Expand All @@ -62,7 +64,7 @@ struct Canvas::Impl
Result push(unique_ptr<Paint> paint)
{
//You can not push paints during rendering.
if (drawing) return Result::InsufficientCondition;
if (status == Status::Drawing) return Result::InsufficientCondition;

auto p = paint.release();
if (!p) return Result::MemoryCorruption;
Expand All @@ -75,12 +77,12 @@ struct Canvas::Impl
Result clear(bool free)
{
//Clear render target before drawing
if (!renderer || !renderer->clear()) return Result::InsufficientCondition;
if (!renderer->clear()) return Result::InsufficientCondition;

//Free paints
if (free) clearPaints();

drawing = false;
status = Status::Synced;

return Result::Success;
}
Expand All @@ -92,7 +94,7 @@ struct Canvas::Impl

Result update(Paint* paint, bool force)
{
if (paints.empty() || drawing || !renderer) return Result::InsufficientCondition;
if (paints.empty() || status == Status::Drawing) return Result::InsufficientCondition;

Array<RenderData> clips;
auto flag = RenderUpdateFlag::None;
Expand All @@ -106,12 +108,13 @@ struct Canvas::Impl
}
refresh = false;
}
status = Status::Updating;
return Result::Success;
}

Result draw()
{
if (drawing || paints.empty() || !renderer || !renderer->preRender()) return Result::InsufficientCondition;
if (status == Status::Drawing || paints.empty() || !renderer->preRender()) return Result::InsufficientCondition;

bool rendered = false;
for (auto paint : paints) {
Expand All @@ -120,22 +123,37 @@ struct Canvas::Impl

if (!rendered || !renderer->postRender()) return Result::InsufficientCondition;

drawing = true;

status = Status::Drawing;
return Result::Success;
}

Result sync()
{
if (!drawing) return Result::InsufficientCondition;
if (status == Status::Synced) return Result::InsufficientCondition;

if (renderer->sync()) {
drawing = false;
status = Status::Synced;
return Result::Success;
}

return Result::InsufficientCondition;
}

Result viewport(int32_t x, int32_t y, int32_t w, int32_t h)
{
if (status != Status::Synced) return Result::InsufficientCondition;
RenderRegion val = {x, y, w, h};
//intersect if the target buffer is already set.
auto surface = renderer->mainSurface();
if (surface && surface->w > 0 && surface->h > 0) {
val.intersect({0, 0, (int32_t)surface->w, (int32_t)surface->h});
}
if (vport == val) return Result::Success;
renderer->viewport(val);
vport = val;
needRefresh();
return Result::Success;
}
};

#endif /* _TVG_CANVAS_H_ */
Loading
Loading