Search in sources :

Example 6 with AlphaComposite

use of java.awt.AlphaComposite in project jdk8u_jdk by JetBrains.

the class BufferedContext method setComposite.

private void setComposite(Composite comp, int flags) {
    // assert rq.lock.isHeldByCurrentThread();
    if (comp instanceof AlphaComposite) {
        AlphaComposite ac = (AlphaComposite) comp;
        rq.ensureCapacity(16);
        buf.putInt(SET_ALPHA_COMPOSITE);
        buf.putInt(ac.getRule());
        buf.putFloat(ac.getAlpha());
        buf.putInt(flags);
    } else if (comp instanceof XORComposite) {
        int xorPixel = ((XORComposite) comp).getXorPixel();
        rq.ensureCapacity(8);
        buf.putInt(SET_XOR_COMPOSITE);
        buf.putInt(xorPixel);
    } else {
        throw new InternalError("not yet implemented");
    }
}
Also used : XORComposite(sun.java2d.loops.XORComposite) AlphaComposite(java.awt.AlphaComposite)

Example 7 with AlphaComposite

use of java.awt.AlphaComposite in project jdk8u_jdk by JetBrains.

the class SunGraphics2D method validateColor.

/*
     * Validate the eargb and pixel fields against the current color.
     *
     * The eargb field must take into account the extraAlpha
     * value of an AlphaComposite.  It may also take into account
     * the Fsrc Porter-Duff blending function if such a function is
     * a constant (see handling of Clear mode below).  For instance,
     * by factoring in the (Fsrc == 0) state of the Clear mode we can
     * use a SrcNoEa loop just as easily as a general Alpha loop
     * since the math will be the same in both cases.
     *
     * The pixel field will always be the best pixel data choice for
     * the final result of all calculations applied to the eargb field.
     *
     * Note that this method is only necessary under the following
     * conditions:
     *     (paintState <= PAINT_ALPHA_COLOR &&
     *      compositeState <= COMP_CUSTOM)
     * though nothing bad will happen if it is run in other states.
     */
final void validateColor() {
    int eargb;
    if (imageComp == CompositeType.Clear) {
        eargb = 0;
    } else {
        eargb = foregroundColor.getRGB();
        if (compositeState <= COMP_ALPHA && imageComp != CompositeType.SrcNoEa && imageComp != CompositeType.SrcOverNoEa) {
            AlphaComposite alphacomp = (AlphaComposite) composite;
            int a = Math.round(alphacomp.getAlpha() * (eargb >>> 24));
            eargb = (eargb & 0x00ffffff) | (a << 24);
        }
    }
    this.eargb = eargb;
    this.pixel = surfaceData.pixelFor(eargb);
}
Also used : 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 8 with AlphaComposite

use of java.awt.AlphaComposite in project jdk8u_jdk by JetBrains.

the class GraphicsTests method initContext.

public void initContext(TestEnvironment env, Context ctx) {
    ctx.graphics = env.getGraphics();
    int w = env.getWidth();
    int h = env.getHeight();
    ctx.size = env.getIntValue(sizeList);
    ctx.outdim = getOutputSize(ctx.size, ctx.size);
    ctx.pixscale = 1.0;
    if (hasGraphics2D) {
        Graphics2D g2d = (Graphics2D) ctx.graphics;
        AlphaComposite ac = (AlphaComposite) env.getModifier(compRules);
        if (env.isEnabled(doExtraAlpha)) {
            ac = AlphaComposite.getInstance(ac.getRule(), 0.125f);
        }
        g2d.setComposite(ac);
        if (env.isEnabled(doXor)) {
            g2d.setXORMode(Color.white);
        }
        if (env.isEnabled(doClipping)) {
            Polygon p = new Polygon();
            p.addPoint(0, 0);
            p.addPoint(w, 0);
            p.addPoint(0, h);
            p.addPoint(w, h);
            p.addPoint(0, 0);
            g2d.clip(p);
        }
        Transform tx = (Transform) env.getModifier(transforms);
        Dimension envdim = new Dimension(w, h);
        tx.init(g2d, ctx, envdim);
        w = envdim.width;
        h = envdim.height;
        g2d.setRenderingHint(RenderingHints.KEY_RENDERING, env.getModifier(renderHint));
    }
    switch(env.getIntValue(animList)) {
        case 0:
            ctx.animate = false;
            ctx.maxX = 3;
            ctx.maxY = 1;
            ctx.orgX = (w - ctx.outdim.width) / 2;
            ctx.orgY = (h - ctx.outdim.height) / 2;
            break;
        case 1:
            ctx.animate = true;
            ctx.maxX = Math.max(Math.min(32, w - ctx.outdim.width), 3);
            ctx.maxY = 1;
            ctx.orgX = (w - ctx.outdim.width - ctx.maxX) / 2;
            ctx.orgY = (h - ctx.outdim.height) / 2;
            break;
        case 2:
            ctx.animate = true;
            ctx.maxX = (w - ctx.outdim.width) + 1;
            ctx.maxY = (h - ctx.outdim.height) + 1;
            ctx.maxX = adjustWidth(ctx.maxX, ctx.maxY);
            ctx.maxX = Math.max(ctx.maxX, 3);
            ctx.maxY = Math.max(ctx.maxY, 1);
            // ctx.orgX = ctx.orgY = 0;
            break;
    }
    ctx.initX = ctx.maxX / 2;
    ctx.initY = ctx.maxY / 2;
}
Also used : AlphaComposite(java.awt.AlphaComposite) Dimension(java.awt.Dimension) Polygon(java.awt.Polygon) AffineTransform(java.awt.geom.AffineTransform) Graphics2D(java.awt.Graphics2D)

Example 9 with AlphaComposite

use of java.awt.AlphaComposite in project jdk8u_jdk by JetBrains.

the class PeekMetrics method checkAlpha.

/**
     * Record information about drawing done
     * with the supplied <code>Composite</code>.
     */
private void checkAlpha(Composite composite) {
    if (composite instanceof AlphaComposite) {
        AlphaComposite alphaComposite = (AlphaComposite) composite;
        float alpha = alphaComposite.getAlpha();
        int rule = alphaComposite.getRule();
        if (alpha != 1.0 || (rule != AlphaComposite.SRC && rule != AlphaComposite.SRC_OVER)) {
            mHasCompositing = true;
        }
    } else {
        mHasCompositing = true;
    }
}
Also used : AlphaComposite(java.awt.AlphaComposite) Paint(java.awt.Paint)

Example 10 with AlphaComposite

use of java.awt.AlphaComposite in project jdk8u_jdk by JetBrains.

the class D3DSurfaceData method validatePipe.

public void validatePipe(SunGraphics2D sg2d) {
    TextPipe textpipe;
    boolean validated = false;
    // for the surface which had any XOR rendering done to.
    if (sg2d.compositeState >= sg2d.COMP_XOR) {
        super.validatePipe(sg2d);
        sg2d.imagepipe = d3dImagePipe;
        disableAccelerationForSurface();
        return;
    }
    if (/* CompositeType.SrcNoEa (any color) */
    (sg2d.compositeState <= sg2d.COMP_ISCOPY && sg2d.paintState <= sg2d.PAINT_ALPHACOLOR) || /* CompositeType.SrcOver (any color) */
    (sg2d.compositeState == sg2d.COMP_ALPHA && sg2d.paintState <= sg2d.PAINT_ALPHACOLOR && (((AlphaComposite) sg2d.composite).getRule() == AlphaComposite.SRC_OVER)) || /* CompositeType.Xor (any color) */
    (sg2d.compositeState == sg2d.COMP_XOR && sg2d.paintState <= sg2d.PAINT_ALPHACOLOR)) {
        textpipe = d3dTextPipe;
    } else {
        // do this to initialize textpipe correctly; we will attempt
        // to override the non-text pipes below
        super.validatePipe(sg2d);
        textpipe = sg2d.textpipe;
        validated = true;
    }
    PixelToParallelogramConverter txPipe = null;
    D3DRenderer nonTxPipe = null;
    if (sg2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
        if (sg2d.paintState <= sg2d.PAINT_ALPHACOLOR) {
            if (sg2d.compositeState <= sg2d.COMP_XOR) {
                txPipe = d3dTxRenderPipe;
                nonTxPipe = d3dRenderPipe;
            }
        } else if (sg2d.compositeState <= sg2d.COMP_ALPHA) {
            if (D3DPaints.isValid(sg2d)) {
                txPipe = d3dTxRenderPipe;
                nonTxPipe = d3dRenderPipe;
            }
        // custom paints handled by super.validatePipe() below
        }
    } else {
        if (sg2d.paintState <= sg2d.PAINT_ALPHACOLOR) {
            if (graphicsDevice.isCapPresent(CAPS_AA_SHADER) && (sg2d.imageComp == CompositeType.SrcOverNoEa || sg2d.imageComp == CompositeType.SrcOver)) {
                if (!validated) {
                    super.validatePipe(sg2d);
                    validated = true;
                }
                PixelToParallelogramConverter aaConverter = new PixelToParallelogramConverter(sg2d.shapepipe, d3dAAPgramPipe, 1.0 / 8.0, 0.499, false);
                sg2d.drawpipe = aaConverter;
                sg2d.fillpipe = aaConverter;
                sg2d.shapepipe = aaConverter;
            } else if (sg2d.compositeState == sg2d.COMP_XOR) {
                // install the solid pipes when AA and XOR are both enabled
                txPipe = d3dTxRenderPipe;
                nonTxPipe = d3dRenderPipe;
            }
        }
    // other cases handled by super.validatePipe() below
    }
    if (txPipe != null) {
        if (sg2d.transformState >= sg2d.TRANSFORM_TRANSLATESCALE) {
            sg2d.drawpipe = txPipe;
            sg2d.fillpipe = txPipe;
        } else if (sg2d.strokeState != sg2d.STROKE_THIN) {
            sg2d.drawpipe = txPipe;
            sg2d.fillpipe = nonTxPipe;
        } else {
            sg2d.drawpipe = nonTxPipe;
            sg2d.fillpipe = nonTxPipe;
        }
        // Note that we use the transforming pipe here because it
        // will examine the shape and possibly perform an optimized
        // operation if it can be simplified.  The simplifications
        // will be valid for all STROKE and TRANSFORM types.
        sg2d.shapepipe = txPipe;
    } else {
        if (!validated) {
            super.validatePipe(sg2d);
        }
    }
    // install the text pipe based on our earlier decision
    sg2d.textpipe = textpipe;
    // always override the image pipe with the specialized D3D pipe
    sg2d.imagepipe = d3dImagePipe;
}
Also used : AlphaComposite(java.awt.AlphaComposite) TextPipe(sun.java2d.pipe.TextPipe) PixelToParallelogramConverter(sun.java2d.pipe.PixelToParallelogramConverter)

Aggregations

AlphaComposite (java.awt.AlphaComposite)10 Paint (java.awt.Paint)3 GradientPaint (java.awt.GradientPaint)2 LinearGradientPaint (java.awt.LinearGradientPaint)2 RadialGradientPaint (java.awt.RadialGradientPaint)2 TexturePaint (java.awt.TexturePaint)2 AffineTransform (java.awt.geom.AffineTransform)2 XORComposite (sun.java2d.loops.XORComposite)2 PixelToParallelogramConverter (sun.java2d.pipe.PixelToParallelogramConverter)2 TextPipe (sun.java2d.pipe.TextPipe)2 Composite (java.awt.Composite)1 Dimension (java.awt.Dimension)1 Graphics2D (java.awt.Graphics2D)1 Polygon (java.awt.Polygon)1 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)1 Rectangle2D (java.awt.geom.Rectangle2D)1 JFreeChart (org.jfree.chart.JFreeChart)1 Plot (org.jfree.chart.plot.Plot)1 CompositeType (sun.java2d.loops.CompositeType)1