mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-10 14:41:50 +00:00
loader lottie: ++optimization.
Aggressive parallelization is implemented to perform updates on every frame in an asynchronous manner.
This commit is contained in:
parent
023b38ad3c
commit
68b8fce501
6 changed files with 35 additions and 27 deletions
|
@ -44,9 +44,11 @@ public:
|
||||||
virtual bool resize(Paint* paint, float w, float h) { return false; }
|
virtual bool resize(Paint* paint, float w, float h) { return false; }
|
||||||
|
|
||||||
virtual bool animatable() { return false; } //true if this loader supports animation.
|
virtual bool animatable() { return false; } //true if this loader supports animation.
|
||||||
|
virtual void sync() {}; //finish immediately if any async update jobs.
|
||||||
|
|
||||||
virtual bool read() = 0;
|
virtual bool read() = 0;
|
||||||
virtual bool close() = 0;
|
virtual bool close() = 0;
|
||||||
|
|
||||||
virtual unique_ptr<Surface> bitmap() { return nullptr; }
|
virtual unique_ptr<Surface> bitmap() { return nullptr; }
|
||||||
virtual unique_ptr<Paint> paint() { return nullptr; }
|
virtual unique_ptr<Paint> paint() { return nullptr; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -109,7 +109,8 @@ struct Picture::Impl
|
||||||
}
|
}
|
||||||
if (paint) return RenderUpdateFlag::None;
|
if (paint) return RenderUpdateFlag::None;
|
||||||
}
|
}
|
||||||
}
|
} else loader->sync();
|
||||||
|
|
||||||
if (!surface) {
|
if (!surface) {
|
||||||
if ((surface = loader->bitmap().release())) {
|
if ((surface = loader->bitmap().release())) {
|
||||||
loader->close();
|
loader->close();
|
||||||
|
|
|
@ -377,25 +377,19 @@ bool LottieBuilder::update(LottieComposition* comp, int32_t frameNo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unique_ptr<Scene> LottieBuilder::build(LottieComposition* comp)
|
void LottieBuilder::build(LottieComposition* comp)
|
||||||
{
|
{
|
||||||
if (comp->scene) {
|
if (comp->scene) return;
|
||||||
TVGERR("LOTTIE", "LottieBuilder::build() is requested multiple times?");
|
|
||||||
return unique_ptr<Scene>(comp->scene);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto scene = Scene::gen();
|
comp->scene = Scene::gen().release();
|
||||||
if (!scene) return nullptr;
|
if (!comp->scene) return;
|
||||||
comp->scene = scene.get();
|
|
||||||
|
|
||||||
//TODO: Process repeater objects?
|
//TODO: Process repeater objects?
|
||||||
|
|
||||||
if (!update(comp, 0)) return nullptr;
|
if (!update(comp, 0)) return;
|
||||||
|
|
||||||
//viewport clip
|
//viewport clip
|
||||||
auto clip = Shape::gen();
|
auto clip = Shape::gen();
|
||||||
clip->appendRect(0, 0, static_cast<float>(comp->w), static_cast<float>(comp->h));
|
clip->appendRect(0, 0, static_cast<float>(comp->w), static_cast<float>(comp->h));
|
||||||
scene->composite(std::move(clip), CompositeMethod::ClipPath);
|
comp->scene->composite(std::move(clip), CompositeMethod::ClipPath);
|
||||||
|
|
||||||
return scene;
|
|
||||||
}
|
}
|
|
@ -30,7 +30,7 @@ struct LottieComposition;
|
||||||
struct LottieBuilder
|
struct LottieBuilder
|
||||||
{
|
{
|
||||||
bool update(LottieComposition* comp, int32_t frameNo);
|
bool update(LottieComposition* comp, int32_t frameNo);
|
||||||
unique_ptr<Scene> build(LottieComposition* comp);
|
void build(LottieComposition* comp);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //_TVG_LOTTIE_BUILDER_H
|
#endif //_TVG_LOTTIE_BUILDER_H
|
|
@ -75,12 +75,16 @@ void LottieLoader::clear()
|
||||||
|
|
||||||
void LottieLoader::run(unsigned tid)
|
void LottieLoader::run(unsigned tid)
|
||||||
{
|
{
|
||||||
LottieParser parser(content);
|
//update frame
|
||||||
parser.parse();
|
if (comp && comp->scene) {
|
||||||
|
builder->update(comp, frameNo);
|
||||||
comp = parser.comp;
|
//initial loading
|
||||||
|
} else {
|
||||||
root = builder->build(comp);
|
LottieParser parser(content);
|
||||||
|
parser.parse();
|
||||||
|
comp = parser.comp;
|
||||||
|
builder->build(comp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -143,6 +147,8 @@ bool LottieLoader::header()
|
||||||
p = e;
|
p = e;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
//TODO: need a duration time in advance.
|
||||||
|
|
||||||
//width
|
//width
|
||||||
if (!strncmp(p, "\"w\":", 4)) {
|
if (!strncmp(p, "\"w\":", 4)) {
|
||||||
p += 4;
|
p += 4;
|
||||||
|
@ -251,7 +257,7 @@ bool LottieLoader::read()
|
||||||
if (!content || size == 0) return false;
|
if (!content || size == 0) return false;
|
||||||
|
|
||||||
//the loading has been already completed in header()
|
//the loading has been already completed in header()
|
||||||
if (root) return true;
|
if (comp) return true;
|
||||||
|
|
||||||
TaskScheduler::request(this);
|
TaskScheduler::request(this);
|
||||||
|
|
||||||
|
@ -273,7 +279,7 @@ unique_ptr<Paint> LottieLoader::paint()
|
||||||
{
|
{
|
||||||
this->done();
|
this->done();
|
||||||
|
|
||||||
return std::move(root);
|
return cast<Paint>(comp->scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -287,7 +293,9 @@ bool LottieLoader::frame(uint32_t frameNo)
|
||||||
|
|
||||||
this->frameNo = frameNo;
|
this->frameNo = frameNo;
|
||||||
|
|
||||||
return builder->update(comp, frameNo);
|
TaskScheduler::request(this);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -302,8 +310,6 @@ uint32_t LottieLoader::totalFrame()
|
||||||
|
|
||||||
uint32_t LottieLoader::curFrame()
|
uint32_t LottieLoader::curFrame()
|
||||||
{
|
{
|
||||||
this->done();
|
|
||||||
|
|
||||||
return frameNo;
|
return frameNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,4 +320,10 @@ float LottieLoader::duration()
|
||||||
|
|
||||||
if (!comp) return 0;
|
if (!comp) return 0;
|
||||||
return comp->duration();
|
return comp->duration();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LottieLoader::sync()
|
||||||
|
{
|
||||||
|
this->done();
|
||||||
}
|
}
|
|
@ -41,8 +41,6 @@ public:
|
||||||
LottieBuilder* builder = nullptr;
|
LottieBuilder* builder = nullptr;
|
||||||
LottieComposition* comp = nullptr;
|
LottieComposition* comp = nullptr;
|
||||||
|
|
||||||
unique_ptr<Scene> root; //current motion frame
|
|
||||||
|
|
||||||
bool copy = false; //"content" is owned by this loader
|
bool copy = false; //"content" is owned by this loader
|
||||||
|
|
||||||
LottieLoader();
|
LottieLoader();
|
||||||
|
@ -62,6 +60,7 @@ public:
|
||||||
uint32_t totalFrame() override;
|
uint32_t totalFrame() override;
|
||||||
uint32_t curFrame() override;
|
uint32_t curFrame() override;
|
||||||
float duration() override;
|
float duration() override;
|
||||||
|
void sync() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool header();
|
bool header();
|
||||||
|
|
Loading…
Add table
Reference in a new issue