Search in sources :

Example 6 with Blit

use of sun.java2d.loops.Blit 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 7 with Blit

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

the class GeneralCompositePipe method renderPathTile.

/**
    * GeneralCompositePipe.renderPathTile works with custom composite operator
    * provided by an application
    */
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;
    CompositeContext compCtxt = context.compCtxt;
    SunGraphics2D sg = context.sunG2D;
    Raster srcRaster = paintCtxt.getRaster(x, y, w, h);
    ColorModel paintModel = paintCtxt.getColorModel();
    Raster dstRaster;
    Raster dstIn;
    WritableRaster dstOut;
    SurfaceData sd = sg.getSurfaceData();
    dstRaster = sd.getRaster(x, y, w, h);
    if (dstRaster instanceof WritableRaster && atile == null) {
        dstOut = (WritableRaster) dstRaster;
        dstOut = dstOut.createWritableChild(x, y, w, h, 0, 0, null);
        dstIn = dstOut;
    } else {
        dstIn = dstRaster.createChild(x, y, w, h, 0, 0, null);
        dstOut = dstIn.createCompatibleWritableRaster();
    }
    compCtxt.compose(srcRaster, dstIn, dstOut);
    if (dstRaster != dstOut && dstOut.getParent() != dstRaster) {
        if (dstRaster instanceof WritableRaster && atile == null) {
            ((WritableRaster) dstRaster).setDataElements(x, y, dstOut);
        } else {
            ColorModel cm = sg.getDeviceColorModel();
            BufferedImage resImg = new BufferedImage(cm, dstOut, cm.isAlphaPremultiplied(), null);
            SurfaceData resData = BufImgSurfaceData.createData(resImg);
            if (atile == null) {
                Blit blit = Blit.getFromCache(resData.getSurfaceType(), CompositeType.SrcNoEa, sd.getSurfaceType());
                blit.Blit(resData, sd, AlphaComposite.Src, null, 0, 0, x, y, w, h);
            } else {
                MaskBlit blit = MaskBlit.getFromCache(resData.getSurfaceType(), CompositeType.SrcNoEa, sd.getSurfaceType());
                blit.MaskBlit(resData, sd, AlphaComposite.Src, null, 0, 0, x, y, w, h, atile, offset, tilesize);
            }
        }
    }
}
Also used : SurfaceData(sun.java2d.SurfaceData) BufImgSurfaceData(sun.awt.image.BufImgSurfaceData) CompositeContext(java.awt.CompositeContext) ColorModel(java.awt.image.ColorModel) WritableRaster(java.awt.image.WritableRaster) MaskBlit(sun.java2d.loops.MaskBlit) Raster(java.awt.image.Raster) WritableRaster(java.awt.image.WritableRaster) Blit(sun.java2d.loops.Blit) MaskBlit(sun.java2d.loops.MaskBlit) PaintContext(java.awt.PaintContext) SunGraphics2D(sun.java2d.SunGraphics2D) BufferedImage(java.awt.image.BufferedImage)

Example 8 with Blit

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

the class D3DSurfaceToGDIWindowSurfaceTransform method Blit.

public synchronized void Blit(SurfaceData src, SurfaceData dst, Composite comp, Region clip, int sx, int sy, int dx, int dy, int w, int h) {
    Blit convertsrc = Blit.getFromCache(src.getSurfaceType(), CompositeType.SrcNoEa, SurfaceType.IntArgbPre);
    SurfaceData cachedSrc = null;
    if (srcTmp != null) {
        // use cached intermediate surface, if available
        cachedSrc = (SurfaceData) srcTmp.get();
    }
    // convert source to IntArgbPre
    src = convertFrom(convertsrc, src, sx, sy, w, h, cachedSrc, BufferedImage.TYPE_INT_ARGB_PRE);
    // copy IntArgbPre intermediate surface to D3D surface
    performop.Blit(src, dst, comp, clip, 0, 0, dx, dy, w, h);
    if (src != cachedSrc) {
        // cache the intermediate surface
        srcTmp = new WeakReference(src);
    }
}
Also used : SurfaceData(sun.java2d.SurfaceData) GDIWindowSurfaceData(sun.java2d.windows.GDIWindowSurfaceData) WeakReference(java.lang.ref.WeakReference) Blit(sun.java2d.loops.Blit) TransformBlit(sun.java2d.loops.TransformBlit) ScaledBlit(sun.java2d.loops.ScaledBlit)

Example 9 with Blit

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

the class DrawImage method renderImageXform.

protected void renderImageXform(SunGraphics2D sg, Image img, AffineTransform tx, int interpType, int sx1, int sy1, int sx2, int sy2, Color bgColor) {
    final AffineTransform itx;
    try {
        itx = tx.createInverse();
    } catch (final NoninvertibleTransformException ignored) {
        // Non-invertible transform means no output
        return;
    }
    /*
         * Find the maximum bounds on the destination that will be
         * affected by the transformed source.  First, transform all
         * four corners of the source and then min and max the resulting
         * destination coordinates of the transformed corners.
         * Note that tx already has the offset to sx1,sy1 accounted
         * for so we use the box (0, 0, sx2-sx1, sy2-sy1) as the
         * source coordinates.
         */
    final double[] coords = new double[8];
    /* corner:  UL      UR      LL      LR   */
    /* index:  0  1    2  3    4  5    6  7  */
    /* coord: (0, 0), (w, 0), (0, h), (w, h) */
    coords[2] = coords[6] = sx2 - sx1;
    coords[5] = coords[7] = sy2 - sy1;
    tx.transform(coords, 0, coords, 0, 4);
    double ddx1, ddy1, ddx2, ddy2;
    ddx1 = ddx2 = coords[0];
    ddy1 = ddy2 = coords[1];
    for (int i = 2; i < coords.length; i += 2) {
        double d = coords[i];
        if (ddx1 > d)
            ddx1 = d;
        else if (ddx2 < d)
            ddx2 = d;
        d = coords[i + 1];
        if (ddy1 > d)
            ddy1 = d;
        else if (ddy2 < d)
            ddy2 = d;
    }
    Region clip = sg.getCompClip();
    final int dx1 = Math.max((int) Math.floor(ddx1), clip.lox);
    final int dy1 = Math.max((int) Math.floor(ddy1), clip.loy);
    final int dx2 = Math.min((int) Math.ceil(ddx2), clip.hix);
    final int dy2 = Math.min((int) Math.ceil(ddy2), clip.hiy);
    if (dx2 <= dx1 || dy2 <= dy1) {
        // empty destination means no output
        return;
    }
    final SurfaceData dstData = sg.surfaceData;
    SurfaceData srcData = dstData.getSourceSurfaceData(img, SunGraphics2D.TRANSFORM_GENERIC, sg.imageComp, bgColor);
    if (srcData == null) {
        img = getBufferedImage(img);
        srcData = dstData.getSourceSurfaceData(img, SunGraphics2D.TRANSFORM_GENERIC, sg.imageComp, bgColor);
        if (srcData == null) {
            // REMIND: Is this correct?  Can this happen?
            return;
        }
    }
    if (isBgOperation(srcData, bgColor)) {
        // We cannot perform bg operations during transform so make
        // an opaque temp image with the appropriate background
        // and work from there.
        img = makeBufferedImage(img, bgColor, BufferedImage.TYPE_INT_RGB, sx1, sy1, sx2, sy2);
        // Temp image has appropriate subimage at 0,0 now.
        sx2 -= sx1;
        sy2 -= sy1;
        sx1 = sy1 = 0;
        srcData = dstData.getSourceSurfaceData(img, SunGraphics2D.TRANSFORM_GENERIC, sg.imageComp, bgColor);
    }
    SurfaceType srcType = srcData.getSurfaceType();
    TransformHelper helper = TransformHelper.getFromCache(srcType);
    if (helper == null) {
        /* We have no helper for this source image type.
             * But we know that we do have helpers for both RGB and ARGB,
             * so convert to one of those types depending on transparency.
             * ARGB_PRE might be a better choice if the source image has
             * alpha, but it may cause some recursion here since we only
             * tend to have converters that convert to ARGB.
             */
        int type = ((srcData.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB);
        img = makeBufferedImage(img, null, type, sx1, sy1, sx2, sy2);
        // Temp image has appropriate subimage at 0,0 now.
        sx2 -= sx1;
        sy2 -= sy1;
        sx1 = sy1 = 0;
        srcData = dstData.getSourceSurfaceData(img, SunGraphics2D.TRANSFORM_GENERIC, sg.imageComp, null);
        srcType = srcData.getSurfaceType();
        helper = TransformHelper.getFromCache(srcType);
    // assert(helper != null);
    }
    SurfaceType dstType = dstData.getSurfaceType();
    if (sg.compositeState <= SunGraphics2D.COMP_ALPHA) {
        /* NOTE: We either have, or we can make,
             * a MaskBlit for any alpha composite type
             */
        MaskBlit maskblit = MaskBlit.getFromCache(SurfaceType.IntArgbPre, sg.imageComp, dstType);
        /* NOTE: We can only use the native TransformHelper
             * func to go directly to the dest if both the helper
             * and the MaskBlit are native.
             * All helpers are native at this point, but some MaskBlit
             * objects are implemented in Java, so we need to check.
             */
        if (maskblit.getNativePrim() != 0) {
            // We can render directly.
            helper.Transform(maskblit, srcData, dstData, sg.composite, clip, itx, interpType, sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2, null, 0, 0);
            return;
        }
    }
    // We need to transform to a temp image and then copy
    // just the pieces that are valid data to the dest.
    final int w = dx2 - dx1;
    final int h = dy2 - dy1;
    BufferedImage tmpimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
    SurfaceData tmpData = SurfaceData.getPrimarySurfaceData(tmpimg);
    SurfaceType tmpType = tmpData.getSurfaceType();
    MaskBlit tmpmaskblit = MaskBlit.getFromCache(SurfaceType.IntArgbPre, CompositeType.SrcNoEa, tmpType);
    /*
         * The helper function fills a temporary edges buffer
         * for us with the bounding coordinates of each scanline
         * in the following format:
         *
         * edges[0, 1] = [top y, bottom y)
         * edges[2, 3] = [left x, right x) of top row
         * ...
         * edges[h*2, h*2+1] = [left x, right x) of bottom row
         *
         * all coordinates in the edges array will be relative to dx1, dy1
         *
         * edges thus has to be h*2+2 in length
         */
    final int[] edges = new int[h * 2 + 2];
    // It is important that edges[0]=edges[1]=0 when we call
    // Transform in case it must return early and we would
    // not want to render anything on an error condition.
    helper.Transform(tmpmaskblit, srcData, tmpData, AlphaComposite.Src, null, itx, interpType, sx1, sy1, sx2, sy2, 0, 0, w, h, edges, dx1, dy1);
    final Region region = Region.getInstance(dx1, dy1, dx2, dy2, edges);
    clip = clip.getIntersection(region);
    /* NOTE: We either have, or we can make,
         * a Blit for any composite type, even Custom
         */
    final Blit blit = Blit.getFromCache(tmpType, sg.imageComp, dstType);
    blit.Blit(tmpData, dstData, sg.composite, clip, 0, 0, dx1, dy1, w, h);
}
Also used : Blit(sun.java2d.loops.Blit) MaskBlit(sun.java2d.loops.MaskBlit) ScaledBlit(sun.java2d.loops.ScaledBlit) SurfaceType(sun.java2d.loops.SurfaceType) TransformHelper(sun.java2d.loops.TransformHelper) BufferedImage(java.awt.image.BufferedImage) NoninvertibleTransformException(java.awt.geom.NoninvertibleTransformException) SurfaceData(sun.java2d.SurfaceData) MaskBlit(sun.java2d.loops.MaskBlit) AffineTransform(java.awt.geom.AffineTransform)

Example 10 with Blit

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

the class SurfaceDataProxy method updateSurfaceData.

/**
     * This is the default implementation for updating the cached
     * SurfaceData from the source (primary) SurfaceData.
     * A simple Blit is used to copy the pixels from the source to
     * the destination SurfaceData.
     * A subclass can override this implementation if a more complex
     * operation is required to update its cached copies.
     */
public void updateSurfaceData(SurfaceData srcData, SurfaceData dstData, int w, int h) {
    SurfaceType srcType = srcData.getSurfaceType();
    SurfaceType dstType = dstData.getSurfaceType();
    Blit blit = Blit.getFromCache(srcType, CompositeType.SrcNoEa, dstType);
    blit.Blit(srcData, dstData, AlphaComposite.Src, null, 0, 0, 0, 0, w, h);
    dstData.markDirty();
}
Also used : Blit(sun.java2d.loops.Blit) SurfaceType(sun.java2d.loops.SurfaceType)

Aggregations

Blit (sun.java2d.loops.Blit)14 ScaledBlit (sun.java2d.loops.ScaledBlit)9 SurfaceData (sun.java2d.SurfaceData)7 TransformBlit (sun.java2d.loops.TransformBlit)7 BufferedImage (java.awt.image.BufferedImage)3 MaskBlit (sun.java2d.loops.MaskBlit)3 SurfaceType (sun.java2d.loops.SurfaceType)3 WritableRaster (java.awt.image.WritableRaster)2 WeakReference (java.lang.ref.WeakReference)2 BufImgSurfaceData (sun.awt.image.BufImgSurfaceData)2 CompositeType (sun.java2d.loops.CompositeType)2 GraphicsPrimitive (sun.java2d.loops.GraphicsPrimitive)2 GDIWindowSurfaceData (sun.java2d.windows.GDIWindowSurfaceData)2 AlphaComposite (java.awt.AlphaComposite)1 Composite (java.awt.Composite)1 CompositeContext (java.awt.CompositeContext)1 GradientPaint (java.awt.GradientPaint)1 LinearGradientPaint (java.awt.LinearGradientPaint)1 Paint (java.awt.Paint)1 PaintContext (java.awt.PaintContext)1