Search in sources :

Example 1 with SunGraphics2D

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

the class TransformSetGet method main.

public static void main(final String[] args) {
    final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    final VolatileImage vi = gc.createCompatibleVolatileImage(200, 200);
    final SunGraphics2D sg2d = (SunGraphics2D) vi.createGraphics();
    sg2d.constrain(0, 61, 100, 100);
    final AffineTransform expected = sg2d.cloneTransform();
    sg2d.setTransform(sg2d.getTransform());
    final AffineTransform actual = sg2d.cloneTransform();
    sg2d.dispose();
    vi.flush();
    if (!expected.equals(actual)) {
        System.out.println("Expected = " + expected);
        System.out.println("Actual = " + actual);
        throw new RuntimeException("Wrong transform");
    }
}
Also used : VolatileImage(java.awt.image.VolatileImage) AffineTransform(java.awt.geom.AffineTransform) SunGraphics2D(sun.java2d.SunGraphics2D) GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 2 with SunGraphics2D

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

the class MultiResolutionSplashTest method getScaleFactor.

static float getScaleFactor() {
    final Dialog dialog = new Dialog((Window) null);
    dialog.setSize(100, 100);
    dialog.setModal(true);
    final float[] scaleFactors = new float[1];
    Panel panel = new Panel() {

        @Override
        public void paint(Graphics g) {
            float scaleFactor = 1;
            if (g instanceof SunGraphics2D) {
                scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale();
            }
            scaleFactors[0] = scaleFactor;
            dialog.setVisible(false);
        }
    };
    dialog.add(panel);
    dialog.setVisible(true);
    dialog.dispose();
    return scaleFactors[0];
}
Also used : Graphics(java.awt.Graphics) Panel(java.awt.Panel) Dialog(java.awt.Dialog) SunGraphics2D(sun.java2d.SunGraphics2D)

Example 3 with SunGraphics2D

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

the class WGLGraphicsConfig method flip.

/**
     * Performs the native WGL flip operation for the given target Component.
     */
@Override
public void flip(WComponentPeer peer, Component target, VolatileImage backBuffer, int x1, int y1, int x2, int y2, BufferCapabilities.FlipContents flipAction) {
    if (flipAction == BufferCapabilities.FlipContents.COPIED) {
        SurfaceManager vsm = SurfaceManager.getManager(backBuffer);
        SurfaceData sd = vsm.getPrimarySurfaceData();
        if (sd instanceof WGLVSyncOffScreenSurfaceData) {
            WGLVSyncOffScreenSurfaceData vsd = (WGLVSyncOffScreenSurfaceData) sd;
            SurfaceData bbsd = vsd.getFlipSurface();
            Graphics2D bbg = new SunGraphics2D(bbsd, Color.black, Color.white, null);
            try {
                bbg.drawImage(backBuffer, 0, 0, null);
            } finally {
                bbg.dispose();
            }
        } else {
            Graphics g = peer.getGraphics();
            try {
                g.drawImage(backBuffer, x1, y1, x2, y2, x1, y1, x2, y2, null);
            } finally {
                g.dispose();
            }
            return;
        }
    } else if (flipAction == BufferCapabilities.FlipContents.PRIOR) {
        // not supported by WGL...
        return;
    }
    OGLSurfaceData.swapBuffers(peer.getData());
    if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {
        Graphics g = backBuffer.getGraphics();
        try {
            g.setColor(target.getBackground());
            g.fillRect(0, 0, backBuffer.getWidth(), backBuffer.getHeight());
        } finally {
            g.dispose();
        }
    }
}
Also used : Graphics(java.awt.Graphics) WGLSurfaceData(sun.java2d.opengl.WGLSurfaceData) SurfaceData(sun.java2d.SurfaceData) GDIWindowSurfaceData(sun.java2d.windows.GDIWindowSurfaceData) SurfaceManager(sun.awt.image.SurfaceManager) SunGraphics2D(sun.java2d.SunGraphics2D) Graphics2D(java.awt.Graphics2D) SunGraphics2D(sun.java2d.SunGraphics2D)

Example 4 with SunGraphics2D

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

the class D3DScreenUpdateManager method createGraphics.

/**
     * Creates a graphics object for the passed in surface data. If
     * the surface is lost, it is restored.
     * If the surface wasn't lost or the restoration was successful
     * the surface is added to the list of maintained surfaces
     * (if it hasn't been already).
     *
     * If the updater thread hasn't been created yet , it will be created and
     * started.
     *
     * @param sd surface data for which to create SunGraphics2D
     * @param peer peer associated with the surface data
     * @param fgColor fg color to be used in graphics
     * @param bgColor bg color to be used in graphics
     * @param font font to be used in graphics
     * @return a SunGraphics2D object for the surface (or for temp GDI
     * surface data)
     */
@Override
public Graphics2D createGraphics(SurfaceData sd, WComponentPeer peer, Color fgColor, Color bgColor, Font font) {
    if (!done && sd instanceof D3DWindowSurfaceData) {
        D3DWindowSurfaceData d3dw = (D3DWindowSurfaceData) sd;
        if (!d3dw.isSurfaceLost() || validate(d3dw)) {
            trackScreenSurface(d3dw);
            return new SunGraphics2D(sd, fgColor, bgColor, font);
        }
        // could not restore the d3dw surface, use the cached gdi surface
        // instead for this graphics object; note that we do not track
        // this new gdi surface, it is only used for this graphics
        // object
        sd = getGdiSurface(d3dw);
    }
    return super.createGraphics(sd, peer, fgColor, bgColor, font);
}
Also used : SunGraphics2D(sun.java2d.SunGraphics2D) D3DWindowSurfaceData(sun.java2d.d3d.D3DSurfaceData.D3DWindowSurfaceData)

Example 5 with SunGraphics2D

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

the class D3DScreenUpdateManager method validate.

/**
     * Restores the passed surface if it was lost, resets the lost status.
     * @param sd surface to be validated
     * @return true if surface wasn't lost or if restoration was successful,
     * false otherwise
     */
private boolean validate(D3DWindowSurfaceData sd) {
    if (sd.isSurfaceLost()) {
        try {
            sd.restoreSurface();
            // if succeeded, first fill the surface with bg color
            // note: use the non-synch method to avoid incorrect lock order
            Color bg = sd.getPeer().getBackgroundNoSync();
            SunGraphics2D sg2d = new SunGraphics2D(sd, bg, bg, null);
            sg2d.fillRect(0, 0, sd.getBounds().width, sd.getBounds().height);
            sg2d.dispose();
            // now clean the dirty status so that we don't flip it
            // next time before it gets repainted; it is safe
            // to do without the lock because we will issue a
            // repaint anyway so we will not lose any rendering
            sd.markClean();
            // since the surface was successfully restored we need to
            // repaint whole window to repopulate the back-buffer
            repaintPeerTarget(sd.getPeer());
        } catch (InvalidPipeException ipe) {
            return false;
        }
    }
    return true;
}
Also used : InvalidPipeException(sun.java2d.InvalidPipeException) Color(java.awt.Color) SunGraphics2D(sun.java2d.SunGraphics2D)

Aggregations

SunGraphics2D (sun.java2d.SunGraphics2D)18 SurfaceData (sun.java2d.SurfaceData)7 Color (java.awt.Color)3 Graphics (java.awt.Graphics)3 Rectangle (java.awt.Rectangle)3 BufferedImage (java.awt.image.BufferedImage)3 Graphics2D (java.awt.Graphics2D)2 GraphicsEnvironment (java.awt.GraphicsEnvironment)2 PaintContext (java.awt.PaintContext)2 AffineTransform (java.awt.geom.AffineTransform)2 ColorModel (java.awt.image.ColorModel)2 Raster (java.awt.image.Raster)2 WritableRaster (java.awt.image.WritableRaster)2 BufImgSurfaceData (sun.awt.image.BufImgSurfaceData)2 SurfaceManager (sun.awt.image.SurfaceManager)2 CompositeContext (java.awt.CompositeContext)1 Dialog (java.awt.Dialog)1 Font (java.awt.Font)1 GraphicsConfiguration (java.awt.GraphicsConfiguration)1 Panel (java.awt.Panel)1