Skip to content

Long refresh time for large Swing screens #506

@ptziegler

Description

@ptziegler

Creating the snapshot of large screens (10000x10000 pixels) takes 4-5 seconds. This doesn't only affect the initial creation, but also any modifications done to the screen.

According to VisualVM, the problem is located in the SwingScreenshotMaker, during the conversion from a BufferedImage to an SWT Image.

image

Corresponding Code Snippet:

public static Image convertImage_AWT_to_SWT(final java.awt.Image image) throws Exception {
        return SwingUtils.runObjectLaterAndWait(new RunnableObjectEx<Image>() {
	        public Image runObject() throws Exception {
		        BufferedImage bufferedImage = (BufferedImage) image;
		        int imageWidth = bufferedImage.getWidth();
		        int imageHeight = bufferedImage.getHeight();
		        Image swtImage = new Image(null, imageWidth, imageHeight);
		        final ImageData swtImageData = swtImage.getImageData();
		        try {
			        ImageProducer source = image.getSource();
			        source.startProduction(new AwtToSwtImageConverter(bufferedImage, swtImageData));
			        return new Image(null, swtImageData);
		        } catch (Throwable e) {
			        // fallback to ImageIO.
			        return ImageUtils.convertToSWT(image);
		        } finally {
			        swtImage.dispose();
		        }
	        }
        });
}

The problematic lines are Image swtImage = new Image(null, imageWidth, imageHeight); and final ImageData swtImageData = swtImage.getImageData();.
Effectively, this just creates a blank ImageData object with given width and height. So we might get away by simply creating the ImageData object directly, instead of going via the Image.

Swing Screen:

public class Test {
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setBounds(100, 100, 10000, 10000);
		frame.setVisible(true);
	}
}

I assume a similar problem exists for smaller, but more complex screens.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions