|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
package sun.java2d.opengl; |
|
|
|
import java.awt.GradientPaint; |
|
import java.awt.LinearGradientPaint; |
|
import java.awt.MultipleGradientPaint; |
|
import java.awt.MultipleGradientPaint.ColorSpaceType; |
|
import java.awt.MultipleGradientPaint.CycleMethod; |
|
import java.awt.RadialGradientPaint; |
|
import java.awt.TexturePaint; |
|
import java.awt.image.BufferedImage; |
|
import java.util.HashMap; |
|
import java.util.Map; |
|
import sun.java2d.SunGraphics2D; |
|
import sun.java2d.SurfaceData; |
|
import sun.java2d.loops.CompositeType; |
|
import static sun.java2d.pipe.BufferedPaints.*; |
|
import static sun.java2d.opengl.OGLContext.OGLContextCaps.*; |
|
|
|
abstract class OGLPaints { |
|
|
|
|
|
|
|
|
|
*/ |
|
private static Map<Integer, OGLPaints> impls = |
|
new HashMap<Integer, OGLPaints>(4, 1.0f); |
|
|
|
static { |
|
impls.put(SunGraphics2D.PAINT_GRADIENT, new Gradient()); |
|
impls.put(SunGraphics2D.PAINT_LIN_GRADIENT, new LinearGradient()); |
|
impls.put(SunGraphics2D.PAINT_RAD_GRADIENT, new RadialGradient()); |
|
impls.put(SunGraphics2D.PAINT_TEXTURE, new Texture()); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static boolean isValid(SunGraphics2D sg2d) { |
|
OGLPaints impl = impls.get(sg2d.paintState); |
|
return (impl != null && impl.isPaintValid(sg2d)); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
abstract boolean isPaintValid(SunGraphics2D sg2d); |
|
|
|
/************************* GradientPaint support ****************************/ |
|
|
|
private static class Gradient extends OGLPaints { |
|
private Gradient() {} |
|
|
|
|
|
|
|
|
|
*/ |
|
@Override |
|
boolean isPaintValid(SunGraphics2D sg2d) { |
|
return true; |
|
} |
|
} |
|
|
|
/************************** TexturePaint support ****************************/ |
|
|
|
private static class Texture extends OGLPaints { |
|
private Texture() {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Override |
|
boolean isPaintValid(SunGraphics2D sg2d) { |
|
TexturePaint paint = (TexturePaint)sg2d.paint; |
|
OGLSurfaceData dstData = (OGLSurfaceData)sg2d.surfaceData; |
|
BufferedImage bi = paint.getImage(); |
|
|
|
|
|
if (!dstData.isTexNonPow2Available()) { |
|
int imgw = bi.getWidth(); |
|
int imgh = bi.getHeight(); |
|
|
|
|
|
if ((imgw & (imgw - 1)) != 0 || (imgh & (imgh - 1)) != 0) { |
|
return false; |
|
} |
|
} |
|
|
|
SurfaceData srcData = |
|
dstData.getSourceSurfaceData(bi, |
|
SunGraphics2D.TRANSFORM_ISIDENT, |
|
CompositeType.SrcOver, null); |
|
if (!(srcData instanceof OGLSurfaceData)) { |
|
// REMIND: this is a hack that attempts to cache the system |
|
// memory image from the TexturePaint instance into an |
|
|
|
srcData = |
|
dstData.getSourceSurfaceData(bi, |
|
SunGraphics2D.TRANSFORM_ISIDENT, |
|
CompositeType.SrcOver, null); |
|
if (!(srcData instanceof OGLSurfaceData)) { |
|
return false; |
|
} |
|
} |
|
|
|
|
|
OGLSurfaceData oglData = (OGLSurfaceData)srcData; |
|
if (oglData.getType() != OGLSurfaceData.TEXTURE) { |
|
return false; |
|
} |
|
|
|
return true; |
|
} |
|
} |
|
|
|
/****************** Shared MultipleGradientPaint support ********************/ |
|
|
|
private static abstract class MultiGradient extends OGLPaints { |
|
protected MultiGradient() {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Override |
|
boolean isPaintValid(SunGraphics2D sg2d) { |
|
MultipleGradientPaint paint = (MultipleGradientPaint)sg2d.paint; |
|
// REMIND: ugh, this creates garbage; would be nicer if |
|
|
|
if (paint.getFractions().length > MULTI_MAX_FRACTIONS) { |
|
return false; |
|
} |
|
|
|
OGLSurfaceData dstData = (OGLSurfaceData)sg2d.surfaceData; |
|
OGLGraphicsConfig gc = dstData.getOGLGraphicsConfig(); |
|
if (!gc.isCapPresent(CAPS_EXT_GRAD_SHADER)) { |
|
return false; |
|
} |
|
|
|
return true; |
|
} |
|
} |
|
|
|
/********************** LinearGradientPaint support *************************/ |
|
|
|
private static class LinearGradient extends MultiGradient { |
|
private LinearGradient() {} |
|
|
|
@Override |
|
boolean isPaintValid(SunGraphics2D sg2d) { |
|
LinearGradientPaint paint = (LinearGradientPaint)sg2d.paint; |
|
|
|
if (paint.getFractions().length == 2 && |
|
paint.getCycleMethod() != CycleMethod.REPEAT && |
|
paint.getColorSpace() != ColorSpaceType.LINEAR_RGB) |
|
{ |
|
// we can delegate to the optimized two-color gradient |
|
|
|
return true; |
|
} |
|
|
|
return super.isPaintValid(sg2d); |
|
} |
|
} |
|
|
|
/********************** RadialGradientPaint support *************************/ |
|
|
|
private static class RadialGradient extends MultiGradient { |
|
private RadialGradient() {} |
|
} |
|
} |