use of java.awt.Composite in project android_frameworks_base by ParanoidAndroid.
the class GcSnapshot method createCustomGraphics.
/**
* Creates a new {@link Graphics2D} based on the {@link Paint} parameters.
* <p/>The object must be disposed ({@link Graphics2D#dispose()}) after being used.
*/
private Graphics2D createCustomGraphics(Graphics2D original, Paint_Delegate paint, boolean compositeOnly, boolean forceSrcMode) {
// make new one graphics
Graphics2D g = (Graphics2D) original.create();
if (paint.isAntiAliased()) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
boolean customShader = false;
// get the shader first, as it'll replace the color if it can be used it.
if (compositeOnly == false) {
Shader_Delegate shaderDelegate = paint.getShader();
if (shaderDelegate != null) {
if (shaderDelegate.isSupported()) {
java.awt.Paint shaderPaint = shaderDelegate.getJavaPaint();
assert shaderPaint != null;
if (shaderPaint != null) {
g.setPaint(shaderPaint);
customShader = true;
}
} else {
Bridge.getLog().fidelityWarning(LayoutLog.TAG_SHADER, shaderDelegate.getSupportMessage(), null, /*throwable*/
null);
}
}
// if no shader, use the paint color
if (customShader == false) {
g.setColor(new Color(paint.getColor(), true));
}
// set the stroke
g.setStroke(paint.getJavaStroke());
}
// the alpha for the composite. Always opaque if the normal paint color is used since
// it contains the alpha
int alpha = (compositeOnly || customShader) ? paint.getAlpha() : 0xFF;
if (forceSrcMode) {
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, (float) alpha / 255.f));
} else {
boolean customXfermode = false;
Xfermode_Delegate xfermodeDelegate = paint.getXfermode();
if (xfermodeDelegate != null) {
if (xfermodeDelegate.isSupported()) {
Composite composite = xfermodeDelegate.getComposite(alpha);
assert composite != null;
if (composite != null) {
g.setComposite(composite);
customXfermode = true;
}
} else {
Bridge.getLog().fidelityWarning(LayoutLog.TAG_XFERMODE, xfermodeDelegate.getSupportMessage(), null, /*throwable*/
null);
}
}
// that will handle the alpha.
if (customXfermode == false && alpha != 0xFF) {
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) alpha / 255.f));
}
}
return g;
}
use of java.awt.Composite in project EnrichmentMapApp by BaderLab.
the class ColorGradientWidget method clearImage.
/**
* Utility function to clean the background of the image.
*/
private void clearImage(Graphics2D image2D) {
// set the alpha composite on the image, and clear its area
Composite origComposite = image2D.getComposite();
image2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
image2D.setComposite(origComposite);
}
use of java.awt.Composite in project jdk8u_jdk by JetBrains.
the class BufferedTextPipe method drawGlyphList.
@Override
protected void drawGlyphList(SunGraphics2D sg2d, GlyphList gl) {
/*
* The native drawGlyphList() only works with two composite types:
* - CompositeType.SrcOver (with any extra alpha), or
* - CompositeType.Xor
*/
Composite comp = sg2d.composite;
if (comp == AlphaComposite.Src) {
/*
* In addition to the composite types listed above, the logic
* in OGL/D3DSurfaceData.validatePipe() allows for
* CompositeType.SrcNoEa, but only in the presence of an opaque
* color. If we reach this case, we know the color is opaque,
* and therefore SrcNoEa is the same as SrcOverNoEa, so we
* override the composite here.
*/
comp = AlphaComposite.SrcOver;
}
rq.lock();
try {
validateContext(sg2d, comp);
enqueueGlyphList(sg2d, gl);
} finally {
rq.unlock();
}
}
use of java.awt.Composite in project jdk8u_jdk by JetBrains.
the class SunGraphics2D method clearRect.
public void clearRect(int x, int y, int w, int h) {
// REMIND: has some "interesting" consequences if threads are
// not synchronized
Composite c = composite;
Paint p = paint;
setComposite(AlphaComposite.Src);
setColor(getBackground());
fillRect(x, y, w, h);
setPaint(p);
setComposite(c);
}
use of java.awt.Composite in project jdk8u_jdk by JetBrains.
the class GDIRenderer method doFillSpans.
// REMIND: This is just a hack to get WIDE lines to honor the
// necessary hinted pixelization rules. This should be replaced
// by a native FillSpans method or a getHintedStrokeGeneralPath()
// method that could be filled by the doShape method more quickly.
public void doFillSpans(SunGraphics2D sg2d, SpanIterator si) {
int[] box = new int[4];
GDIWindowSurfaceData sd;
try {
sd = (GDIWindowSurfaceData) sg2d.surfaceData;
} catch (ClassCastException e) {
throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
}
Region clip = sg2d.getCompClip();
Composite comp = sg2d.composite;
int eargb = sg2d.eargb;
while (si.nextSpan(box)) {
doFillRect(sd, clip, comp, eargb, box[0], box[1], box[2] - box[0], box[3] - box[1]);
}
}
Aggregations