Search in sources :

Example 1 with PaintContext

use of java.awt.PaintContext 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 2 with PaintContext

use of java.awt.PaintContext 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 3 with PaintContext

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

the class GeneralCompositePipe method startSequence.

public Object startSequence(SunGraphics2D sg, Shape s, Rectangle devR, int[] abox) {
    RenderingHints hints = sg.getRenderingHints();
    ColorModel model = sg.getDeviceColorModel();
    PaintContext paintContext = sg.paint.createContext(model, devR, s.getBounds2D(), sg.cloneTransform(), hints);
    CompositeContext compositeContext = sg.composite.createContext(paintContext.getColorModel(), model, hints);
    return new TileContext(sg, paintContext, compositeContext, model);
}
Also used : CompositeContext(java.awt.CompositeContext) ColorModel(java.awt.image.ColorModel) PaintContext(java.awt.PaintContext) RenderingHints(java.awt.RenderingHints)

Aggregations

PaintContext (java.awt.PaintContext)3 ColorModel (java.awt.image.ColorModel)3 CompositeContext (java.awt.CompositeContext)2 BufferedImage (java.awt.image.BufferedImage)2 Raster (java.awt.image.Raster)2 WritableRaster (java.awt.image.WritableRaster)2 BufImgSurfaceData (sun.awt.image.BufImgSurfaceData)2 SunGraphics2D (sun.java2d.SunGraphics2D)2 SurfaceData (sun.java2d.SurfaceData)2 RenderingHints (java.awt.RenderingHints)1 WeakReference (java.lang.ref.WeakReference)1 Blit (sun.java2d.loops.Blit)1 CompositeType (sun.java2d.loops.CompositeType)1 MaskBlit (sun.java2d.loops.MaskBlit)1