lottie: Added gradient population preventing logic

`LottieGradient.populate` function checks whether the value has already been calculated and populated via the flag `populated`.
This commit is contained in:
Jinny You 2024-03-20 11:01:22 +09:00 committed by Hermet Park
parent 23386625fc
commit dcdec440df
2 changed files with 10 additions and 5 deletions

View file

@ -455,17 +455,20 @@ struct LottieGradient : LottieObject
color.input->reset(); color.input->reset();
delete(color.input); delete(color.input);
colorStops.populated = true;
return output.count; return output.count;
} }
bool prepare() bool prepare()
{ {
if (colorStops.frames) { if (!colorStops.populated) {
for (auto v = colorStops.frames->begin(); v < colorStops.frames->end(); ++v) { if (colorStops.frames) {
colorStops.count = populate(v->value); for (auto v = colorStops.frames->begin(); v < colorStops.frames->end(); ++v) {
colorStops.count = populate(v->value);
}
} else {
colorStops.count = populate(colorStops.value);
} }
} else {
colorStops.count = populate(colorStops.value);
} }
if (start.frames || end.frames || height.frames || angle.frames || opacity.frames || colorStops.frames) return true; if (start.frames || end.frames || height.frames || angle.frames || opacity.frames || colorStops.frames) return true;
return false; return false;

View file

@ -361,6 +361,7 @@ struct LottieColorStop : LottieProperty
Array<LottieScalarFrame<ColorStop>>* frames = nullptr; Array<LottieScalarFrame<ColorStop>>* frames = nullptr;
ColorStop value; ColorStop value;
uint16_t count = 0; //colorstop count uint16_t count = 0; //colorstop count
bool populated = false;
~LottieColorStop() ~LottieColorStop()
{ {
@ -462,6 +463,7 @@ struct LottieColorStop : LottieProperty
value = other.value; value = other.value;
const_cast<LottieColorStop&>(other).value.data = nullptr; const_cast<LottieColorStop&>(other).value.data = nullptr;
} }
populated = other.populated;
count = other.count; count = other.count;
return *this; return *this;
} }