sun.java2d.SunGraphics2D Java Examples

The following examples show how to use sun.java2d.SunGraphics2D. 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: DrawImage.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public boolean scaleImage(SunGraphics2D sg, Image img,
                          int dx1, int dy1, int dx2, int dy2,
                          int sx1, int sy1, int sx2, int sy2,
                          Color bgColor,
                          ImageObserver observer) {
    if (!(img instanceof ToolkitImage)) {
        return scaleImage(sg, img, dx1, dy1, dx2, dy2,
                          sx1, sy1, sx2, sy2, bgColor);
    } else {
        ToolkitImage sunimg = (ToolkitImage)img;
        if (!imageReady(sunimg, observer)) {
            return false;
        }
        ImageRepresentation ir = sunimg.getImageRep();
        return ir.drawToBufImage(sg, sunimg, dx1, dy1, dx2, dy2,
                                 sx1, sy1, sx2, sy2, bgColor, observer);
    }
}
 
Example #2
Source File: D3DPaints.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns true if the given MultipleGradientPaint instance can be
 * used by the accelerated D3DPaints.MultiGradient implementation.
 * A MultipleGradientPaint is considered valid if the following
 * conditions are met:
 *   - the number of gradient "stops" is <= MAX_FRACTIONS
 *   - the destination has support for fragment shaders
 */
@Override
boolean isPaintValid(SunGraphics2D sg2d) {
    MultipleGradientPaint paint = (MultipleGradientPaint)sg2d.paint;
    // REMIND: ugh, this creates garbage; would be nicer if
    // we had a MultipleGradientPaint.getNumStops() method...
    if (paint.getFractions().length > MULTI_MAX_FRACTIONS_D3D) {
        return false;
    }

    D3DSurfaceData dstData = (D3DSurfaceData)sg2d.surfaceData;
    D3DGraphicsDevice gd = (D3DGraphicsDevice)
        dstData.getDeviceConfiguration().getDevice();
    if (!gd.isCapPresent(CAPS_LCD_SHADER)) {
        return false;
    }
    return true;
}
 
Example #3
Source File: XRSurfaceData.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
protected MaskFill getMaskFill(SunGraphics2D sg2d) {
    AlphaComposite aComp = null;
    if(sg2d.composite != null
            && sg2d.composite instanceof AlphaComposite) {
        aComp = (AlphaComposite) sg2d.composite;
    }

    boolean supportedPaint = sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR
            || XRPaints.isValid(sg2d);

    boolean supportedCompOp = false;
    if(aComp != null) {
        int rule = aComp.getRule();
        supportedCompOp = XRUtils.isMaskEvaluated(XRUtils.j2dAlphaCompToXR(rule));
    }

    return (supportedPaint && supportedCompOp) ?  super.getMaskFill(sg2d) : null;
}
 
Example #4
Source File: BufferedRenderPipe.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void fillRect(SunGraphics2D sg2d,
                     int x, int y, int width, int height)
{
    rq.lock();
    try {
        validateContext(sg2d);
        rq.ensureCapacity(20);
        buf.putInt(FILL_RECT);
        buf.putInt(x + sg2d.transX);
        buf.putInt(y + sg2d.transY);
        buf.putInt(width);
        buf.putInt(height);
    } finally {
        rq.unlock();
    }
}
 
Example #5
Source File: MaskFill.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void MaskFill(SunGraphics2D sg2d,
                     SurfaceData sData,
                     Composite comp,
                     int x, int y, int w, int h,
                     byte mask[], int offset, int scan)
{
    BufferedImage dstBI =
        new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    SurfaceData tmpData = BufImgSurfaceData.createData(dstBI);

    // REMIND: This is not pretty.  It would be nicer if we
    // passed a "FillData" object to the Pixel loops, instead
    // of a SunGraphics2D parameter...
    Region clip = sg2d.clipRegion;
    sg2d.clipRegion = null;
    int pixel = sg2d.pixel;
    sg2d.pixel = tmpData.pixelFor(sg2d.getColor());
    fillop.FillRect(sg2d, tmpData, 0, 0, w, h);
    sg2d.pixel = pixel;
    sg2d.clipRegion = clip;

    maskop.MaskBlit(tmpData, sData, comp, null,
                    0, 0, x, y, w, h,
                    mask, offset, scan);
}
 
Example #6
Source File: MultiResolutionSplashTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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];
    }
 
Example #7
Source File: D3DDrawImage.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void transformImage(SunGraphics2D sg, BufferedImage img,
                           BufferedImageOp op, int x, int y)
{
    if (op != null) {
        if (op instanceof AffineTransformOp) {
            AffineTransformOp atop = (AffineTransformOp) op;
            transformImage(sg, img, x, y,
                           atop.getTransform(),
                           atop.getInterpolationType());
            return;
        } else {
            if (D3DBufImgOps.renderImageWithOp(sg, img, op, x, y)) {
                return;
            }
        }
        img = op.filter(img, null);
    }
    copyImage(sg, img, x, y, null);
}
 
Example #8
Source File: GlyphListLoopPipe.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
protected void drawGlyphList(SunGraphics2D sg2d, GlyphList gl,
                             int aaHint) {
    switch (aaHint) {
     case SunHints.INTVAL_TEXT_ANTIALIAS_OFF:
         sg2d.loops.drawGlyphListLoop.
             DrawGlyphList(sg2d, sg2d.surfaceData, gl);
         return;
     case SunHints.INTVAL_TEXT_ANTIALIAS_ON:
         sg2d.loops.drawGlyphListAALoop.
             DrawGlyphListAA(sg2d, sg2d.surfaceData, gl);
         return;
    case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB:
    case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VRGB:
        sg2d.loops.drawGlyphListLCDLoop.
            DrawGlyphListLCD(sg2d,sg2d.surfaceData, gl);
        return;
    }
}
 
Example #9
Source File: D3DRenderer.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
void copyArea(SunGraphics2D sg2d,
              int x, int y, int w, int h, int dx, int dy)
{
    rq.lock();
    try {
        int ctxflags =
            sg2d.surfaceData.getTransparency() == Transparency.OPAQUE ?
                D3DContext.SRC_IS_OPAQUE : D3DContext.NO_CONTEXT_FLAGS;
        D3DSurfaceData dstData;
        try {
            dstData = (D3DSurfaceData)sg2d.surfaceData;
        } catch (ClassCastException e) {
            throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
        }
        D3DContext.validateContext(dstData, dstData,
                                   sg2d.getCompClip(), sg2d.composite,
                                   null, null, null, ctxflags);

        rq.ensureCapacity(28);
        buf.putInt(COPY_AREA);
        buf.putInt(x).putInt(y).putInt(w).putInt(h);
        buf.putInt(dx).putInt(dy);
    } finally {
        rq.unlock();
    }
}
 
Example #10
Source File: OGLSurfaceData.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public boolean copyArea(SunGraphics2D sg2d,
                        int x, int y, int w, int h, int dx, int dy)
{
    if (sg2d.transformState < SunGraphics2D.TRANSFORM_TRANSLATESCALE &&
        sg2d.compositeState < SunGraphics2D.COMP_XOR)
    {
        x += sg2d.transX;
        y += sg2d.transY;

        oglRenderPipe.copyArea(sg2d, x, y, w, h, dx, dy);

        return true;
    }
    return false;
}
 
Example #11
Source File: LoopPipe.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void fillPolygon(SunGraphics2D sg2d,
                        int xPoints[], int yPoints[],
                        int nPoints)
{
    ShapeSpanIterator sr = getFillSSI(sg2d);

    try {
        sr.setOutputArea(sg2d.getCompClip());
        sr.appendPoly(xPoints, yPoints, nPoints, sg2d.transX, sg2d.transY);
        fillSpans(sg2d, sr);
    } finally {
        sr.dispose();
    }
}
 
Example #12
Source File: LoopPipe.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void fill(SunGraphics2D sg2d, Shape s) {
    if (sg2d.strokeState == SunGraphics2D.STROKE_THIN) {
        Path2D.Float p2df;
        int transX;
        int transY;
        if (sg2d.transformState <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) {
            if (s instanceof Path2D.Float) {
                p2df = (Path2D.Float)s;
            } else {
                p2df = new Path2D.Float(s);
            }
            transX = sg2d.transX;
            transY = sg2d.transY;
        } else {
            p2df = new Path2D.Float(s, sg2d.transform);
            transX = 0;
            transY = 0;
        }
        sg2d.loops.fillPathLoop.FillPath(sg2d, sg2d.getSurfaceData(),
                                         transX, transY, p2df);
        return;
    }

    ShapeSpanIterator sr = getFillSSI(sg2d);
    try {
        sr.setOutputArea(sg2d.getCompClip());
        AffineTransform at =
            ((sg2d.transformState == SunGraphics2D.TRANSFORM_ISIDENT)
             ? null
             : sg2d.transform);
        sr.appendPath(s.getPathIterator(at));
        fillSpans(sg2d, sr);
    } finally {
        sr.dispose();
    }
}
 
Example #13
Source File: XRRenderer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This method needs to be called prior to each draw/fillPath()
 * operation to ensure the clip bounds are up to date.
 */
void validate(SunGraphics2D sg2d) {
    Region clip = sg2d.getCompClip();
    setBounds(clip.getLoX(), clip.getLoY(),
              clip.getHiX(), clip.getHiY(), sg2d.strokeHint);
    validateSurface(sg2d);
}
 
Example #14
Source File: AlphaPaintPipe.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public TileContext(SunGraphics2D sg, PaintContext pc) {
    sunG2D = sg;
    paintCtxt = pc;
    paintModel = pc.getColorModel();
    dstData = sg.getSurfaceData();
    synchronized (AlphaPaintPipe.class) {
        if (cachedLastColorModel != null &&
            cachedLastColorModel.get() == paintModel)
        {
            this.lastRaster = cachedLastRaster;
            this.lastData = cachedLastData;
        }
    }
}
 
Example #15
Source File: MaskFill.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void DrawAAPgram(SunGraphics2D sg2d, SurfaceData sData,
                        Composite comp,
                        double x, double y,
                        double dx1, double dy1,
                        double dx2, double dy2,
                        double lw1, double lw2)
{
    tracePrimitive(drawPgramTarget);
    target.DrawAAPgram(sg2d, sData, comp,
                       x, y, dx1, dy1, dx2, dy2, lw1, lw2);
}
 
Example #16
Source File: D3DRenderer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void validateContextAA(SunGraphics2D sg2d) {
    int ctxflags = D3DContext.NO_CONTEXT_FLAGS;
    D3DSurfaceData dstData;
    try {
        dstData = (D3DSurfaceData)sg2d.surfaceData;
    } catch (ClassCastException e) {
        throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
    }
    D3DContext.validateContext(dstData, dstData,
                               sg2d.getCompClip(), sg2d.composite,
                               null, sg2d.paint, sg2d, ctxflags);
}
 
Example #17
Source File: CGLSurfaceData.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static long createOGLContextOnSurface(Graphics g, long sharedContext) {
    SurfaceData sd = ((SunGraphics2D) g).surfaceData;
    if ((sd instanceof CGLSurfaceData) == true) {
        CGLSurfaceData cglsd = (CGLSurfaceData) sd;
        return createCGLContextOnSurface(cglsd, sharedContext);
    } else {
        return 0L;
    }
}
 
Example #18
Source File: XRRenderer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Common validate method, used by all XRRender functions to validate the
 * destination context.
 */
private final void validateSurface(SunGraphics2D sg2d) {
    XRSurfaceData xrsd;
    try {
        xrsd = (XRSurfaceData) sg2d.surfaceData;
    } catch (ClassCastException e) {
        throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
    }
    xrsd.validateAsDestination(sg2d, sg2d.getCompClip());
    xrsd.maskBuffer.validateCompositeState(sg2d.composite, sg2d.transform,
                                           sg2d.paint, sg2d);
}
 
Example #19
Source File: GlyphListPipe.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void drawChars(SunGraphics2D sg2d,
                      char data[], int offset, int length,
                      int ix, int iy)
{
    FontInfo info = sg2d.getFontInfo();
    float x, y;
    if (info.pixelHeight > OutlineTextRenderer.THRESHHOLD) {
        SurfaceData.outlineTextRenderer.drawChars(
                                    sg2d, data, offset, length, ix, iy);
        return;
    }
    if (sg2d.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
        double origin[] = {ix + info.originX, iy + info.originY};
        sg2d.transform.transform(origin, 0, origin, 0, 1);
        x = (float) origin[0];
        y = (float) origin[1];
    } else {
        x = ix + info.originX + sg2d.transX;
        y = iy + info.originY + sg2d.transY;
    }
    GlyphList gl = GlyphList.getInstance();
    if (gl.setFromChars(info, data, offset, length, x, y)) {
        drawGlyphList(sg2d, gl);
        gl.dispose();
    } else {
        gl.dispose(); // release this asap.
        TextLayout tl = new TextLayout(new String(data, offset, length),
                                       sg2d.getFont(),
                                       sg2d.getFontRenderContext());
        tl.draw(sg2d, ix, iy);

    }
}
 
Example #20
Source File: OGLMaskFill.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void validateContext(SunGraphics2D sg2d,
                               Composite comp, int ctxflags)
{
    OGLSurfaceData dstData = (OGLSurfaceData)sg2d.surfaceData;
    OGLContext.validateContext(dstData, dstData,
                               sg2d.getCompClip(), comp,
                               null, sg2d.paint, sg2d, ctxflags);
}
 
Example #21
Source File: OGLPaints.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
boolean isPaintValid(SunGraphics2D sg2d) {
    LinearGradientPaint paint = (LinearGradientPaint)sg2d.paint;

    if (paint.getFractions().length == 2 &&
        paint.getCycleMethod() != CycleMethod.REPEAT &&
        paint.getColorSpace() != ColorSpaceType.LINEAR_RGB)
    {
        // we can delegate to the optimized two-color gradient
        // codepath, which does not require fragment shader support
        return true;
    }

    return super.isPaintValid(sg2d);
}
 
Example #22
Source File: FillParallelogram.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void FillParallelogram(SunGraphics2D sg2d, SurfaceData dest,
                              double x0, double y0,
                              double dx1, double dy1,
                              double dx2, double dy2)
{
    tracePrimitive(target);
    target.FillParallelogram(sg2d, dest, x0, y0, dx1, dy1, dx2, dy2);
}
 
Example #23
Source File: Test8004859.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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;
        }
    }
}
 
Example #24
Source File: PixelToParallelogramConverter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void drawLine(SunGraphics2D sg2d,
                     int x1, int y1, int x2, int y2)
{
    if (!drawGeneralLine(sg2d, x1, y1, x2, y2)) {
        super.drawLine(sg2d, x1, y1, x2, y2);
    }
}
 
Example #25
Source File: X11Renderer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void drawRect(SunGraphics2D sg2d,
                     int x, int y, int width, int height)
{
    SunToolkit.awtLock();
    try {
        long xgc = validate(sg2d);
        XDrawRect(sg2d.surfaceData.getNativeOps(), xgc,
                  x+sg2d.transX, y+sg2d.transY, width, height);
    } finally {
        SunToolkit.awtUnlock();
    }
}
 
Example #26
Source File: OGLUtilities.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #27
Source File: PixelToParallelogramConverter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void fill(SunGraphics2D sg2d, Shape s) {
    if (s instanceof Rectangle2D) {
        Rectangle2D r2d = (Rectangle2D) s;
        double w = r2d.getWidth();
        double h = r2d.getHeight();
        if (w > 0 && h > 0) {
            double x = r2d.getX();
            double y = r2d.getY();
            fillRectangle(sg2d, x, y, w, h);
        }
        return;
    }

    outpipe.fill(sg2d, s);
}
 
Example #28
Source File: OGLRenderer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void validateContextAA(SunGraphics2D sg2d) {
    int ctxflags = OGLContext.NO_CONTEXT_FLAGS;
    OGLSurfaceData dstData;
    try {
        dstData = (OGLSurfaceData)sg2d.surfaceData;
    } catch (ClassCastException e) {
        throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
    }
    OGLContext.validateContext(dstData, dstData,
                               sg2d.getCompClip(), sg2d.composite,
                               null, sg2d.paint, sg2d, ctxflags);
}
 
Example #29
Source File: DrawPolygons.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void DrawPolygons(SunGraphics2D sg2d, SurfaceData sData,
                         int xPoints[], int yPoints[],
                         int nPoints[], int numPolys,
                         int transX, int transY,
                         boolean close)
{
    tracePrimitive(target);
    target.DrawPolygons(sg2d, sData,
                        xPoints, yPoints, nPoints, numPolys,
                        transX, transY, close);
}
 
Example #30
Source File: LoopPipe.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void fillPolygon(SunGraphics2D sg2d,
                        int xPoints[], int yPoints[],
                        int nPoints)
{
    ShapeSpanIterator sr = getFillSSI(sg2d);

    try {
        sr.setOutputArea(sg2d.getCompClip());
        sr.appendPoly(xPoints, yPoints, nPoints, sg2d.transX, sg2d.transY);
        fillSpans(sg2d, sr);
    } finally {
        sr.dispose();
    }
}