Search in sources :

Example 1 with CompositeType

use of sun.java2d.loops.CompositeType in project jdk8u_jdk by JetBrains.

the class SunGraphics2D method setComposite.

/**
     * Sets the Composite in the current graphics state. Composite is used
     * in all drawing methods such as drawImage, drawString, drawPath,
     * and fillPath.  It specifies how new pixels are to be combined with
     * the existing pixels on the graphics device in the rendering process.
     * @param comp The Composite object to be used for drawing.
     * @see java.awt.Graphics#setXORMode
     * @see java.awt.Graphics#setPaintMode
     * @see AlphaComposite
     */
public void setComposite(Composite comp) {
    if (composite == comp) {
        return;
    }
    int newCompState;
    CompositeType newCompType;
    if (comp instanceof AlphaComposite) {
        AlphaComposite alphacomp = (AlphaComposite) comp;
        newCompType = CompositeType.forAlphaComposite(alphacomp);
        if (newCompType == CompositeType.SrcOverNoEa) {
            if (paintState == PAINT_OPAQUECOLOR || (paintState > PAINT_ALPHACOLOR && paint.getTransparency() == Transparency.OPAQUE)) {
                newCompState = COMP_ISCOPY;
            } else {
                newCompState = COMP_ALPHA;
            }
        } else if (newCompType == CompositeType.SrcNoEa || newCompType == CompositeType.Src || newCompType == CompositeType.Clear) {
            newCompState = COMP_ISCOPY;
        } else if (surfaceData.getTransparency() == Transparency.OPAQUE && newCompType == CompositeType.SrcIn) {
            newCompState = COMP_ISCOPY;
        } else {
            newCompState = COMP_ALPHA;
        }
    } else if (comp instanceof XORComposite) {
        newCompState = COMP_XOR;
        newCompType = CompositeType.Xor;
    } else if (comp == null) {
        throw new IllegalArgumentException("null Composite");
    } else {
        surfaceData.checkCustomComposite();
        newCompState = COMP_CUSTOM;
        newCompType = CompositeType.General;
    }
    if (compositeState != newCompState || imageComp != newCompType) {
        compositeState = newCompState;
        imageComp = newCompType;
        invalidatePipe();
        validFontInfo = false;
    }
    composite = comp;
    if (paintState <= PAINT_ALPHACOLOR) {
        validateColor();
    }
}
Also used : 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) CompositeType(sun.java2d.loops.CompositeType)

Example 2 with CompositeType

use of sun.java2d.loops.CompositeType in project jdk8u_jdk by JetBrains.

the class SunGraphics2D method doCopyArea.

private void doCopyArea(int x, int y, int w, int h, int dx, int dy) {
    if (w <= 0 || h <= 0) {
        return;
    }
    SurfaceData theData = surfaceData;
    if (theData.copyArea(this, x, y, w, h, dx, dy)) {
        return;
    }
    if (transformState > TRANSFORM_TRANSLATESCALE) {
        throw new InternalError("transformed copyArea not implemented yet");
    }
    // REMIND: This method does not deal with missing data from the
    // source object (i.e. it does not send exposure events...)
    Region clip = getCompClip();
    Composite comp = composite;
    if (lastCAcomp != comp) {
        SurfaceType dsttype = theData.getSurfaceType();
        CompositeType comptype = imageComp;
        if (CompositeType.SrcOverNoEa.equals(comptype) && theData.getTransparency() == Transparency.OPAQUE) {
            comptype = CompositeType.SrcNoEa;
        }
        lastCAblit = Blit.locate(dsttype, comptype, dsttype);
        lastCAcomp = comp;
    }
    double[] coords = { x, y, x + w, y + h, x + dx, y + dy };
    transform.transform(coords, 0, coords, 0, 3);
    x = (int) Math.ceil(coords[0] - 0.5);
    y = (int) Math.ceil(coords[1] - 0.5);
    w = ((int) Math.ceil(coords[2] - 0.5)) - x;
    h = ((int) Math.ceil(coords[3] - 0.5)) - y;
    dx = ((int) Math.ceil(coords[4] - 0.5)) - x;
    dy = ((int) Math.ceil(coords[5] - 0.5)) - y;
    // In case of negative scale transform, reflect the rect coords.
    if (w < 0) {
        w *= -1;
        x -= w;
    }
    if (h < 0) {
        h *= -1;
        y -= h;
    }
    Blit ob = lastCAblit;
    if (dy == 0 && dx > 0 && dx < w) {
        while (w > 0) {
            int partW = Math.min(w, dx);
            w -= partW;
            int sx = x + w;
            ob.Blit(theData, theData, comp, clip, sx, y, sx + dx, y + dy, partW, h);
        }
        return;
    }
    if (dy > 0 && dy < h && dx > -w && dx < w) {
        while (h > 0) {
            int partH = Math.min(h, dy);
            h -= partH;
            int sy = y + h;
            ob.Blit(theData, theData, comp, clip, x, sy, x + dx, sy + dy, w, partH);
        }
        return;
    }
    ob.Blit(theData, theData, comp, clip, x, y, x + dx, y + dy, w, h);
}
Also used : Composite(java.awt.Composite) XORComposite(sun.java2d.loops.XORComposite) AlphaComposite(java.awt.AlphaComposite) Region(sun.java2d.pipe.Region) Blit(sun.java2d.loops.Blit) SurfaceType(sun.java2d.loops.SurfaceType) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) TexturePaint(java.awt.TexturePaint) LinearGradientPaint(java.awt.LinearGradientPaint) GradientPaint(java.awt.GradientPaint) CompositeType(sun.java2d.loops.CompositeType)

Example 3 with CompositeType

use of sun.java2d.loops.CompositeType in project jdk8u_jdk by JetBrains.

the class AlphaPaintPipe method renderPathTile.

public void renderPathTile(Object ctx, byte[] atile, int offset, int tilesize, int x, int y, int w, int h) {
    TileContext context = (TileContext) ctx;
    PaintContext paintCtxt = context.paintCtxt;
    SunGraphics2D sg = context.sunG2D;
    SurfaceData dstData = context.dstData;
    SurfaceData srcData = null;
    Raster lastRas = null;
    if (context.lastData != null && context.lastRaster != null) {
        srcData = (SurfaceData) context.lastData.get();
        lastRas = (Raster) context.lastRaster.get();
        if (srcData == null || lastRas == null) {
            srcData = null;
            lastRas = null;
        }
    }
    ColorModel paintModel = context.paintModel;
    for (int rely = 0; rely < h; rely += TILE_SIZE) {
        int ty = y + rely;
        int th = Math.min(h - rely, TILE_SIZE);
        for (int relx = 0; relx < w; relx += TILE_SIZE) {
            int tx = x + relx;
            int tw = Math.min(w - relx, TILE_SIZE);
            Raster srcRaster = paintCtxt.getRaster(tx, ty, tw, th);
            if ((srcRaster.getMinX() != 0) || (srcRaster.getMinY() != 0)) {
                srcRaster = srcRaster.createTranslatedChild(0, 0);
            }
            if (lastRas != srcRaster) {
                lastRas = srcRaster;
                context.lastRaster = new WeakReference(lastRas);
                // REMIND: This will fail for a non-Writable raster!
                BufferedImage bImg = new BufferedImage(paintModel, (WritableRaster) srcRaster, paintModel.isAlphaPremultiplied(), null);
                srcData = BufImgSurfaceData.createData(bImg);
                context.lastData = new WeakReference(srcData);
                context.lastMask = null;
                context.lastBlit = null;
            }
            if (atile == null) {
                if (context.lastBlit == null) {
                    CompositeType comptype = sg.imageComp;
                    if (CompositeType.SrcOverNoEa.equals(comptype) && paintModel.getTransparency() == Transparency.OPAQUE) {
                        comptype = CompositeType.SrcNoEa;
                    }
                    context.lastBlit = Blit.getFromCache(srcData.getSurfaceType(), comptype, dstData.getSurfaceType());
                }
                context.lastBlit.Blit(srcData, dstData, sg.composite, null, 0, 0, tx, ty, tw, th);
            } else {
                if (context.lastMask == null) {
                    CompositeType comptype = sg.imageComp;
                    if (CompositeType.SrcOverNoEa.equals(comptype) && paintModel.getTransparency() == Transparency.OPAQUE) {
                        comptype = CompositeType.SrcNoEa;
                    }
                    context.lastMask = MaskBlit.getFromCache(srcData.getSurfaceType(), comptype, dstData.getSurfaceType());
                }
                int toff = offset + rely * tilesize + relx;
                context.lastMask.MaskBlit(srcData, dstData, sg.composite, null, 0, 0, tx, ty, tw, th, atile, toff, tilesize);
            }
        }
    }
}
Also used : SurfaceData(sun.java2d.SurfaceData) BufImgSurfaceData(sun.awt.image.BufImgSurfaceData) ColorModel(java.awt.image.ColorModel) Raster(java.awt.image.Raster) WritableRaster(java.awt.image.WritableRaster) WeakReference(java.lang.ref.WeakReference) PaintContext(java.awt.PaintContext) SunGraphics2D(sun.java2d.SunGraphics2D) BufferedImage(java.awt.image.BufferedImage) CompositeType(sun.java2d.loops.CompositeType)

Example 4 with CompositeType

use of sun.java2d.loops.CompositeType in project jdk8u_jdk by JetBrains.

the class DrawImage method blitSurfaceData.

protected void blitSurfaceData(SunGraphics2D sg, Region clipRegion, SurfaceData srcData, SurfaceData dstData, SurfaceType srcType, SurfaceType dstType, int sx, int sy, int dx, int dy, int w, int h, Color bgColor) {
    if (w <= 0 || h <= 0) {
        /*
             * Fix for bugid 4783274 - BlitBg throws an exception for
             * a particular set of anomalous parameters.
             * REMIND: The native loops do proper clipping and would
             * detect this situation themselves, but the Java loops
             * all seem to trust their parameters a little too well
             * to the point where they will try to process a negative
             * area of pixels and throw exceptions.  The real fix is
             * to modify the Java loops to do proper clipping so that
             * they can deal with negative dimensions as well as
             * improperly large dimensions, but that fix is too risky
             * to integrate for Mantis at this point.  In the meantime
             * eliminating the negative or zero dimensions here is
             * "correct" and saves them from some nasty exceptional
             * conditions, one of which is the test case of 4783274.
             */
        return;
    }
    CompositeType comp = sg.imageComp;
    if (CompositeType.SrcOverNoEa.equals(comp) && (srcData.getTransparency() == Transparency.OPAQUE || (bgColor != null && bgColor.getTransparency() == Transparency.OPAQUE))) {
        comp = CompositeType.SrcNoEa;
    }
    if (!isBgOperation(srcData, bgColor)) {
        Blit blit = Blit.getFromCache(srcType, comp, dstType);
        blit.Blit(srcData, dstData, sg.composite, clipRegion, sx, sy, dx, dy, w, h);
    } else {
        BlitBg blit = BlitBg.getFromCache(srcType, comp, dstType);
        blit.BlitBg(srcData, dstData, sg.composite, clipRegion, bgColor.getRGB(), sx, sy, dx, dy, w, h);
    }
}
Also used : BlitBg(sun.java2d.loops.BlitBg) Blit(sun.java2d.loops.Blit) MaskBlit(sun.java2d.loops.MaskBlit) ScaledBlit(sun.java2d.loops.ScaledBlit) CompositeType(sun.java2d.loops.CompositeType)

Example 5 with CompositeType

use of sun.java2d.loops.CompositeType in project jdk8u_jdk by JetBrains.

the class DrawImage method scaleSurfaceData.

protected boolean scaleSurfaceData(SunGraphics2D sg, Region clipRegion, SurfaceData srcData, SurfaceData dstData, SurfaceType srcType, SurfaceType dstType, int sx1, int sy1, int sx2, int sy2, double dx1, double dy1, double dx2, double dy2) {
    CompositeType comp = sg.imageComp;
    if (CompositeType.SrcOverNoEa.equals(comp) && (srcData.getTransparency() == Transparency.OPAQUE)) {
        comp = CompositeType.SrcNoEa;
    }
    ScaledBlit blit = ScaledBlit.getFromCache(srcType, comp, dstType);
    if (blit != null) {
        blit.Scale(srcData, dstData, sg.composite, clipRegion, sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2);
        return true;
    }
    return false;
}
Also used : ScaledBlit(sun.java2d.loops.ScaledBlit) CompositeType(sun.java2d.loops.CompositeType)

Aggregations

CompositeType (sun.java2d.loops.CompositeType)9 SurfaceType (sun.java2d.loops.SurfaceType)3 AlphaComposite (java.awt.AlphaComposite)2 GradientPaint (java.awt.GradientPaint)2 LinearGradientPaint (java.awt.LinearGradientPaint)2 Paint (java.awt.Paint)2 RadialGradientPaint (java.awt.RadialGradientPaint)2 TexturePaint (java.awt.TexturePaint)2 Blit (sun.java2d.loops.Blit)2 ScaledBlit (sun.java2d.loops.ScaledBlit)2 XORComposite (sun.java2d.loops.XORComposite)2 Region (sun.java2d.pipe.Region)2 Composite (java.awt.Composite)1 PaintContext (java.awt.PaintContext)1 BufferedImage (java.awt.image.BufferedImage)1 ColorModel (java.awt.image.ColorModel)1 Raster (java.awt.image.Raster)1 WritableRaster (java.awt.image.WritableRaster)1 WeakReference (java.lang.ref.WeakReference)1 BufImgSurfaceData (sun.awt.image.BufImgSurfaceData)1