[lua] Cache temporal surface in GraphicsContext::drawImage()

This commit is contained in:
David Capello 2023-03-13 17:10:25 -03:00
parent c280732fb1
commit 87cd81b9f6

View File

@ -56,7 +56,14 @@ void GraphicsContext::drawImage(const doc::Image* img,
if (srcRc.isEmpty() || dstRc.isEmpty())
return; // Do nothing for empty rectangles
auto tmpSurface = os::instance()->makeRgbaSurface(srcRc.w, srcRc.h);
static os::SurfaceRef tmpSurface = nullptr;
if (!tmpSurface ||
tmpSurface->width() < srcRc.w ||
tmpSurface->height() < srcRc.h) {
tmpSurface = os::instance()->makeRgbaSurface(
std::max(srcRc.w, (tmpSurface ? tmpSurface->width(): 0)),
std::max(srcRc.h, (tmpSurface ? tmpSurface->height(): 0)));
}
if (tmpSurface) {
convert_image_to_surface(
img,