client: copy screenshot image in draw manager callback

The image backed by the client buffer which will change on the next
frame, however the screenshot plugin uses both executor thread and EDT
thread to paint the full screenshot, and so it requires the image will
not change. Note the gpu plugin already returns a new image because it
has to pull it out of the GL.
This commit is contained in:
Adam
2019-01-03 14:11:27 -05:00
parent 4ec50046c7
commit 8e5da844b6

View File

@@ -347,7 +347,7 @@ public class Hooks implements Callbacks
: RenderingHints.VALUE_INTERPOLATION_BILINEAR);
stretchedGraphics.drawImage(image, 0, 0, stretchedDimensions.width, stretchedDimensions.height, null);
finalImage = image = stretchedImage;
finalImage = stretchedImage;
}
else
{
@@ -355,9 +355,27 @@ public class Hooks implements Callbacks
}
// Draw the image onto the game canvas
graphics.drawImage(image, 0, 0, client.getCanvas());
graphics.drawImage(finalImage, 0, 0, client.getCanvas());
drawManager.processDrawComplete(() -> finalImage);
// finalImage is backed by the client buffer which will change soon. make a copy
// so that callbacks can safely use it later from threads.
drawManager.processDrawComplete(() -> copy(finalImage));
}
/**
* Copy an image
* @param src
* @return
*/
private static Image copy(Image src)
{
final int width = src.getWidth(null);
final int height = src.getHeight(null);
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics graphics = image.getGraphics();
graphics.drawImage(src, 0, 0, width, height, null);
graphics.dispose();
return image;
}
@Override