Author: noelgrandin
Date: Thu Oct 20 14:03:31 2011
New Revision: 1186817
URL: http://svn.apache.org/viewvc?rev=1186817&view=rev
Log:
second attempt to fix cached volatile buffer drawing
Modified:
pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java
URL:
http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java?rev=1186817&r1=1186816&r2=1186817&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java Thu Oct 20
14:03:31 2011
@@ -93,7 +93,7 @@ public abstract class ApplicationContext
private boolean disableVolatileBuffer = false;
private boolean debugPaint = false;
private java.awt.image.VolatileImage volatileImage = null;
- private java.awt.image.VolatileImage volatileImageClipBounds = null;
+ private GraphicsConfiguration volatileImageGC = null;
private Random random = null;
@@ -513,37 +513,43 @@ public abstract class ApplicationContext
// Paint the display into a volatile offscreen buffer
GraphicsConfiguration gc = graphics.getDeviceConfiguration();
java.awt.Rectangle gcBounds = gc.getBounds();
- if (volatileImage == null) {
+ if (volatileImage == null || volatileImageGC != gc) {
+ if (volatileImage != null) {
+ volatileImage.flush();
+ }
volatileImage =
gc.createCompatibleVolatileImage(gcBounds.width, gcBounds.height,
Transparency.OPAQUE);
+ // we need to create a new volatile if the GC changes
+ volatileImageGC = gc;
}
// If we have a valid volatile image, attempt to paint the
// display to it
- if (volatileImage != null) {
- int valid = volatileImage.validate(gc);
-
- if (valid == java.awt.image.VolatileImage.IMAGE_OK
- || valid == java.awt.image.VolatileImage.IMAGE_RESTORED) {
- java.awt.Rectangle clipBounds = graphics.getClipBounds();
- Graphics2D volatileImageGraphics =
volatileImage.createGraphics();
- volatileImageGraphics.setClip(clipBounds.x, clipBounds.y,
clipBounds.width, clipBounds.height);
+ int valid = volatileImage.validate(gc);
- try {
- paintDisplay(volatileImageGraphics);
- graphics.drawImage(volatileImage,
- clipBounds.x, clipBounds.y, clipBounds.width,
clipBounds.height,
- clipBounds.x, clipBounds.y, clipBounds.width,
clipBounds.height,
- this);
- } finally {
- volatileImageGraphics.dispose();
- }
+ if (valid == java.awt.image.VolatileImage.IMAGE_OK
+ || valid == java.awt.image.VolatileImage.IMAGE_RESTORED) {
+ java.awt.Rectangle clipBounds = graphics.getClipBounds();
+ Graphics2D volatileImageGraphics =
volatileImage.createGraphics();
+ volatileImageGraphics.setClip(clipBounds.x, clipBounds.y,
clipBounds.width, clipBounds.height);
- painted = !volatileImage.contentsLost();
- } else {
- volatileImage.flush();
- volatileImage = null;
+ try {
+ paintDisplay(volatileImageGraphics);
+ // this drawImage method doesn't use width and height
+ int x2 = clipBounds.x + clipBounds.width;
+ int y2 = clipBounds.y + clipBounds.height;
+ graphics.drawImage(volatileImage,
+ clipBounds.x, clipBounds.y, x2, y2,
+ clipBounds.x, clipBounds.y, x2, y2,
+ this);
+ } finally {
+ volatileImageGraphics.dispose();
}
+
+ painted = !volatileImage.contentsLost();
+ } else {
+ volatileImage.flush();
+ volatileImage = null;
}
return painted;