mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-09 06:04:03 +00:00
bindings/wasm: optimize the performance.
Do not try to update/render if nothing has been changed.
This commit is contained in:
parent
ad9d9d0ecd
commit
7626aaf5d2
1 changed files with 16 additions and 1 deletions
|
@ -93,11 +93,15 @@ public:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updated = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool update()
|
bool update()
|
||||||
{
|
{
|
||||||
|
if (!updated) return true;
|
||||||
|
|
||||||
errorMsg = NoError;
|
errorMsg = NoError;
|
||||||
|
|
||||||
if (canvas->update() != Result::Success) {
|
if (canvas->update() != Result::Success) {
|
||||||
|
@ -114,6 +118,8 @@ public:
|
||||||
|
|
||||||
if (!canvas || !animation) return val(typed_memory_view<uint8_t>(0, nullptr));
|
if (!canvas || !animation) return val(typed_memory_view<uint8_t>(0, nullptr));
|
||||||
|
|
||||||
|
if (!updated) return val(typed_memory_view(width * height * 4, buffer));
|
||||||
|
|
||||||
if (canvas->draw() != Result::Success) {
|
if (canvas->draw() != Result::Success) {
|
||||||
errorMsg = "draw() fail";
|
errorMsg = "draw() fail";
|
||||||
return val(typed_memory_view<uint8_t>(0, nullptr));
|
return val(typed_memory_view<uint8_t>(0, nullptr));
|
||||||
|
@ -121,6 +127,8 @@ public:
|
||||||
|
|
||||||
canvas->sync();
|
canvas->sync();
|
||||||
|
|
||||||
|
updated = false;
|
||||||
|
|
||||||
return val(typed_memory_view(width * height * 4, buffer));
|
return val(typed_memory_view(width * height * 4, buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,10 +152,14 @@ public:
|
||||||
bool frame(uint32_t no)
|
bool frame(uint32_t no)
|
||||||
{
|
{
|
||||||
if (!canvas || !animation) return false;
|
if (!canvas || !animation) return false;
|
||||||
|
if (animation->curFrame() == no) return true;
|
||||||
if (animation->frame(no) != Result::Success) {
|
if (animation->frame(no) != Result::Success) {
|
||||||
errorMsg = "frame() fail";
|
errorMsg = "frame() fail";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updated = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,6 +186,8 @@ public:
|
||||||
}
|
}
|
||||||
animation->picture()->scale(scale);
|
animation->picture()->scale(scale);
|
||||||
animation->picture()->translate(shiftX, shiftY);
|
animation->picture()->translate(shiftX, shiftY);
|
||||||
|
|
||||||
|
updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool save(bool compress)
|
bool save(bool compress)
|
||||||
|
@ -340,6 +354,7 @@ private:
|
||||||
uint32_t height = 0;
|
uint32_t height = 0;
|
||||||
float bounds[4];
|
float bounds[4];
|
||||||
float psize[2]; //picture size
|
float psize[2]; //picture size
|
||||||
|
bool updated = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue