loader lottie: tiny data copy optimization.

This patch tries to skip the matrix data copy as possible.
This commit is contained in:
Hermet Park 2023-08-11 23:56:30 +09:00
parent 8212d6f0f9
commit 9e0a3aa678
4 changed files with 15 additions and 11 deletions

View file

@ -82,4 +82,7 @@ using Size = Point;
uint16_t THORVG_VERSION_NUMBER(); uint16_t THORVG_VERSION_NUMBER();
#define P(A) (A->pImpl) //Access to pimpl.
#endif //_TVG_COMMON_H_ #endif //_TVG_COMMON_H_

View file

@ -20,7 +20,8 @@
* SOFTWARE. * SOFTWARE.
*/ */
#include "tvgMath.h" #include "tvgCommon.h"
#include "tvgPaint.h"
#include "tvgShapeImpl.h" #include "tvgShapeImpl.h"
#include "tvgLottieModel.h" #include "tvgLottieModel.h"
#include "tvgLottieBuilder.h" #include "tvgLottieBuilder.h"
@ -104,9 +105,10 @@ static Shape* _updateTransform(Paint* paint, LottieTransform* transform, int32_t
uint8_t opacity; uint8_t opacity;
if (!_updateTransform(transform, frameNo, false, matrix, opacity)) return nullptr; if (!_updateTransform(transform, frameNo, false, matrix, opacity)) return nullptr;
auto pmatrix = paint->transform(); auto pmatrix = P(paint)->transform();
paint->transform(mathMultiply(&pmatrix, &matrix)); paint->transform(pmatrix ? mathMultiply(pmatrix, &matrix) : matrix);
paint->opacity(opacity); paint->opacity(opacity);
return nullptr; return nullptr;
} }
@ -229,14 +231,14 @@ static Shape* _updatePath(LottieGroup* parent, LottiePath* path, int32_t frameNo
mergingShape = newShape.get(); mergingShape = newShape.get();
static_cast<Scene*>(parent->scene)->push(std::move(newShape)); static_cast<Scene*>(parent->scene)->push(std::move(newShape));
} }
if (path->pathset(frameNo, mergingShape->pImpl->rs.path.cmds, mergingShape->pImpl->rs.path.pts)) { if (path->pathset(frameNo, P(mergingShape)->rs.path.cmds, P(mergingShape)->rs.path.pts)) {
mergingShape->pImpl->update(RenderUpdateFlag::Path); P(mergingShape)->update(RenderUpdateFlag::Path);
} }
return mergingShape; 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(); auto picture = Picture::gen();
@ -247,12 +249,15 @@ static void _updateImage(LottieGroup* parent, LottieImage* image, int32_t frameN
} }
if (baseShape) { if (baseShape) {
picture->transform(baseShape->transform()); if (auto matrix = P(baseShape)->transform()) {
picture->transform(*matrix);
}
picture->opacity(baseShape->opacity()); picture->opacity(baseShape->opacity());
} }
parent->scene->push(std::move(picture)); parent->scene->push(std::move(picture));
} }
static void _updateChildren(LottieGroup* parent, int32_t frameNo, Shape* baseShape, bool reset) static void _updateChildren(LottieGroup* parent, int32_t frameNo, Shape* baseShape, bool reset)
{ {
if (parent->children.empty()) return; if (parent->children.empty()) return;

View file

@ -34,8 +34,6 @@
#include "tvgShapeImpl.h" #include "tvgShapeImpl.h"
#define P(A) A->pImpl
/************************************************************************/ /************************************************************************/
/* Internal Class Implementation */ /* Internal Class Implementation */
/************************************************************************/ /************************************************************************/

View file

@ -52,8 +52,6 @@ static FILE* _fopen(const char* filename, const char* mode)
#define SIZE(A) sizeof(A) #define SIZE(A) sizeof(A)
#define P(A) A->pImpl
/************************************************************************/ /************************************************************************/
/* Internal Class Implementation */ /* Internal Class Implementation */
/************************************************************************/ /************************************************************************/