javauis/lcdui_qt/src/javax/microedition/lcdui/Image.java
changeset 35 85266cc22c7f
parent 26 dc7c549001d5
child 78 71ad690e91f5
--- a/javauis/lcdui_qt/src/javax/microedition/lcdui/Image.java	Thu May 27 12:49:31 2010 +0300
+++ b/javauis/lcdui_qt/src/javax/microedition/lcdui/Image.java	Fri Jun 11 13:33:44 2010 +0300
@@ -43,6 +43,10 @@
     // buffer has package visibility so that it can be used as
     // a lock in other classes
     ImageBuffer graphicsBuffer;
+    
+    // Graphics for transferring instance
+    // between application and UI thread
+    Graphics tempGraphics;
 
     /**
      * Constructor.
@@ -647,14 +651,33 @@
     }
 
     /**
-     * Synchronizes any pending draw commands to this image
+     * Synchronizes any pending draw commands to this image. The buffer sync 
+     * must be executed in UI thread and if this method is not requested to switch to
+     * UI thread, the caller must take care of serializing the call over the graphicsBuffer
+     * of this instance.
+     * 
+     * @param switchToUIThread If true the sync is run in UI thread, oherwise
+     *        caller must take care of switching to UI thread
      */
-    void sync()
+    void sync(boolean switchToUIThread)
     {
-        synchronized(graphicsBuffer)
-        {
-            graphicsBuffer.sync();
-        }
+    	if(switchToUIThread) 
+		{
+    	    synchronized(graphicsBuffer)
+            {
+                ESWTUIThreadRunner.safeSyncExec(new Runnable()
+                {
+                    public void run()
+                    {
+                        graphicsBuffer.sync();
+                    }
+                });
+            }
+         } 
+    	else 
+    	{
+    		graphicsBuffer.sync();
+    	}
     }
 
     /**
@@ -762,7 +785,6 @@
 
         synchronized(graphicsBuffer)
         {
-            graphicsBuffer.sync();
             final int[] localRgbData = rgbData;
             final int localOffset = offset;
             final int localLength = length;
@@ -774,6 +796,7 @@
             {
                 public void run()
                 {
+                	graphicsBuffer.sync();
                     org.eclipse.swt.internal.qt.graphics.Image cgImage = Internal_GfxPackageSupport.getImage(eswtImage);
                     cgImage.getRGB(localRgbData, localOffset, localLength,
                                    localX, localY, localW, localH);
@@ -791,8 +814,16 @@
     public Graphics getGraphics()
     {
         if(mutable)
-        {
-            return graphicsBuffer.getGraphics();
+        {	
+        	tempGraphics = null;
+        	ESWTUIThreadRunner.safeSyncExec(new Runnable()
+            {
+                public void run()
+                {
+        	        tempGraphics =  graphicsBuffer.getGraphics();
+                }
+            });
+            return tempGraphics;
         }
         throw new IllegalStateException(MsgRepository.IMAGE_EXCEPTION_IMMUTABLE);
     }