Improved performance of ImageData:mapPixel (now up to 2x as fast as in 0.8.0!); love.graphics.newImage, Image:refresh, love.window.setIcon, and ImageRasterizers now prevent other threads from modifying the ImageData used in those functions until they're done accessing it

This commit is contained in:
Alex Szpakowski
2013-06-25 05:28:20 -03:00
parent 8d7e0b5629
commit 6e3a7288dd
8 changed files with 191 additions and 28 deletions
+7 -1
View File
@@ -73,13 +73,16 @@ GlyphData *ImageRasterizer::getGlyphData(uint32 glyph) const
if (gm.width == 0)
return g;
// We don't want another thread modifying our ImageData mid-copy.
love::thread::Lock lock(imageData->getMutex());
love::image::pixel *gdpixels = (love::image::pixel *) g->getData();
love::image::pixel *imagepixels = (love::image::pixel *) imageData->getData();
// copy glyph pixels from imagedata to glyphdata
for (int i = 0; i < g->getWidth() * g->getHeight(); i++)
{
love::image::pixel p = imagepixels[ it->second.x + (i % gm.width) + (imageData->getWidth() * (i / gm.width)) ];
love::image::pixel p = imagepixels[it->second.x + (i % gm.width) + (imageData->getWidth() * (i / gm.width))];
// Use transparency instead of the spacer color
if (equal(p, spacer))
@@ -98,6 +101,9 @@ void ImageRasterizer::load()
int imgw = imageData->getWidth();
int imgh = imageData->getHeight();
// We don't want another thread modifying our ImageData mid-parse.
love::thread::Lock lock(imageData->getMutex());
// Set the only metric that matters
metrics.height = imgh;