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
This commit is contained in:
Mario Torre 2009-10-30 19:19:35 +01:00
parent 32f47acd27
commit 041e6cb967
10 changed files with 71 additions and 13 deletions

View File

@ -257,7 +257,6 @@ public final class SunGraphics2D
font = defaultFont; font = defaultFont;
} }
loops = sd.getRenderLoops(this);
setDevClip(sd.getBounds()); setDevClip(sd.getBounds());
invalidatePipe(); invalidatePipe();
} }
@ -367,6 +366,7 @@ public final class SunGraphics2D
shapepipe = invalidpipe; shapepipe = invalidpipe;
textpipe = invalidpipe; textpipe = invalidpipe;
imagepipe = invalidpipe; imagepipe = invalidpipe;
loops = null;
} }
public void validatePipe() { public void validatePipe() {

View File

@ -69,6 +69,7 @@ import sun.java2d.pipe.DrawImagePipe;
import sun.java2d.pipe.DrawImage; import sun.java2d.pipe.DrawImage;
import sun.awt.SunHints; import sun.awt.SunHints;
import sun.awt.image.SurfaceManager; import sun.awt.image.SurfaceManager;
import sun.java2d.pipe.LoopBasedPipe;
/** /**
* This class provides various pieces of information relevant to a * This class provides various pieces of information relevant to a
@ -506,7 +507,6 @@ public abstract class SurfaceData
sg2d.textpipe = solidTextRenderer; sg2d.textpipe = solidTextRenderer;
} }
sg2d.shapepipe = colorPrimitives; sg2d.shapepipe = colorPrimitives;
sg2d.loops = getRenderLoops(sg2d);
// assert(sg2d.surfaceData == this); // assert(sg2d.surfaceData == this);
} }
} else if (sg2d.compositeState == sg2d.COMP_CUSTOM) { } else if (sg2d.compositeState == sg2d.COMP_CUSTOM) {
@ -603,9 +603,18 @@ public abstract class SurfaceData
sg2d.textpipe = getTextPipe(sg2d, false /* AA==OFF */); sg2d.textpipe = getTextPipe(sg2d, false /* AA==OFF */);
sg2d.shapepipe = colorPrimitives; sg2d.shapepipe = colorPrimitives;
sg2d.loops = getRenderLoops(sg2d);
// assert(sg2d.surfaceData == this); // 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, /* Return the text pipe to be used based on the graphics AA hint setting,

View File

@ -34,8 +34,9 @@ import sun.font.GlyphList;
* a solid source colour to an opaque destination. * 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) { protected void drawGlyphList(SunGraphics2D sg2d, GlyphList gl) {
sg2d.loops.drawGlyphListAALoop.DrawGlyphListAA(sg2d, sg2d.surfaceData, sg2d.loops.drawGlyphListAALoop.DrawGlyphListAA(sg2d, sg2d.surfaceData,
gl); gl);

View File

@ -36,8 +36,9 @@ import sun.font.GlyphList;
* the installed loop may not match the glyphvector. * 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, protected void drawGlyphList(SunGraphics2D sg2d, GlyphList gl,
int aaHint) { int aaHint) {
switch (aaHint) { switch (aaHint) {

View File

@ -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 {
}

View File

@ -46,7 +46,8 @@ import sun.awt.SunHints;
public class LoopPipe public class LoopPipe
implements PixelDrawPipe, implements PixelDrawPipe,
PixelFillPipe, PixelFillPipe,
ShapeDrawPipe ShapeDrawPipe,
LoopBasedPipe
{ {
final static RenderingEngine RenderEngine = RenderingEngine.getInstance(); final static RenderingEngine RenderEngine = RenderingEngine.getInstance();

View File

@ -35,8 +35,9 @@ import sun.font.GlyphList;
* a solid source colour to an opaque destination. * 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) { protected void drawGlyphList(SunGraphics2D sg2d, GlyphList gl) {
sg2d.loops.drawGlyphListLoop.DrawGlyphList(sg2d, sg2d.surfaceData, gl); sg2d.loops.drawGlyphListLoop.DrawGlyphList(sg2d, sg2d.surfaceData, gl);
} }

View File

@ -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, public Object startSequence(SunGraphics2D sg, Shape s,
Rectangle devR, int[] bbox) { Rectangle devR, int[] bbox) {
return sg; return sg;

View File

@ -388,7 +388,10 @@ public abstract class X11SurfaceData extends SurfaceData {
// if a GlyphVector overrides the AA setting. // if a GlyphVector overrides the AA setting.
// We use getRenderLoops() rather than setting solidloops // We use getRenderLoops() rather than setting solidloops
// directly so that we get the appropriate loops in XOR mode. // directly so that we get the appropriate loops in XOR mode.
if (sg2d.loops == null) {
// assert(some pipe will always be a LoopBasedPipe)
sg2d.loops = getRenderLoops(sg2d); sg2d.loops = getRenderLoops(sg2d);
}
} else { } else {
super.validatePipe(sg2d); super.validatePipe(sg2d);
} }

View File

@ -210,7 +210,10 @@ public class GDIWindowSurfaceData extends SurfaceData {
// if a GlyphVector overrides the AA setting. // if a GlyphVector overrides the AA setting.
// We use getRenderLoops() rather than setting solidloops // We use getRenderLoops() rather than setting solidloops
// directly so that we get the appropriate loops in XOR mode. // directly so that we get the appropriate loops in XOR mode.
if (sg2d.loops == null) {
// assert(some pipe will always be a LoopBasedPipe)
sg2d.loops = getRenderLoops(sg2d); sg2d.loops = getRenderLoops(sg2d);
}
} else { } else {
super.validatePipe(sg2d); super.validatePipe(sg2d);
} }