bindings/wasm: optimize the performance.

Do not try to update/render if nothing has been changed.
This commit is contained in:
Hermet Park 2023-09-01 13:42:30 +09:00 committed by Hermet Park
parent ad9d9d0ecd
commit 7626aaf5d2

View file

@ -93,11 +93,15 @@ public:
return false;
}
updated = true;
return true;
}
bool update()
{
if (!updated) return true;
errorMsg = NoError;
if (canvas->update() != Result::Success) {
@ -114,6 +118,8 @@ public:
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) {
errorMsg = "draw() fail";
return val(typed_memory_view<uint8_t>(0, nullptr));
@ -121,6 +127,8 @@ public:
canvas->sync();
updated = false;
return val(typed_memory_view(width * height * 4, buffer));
}
@ -144,10 +152,14 @@ public:
bool frame(uint32_t no)
{
if (!canvas || !animation) return false;
if (animation->curFrame() == no) return true;
if (animation->frame(no) != Result::Success) {
errorMsg = "frame() fail";
return false;
}
updated = true;
return true;
}
@ -174,6 +186,8 @@ public:
}
animation->picture()->scale(scale);
animation->picture()->translate(shiftX, shiftY);
updated = true;
}
bool save(bool compress)
@ -339,7 +353,8 @@ private:
uint32_t width = 0;
uint32_t height = 0;
float bounds[4];
float psize[2]; //picture size
float psize[2]; //picture size
bool updated = false;
};