From 9e0a3aa67838e284c648d601ca6395f1d2d28b35 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Fri, 11 Aug 2023 23:56:30 +0900 Subject: [PATCH] loader lottie: tiny data copy optimization. This patch tries to skip the matrix data copy as possible. --- src/lib/tvgCommon.h | 3 +++ src/loaders/lottie/tvgLottieBuilder.cpp | 19 ++++++++++++------- src/loaders/tvg/tvgTvgBinInterpreter.cpp | 2 -- src/savers/tvg/tvgTvgSaver.cpp | 2 -- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/lib/tvgCommon.h b/src/lib/tvgCommon.h index 23011ffe..dcaf9fad 100644 --- a/src/lib/tvgCommon.h +++ b/src/lib/tvgCommon.h @@ -82,4 +82,7 @@ using Size = Point; uint16_t THORVG_VERSION_NUMBER(); + +#define P(A) (A->pImpl) //Access to pimpl. + #endif //_TVG_COMMON_H_ diff --git a/src/loaders/lottie/tvgLottieBuilder.cpp b/src/loaders/lottie/tvgLottieBuilder.cpp index 22d9bedb..4ba2e0c0 100644 --- a/src/loaders/lottie/tvgLottieBuilder.cpp +++ b/src/loaders/lottie/tvgLottieBuilder.cpp @@ -20,7 +20,8 @@ * SOFTWARE. */ -#include "tvgMath.h" +#include "tvgCommon.h" +#include "tvgPaint.h" #include "tvgShapeImpl.h" #include "tvgLottieModel.h" #include "tvgLottieBuilder.h" @@ -104,9 +105,10 @@ static Shape* _updateTransform(Paint* paint, LottieTransform* transform, int32_t uint8_t opacity; if (!_updateTransform(transform, frameNo, false, matrix, opacity)) return nullptr; - auto pmatrix = paint->transform(); - paint->transform(mathMultiply(&pmatrix, &matrix)); + auto pmatrix = P(paint)->transform(); + paint->transform(pmatrix ? mathMultiply(pmatrix, &matrix) : matrix); paint->opacity(opacity); + return nullptr; } @@ -229,14 +231,14 @@ static Shape* _updatePath(LottieGroup* parent, LottiePath* path, int32_t frameNo mergingShape = newShape.get(); static_cast(parent->scene)->push(std::move(newShape)); } - if (path->pathset(frameNo, mergingShape->pImpl->rs.path.cmds, mergingShape->pImpl->rs.path.pts)) { - mergingShape->pImpl->update(RenderUpdateFlag::Path); + if (path->pathset(frameNo, P(mergingShape)->rs.path.cmds, P(mergingShape)->rs.path.pts)) { + P(mergingShape)->update(RenderUpdateFlag::Path); } return mergingShape; } -static void _updateImage(LottieGroup* parent, LottieImage* image, int32_t frameNo, Shape* baseShape) +static void _updateImage(LottieGroup* parent, LottieImage* image, int32_t frameNo, Paint* baseShape) { auto picture = Picture::gen(); @@ -247,12 +249,15 @@ static void _updateImage(LottieGroup* parent, LottieImage* image, int32_t frameN } if (baseShape) { - picture->transform(baseShape->transform()); + if (auto matrix = P(baseShape)->transform()) { + picture->transform(*matrix); + } picture->opacity(baseShape->opacity()); } parent->scene->push(std::move(picture)); } + static void _updateChildren(LottieGroup* parent, int32_t frameNo, Shape* baseShape, bool reset) { if (parent->children.empty()) return; diff --git a/src/loaders/tvg/tvgTvgBinInterpreter.cpp b/src/loaders/tvg/tvgTvgBinInterpreter.cpp index 284c068b..185d5235 100644 --- a/src/loaders/tvg/tvgTvgBinInterpreter.cpp +++ b/src/loaders/tvg/tvgTvgBinInterpreter.cpp @@ -34,8 +34,6 @@ #include "tvgShapeImpl.h" -#define P(A) A->pImpl - /************************************************************************/ /* Internal Class Implementation */ /************************************************************************/ diff --git a/src/savers/tvg/tvgTvgSaver.cpp b/src/savers/tvg/tvgTvgSaver.cpp index 14a762d6..c8b6bf5e 100644 --- a/src/savers/tvg/tvgTvgSaver.cpp +++ b/src/savers/tvg/tvgTvgSaver.cpp @@ -52,8 +52,6 @@ static FILE* _fopen(const char* filename, const char* mode) #define SIZE(A) sizeof(A) -#define P(A) A->pImpl - /************************************************************************/ /* Internal Class Implementation */ /************************************************************************/