From 041e6cb96718723f4d8389b7f029cf5322e5738a Mon Sep 17 00:00:00 2001 From: Mario Torre Date: Fri, 30 Oct 2009 19:19:35 +0100 Subject: [PATCH] 6896068: SunGraphics2D exposes a reference to itself while non fully initialised Introduce a new Interface to mark the Loops based pipes and initialise the loops accordingly. Reviewed-by: flar, rkennke --- .../classes/sun/java2d/SunGraphics2D.java | 2 +- .../share/classes/sun/java2d/SurfaceData.java | 13 ++++++- .../sun/java2d/pipe/AATextRenderer.java | 5 ++- .../sun/java2d/pipe/GlyphListLoopPipe.java | 5 ++- .../sun/java2d/pipe/LoopBasedPipe.java | 37 +++++++++++++++++++ .../classes/sun/java2d/pipe/LoopPipe.java | 3 +- .../sun/java2d/pipe/SolidTextRenderer.java | 5 ++- .../sun/java2d/pipe/SpanShapeRenderer.java | 4 +- .../sun/java2d/x11/X11SurfaceData.java | 5 ++- .../java2d/windows/GDIWindowSurfaceData.java | 5 ++- 10 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 jdk/src/share/classes/sun/java2d/pipe/LoopBasedPipe.java diff --git a/jdk/src/share/classes/sun/java2d/SunGraphics2D.java b/jdk/src/share/classes/sun/java2d/SunGraphics2D.java index c63db02e756..951876eb237 100644 --- a/jdk/src/share/classes/sun/java2d/SunGraphics2D.java +++ b/jdk/src/share/classes/sun/java2d/SunGraphics2D.java @@ -257,7 +257,6 @@ public final class SunGraphics2D font = defaultFont; } - loops = sd.getRenderLoops(this); setDevClip(sd.getBounds()); invalidatePipe(); } @@ -367,6 +366,7 @@ public final class SunGraphics2D shapepipe = invalidpipe; textpipe = invalidpipe; imagepipe = invalidpipe; + loops = null; } public void validatePipe() { diff --git a/jdk/src/share/classes/sun/java2d/SurfaceData.java b/jdk/src/share/classes/sun/java2d/SurfaceData.java index 65a04c23220..95ef18c85f4 100644 --- a/jdk/src/share/classes/sun/java2d/SurfaceData.java +++ b/jdk/src/share/classes/sun/java2d/SurfaceData.java @@ -69,6 +69,7 @@ import sun.java2d.pipe.DrawImagePipe; 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 @@ public abstract class SurfaceData sg2d.textpipe = solidTextRenderer; } sg2d.shapepipe = colorPrimitives; - sg2d.loops = getRenderLoops(sg2d); // assert(sg2d.surfaceData == this); } } else if (sg2d.compositeState == sg2d.COMP_CUSTOM) { @@ -603,9 +603,18 @@ public abstract class SurfaceData sg2d.textpipe = getTextPipe(sg2d, false /* AA==OFF */); sg2d.shapepipe = colorPrimitives; - sg2d.loops = getRenderLoops(sg2d); // 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); + } } /* Return the text pipe to be used based on the graphics AA hint setting, diff --git a/jdk/src/share/classes/sun/java2d/pipe/AATextRenderer.java b/jdk/src/share/classes/sun/java2d/pipe/AATextRenderer.java index 389db9cbefd..602e5be5ef8 100644 --- a/jdk/src/share/classes/sun/java2d/pipe/AATextRenderer.java +++ b/jdk/src/share/classes/sun/java2d/pipe/AATextRenderer.java @@ -34,8 +34,9 @@ import sun.font.GlyphList; * 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); diff --git a/jdk/src/share/classes/sun/java2d/pipe/GlyphListLoopPipe.java b/jdk/src/share/classes/sun/java2d/pipe/GlyphListLoopPipe.java index cbe76016cf7..385a768cf9e 100644 --- a/jdk/src/share/classes/sun/java2d/pipe/GlyphListLoopPipe.java +++ b/jdk/src/share/classes/sun/java2d/pipe/GlyphListLoopPipe.java @@ -36,8 +36,9 @@ import sun.font.GlyphList; * 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) { diff --git a/jdk/src/share/classes/sun/java2d/pipe/LoopBasedPipe.java b/jdk/src/share/classes/sun/java2d/pipe/LoopBasedPipe.java new file mode 100644 index 00000000000..34b9067335c --- /dev/null +++ b/jdk/src/share/classes/sun/java2d/pipe/LoopBasedPipe.java @@ -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 + */ +public interface LoopBasedPipe { + +} diff --git a/jdk/src/share/classes/sun/java2d/pipe/LoopPipe.java b/jdk/src/share/classes/sun/java2d/pipe/LoopPipe.java index 93334e56fac..a7d2c1dae23 100644 --- a/jdk/src/share/classes/sun/java2d/pipe/LoopPipe.java +++ b/jdk/src/share/classes/sun/java2d/pipe/LoopPipe.java @@ -46,7 +46,8 @@ import sun.awt.SunHints; public class LoopPipe implements PixelDrawPipe, PixelFillPipe, - ShapeDrawPipe + ShapeDrawPipe, + LoopBasedPipe { final static RenderingEngine RenderEngine = RenderingEngine.getInstance(); diff --git a/jdk/src/share/classes/sun/java2d/pipe/SolidTextRenderer.java b/jdk/src/share/classes/sun/java2d/pipe/SolidTextRenderer.java index 52d1a709a53..bb8778aba93 100644 --- a/jdk/src/share/classes/sun/java2d/pipe/SolidTextRenderer.java +++ b/jdk/src/share/classes/sun/java2d/pipe/SolidTextRenderer.java @@ -35,8 +35,9 @@ import sun.font.GlyphList; * 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); } diff --git a/jdk/src/share/classes/sun/java2d/pipe/SpanShapeRenderer.java b/jdk/src/share/classes/sun/java2d/pipe/SpanShapeRenderer.java index 574ebed8188..a02b761c8dc 100644 --- a/jdk/src/share/classes/sun/java2d/pipe/SpanShapeRenderer.java +++ b/jdk/src/share/classes/sun/java2d/pipe/SpanShapeRenderer.java @@ -65,7 +65,9 @@ public abstract class SpanShapeRenderer implements ShapeDrawPipe { } } - 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; diff --git a/jdk/src/solaris/classes/sun/java2d/x11/X11SurfaceData.java b/jdk/src/solaris/classes/sun/java2d/x11/X11SurfaceData.java index f613c118831..943f6e73a06 100644 --- a/jdk/src/solaris/classes/sun/java2d/x11/X11SurfaceData.java +++ b/jdk/src/solaris/classes/sun/java2d/x11/X11SurfaceData.java @@ -388,7 +388,10 @@ public abstract class X11SurfaceData extends SurfaceData { // 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); } diff --git a/jdk/src/windows/classes/sun/java2d/windows/GDIWindowSurfaceData.java b/jdk/src/windows/classes/sun/java2d/windows/GDIWindowSurfaceData.java index e246a7fc63d..c55b54d9f6b 100644 --- a/jdk/src/windows/classes/sun/java2d/windows/GDIWindowSurfaceData.java +++ b/jdk/src/windows/classes/sun/java2d/windows/GDIWindowSurfaceData.java @@ -210,7 +210,10 @@ public class GDIWindowSurfaceData extends SurfaceData { // 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); }