diff options
author | Martin Capitanio <capnm@capitanio.org> | 2023-09-29 14:58:36 +0200 |
---|---|---|
committer | Martin Capitanio <capnm@capitanio.org> | 2023-09-29 19:50:19 +0200 |
commit | aab650f2ef97915e22312e5da543e01989bbfd76 (patch) | |
tree | 847d2e5c6033ab1d06122c57beefa6dc6c019aad /thirdparty/thorvg/src | |
parent | 19890614c6a78ec36030ce65c7da05f07fcdb9ed (diff) | |
download | redot-engine-aab650f2ef97915e22312e5da543e01989bbfd76.tar.gz |
ThorVG: update to v0.11.0 release.
See https://github.com/thorvg/thorvg/releases/tag/v0.11.0
+ Infrastructure
Repository folder structure was make it more intuitive and coherent.
"thorvg/src/lib" -> "thorvg/src/common"
(providing essential common functionalities
used internally among the renderer and sub-modules)
"thorvg/src/lib" -> "thorvg/src/renderer"
(for vector drawing features)
+ SVG related
Fix stroke regression https://github.com/thorvg/thorvg/issues/1670
Support stroke dash offset function https://github.com/thorvg/thorvg/issues/1591#issuecomment-1681319321
Support Focal property in Radial Gradient https://github.com/thorvg/thorvg/issues/1558
Diffstat (limited to 'thirdparty/thorvg/src')
-rw-r--r-- | thirdparty/thorvg/src/common/tvgArray.h (renamed from thirdparty/thorvg/src/utils/tvgArray.h) | 33 | ||||
-rw-r--r-- | thirdparty/thorvg/src/common/tvgBezier.cpp (renamed from thirdparty/thorvg/src/utils/tvgBezier.cpp) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/common/tvgBezier.h (renamed from thirdparty/thorvg/src/utils/tvgBezier.h) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/common/tvgCompressor.cpp (renamed from thirdparty/thorvg/src/utils/tvgCompressor.cpp) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/common/tvgCompressor.h (renamed from thirdparty/thorvg/src/utils/tvgCompressor.h) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/common/tvgList.h | 90 | ||||
-rw-r--r-- | thirdparty/thorvg/src/common/tvgMath.cpp | 102 | ||||
-rw-r--r-- | thirdparty/thorvg/src/common/tvgMath.h (renamed from thirdparty/thorvg/src/utils/tvgMath.h) | 84 | ||||
-rw-r--r-- | thirdparty/thorvg/src/common/tvgStr.cpp (renamed from thirdparty/thorvg/src/utils/tvgStr.cpp) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/common/tvgStr.h (renamed from thirdparty/thorvg/src/utils/tvgStr.h) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.cpp | 65 | ||||
-rw-r--r-- | thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.h | 2 | ||||
-rw-r--r-- | thirdparty/thorvg/src/loaders/svg/tvgSvgLoaderCommon.h | 1 | ||||
-rw-r--r-- | thirdparty/thorvg/src/loaders/svg/tvgSvgSceneBuilder.cpp | 107 | ||||
-rw-r--r-- | thirdparty/thorvg/src/loaders/svg/tvgSvgUtil.cpp | 21 | ||||
-rw-r--r-- | thirdparty/thorvg/src/loaders/svg/tvgSvgUtil.h | 2 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/sw_engine/tvgSwCommon.h (renamed from thirdparty/thorvg/src/lib/sw_engine/tvgSwCommon.h) | 3 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/sw_engine/tvgSwFill.cpp (renamed from thirdparty/thorvg/src/lib/sw_engine/tvgSwFill.cpp) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/sw_engine/tvgSwImage.cpp (renamed from thirdparty/thorvg/src/lib/sw_engine/tvgSwImage.cpp) | 2 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/sw_engine/tvgSwMath.cpp (renamed from thirdparty/thorvg/src/lib/sw_engine/tvgSwMath.cpp) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/sw_engine/tvgSwMemPool.cpp (renamed from thirdparty/thorvg/src/lib/sw_engine/tvgSwMemPool.cpp) | 75 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/sw_engine/tvgSwRaster.cpp (renamed from thirdparty/thorvg/src/lib/sw_engine/tvgSwRaster.cpp) | 4 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterAvx.h (renamed from thirdparty/thorvg/src/lib/sw_engine/tvgSwRasterAvx.h) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterC.h (renamed from thirdparty/thorvg/src/lib/sw_engine/tvgSwRasterC.h) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterNeon.h (renamed from thirdparty/thorvg/src/lib/sw_engine/tvgSwRasterNeon.h) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterTexmap.h (renamed from thirdparty/thorvg/src/lib/sw_engine/tvgSwRasterTexmap.h) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/sw_engine/tvgSwRenderer.cpp (renamed from thirdparty/thorvg/src/lib/sw_engine/tvgSwRenderer.cpp) | 12 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/sw_engine/tvgSwRenderer.h (renamed from thirdparty/thorvg/src/lib/sw_engine/tvgSwRenderer.h) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/sw_engine/tvgSwRle.cpp (renamed from thirdparty/thorvg/src/lib/sw_engine/tvgSwRle.cpp) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/sw_engine/tvgSwShape.cpp (renamed from thirdparty/thorvg/src/lib/sw_engine/tvgSwShape.cpp) | 27 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/sw_engine/tvgSwStroke.cpp (renamed from thirdparty/thorvg/src/lib/sw_engine/tvgSwStroke.cpp) | 4 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgAccessor.cpp (renamed from thirdparty/thorvg/src/lib/tvgAccessor.cpp) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgAnimation.cpp (renamed from thirdparty/thorvg/src/lib/tvgAnimation.cpp) | 7 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgBinaryDesc.h (renamed from thirdparty/thorvg/src/lib/tvgBinaryDesc.h) | 5 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgCanvas.cpp (renamed from thirdparty/thorvg/src/lib/tvgCanvas.cpp) | 2 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgCanvas.h (renamed from thirdparty/thorvg/src/lib/tvgCanvasImpl.h) | 16 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgCommon.h (renamed from thirdparty/thorvg/src/lib/tvgCommon.h) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgFill.cpp (renamed from thirdparty/thorvg/src/lib/tvgFill.cpp) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgFill.h (renamed from thirdparty/thorvg/src/lib/tvgFill.h) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgFrameModule.h (renamed from thirdparty/thorvg/src/lib/tvgFrameModule.h) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgGlCanvas.cpp (renamed from thirdparty/thorvg/src/lib/tvgGlCanvas.cpp) | 2 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgInitializer.cpp (renamed from thirdparty/thorvg/src/lib/tvgInitializer.cpp) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgIteratorAccessor.h (renamed from thirdparty/thorvg/src/lib/tvgIteratorAccessor.h) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgLoadModule.h (renamed from thirdparty/thorvg/src/lib/tvgLoadModule.h) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgLoader.cpp (renamed from thirdparty/thorvg/src/lib/tvgLoader.cpp) | 2 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgLoader.h (renamed from thirdparty/thorvg/src/lib/tvgLoader.h) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgPaint.cpp (renamed from thirdparty/thorvg/src/lib/tvgPaint.cpp) | 2 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgPaint.h (renamed from thirdparty/thorvg/src/lib/tvgPaint.h) | 5 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgPicture.cpp (renamed from thirdparty/thorvg/src/lib/tvgPicture.cpp) | 52 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgPicture.h (renamed from thirdparty/thorvg/src/lib/tvgPictureImpl.h) | 47 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgRender.cpp (renamed from thirdparty/thorvg/src/lib/tvgRender.cpp) | 7 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgRender.h (renamed from thirdparty/thorvg/src/lib/tvgRender.h) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgSaveModule.h (renamed from thirdparty/thorvg/src/lib/tvgSaveModule.h) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgSaver.cpp (renamed from thirdparty/thorvg/src/lib/tvgSaver.cpp) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgScene.cpp (renamed from thirdparty/thorvg/src/lib/tvgScene.cpp) | 3 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgScene.h (renamed from thirdparty/thorvg/src/lib/tvgSceneImpl.h) | 8 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgShape.cpp (renamed from thirdparty/thorvg/src/lib/tvgShape.cpp) | 2 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgShape.h (renamed from thirdparty/thorvg/src/lib/tvgShapeImpl.h) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgSwCanvas.cpp (renamed from thirdparty/thorvg/src/lib/tvgSwCanvas.cpp) | 2 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgTaskScheduler.cpp (renamed from thirdparty/thorvg/src/lib/tvgTaskScheduler.cpp) | 0 | ||||
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgTaskScheduler.h (renamed from thirdparty/thorvg/src/lib/tvgTaskScheduler.h) | 0 |
61 files changed, 467 insertions, 329 deletions
diff --git a/thirdparty/thorvg/src/utils/tvgArray.h b/thirdparty/thorvg/src/common/tvgArray.h index 919da7e108..08eb25329c 100644 --- a/thirdparty/thorvg/src/utils/tvgArray.h +++ b/thirdparty/thorvg/src/common/tvgArray.h @@ -24,6 +24,7 @@ #define _TVG_ARRAY_H_ #include <memory.h> +#include <cstdint> namespace tvg { @@ -135,6 +136,12 @@ struct Array return count == 0; } + template<class COMPARE> + void sort() + { + qsort<COMPARE>(data, 0, static_cast<int32_t>(count) - 1); + } + void operator=(const Array& rhs) { reserve(rhs.count); @@ -146,6 +153,32 @@ struct Array { free(data); } + +private: + template<class COMPARE> + void qsort(T* arr, int32_t low, int32_t high) + { + if (low < high) { + int32_t i = low; + int32_t j = high; + T tmp = arr[low]; + while (i < j) { + while (i < j && !COMPARE{}(arr[j], tmp)) --j; + if (i < j) { + arr[i] = arr[j]; + ++i; + } + while (i < j && COMPARE{}(arr[i], tmp)) ++i; + if (i < j) { + arr[j] = arr[i]; + --j; + } + } + arr[i] = tmp; + qsort<COMPARE>(arr, low, i - 1); + qsort<COMPARE>(arr, i + 1, high); + } + } }; } diff --git a/thirdparty/thorvg/src/utils/tvgBezier.cpp b/thirdparty/thorvg/src/common/tvgBezier.cpp index f9daf07b84..f9daf07b84 100644 --- a/thirdparty/thorvg/src/utils/tvgBezier.cpp +++ b/thirdparty/thorvg/src/common/tvgBezier.cpp diff --git a/thirdparty/thorvg/src/utils/tvgBezier.h b/thirdparty/thorvg/src/common/tvgBezier.h index 539a63bdd3..539a63bdd3 100644 --- a/thirdparty/thorvg/src/utils/tvgBezier.h +++ b/thirdparty/thorvg/src/common/tvgBezier.h diff --git a/thirdparty/thorvg/src/utils/tvgCompressor.cpp b/thirdparty/thorvg/src/common/tvgCompressor.cpp index e38940f3d0..e38940f3d0 100644 --- a/thirdparty/thorvg/src/utils/tvgCompressor.cpp +++ b/thirdparty/thorvg/src/common/tvgCompressor.cpp diff --git a/thirdparty/thorvg/src/utils/tvgCompressor.h b/thirdparty/thorvg/src/common/tvgCompressor.h index 05d23f4293..05d23f4293 100644 --- a/thirdparty/thorvg/src/utils/tvgCompressor.h +++ b/thirdparty/thorvg/src/common/tvgCompressor.h diff --git a/thirdparty/thorvg/src/common/tvgList.h b/thirdparty/thorvg/src/common/tvgList.h new file mode 100644 index 0000000000..01e87a840f --- /dev/null +++ b/thirdparty/thorvg/src/common/tvgList.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2023 the ThorVG project. 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_LIST_H_ +#define _TVG_LIST_H_ + +namespace tvg { + +template<typename T> +struct LinkedList +{ + T *head = nullptr; + T *tail = nullptr; + + LinkedList() = default; + LinkedList(T *head, T *tail) : head(head), tail(tail) + { + } + + template<T *T::*Prev, T *T::*Next> + static void insert(T *t, T *prev, T *next, T **head, T **tail) + { + t->*Prev = prev; + t->*Next = next; + + if (prev) { + prev->*Next = t; + } else if (head) { + *head = t; + } + + if (next) { + next->*Prev = t; + } else if (tail) { + *tail = t; + } + } + + template<T *T::*Prev, T *T::*Next> + static void remove(T *t, T **head, T **tail) + { + if (t->*Prev) { + t->*Prev->*Next = t->*Next; + } else if (head) { + *head = t->*Next; + } + + if (t->*Next) { + t->*Next->*Prev = t->*Prev; + } else if (tail) { + *tail = t->*Prev; + } + + t->*Prev = t->*Next = nullptr; + } + + template <T* T::*Next> + static bool contains(T *t, T **head, T **tail) { + for (T *it = *head; it; it = it->*Next) { + if (it == t) { + return true; + } + } + + return false; + } +}; + +} + +#endif // _TVG_LIST_H_ diff --git a/thirdparty/thorvg/src/common/tvgMath.cpp b/thirdparty/thorvg/src/common/tvgMath.cpp new file mode 100644 index 0000000000..a9463c8077 --- /dev/null +++ b/thirdparty/thorvg/src/common/tvgMath.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2021 - 2023 the ThorVG project. 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 "tvgMath.h" + + +bool mathInverse(const Matrix* m, Matrix* out) +{ + auto det = m->e11 * (m->e22 * m->e33 - m->e32 * m->e23) - + m->e12 * (m->e21 * m->e33 - m->e23 * m->e31) + + m->e13 * (m->e21 * m->e32 - m->e22 * m->e31); + + if (mathZero(det)) return false; + + auto invDet = 1 / det; + + out->e11 = (m->e22 * m->e33 - m->e32 * m->e23) * invDet; + out->e12 = (m->e13 * m->e32 - m->e12 * m->e33) * invDet; + out->e13 = (m->e12 * m->e23 - m->e13 * m->e22) * invDet; + out->e21 = (m->e23 * m->e31 - m->e21 * m->e33) * invDet; + out->e22 = (m->e11 * m->e33 - m->e13 * m->e31) * invDet; + out->e23 = (m->e21 * m->e13 - m->e11 * m->e23) * invDet; + out->e31 = (m->e21 * m->e32 - m->e31 * m->e22) * invDet; + out->e32 = (m->e31 * m->e12 - m->e11 * m->e32) * invDet; + out->e33 = (m->e11 * m->e22 - m->e21 * m->e12) * invDet; + + return true; +} + + +Matrix mathMultiply(const Matrix* lhs, const Matrix* rhs) +{ + Matrix m; + + m.e11 = lhs->e11 * rhs->e11 + lhs->e12 * rhs->e21 + lhs->e13 * rhs->e31; + m.e12 = lhs->e11 * rhs->e12 + lhs->e12 * rhs->e22 + lhs->e13 * rhs->e32; + m.e13 = lhs->e11 * rhs->e13 + lhs->e12 * rhs->e23 + lhs->e13 * rhs->e33; + + m.e21 = lhs->e21 * rhs->e11 + lhs->e22 * rhs->e21 + lhs->e23 * rhs->e31; + m.e22 = lhs->e21 * rhs->e12 + lhs->e22 * rhs->e22 + lhs->e23 * rhs->e32; + m.e23 = lhs->e21 * rhs->e13 + lhs->e22 * rhs->e23 + lhs->e23 * rhs->e33; + + m.e31 = lhs->e31 * rhs->e11 + lhs->e32 * rhs->e21 + lhs->e33 * rhs->e31; + m.e32 = lhs->e31 * rhs->e12 + lhs->e32 * rhs->e22 + lhs->e33 * rhs->e32; + m.e33 = lhs->e31 * rhs->e13 + lhs->e32 * rhs->e23 + lhs->e33 * rhs->e33; + + return m; +} + + +void mathRotate(Matrix* m, float degree) +{ + if (degree == 0.0f) return; + + auto radian = degree / 180.0f * M_PI; + auto cosVal = cosf(radian); + auto sinVal = sinf(radian); + + m->e12 = m->e11 * -sinVal; + m->e11 *= cosVal; + m->e21 = m->e22 * sinVal; + m->e22 *= cosVal; +} + + +bool mathIdentity(const Matrix* m) +{ + if (m->e11 != 1.0f || m->e12 != 0.0f || m->e13 != 0.0f || + m->e21 != 0.0f || m->e22 != 1.0f || m->e23 != 0.0f || + m->e31 != 0.0f || m->e32 != 0.0f || m->e33 != 1.0f) { + return false; + } + return true; +} + + +void mathMultiply(Point* pt, const Matrix* transform) +{ + auto tx = pt->x * transform->e11 + pt->y * transform->e12 + transform->e13; + auto ty = pt->x * transform->e21 + pt->y * transform->e22 + transform->e23; + pt->x = tx; + pt->y = ty; +} diff --git a/thirdparty/thorvg/src/utils/tvgMath.h b/thirdparty/thorvg/src/common/tvgMath.h index 897ff46427..004fff1e7b 100644 --- a/thirdparty/thorvg/src/utils/tvgMath.h +++ b/thirdparty/thorvg/src/common/tvgMath.h @@ -36,6 +36,13 @@ #define mathMax(x, y) (((x) > (y)) ? (x) : (y)) +bool mathInverse(const Matrix* m, Matrix* out); +Matrix mathMultiply(const Matrix* lhs, const Matrix* rhs); +void mathRotate(Matrix* m, float degree); +bool mathIdentity(const Matrix* m); +void mathMultiply(Point* pt, const Matrix* transform); + + static inline bool mathZero(float a) { return (fabsf(a) < FLT_EPSILON) ? true : false; @@ -73,41 +80,6 @@ static inline bool mathSkewed(const Matrix* m) } -static inline bool mathIdentity(const Matrix* m) -{ - if (!mathEqual(m->e11, 1.0f) || !mathZero(m->e12) || !mathZero(m->e13) || - !mathZero(m->e21) || !mathEqual(m->e22, 1.0f) || !mathZero(m->e23) || - !mathZero(m->e31) || !mathZero(m->e32) || !mathEqual(m->e33, 1.0f)) { - return false; - } - return true; -} - - -static inline bool mathInverse(const Matrix* m, Matrix* out) -{ - auto det = m->e11 * (m->e22 * m->e33 - m->e32 * m->e23) - - m->e12 * (m->e21 * m->e33 - m->e23 * m->e31) + - m->e13 * (m->e21 * m->e32 - m->e22 * m->e31); - - if (mathZero(det)) return false; - - auto invDet = 1 / det; - - out->e11 = (m->e22 * m->e33 - m->e32 * m->e23) * invDet; - out->e12 = (m->e13 * m->e32 - m->e12 * m->e33) * invDet; - out->e13 = (m->e12 * m->e23 - m->e13 * m->e22) * invDet; - out->e21 = (m->e23 * m->e31 - m->e21 * m->e33) * invDet; - out->e22 = (m->e11 * m->e33 - m->e13 * m->e31) * invDet; - out->e23 = (m->e21 * m->e13 - m->e11 * m->e23) * invDet; - out->e31 = (m->e21 * m->e32 - m->e31 * m->e22) * invDet; - out->e32 = (m->e31 * m->e12 - m->e11 * m->e32) * invDet; - out->e33 = (m->e11 * m->e22 - m->e21 * m->e12) * invDet; - - return true; -} - - static inline void mathIdentity(Matrix* m) { m->e11 = 1.0f; @@ -158,48 +130,6 @@ static inline void mathTranslate(Matrix* m, float x, float y) } -static inline void mathRotate(Matrix* m, float degree) -{ - auto radian = degree / 180.0f * M_PI; - auto cosVal = cosf(radian); - auto sinVal = sinf(radian); - - m->e12 = m->e11 * -sinVal; - m->e11 *= cosVal; - m->e21 = m->e22 * sinVal; - m->e22 *= cosVal; -} - - -static inline void mathMultiply(Point* pt, const Matrix* transform) -{ - auto tx = pt->x * transform->e11 + pt->y * transform->e12 + transform->e13; - auto ty = pt->x * transform->e21 + pt->y * transform->e22 + transform->e23; - pt->x = tx; - pt->y = ty; -} - - -static inline Matrix mathMultiply(const Matrix* lhs, const Matrix* rhs) -{ - Matrix m; - - m.e11 = lhs->e11 * rhs->e11 + lhs->e12 * rhs->e21 + lhs->e13 * rhs->e31; - m.e12 = lhs->e11 * rhs->e12 + lhs->e12 * rhs->e22 + lhs->e13 * rhs->e32; - m.e13 = lhs->e11 * rhs->e13 + lhs->e12 * rhs->e23 + lhs->e13 * rhs->e33; - - m.e21 = lhs->e21 * rhs->e11 + lhs->e22 * rhs->e21 + lhs->e23 * rhs->e31; - m.e22 = lhs->e21 * rhs->e12 + lhs->e22 * rhs->e22 + lhs->e23 * rhs->e32; - m.e23 = lhs->e21 * rhs->e13 + lhs->e22 * rhs->e23 + lhs->e23 * rhs->e33; - - m.e31 = lhs->e31 * rhs->e11 + lhs->e32 * rhs->e21 + lhs->e33 * rhs->e31; - m.e32 = lhs->e31 * rhs->e12 + lhs->e32 * rhs->e22 + lhs->e33 * rhs->e32; - m.e33 = lhs->e31 * rhs->e13 + lhs->e32 * rhs->e23 + lhs->e33 * rhs->e33; - - return m; -} - - static inline void mathTranslateR(Matrix* m, float x, float y) { if (x == 0.0f && y == 0.0f) return; diff --git a/thirdparty/thorvg/src/utils/tvgStr.cpp b/thirdparty/thorvg/src/common/tvgStr.cpp index eeed4fc404..eeed4fc404 100644 --- a/thirdparty/thorvg/src/utils/tvgStr.cpp +++ b/thirdparty/thorvg/src/common/tvgStr.cpp diff --git a/thirdparty/thorvg/src/utils/tvgStr.h b/thirdparty/thorvg/src/common/tvgStr.h index 448cc69336..448cc69336 100644 --- a/thirdparty/thorvg/src/utils/tvgStr.h +++ b/thirdparty/thorvg/src/common/tvgStr.h diff --git a/thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.cpp b/thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.cpp index 9825fd8cc4..be99ec085c 100644 --- a/thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.cpp +++ b/thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.cpp @@ -48,13 +48,9 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -#define _USE_MATH_DEFINES //Math Constants are not defined in Standard C/C++. - #include <cstring> #include <fstream> #include <float.h> -#include <math.h> #include "tvgLoader.h" #include "tvgXmlParser.h" #include "tvgSvgLoader.h" @@ -3508,8 +3504,29 @@ static bool _svgLoaderParserForValidCheck(void* data, SimpleXMLType type, const } -void SvgLoader::clear() +void SvgLoader::clear(bool all) { + //flush out the intermediate data + free(loaderData.svgParse); + loaderData.svgParse = nullptr; + + for (auto gradient = loaderData.gradients.data; gradient < loaderData.gradients.end(); ++gradient) { + (*gradient)->clear(); + free(*gradient); + } + loaderData.gradients.reset(); + + _freeNode(loaderData.doc); + loaderData.doc = nullptr; + loaderData.stack.reset(); + + if (!all) return; + + for (auto p = loaderData.images.data; p < loaderData.images.end(); ++p) { + free(*p); + } + loaderData.images.reset(); + if (copy) free((char*)content); size = 0; content = nullptr; @@ -3561,6 +3578,20 @@ void SvgLoader::run(unsigned tid) if (defs) _updateGradient(&loaderData, loaderData.doc, &defs->node.defs.gradients); } root = svgSceneBuild(loaderData, {vx, vy, vw, vh}, w, h, align, meetOrSlice, svgPath, viewFlag); + + //In case no viewbox and width/height data is provided the completion of loading + //has to be forced, in order to establish this data based on the whole picture. + if (!(viewFlag & SvgViewFlag::Viewbox)) { + //Override viewbox & size again after svg loading. + vx = loaderData.doc->node.doc.vx; + vy = loaderData.doc->node.doc.vy; + vw = loaderData.doc->node.doc.vw; + vh = loaderData.doc->node.doc.vh; + w = loaderData.doc->node.doc.w; + h = loaderData.doc->node.doc.h; + } + + clear(false); } @@ -3630,14 +3661,6 @@ bool SvgLoader::header() } run(0); - - //Override viewbox & size again after svg loading. - vx = loaderData.doc->node.doc.vx; - vy = loaderData.doc->node.doc.vy; - vw = loaderData.doc->node.doc.vw; - vh = loaderData.doc->node.doc.vh; - w = loaderData.doc->node.doc.w; - h = loaderData.doc->node.doc.h; } return true; @@ -3717,22 +3740,6 @@ bool SvgLoader::close() { this->done(); - if (loaderData.svgParse) { - free(loaderData.svgParse); - loaderData.svgParse = nullptr; - } - auto gradients = loaderData.gradients.data; - for (size_t i = 0; i < loaderData.gradients.count; ++i) { - (*gradients)->clear(); - free(*gradients); - ++gradients; - } - loaderData.gradients.reset(); - - _freeNode(loaderData.doc); - loaderData.doc = nullptr; - loaderData.stack.reset(); - clear(); return true; diff --git a/thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.h b/thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.h index 8331bf4c16..4bac52e0b9 100644 --- a/thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.h +++ b/thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.h @@ -61,7 +61,7 @@ private: float vh = 0; bool header(); - void clear(); + void clear(bool all = true); void run(unsigned tid) override; }; diff --git a/thirdparty/thorvg/src/loaders/svg/tvgSvgLoaderCommon.h b/thirdparty/thorvg/src/loaders/svg/tvgSvgLoaderCommon.h index 1809c7749c..b4ee3e8e0d 100644 --- a/thirdparty/thorvg/src/loaders/svg/tvgSvgLoaderCommon.h +++ b/thirdparty/thorvg/src/loaders/svg/tvgSvgLoaderCommon.h @@ -556,6 +556,7 @@ struct SvgLoaderData SvgParser* svgParse = nullptr; Array<SvgNodeIdPair> cloneNodes; Array<SvgNodeIdPair> nodesToStyle; + Array<char*> images; //embedded images int level = 0; bool result = false; bool style = false; diff --git a/thirdparty/thorvg/src/loaders/svg/tvgSvgSceneBuilder.cpp b/thirdparty/thorvg/src/loaders/svg/tvgSvgSceneBuilder.cpp index 71712442e8..2e018e2799 100644 --- a/thirdparty/thorvg/src/loaders/svg/tvgSvgSceneBuilder.cpp +++ b/thirdparty/thorvg/src/loaders/svg/tvgSvgSceneBuilder.cpp @@ -20,39 +20,10 @@ * SOFTWARE. */ -/* - * Copyright notice for the EFL: - - * Copyright (C) EFL developers (see AUTHORS) - - * All rights reserved. - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - - #include "tvgMath.h" /* to include math.h before cstring */ #include <cstring> #include <string> -#include "tvgShapeImpl.h" +#include "tvgShape.h" #include "tvgCompressor.h" #include "tvgPaint.h" #include "tvgFill.h" @@ -66,9 +37,9 @@ /* Internal Class Implementation */ /************************************************************************/ -static bool _appendShape(SvgNode* node, Shape* shape, const Box& vBox, const string& svgPath); -static bool _appendClipShape(SvgNode* node, Shape* shape, const Box& vBox, const string& svgPath, const Matrix* transform); -static unique_ptr<Scene> _sceneBuildHelper(const SvgNode* node, const Box& vBox, const string& svgPath, bool mask, int depth, bool* isMaskWhite = nullptr); +static bool _appendShape(SvgLoaderData& loaderData, SvgNode* node, Shape* shape, const Box& vBox, const string& svgPath); +static bool _appendClipShape(SvgLoaderData& loaderData, SvgNode* node, Shape* shape, const Box& vBox, const string& svgPath, const Matrix* transform); +static unique_ptr<Scene> _sceneBuildHelper(SvgLoaderData& loaderData, const SvgNode* node, const Box& vBox, const string& svgPath, bool mask, int depth, bool* isMaskWhite = nullptr); static inline bool _isGroupType(SvgNodeType type) @@ -223,7 +194,7 @@ static unique_ptr<RadialGradient> _applyRadialGradientProperty(SvgStyleGradient* //The SVG standard allows only for 'use' nodes that point directly to a basic shape. -static bool _appendClipUseNode(SvgNode* node, Shape* shape, const Box& vBox, const string& svgPath) +static bool _appendClipUseNode(SvgLoaderData& loaderData, SvgNode* node, Shape* shape, const Box& vBox, const string& svgPath) { if (node->child.count != 1) return false; auto child = *(node->child.data); @@ -236,16 +207,16 @@ static bool _appendClipUseNode(SvgNode* node, Shape* shape, const Box& vBox, con } if (child->transform) finalTransform = mathMultiply(child->transform, &finalTransform); - return _appendClipShape(child, shape, vBox, svgPath, mathIdentity((const Matrix*)(&finalTransform)) ? nullptr : &finalTransform); + return _appendClipShape(loaderData, child, shape, vBox, svgPath, mathIdentity((const Matrix*)(&finalTransform)) ? nullptr : &finalTransform); } -static bool _appendClipChild(SvgNode* node, Shape* shape, const Box& vBox, const string& svgPath, bool clip) +static bool _appendClipChild(SvgLoaderData& loaderData, SvgNode* node, Shape* shape, const Box& vBox, const string& svgPath, bool clip) { if (node->type == SvgNodeType::Use) { - return _appendClipUseNode(node, shape, vBox, svgPath); + return _appendClipUseNode(loaderData, node, shape, vBox, svgPath); } - return _appendClipShape(node, shape, vBox, svgPath, nullptr); + return _appendClipShape(loaderData, node, shape, vBox, svgPath, nullptr); } @@ -269,7 +240,7 @@ static Matrix _compositionTransform(Paint* paint, const SvgNode* node, const Svg } -static void _applyComposition(Paint* paint, const SvgNode* node, const Box& vBox, const string& svgPath) +static void _applyComposition(SvgLoaderData& loaderData, Paint* paint, const SvgNode* node, const Box& vBox, const string& svgPath) { /* ClipPath */ /* Do not drop in Circular Dependency for ClipPath. @@ -287,7 +258,7 @@ static void _applyComposition(Paint* paint, const SvgNode* node, const Box& vBox auto valid = false; //Composite only when valid shapes exist for (uint32_t i = 0; i < compNode->child.count; ++i, ++child) { - if (_appendClipChild(*child, comp.get(), vBox, svgPath, compNode->child.count > 1)) valid = true; + if (_appendClipChild(loaderData, *child, comp.get(), vBox, svgPath, compNode->child.count > 1)) valid = true; } if (valid) { @@ -312,7 +283,7 @@ static void _applyComposition(Paint* paint, const SvgNode* node, const Box& vBox node->style->mask.applying = true; bool isMaskWhite = true; - if (auto comp = _sceneBuildHelper(compNode, vBox, svgPath, true, 0, &isMaskWhite)) { + if (auto comp = _sceneBuildHelper(loaderData, compNode, vBox, svgPath, true, 0, &isMaskWhite)) { Matrix finalTransform = _compositionTransform(paint, node, compNode, SvgNodeType::Mask); comp->transform(finalTransform); @@ -329,7 +300,7 @@ static void _applyComposition(Paint* paint, const SvgNode* node, const Box& vBox } -static void _applyProperty(SvgNode* node, Shape* vg, const Box& vBox, const string& svgPath, bool clip) +static void _applyProperty(SvgLoaderData& loaderData, SvgNode* node, Shape* vg, const Box& vBox, const string& svgPath, bool clip) { SvgStyleProperty* style = node->style; @@ -404,14 +375,14 @@ static void _applyProperty(SvgNode* node, Shape* vg, const Box& vBox, const stri vg->stroke(style->stroke.paint.color.r, style->stroke.paint.color.g, style->stroke.paint.color.b, style->stroke.opacity); } - _applyComposition(vg, node, vBox, svgPath); + _applyComposition(loaderData, vg, node, vBox, svgPath); } -static unique_ptr<Shape> _shapeBuildHelper(SvgNode* node, const Box& vBox, const string& svgPath) +static unique_ptr<Shape> _shapeBuildHelper(SvgLoaderData& loaderData, SvgNode* node, const Box& vBox, const string& svgPath) { auto shape = Shape::gen(); - if (_appendShape(node, shape.get(), vBox, svgPath)) return shape; + if (_appendShape(loaderData, node, shape.get(), vBox, svgPath)) return shape; else return nullptr; } @@ -473,16 +444,16 @@ static bool _recognizeShape(SvgNode* node, Shape* shape) } -static bool _appendShape(SvgNode* node, Shape* shape, const Box& vBox, const string& svgPath) +static bool _appendShape(SvgLoaderData& loaderData, SvgNode* node, Shape* shape, const Box& vBox, const string& svgPath) { if (!_recognizeShape(node, shape)) return false; - _applyProperty(node, shape, vBox, svgPath, false); + _applyProperty(loaderData, node, shape, vBox, svgPath, false); return true; } -static bool _appendClipShape(SvgNode* node, Shape* shape, const Box& vBox, const string& svgPath, const Matrix* transform) +static bool _appendClipShape(SvgLoaderData& loaderData, SvgNode* node, Shape* shape, const Box& vBox, const string& svgPath, const Matrix* transform) { //The 'transform' matrix has higher priority than the node->transform, since it already contains it auto m = transform ? transform : (node->transform ? node->transform : nullptr); @@ -503,7 +474,7 @@ static bool _appendClipShape(SvgNode* node, Shape* shape, const Box& vBox, const while (currentPtsCnt++ < ptsCnt) mathMultiply(p++, m); } - _applyProperty(node, shape, vBox, svgPath, true); + _applyProperty(loaderData, node, shape, vBox, svgPath, true); return true; } @@ -581,7 +552,7 @@ static bool _isValidImageMimeTypeAndEncoding(const char** href, const char** mim #include "tvgTaskScheduler.h" -static unique_ptr<Picture> _imageBuildHelper(SvgNode* node, const Box& vBox, const string& svgPath) +static unique_ptr<Picture> _imageBuildHelper(SvgLoaderData& loaderData, SvgNode* node, const Box& vBox, const string& svgPath) { if (!node->node.image.href) return nullptr; auto picture = Picture::gen(); @@ -594,24 +565,23 @@ static unique_ptr<Picture> _imageBuildHelper(SvgNode* node, const Box& vBox, con const char* mimetype; imageMimeTypeEncoding encoding; if (!_isValidImageMimeTypeAndEncoding(&href, &mimetype, &encoding)) return nullptr; //not allowed mime type or encoding + char *decoded = nullptr; if (encoding == imageMimeTypeEncoding::base64) { - char* decoded = nullptr; auto size = b64Decode(href, strlen(href), &decoded); - //OPTIMIZE: Skip data copy. - if (picture->load(decoded, size, mimetype, true) != Result::Success) { + if (picture->load(decoded, size, mimetype, false) != Result::Success) { free(decoded); TaskScheduler::async(true); return nullptr; } - free(decoded); } else { - string decoded = svgUtilURLDecode(href); - //OPTIMIZE: Skip data copy. - if (picture->load(decoded.c_str(), decoded.size(), mimetype, true) != Result::Success) { + auto size = svgUtilURLDecode(href, &decoded); + if (picture->load(decoded, size, mimetype, false) != Result::Success) { + free(decoded); TaskScheduler::async(true); return nullptr; } } + loaderData.images.push(decoded); } else { if (!strncmp(href, "file://", sizeof("file://") - 1)) href += sizeof("file://") - 1; //TODO: protect against recursive svg image loading @@ -645,7 +615,8 @@ static unique_ptr<Picture> _imageBuildHelper(SvgNode* node, const Box& vBox, con if (node->transform) m = mathMultiply(node->transform, &m); picture->transform(m); - _applyComposition(picture.get(), node, vBox, svgPath); + _applyComposition(loaderData, picture.get(), node, vBox, svgPath); + return picture; } @@ -724,10 +695,10 @@ static Matrix _calculateAspectRatioMatrix(AspectRatioAlign align, AspectRatioMee } -static unique_ptr<Scene> _useBuildHelper(const SvgNode* node, const Box& vBox, const string& svgPath, int depth, bool* isMaskWhite) +static unique_ptr<Scene> _useBuildHelper(SvgLoaderData& loaderData, const SvgNode* node, const Box& vBox, const string& svgPath, int depth, bool* isMaskWhite) { unique_ptr<Scene> finalScene; - auto scene = _sceneBuildHelper(node, vBox, svgPath, false, depth + 1, isMaskWhite); + auto scene = _sceneBuildHelper(loaderData, node, vBox, svgPath, false, depth + 1, isMaskWhite); // mUseTransform = mUseTransform * mTranslate Matrix mUseTransform = {1, 0, 0, 0, 1, 0, 0, 0, 1}; @@ -786,7 +757,7 @@ static unique_ptr<Scene> _useBuildHelper(const SvgNode* node, const Box& vBox, c finalScene = std::move(root); } } else { - if (!mathIdentity((const Matrix*)(&mUseTransform))) scene->transform(mUseTransform); + scene->transform(mUseTransform); finalScene = std::move(scene); } @@ -794,7 +765,7 @@ static unique_ptr<Scene> _useBuildHelper(const SvgNode* node, const Box& vBox, c } -static unique_ptr<Scene> _sceneBuildHelper(const SvgNode* node, const Box& vBox, const string& svgPath, bool mask, int depth, bool* isMaskWhite) +static unique_ptr<Scene> _sceneBuildHelper(SvgLoaderData& loaderData, const SvgNode* node, const Box& vBox, const string& svgPath, bool mask, int depth, bool* isMaskWhite) { /* Exception handling: Prevent invalid SVG data input. The size is the arbitrary value, we need an experimental size. */ @@ -813,17 +784,17 @@ static unique_ptr<Scene> _sceneBuildHelper(const SvgNode* node, const Box& vBox, for (uint32_t i = 0; i < node->child.count; ++i, ++child) { if (_isGroupType((*child)->type)) { if ((*child)->type == SvgNodeType::Use) - scene->push(_useBuildHelper(*child, vBox, svgPath, depth + 1, isMaskWhite)); + scene->push(_useBuildHelper(loaderData, *child, vBox, svgPath, depth + 1, isMaskWhite)); else - scene->push(_sceneBuildHelper(*child, vBox, svgPath, false, depth + 1, isMaskWhite)); + scene->push(_sceneBuildHelper(loaderData, *child, vBox, svgPath, false, depth + 1, isMaskWhite)); } else if ((*child)->type == SvgNodeType::Image) { - auto image = _imageBuildHelper(*child, vBox, svgPath); + auto image = _imageBuildHelper(loaderData, *child, vBox, svgPath); if (image) { scene->push(std::move(image)); if (isMaskWhite) *isMaskWhite = false; } } else if ((*child)->type != SvgNodeType::Mask) { - auto shape = _shapeBuildHelper(*child, vBox, svgPath); + auto shape = _shapeBuildHelper(loaderData, *child, vBox, svgPath); if (shape) { if (isMaskWhite) { uint8_t r, g, b; @@ -837,7 +808,7 @@ static unique_ptr<Scene> _sceneBuildHelper(const SvgNode* node, const Box& vBox, } } } - _applyComposition(scene.get(), node, vBox, svgPath); + _applyComposition(loaderData, scene.get(), node, vBox, svgPath); scene->opacity(node->style->opacity); } return scene; @@ -876,7 +847,7 @@ unique_ptr<Scene> svgSceneBuild(SvgLoaderData& loaderData, Box vBox, float w, fl if (!loaderData.doc || (loaderData.doc->type != SvgNodeType::Doc)) return nullptr; - auto docNode = _sceneBuildHelper(loaderData.doc, vBox, svgPath, false, 0); + auto docNode = _sceneBuildHelper(loaderData, loaderData.doc, vBox, svgPath, false, 0); if (!(viewFlag & SvgViewFlag::Viewbox)) _updateInvalidViewSize(docNode.get(), vBox, w, h, viewFlag); diff --git a/thirdparty/thorvg/src/loaders/svg/tvgSvgUtil.cpp b/thirdparty/thorvg/src/loaders/svg/tvgSvgUtil.cpp index 763a357f99..7940188ade 100644 --- a/thirdparty/thorvg/src/loaders/svg/tvgSvgUtil.cpp +++ b/thirdparty/thorvg/src/loaders/svg/tvgSvgUtil.cpp @@ -39,29 +39,32 @@ static uint8_t _hexCharToDec(const char c) /* External Class Implementation */ /************************************************************************/ -string svgUtilURLDecode(const char *src) +size_t svgUtilURLDecode(const char *src, char** dst) { - if (!src) return nullptr; + if (!src) return 0; auto length = strlen(src); - if (length == 0) return nullptr; + if (length == 0) return 0; - string decoded; - decoded.reserve(length); + char* decoded = (char*)malloc(sizeof(char) * length + 1); + decoded[length] = '\0'; char a, b; + int idx =0; while (*src) { if (*src == '%' && ((a = src[1]) && (b = src[2])) && (isxdigit(a) && isxdigit(b))) { - decoded += (_hexCharToDec(a) << 4) + _hexCharToDec(b); + decoded[idx++] = (_hexCharToDec(a) << 4) + _hexCharToDec(b); src+=3; } else if (*src == '+') { - decoded += ' '; + decoded[idx++] = ' '; src++; } else { - decoded += *src++; + decoded[idx++] = *src++; } } - return decoded; + + *dst = decoded; + return length + 1; } diff --git a/thirdparty/thorvg/src/loaders/svg/tvgSvgUtil.h b/thirdparty/thorvg/src/loaders/svg/tvgSvgUtil.h index e914eadc65..ee0e3f8861 100644 --- a/thirdparty/thorvg/src/loaders/svg/tvgSvgUtil.h +++ b/thirdparty/thorvg/src/loaders/svg/tvgSvgUtil.h @@ -25,6 +25,6 @@ #include "tvgCommon.h" -string svgUtilURLDecode(const char *src); +size_t svgUtilURLDecode(const char *src, char** dst); #endif //_TVG_SVG_UTIL_H_ diff --git a/thirdparty/thorvg/src/lib/sw_engine/tvgSwCommon.h b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwCommon.h index 4cee0b18e2..c0cd8863a2 100644 --- a/thirdparty/thorvg/src/lib/sw_engine/tvgSwCommon.h +++ b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwCommon.h @@ -273,6 +273,7 @@ struct SwMpool { SwOutline* outline; SwOutline* strokeOutline; + SwOutline* dashOutline; unsigned allocSize; }; @@ -544,6 +545,8 @@ SwOutline* mpoolReqOutline(SwMpool* mpool, unsigned idx); void mpoolRetOutline(SwMpool* mpool, unsigned idx); SwOutline* mpoolReqStrokeOutline(SwMpool* mpool, unsigned idx); void mpoolRetStrokeOutline(SwMpool* mpool, unsigned idx); +SwOutline* mpoolReqDashOutline(SwMpool* mpool, unsigned idx); +void mpoolRetDashOutline(SwMpool* mpool, unsigned idx); bool rasterCompositor(SwSurface* surface); bool rasterGradientShape(SwSurface* surface, SwShape* shape, unsigned id); diff --git a/thirdparty/thorvg/src/lib/sw_engine/tvgSwFill.cpp b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwFill.cpp index cede9e6eb7..cede9e6eb7 100644 --- a/thirdparty/thorvg/src/lib/sw_engine/tvgSwFill.cpp +++ b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwFill.cpp diff --git a/thirdparty/thorvg/src/lib/sw_engine/tvgSwImage.cpp b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwImage.cpp index fb8581b412..b1624037bc 100644 --- a/thirdparty/thorvg/src/lib/sw_engine/tvgSwImage.cpp +++ b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwImage.cpp @@ -48,7 +48,7 @@ static bool _genOutline(SwImage* image, const RenderMesh* mesh, const Matrix* tr if (mesh->triangleCnt > 0) { // TODO: Optimise me. We appear to calculate this exact min/max bounding area in multiple // places. We should be able to re-use one we have already done? Also see: - // tvgPictureImpl.h --> bounds + // tvgPicture.h --> bounds // tvgSwRasterTexmap.h --> _rasterTexmapPolygonMesh // // TODO: Should we calculate the exact path(s) of the triangle mesh instead? diff --git a/thirdparty/thorvg/src/lib/sw_engine/tvgSwMath.cpp b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwMath.cpp index dbcfa754f3..dbcfa754f3 100644 --- a/thirdparty/thorvg/src/lib/sw_engine/tvgSwMath.cpp +++ b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwMath.cpp diff --git a/thirdparty/thorvg/src/lib/sw_engine/tvgSwMemPool.cpp b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwMemPool.cpp index 936d9cbded..54ae594bff 100644 --- a/thirdparty/thorvg/src/lib/sw_engine/tvgSwMemPool.cpp +++ b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwMemPool.cpp @@ -62,54 +62,52 @@ void mpoolRetStrokeOutline(SwMpool* mpool, unsigned idx) } +SwOutline* mpoolReqDashOutline(SwMpool* mpool, unsigned idx) +{ + return &mpool->dashOutline[idx]; +} + + +void mpoolRetDashOutline(SwMpool* mpool, unsigned idx) +{ + mpool->dashOutline[idx].pts.clear(); + mpool->dashOutline[idx].cntrs.clear(); + mpool->dashOutline[idx].types.clear(); + mpool->dashOutline[idx].closed.clear(); +} + + SwMpool* mpoolInit(unsigned threads) { auto allocSize = threads + 1; auto mpool = static_cast<SwMpool*>(calloc(sizeof(SwMpool), 1)); mpool->outline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline) * allocSize)); - if (!mpool->outline) goto err; - mpool->strokeOutline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline) * allocSize)); - if (!mpool->strokeOutline) goto err; - + mpool->dashOutline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline) * allocSize)); mpool->allocSize = allocSize; return mpool; - -err: - if (mpool->outline) { - free(mpool->outline); - mpool->outline = nullptr; - } - - if (mpool->strokeOutline) { - free(mpool->strokeOutline); - mpool->strokeOutline = nullptr; - } - free(mpool); - return nullptr; } bool mpoolClear(SwMpool* mpool) { - SwOutline* p; - for (unsigned i = 0; i < mpool->allocSize; ++i) { - //Outline - p = &mpool->outline[i]; - p->pts.reset(); - p->cntrs.reset(); - p->types.reset(); - p->closed.reset(); - - //StrokeOutline - p = &mpool->strokeOutline[i]; - p->pts.reset(); - p->cntrs.reset(); - p->types.reset(); - p->closed.reset(); + mpool->outline[i].pts.reset(); + mpool->outline[i].cntrs.reset(); + mpool->outline[i].types.reset(); + mpool->outline[i].closed.reset(); + + mpool->strokeOutline[i].pts.reset(); + mpool->strokeOutline[i].cntrs.reset(); + mpool->strokeOutline[i].types.reset(); + mpool->strokeOutline[i].closed.reset(); + + mpool->dashOutline[i].pts.reset(); + mpool->dashOutline[i].cntrs.reset(); + mpool->dashOutline[i].types.reset(); + mpool->dashOutline[i].closed.reset(); } return true; @@ -122,16 +120,9 @@ bool mpoolTerm(SwMpool* mpool) mpoolClear(mpool); - if (mpool->outline) { - free(mpool->outline); - mpool->outline = nullptr; - } - - if (mpool->strokeOutline) { - free(mpool->strokeOutline); - mpool->strokeOutline = nullptr; - } - + free(mpool->outline); + free(mpool->strokeOutline); + free(mpool->dashOutline); free(mpool); return true; diff --git a/thirdparty/thorvg/src/lib/sw_engine/tvgSwRaster.cpp b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRaster.cpp index 8fd54c2a4f..4b1ba59100 100644 --- a/thirdparty/thorvg/src/lib/sw_engine/tvgSwRaster.cpp +++ b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRaster.cpp @@ -2024,11 +2024,11 @@ bool rasterConvertCS(Surface* surface, ColorSpace to) //TOOD: Support SIMD accelerations auto from = surface->cs; - if ((from == ColorSpace::ABGR8888 && to == ColorSpace::ARGB8888) || (from == ColorSpace::ABGR8888S && to == ColorSpace::ARGB8888S)) { + if (((from == ColorSpace::ABGR8888) || (from == ColorSpace::ABGR8888S)) && ((to == ColorSpace::ARGB8888) || (to == ColorSpace::ARGB8888S))) { surface->cs = to; return cRasterABGRtoARGB(surface); } - if ((from == ColorSpace::ARGB8888 && to == ColorSpace::ABGR8888) || (from == ColorSpace::ARGB8888S && to == ColorSpace::ABGR8888S)) { + if (((from == ColorSpace::ARGB8888) || (from == ColorSpace::ARGB8888S)) && ((to == ColorSpace::ABGR8888) || (to == ColorSpace::ABGR8888S))) { surface->cs = to; return cRasterARGBtoABGR(surface); } diff --git a/thirdparty/thorvg/src/lib/sw_engine/tvgSwRasterAvx.h b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterAvx.h index 090fa29a7a..090fa29a7a 100644 --- a/thirdparty/thorvg/src/lib/sw_engine/tvgSwRasterAvx.h +++ b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterAvx.h diff --git a/thirdparty/thorvg/src/lib/sw_engine/tvgSwRasterC.h b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterC.h index eb377e78e3..eb377e78e3 100644 --- a/thirdparty/thorvg/src/lib/sw_engine/tvgSwRasterC.h +++ b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterC.h diff --git a/thirdparty/thorvg/src/lib/sw_engine/tvgSwRasterNeon.h b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterNeon.h index ba77ed53cf..ba77ed53cf 100644 --- a/thirdparty/thorvg/src/lib/sw_engine/tvgSwRasterNeon.h +++ b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterNeon.h diff --git a/thirdparty/thorvg/src/lib/sw_engine/tvgSwRasterTexmap.h b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterTexmap.h index 698ab37da2..698ab37da2 100644 --- a/thirdparty/thorvg/src/lib/sw_engine/tvgSwRasterTexmap.h +++ b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterTexmap.h diff --git a/thirdparty/thorvg/src/lib/sw_engine/tvgSwRenderer.cpp b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRenderer.cpp index 091b72fa97..049aa3d1d0 100644 --- a/thirdparty/thorvg/src/lib/sw_engine/tvgSwRenderer.cpp +++ b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRenderer.cpp @@ -742,6 +742,12 @@ void* SwRenderer::prepareCommon(SwTask* task, const RenderTransform* transform, task->transform = nullptr; } + //zero size? + if (task->transform) { + if (task->transform->e11 == 0.0f && task->transform->e12 == 0.0f) return task; //zero width + if (task->transform->e21 == 0.0f && task->transform->e22 == 0.0f) return task; //zero height + } + task->opacity = opacity; task->surface = surface; task->mpool = mpool; @@ -767,10 +773,8 @@ RenderData SwRenderer::prepare(Surface* surface, const RenderMesh* mesh, RenderD //prepare task auto task = static_cast<SwImageTask*>(data); if (!task) task = new SwImageTask; - if (flags & RenderUpdateFlag::Image) { - task->source = surface; - task->mesh = mesh; - } + task->source = surface; + task->mesh = mesh; return prepareCommon(task, transform, clips, opacity, flags); } diff --git a/thirdparty/thorvg/src/lib/sw_engine/tvgSwRenderer.h b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRenderer.h index 4393740bd9..4393740bd9 100644 --- a/thirdparty/thorvg/src/lib/sw_engine/tvgSwRenderer.h +++ b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRenderer.h diff --git a/thirdparty/thorvg/src/lib/sw_engine/tvgSwRle.cpp b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRle.cpp index a4a7fabdee..a4a7fabdee 100644 --- a/thirdparty/thorvg/src/lib/sw_engine/tvgSwRle.cpp +++ b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRle.cpp diff --git a/thirdparty/thorvg/src/lib/sw_engine/tvgSwShape.cpp b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwShape.cpp index 651eaee452..159898c750 100644 --- a/thirdparty/thorvg/src/lib/sw_engine/tvgSwShape.cpp +++ b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwShape.cpp @@ -212,7 +212,7 @@ static void _dashCubicTo(SwDashStroke& dash, const Point* ctrl1, const Point* ct } -static SwOutline* _genDashOutline(const RenderShape* rshape, const Matrix* transform, float length) +static SwOutline* _genDashOutline(const RenderShape* rshape, const Matrix* transform, float length, SwMpool* mpool, unsigned tid) { const PathCommand* cmds = rshape->path.cmds.data; auto cmdCnt = rshape->path.cmds.count; @@ -283,8 +283,7 @@ static SwOutline* _genDashOutline(const RenderShape* rshape, const Matrix* trans } } - //OPTMIZE ME: Use mempool??? - dash.outline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline))); + dash.outline = mpoolReqDashOutline(mpool, tid); //smart reservation auto closeCnt = 0; @@ -567,16 +566,16 @@ bool shapeGenStrokeRle(SwShape* shape, const RenderShape* rshape, const Matrix* { SwOutline* shapeOutline = nullptr; SwOutline* strokeOutline = nullptr; - bool freeOutline = false; - bool ret = true; + auto dashStroking = false; + auto ret = true; auto length = rshape->strokeTrim() ? _outlineLength(rshape) : 0.0f; //Dash style (+trimming) if (rshape->stroke->dashCnt > 0 || length > 0) { - shapeOutline = _genDashOutline(rshape, transform, length); + shapeOutline = _genDashOutline(rshape, transform, length, mpool, tid); if (!shapeOutline) return false; - freeOutline = true; + dashStroking = true; //Normal style } else { if (!shape->outline) { @@ -587,26 +586,20 @@ bool shapeGenStrokeRle(SwShape* shape, const RenderShape* rshape, const Matrix* if (!strokeParseOutline(shape->stroke, *shapeOutline)) { ret = false; - goto fail; + goto clear; } strokeOutline = strokeExportOutline(shape->stroke, mpool, tid); if (!mathUpdateOutlineBBox(strokeOutline, clipRegion, renderRegion, false)) { ret = false; - goto fail; + goto clear; } shape->strokeRle = rleRender(shape->strokeRle, strokeOutline, renderRegion, true); -fail: - if (freeOutline) { - free(shapeOutline->cntrs.data); - free(shapeOutline->pts.data); - free(shapeOutline->types.data); - free(shapeOutline->closed.data); - free(shapeOutline); - } +clear: + if (dashStroking) mpoolRetDashOutline(mpool, tid); mpoolRetStrokeOutline(mpool, tid); return ret; diff --git a/thirdparty/thorvg/src/lib/sw_engine/tvgSwStroke.cpp b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwStroke.cpp index f46a4a5a1d..b1bdccbbba 100644 --- a/thirdparty/thorvg/src/lib/sw_engine/tvgSwStroke.cpp +++ b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwStroke.cpp @@ -373,6 +373,10 @@ void _firstSubPath(SwStroke& stroke, SwFixed startAngle, SwFixed lineLength) static void _lineTo(SwStroke& stroke, const SwPoint& to) { auto delta = to - stroke.center; + + //a zero-length lineto is a no-op; avoid creating a spurious corner + if (delta.zero()) return; + //compute length of line auto angle = mathAtan(delta); diff --git a/thirdparty/thorvg/src/lib/tvgAccessor.cpp b/thirdparty/thorvg/src/renderer/tvgAccessor.cpp index 0c636979b5..0c636979b5 100644 --- a/thirdparty/thorvg/src/lib/tvgAccessor.cpp +++ b/thirdparty/thorvg/src/renderer/tvgAccessor.cpp diff --git a/thirdparty/thorvg/src/lib/tvgAnimation.cpp b/thirdparty/thorvg/src/renderer/tvgAnimation.cpp index 4e8c8568d4..7a29ecf973 100644 --- a/thirdparty/thorvg/src/lib/tvgAnimation.cpp +++ b/thirdparty/thorvg/src/renderer/tvgAnimation.cpp @@ -20,11 +20,10 @@ * SOFTWARE. */ -//#include "tvgAnimationImpl.h" #include "tvgCommon.h" #include "tvgFrameModule.h" #include "tvgPaint.h" -#include "tvgPictureImpl.h" +#include "tvgPicture.h" /************************************************************************/ /* Internal Class Implementation */ @@ -37,12 +36,12 @@ struct Animation::Impl Impl() { picture = Picture::gen().release(); - static_cast<Paint*>(picture)->pImpl->ref(); + PP(picture)->ref(); } ~Impl() { - if (static_cast<Paint*>(picture)->pImpl->unref() == 0) { + if (PP(picture)->unref() == 0) { delete(picture); } } diff --git a/thirdparty/thorvg/src/lib/tvgBinaryDesc.h b/thirdparty/thorvg/src/renderer/tvgBinaryDesc.h index 3b9dbe891b..b1468148d6 100644 --- a/thirdparty/thorvg/src/lib/tvgBinaryDesc.h +++ b/thirdparty/thorvg/src/renderer/tvgBinaryDesc.h @@ -36,7 +36,7 @@ using TvgBinFlag = TvgBinByte; #define TVG_HEADER_SIZE 33 //TVG_HEADER_SIGNATURE_LENGTH + TVG_HEADER_VERSION_LENGTH + 2*SIZE(float) + TVG_HEADER_RESERVED_LENGTH + TVG_HEADER_COMPRESS_SIZE #define TVG_HEADER_SIGNATURE "ThorVG" #define TVG_HEADER_SIGNATURE_LENGTH 6 -#define TVG_HEADER_VERSION "001000" //Major 00, Minor 10, Micro 00 +#define TVG_HEADER_VERSION "001100" //Major 00, Minor 11, Micro 00 #define TVG_HEADER_VERSION_LENGTH 6 #define TVG_HEADER_RESERVED_LENGTH 1 //Storing flags for extensions #define TVG_HEADER_COMPRESS_SIZE 12 //TVG_HEADER_UNCOMPRESSED_SIZE + TVG_HEADER_COMPRESSED_SIZE + TVG_HEADER_COMPRESSED_SIZE_BITS @@ -82,6 +82,7 @@ using TvgBinFlag = TvgBinByte; #define TVG_TAG_SHAPE_STROKE_DASHPTRN (TvgBinTag)0x55 #define TVG_TAG_SHAPE_STROKE_MITERLIMIT (TvgBinTag)0x56 #define TVG_TAG_SHAPE_STROKE_ORDER (TvgBinTag)0x57 +#define TVG_TAG_SHAPE_STROKE_DASH_OFFSET (TvgBinTag)0x58 //Fill @@ -90,7 +91,7 @@ using TvgBinFlag = TvgBinByte; #define TVG_TAG_FILL_COLORSTOPS (TvgBinTag)0x62 #define TVG_TAG_FILL_FILLSPREAD (TvgBinTag)0x63 #define TVG_TAG_FILL_TRANSFORM (TvgBinTag)0x64 - +#define TVG_TAG_FILL_RADIAL_GRADIENT_FOCAL (TvgBinTag)0x65 //Picture #define TVG_TAG_PICTURE_RAW_IMAGE (TvgBinTag)0x70 diff --git a/thirdparty/thorvg/src/lib/tvgCanvas.cpp b/thirdparty/thorvg/src/renderer/tvgCanvas.cpp index 1dee370326..2d4cbd048f 100644 --- a/thirdparty/thorvg/src/lib/tvgCanvas.cpp +++ b/thirdparty/thorvg/src/renderer/tvgCanvas.cpp @@ -20,7 +20,7 @@ * SOFTWARE. */ -#include "tvgCanvasImpl.h" +#include "tvgCanvas.h" /************************************************************************/ /* External Class Implementation */ diff --git a/thirdparty/thorvg/src/lib/tvgCanvasImpl.h b/thirdparty/thorvg/src/renderer/tvgCanvas.h index fe934ec352..f893f9f7c0 100644 --- a/thirdparty/thorvg/src/lib/tvgCanvasImpl.h +++ b/thirdparty/thorvg/src/renderer/tvgCanvas.h @@ -53,6 +53,7 @@ struct Canvas::Impl auto p = paint.release(); if (!p) return Result::MemoryCorruption; + PP(p)->ref(); paints.push_back(p); return update(p, true); @@ -64,14 +65,15 @@ struct Canvas::Impl if (!renderer || !renderer->clear()) return Result::InsufficientCondition; //Free paints - for (auto paint : paints) { - if (paint->pImpl->dispose(*renderer)) { - if (free && paint->pImpl->unref() == 0) delete(paint); - } + if (free) { + for (auto paint : paints) { + P(paint)->unref(); + if (paint->pImpl->dispose(*renderer) && P(paint)->refCnt == 0) { + delete(paint); + } + } + paints.clear(); } - - paints.clear(); - drawing = false; return Result::Success; diff --git a/thirdparty/thorvg/src/lib/tvgCommon.h b/thirdparty/thorvg/src/renderer/tvgCommon.h index f36b4b9b30..f36b4b9b30 100644 --- a/thirdparty/thorvg/src/lib/tvgCommon.h +++ b/thirdparty/thorvg/src/renderer/tvgCommon.h diff --git a/thirdparty/thorvg/src/lib/tvgFill.cpp b/thirdparty/thorvg/src/renderer/tvgFill.cpp index 9215882c8d..9215882c8d 100644 --- a/thirdparty/thorvg/src/lib/tvgFill.cpp +++ b/thirdparty/thorvg/src/renderer/tvgFill.cpp diff --git a/thirdparty/thorvg/src/lib/tvgFill.h b/thirdparty/thorvg/src/renderer/tvgFill.h index ff3dd48c49..ff3dd48c49 100644 --- a/thirdparty/thorvg/src/lib/tvgFill.h +++ b/thirdparty/thorvg/src/renderer/tvgFill.h diff --git a/thirdparty/thorvg/src/lib/tvgFrameModule.h b/thirdparty/thorvg/src/renderer/tvgFrameModule.h index 857c6caeb9..857c6caeb9 100644 --- a/thirdparty/thorvg/src/lib/tvgFrameModule.h +++ b/thirdparty/thorvg/src/renderer/tvgFrameModule.h diff --git a/thirdparty/thorvg/src/lib/tvgGlCanvas.cpp b/thirdparty/thorvg/src/renderer/tvgGlCanvas.cpp index dbbab516b2..aa7f8dbe2a 100644 --- a/thirdparty/thorvg/src/lib/tvgGlCanvas.cpp +++ b/thirdparty/thorvg/src/renderer/tvgGlCanvas.cpp @@ -20,7 +20,7 @@ * SOFTWARE. */ -#include "tvgCanvasImpl.h" +#include "tvgCanvas.h" #ifdef THORVG_GL_RASTER_SUPPORT #include "tvgGlRenderer.h" diff --git a/thirdparty/thorvg/src/lib/tvgInitializer.cpp b/thirdparty/thorvg/src/renderer/tvgInitializer.cpp index b7326a9fbc..b7326a9fbc 100644 --- a/thirdparty/thorvg/src/lib/tvgInitializer.cpp +++ b/thirdparty/thorvg/src/renderer/tvgInitializer.cpp diff --git a/thirdparty/thorvg/src/lib/tvgIteratorAccessor.h b/thirdparty/thorvg/src/renderer/tvgIteratorAccessor.h index 2347613ed8..2347613ed8 100644 --- a/thirdparty/thorvg/src/lib/tvgIteratorAccessor.h +++ b/thirdparty/thorvg/src/renderer/tvgIteratorAccessor.h diff --git a/thirdparty/thorvg/src/lib/tvgLoadModule.h b/thirdparty/thorvg/src/renderer/tvgLoadModule.h index 29ceba3fcc..29ceba3fcc 100644 --- a/thirdparty/thorvg/src/lib/tvgLoadModule.h +++ b/thirdparty/thorvg/src/renderer/tvgLoadModule.h diff --git a/thirdparty/thorvg/src/lib/tvgLoader.cpp b/thirdparty/thorvg/src/renderer/tvgLoader.cpp index 8ed0d5752e..52bdb91d6a 100644 --- a/thirdparty/thorvg/src/lib/tvgLoader.cpp +++ b/thirdparty/thorvg/src/renderer/tvgLoader.cpp @@ -220,7 +220,7 @@ shared_ptr<LoadModule> LoaderMgr::loader(const char* data, uint32_t size, const if (loader->open(data, size, copy)) { return shared_ptr<LoadModule>(loader); } else { - TVGLOG("LOADER", "Given mimetype \"%s\" seems incorrect or not supported. Will try again with other types.", mimeType.c_str()); + TVGLOG("LOADER", "Given mimetype \"%s\" seems incorrect or not supported.", mimeType.c_str()); delete(loader); } } diff --git a/thirdparty/thorvg/src/lib/tvgLoader.h b/thirdparty/thorvg/src/renderer/tvgLoader.h index 17ff9e2637..17ff9e2637 100644 --- a/thirdparty/thorvg/src/lib/tvgLoader.h +++ b/thirdparty/thorvg/src/renderer/tvgLoader.h diff --git a/thirdparty/thorvg/src/lib/tvgPaint.cpp b/thirdparty/thorvg/src/renderer/tvgPaint.cpp index bac5e434a5..37df906dac 100644 --- a/thirdparty/thorvg/src/lib/tvgPaint.cpp +++ b/thirdparty/thorvg/src/renderer/tvgPaint.cpp @@ -132,7 +132,7 @@ bool Paint::Impl::scale(float factor) if (rTransform) { if (mathEqual(factor, rTransform->scale)) return true; } else { - if (mathZero(factor)) return true; + if (mathEqual(factor, 1.0f)) return true; rTransform = new RenderTransform(); } rTransform->scale = factor; diff --git a/thirdparty/thorvg/src/lib/tvgPaint.h b/thirdparty/thorvg/src/renderer/tvgPaint.h index c020a7dffd..0ee07fedff 100644 --- a/thirdparty/thorvg/src/lib/tvgPaint.h +++ b/thirdparty/thorvg/src/renderer/tvgPaint.h @@ -24,7 +24,7 @@ #define _TVG_PAINT_H_ #include "tvgRender.h" - +#include "tvgMath.h" namespace tvg { @@ -68,7 +68,7 @@ namespace tvg uint8_t ctxFlag = ContextFlag::Invalid; uint8_t id; uint8_t opacity = 255; - uint8_t refCnt = 1; + uint8_t refCnt = 0; ~Impl() { @@ -100,6 +100,7 @@ namespace tvg bool transform(const Matrix& m) { if (!rTransform) { + if (mathIdentity(&m)) return true; rTransform = new RenderTransform(); if (!rTransform) return false; } diff --git a/thirdparty/thorvg/src/lib/tvgPicture.cpp b/thirdparty/thorvg/src/renderer/tvgPicture.cpp index fd324a947c..07877b92de 100644 --- a/thirdparty/thorvg/src/lib/tvgPicture.cpp +++ b/thirdparty/thorvg/src/renderer/tvgPicture.cpp @@ -20,7 +20,40 @@ * SOFTWARE. */ -#include "tvgPictureImpl.h" +#include "tvgPicture.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +RenderUpdateFlag Picture::Impl::load() +{ + if (loader) { + if (!paint) { + if (auto p = loader->paint()) { + paint = p.release(); + loader->close(); + if (w != loader->w || h != loader->h) { + if (!resizing) { + w = loader->w; + h = loader->h; + } + loader->resize(paint, w, h); + resizing = false; + } + if (paint) return RenderUpdateFlag::None; + } + } else loader->sync(); + + if (!surface) { + if ((surface = loader->bitmap().release())) { + loader->close(); + return RenderUpdateFlag::Image; + } + } + } + return RenderUpdateFlag::None; +} /************************************************************************/ /* External Class Implementation */ @@ -97,23 +130,6 @@ Result Picture::size(float* w, float* h) const noexcept } -const uint32_t* Picture::data(uint32_t* w, uint32_t* h) const noexcept -{ - //Try it, If not loaded yet. - pImpl->load(); - - if (pImpl->loader) { - if (w) *w = static_cast<uint32_t>(pImpl->loader->w); - if (h) *h = static_cast<uint32_t>(pImpl->loader->h); - } else { - if (w) *w = 0; - if (h) *h = 0; - } - if (pImpl->surface) return pImpl->surface->buf32; - else return nullptr; -} - - Result Picture::mesh(const Polygon* triangles, uint32_t triangleCnt) noexcept { if (!triangles && triangleCnt > 0) return Result::InvalidArguments; diff --git a/thirdparty/thorvg/src/lib/tvgPictureImpl.h b/thirdparty/thorvg/src/renderer/tvgPicture.h index f29b8a1ec3..447f56ecb7 100644 --- a/thirdparty/thorvg/src/lib/tvgPictureImpl.h +++ b/thirdparty/thorvg/src/renderer/tvgPicture.h @@ -89,35 +89,6 @@ struct Picture::Impl return true; } - RenderUpdateFlag load() - { - if (loader) { - if (!paint) { - if (auto p = loader->paint()) { - paint = p.release(); - loader->close(); - if (w != loader->w || h != loader->h) { - if (!resizing) { - w = loader->w; - h = loader->h; - } - loader->resize(paint, w, h); - resizing = false; - } - if (paint) return RenderUpdateFlag::None; - } - } else loader->sync(); - - if (!surface) { - if ((surface = loader->bitmap().release())) { - loader->close(); - return RenderUpdateFlag::Image; - } - } - } - return RenderUpdateFlag::None; - } - RenderTransform resizeTransform(const RenderTransform* pTransform) { //Overriding Transformation by the desired image size @@ -317,6 +288,24 @@ struct Picture::Impl load(); return new PictureIterator(paint); } + + uint32_t* data(uint32_t* w, uint32_t* h) + { + //Try it, If not loaded yet. + load(); + + if (loader) { + if (w) *w = static_cast<uint32_t>(loader->w); + if (h) *h = static_cast<uint32_t>(loader->h); + } else { + if (w) *w = 0; + if (h) *h = 0; + } + if (surface) return surface->buf32; + else return nullptr; + } + + RenderUpdateFlag load(); }; #endif //_TVG_PICTURE_IMPL_H_ diff --git a/thirdparty/thorvg/src/lib/tvgRender.cpp b/thirdparty/thorvg/src/renderer/tvgRender.cpp index ec4db13f6e..9768b5ede0 100644 --- a/thirdparty/thorvg/src/lib/tvgRender.cpp +++ b/thirdparty/thorvg/src/renderer/tvgRender.cpp @@ -35,12 +35,7 @@ void RenderTransform::override(const Matrix& m) { this->m = m; - - if (m.e11 == 0.0f && m.e12 == 0.0f && m.e13 == 0.0f && - m.e21 == 0.0f && m.e22 == 0.0f && m.e23 == 0.0f && - m.e31 == 0.0f && m.e32 == 0.0f && m.e33 == 0.0f) { - overriding = false; - } else overriding = true; + overriding = true; } diff --git a/thirdparty/thorvg/src/lib/tvgRender.h b/thirdparty/thorvg/src/renderer/tvgRender.h index 1231089ff5..1231089ff5 100644 --- a/thirdparty/thorvg/src/lib/tvgRender.h +++ b/thirdparty/thorvg/src/renderer/tvgRender.h diff --git a/thirdparty/thorvg/src/lib/tvgSaveModule.h b/thirdparty/thorvg/src/renderer/tvgSaveModule.h index a997b644a7..a997b644a7 100644 --- a/thirdparty/thorvg/src/lib/tvgSaveModule.h +++ b/thirdparty/thorvg/src/renderer/tvgSaveModule.h diff --git a/thirdparty/thorvg/src/lib/tvgSaver.cpp b/thirdparty/thorvg/src/renderer/tvgSaver.cpp index 3b4dfddcc2..3b4dfddcc2 100644 --- a/thirdparty/thorvg/src/lib/tvgSaver.cpp +++ b/thirdparty/thorvg/src/renderer/tvgSaver.cpp diff --git a/thirdparty/thorvg/src/lib/tvgScene.cpp b/thirdparty/thorvg/src/renderer/tvgScene.cpp index d2b7503e28..52e7ea2bf6 100644 --- a/thirdparty/thorvg/src/lib/tvgScene.cpp +++ b/thirdparty/thorvg/src/renderer/tvgScene.cpp @@ -20,7 +20,7 @@ * SOFTWARE. */ -#include "tvgSceneImpl.h" +#include "tvgScene.h" /************************************************************************/ /* External Class Implementation */ @@ -55,6 +55,7 @@ Result Scene::push(unique_ptr<Paint> paint) noexcept { auto p = paint.release(); if (!p) return Result::MemoryCorruption; + PP(p)->ref(); pImpl->paints.push_back(p); return Result::Success; diff --git a/thirdparty/thorvg/src/lib/tvgSceneImpl.h b/thirdparty/thorvg/src/renderer/tvgScene.h index 90b1775610..10daa49a99 100644 --- a/thirdparty/thorvg/src/lib/tvgSceneImpl.h +++ b/thirdparty/thorvg/src/renderer/tvgScene.h @@ -220,7 +220,9 @@ struct Scene::Impl auto dup = ret.get()->pImpl; for (auto paint : paints) { - dup->paints.push_back(paint->duplicate()); + auto cdup = paint->duplicate(); + P(cdup)->ref(); + dup->paints.push_back(cdup); } return ret.release(); @@ -231,8 +233,8 @@ struct Scene::Impl auto dispose = renderer ? true : false; for (auto paint : paints) { - if (dispose) free &= paint->pImpl->dispose(*renderer); - if (free) delete(paint); + if (dispose) free &= P(paint)->dispose(*renderer); + if (P(paint)->unref() == 0 && free) delete(paint); } paints.clear(); renderer = nullptr; diff --git a/thirdparty/thorvg/src/lib/tvgShape.cpp b/thirdparty/thorvg/src/renderer/tvgShape.cpp index 336ac71d81..efb7666b29 100644 --- a/thirdparty/thorvg/src/lib/tvgShape.cpp +++ b/thirdparty/thorvg/src/renderer/tvgShape.cpp @@ -21,7 +21,7 @@ */ #include "tvgMath.h" -#include "tvgShapeImpl.h" +#include "tvgShape.h" /************************************************************************/ /* Internal Class Implementation */ diff --git a/thirdparty/thorvg/src/lib/tvgShapeImpl.h b/thirdparty/thorvg/src/renderer/tvgShape.h index bb266866d0..bb266866d0 100644 --- a/thirdparty/thorvg/src/lib/tvgShapeImpl.h +++ b/thirdparty/thorvg/src/renderer/tvgShape.h diff --git a/thirdparty/thorvg/src/lib/tvgSwCanvas.cpp b/thirdparty/thorvg/src/renderer/tvgSwCanvas.cpp index 7e6bc40c5b..95df6b486d 100644 --- a/thirdparty/thorvg/src/lib/tvgSwCanvas.cpp +++ b/thirdparty/thorvg/src/renderer/tvgSwCanvas.cpp @@ -20,7 +20,7 @@ * SOFTWARE. */ -#include "tvgCanvasImpl.h" +#include "tvgCanvas.h" #ifdef THORVG_SW_RASTER_SUPPORT #include "tvgSwRenderer.h" diff --git a/thirdparty/thorvg/src/lib/tvgTaskScheduler.cpp b/thirdparty/thorvg/src/renderer/tvgTaskScheduler.cpp index e3887c60fc..e3887c60fc 100644 --- a/thirdparty/thorvg/src/lib/tvgTaskScheduler.cpp +++ b/thirdparty/thorvg/src/renderer/tvgTaskScheduler.cpp diff --git a/thirdparty/thorvg/src/lib/tvgTaskScheduler.h b/thirdparty/thorvg/src/renderer/tvgTaskScheduler.h index 2dad80f5d0..2dad80f5d0 100644 --- a/thirdparty/thorvg/src/lib/tvgTaskScheduler.h +++ b/thirdparty/thorvg/src/renderer/tvgTaskScheduler.h |