Search in sources :

Example 1 with SurfaceData

use of sun.java2d.SurfaceData in project jdk8u_jdk by JetBrains.

the class BufImgSurfaceData method createData.

public static SurfaceData createData(BufferedImage bufImg, double scaleX, double scaleY) {
    if (bufImg == null) {
        throw new NullPointerException("BufferedImage cannot be null");
    }
    SurfaceData sData;
    ColorModel cm = bufImg.getColorModel();
    int type = bufImg.getType();
    // REMIND: Check the image type and pick an appropriate subclass
    switch(type) {
        case BufferedImage.TYPE_INT_BGR:
            sData = createDataIC(bufImg, SurfaceType.IntBgr, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_INT_RGB:
            sData = createDataIC(bufImg, SurfaceType.IntRgb, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_INT_ARGB:
            sData = createDataIC(bufImg, SurfaceType.IntArgb, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_INT_ARGB_PRE:
            sData = createDataIC(bufImg, SurfaceType.IntArgbPre, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_3BYTE_BGR:
            sData = createDataBC(bufImg, SurfaceType.ThreeByteBgr, 2, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_4BYTE_ABGR:
            sData = createDataBC(bufImg, SurfaceType.FourByteAbgr, 3, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_4BYTE_ABGR_PRE:
            sData = createDataBC(bufImg, SurfaceType.FourByteAbgrPre, 3, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_USHORT_565_RGB:
            sData = createDataSC(bufImg, SurfaceType.Ushort565Rgb, null, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_USHORT_555_RGB:
            sData = createDataSC(bufImg, SurfaceType.Ushort555Rgb, null, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_BYTE_INDEXED:
            {
                SurfaceType sType;
                switch(cm.getTransparency()) {
                    case OPAQUE:
                        if (isOpaqueGray((IndexColorModel) cm)) {
                            sType = SurfaceType.Index8Gray;
                        } else {
                            sType = SurfaceType.ByteIndexedOpaque;
                        }
                        break;
                    case BITMASK:
                        sType = SurfaceType.ByteIndexedBm;
                        break;
                    case TRANSLUCENT:
                        sType = SurfaceType.ByteIndexed;
                        break;
                    default:
                        throw new InternalError("Unrecognized transparency");
                }
                sData = createDataBC(bufImg, sType, 0, scaleX, scaleY);
            }
            break;
        case BufferedImage.TYPE_BYTE_GRAY:
            sData = createDataBC(bufImg, SurfaceType.ByteGray, 0, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_USHORT_GRAY:
            sData = createDataSC(bufImg, SurfaceType.UshortGray, null, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_BYTE_BINARY:
            {
                SurfaceType sType;
                SampleModel sm = bufImg.getRaster().getSampleModel();
                switch(sm.getSampleSize(0)) {
                    case 1:
                        sType = SurfaceType.ByteBinary1Bit;
                        break;
                    case 2:
                        sType = SurfaceType.ByteBinary2Bit;
                        break;
                    case 4:
                        sType = SurfaceType.ByteBinary4Bit;
                        break;
                    default:
                        throw new InternalError("Unrecognized pixel size");
                }
                sData = createDataBP(bufImg, sType, scaleX, scaleY);
            }
            break;
        case BufferedImage.TYPE_CUSTOM:
        default:
            {
                Raster raster = bufImg.getRaster();
                int numBands = raster.getNumBands();
                if (raster instanceof IntegerComponentRaster && raster.getNumDataElements() == 1 && ((IntegerComponentRaster) raster).getPixelStride() == 1) {
                    SurfaceType sType = SurfaceType.AnyInt;
                    if (cm instanceof DirectColorModel) {
                        DirectColorModel dcm = (DirectColorModel) cm;
                        int aMask = dcm.getAlphaMask();
                        int rMask = dcm.getRedMask();
                        int gMask = dcm.getGreenMask();
                        int bMask = dcm.getBlueMask();
                        if (numBands == 3 && aMask == 0 && rMask == DCM_RGBX_RED_MASK && gMask == DCM_RGBX_GREEN_MASK && bMask == DCM_RGBX_BLUE_MASK) {
                            sType = SurfaceType.IntRgbx;
                        } else if (numBands == 4 && aMask == DCM_ARGBBM_ALPHA_MASK && rMask == DCM_ARGBBM_RED_MASK && gMask == DCM_ARGBBM_GREEN_MASK && bMask == DCM_ARGBBM_BLUE_MASK) {
                            sType = SurfaceType.IntArgbBm;
                        } else {
                            sType = SurfaceType.AnyDcm;
                        }
                    }
                    sData = createDataIC(bufImg, sType, scaleX, scaleY);
                    break;
                } else if (raster instanceof ShortComponentRaster && raster.getNumDataElements() == 1 && ((ShortComponentRaster) raster).getPixelStride() == 1) {
                    SurfaceType sType = SurfaceType.AnyShort;
                    IndexColorModel icm = null;
                    if (cm instanceof DirectColorModel) {
                        DirectColorModel dcm = (DirectColorModel) cm;
                        int aMask = dcm.getAlphaMask();
                        int rMask = dcm.getRedMask();
                        int gMask = dcm.getGreenMask();
                        int bMask = dcm.getBlueMask();
                        if (numBands == 3 && aMask == 0 && rMask == DCM_555X_RED_MASK && gMask == DCM_555X_GREEN_MASK && bMask == DCM_555X_BLUE_MASK) {
                            sType = SurfaceType.Ushort555Rgbx;
                        } else if (numBands == 4 && aMask == DCM_4444_ALPHA_MASK && rMask == DCM_4444_RED_MASK && gMask == DCM_4444_GREEN_MASK && bMask == DCM_4444_BLUE_MASK) {
                            sType = SurfaceType.Ushort4444Argb;
                        }
                    } else if (cm instanceof IndexColorModel) {
                        icm = (IndexColorModel) cm;
                        if (icm.getPixelSize() == 12) {
                            if (isOpaqueGray(icm)) {
                                sType = SurfaceType.Index12Gray;
                            } else {
                                sType = SurfaceType.UshortIndexed;
                            }
                        } else {
                            icm = null;
                        }
                    }
                    sData = createDataSC(bufImg, sType, icm, scaleX, scaleY);
                    break;
                }
                sData = new BufImgSurfaceData(raster.getDataBuffer(), bufImg, SurfaceType.Custom, scaleX, scaleY);
            }
            break;
    }
    ((BufImgSurfaceData) sData).initSolidLoops();
    return sData;
}
Also used : Raster(java.awt.image.Raster) SurfaceType(sun.java2d.loops.SurfaceType) SampleModel(java.awt.image.SampleModel) SurfaceData(sun.java2d.SurfaceData) DirectColorModel(java.awt.image.DirectColorModel) ColorModel(java.awt.image.ColorModel) IndexColorModel(java.awt.image.IndexColorModel) DirectColorModel(java.awt.image.DirectColorModel) IndexColorModel(java.awt.image.IndexColorModel)

Example 2 with SurfaceData

use of sun.java2d.SurfaceData in project jdk8u_jdk by JetBrains.

the class VolatileSurfaceManager method flush.

/**
     * Releases any associated hardware memory for this image by
     * calling flush on sdAccel.  This method forces a lostSurface
     * situation so any future operations on the image will need to
     * revalidate the image first.
     */
public void flush() {
    lostSurface = true;
    SurfaceData oldSD = sdAccel;
    sdAccel = null;
    if (oldSD != null) {
        oldSD.flush();
    }
}
Also used : SurfaceData(sun.java2d.SurfaceData)

Example 3 with SurfaceData

use of sun.java2d.SurfaceData in project jdk8u_jdk by JetBrains.

the class VolatileSurfaceManager method displayChanged.

/**
     * Called from SunGraphicsEnv when there has been a display mode change.
     * Note that we simply invalidate hardware surfaces here; we do not
     * attempt to recreate or re-render them.  This is to avoid threading
     * conflicts with the native toolkit and associated threads.  Instead,
     * we just nullify the old surface data object and wait for a future
     * method in the rendering process to recreate the surface.
     */
public void displayChanged() {
    if (!isAccelerationEnabled()) {
        return;
    }
    lostSurface = true;
    if (sdAccel != null) {
        // First, nullify the software surface.  This guards against
        // using a SurfaceData that was created in a different
        // display mode.
        sdBackup = null;
        // Now, invalidate the old hardware-based SurfaceData
        // Note that getBackupSurface may set sdAccel to null so we have to invalidate it before
        SurfaceData oldData = sdAccel;
        sdAccel = null;
        oldData.invalidate();
        sdCurrent = getBackupSurface();
    }
    // Update graphicsConfig for the vImg in case it changed due to
    // this display change event
    vImg.updateGraphicsConfig();
}
Also used : SurfaceData(sun.java2d.SurfaceData)

Example 4 with SurfaceData

use of sun.java2d.SurfaceData in project jdk8u_jdk by JetBrains.

the class OGLBufImgOps method renderImageWithOp.

/**
     * This method is called from OGLDrawImage.transformImage() only.  It
     * validates the provided BufferedImageOp to determine whether the op
     * is one that can be accelerated by the OGL pipeline.  If the operation
     * cannot be completed for any reason, this method returns false;
     * otherwise, the given BufferedImage is rendered to the destination
     * using the provided BufferedImageOp and this method returns true.
     */
static boolean renderImageWithOp(SunGraphics2D sg, BufferedImage img, BufferedImageOp biop, int x, int y) {
    // is supported, and that its properties are acceleratable)
    if (biop instanceof ConvolveOp) {
        if (!isConvolveOpValid((ConvolveOp) biop)) {
            return false;
        }
    } else if (biop instanceof RescaleOp) {
        if (!isRescaleOpValid((RescaleOp) biop, img)) {
            return false;
        }
    } else if (biop instanceof LookupOp) {
        if (!isLookupOpValid((LookupOp) biop, img)) {
            return false;
        }
    } else {
        // No acceleration for other BufferedImageOps (yet)
        return false;
    }
    SurfaceData dstData = sg.surfaceData;
    if (!(dstData instanceof OGLSurfaceData) || (sg.interpolationType == AffineTransformOp.TYPE_BICUBIC) || (sg.compositeState > SunGraphics2D.COMP_ALPHA)) {
        return false;
    }
    SurfaceData srcData = dstData.getSourceSurfaceData(img, SunGraphics2D.TRANSFORM_ISIDENT, CompositeType.SrcOver, null);
    if (!(srcData instanceof OGLSurfaceData)) {
        // REMIND: this hack tries to ensure that we have a cached texture
        srcData = dstData.getSourceSurfaceData(img, SunGraphics2D.TRANSFORM_ISIDENT, CompositeType.SrcOver, null);
        if (!(srcData instanceof OGLSurfaceData)) {
            return false;
        }
    }
    // Verify that the source surface is actually a texture and
    // that the operation is supported
    OGLSurfaceData oglSrc = (OGLSurfaceData) srcData;
    OGLGraphicsConfig gc = oglSrc.getOGLGraphicsConfig();
    if (oglSrc.getType() != OGLSurfaceData.TEXTURE || !gc.isCapPresent(CAPS_EXT_BIOP_SHADER)) {
        return false;
    }
    int sw = img.getWidth();
    int sh = img.getHeight();
    OGLBlitLoops.IsoBlit(srcData, dstData, img, biop, sg.composite, sg.getCompClip(), sg.transform, sg.interpolationType, 0, 0, sw, sh, x, y, x + sw, y + sh, true);
    return true;
}
Also used : RescaleOp(java.awt.image.RescaleOp) SurfaceData(sun.java2d.SurfaceData) ConvolveOp(java.awt.image.ConvolveOp) LookupOp(java.awt.image.LookupOp)

Example 5 with SurfaceData

use of sun.java2d.SurfaceData in project jdk8u_jdk by JetBrains.

the class OGLDrawImage method renderImageXform.

@Override
protected void renderImageXform(SunGraphics2D sg, Image img, AffineTransform tx, int interpType, int sx1, int sy1, int sx2, int sy2, Color bgColor) {
    //     - an appropriate TransformBlit primitive could not be found
    if (interpType != AffineTransformOp.TYPE_BICUBIC) {
        SurfaceData dstData = sg.surfaceData;
        SurfaceData srcData = dstData.getSourceSurfaceData(img, SunGraphics2D.TRANSFORM_GENERIC, sg.imageComp, bgColor);
        if (srcData != null && !isBgOperation(srcData, bgColor) && (srcData.getSurfaceType() == OGLSurfaceData.OpenGLTexture || srcData.getSurfaceType() == OGLSurfaceData.OpenGLSurfaceRTT || interpType == AffineTransformOp.TYPE_NEAREST_NEIGHBOR)) {
            SurfaceType srcType = srcData.getSurfaceType();
            SurfaceType dstType = dstData.getSurfaceType();
            TransformBlit blit = TransformBlit.getFromCache(srcType, sg.imageComp, dstType);
            if (blit != null) {
                blit.Transform(srcData, dstData, sg.composite, sg.getCompClip(), tx, interpType, sx1, sy1, 0, 0, sx2 - sx1, sy2 - sy1);
                return;
            }
        }
    }
    super.renderImageXform(sg, img, tx, interpType, sx1, sy1, sx2, sy2, bgColor);
}
Also used : TransformBlit(sun.java2d.loops.TransformBlit) SurfaceData(sun.java2d.SurfaceData) SurfaceType(sun.java2d.loops.SurfaceType)

Aggregations

SurfaceData (sun.java2d.SurfaceData)39 ColorModel (java.awt.image.ColorModel)9 SunGraphics2D (sun.java2d.SunGraphics2D)7 Blit (sun.java2d.loops.Blit)7 TransformBlit (sun.java2d.loops.TransformBlit)7 ScaledBlit (sun.java2d.loops.ScaledBlit)6 SurfaceType (sun.java2d.loops.SurfaceType)6 GDIWindowSurfaceData (sun.java2d.windows.GDIWindowSurfaceData)5 Component (java.awt.Component)4 BufferedImage (java.awt.image.BufferedImage)4 OGLSurfaceData (sun.java2d.opengl.OGLSurfaceData)4 BufferCapabilities (java.awt.BufferCapabilities)3 Graphics (java.awt.Graphics)3 Raster (java.awt.image.Raster)3 WeakReference (java.lang.ref.WeakReference)3 SurfaceManager (sun.awt.image.SurfaceManager)3 InvalidPipeException (sun.java2d.InvalidPipeException)3 D3DSurfaceData (sun.java2d.d3d.D3DSurfaceData)3 Graphics2D (java.awt.Graphics2D)2 PaintContext (java.awt.PaintContext)2