Skip to main content

Rendering optimization causes regression?

2 replies [Last post]
swpalmer
Offline
Joined: 2003-06-10
Points: 0

I've already filed a bug, but I figured I would mention it here where comments are more visible.

I've noticed a regression from 1.6.0_04 to 1.6.0_10b21 where my linear gradient paint is not updated properly after I translate the graphics context and setPaint then render in a loop.
Basically the first iteration of the loop works, but subsequent iterations appear to behave as if the gradient coordinates are not respecting the new translation.

e.g.

<br />
int x = 0;<br />
for(int y = 0; y < 100; y+=10) {<br />
g.translate(x,y);<br />
g.setPaint(gradient);<br />
g.draw(something);<br />
g.translate(-x,-y);<br />
//...<br />
}<br />

To work around it I have to set a different paint and draw with it such as:

<br />
int x = 0;<br />
for(int y = 0; y < 100; y+=10) {<br />
g.translate(x,y);<br />
g.setPaint(gradient);<br />
g.draw(something);<br />
g.translate(-x,-y);<br />
g.setPaint(Color.BLACK);<br />
g.drawRect(0,0,0,0);<br />
}<br />

I assume the setPaint call in the first, failing case doesn't think it has to do anything because it is the same paint that is already set. It's missing the fact that the transform as changed.

I'm not entirely sure if I should need to re-set the paint in the first place.. should the gradients coordinates follow the transformed coordinate space anyway? My original code needed the setPaint call to be in the loop because there was conditional drawing afterwards inside the loop body. Either way.. it works as I expected in earlier releases of Java 6.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
trembovetski
Offline
Joined: 2003-12-31
Points: 0

Thanks for the bug report. I have integrated the fix into b23:
6689025: Graphics2D.setPaint() doesn't work if transform has changed but paint hasn't

Dmitri

swpalmer
Offline
Joined: 2003-06-10
Points: 0

I'm on the 2d-bugupdates email list... I thought that might have been you working on it ;-)

Thanks.