You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-commits@xmlgraphics.apache.org by dv...@apache.org on 2007/02/08 09:23:21 UTC

svn commit: r504819 - in /xmlgraphics/batik/trunk/sources/org/apache/batik: bridge/ ext/awt/geom/ gvt/renderer/ util/

Author: dvholten
Date: Thu Feb  8 00:23:19 2007
New Revision: 504819

URL: http://svn.apache.org/viewvc?view=rev&rev=504819
Log:
1.) release some referenced objects in dispose()
2.) drop some trailing whitespace

Modified:
    xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/AbstractGraphicsNodeBridge.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/BridgeContext.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/BridgeEventSupport.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/SVGTextElementBridge.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/ext/awt/geom/ExtendedGeneralPath.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/gvt/renderer/MacRenderer.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/gvt/renderer/StaticRenderer.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/util/SoftReferenceCache.java

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/AbstractGraphicsNodeBridge.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/AbstractGraphicsNodeBridge.java?view=diff&rev=504819&r1=504818&r2=504819
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/AbstractGraphicsNodeBridge.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/AbstractGraphicsNodeBridge.java Thu Feb  8 00:23:19 2007
@@ -68,11 +68,11 @@
  * @version $Id$
  */
 public abstract class AbstractGraphicsNodeBridge extends AnimatableSVGBridge
-    implements SVGContext, 
-               BridgeUpdateHandler, 
-               GraphicsNodeBridge, 
+    implements SVGContext,
+               BridgeUpdateHandler,
+               GraphicsNodeBridge,
                ErrorConstants {
-    
+
     /**
      * The graphics node constructed by this bridge.
      */
@@ -87,7 +87,7 @@
      * The unit context for length conversions.
      */
     protected UnitProcessor.Context unitContext;
-    
+
     /**
      * Constructs a new abstract bridge.
      */
@@ -302,7 +302,7 @@
     }
 
     /**
-     * Invoked when an MutationEvent of type 'DOMCharacterDataModified' 
+     * Invoked when an MutationEvent of type 'DOMCharacterDataModified'
      * is fired.
      */
     public void handleDOMCharacterDataModified(MutationEvent evt) {
@@ -315,6 +315,8 @@
         SVGOMElement elt = (SVGOMElement)e;
         elt.setSVGContext(null);
         ctx.unbind(e);
+
+        bboxShape = null;
     }
 
     /**
@@ -488,7 +490,7 @@
             return null;
         }
         Shape s = node.getOutline();
-        
+
         if ((bboxShape != null) && (s == bboxShape.get())) return bbox;
         bboxShape = new SoftReference(s); // don't keep this live.
         bbox = null;

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/BridgeContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/BridgeContext.java?view=diff&rev=504819&r1=504818&r2=504819
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/BridgeContext.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/BridgeContext.java Thu Feb  8 00:23:19 2007
@@ -1450,6 +1450,15 @@
         if (focusManager != null) {
             focusManager.dispose();
         }
+        if ( elementDataMap != null ){
+            elementDataMap.clear();
+        }
+        if ( nodeElementMap != null ){
+            nodeElementMap.clear();
+        }
+        if ( elementNodeMap != null ){
+            elementNodeMap.clear();
+        }        
     }
 
     /**

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/BridgeEventSupport.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/BridgeEventSupport.java?view=diff&rev=504819&r1=504818&r2=504819
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/BridgeEventSupport.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/BridgeEventSupport.java Thu Feb  8 00:23:19 2007
@@ -61,7 +61,7 @@
  */
 public abstract class BridgeEventSupport implements SVGConstants {
 
-    public static final 
+    public static final
         AttributedCharacterIterator.Attribute TEXT_COMPOUND_ID =
         GVTAttributedCharacterIterator.TextAttribute.TEXT_COMPOUND_ID;
 
@@ -124,7 +124,7 @@
         protected EventDispatcher dispatcher;
         protected Listener listener;
 
-        public GVTUnloadListener(EventDispatcher dispatcher, 
+        public GVTUnloadListener(EventDispatcher dispatcher,
                                  Listener listener) {
             this.dispatcher = dispatcher;
             this.listener = listener;
@@ -145,7 +145,7 @@
      */
     protected static class Listener implements GraphicsNodeMouseListener,
                                                GraphicsNodeKeyListener {
-        
+
         protected BridgeContext context;
         protected UserAgent ua;
         protected Element lastTargetElement;
@@ -194,7 +194,7 @@
         /**
          * Dispatch a DOM 2 Draft Key event.
          */
-        protected void dispatchKeyEvent(String eventType, 
+        protected void dispatchKeyEvent(String eventType,
                                         GraphicsNodeKeyEvent evt) {
             FocusManager fmgr = context.getFocusManager();
             if (fmgr == null) return;
@@ -205,14 +205,14 @@
             }
             DocumentEvent d = (DocumentEvent)targetElement.getOwnerDocument();
             DOMKeyEvent keyEvt = (DOMKeyEvent)d.createEvent("KeyEvents");
-            keyEvt.initKeyEvent(eventType, 
-                                true, 
-                                true, 
-                                evt.isControlDown(), 
+            keyEvt.initKeyEvent(eventType,
+                                true,
+                                true,
+                                evt.isControlDown(),
                                 evt.isAltDown(),
-                                evt.isShiftDown(), 
+                                evt.isShiftDown(),
                                 evt.isMetaDown(),
-                                mapKeyCode(evt.getKeyCode()), 
+                                mapKeyCode(evt.getKeyCode()),
                                 evt.getKeyChar(),
                                 null);
 
@@ -232,7 +232,7 @@
         protected final int mapKeyCode(int keyCode) {
             switch (keyCode) {
                 case KeyEvent.VK_ENTER:
-                    return DOMKeyEvent.DOM_VK_ENTER; 
+                    return DOMKeyEvent.DOM_VK_ENTER;
             case KeyEvent.VK_KANA_LOCK:
                 return DOMKeyEvent.DOM_VK_UNDEFINED;
             case KeyEvent.VK_INPUT_METHOD_ON_OFF:
@@ -262,11 +262,11 @@
             Element targetElement = getEventTarget
                 (node, new Point2D.Float(evt.getX(), evt.getY()));
             Element relatedElement = getRelatedElement(evt);
-            dispatchMouseEvent("mouseover", 
+            dispatchMouseEvent("mouseover",
                                targetElement,
                                relatedElement,
-                               clientXY, 
-                               evt, 
+                               clientXY,
+                               evt,
                                true);
         }
 
@@ -276,7 +276,7 @@
             GraphicsNode node = evt.getRelatedNode();
             Element targetElement = getEventTarget(node, clientXY);
             if (lastTargetElement != null) {
-                dispatchMouseEvent("mouseout", 
+                dispatchMouseEvent("mouseout",
                                    lastTargetElement, // target
                                    targetElement,     // relatedTarget
                                    clientXY,
@@ -297,7 +297,7 @@
             Element holdLTE = lastTargetElement;
             if (holdLTE != targetElement) {
                 if (holdLTE != null) {
-                    dispatchMouseEvent("mouseout", 
+                    dispatchMouseEvent("mouseout",
                                        holdLTE, // target
                                        targetElement,     // relatedTarget
                                        clientXY,
@@ -305,7 +305,7 @@
                                        true);
                 }
                 if (targetElement != null) {
-                    dispatchMouseEvent("mouseover", 
+                    dispatchMouseEvent("mouseover",
                                        targetElement,     // target
                                        holdLTE, // relatedTarget
                                        clientXY,
@@ -313,7 +313,7 @@
                                        true);
                 }
             }
-            dispatchMouseEvent("mousemove", 
+            dispatchMouseEvent("mousemove",
                                targetElement,     // target
                                null,              // relatedTarget
                                clientXY,
@@ -337,11 +337,11 @@
             Element targetElement = getEventTarget
                 (node, new Point2D.Float(evt.getX(), evt.getY()));
             Element relatedElement = getRelatedElement(evt);
-            dispatchMouseEvent(eventType, 
+            dispatchMouseEvent(eventType,
                                targetElement,
                                relatedElement,
-                               clientXY, 
-                               evt, 
+                               clientXY,
+                               evt,
                                cancelable);
         }
 
@@ -388,16 +388,16 @@
                 = DOMUtilities.getModifiersList(evt.getLockState(),
                                                 evt.getModifiers());
             mouseEvt.initMouseEventNS(XMLConstants.XML_EVENTS_NAMESPACE_URI,
-                                      eventType, 
-                                      true, 
-                                      cancelable, 
+                                      eventType,
+                                      true,
+                                      cancelable,
                                       null,
                                       evt.getClickCount(),
-                                      screenXY.x, 
+                                      screenXY.x,
                                       screenXY.y,
                                       clientXY.x,
                                       clientXY.y,
-                                      button, 
+                                      button,
                                       (EventTarget)relatedElement,
                                       modifiers);
 
@@ -470,7 +470,7 @@
                         float y = (float)pt.getY();
                         TextHit textHit = layout.hitTestChar(x, y);
                         Rectangle2D bounds = layout.getBounds2D();
-                        if ((textHit != null) && 
+                        if ((textHit != null) &&
                             (bounds != null) && bounds.contains(x, y)) {
                             SoftReference sr;
                             sr =(SoftReference)aci.getAttribute

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/SVGTextElementBridge.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/SVGTextElementBridge.java?view=diff&rev=504819&r1=504818&r2=504819
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/SVGTextElementBridge.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/SVGTextElementBridge.java Thu Feb  8 00:23:19 2007
@@ -924,7 +924,7 @@
                     EventListener l;
                     l = new SVGAElementBridge.AnchorListener(ua, ch);
                     target.addEventListenerNS
-                        (XMLConstants.XML_EVENTS_NAMESPACE_URI, 
+                        (XMLConstants.XML_EVENTS_NAMESPACE_URI,
                          SVG_EVENT_CLICK, l, false, null);
                     ctx.storeEventListenerNS
                         (target, XMLConstants.XML_EVENTS_NAMESPACE_URI,

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/ext/awt/geom/ExtendedGeneralPath.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/ext/awt/geom/ExtendedGeneralPath.java?view=diff&rev=504819&r1=504818&r2=504819
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/ext/awt/geom/ExtendedGeneralPath.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/ext/awt/geom/ExtendedGeneralPath.java Thu Feb  8 00:23:19 2007
@@ -131,7 +131,7 @@
             return;
         }
 
-        Arc2D arc = computeArc(x0, y0, rx, ry, angle, 
+        Arc2D arc = computeArc(x0, y0, rx, ry, angle,
                                largeArcFlag, sweepFlag, x, y);
         if (arc == null) return;
 
@@ -152,11 +152,11 @@
     }
 
 
-    /** 
-     * This constructs an unrotated Arc2D from the SVG specification of an 
+    /**
+     * This constructs an unrotated Arc2D from the SVG specification of an
      * Elliptical arc.  To get the final arc you need to apply a rotation
      * transform such as:
-     * 
+     *
      * AffineTransform.getRotateInstance
      *     (angle, arc.getX()+arc.getWidth()/2, arc.getY()+arc.getHeight()/2);
      */
@@ -267,7 +267,7 @@
         types [numSeg++]  = PathIterator.SEG_MOVETO;
         cx = mx = values[numVals++] = x;
         cy = my = values[numVals++] = y;
-        
+
     }
 
     /**
@@ -354,7 +354,7 @@
                 path.moveTo(values[numVals-2], values[numVals-1]);
             break;
 
-        default: 
+        default:
             break;
         }
     }
@@ -370,7 +370,7 @@
      * Delegates to the enclosed <code>GeneralPath</code>.
      */
     public void append(PathIterator pi, boolean connect) {
-        
+
         while (!pi.isDone()) {
             double [] vals = new double[6];
             int type = pi.currentSegment(vals);
@@ -395,15 +395,15 @@
 
             switch(type) {
             case PathIterator.SEG_CLOSE:   closePath(); break;
-            case PathIterator.SEG_MOVETO:  
+            case PathIterator.SEG_MOVETO:
                 moveTo ((float)vals[0], (float)vals[1]); break;
-            case PathIterator.SEG_LINETO:  
+            case PathIterator.SEG_LINETO:
                 lineTo ((float)vals[0], (float)vals[1]); break;
-            case PathIterator.SEG_QUADTO:  
-                quadTo ((float)vals[0], (float)vals[1], 
+            case PathIterator.SEG_QUADTO:
+                quadTo ((float)vals[0], (float)vals[1],
                         (float)vals[2], (float)vals[3]); break;
-            case PathIterator.SEG_CUBICTO: 
-                curveTo((float)vals[0], (float)vals[1], 
+            case PathIterator.SEG_CUBICTO:
+                curveTo((float)vals[0], (float)vals[1],
                         (float)vals[2], (float)vals[3],
                         (float)vals[4], (float)vals[5]); break;
             }
@@ -438,20 +438,20 @@
 
             switch(type) {
             case PathIterator.SEG_CLOSE:   closePath(); break;
-            case PathIterator.SEG_MOVETO:  
+            case PathIterator.SEG_MOVETO:
                 moveTo ((float)vals[0], (float)vals[1]); break;
-            case PathIterator.SEG_LINETO:  
+            case PathIterator.SEG_LINETO:
                 lineTo ((float)vals[0], (float)vals[1]); break;
-            case PathIterator.SEG_QUADTO:  
-                quadTo ((float)vals[0], (float)vals[1], 
+            case PathIterator.SEG_QUADTO:
+                quadTo ((float)vals[0], (float)vals[1],
                         (float)vals[2], (float)vals[3]); break;
-            case PathIterator.SEG_CUBICTO: 
-                curveTo((float)vals[0], (float)vals[1], 
+            case PathIterator.SEG_CUBICTO:
+                curveTo((float)vals[0], (float)vals[1],
                         (float)vals[2], (float)vals[3],
                         (float)vals[4], (float)vals[5]); break;
-            case ExtendedPathIterator.SEG_ARCTO:   
-                arcTo  (vals[0], vals[1], vals[2], 
-                        (vals[3]!=0), (vals[4]!=0), 
+            case ExtendedPathIterator.SEG_ARCTO:
+                arcTo  (vals[0], vals[1], vals[2],
+                        (vals[3]!=0), (vals[4]!=0),
                         vals[5], vals[6]); break;
             }
         }
@@ -594,8 +594,8 @@
             int ret = types[segNum];
             switch (ret) {
             case SEG_CLOSE: break;
-            case SEG_MOVETO: 
-            case SEG_LINETO: 
+            case SEG_MOVETO:
+            case SEG_LINETO:
                 coords[0] = values[valsIdx];
                 coords[1] = values[valsIdx+1];
                 break;
@@ -623,7 +623,7 @@
                 coords[6] = values[valsIdx+6];
                 break;
             }
-            // System.out.println("Seg: [" + segNum + "] type: " + ret + 
+            // System.out.println("Seg: [" + segNum + "] type: " + ret +
             //                    " vals: [" + coords[0] + ", " + coords[1] +
             //                    "]");
             return ret;
@@ -633,33 +633,36 @@
             int ret = types[segNum];
             switch (ret) {
             case SEG_CLOSE: break;
-            case SEG_MOVETO: 
-            case SEG_LINETO: 
-                coords[0] = (float)values[valsIdx];
-                coords[1] = (float)values[valsIdx+1];
+            case SEG_MOVETO:
+            case SEG_LINETO:
+                coords[0] = values[valsIdx];
+                coords[1] = values[valsIdx+1];
                 break;
             case SEG_QUADTO:
-                coords[0] = (float)values[valsIdx];
-                coords[1] = (float)values[valsIdx+1];
-                coords[2] = (float)values[valsIdx+2];
-                coords[3] = (float)values[valsIdx+3];
+                // coords[0] = values[valsIdx];
+                // coords[1] = values[valsIdx+1];
+                // coords[2] = values[valsIdx+2];
+                // coords[3] = values[valsIdx+3];
+                System.arraycopy( values, 0, coords, 0, 4 );
                 break;
             case SEG_CUBICTO:
-                coords[0] = (float)values[valsIdx];
-                coords[1] = (float)values[valsIdx+1];
-                coords[2] = (float)values[valsIdx+2];
-                coords[3] = (float)values[valsIdx+3];
-                coords[4] = (float)values[valsIdx+4];
-                coords[5] = (float)values[valsIdx+5];
+                // coords[0] = values[valsIdx];
+                // coords[1] = values[valsIdx+1];
+                // coords[2] = values[valsIdx+2];
+                // coords[3] = values[valsIdx+3];
+                // coords[4] = values[valsIdx+4];
+                // coords[5] = values[valsIdx+5];
+                System.arraycopy( values, 0, coords, 0, 6 );
                 break;
             case SEG_ARCTO:
-                coords[0] = (float)values[valsIdx];
-                coords[1] = (float)values[valsIdx+1];
-                coords[2] = (float)values[valsIdx+2];
-                coords[3] = (float)values[valsIdx+3];
-                coords[4] = (float)values[valsIdx+4];
-                coords[5] = (float)values[valsIdx+5];
-                coords[6] = (float)values[valsIdx+6];
+                // coords[0] = values[valsIdx];
+                // coords[1] = values[valsIdx+1];
+                // coords[2] = values[valsIdx+2];
+                // coords[3] = values[valsIdx+3];
+                // coords[4] = values[valsIdx+4];
+                // coords[5] = values[valsIdx+5];
+                // coords[6] = values[valsIdx+6];
+                System.arraycopy( values, 0, coords, 0, 7 );
                 break;
             }
             return ret;
@@ -675,7 +678,7 @@
             int type = types[segNum++];
             switch (type) {
             case SEG_CLOSE: break;
-            case SEG_MOVETO: 
+            case SEG_MOVETO:
             case SEG_LINETO: valsIdx+=2; break;
             case SEG_QUADTO: valsIdx+=4; break;
             case SEG_CUBICTO:valsIdx+=6; break;
@@ -713,12 +716,13 @@
             numSeg  = 0;
             return;
         }
-        
-        if ((numVals + numValues) > values.length) {
+
+        int newSize = numVals + numValues;
+        if ( newSize > values.length) {
             int nlen = values.length*2;
-            if (nlen < (numVals + numValues))
-                nlen = numVals + numValues;
-        
+            if ( nlen < newSize )
+                nlen = newSize;
+
             float [] nvals = new float[nlen];
             System.arraycopy(values, 0, nvals, 0, numVals);
             values = nvals;

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/gvt/renderer/MacRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/gvt/renderer/MacRenderer.java?view=diff&rev=504819&r1=504818&r2=504819
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/gvt/renderer/MacRenderer.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/gvt/renderer/MacRenderer.java Thu Feb  8 00:23:19 2007
@@ -94,6 +94,9 @@
         workImg = null;
         renderingHints = null;
         usr2dev = null;
+        if ( damagedAreas != null ){
+            damagedAreas.clear();
+        }
         damagedAreas = null;
     }
     /**

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/gvt/renderer/StaticRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/gvt/renderer/StaticRenderer.java?view=diff&rev=504819&r1=504818&r2=504819
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/gvt/renderer/StaticRenderer.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/gvt/renderer/StaticRenderer.java Thu Feb  8 00:23:19 2007
@@ -128,7 +128,7 @@
         rootGN     = null;
         rootFilter = null;
         rootCR     = null;
-        
+
         workingOffScreen = null;
         workingBaseRaster = null;
         workingRaster = null;
@@ -138,6 +138,8 @@
         currentRaster = null;
 
         renderingHints = null;
+        lastCache = null;
+        lastCR = null;
     }
 
     /**
@@ -185,7 +187,7 @@
 
     /**
      * @return the RenderingHints which the Renderer is using for its
-     *         rendering 
+     *         rendering
      */
     public RenderingHints getRenderingHints() {
         return renderingHints;
@@ -221,7 +223,7 @@
     /**
      * Returns true if the Renderer is currently doubleBuffering is
      * rendering requests.  If it is then getOffscreen will only
-     * return completed renderings (or null if nothing is available).  
+     * return completed renderings (or null if nothing is available).
      */
     public boolean isDoubleBuffered(){
         return isDoubleBuffered;
@@ -258,7 +260,7 @@
      * Note that this change will not be reflected by calls to
      * getOffscreen until either clearOffScreen has completed (when
      * isDoubleBuffered is false) or reapint has completed (when
-     * isDoubleBuffered is true).  
+     * isDoubleBuffered is true).
      *
      */
     public void updateOffScreen(int width, int height) {
@@ -268,7 +270,7 @@
 
     /**
      * Returns the current offscreen image.
-     * 
+     *
      * The exact symantics of this vary base on the value of
      * isDoubleBuffered.  If isDoubleBuffered is false this will
      * return the image currently being worked on as soon as it is
@@ -293,20 +295,20 @@
      *
      * When double buffering this call can effectively be skipped,
      * since getOffscreen will only refect the new rendering after
-     * repaint completes.  
+     * repaint completes.
      */
     public void clearOffScreen() {
 
         // No need to clear in double buffer case people will
         // only see it when it is done...
-        if (isDoubleBuffered) 
+        if (isDoubleBuffered)
             return;
 
         updateWorkingBuffers();
         if ((rootCR == null)           ||
             (workingBaseRaster == null))
             return;
-        
+
         ColorModel     cm         = rootCR.getColorModel();
         WritableRaster syncRaster = workingBaseRaster;
 
@@ -324,7 +326,7 @@
 
     /**
      * Repaints the associated GVT tree under <tt>area</tt>.
-     * 
+     *
      * If double buffered is true and this method completes cleanly it
      * will set the result of the repaint as the image returned by
      * getOffscreen otherwise the old image will still be returned.
@@ -333,7 +335,7 @@
      * by getOffscreen.
      *
      * @param area region to be repainted, in the current user space
-     * coordinate system.  
+     * coordinate system.
      */
     public void repaint(Shape area) {
         if (area == null) return;
@@ -344,7 +346,7 @@
 
     /**
      * Repaints the associated GVT tree under the list of <tt>areas</tt>.
-     * 
+     *
      * If double buffered is true and this method completes cleanly it
      * will set the result of the repaint as the image returned by
      * getOffscreen otherwise the old image will still be returned.
@@ -353,7 +355,7 @@
      * by getOffscreen.
      *
      * @param areas a List of regions to be repainted, in the current
-     * user space coordinate system.  
+     * user space coordinate system.
      */
     public void repaint(RectListManager areas) {
 
@@ -415,7 +417,7 @@
         if (lastCache == null) return;
         Object o = lastCache.get();
         if (o == null) return;
-        
+
         TileCacheRed tcr = (TileCacheRed)o;
         tcr.flushCache(tcr.getBounds());
     }
@@ -475,7 +477,7 @@
                                    0, 0);
 
         RenderContext rc = new RenderContext(rcAT, null, renderingHints);
-            
+
         RenderedImage ri = rootFilter.createRendering(rc);
         if (ri == null)
             return null;
@@ -483,7 +485,7 @@
         CachableRed ret;
         ret = GraphicsUtil.wrap(ri);
         ret = setupCache(ret);
-        
+
         int dx = Math.round((float)at.getTranslateX());
         int dy = Math.round((float)at.getTranslateY());
         ret = new TranslateRed(ret, ret.getMinX()+dx, ret.getMinY()+dy);
@@ -495,7 +497,7 @@
 
     /**
      * Internal method used to synchronize local state in response to
-     * various set methods.  
+     * various set methods.
      */
     protected void updateWorkingBuffers() {
         if (rootFilter == null) {
@@ -509,7 +511,7 @@
             workingRaster = null;
             workingOffScreen = null;
             workingBaseRaster = null;
-            
+
             currentOffScreen = null;
             currentBaseRaster = null;
             currentRaster = null;
@@ -530,8 +532,8 @@
             (workingBaseRaster.getHeight() < h)) {
 
             sm = sm.createCompatibleSampleModel(w, h);
-            
-            workingBaseRaster 
+
+            workingBaseRaster
                 = Raster.createWritableRaster(sm, new Point(0,0));
         }
 
@@ -545,9 +547,9 @@
 
         int xloc = xt*tw - tgx;
         int yloc = yt*th - tgy;
-        
-        // System.out.println("Info: [" + 
-        //                    xloc + "," + yloc + "] [" + 
+
+        // System.out.println("Info: [" +
+        //                    xloc + "," + yloc + "] [" +
         //                    tgx  + "," + tgy  + "] [" +
         //                    xt   + "," + yt   + "] [" +
         //                    tw   + "," + th   + "]");
@@ -556,7 +558,7 @@
           (0, 0, w, h, xloc, yloc, null);
 
         workingOffScreen =  new BufferedImage
-          (rootCR.getColorModel(), 
+          (rootCR.getColorModel(),
            workingRaster.createWritableChild (0, 0, offScreenWidth,
                                            offScreenHeight, 0, 0, null),
            rootCR.getColorModel().isAlphaPremultiplied(), null);

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/util/SoftReferenceCache.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/util/SoftReferenceCache.java?view=diff&rev=504819&r1=504818&r2=504819
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/util/SoftReferenceCache.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/util/SoftReferenceCache.java Thu Feb  8 00:23:19 2007
@@ -20,10 +20,11 @@
 
 import java.lang.ref.SoftReference;
 import java.util.HashMap;
+import java.util.Map;
 
 /**
  * This class manages a cache of soft references to objects that may
- * take some time to load or create, such as images loaded from the 
+ * take some time to load or create, such as images loaded from the
  * network.
  *
  * <p>Adding an object is two fold:</p>
@@ -49,7 +50,7 @@
     /**
      * The map of cached objects.
      */
-    protected HashMap map = new HashMap();
+    protected Map map = new HashMap();
 
     /**
      * Let people create their own caches.
@@ -59,7 +60,7 @@
     /**
      * Let people flush the cache (remove any cached data).  Pending
      * requests will be treated as though clear() was called on the
-     * key, this should cause them to go and re-read the data.  
+     * key, this should cause them to go and re-read the data.
      */
     public synchronized void flush() {
         map.clear();
@@ -72,14 +73,14 @@
      * that this will return true but between this call and the call
      * to request the soft-reference will be cleared.  So it
      * is still possible for request to return NULL, just much less
-     * likely (you can always call 'clear' in that case). 
+     * likely (you can always call 'clear' in that case).
      */
     protected final synchronized boolean isPresentImpl(Object key) {
         if (!map.containsKey(key))
             return false;
 
         Object o = map.get(key);
-        if (o == null)  
+        if (o == null)
             // It's been requested but hasn't been 'put' yet.
             return true;
 
@@ -192,13 +193,13 @@
                 if (this == o) {
                     // Notify other threads that they may have
                     // to provide this resource now.
-                    cache.notifyAll(); 
+                    cache.notifyAll();
                 } else {
                     // Must not have been ours put it back...
                     // Can happen if a clear is done.
                     cache.map.put(key, o);
                 }
- 
+
             }
         }
     }



Re: svn commit: r504819 - in /xmlgraphics/batik/trunk/sources/org/apache/batik: bridge/ ext/awt/geom/ gvt/renderer/ util/

Posted by Dieter von Holten <in...@dvholten.de>.
Hi Thomas,

a couple of comments on your comments:

1.) dispose()
 i try to get a meaningful benchmark which shows that performance of batik
1.7 is better than 1.6. - that's what i'd expect. However,  that is
difficult to prove. I run the imagetranscoder on a couple of svg-files using
jdk1.4, 1.5 and 1.6 on the old set of batik1.6 jars against a current jar.
the current jar is *always* slower! :-(  watching the profiler results it
seems, that the current code creates more work for the garbage collector.
Not more garbage in bytes, but in quality - it seems to be more 'sticky'.
The old batik spends (lets say) 15% of its time in gc, the current batik
spends 22% of its runtime in gc (working on the same input). A likely cause
of this are caches, finalizers, references etc.
so, the manually clearing obsolete datastructures is an (so far not
successful) attempt to simplify the work of gc. There are not many dispose()
methods to try..
Of course, when i run out of ideas i can cheat with a simple benchmark: load
+ render one image to screen, then stop the watch, ignoring gc-cost...

Any ideas of fundamental changes in object structure since 1.6?

2.) arraycopy.
after the vm-sourcecode was made public last year i spend some time poking
around to see what is really behind the various myths about the hotspot
capabilities. the object of the investigation was the float-to-int
conversion. There is an x86 instruction for that, but it does a rounding
conversion. to have to truncation, the fpu must be set to another rounding
mode. that costs 40 cycles. after conversion, the mode must be restored
(costs another 40 cycles).
Newer cpu-models have mmx, sse, ss2e instructions. Among those is a
optimized float-to-int conversion, bypassing the fpu. So, the hotspot
detects the current cpu-model and generates the best float-to-int conversion
available.
Hotspot has a number of tricks to compile arraycopy(). It knows, that it
deals with a primitive array. It knows, that it doesnt need to check source
and destination index (0 is always valid). Both are 0, so no need for
overlap check. The copy-size is fixed and small, so it doesnt produce a
block-move, just some load/store-instructions.
This Hotspot-thing is a really smart piece of code. However, I wouldnt bet
on the capabilities of a jdk1.3 client...
The point is to use idioms: when it is a block-move, it should be written as
a block move.
Probably, the best way to write this is to use the switch-statement to
select the number of slots to copy, and then have only one arraycopy after
the switch.

Unfortunately, so far i have not found a way to make it use the fancy
sse-instructions to pack/unpack the bytes <-> int. That would give a real
boost to any pixel-packing graphics app.

3.) whitespace is removed automatically when i open a file. ok, i can
refrain from committing 'white-space-only' changes.

greetings
dieter



----- Original Message -----
From: <th...@kodak.com>
To: <ba...@xmlgraphics.apache.org>
Cc: <ba...@xmlgraphics.apache.org>
Sent: Thursday, February 08, 2007 11:52 AM
Subject: Re: svn commit: r504819 - in
/xmlgraphics/batik/trunk/sources/org/apache/batik: bridge/ ext/awt/geom/
gvt/renderer/ util/


> Hi Deiter,
>
>    A couple of comments on this
>
> dvholten@apache.org wrote on 02/08/2007 03:23:21 AM:
>
> > xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/BridgeContext.
>
>    The main purpose of 'dispose' is to remove references to objects
> that otherwise would not have references removed.  In the case of
> the Maps the whole map is about to become unreferenced meaning that
> any references it has will become meaningless.  Unless you know
> something I don't I suspect that calling 'clear' on these just
> adds work and doesn't help anything....
>
> > java Thu Feb  8 00:23:19 2007
> > @@ -1450,6 +1450,15 @@
> >          if (focusManager != null) {
> >              focusManager.dispose();
> >          }
> > +        if ( elementDataMap != null ){
> > +            elementDataMap.clear();
> > +        }
> > +        if ( nodeElementMap != null ){
> > +            nodeElementMap.clear();
> > +        }
> > +        if ( elementNodeMap != null ){
> > +            elementNodeMap.clear();
> > +        }
> >      }
>
>    I understand that System.arraycopy is by far
> the fastest way to copy large amounts of data, I've
> always assumed that for small chunks of data the
> overhead needed for arraycopy to get going (function
> call, data type matching, array pinning(?) etc) way
> outweighed the speed advantage once it is going.
>
>    I don't know if there is 'magic' under the
> hood that avoids this (for example some C compilers
> will replace calls to memcpy).  So I'm wondering
> if you know something I don't or if you are just
> operating on the conventional wisdom of use
> arraycopy.
>
> > -                coords[0] = (float)values[valsIdx];
> > -                coords[1] = (float)values[valsIdx+1];
> > -                coords[2] = (float)values[valsIdx+2];
> > -                coords[3] = (float)values[valsIdx+3];
> > +                // coords[0] = values[valsIdx];
> > +                // coords[1] = values[valsIdx+1];
> > +                // coords[2] = values[valsIdx+2];
> > +                // coords[3] = values[valsIdx+3];
> > +                System.arraycopy( values, 0, coords, 0, 4 );
> >                  break;
>
> PS.  The space thing.  I don't mind the removal of
> trailing whitespace, but can we do this in one large
> pass rather one file at a time?  It makes your
> commits very hard to read.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-dev-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-dev-help@xmlgraphics.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-dev-help@xmlgraphics.apache.org


Re: svn commit: r504819 - in /xmlgraphics/batik/trunk/sources/org/apache/batik: bridge/ ext/awt/geom/ gvt/renderer/ util/

Posted by th...@kodak.com.
Hi Deiter,

   A couple of comments on this

dvholten@apache.org wrote on 02/08/2007 03:23:21 AM:

> xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/BridgeContext.

   The main purpose of 'dispose' is to remove references to objects
that otherwise would not have references removed.  In the case of
the Maps the whole map is about to become unreferenced meaning that 
any references it has will become meaningless.  Unless you know
something I don't I suspect that calling 'clear' on these just
adds work and doesn't help anything....

> java Thu Feb  8 00:23:19 2007
> @@ -1450,6 +1450,15 @@
>          if (focusManager != null) {
>              focusManager.dispose();
>          }
> +        if ( elementDataMap != null ){
> +            elementDataMap.clear();
> +        }
> +        if ( nodeElementMap != null ){
> +            nodeElementMap.clear();
> +        }
> +        if ( elementNodeMap != null ){
> +            elementNodeMap.clear();
> +        } 
>      }

   I understand that System.arraycopy is by far
the fastest way to copy large amounts of data, I've
always assumed that for small chunks of data the 
overhead needed for arraycopy to get going (function
call, data type matching, array pinning(?) etc) way 
outweighed the speed advantage once it is going.

   I don't know if there is 'magic' under the
hood that avoids this (for example some C compilers 
will replace calls to memcpy).  So I'm wondering
if you know something I don't or if you are just
operating on the conventional wisdom of use
arraycopy.

> -                coords[0] = (float)values[valsIdx];
> -                coords[1] = (float)values[valsIdx+1];
> -                coords[2] = (float)values[valsIdx+2];
> -                coords[3] = (float)values[valsIdx+3];
> +                // coords[0] = values[valsIdx];
> +                // coords[1] = values[valsIdx+1];
> +                // coords[2] = values[valsIdx+2];
> +                // coords[3] = values[valsIdx+3];
> +                System.arraycopy( values, 0, coords, 0, 4 );
>                  break;

PS.  The space thing.  I don't mind the removal of
trailing whitespace, but can we do this in one large
pass rather one file at a time?  It makes your
commits very hard to read.


Re: svn commit: r504819 - in /xmlgraphics/batik/trunk/sources/org/apache/batik: bridge/ ext/awt/geom/ gvt/renderer/ util/

Posted by th...@kodak.com.
Hi Deiter,

   A couple of comments on this

dvholten@apache.org wrote on 02/08/2007 03:23:21 AM:

> xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/BridgeContext.

   The main purpose of 'dispose' is to remove references to objects
that otherwise would not have references removed.  In the case of
the Maps the whole map is about to become unreferenced meaning that 
any references it has will become meaningless.  Unless you know
something I don't I suspect that calling 'clear' on these just
adds work and doesn't help anything....

> java Thu Feb  8 00:23:19 2007
> @@ -1450,6 +1450,15 @@
>          if (focusManager != null) {
>              focusManager.dispose();
>          }
> +        if ( elementDataMap != null ){
> +            elementDataMap.clear();
> +        }
> +        if ( nodeElementMap != null ){
> +            nodeElementMap.clear();
> +        }
> +        if ( elementNodeMap != null ){
> +            elementNodeMap.clear();
> +        } 
>      }

   I understand that System.arraycopy is by far
the fastest way to copy large amounts of data, I've
always assumed that for small chunks of data the 
overhead needed for arraycopy to get going (function
call, data type matching, array pinning(?) etc) way 
outweighed the speed advantage once it is going.

   I don't know if there is 'magic' under the
hood that avoids this (for example some C compilers 
will replace calls to memcpy).  So I'm wondering
if you know something I don't or if you are just
operating on the conventional wisdom of use
arraycopy.

> -                coords[0] = (float)values[valsIdx];
> -                coords[1] = (float)values[valsIdx+1];
> -                coords[2] = (float)values[valsIdx+2];
> -                coords[3] = (float)values[valsIdx+3];
> +                // coords[0] = values[valsIdx];
> +                // coords[1] = values[valsIdx+1];
> +                // coords[2] = values[valsIdx+2];
> +                // coords[3] = values[valsIdx+3];
> +                System.arraycopy( values, 0, coords, 0, 4 );
>                  break;

PS.  The space thing.  I don't mind the removal of
trailing whitespace, but can we do this in one large
pass rather one file at a time?  It makes your
commits very hard to read.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-dev-help@xmlgraphics.apache.org