Search in sources :

Example 1 with AccelSurface

use of sun.java2d.pipe.hw.AccelSurface in project jdk8u_jdk by JetBrains.

the class RSLAPITest method testGC.

private static void testGC(GraphicsConfiguration gc) {
    if (!(gc instanceof AccelGraphicsConfig)) {
        System.out.println("Test passed: no hw accelerated configs found.");
        return;
    }
    System.out.println("AccelGraphicsConfig exists, testing.");
    AccelGraphicsConfig agc = (AccelGraphicsConfig) gc;
    printAGC(agc);
    testContext(agc);
    VolatileImage vi = gc.createCompatibleVolatileImage(10, 10);
    vi.validate(gc);
    if (vi instanceof DestSurfaceProvider) {
        System.out.println("Passed: VI is DestSurfaceProvider");
        Surface s = ((DestSurfaceProvider) vi).getDestSurface();
        if (s instanceof AccelSurface) {
            System.out.println("Passed: Obtained Accel Surface");
            printSurface((AccelSurface) s);
        }
        Graphics g = vi.getGraphics();
        if (g instanceof DestSurfaceProvider) {
            System.out.println("Passed: VI graphics is " + "DestSurfaceProvider");
            printSurface(((DestSurfaceProvider) g).getDestSurface());
        }
    } else {
        System.out.println("VI is not DestSurfaceProvider");
    }
    testVICreation(agc, CAPS_RT_TEXTURE_ALPHA, TRANSLUCENT, RT_TEXTURE);
    testVICreation(agc, CAPS_RT_TEXTURE_OPAQUE, OPAQUE, RT_TEXTURE);
    testVICreation(agc, CAPS_RT_PLAIN_ALPHA, TRANSLUCENT, RT_PLAIN);
    testVICreation(agc, agc.getContextCapabilities().getCaps(), OPAQUE, TEXTURE);
    testForNPEDuringCreation(agc);
}
Also used : Graphics(java.awt.Graphics) AccelSurface(sun.java2d.pipe.hw.AccelSurface) VolatileImage(java.awt.image.VolatileImage) AccelGraphicsConfig(sun.java2d.pipe.hw.AccelGraphicsConfig) DestSurfaceProvider(sun.java2d.DestSurfaceProvider) Surface(sun.java2d.Surface) AccelSurface(sun.java2d.pipe.hw.AccelSurface)

Example 2 with AccelSurface

use of sun.java2d.pipe.hw.AccelSurface in project jdk8u_jdk by JetBrains.

the class RSLAPITest method testVICreation.

private static void testVICreation(AccelGraphicsConfig agc, int cap, int transparency, int type) {
    int caps = agc.getContextCapabilities().getCaps();
    int w = 11, h = 17;
    VolatileImage vi = agc.createCompatibleVolatileImage(w, h, transparency, type);
    if ((cap & caps) != 0) {
        if (vi == null) {
            System.out.printf("Failed: cap=%d is supported but " + "image wasn't created\n", cap);
            throw new RuntimeException("Failed: image wasn't created " + "for supported cap");
        } else {
            if (!(vi instanceof DestSurfaceProvider)) {
                throw new RuntimeException("Failed: created VI is not " + "DestSurfaceProvider");
            }
            Surface s = ((DestSurfaceProvider) vi).getDestSurface();
            if (s instanceof AccelSurface) {
                AccelSurface as = (AccelSurface) s;
                printSurface(as);
                if (as.getType() != type) {
                    throw new RuntimeException("Failed: returned VI is" + " of incorrect type: " + as.getType() + " requested type=" + type);
                } else {
                    System.out.printf("Passed: VI of type %d was " + "created for cap=%d\n", type, cap);
                }
                if (as.getType() == TEXTURE) {
                    boolean ex = false;
                    try {
                        Graphics g = vi.getGraphics();
                        g.dispose();
                    } catch (UnsupportedOperationException e) {
                        ex = true;
                    }
                    if (!ex) {
                        throw new RuntimeException("Failed: " + "texture.getGraphics() didn't throw exception");
                    } else {
                        System.out.println("Passed: VI.getGraphics()" + " threw exception for texture-based VI");
                    }
                }
            } else {
                System.out.printf("Passed: VI of type %d was " + "created for cap=%d but accel surface is null\n", type, cap);
            }
        }
    } else {
        if (vi != null) {
            throw new RuntimeException("Failed: created VI for " + "unsupported cap=" + cap);
        }
    }
}
Also used : Graphics(java.awt.Graphics) AccelSurface(sun.java2d.pipe.hw.AccelSurface) VolatileImage(java.awt.image.VolatileImage) DestSurfaceProvider(sun.java2d.DestSurfaceProvider) Surface(sun.java2d.Surface) AccelSurface(sun.java2d.pipe.hw.AccelSurface)

Example 3 with AccelSurface

use of sun.java2d.pipe.hw.AccelSurface in project jdk8u_jdk by JetBrains.

the class GLXGraphicsConfig method createCompatibleVolatileImage.

/**
     * {@inheritDoc}
     *
     * @see sun.java2d.pipe.hw.AccelGraphicsConfig#createCompatibleVolatileImage
     */
@Override
public VolatileImage createCompatibleVolatileImage(int width, int height, int transparency, int type) {
    if (type == FLIP_BACKBUFFER || type == WINDOW || type == UNDEFINED || transparency == Transparency.BITMASK) {
        return null;
    }
    if (type == FBOBJECT) {
        if (!isCapPresent(CAPS_EXT_FBOBJECT)) {
            return null;
        }
    } else if (type == PBUFFER) {
        boolean isOpaque = transparency == Transparency.OPAQUE;
        if (!isOpaque && !isCapPresent(CAPS_STORED_ALPHA)) {
            return null;
        }
    }
    SunVolatileImage vi = new AccelTypedVolatileImage(this, width, height, transparency, type);
    Surface sd = vi.getDestSurface();
    if (!(sd instanceof AccelSurface) || ((AccelSurface) sd).getType() != type) {
        vi.flush();
        vi = null;
    }
    return vi;
}
Also used : AccelSurface(sun.java2d.pipe.hw.AccelSurface) SunVolatileImage(sun.awt.image.SunVolatileImage) AccelTypedVolatileImage(sun.java2d.pipe.hw.AccelTypedVolatileImage) Surface(sun.java2d.Surface) AccelSurface(sun.java2d.pipe.hw.AccelSurface)

Example 4 with AccelSurface

use of sun.java2d.pipe.hw.AccelSurface in project jdk8u_jdk by JetBrains.

the class D3DGraphicsConfig method createCompatibleVolatileImage.

/**
     * {@inheritDoc}
     *
     * @see sun.java2d.pipe.hw.AccelGraphicsConfig#createCompatibleVolatileImage
     */
@Override
public VolatileImage createCompatibleVolatileImage(int width, int height, int transparency, int type) {
    if (type == FLIP_BACKBUFFER || type == WINDOW || type == UNDEFINED || transparency == Transparency.BITMASK) {
        return null;
    }
    boolean isOpaque = transparency == Transparency.OPAQUE;
    if (type == RT_TEXTURE) {
        int cap = isOpaque ? CAPS_RT_TEXTURE_OPAQUE : CAPS_RT_TEXTURE_ALPHA;
        if (!device.isCapPresent(cap)) {
            return null;
        }
    } else if (type == RT_PLAIN) {
        if (!isOpaque && !device.isCapPresent(CAPS_RT_PLAIN_ALPHA)) {
            return null;
        }
    }
    SunVolatileImage vi = new AccelTypedVolatileImage(this, width, height, transparency, type);
    Surface sd = vi.getDestSurface();
    if (!(sd instanceof AccelSurface) || ((AccelSurface) sd).getType() != type) {
        vi.flush();
        vi = null;
    }
    return vi;
}
Also used : AccelSurface(sun.java2d.pipe.hw.AccelSurface) SunVolatileImage(sun.awt.image.SunVolatileImage) AccelTypedVolatileImage(sun.java2d.pipe.hw.AccelTypedVolatileImage) Surface(sun.java2d.Surface) AccelSurface(sun.java2d.pipe.hw.AccelSurface)

Example 5 with AccelSurface

use of sun.java2d.pipe.hw.AccelSurface in project jdk8u_jdk by JetBrains.

the class BufferedContext method validate.

/**
     * Validates the given parameters against the current state for this
     * context.  If this context is not current, it will be made current
     * for the given source and destination surfaces, and the viewport will
     * be updated.  Then each part of the context state (clip, composite,
     * etc.) is checked against the previous value.  If the value has changed
     * since the last call to validate(), it will be updated accordingly.
     *
     * Note that the SunGraphics2D parameter is only used for the purposes
     * of validating a (non-null) Paint parameter.  In all other cases it
     * is safe to pass a null SunGraphics2D and it will be ignored.
     *
     * Note: must be called while the RenderQueue lock is held.
     *
     * It's assumed that the type of surfaces has been checked by the Renderer
     *
     * @throws InvalidPipeException if either src or dest surface is not valid
     * or lost
     */
public void validate(AccelSurface srcData, AccelSurface dstData, Region clip, Composite comp, AffineTransform xform, Paint paint, SunGraphics2D sg2d, int flags) {
    // assert rq.lock.isHeldByCurrentThread();
    boolean updateClip = false;
    boolean updatePaint = false;
    if (!dstData.isValid() || dstData.isSurfaceLost() || srcData.isSurfaceLost()) {
        invalidateContext();
        throw new InvalidPipeException("bounds changed or surface lost");
    }
    if (paint instanceof Color) {
        // REMIND: not 30-bit friendly
        int newRGB = ((Color) paint).getRGB();
        if (isValidatedPaintJustAColor) {
            if (newRGB != validatedRGB) {
                validatedRGB = newRGB;
                updatePaint = true;
            }
        } else {
            validatedRGB = newRGB;
            updatePaint = true;
            isValidatedPaintJustAColor = true;
        }
    } else if (validPaintRef.get() != paint) {
        updatePaint = true;
        // this should be set when we are switching from paint to color
        // in which case this condition will be true
        isValidatedPaintJustAColor = false;
    }
    final AccelSurface validatedSrcData = validSrcDataRef.get();
    final AccelSurface validatedDstData = validDstDataRef.get();
    if ((currentContext != this) || (srcData != validatedSrcData) || (dstData != validatedDstData)) {
        if (dstData != validatedDstData) {
            // the clip is dependent on the destination surface, so we
            // need to update it if we have a new destination surface
            updateClip = true;
        }
        if (paint == null) {
            // make sure we update the color state (otherwise, it might
            // not be updated if this is the first time the context
            // is being validated)
            updatePaint = true;
        }
        // update the current source and destination surfaces
        setSurfaces(srcData, dstData);
        currentContext = this;
        validSrcDataRef = new WeakReference<>(srcData);
        validDstDataRef = new WeakReference<>(dstData);
    }
    // validate clip
    final Region validatedClip = validClipRef.get();
    if ((clip != validatedClip) || updateClip) {
        if (clip != null) {
            if (updateClip || validatedClip == null || !(validatedClip.isRectangular() && clip.isRectangular()) || ((clip.getLoX() != validatedClip.getLoX() || clip.getLoY() != validatedClip.getLoY() || clip.getHiX() != validatedClip.getHiX() || clip.getHiY() != validatedClip.getHiY()))) {
                setClip(clip);
            }
        } else {
            resetClip();
        }
        validClipRef = new WeakReference<>(clip);
    }
    // composite has not changed)
    if ((comp != validCompRef.get()) || (flags != validatedFlags)) {
        if (comp != null) {
            setComposite(comp, flags);
        } else {
            resetComposite();
        }
        // the paint state is dependent on the composite state, so make
        // sure we update the color below
        updatePaint = true;
        validCompRef = new WeakReference<>(comp);
        validatedFlags = flags;
    }
    // validate transform
    boolean txChanged = false;
    if (xform == null) {
        if (xformInUse) {
            resetTransform();
            xformInUse = false;
            txChanged = true;
        } else if (sg2d != null && !sg2d.transform.equals(transform)) {
            txChanged = true;
        }
        if (sg2d != null && txChanged) {
            transform = new AffineTransform(sg2d.transform);
        }
    } else {
        setTransform(xform);
        xformInUse = true;
        txChanged = true;
    }
    // non-Color paints may require paint revalidation
    if (!isValidatedPaintJustAColor && txChanged) {
        updatePaint = true;
    }
    // validate paint
    if (updatePaint) {
        if (paint != null) {
            BufferedPaints.setPaint(rq, sg2d, paint, flags);
        } else {
            BufferedPaints.resetPaint(rq);
        }
        validPaintRef = new WeakReference<>(paint);
    }
    // mark dstData dirty
    // REMIND: is this really needed now? we do it in SunGraphics2D..
    dstData.markDirty();
}
Also used : InvalidPipeException(sun.java2d.InvalidPipeException) AccelSurface(sun.java2d.pipe.hw.AccelSurface) Color(java.awt.Color) AffineTransform(java.awt.geom.AffineTransform) Paint(java.awt.Paint)

Aggregations

AccelSurface (sun.java2d.pipe.hw.AccelSurface)8 Surface (sun.java2d.Surface)6 SunVolatileImage (sun.awt.image.SunVolatileImage)4 AccelTypedVolatileImage (sun.java2d.pipe.hw.AccelTypedVolatileImage)4 Graphics (java.awt.Graphics)2 VolatileImage (java.awt.image.VolatileImage)2 DestSurfaceProvider (sun.java2d.DestSurfaceProvider)2 Color (java.awt.Color)1 Paint (java.awt.Paint)1 AffineTransform (java.awt.geom.AffineTransform)1 InvalidPipeException (sun.java2d.InvalidPipeException)1 RenderQueue (sun.java2d.pipe.RenderQueue)1 AccelGraphicsConfig (sun.java2d.pipe.hw.AccelGraphicsConfig)1