javauis/m2g_qt/javasrc/com/nokia/microedition/m2g/M2GScalableGraphics.java
changeset 87 1627c337e51e
parent 80 d6dafc5d983f
--- a/javauis/m2g_qt/javasrc/com/nokia/microedition/m2g/M2GScalableGraphics.java	Fri Oct 15 12:29:39 2010 +0300
+++ b/javauis/m2g_qt/javasrc/com/nokia/microedition/m2g/M2GScalableGraphics.java	Fri Oct 29 11:49:32 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -29,7 +29,7 @@
 import com.nokia.mj.impl.nokialcdui.LCDUIInvoker;
 import org.eclipse.swt.internal.qt.GCData;
 import org.eclipse.swt.internal.qt.graphics.GraphicsContext;
-import org.eclipse.swt.internal.extension.GraphicsUtil; 
+import org.eclipse.swt.internal.extension.GraphicsUtil;
 
 /*
  * ScalableGraphics
@@ -40,23 +40,7 @@
     //--------------------------------------------------
     // STATIC CONSTANTS
     //--------------------------------------------------
-    // Exception text
-    /* Optimization: static finals changed to local variables
-    private static final String ALPHA_OUT_OF_RANGE_ESTR =
-        "The alpha is out of range";
-    private static final String INVALID_TARGET_ESTR =
-        "The target is invalid";
-    private static final String MODE_INVALID_ESTR =
-        "The mode is invalid";
-    private static final String NULL_IMAGE_ESTR =
-        "The image is null";
-    private static final String NULL_TARGET_ESTR =
-        "The target is null";
-    private static final String TARGET_ALREADY_BOUND_ESTR =
-        "Target is already bound";
-    private static final String TARGET_NOT_BOUND_ESTR =
-        "Target is not bound";
-    */
+
     // Transparency alpha max and min limits
     private static final float MAX_TRANSPARENCY_ALPHA = 1.0f;
     private static final float MIN_TRANSPARENCY_ALPHA = 0.0f;
@@ -69,8 +53,8 @@
     private Graphics iTargetGraphics;
     private Rectangle iSurfaceRectangle;
     private Rectangle iFinalESWTSurfaceRectangle;
-    
-     int iSurfaceHandle;
+
+    int iSurfaceHandle;
 
     //--------------------------------------------------
     // METHODS
@@ -81,7 +65,7 @@
     public M2GScalableGraphics()
     {
         super();
-        
+
         doConstruct();
     }
     /**
@@ -89,91 +73,79 @@
      */
     public synchronized void bindTarget(Object target)
     {
-    	
-    	if (target == null )
-    	{
-    		throw new NullPointerException(/*SF*/"The target is null"/*SF*/);
-    	}
-    	
-    	if (target instanceof org.eclipse.swt.graphics.GC)
-        	{
-    		
-			final GC finalGc = (GC)target;
+        if (target == null)
+        {
+            throw new NullPointerException(/*SF*/"The target is null"/*SF*/);
+        }
+
+        if (target instanceof org.eclipse.swt.graphics.GC)
+        {
+            final GC finalGc = (GC)target;
+
+            // Execute in UI thread
+            Platform.executeInUIThread(
+                new M2GRunnableQt()
+            {
+                public void doRun()
+                {
+                    iFinalESWTSurfaceRectangle = GraphicsUtil.startExternalRendering(finalGc);
+
+                    // Get GCData from GC
+                    iSurfaceHandle = GraphicsUtil.getWindowSurface(finalGc).getHandle();
+                    _bind(getHandle(), iSurfaceHandle);
+                }
+            });
 
-        	// Execute in UI thread     
-        	Platform.executeInUIThread(
-                new M2GRunnableQt() {
-                    public void doRun() {
-                    	iFinalESWTSurfaceRectangle = GraphicsUtil.startExternalRendering(finalGc);
-                    	
-                    	// Get GCData from GC
-                    	/*TODO check for this cahnge GCData gcData = ((org.eclipse.swt.graphics.GC)finalGc).getGCData();    
-                    	// Get internalGC (Graphicscontext), WindowSurface and the WindowSurface handle for native access
-                        iSurfaceHandle = gcData.internalGc.getWindowSurface().getHandle();*/
-                    	iSurfaceHandle = GraphicsUtil.getWindowSurface(finalGc).getHandle();
-                        
-                        _bind(getHandle(), iSurfaceHandle);
-                        
-                      }
-                      });
-                    //  currentTarget = target;
-        		iTargetGC = (GC)finalGc;
-		    // Handling for LCDUI Graphics
-		    //
-		    }
-//Change accordingly to M3G not as site content.		    
-		    else if (target instanceof javax.microedition.lcdui.Graphics)
-		    {
-		    	Graphics g = (Graphics)target;
-		    	final Graphics finalG = g;
-		    	iSurfaceRectangle = LCDUIInvoker.startExternalRendering( finalG );
-		    	 // Execute in UI thread     
-			        Platform.executeInUIThread(
-			                new M2GRunnableQt() {
-			                    public void doRun() {
-														
-			                    	  
-			                    	
-                        		iSurfaceHandle = LCDUIInvoker.getWindowSurface(finalG).getHandle();
-                        		
-                        		// Flush Canvas
-								            //M2GManager.flushDisplayBuffer();
-		                        _bind(getHandle(), iSurfaceHandle);
-		                        
+            iTargetGC = (GC)finalGc;
+            // Handling for LCDUI Graphics
+        }
+        else if (target instanceof javax.microedition.lcdui.Graphics)
+        {
+            Graphics g = (Graphics)target;
+            final Graphics finalG = g;
+            iSurfaceRectangle = LCDUIInvoker.startExternalRendering(finalG);
+            // Execute in UI thread
+            Platform.executeInUIThread(
+                new M2GRunnableQt()
+            {
+                public void doRun()
+                {
 
-			                    }
-			                  });
-			                  
-			                  iTargetGraphics  = (Graphics)finalG;
-		    	}
-			         
-	         else {
-			        throw new IllegalArgumentException();
-			    }
-    	
-    	//TODO Check for : when to give this exception java.lang.IllegalStateException - if target is already bound.
-    
-  }
-    	
+                    iSurfaceHandle = LCDUIInvoker.getWindowSurface(finalG).getHandle();
+
+                    // Flush Canvas
+                    //M2GManager.flushDisplayBuffer();
+                    _bind(getHandle(), iSurfaceHandle);
+                }
+            });
 
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+            iTargetGraphics  = (Graphics)finalG;
+        }
+
+        else
+        {
+            throw new IllegalArgumentException();
+        }
+    }
 
     /**
      * @see com.nokia.microedition.m2g.M2GObject#doConstruct()
      */
     public void doConstruct()
     {
-      super.doConstruct();
-      
-    	 // Execute in UI thread     
-	    Platform.executeInUIThread(
-            new M2GRunnableQt() {
-                public void doRun() {
-										        setHandle(_createRenderContext(
-										                      getNativeSVGProxyHandle() ));
-										        // Add object to the live objects container
-										      }
-										    });
+        super.doConstruct();
+
+        // Execute in UI thread
+        Platform.executeInUIThread(
+            new M2GRunnableQt()
+        {
+            public void doRun()
+            {
+                setHandle(_createRenderContext(
+                              getNativeSVGProxyHandle()));
+                // Add object to the live objects container
+            }
+        });
         register(this);
     }
 
@@ -182,16 +154,18 @@
      */
     public synchronized void doCleanup()
     {
-    	
- 		    	 // Execute in UI thread     
-			        Platform.executeInUIThread(
-			                new M2GRunnableQt() {
-			                    public void doRun() {  	
-																			        _deleteRenderContext(
-																			            getHandle() );
-																			          }
-																			       }
-																			    );      
+
+        // Execute in UI thread
+        Platform.executeInUIThread(
+            new M2GRunnableQt()
+        {
+            public void doRun()
+            {
+                _deleteRenderContext(
+                    getHandle());
+            }
+        }
+        );
         resetHandles();
         iTargetGC = null;
         iTargetGraphics = null;
@@ -202,53 +176,49 @@
      */
     public synchronized void releaseTarget()
     {
-    	
-      if (iTargetGC != null)
-      {
-      
-			Platform.executeInUIThread(
-            new M2GRunnableQt() {
-             public void doRun() {
-            	 						   GraphicsUtil.endExternalRendering(iTargetGC);
-            	      				      _release(iSurfaceHandle, getHandle());
-            	      				    }
-            	      				  });
+        if (iTargetGC != null)
+        {
+
+            Platform.executeInUIThread(
+                new M2GRunnableQt()
+            {
+                public void doRun()
+                {
+                    GraphicsUtil.endExternalRendering(iTargetGC);
+                    _release(iSurfaceHandle, getHandle());
+                }
+            });
             iTargetGC = null;
         }
-			else if (iTargetGraphics != null )
-		    {
-				
-				
-				final Graphics finalG = iTargetGraphics;
-				Platform.executeInUIThread(
-	            new M2GRunnableQt() {
-	             public void doRun() {
-	            			_release(iSurfaceHandle, getHandle());
-	            		}
-	            	});
-				LCDUIInvoker.endExternalRendering( iTargetGraphics );
-				
-        iTargetGraphics = null;
+        else if (iTargetGraphics != null)
+        {
+            final Graphics finalG = iTargetGraphics;
+            Platform.executeInUIThread(
+                new M2GRunnableQt()
+            {
+                public void doRun()
+                {
+                    _release(iSurfaceHandle, getHandle());
+                }
+            });
+            LCDUIInvoker.endExternalRendering(iTargetGraphics);
+
+            iTargetGraphics = null;
         }
-      else 
-      	{
-  			
-  		   // check for invalid Graphics TODO this exception is getting trough when we trying to bind.s
+        else
+        {
             throw new IllegalStateException(/*SF*/"Target is not bound"/*SF*/);
-      	}
+        }
 
     }
+
     public synchronized void render(
         int x, int y, ScalableImage image, boolean aUseNativeClear)
     {
-				
-
         iUseNativeClear = aUseNativeClear ? 1 : 0;
         render(x, y, image);
         iUseNativeClear = 0;
-        
-        
-        
+
     }
 
     /**
@@ -256,14 +226,14 @@
      */
     public synchronized void render(int x, int y, ScalableImage image)
     {
-    		
+
         if (image == null)
         {
             Logger.ELOG(Logger.EJavaUI, "render() - exception: "
                         + /*SF*/"The target is null"/*SF*/);
             throw new NullPointerException(/*SF*/"The target is null"/*SF*/);
         }
-       if (iTargetGC != null)
+        if (iTargetGC != null)
         {
             final M2GDocument finalDoc = (M2GDocument)((SVGImage)image).getDocument();
             // Get synchronized svg image data
@@ -273,16 +243,15 @@
             {
                 return;
             }
-            // Calculate clip dimensions TODO check the new clipping rect provided from StartExternalRendering API.s
-            //Rectangle clipRect = iTargetGC.getClipping();
+
             Rectangle clipRect = iFinalESWTSurfaceRectangle;
-            
+
             final int finalClipX = clipRect.x;
             final int finalClipY = clipRect.y;
             final int finalClipW = clipRect.width;
             final int finalClipH = clipRect.height;
-            
-            
+
+
             // if none of the svg image is visible due to clipping then don't
             // bother to call render
             if ((x >= (finalClipX + finalClipW)) || (y >= (finalClipY + finalClipH)))
@@ -297,67 +266,60 @@
                            "render() - svg image isn't visible due to clipping");
                 return;
             }
-            
+
+
+            final int finalX = x;
+            final int finalY = y;
+
+            // Execute in UI thread
+            Platform.executeInUIThread(
+                new M2GRunnableQt()
+            {
+                public void doRun()
+                {
+
+                    final int[] finalData = _renderESWT(getHandle(),
+                                                        finalDoc.getHandle(), finalX, finalY,
+                                                        finalClipX, finalClipY, finalClipW, finalClipH, finalSvgW, finalSvgW,
+                                                        finalDoc.getRootElement().getCurrentTime(),
+                                                        iUseNativeClear);
 
-						final int finalX = x;            
-						final int finalY = y; 
-						         
-        		    	 // Execute in UI thread   
-	        Platform.executeInUIThread(
-	                new M2GRunnableQt() {
-	                    public void doRun() {         
-	                    	
-	                    								
-	                    									
-																			final int[] finalData = _renderESWT(getHandle(),
-											                                     finalDoc.getHandle(), finalX, finalY,
-											                                     finalClipX, finalClipY, finalClipW, finalClipH, finalSvgW, finalSvgW,
-											                                     finalDoc.getRootElement().getCurrentTime(),
-											                                     iUseNativeClear);
-																									                                     
-																				int[] bitmapHandles;
-														            bitmapHandles = new int[4];
-														            for (int i = 0; i < 4; i++)
-														            {
-														                bitmapHandles[i] = finalData[i];
-														            }
-														            int[] renderData;
-														            renderData = new int[6];
-														            for (int i = 0; i < 6; i++)
-														            {
-														                renderData[i] = finalData[i+4];
-														            }
-														            //iTargetGC.internal_drawM2GImage(bitmapHandles, renderData, iUseNativeClear);
+                    int[] bitmapHandles;
+                    bitmapHandles = new int[4];
+                    for (int i = 0; i < 4; i++)
+                    {
+                        bitmapHandles[i] = finalData[i];
+                    }
+                    int[] renderData;
+                    renderData = new int[6];
+                    for (int i = 0; i < 6; i++)
+                    {
+                        renderData[i] = finalData[i+4];
+                    }
 
-																					}});											                                     
-            
+                }
+            });
+
         }//if(true)
-		else if (iTargetGraphics != null)
-		    {
-		    	
-   	    		
+        else if (iTargetGraphics != null)
+        {
+
+
             final M2GDocument finalDoc = (M2GDocument)((SVGImage)image).getDocument();
             // Get synchronized svg image data
             final int finalSvgW  = image.getViewportWidth();
             final int finalSvgH = image.getViewportHeight();
             if ((finalSvgW == 0) || (finalSvgH == 0))
-            {	
-            	
+            {
+
                 return;
             }
-            
-            
-            //TODO as we are using Surface rectangle provided by StartExternalRendering as Clip Rectangle.
+
             final int finalClipX = iSurfaceRectangle.x;
             final int finalClipY = iSurfaceRectangle.y;
             final int finalClipW  = iSurfaceRectangle.width;
             final int finalClipH = iSurfaceRectangle.height;
 
-            // Calculate clip dimensions
-            /*final int finalClipX = iTargetGraphics.getClipX() + iTargetGraphics.getTranslateX();
-            final int finalClipY = iTargetGraphics.getClipY() + iTargetGraphics.getTranslateY();
-            final int finalClipW  = iTargetGraphics.getClipWidth();
-            final int finalClipH = iTargetGraphics.getClipHeight();*/
             // if none of the svg image is visible due to clipping then don't
             // bother to call render
             if ((x >= (finalClipX + finalClipW)) || (y >= (finalClipY + finalClipH)))
@@ -372,31 +334,30 @@
                            "render() - svg image isn't visible due to clipping");
                 return;
             }
-            
-				final int finalX = x;            
-				final int finalY = y;
-				
-				
+
+            final int finalX = x;
+            final int finalY = y;
 
-      		    	 // Execute in UI thread     
-        Platform.executeInUIThread(
-                new M2GRunnableQt() {
-                    public void doRun() {
-								            _renderLCDUI(getHandle(), finalDoc.getHandle(), finalX, finalY,
-								                         finalClipX, finalClipY, finalClipW, finalClipH, finalSvgW, finalSvgH,
-								                         finalDoc.getRootElement().getCurrentTime());
-								                       }});
-								                       
-				
+            // Execute in UI thread
+            Platform.executeInUIThread(
+                new M2GRunnableQt()
+            {
+                public void doRun()
+                {
+                    _renderLCDUI(getHandle(), finalDoc.getHandle(), finalX, finalY,
+                                 finalClipX, finalClipY, finalClipW, finalClipH, finalSvgW, finalSvgH,
+                                 finalDoc.getRootElement().getCurrentTime());
+                }
+            });
         }
 
-       else 
-        	{
-                Logger.ELOG(Logger.EJavaUI, "render() - exception: "
-                + /*SF*/"Target is not bound"/*SF*/);//TODO for time being commented.s
-                throw new IllegalStateException(/*SF*/"Target is not bound"/*SF*/);
-        	}
-        	
+        else
+        {
+            Logger.ELOG(Logger.EJavaUI, "render() - exception: "
+                        + /*SF*/"Target is not bound"/*SF*/);
+            throw new IllegalStateException(/*SF*/"Target is not bound"/*SF*/);
+        }
+
     }
 
     /**
@@ -407,14 +368,16 @@
         if ((mode == ScalableGraphics.RENDERING_QUALITY_LOW) ||
                 (mode == ScalableGraphics.RENDERING_QUALITY_HIGH))
         {
-        	final int finalMode = mode;
-        			    	 // Execute in UI thread     
-			        Platform.executeInUIThread(
-			                new M2GRunnableQt() {
-			                    public void doRun() {
-											            _setRenderingQuality(getHandle(), finalMode);
-											          }
-											        });
+            final int finalMode = mode;
+            // Execute in UI thread
+            Platform.executeInUIThread(
+                new M2GRunnableQt()
+            {
+                public void doRun()
+                {
+                    _setRenderingQuality(getHandle(), finalMode);
+                }
+            });
         }
         else
         {
@@ -431,15 +394,17 @@
     {
         if (alpha >= MIN_TRANSPARENCY_ALPHA && alpha <= MAX_TRANSPARENCY_ALPHA)
         {
-        	final float finalAlpha = alpha;
-        			    	 // Execute in UI thread     
-			        Platform.executeInUIThread(
-			                new M2GRunnableQt() {
-			                    public void doRun() {
-            															_setTransparency(getHandle(), finalAlpha);
-            														}
-            													}
-            													);
+            final float finalAlpha = alpha;
+            // Execute in UI thread
+            Platform.executeInUIThread(
+                new M2GRunnableQt()
+            {
+                public void doRun()
+                {
+                    _setTransparency(getHandle(), finalAlpha);
+                }
+            }
+            );
         }
         else
         {
@@ -460,17 +425,17 @@
     private native void _deleteRenderContext(
         int aRenderContextHandle);
     private native int _release(
-       int aSurfaceHandle ,int aRenderContextHandle);
+        int aSurfaceHandle ,int aRenderContextHandle);
     private native int _renderLCDUI(
-       int aRenderContextHandle, int aDocumentHandle,
+        int aRenderContextHandle, int aDocumentHandle,
         int aX, int aY, int aClipX, int aClipY, int aClipW, int aClipH,
         int aSvgW, int aSvgH, float aCurrentTime);
     private native int[] _renderESWT(
-       int aRenderContextHandle, int aDocumentHandle,
+        int aRenderContextHandle, int aDocumentHandle,
         int aX, int aY, int aClipX, int aClipY, int aClipW, int aClipH,
         int aSvgW, int aSvgH, float aCurrentTime, int iUseNativeClear);
     private native void _setRenderingQuality(
-       int aRenderContextHandle, int aMode);
+        int aRenderContextHandle, int aMode);
     private native void _setTransparency(
-       int aRenderContextHandle, float aAlpha);
+        int aRenderContextHandle, float aAlpha);
 }