Search in sources :

Example 11 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 12 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)

Example 13 with SunGraphics2D

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

the class OffScreenImage method createGraphics.

public Graphics2D createGraphics() {
    if (c == null) {
        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        return env.createGraphics(this);
    }
    Color bg = c.getBackground();
    if (bg == null) {
        bg = SystemColor.window;
    }
    Color fg = c.getForeground();
    if (fg == null) {
        fg = SystemColor.windowText;
    }
    Font font = c.getFont();
    if (font == null) {
        if (defaultFont == null) {
            defaultFont = new Font("Dialog", Font.PLAIN, 12);
        }
        font = defaultFont;
    }
    return new SunGraphics2D(SurfaceData.getPrimarySurfaceData(this), fg, bg, font);
}
Also used : Color(java.awt.Color) SystemColor(java.awt.SystemColor) SunGraphics2D(sun.java2d.SunGraphics2D) GraphicsEnvironment(java.awt.GraphicsEnvironment) Font(java.awt.Font)

Example 14 with SunGraphics2D

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

the class OGLUtilities method invokeWithOGLContextCurrent.

/**
     * Invokes the given Runnable on the OGL QueueFlusher thread with the
     * OpenGL context corresponding to the given Graphics object made
     * current.  It is legal for OpenGL code executed in the given
     * Runnable to change the current OpenGL context; it will be reset
     * once the Runnable completes.  No guarantees are made as to the
     * state of the OpenGL context of the Graphics object; for
     * example, calling code must set the scissor box using the return
     * value from {@link #getOGLScissorBox} to avoid drawing
     * over other Swing components, and must typically set the OpenGL
     * viewport using the return value from {@link #getOGLViewport} to
     * make the client's OpenGL rendering appear in the correct place
     * relative to the scissor region.
     *
     * In order to avoid deadlock, it is important that the given Runnable
     * does not attempt to acquire the AWT lock, as that will be handled
     * automatically as part of the <code>rq.flushAndInvokeNow()</code> step.
     *
     * @param g the Graphics object for the corresponding destination surface;
     * if null, the step making a context current to the destination surface
     * will be skipped
     * @param r the action to be performed on the QFT; cannot be null
     * @return true if the operation completed successfully, or false if
     * there was any problem making a context current to the surface
     * associated with the given Graphics object
     */
public static boolean invokeWithOGLContextCurrent(Graphics g, Runnable r) {
    OGLRenderQueue rq = OGLRenderQueue.getInstance();
    rq.lock();
    try {
        if (g != null) {
            if (!(g instanceof SunGraphics2D)) {
                return false;
            }
            SurfaceData sData = ((SunGraphics2D) g).surfaceData;
            if (!(sData instanceof OGLSurfaceData)) {
                return false;
            }
            // make a context current to the destination surface
            OGLContext.validateContext((OGLSurfaceData) sData);
        }
        // invoke the given runnable on the QFT
        rq.flushAndInvokeNow(r);
        // invalidate the current context so that the next time we render
        // with Java 2D, the context state will be completely revalidated
        OGLContext.invalidateCurrentContext();
    } finally {
        rq.unlock();
    }
    return true;
}
Also used : SurfaceData(sun.java2d.SurfaceData) SunGraphics2D(sun.java2d.SunGraphics2D)

Example 15 with SunGraphics2D

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

the class MultiResolutionRenderingHintsTest method getImageColor.

private static Color getImageColor(final Object renderingHint, Image image, double configScale, double graphicsScale) {
    int width = image.getWidth(null);
    int height = image.getHeight(null);
    TestSurfaceData surface = new TestSurfaceData(width, height, configScale);
    SunGraphics2D g2d = new SunGraphics2D(surface, Color.BLACK, Color.BLACK, null);
    g2d.setRenderingHint(KEY_RESOLUTION_VARIANT, renderingHint);
    g2d.scale(graphicsScale, graphicsScale);
    g2d.drawImage(image, 0, 0, null);
    g2d.dispose();
    return surface.getColor(width / 2, height / 2);
}
Also used : 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