Search in sources :

Example 6 with Xfermode_Delegate

use of android.graphics.Xfermode_Delegate 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)

Aggregations

Paint (android.graphics.Paint)6 Xfermode_Delegate (android.graphics.Xfermode_Delegate)6 AlphaComposite (java.awt.AlphaComposite)6 Composite (java.awt.Composite)6 Shader_Delegate (android.graphics.Shader_Delegate)1 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1