6896068: SunGraphics2D exposes a reference to itself while non fully initialised.
authorneugens
Fri, 30 Oct 2009 19:19:35 +0100
changeset 4250 e88776b21913
parent 4249 b890f1c39c38
child 4251 7d3154406018
6896068: SunGraphics2D exposes a reference to itself while non fully initialised. Summary: Introduce a new Interface to mark the Loops based pipes and initialise the loops accordingly. Reviewed-by: flar, rkennke
jdk/src/share/classes/sun/java2d/SunGraphics2D.java
jdk/src/share/classes/sun/java2d/SurfaceData.java
jdk/src/share/classes/sun/java2d/pipe/AATextRenderer.java
jdk/src/share/classes/sun/java2d/pipe/GlyphListLoopPipe.java
jdk/src/share/classes/sun/java2d/pipe/LoopBasedPipe.java
jdk/src/share/classes/sun/java2d/pipe/LoopPipe.java
jdk/src/share/classes/sun/java2d/pipe/SolidTextRenderer.java
jdk/src/share/classes/sun/java2d/pipe/SpanShapeRenderer.java
jdk/src/solaris/classes/sun/java2d/x11/X11SurfaceData.java
jdk/src/windows/classes/sun/java2d/windows/GDIWindowSurfaceData.java
--- a/jdk/src/share/classes/sun/java2d/SunGraphics2D.java	Fri Oct 23 16:21:50 2009 +0400
+++ b/jdk/src/share/classes/sun/java2d/SunGraphics2D.java	Fri Oct 30 19:19:35 2009 +0100
@@ -257,7 +257,6 @@
             font = defaultFont;
         }
 
-        loops = sd.getRenderLoops(this);
         setDevClip(sd.getBounds());
         invalidatePipe();
     }
@@ -367,6 +366,7 @@
         shapepipe = invalidpipe;
         textpipe = invalidpipe;
         imagepipe = invalidpipe;
+        loops = null;
     }
 
     public void validatePipe() {
--- a/jdk/src/share/classes/sun/java2d/SurfaceData.java	Fri Oct 23 16:21:50 2009 +0400
+++ b/jdk/src/share/classes/sun/java2d/SurfaceData.java	Fri Oct 30 19:19:35 2009 +0100
@@ -69,6 +69,7 @@
 import sun.java2d.pipe.DrawImage;
 import sun.awt.SunHints;
 import sun.awt.image.SurfaceManager;
+import sun.java2d.pipe.LoopBasedPipe;
 
 /**
  * This class provides various pieces of information relevant to a
@@ -506,7 +507,6 @@
                     sg2d.textpipe = solidTextRenderer;
                 }
                 sg2d.shapepipe = colorPrimitives;
-                sg2d.loops = getRenderLoops(sg2d);
                 // assert(sg2d.surfaceData == this);
             }
         } else if (sg2d.compositeState == sg2d.COMP_CUSTOM) {
@@ -603,8 +603,17 @@
 
             sg2d.textpipe = getTextPipe(sg2d, false /* AA==OFF */);
             sg2d.shapepipe = colorPrimitives;
+            // assert(sg2d.surfaceData == this);
+        }
+
+        // check for loops
+        if (sg2d.textpipe  instanceof LoopBasedPipe ||
+            sg2d.shapepipe instanceof LoopBasedPipe ||
+            sg2d.fillpipe  instanceof LoopBasedPipe ||
+            sg2d.drawpipe  instanceof LoopBasedPipe ||
+            sg2d.imagepipe instanceof LoopBasedPipe)
+        {
             sg2d.loops = getRenderLoops(sg2d);
-            // assert(sg2d.surfaceData == this);
         }
     }
 
--- a/jdk/src/share/classes/sun/java2d/pipe/AATextRenderer.java	Fri Oct 23 16:21:50 2009 +0400
+++ b/jdk/src/share/classes/sun/java2d/pipe/AATextRenderer.java	Fri Oct 30 19:19:35 2009 +0100
@@ -34,8 +34,9 @@
  * a solid source colour to an opaque destination.
  */
 
-public class AATextRenderer extends GlyphListLoopPipe {
-
+public class AATextRenderer extends GlyphListLoopPipe
+    implements LoopBasedPipe
+{
    protected void drawGlyphList(SunGraphics2D sg2d, GlyphList gl) {
        sg2d.loops.drawGlyphListAALoop.DrawGlyphListAA(sg2d, sg2d.surfaceData,
                                                       gl);
--- a/jdk/src/share/classes/sun/java2d/pipe/GlyphListLoopPipe.java	Fri Oct 23 16:21:50 2009 +0400
+++ b/jdk/src/share/classes/sun/java2d/pipe/GlyphListLoopPipe.java	Fri Oct 30 19:19:35 2009 +0100
@@ -36,8 +36,9 @@
  * the installed loop may not match the glyphvector.
  */
 
-public abstract class GlyphListLoopPipe extends GlyphListPipe {
-
+public abstract class GlyphListLoopPipe extends GlyphListPipe
+    implements LoopBasedPipe
+{
     protected void drawGlyphList(SunGraphics2D sg2d, GlyphList gl,
                                  int aaHint) {
         switch (aaHint) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/sun/java2d/pipe/LoopBasedPipe.java	Fri Oct 30 19:19:35 2009 +0100
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package sun.java2d.pipe;
+
+/**
+ * This is a marker interface used by Pipes that need RenderLoops.
+ * RenderLoops are validated in SurfaceData when a pipe is recognised to
+ * implement this interface.
+ *
+ * @author Mario Torre <neugens@aicas.com>
+ */
+public interface LoopBasedPipe {
+
+}
--- a/jdk/src/share/classes/sun/java2d/pipe/LoopPipe.java	Fri Oct 23 16:21:50 2009 +0400
+++ b/jdk/src/share/classes/sun/java2d/pipe/LoopPipe.java	Fri Oct 30 19:19:35 2009 +0100
@@ -46,7 +46,8 @@
 public class LoopPipe
     implements PixelDrawPipe,
                PixelFillPipe,
-               ShapeDrawPipe
+               ShapeDrawPipe,
+               LoopBasedPipe
 {
     final static RenderingEngine RenderEngine = RenderingEngine.getInstance();
 
--- a/jdk/src/share/classes/sun/java2d/pipe/SolidTextRenderer.java	Fri Oct 23 16:21:50 2009 +0400
+++ b/jdk/src/share/classes/sun/java2d/pipe/SolidTextRenderer.java	Fri Oct 30 19:19:35 2009 +0100
@@ -35,8 +35,9 @@
  * a solid source colour to an opaque destination.
  */
 
-public class SolidTextRenderer extends GlyphListLoopPipe {
-
+public class SolidTextRenderer extends GlyphListLoopPipe
+    implements LoopBasedPipe
+{
     protected void drawGlyphList(SunGraphics2D sg2d, GlyphList gl) {
         sg2d.loops.drawGlyphListLoop.DrawGlyphList(sg2d, sg2d.surfaceData, gl);
     }
--- a/jdk/src/share/classes/sun/java2d/pipe/SpanShapeRenderer.java	Fri Oct 23 16:21:50 2009 +0400
+++ b/jdk/src/share/classes/sun/java2d/pipe/SpanShapeRenderer.java	Fri Oct 30 19:19:35 2009 +0100
@@ -65,7 +65,9 @@
         }
     }
 
-    public static class Simple extends SpanShapeRenderer {
+    public static class Simple extends SpanShapeRenderer
+        implements  LoopBasedPipe
+    {
         public Object startSequence(SunGraphics2D sg, Shape s,
                                     Rectangle devR, int[] bbox) {
             return sg;
--- a/jdk/src/solaris/classes/sun/java2d/x11/X11SurfaceData.java	Fri Oct 23 16:21:50 2009 +0400
+++ b/jdk/src/solaris/classes/sun/java2d/x11/X11SurfaceData.java	Fri Oct 30 19:19:35 2009 +0100
@@ -388,7 +388,10 @@
             // if a GlyphVector overrides the AA setting.
             // We use getRenderLoops() rather than setting solidloops
             // directly so that we get the appropriate loops in XOR mode.
-            sg2d.loops = getRenderLoops(sg2d);
+            if (sg2d.loops == null) {
+                // assert(some pipe will always be a LoopBasedPipe)
+                sg2d.loops = getRenderLoops(sg2d);
+            }
         } else {
             super.validatePipe(sg2d);
         }
--- a/jdk/src/windows/classes/sun/java2d/windows/GDIWindowSurfaceData.java	Fri Oct 23 16:21:50 2009 +0400
+++ b/jdk/src/windows/classes/sun/java2d/windows/GDIWindowSurfaceData.java	Fri Oct 30 19:19:35 2009 +0100
@@ -210,7 +210,10 @@
             // if a GlyphVector overrides the AA setting.
             // We use getRenderLoops() rather than setting solidloops
             // directly so that we get the appropriate loops in XOR mode.
-            sg2d.loops = getRenderLoops(sg2d);
+            if (sg2d.loops == null) {
+                // assert(some pipe will always be a LoopBasedPipe)
+                sg2d.loops = getRenderLoops(sg2d);
+            }
         } else {
             super.validatePipe(sg2d);
         }