Java Code Examples for sun.java2d.SurfaceData#getSourceSurfaceData()

The following examples show how to use sun.java2d.SurfaceData#getSourceSurfaceData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: D3DDrawImage.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void renderImageXform(SunGraphics2D sg, Image img,
                                AffineTransform tx, int interpType,
                                int sx1, int sy1, int sx2, int sy2,
                                Color bgColor)
{
    // punt to the MediaLib-based transformImage() in the superclass if:
    //     - bicubic interpolation is specified
    //     - a background color is specified and will be used
    //     - an appropriate TransformBlit primitive could not be found
    if (interpType != AffineTransformOp.TYPE_BICUBIC) {
        SurfaceData dstData = sg.surfaceData;
        SurfaceData srcData =
            dstData.getSourceSurfaceData(img,
                                         sg.TRANSFORM_GENERIC,
                                         sg.imageComp,
                                         bgColor);

        if (srcData != null && !isBgOperation(srcData, bgColor)) {
            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);
}
 
Example 2
Source File: D3DDrawImage.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void renderImageXform(SunGraphics2D sg, Image img,
                                AffineTransform tx, int interpType,
                                int sx1, int sy1, int sx2, int sy2,
                                Color bgColor)
{
    // punt to the MediaLib-based transformImage() in the superclass if:
    //     - bicubic interpolation is specified
    //     - a background color is specified and will be used
    //     - an appropriate TransformBlit primitive could not be found
    if (interpType != AffineTransformOp.TYPE_BICUBIC) {
        SurfaceData dstData = sg.surfaceData;
        SurfaceData srcData =
            dstData.getSourceSurfaceData(img,
                                         sg.TRANSFORM_GENERIC,
                                         sg.imageComp,
                                         bgColor);

        if (srcData != null && !isBgOperation(srcData, bgColor)) {
            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);
}
 
Example 3
Source File: D3DDrawImage.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void renderImageXform(SunGraphics2D sg, Image img,
                                AffineTransform tx, int interpType,
                                int sx1, int sy1, int sx2, int sy2,
                                Color bgColor)
{
    // punt to the MediaLib-based transformImage() in the superclass if:
    //     - bicubic interpolation is specified
    //     - a background color is specified and will be used
    //     - an appropriate TransformBlit primitive could not be found
    if (interpType != AffineTransformOp.TYPE_BICUBIC) {
        SurfaceData dstData = sg.surfaceData;
        SurfaceData srcData =
            dstData.getSourceSurfaceData(img,
                                         sg.TRANSFORM_GENERIC,
                                         sg.imageComp,
                                         bgColor);

        if (srcData != null && !isBgOperation(srcData, bgColor)) {
            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);
}
 
Example 4
Source File: D3DDrawImage.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void renderImageXform(SunGraphics2D sg, Image img,
                                AffineTransform tx, int interpType,
                                int sx1, int sy1, int sx2, int sy2,
                                Color bgColor)
{
    // punt to the MediaLib-based transformImage() in the superclass if:
    //     - bicubic interpolation is specified
    //     - a background color is specified and will be used
    //     - an appropriate TransformBlit primitive could not be found
    if (interpType != AffineTransformOp.TYPE_BICUBIC) {
        SurfaceData dstData = sg.surfaceData;
        SurfaceData srcData =
            dstData.getSourceSurfaceData(img,
                                         sg.TRANSFORM_GENERIC,
                                         sg.imageComp,
                                         bgColor);

        if (srcData != null && !isBgOperation(srcData, bgColor)) {
            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);
}
 
Example 5
Source File: D3DDrawImage.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void renderImageXform(SunGraphics2D sg, Image img,
                                AffineTransform tx, int interpType,
                                int sx1, int sy1, int sx2, int sy2,
                                Color bgColor)
{
    // punt to the MediaLib-based transformImage() in the superclass if:
    //     - bicubic interpolation is specified
    //     - a background color is specified and will be used
    //     - an appropriate TransformBlit primitive could not be found
    if (interpType != AffineTransformOp.TYPE_BICUBIC) {
        SurfaceData dstData = sg.surfaceData;
        SurfaceData srcData =
            dstData.getSourceSurfaceData(img,
                                         sg.TRANSFORM_GENERIC,
                                         sg.imageComp,
                                         bgColor);

        if (srcData != null && !isBgOperation(srcData, bgColor)) {
            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);
}
 
Example 6
Source File: BufferedPaints.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * We use OpenGL's texture coordinate generator to automatically
 * map the TexturePaint image to the geometry being rendered.  The
 * generator uses two separate plane equations that take the (x,y)
 * location (in device space) of the fragment being rendered to
 * calculate (u,v) texture coordinates for that fragment:
 *     u = Ax + By + Cz + Dw
 *     v = Ex + Fy + Gz + Hw
 *
 * Since we use a 2D orthographic projection, we can assume that z=0
 * and w=1 for any fragment.  So we need to calculate appropriate
 * values for the plane equation constants (A,B,D) and (E,F,H) such
 * that {u,v}=0 for the top-left of the TexturePaint's anchor
 * rectangle and {u,v}=1 for the bottom-right of the anchor rectangle.
 * We can easily make the texture image repeat for {u,v} values
 * outside the range [0,1] by specifying the GL_REPEAT texture wrap
 * mode.
 *
 * Calculating the plane equation constants is surprisingly simple.
 * We can think of it as an inverse matrix operation that takes
 * device space coordinates and transforms them into user space
 * coordinates that correspond to a location relative to the anchor
 * rectangle.  First, we translate and scale the current user space
 * transform by applying the anchor rectangle bounds.  We then take
 * the inverse of this affine transform.  The rows of the resulting
 * inverse matrix correlate nicely to the plane equation constants
 * we were seeking.
 */
private static void setTexturePaint(RenderQueue rq,
                                    SunGraphics2D sg2d,
                                    TexturePaint paint,
                                    boolean useMask)
{
    BufferedImage bi = paint.getImage();
    SurfaceData dstData = sg2d.surfaceData;
    SurfaceData srcData =
        dstData.getSourceSurfaceData(bi, SunGraphics2D.TRANSFORM_ISIDENT,
                                     CompositeType.SrcOver, null);
    boolean filter =
        (sg2d.interpolationType !=
         AffineTransformOp.TYPE_NEAREST_NEIGHBOR);

    // calculate plane equation constants
    AffineTransform at = (AffineTransform)sg2d.transform.clone();
    Rectangle2D anchor = paint.getAnchorRect();
    at.translate(anchor.getX(), anchor.getY());
    at.scale(anchor.getWidth(), anchor.getHeight());

    double xp0, xp1, xp3, yp0, yp1, yp3;
    try {
        at.invert();
        xp0 = at.getScaleX();
        xp1 = at.getShearX();
        xp3 = at.getTranslateX();
        yp0 = at.getShearY();
        yp1 = at.getScaleY();
        yp3 = at.getTranslateY();
    } catch (java.awt.geom.NoninvertibleTransformException e) {
        xp0 = xp1 = xp3 = yp0 = yp1 = yp3 = 0.0;
    }

    // assert rq.lock.isHeldByCurrentThread();
    rq.ensureCapacityAndAlignment(68, 12);
    RenderBuffer buf = rq.getBuffer();
    buf.putInt(SET_TEXTURE_PAINT);
    buf.putInt(useMask ? 1 : 0);
    buf.putInt(filter ? 1 : 0);
    buf.putLong(srcData.getNativeOps());
    buf.putDouble(xp0).putDouble(xp1).putDouble(xp3);
    buf.putDouble(yp0).putDouble(yp1).putDouble(yp3);
}
 
Example 7
Source File: D3DBufImgOps.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method is called from D3DDrawImage.transformImage() only.  It
 * validates the provided BufferedImageOp to determine whether the op
 * is one that can be accelerated by the D3D 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)
{
    // Validate the provided BufferedImage (make sure it is one that
    // 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 D3DSurfaceData) ||
        (sg.interpolationType == AffineTransformOp.TYPE_BICUBIC) ||
        (sg.compositeState > SunGraphics2D.COMP_ALPHA))
    {
        return false;
    }

    SurfaceData srcData =
        dstData.getSourceSurfaceData(img, sg.TRANSFORM_ISIDENT,
                                     CompositeType.SrcOver, null);
    if (!(srcData instanceof D3DSurfaceData)) {
        // REMIND: this hack tries to ensure that we have a cached texture
        srcData =
            dstData.getSourceSurfaceData(img, sg.TRANSFORM_ISIDENT,
                                         CompositeType.SrcOver, null);
        if (!(srcData instanceof D3DSurfaceData)) {
            return false;
        }
    }

    // Verify that the source surface is actually a texture and that
    // shaders are supported
    D3DSurfaceData d3dSrc = (D3DSurfaceData)srcData;
    D3DGraphicsDevice gd =
        (D3DGraphicsDevice)d3dSrc.getDeviceConfiguration().getDevice();
    if (d3dSrc.getType() != D3DSurfaceData.TEXTURE ||
        !gd.isCapPresent(CAPS_LCD_SHADER))
    {
        return false;
    }

    int sw = img.getWidth();
    int sh = img.getHeight();
    D3DBlitLoops.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;
}
 
Example 8
Source File: OGLBufImgOps.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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)
{
    // Validate the provided BufferedImage (make sure it is one that
    // 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;
}
 
Example 9
Source File: D3DBufImgOps.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method is called from D3DDrawImage.transformImage() only.  It
 * validates the provided BufferedImageOp to determine whether the op
 * is one that can be accelerated by the D3D 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)
{
    // Validate the provided BufferedImage (make sure it is one that
    // 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 D3DSurfaceData) ||
        (sg.interpolationType == AffineTransformOp.TYPE_BICUBIC) ||
        (sg.compositeState > SunGraphics2D.COMP_ALPHA))
    {
        return false;
    }

    SurfaceData srcData =
        dstData.getSourceSurfaceData(img, sg.TRANSFORM_ISIDENT,
                                     CompositeType.SrcOver, null);
    if (!(srcData instanceof D3DSurfaceData)) {
        // REMIND: this hack tries to ensure that we have a cached texture
        srcData =
            dstData.getSourceSurfaceData(img, sg.TRANSFORM_ISIDENT,
                                         CompositeType.SrcOver, null);
        if (!(srcData instanceof D3DSurfaceData)) {
            return false;
        }
    }

    // Verify that the source surface is actually a texture and that
    // shaders are supported
    D3DSurfaceData d3dSrc = (D3DSurfaceData)srcData;
    D3DGraphicsDevice gd =
        (D3DGraphicsDevice)d3dSrc.getDeviceConfiguration().getDevice();
    if (d3dSrc.getType() != D3DSurfaceData.TEXTURE ||
        !gd.isCapPresent(CAPS_LCD_SHADER))
    {
        return false;
    }

    int sw = img.getWidth();
    int sh = img.getHeight();
    D3DBlitLoops.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;
}
 
Example 10
Source File: D3DBufImgOps.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method is called from D3DDrawImage.transformImage() only.  It
 * validates the provided BufferedImageOp to determine whether the op
 * is one that can be accelerated by the D3D 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)
{
    // Validate the provided BufferedImage (make sure it is one that
    // 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 D3DSurfaceData) ||
        (sg.interpolationType == AffineTransformOp.TYPE_BICUBIC) ||
        (sg.compositeState > SunGraphics2D.COMP_ALPHA))
    {
        return false;
    }

    SurfaceData srcData =
        dstData.getSourceSurfaceData(img, sg.TRANSFORM_ISIDENT,
                                     CompositeType.SrcOver, null);
    if (!(srcData instanceof D3DSurfaceData)) {
        // REMIND: this hack tries to ensure that we have a cached texture
        srcData =
            dstData.getSourceSurfaceData(img, sg.TRANSFORM_ISIDENT,
                                         CompositeType.SrcOver, null);
        if (!(srcData instanceof D3DSurfaceData)) {
            return false;
        }
    }

    // Verify that the source surface is actually a texture and that
    // shaders are supported
    D3DSurfaceData d3dSrc = (D3DSurfaceData)srcData;
    D3DGraphicsDevice gd =
        (D3DGraphicsDevice)d3dSrc.getDeviceConfiguration().getDevice();
    if (d3dSrc.getType() != D3DSurfaceData.TEXTURE ||
        !gd.isCapPresent(CAPS_LCD_SHADER))
    {
        return false;
    }

    int sw = img.getWidth();
    int sh = img.getHeight();
    D3DBlitLoops.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;
}
 
Example 11
Source File: D3DBufImgOps.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method is called from D3DDrawImage.transformImage() only.  It
 * validates the provided BufferedImageOp to determine whether the op
 * is one that can be accelerated by the D3D 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)
{
    // Validate the provided BufferedImage (make sure it is one that
    // 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 D3DSurfaceData) ||
        (sg.interpolationType == AffineTransformOp.TYPE_BICUBIC) ||
        (sg.compositeState > SunGraphics2D.COMP_ALPHA))
    {
        return false;
    }

    SurfaceData srcData =
        dstData.getSourceSurfaceData(img, sg.TRANSFORM_ISIDENT,
                                     CompositeType.SrcOver, null);
    if (!(srcData instanceof D3DSurfaceData)) {
        // REMIND: this hack tries to ensure that we have a cached texture
        srcData =
            dstData.getSourceSurfaceData(img, sg.TRANSFORM_ISIDENT,
                                         CompositeType.SrcOver, null);
        if (!(srcData instanceof D3DSurfaceData)) {
            return false;
        }
    }

    // Verify that the source surface is actually a texture and that
    // shaders are supported
    D3DSurfaceData d3dSrc = (D3DSurfaceData)srcData;
    D3DGraphicsDevice gd =
        (D3DGraphicsDevice)d3dSrc.getDeviceConfiguration().getDevice();
    if (d3dSrc.getType() != D3DSurfaceData.TEXTURE ||
        !gd.isCapPresent(CAPS_LCD_SHADER))
    {
        return false;
    }

    int sw = img.getWidth();
    int sh = img.getHeight();
    D3DBlitLoops.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;
}
 
Example 12
Source File: D3DBufImgOps.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method is called from D3DDrawImage.transformImage() only.  It
 * validates the provided BufferedImageOp to determine whether the op
 * is one that can be accelerated by the D3D 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)
{
    // Validate the provided BufferedImage (make sure it is one that
    // 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 D3DSurfaceData) ||
        (sg.interpolationType == AffineTransformOp.TYPE_BICUBIC) ||
        (sg.compositeState > SunGraphics2D.COMP_ALPHA))
    {
        return false;
    }

    SurfaceData srcData =
        dstData.getSourceSurfaceData(img, sg.TRANSFORM_ISIDENT,
                                     CompositeType.SrcOver, null);
    if (!(srcData instanceof D3DSurfaceData)) {
        // REMIND: this hack tries to ensure that we have a cached texture
        srcData =
            dstData.getSourceSurfaceData(img, sg.TRANSFORM_ISIDENT,
                                         CompositeType.SrcOver, null);
        if (!(srcData instanceof D3DSurfaceData)) {
            return false;
        }
    }

    // Verify that the source surface is actually a texture and that
    // shaders are supported
    D3DSurfaceData d3dSrc = (D3DSurfaceData)srcData;
    D3DGraphicsDevice gd =
        (D3DGraphicsDevice)d3dSrc.getDeviceConfiguration().getDevice();
    if (d3dSrc.getType() != D3DSurfaceData.TEXTURE ||
        !gd.isCapPresent(CAPS_LCD_SHADER))
    {
        return false;
    }

    int sw = img.getWidth();
    int sh = img.getHeight();
    D3DBlitLoops.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;
}
 
Example 13
Source File: OGLDrawImage.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void renderImageXform(SunGraphics2D sg, Image img,
                                AffineTransform tx, int interpType,
                                int sx1, int sy1, int sx2, int sy2,
                                Color bgColor)
{
    // punt to the MediaLib-based transformImage() in the superclass if:
    //     - bicubic interpolation is specified
    //     - a background color is specified and will be used
    //     - the source surface is neither a texture nor render-to-texture
    //       surface, and a non-default interpolation hint is specified
    //       (we can only control the filtering for texture->surface
    //       copies)
    //         REMIND: we should tweak the sw->texture->surface
    //         transform case to handle filtering appropriately
    //         (see 4841762)...
    //     - 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);
}
 
Example 14
Source File: OGLBufImgOps.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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)
{
    // Validate the provided BufferedImage (make sure it is one that
    // 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;
}
 
Example 15
Source File: OGLDrawImage.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void renderImageXform(SunGraphics2D sg, Image img,
                                AffineTransform tx, int interpType,
                                int sx1, int sy1, int sx2, int sy2,
                                Color bgColor)
{
    // punt to the MediaLib-based transformImage() in the superclass if:
    //     - bicubic interpolation is specified
    //     - a background color is specified and will be used
    //     - the source surface is neither a texture nor render-to-texture
    //       surface, and a non-default interpolation hint is specified
    //       (we can only control the filtering for texture->surface
    //       copies)
    //         REMIND: we should tweak the sw->texture->surface
    //         transform case to handle filtering appropriately
    //         (see 4841762)...
    //     - 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);
}
 
Example 16
Source File: OGLDrawImage.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void renderImageXform(SunGraphics2D sg, Image img,
                                AffineTransform tx, int interpType,
                                int sx1, int sy1, int sx2, int sy2,
                                Color bgColor)
{
    // punt to the MediaLib-based transformImage() in the superclass if:
    //     - bicubic interpolation is specified
    //     - a background color is specified and will be used
    //     - the source surface is neither a texture nor render-to-texture
    //       surface, and a non-default interpolation hint is specified
    //       (we can only control the filtering for texture->surface
    //       copies)
    //         REMIND: we should tweak the sw->texture->surface
    //         transform case to handle filtering appropriately
    //         (see 4841762)...
    //     - 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);
}
 
Example 17
Source File: OGLDrawImage.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void renderImageXform(SunGraphics2D sg, Image img,
                                AffineTransform tx, int interpType,
                                int sx1, int sy1, int sx2, int sy2,
                                Color bgColor)
{
    // punt to the MediaLib-based transformImage() in the superclass if:
    //     - bicubic interpolation is specified
    //     - a background color is specified and will be used
    //     - the source surface is neither a texture nor render-to-texture
    //       surface, and a non-default interpolation hint is specified
    //       (we can only control the filtering for texture->surface
    //       copies)
    //         REMIND: we should tweak the sw->texture->surface
    //         transform case to handle filtering appropriately
    //         (see 4841762)...
    //     - 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);
}
 
Example 18
Source File: BufferedPaints.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * We use OpenGL's texture coordinate generator to automatically
 * map the TexturePaint image to the geometry being rendered.  The
 * generator uses two separate plane equations that take the (x,y)
 * location (in device space) of the fragment being rendered to
 * calculate (u,v) texture coordinates for that fragment:
 *     u = Ax + By + Cz + Dw
 *     v = Ex + Fy + Gz + Hw
 *
 * Since we use a 2D orthographic projection, we can assume that z=0
 * and w=1 for any fragment.  So we need to calculate appropriate
 * values for the plane equation constants (A,B,D) and (E,F,H) such
 * that {u,v}=0 for the top-left of the TexturePaint's anchor
 * rectangle and {u,v}=1 for the bottom-right of the anchor rectangle.
 * We can easily make the texture image repeat for {u,v} values
 * outside the range [0,1] by specifying the GL_REPEAT texture wrap
 * mode.
 *
 * Calculating the plane equation constants is surprisingly simple.
 * We can think of it as an inverse matrix operation that takes
 * device space coordinates and transforms them into user space
 * coordinates that correspond to a location relative to the anchor
 * rectangle.  First, we translate and scale the current user space
 * transform by applying the anchor rectangle bounds.  We then take
 * the inverse of this affine transform.  The rows of the resulting
 * inverse matrix correlate nicely to the plane equation constants
 * we were seeking.
 */
private static void setTexturePaint(RenderQueue rq,
                                    SunGraphics2D sg2d,
                                    TexturePaint paint,
                                    boolean useMask)
{
    BufferedImage bi = paint.getImage();
    SurfaceData dstData = sg2d.surfaceData;
    SurfaceData srcData =
        dstData.getSourceSurfaceData(bi, SunGraphics2D.TRANSFORM_ISIDENT,
                                     CompositeType.SrcOver, null);
    boolean filter =
        (sg2d.interpolationType !=
         AffineTransformOp.TYPE_NEAREST_NEIGHBOR);

    // calculate plane equation constants
    AffineTransform at = (AffineTransform)sg2d.transform.clone();
    Rectangle2D anchor = paint.getAnchorRect();
    at.translate(anchor.getX(), anchor.getY());
    at.scale(anchor.getWidth(), anchor.getHeight());

    double xp0, xp1, xp3, yp0, yp1, yp3;
    try {
        at.invert();
        xp0 = at.getScaleX();
        xp1 = at.getShearX();
        xp3 = at.getTranslateX();
        yp0 = at.getShearY();
        yp1 = at.getScaleY();
        yp3 = at.getTranslateY();
    } catch (java.awt.geom.NoninvertibleTransformException e) {
        xp0 = xp1 = xp3 = yp0 = yp1 = yp3 = 0.0;
    }

    // assert rq.lock.isHeldByCurrentThread();
    rq.ensureCapacityAndAlignment(68, 12);
    RenderBuffer buf = rq.getBuffer();
    buf.putInt(SET_TEXTURE_PAINT);
    buf.putInt(useMask ? 1 : 0);
    buf.putInt(filter ? 1 : 0);
    buf.putLong(srcData.getNativeOps());
    buf.putDouble(xp0).putDouble(xp1).putDouble(xp3);
    buf.putDouble(yp0).putDouble(yp1).putDouble(yp3);
}
 
Example 19
Source File: BufferedPaints.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * We use OpenGL's texture coordinate generator to automatically
 * map the TexturePaint image to the geometry being rendered.  The
 * generator uses two separate plane equations that take the (x,y)
 * location (in device space) of the fragment being rendered to
 * calculate (u,v) texture coordinates for that fragment:
 *     u = Ax + By + Cz + Dw
 *     v = Ex + Fy + Gz + Hw
 *
 * Since we use a 2D orthographic projection, we can assume that z=0
 * and w=1 for any fragment.  So we need to calculate appropriate
 * values for the plane equation constants (A,B,D) and (E,F,H) such
 * that {u,v}=0 for the top-left of the TexturePaint's anchor
 * rectangle and {u,v}=1 for the bottom-right of the anchor rectangle.
 * We can easily make the texture image repeat for {u,v} values
 * outside the range [0,1] by specifying the GL_REPEAT texture wrap
 * mode.
 *
 * Calculating the plane equation constants is surprisingly simple.
 * We can think of it as an inverse matrix operation that takes
 * device space coordinates and transforms them into user space
 * coordinates that correspond to a location relative to the anchor
 * rectangle.  First, we translate and scale the current user space
 * transform by applying the anchor rectangle bounds.  We then take
 * the inverse of this affine transform.  The rows of the resulting
 * inverse matrix correlate nicely to the plane equation constants
 * we were seeking.
 */
private static void setTexturePaint(RenderQueue rq,
                                    SunGraphics2D sg2d,
                                    TexturePaint paint,
                                    boolean useMask)
{
    BufferedImage bi = paint.getImage();
    SurfaceData dstData = sg2d.surfaceData;
    SurfaceData srcData =
        dstData.getSourceSurfaceData(bi, SunGraphics2D.TRANSFORM_ISIDENT,
                                     CompositeType.SrcOver, null);
    boolean filter =
        (sg2d.interpolationType !=
         AffineTransformOp.TYPE_NEAREST_NEIGHBOR);

    // calculate plane equation constants
    AffineTransform at = (AffineTransform)sg2d.transform.clone();
    Rectangle2D anchor = paint.getAnchorRect();
    at.translate(anchor.getX(), anchor.getY());
    at.scale(anchor.getWidth(), anchor.getHeight());

    double xp0, xp1, xp3, yp0, yp1, yp3;
    try {
        at.invert();
        xp0 = at.getScaleX();
        xp1 = at.getShearX();
        xp3 = at.getTranslateX();
        yp0 = at.getShearY();
        yp1 = at.getScaleY();
        yp3 = at.getTranslateY();
    } catch (java.awt.geom.NoninvertibleTransformException e) {
        xp0 = xp1 = xp3 = yp0 = yp1 = yp3 = 0.0;
    }

    // assert rq.lock.isHeldByCurrentThread();
    rq.ensureCapacityAndAlignment(68, 12);
    RenderBuffer buf = rq.getBuffer();
    buf.putInt(SET_TEXTURE_PAINT);
    buf.putInt(useMask ? 1 : 0);
    buf.putInt(filter ? 1 : 0);
    buf.putLong(srcData.getNativeOps());
    buf.putDouble(xp0).putDouble(xp1).putDouble(xp3);
    buf.putDouble(yp0).putDouble(yp1).putDouble(yp3);
}
 
Example 20
Source File: OGLDrawImage.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void renderImageXform(SunGraphics2D sg, Image img,
                                AffineTransform tx, int interpType,
                                int sx1, int sy1, int sx2, int sy2,
                                Color bgColor)
{
    // punt to the MediaLib-based transformImage() in the superclass if:
    //     - bicubic interpolation is specified
    //     - a background color is specified and will be used
    //     - the source surface is neither a texture nor render-to-texture
    //       surface, and a non-default interpolation hint is specified
    //       (we can only control the filtering for texture->surface
    //       copies)
    //         REMIND: we should tweak the sw->texture->surface
    //         transform case to handle filtering appropriately
    //         (see 4841762)...
    //     - 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);
}