java.awt.ImageCapabilities Java Examples

The following examples show how to use java.awt.ImageCapabilities. 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: SunVolatileImage.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected VolatileSurfaceManager createSurfaceManager(Object context,
                                                      ImageCapabilities caps)
{
    /**
     * Platform-specific SurfaceManagerFactories will return a
     * manager suited to acceleration on each platform.  But if
     * the user is asking for a VolatileImage from a BufferedImageGC,
     * then we need to return the appropriate unaccelerated manager.
     * Note: this could change in the future; if some platform would
     * like to accelerate BIGC volatile images, then this special-casing
     * of the BIGC graphicsConfig should live in platform-specific
     * code instead.
     * We do the same for a Printer Device, and if user requested an
     * unaccelerated VolatileImage by passing the capabilities object.
     */
    if (graphicsConfig instanceof BufferedImageGraphicsConfig ||
        graphicsConfig instanceof sun.print.PrinterGraphicsConfig ||
        (caps != null && !caps.isAccelerated()))
    {
        return new BufImgVolatileSurfaceManager(this, context);
    }
    SurfaceManagerFactory smf = SurfaceManagerFactory.getInstance();
    return smf.createVolatileManager(this, context);
}
 
Example #2
Source File: SunVolatileImage.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
protected VolatileSurfaceManager createSurfaceManager(Object context,
                                                      ImageCapabilities caps)
{
    /**
     * Platform-specific SurfaceManagerFactories will return a
     * manager suited to acceleration on each platform.  But if
     * the user is asking for a VolatileImage from a BufferedImageGC,
     * then we need to return the appropriate unaccelerated manager.
     * Note: this could change in the future; if some platform would
     * like to accelerate BIGC volatile images, then this special-casing
     * of the BIGC graphicsConfig should live in platform-specific
     * code instead.
     * We do the same for a Printer Device, and if user requested an
     * unaccelerated VolatileImage by passing the capabilities object.
     */
    if (graphicsConfig instanceof BufferedImageGraphicsConfig ||
        graphicsConfig instanceof sun.print.PrinterGraphicsConfig ||
        (caps != null && !caps.isAccelerated()))
    {
        return new BufImgVolatileSurfaceManager(this, context);
    }
    SurfaceManagerFactory smf = SurfaceManagerFactory.getInstance();
    return smf.createVolatileManager(this, context);
}
 
Example #3
Source File: CustomCompositeTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void testVolatileImage(GraphicsConfiguration cfg,
        boolean accelerated)
{
    VolatileImage dst = null;
    try {
        dst = cfg.createCompatibleVolatileImage(640, 480,
            new ImageCapabilities(accelerated));
    } catch (AWTException e) {
        System.out.println("Unable to create volatile image, skip the test.");
        return;
    }
    renderToVolatileImage(dst);
}
 
Example #4
Source File: SunVolatileImage.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public SunVolatileImage(GraphicsConfiguration graphicsConfig,
                        int width, int height, int transparency,
                        ImageCapabilities caps)
{
    this(null, graphicsConfig, width, height, null, transparency,
         caps, UNDEFINED);
}
 
Example #5
Source File: ExtendedBufferCapabilities.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an ExtendedBufferCapabilities instance with front/back/flip caps
 * from the passed image/flip caps, and the v-sync type.
 */
public ExtendedBufferCapabilities(ImageCapabilities front,
                                  ImageCapabilities back, FlipContents flip,
                                  VSyncType t)
{
    super(front, back, flip);

    this.vsync = t;
}
 
Example #6
Source File: VSyncedBufferStrategyTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void createBS(boolean requestVSync) {
    if (bs != null && requestVSync == currentBSVSynced) {
        return;
    }

    BufferCapabilities bc = defaultBC;
    if (requestVSync) {
        bc = new sun.java2d.pipe.hw.ExtendedBufferCapabilities(
                new ImageCapabilities(true),
                new ImageCapabilities(true),
                FlipContents.COPIED,
                sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.VSYNC_ON);
    }
    try {
        createBufferStrategy(2, bc);
    } catch (AWTException e) {
        System.err.println("Warning: cap is not supported: "+bc);
        e.printStackTrace();
        createBufferStrategy(2);
    }
    currentBSVSynced = requestVSync;
    bs = getBufferStrategy();
    String s =
        getParent() instanceof Frame ?
            ((Frame)getParent()).getTitle() : "parent";
    System.out.println("Created BS for \"" + s + "\" frame, bs="+bs);
}
 
Example #7
Source File: SunVolatileImage.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public SunVolatileImage(GraphicsConfiguration graphicsConfig,
                        int width, int height, int transparency,
                        ImageCapabilities caps)
{
    this(null, graphicsConfig, width, height, null, transparency,
         caps, UNDEFINED);
}
 
Example #8
Source File: SunVolatileImage.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public SunVolatileImage(GraphicsConfiguration graphicsConfig,
                        int width, int height, int transparency,
                        ImageCapabilities caps)
{
    this(null, graphicsConfig, width, height, null, transparency,
         caps, UNDEFINED);
}
 
Example #9
Source File: X11VolatileSurfaceManager.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Need to override the default behavior because Pixmaps-based
 * images are accelerated but not volatile.
 */
@Override
public ImageCapabilities getCapabilities(GraphicsConfiguration gc) {
    if (isConfigValid(gc) && isAccelerationEnabled()) {
        // accelerated but not volatile
        return new ImageCapabilities(true);
    }
    // neither accelerated nor volatile
    return new ImageCapabilities(false);
}
 
Example #10
Source File: CustomCompositeTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void testVolatileImage(GraphicsConfiguration cfg,
        boolean accelerated)
{
    VolatileImage dst = null;
    try {
        dst = cfg.createCompatibleVolatileImage(640, 480,
            new ImageCapabilities(accelerated));
    } catch (AWTException e) {
        System.out.println("Unable to create volatile image, skip the test.");
        return;
    }
    renderToVolatileImage(dst);
}
 
Example #11
Source File: SunVolatileImage.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public SunVolatileImage(GraphicsConfiguration graphicsConfig,
                        int width, int height, int transparency,
                        ImageCapabilities caps)
{
    this(null, graphicsConfig, width, height, null, transparency,
         caps, UNDEFINED);
}
 
Example #12
Source File: ExtendedBufferCapabilities.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an ExtendedBufferCapabilities instance with front/back/flip caps
 * from the passed caps, and VSYNC_DEFAULT v-sync mode.
 */
public ExtendedBufferCapabilities(ImageCapabilities front,
                                  ImageCapabilities back, FlipContents flip)
{
    super(front, back, flip);

    this.vsync = VSyncType.VSYNC_DEFAULT;
}
 
Example #13
Source File: SunVolatileImage.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public SunVolatileImage(GraphicsConfiguration graphicsConfig,
                        int width, int height, int transparency,
                        ImageCapabilities caps)
{
    this(null, graphicsConfig, width, height, null, transparency,
         caps, UNDEFINED);
}
 
Example #14
Source File: VSyncedBufferStrategyTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void createBS(boolean requestVSync) {
    if (bs != null && requestVSync == currentBSVSynced) {
        return;
    }

    BufferCapabilities bc = defaultBC;
    if (requestVSync) {
        bc = new sun.java2d.pipe.hw.ExtendedBufferCapabilities(
                new ImageCapabilities(true),
                new ImageCapabilities(true),
                FlipContents.COPIED,
                sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.VSYNC_ON);
    }
    try {
        createBufferStrategy(2, bc);
    } catch (AWTException e) {
        System.err.println("Warning: cap is not supported: "+bc);
        e.printStackTrace();
        createBufferStrategy(2);
    }
    currentBSVSynced = requestVSync;
    bs = getBufferStrategy();
    String s =
        getParent() instanceof Frame ?
            ((Frame)getParent()).getTitle() : "parent";
    System.out.println("Created BS for \"" + s + "\" frame, bs="+bs);
}
 
Example #15
Source File: XRVolatileSurfaceManager.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Need to override the default behavior because Pixmaps-based
 * images are accelerated but not volatile.
 */
@Override
public ImageCapabilities getCapabilities(GraphicsConfiguration gc) {
    if (isConfigValid(gc) && isAccelerationEnabled()) {
        return new ImageCapabilities(true);
    }
    return new ImageCapabilities(false);
}
 
Example #16
Source File: X11VolatileSurfaceManager.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Need to override the default behavior because Pixmaps-based
 * images are accelerated but not volatile.
 */
@Override
public ImageCapabilities getCapabilities(GraphicsConfiguration gc) {
    if (isConfigValid(gc) && isAccelerationEnabled()) {
        // accelerated but not volatile
        return new ImageCapabilities(true);
    }
    // neither accelerated nor volatile
    return new ImageCapabilities(false);
}
 
Example #17
Source File: SunVolatileImage.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private SunVolatileImage(Component comp,
                         GraphicsConfiguration graphicsConfig,
                         int width, int height, Object context,
                         ImageCapabilities caps)
{
    this(comp, graphicsConfig,
         width, height, context, Transparency.OPAQUE, caps, UNDEFINED);
}
 
Example #18
Source File: VSyncedBufferStrategyTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void createBS(boolean requestVSync) {
    if (bs != null && requestVSync == currentBSVSynced) {
        return;
    }

    BufferCapabilities bc = defaultBC;
    if (requestVSync) {
        bc = new sun.java2d.pipe.hw.ExtendedBufferCapabilities(
                new ImageCapabilities(true),
                new ImageCapabilities(true),
                FlipContents.COPIED,
                sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.VSYNC_ON);
    }
    try {
        createBufferStrategy(2, bc);
    } catch (AWTException e) {
        System.err.println("Warning: cap is not supported: "+bc);
        e.printStackTrace();
        createBufferStrategy(2);
    }
    currentBSVSynced = requestVSync;
    bs = getBufferStrategy();
    String s =
        getParent() instanceof Frame ?
            ((Frame)getParent()).getTitle() : "parent";
    System.out.println("Created BS for \"" + s + "\" frame, bs="+bs);
}
 
Example #19
Source File: CustomCompositeTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void testVolatileImage(GraphicsConfiguration cfg,
        boolean accelerated)
{
    VolatileImage dst = null;
    try {
        dst = cfg.createCompatibleVolatileImage(640, 480,
            new ImageCapabilities(accelerated));
    } catch (AWTException e) {
        System.out.println("Unable to create volatile image, skip the test.");
        return;
    }
    renderToVolatileImage(dst);
}
 
Example #20
Source File: XRVolatileSurfaceManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Need to override the default behavior because Pixmaps-based
 * images are accelerated but not volatile.
 */
@Override
public ImageCapabilities getCapabilities(GraphicsConfiguration gc) {
    if (isConfigValid(gc) && isAccelerationEnabled()) {
        return new ImageCapabilities(true);
    }
    return new ImageCapabilities(false);
}
 
Example #21
Source File: VolatileSurfaceManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ImageCapabilities getCapabilities(GraphicsConfiguration gc) {
    if (isConfigValid(gc)) {
        return isAccelerationEnabled() ?
            new AcceleratedImageCapabilities() :
            new ImageCapabilities(false);
    }
    return super.getCapabilities(gc);
}
 
Example #22
Source File: ExtendedBufferCapabilities.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an ExtendedBufferCapabilities instance with front/back/flip caps
 * from the passed image/flip caps, and the v-sync type.
 */
public ExtendedBufferCapabilities(ImageCapabilities front,
                                  ImageCapabilities back, FlipContents flip,
                                  VSyncType t)
{
    super(front, back, flip);

    this.vsync = t;
}
 
Example #23
Source File: VolatileSurfaceManager.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ImageCapabilities getCapabilities(GraphicsConfiguration gc) {
    if (isConfigValid(gc)) {
        return isAccelerationEnabled() ?
            new AcceleratedImageCapabilities() :
            new ImageCapabilities(false);
    }
    return super.getCapabilities(gc);
}
 
Example #24
Source File: VolatileSurfaceManager.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ImageCapabilities getCapabilities(GraphicsConfiguration gc) {
    if (isConfigValid(gc)) {
        return isAccelerationEnabled() ?
            new AcceleratedImageCapabilities() :
            new ImageCapabilities(false);
    }
    return super.getCapabilities(gc);
}
 
Example #25
Source File: SunVolatileImage.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected SunVolatileImage(Component comp,
                           GraphicsConfiguration graphicsConfig,
                           int width, int height, Object context,
                           int transparency, ImageCapabilities caps,
                           int accType)
{
    this.comp = comp;
    this.graphicsConfig = graphicsConfig;
    if (width <= 0 || height <= 0) {
        throw new IllegalArgumentException("Width (" + width + ")" +
                          " and height (" + height + ") cannot be <= 0");
    }
    this.width = width;
    this.height = height;
    this.forcedAccelSurfaceType = accType;
    if (!(transparency == Transparency.OPAQUE ||
        transparency == Transparency.BITMASK ||
        transparency == Transparency.TRANSLUCENT))
    {
        throw new IllegalArgumentException("Unknown transparency type:" +
                                           transparency);
    }
    this.transparency = transparency;
    this.volSurfaceManager = createSurfaceManager(context, caps);
    SurfaceManager.setManager(this, volSurfaceManager);

    // post-construction initialization of the surface manager
    volSurfaceManager.initialize();
    // clear the background
    volSurfaceManager.initContents();
}
 
Example #26
Source File: Tachometer.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
@Override
    public void paint(Graphics g) {
        try {
            Border border = getBorder();
            Insets insets = new Insets(0, 0, 0, 0);
            if (border != null) {
                insets = border.getBorderInsets(this);
            }
            
            int diameter = Math.min(getBounds().width - (insets.left + insets.right), getBounds().height - (insets.top + insets.bottom)) - 4;
            VolatileImage img = createVolatileImage(getBounds().width - (insets.left + insets.right), getBounds().height - (insets.top + insets.bottom), new ImageCapabilities(true));
            Graphics2D gr = img.createGraphics();

            gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            gr.drawOval(insets.left, insets.top, diameter, diameter);
            TextLayout textTl = new TextLayout("fERRARI", getFont(), gr.getFontRenderContext());
            AffineTransform at = new AffineTransform();
            at.translate(0, (float)getBounds().getHeight() - (insets.top + insets.bottom) - (float)textTl.getBounds().getHeight());
            at.scale(2d, 2d);
//            at.shear(1.3d, 0.8d);
            Shape textShape  = textTl.getOutline(at);
            gr.fill(textShape);
//            GlyphVector gv = getFont().createGlyphVector(gr.getFontRenderContext(), "fERRARI");
//            Rectangle bounds = gv.getPixelBounds(gr.getFontRenderContext(), 0, 0);
//            double scale = (double)(getBounds().width - (insets.left + insets.right)) / (double)bounds.width;
//            for(int i=0;i<gv.getNumGlyphs();i++) {
//                gv.setGlyphTransform(i, AffineTransform.getScaleInstance(scale, 1d));
//                gv.
//            }
//            gr.drawGlyphVector(gv, insets.left + 2, getBounds().height - (insets.top + insets.bottom) - 2 - bounds.height);
            int lineLenght = diameter / 2 - 10;
            gr.drawLine(diameter / 2, diameter / 2, diameter / 2 - getXOnArc(lineLenght, getAngle()), diameter / 2 - getYOnArc(lineLenght, getAngle()));
            gr.dispose();
            
            g.drawImage(img, insets.left, insets.top, this);
            if (border != null) {
                border.paintBorder(this, g, 0, 0, getBounds().width, getBounds().height);
            }
        } catch (AWTException e) {}
    }
 
Example #27
Source File: CustomCompositeTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void testVolatileImage(GraphicsConfiguration cfg,
        boolean accelerated)
{
    VolatileImage dst = null;
    try {
        dst = cfg.createCompatibleVolatileImage(640, 480,
            new ImageCapabilities(accelerated));
    } catch (AWTException e) {
        System.out.println("Unable to create volatile image, skip the test.");
        return;
    }
    renderToVolatileImage(dst);
}
 
Example #28
Source File: SunVolatileImage.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected SunVolatileImage(Component comp,
                           GraphicsConfiguration graphicsConfig,
                           int width, int height, Object context,
                           int transparency, ImageCapabilities caps,
                           int accType)
{
    this.comp = comp;
    this.graphicsConfig = graphicsConfig;
    this.width = width;
    this.height = height;
    this.forcedAccelSurfaceType = accType;
    if (!(transparency == Transparency.OPAQUE ||
        transparency == Transparency.BITMASK ||
        transparency == Transparency.TRANSLUCENT))
    {
        throw new IllegalArgumentException("Unknown transparency type:" +
                                           transparency);
    }
    this.transparency = transparency;
    this.volSurfaceManager = createSurfaceManager(context, caps);
    SurfaceManager.setManager(this, volSurfaceManager);

    // post-construction initialization of the surface manager
    volSurfaceManager.initialize();
    // clear the background
    volSurfaceManager.initContents();
}
 
Example #29
Source File: SunVolatileImage.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public SunVolatileImage(GraphicsConfiguration graphicsConfig,
                        int width, int height, int transparency,
                        ImageCapabilities caps)
{
    this(null, graphicsConfig, width, height, null, transparency,
         caps, UNDEFINED);
}
 
Example #30
Source File: BufferStrategyExceptionTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void render() {
    ImageCapabilities imgBackBufCap = new ImageCapabilities(true);
    ImageCapabilities imgFrontBufCap = new ImageCapabilities(true);
    BufferCapabilities bufCap =
        new BufferCapabilities(imgFrontBufCap,
            imgBackBufCap, BufferCapabilities.FlipContents.COPIED);
    try {

        createBufferStrategy(2, bufCap);
    } catch (AWTException ex) {
        createBufferStrategy(2);
    }

    BufferStrategy bs = getBufferStrategy();
    do {
        Graphics g =  bs.getDrawGraphics();
        g.setColor(Color.green);
        g.fillRect(0, 0, getWidth(), getHeight());

        g.setColor(Color.red);
        g.drawString("Rendering test", 20, 20);

        g.drawImage(bi, 50, 50, null);

        g.dispose();
        bs.show();
    } while (bs.contentsLost()||bs.contentsRestored());
}