Search in sources :

Example 16 with Composite

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;
}
Also used : Shader_Delegate(android.graphics.Shader_Delegate) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) Color(java.awt.Color) Xfermode_Delegate(android.graphics.Xfermode_Delegate) Paint(android.graphics.Paint) Graphics2D(java.awt.Graphics2D)

Example 17 with Composite

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);
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite)

Example 18 with Composite

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();
    }
}
Also used : AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite)

Example 19 with Composite

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);
}
Also used : Composite(java.awt.Composite) XORComposite(sun.java2d.loops.XORComposite) AlphaComposite(java.awt.AlphaComposite) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) TexturePaint(java.awt.TexturePaint) LinearGradientPaint(java.awt.LinearGradientPaint) GradientPaint(java.awt.GradientPaint)

Example 20 with Composite

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]);
    }
}
Also used : InvalidPipeException(sun.java2d.InvalidPipeException) Composite(java.awt.Composite) Region(sun.java2d.pipe.Region)

Aggregations

Composite (java.awt.Composite)21 AlphaComposite (java.awt.AlphaComposite)18 Paint (android.graphics.Paint)6 Xfermode_Delegate (android.graphics.Xfermode_Delegate)6 Shape (java.awt.Shape)6 Color (java.awt.Color)5 Graphics2D (java.awt.Graphics2D)4 Paint (java.awt.Paint)4 TexturePaint (java.awt.TexturePaint)4 AffineTransform (java.awt.geom.AffineTransform)4 BasicStroke (java.awt.BasicStroke)2 GradientPaint (java.awt.GradientPaint)2 LinearGradientPaint (java.awt.LinearGradientPaint)2 RadialGradientPaint (java.awt.RadialGradientPaint)2 Rectangle (java.awt.Rectangle)2 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)2 Rectangle2D (java.awt.geom.Rectangle2D)2 BufferedImage (java.awt.image.BufferedImage)2 RectangleInsets (org.jfree.ui.RectangleInsets)2 Shader_Delegate (android.graphics.Shader_Delegate)1