Skip to main content

AbstractPainter Cached Image Clip

No replies
Joined: 2005-05-13

I was looking at the updates to SwingX since the last time that I updated, and I noticed a change that was committed to the AbstractPainter class:

@@ -381,7 +381,8 @@

<br />
                     cache = GraphicsUtilities.createCompatibleTranslucentImage(width, height);<br />
                 }<br />
                 Graphics2D gfx = cache.createGraphics();<br />
-                gfx.setClip(0, 0, width, height);<br />
+                //gfx.setClip(0, 0, width, height);<br />
+                gfx.setClip(g.getClip());</p>
<p>                 if (!invalidCache) {<br />
                     // If we are doing a repaint, but we didn't have to<br />

I am wondering why that change was made? (To set the gfx clip to g.getClip()?)

I think that it should be switched back to the old way (setClip(0,0,width,height) or remove the setClip entirely (the Graphics2D gfx object should already have a clip that is the same size as the image I think). The reason is that if the Painter had filled in it's entire image, it could be shared without any missing pixels.

If a cached Painter is being shared in several trees of Painters with different clipping regions, the second use of a cached Painter will get an image that doesn't necessarily match ITS clip. Since the Painter is cached, it won't repaint the cached image with "new" Graphics clip.

Additionally, there is the "g.drawImage(cache, 0, 0, null);" after the image is painted which should do the clipping of the image to fit within the passed in Graphics clip anyway.