This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gui] [PATCH] Fixes to MemoryImageSource


Hello,

I committed the following patch to the java-gui-branch.  It mainly
reimplements the private field "consumers" using Vector instead of
Hashtable.  This is because enumeration on Hashtable is not thread-safe,
and can have unexpected behaviour if the underlying Hashtable is changed
while we're enumerating through it.  With a couple other small fixes
that are included, this patch makes sure that calling imageComplete() on
the image consumers will behave correctly.

-David Jee

2004-07-12  David Jee  <djee@redhat.com>

        * gnu/java/awt/peer/gtk/GtkImagePainter.java
        (imageComplete): Call image.imageComplete().
        * java/awt/image/MemoryImageSource.java:
        Reimplement consumers as a Vector instead of a Hashtable.  This is
        because enumeration on a Hashtable is not thread-safe.
        (addConsumer): Adapt to Vector consumers.
        (isConsumer): Adapt to Vector consumers.
        (removeConsumer): Adapt to Vector consumers.
        (startProduction): Adapt to Vector consumers. Call imageComplete()
        with STATICIMAGEDONE flag instead of SINGLEFRAME flag.
        (newPixels): Adapt to Vector consumers.
        (sendPicture): Set the color model of the image consumer.
        (newPixels(IIII)): Adapt to Vector consumers.
        (newPixels(IIIIB)): Adapt to Vector consumers.


Index: gnu/java/awt/peer/gtk/GtkImagePainter.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkImagePainter.java,v
retrieving revision 1.2.18.3
diff -u -r1.2.18.3 GtkImagePainter.java
--- gnu/java/awt/peer/gtk/GtkImagePainter.java	11 Jun 2004 23:59:01 -0000	1.2.18.3
+++ gnu/java/awt/peer/gtk/GtkImagePainter.java	12 Jul 2004 18:36:48 -0000
@@ -246,5 +246,6 @@
   public void 
   imageComplete (int status)
   {
+    image.imageComplete(status);
   }
 }
Index: java/awt/image/MemoryImageSource.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/image/MemoryImageSource.java,v
retrieving revision 1.5.16.2
diff -u -r1.5.16.2 MemoryImageSource.java
--- java/awt/image/MemoryImageSource.java	18 May 2004 17:30:22 -0000	1.5.16.2
+++ java/awt/image/MemoryImageSource.java	12 Jul 2004 18:36:48 -0000
@@ -41,6 +41,7 @@
 import java.awt.Image;
 import java.util.Enumeration;
 import java.util.Hashtable;
+import java.util.Vector;
 
 public class MemoryImageSource implements ImageProducer 
 {
@@ -49,7 +50,8 @@
     private int pixeli[], width, height, offset, scansize;
     private byte pixelb[];
     private ColorModel cm;
-    private Hashtable props, consumers = new Hashtable();
+    private Hashtable props = new Hashtable();
+    private Vector consumers = new Vector();
 
     /**
        Constructs an ImageProducer from memory
@@ -126,10 +128,10 @@
      * <code>ImageProducer</code>.  
      */
     public synchronized void addConsumer(ImageConsumer ic) {
-	if (consumers.containsKey(ic))
+	if (consumers.contains(ic))
 	    return;
 
-	consumers.put(ic, ic);
+	consumers.addElement(ic);
     }
 
     /**
@@ -137,7 +139,7 @@
      * already registered with this <code>ImageProducer</code>.  
      */
     public synchronized boolean isConsumer(ImageConsumer ic) {
-	if (consumers.containsKey(ic))
+	if (consumers.contains(ic))
 	    return true;
 	return false;
     }
@@ -147,7 +149,7 @@
      * registered consumers for this <code>ImageProducer</code>.  
      */
     public synchronized void removeConsumer(ImageConsumer ic) {
-	consumers.remove(ic);
+	consumers.removeElement(ic);
     }
 
     /**
@@ -157,16 +159,16 @@
      * registered consumers.  
      */
     public void startProduction(ImageConsumer ic) {
-	if (!(consumers.containsKey(ic))) {
-	    consumers.put(ic, ic);
+	if (!(consumers.contains(ic))) {
+	    consumers.addElement(ic);
 	}        
-	Enumeration e = consumers.elements();
-	for( ; e.hasMoreElements(); ) {
-		ic = (ImageConsumer)e.nextElement();
-		sendPicture( ic );
-		ic.imageComplete( ImageConsumer.SINGLEFRAME );
-	    }	
 
+	Vector list = (Vector) consumers.clone();
+	for(int i = 0; i < list.size(); i++) {
+	    ic = (ImageConsumer) list.elementAt(i);
+	    sendPicture( ic );
+	    ic.imageComplete( ImageConsumer.STATICIMAGEDONE );
+	}	
     }
 
     /**
@@ -210,12 +212,12 @@
     {
 	if( animated == true ) {
 		ImageConsumer ic;
-		Enumeration e = consumers.elements();
-		for( ; e.hasMoreElements(); ) {
-			ic = (ImageConsumer)e.nextElement();
+		Vector list = (Vector) consumers.clone();
+		for(int i = 0; i < list.size(); i++) {
+			ic = (ImageConsumer) list.elementAt(i);
 			sendPicture( ic );
 			ic.imageComplete( ImageConsumer.SINGLEFRAME );
-		    }	
+		}	
 	    }
     }
 
@@ -227,6 +229,7 @@
 	    ic.setProperties( props );
 	}
 	ic.setDimensions(width, height);
+	ic.setColorModel(cm);
 	if( pixeli != null ) {
 	    ic.setPixels( 0, 0, width, height, cm, pixeli, offset, scansize );
 	} else {
@@ -249,9 +252,9 @@
 		    newPixels();
 		} else {
 		    ImageConsumer ic;
-		    Enumeration e = consumers.elements();
-		    for( ; e.hasMoreElements(); ) {
-			    ic = (ImageConsumer)e.nextElement();
+		    Vector list = (Vector) consumers.clone();
+		    for(int i = 0; i < list.size(); i++) {
+			    ic = (ImageConsumer) list.elementAt(i);
 			    ic.setHints( ImageConsumer.TOPDOWNLEFTRIGHT );
 			    if( props != null ) {
 				ic.setProperties( props );
@@ -294,9 +297,9 @@
 		    newPixels();
 		} else {
 		    ImageConsumer ic;
-		    Enumeration e = consumers.elements();
-		    for( ; e.hasMoreElements(); ) {
-			    ic = (ImageConsumer)e.nextElement();
+		    Vector list = (Vector) consumers.clone();
+		    for(int i = 0; i < list.size(); i++) {
+			    ic = (ImageConsumer) list.elementAt(i);
 			    ic.setHints( ImageConsumer.TOPDOWNLEFTRIGHT );
 			    if( props != null ) {
 				ic.setProperties( props );

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]