Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT canvas, images and tranparancies performance issue
SWT canvas, images and tranparancies performance issue [message #452160] Mon, 14 March 2005 19:12 Go to next message
Builder Chad is currently offline Builder ChadFriend
Messages: 5
Registered: July 2009
Junior Member
Hi,

I have tried implementing a tile based mapping tool for a little game I
am writting using double buffering and have come across some poor
performance results.

canvas = new Canvas(shell, SWT.NO_BACKGROUND);
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent event) {

Image image = new Image(shell.getDisplay(), canvas.getBounds());
GC gcImage = new GC(image);
gcImage.setBackground(event.gc.getBackground());
gcImage.fillRectangle(image.getBounds());

int lx = 0;
int ly = 0;

int i;
int j;

boolean indent = false;

for (i = 0; i < 20; i++) {
if (indent) {
lx = 32;
indent = false;
} else {
lx = 0;
indent = true;
}

for (j = 0; j < 12; j++) {
gcImage.drawImage(ImageManager.t1, lx, ly);
lx += 64;
}
ly += 16;
}

gcImage.drawImage(ImageManager.t2, x, y);
event.gc.drawImage(image, 0, 0);

image.dispose();
gcImage.dispose();
}
});
}


This uses simple isometric tiles (64x32). ImageManager.t1 is repeated
across the whole canvase and ImageManager.t2 is used just to demonstrate
animation (x and y are set outside by a runnable to make that tile move
around)

This code is infact straight out of "The definitive guide to SWT and
JFace" by Robert Warner with the addition of the loop to draw my tiles.

If I use t1 and t2 as they are (without setting a transparancy bit) then
performance is great.

But if I extract the ImageData and set transparentPixel then performance
drops off to an unacceptable level.

Even if I extract the ImageData and create an new image from that
without even setting transparentPixel performance is notably reduced.

public class ImageManager {
private Image blob;
static Image t1;
static Image t2;

ImageManager(Display display) {
blob = new Image(display, "all_tiles.png");

Image xt1 = new Image(display, 64, 32);
ImageData tData = xt1.getImageData();
int purplePixel =
tData.palette.getPixel(new RGB(127,0,127));
tData.transparentPixel = purplePixel;
t1 = new Image(display, tData);

Image xt2 = new Image(display, 64, 32);
ImageData tData2 = xt2.getImageData();
tData2.transparentPixel = purplePixel;
t2 = new Image(display, tData2);

GC dest = new GC(t1);
dest.drawImage(blob, 65, 0, 64, 32, 0, 0, 64, 32);

GC dest2 = new GC(t2);
dest2.drawImage(blob, 0, 0, 64, 32, 0, 0, 64, 32);

}
}


Am I doing something wrong? Or should I be going for the Java2D
solution as demonstrated by Yannick Saillet:

http://www-128.ibm.com/developerworks/java/library/j-2dswt/

I wanted to avoid using any AWT stuff but it looks like I may have to
for this project. But from the above article it looks like there is a
huge bottleneck in first painting on an AWT surface, then copying to an
SWT image and then to the canvas - 2 copy ops instead of just one.

If you have any ideas or advice please let me know.

Thanks,

Chad.
Re: SWT canvas, images and tranparancies performance issue [message #452237 is a reply to message #452160] Tue, 15 March 2005 14:32 Go to previous messageGo to next message
Billy Biggs is currently offline Billy BiggsFriend
Messages: 94
Registered: July 2009
Member
Builder Chad wrote:
> Hi,
>
> I have tried implementing a tile based mapping tool for a little game I
> am writting using double buffering and have come across some poor
> performance results.

Can you please post the full code snippet to a bug at
bugs.eclipse.org/bugs/ against Platform > SWT? I wonder if something
bad is going on...

-Billy
Re: SWT canvas, images and tranparancies performance issue [message #452260 is a reply to message #452237] Wed, 16 March 2005 09:51 Go to previous message
Builder Chad is currently offline Builder ChadFriend
Messages: 5
Registered: July 2009
Junior Member
Billy Biggs wrote:

> Builder Chad wrote:
>
>> Hi,
>>
>> I have tried implementing a tile based mapping tool for a little game
>> I am writting using double buffering and have come across some poor
>> performance results.
>
>
> Can you please post the full code snippet to a bug at
> bugs.eclipse.org/bugs/ against Platform > SWT? I wonder if something
> bad is going on...
>
> -Billy


Ok that has been posted as a bug. Thanks Billy.
Previous Topic:SWT Widgets - All are native???
Next Topic:Text editor
Goto Forum:
  


Current Time: Mon Jul 22 21:05:51 GMT 2019

Powered by FUDForum. Page generated in 0.01401 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top