Search in sources :

Example 16 with SunGraphics2D

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

the class Test8004859 method test.

private static void test(final Graphics2D g) {
    for (final Shape clip : clips) {
        g.setClip(clip);
        if (!g.getClip().equals(clip)) {
            System.err.println("Expected clip: " + clip);
            System.err.println("Actual clip: " + g.getClip());
            System.err.println("bounds=" + g.getClip().getBounds2D());
            System.err.println("bounds=" + g.getClip().getBounds());
            status = false;
        }
        final Rectangle bounds = g.getClipBounds();
        if (!clip.equals(bounds)) {
            System.err.println("Expected getClipBounds(): " + clip);
            System.err.println("Actual getClipBounds(): " + bounds);
            status = false;
        }
        g.getClipBounds(bounds);
        if (!clip.equals(bounds)) {
            System.err.println("Expected getClipBounds(r): " + clip);
            System.err.println("Actual getClipBounds(r): " + bounds);
            status = false;
        }
        if (!clip.getBounds2D().isEmpty() && ((SunGraphics2D) g).clipRegion.isEmpty()) {
            System.err.println("clipRegion should not be empty");
            status = false;
        }
    }
}
Also used : Shape(java.awt.Shape) Rectangle(java.awt.Rectangle) SunGraphics2D(sun.java2d.SunGraphics2D)

Example 17 with SunGraphics2D

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

the class MultiResolutionDrawImageWithTransformTest method getImageColor.

private static Color getImageColor(Image image, double configScale, double transformScale) {
    TestSurfaceData surface = new TestSurfaceData(SCREEN_SIZE, SCREEN_SIZE, configScale);
    SunGraphics2D g2d = new SunGraphics2D(surface, Color.BLACK, Color.BLACK, null);
    g2d.setRenderingHint(KEY_RESOLUTION_VARIANT, VALUE_RESOLUTION_VARIANT_SIZE_FIT);
    AffineTransform tx = AffineTransform.getScaleInstance(transformScale, transformScale);
    g2d.drawImage(image, tx, null);
    g2d.dispose();
    int backgroundX = (int) (1.5 * image.getWidth(null) * transformScale);
    int backgroundY = (int) (1.5 * image.getHeight(null) * transformScale);
    Color backgroundColor = surface.getColor(backgroundX, backgroundY);
    //surface.show(String.format("Config: %f, transform: %f", configScale, transformScale));
    if (!BACKGROUND_COLOR.equals(backgroundColor)) {
        throw new RuntimeException("Wrong background color!");
    }
    return surface.getColor(IMAGE_SIZE / 4, IMAGE_SIZE / 4);
}
Also used : Color(java.awt.Color) AffineTransform(java.awt.geom.AffineTransform) SunGraphics2D(sun.java2d.SunGraphics2D)

Example 18 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)

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