mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
loader/lottie: optimize the matrix computation.
Do not multiply the matrices if either one is identity.
This commit is contained in:
parent
b240e781d9
commit
345b867c38
2 changed files with 13 additions and 10 deletions
|
@ -38,10 +38,13 @@ static bool _buildPrecomp(LottieComposition* comp, LottieGroup* parent);
|
|||
|
||||
static bool _updateTransform(LottieTransform* transform, int32_t frameNo, bool autoOrient, Matrix& matrix, uint8_t& opacity)
|
||||
{
|
||||
if (!transform) return false;
|
||||
|
||||
mathIdentity(&matrix);
|
||||
|
||||
if (!transform) {
|
||||
opacity = 255;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (transform->coords) {
|
||||
mathTranslate(&matrix, transform->coords->x(frameNo), transform->coords->y(frameNo));
|
||||
} else {
|
||||
|
@ -76,15 +79,15 @@ static void _updateTransform(LottieLayer* layer, int32_t frameNo)
|
|||
if (parent) _updateTransform(parent, parent->remap(frameNo));
|
||||
|
||||
auto& matrix = layer->cache.matrix;
|
||||
uint8_t opacity;
|
||||
|
||||
_updateTransform(transform, frameNo, layer->autoOrient, matrix, opacity);
|
||||
_updateTransform(transform, frameNo, layer->autoOrient, matrix, layer->cache.opacity);
|
||||
|
||||
if (parent) {
|
||||
layer->cache.matrix = mathMultiply(&parent->cache.matrix, &matrix);
|
||||
layer->cache.opacity = MULTIPLY(opacity, parent->cache.opacity);
|
||||
if (!mathIdentity((const Matrix*) &parent->cache.matrix)) {
|
||||
if (mathIdentity((const Matrix*) &matrix)) layer->cache.matrix = parent->cache.matrix;
|
||||
else layer->cache.matrix = mathMultiply(&parent->cache.matrix, &matrix);
|
||||
}
|
||||
}
|
||||
layer->cache.opacity = opacity;
|
||||
layer->cache.frameNo = frameNo;
|
||||
}
|
||||
|
||||
|
|
|
@ -84,9 +84,9 @@ void mathRotate(Matrix* m, float degree)
|
|||
|
||||
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)) {
|
||||
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;
|
||||
|
|
Loading…
Add table
Reference in a new issue