Java Code Examples for sun.java2d.SunGraphics2D

The following are top voted examples for showing how to use sun.java2d.SunGraphics2D. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: openjdk-jdk10   File: X11Renderer.java   Source Code and License 7 votes vote down vote up
private void doPath(SunGraphics2D sg2d, Shape s, boolean isFill) {
    Path2D.Float p2df;
    int transx, 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;
    }
    SunToolkit.awtLock();
    try {
        long xgc = validate(sg2d);
        XDoPath(sg2d, sg2d.surfaceData.getNativeOps(), xgc,
                transx, transy, p2df, isFill);
    } finally {
        SunToolkit.awtUnlock();
    }
}
 
Example 2
Project: OpenJSharp   File: DrawImage.java   Source Code and License 6 votes vote down vote up
protected boolean scaleSurfaceData(SunGraphics2D sg,
                                   Region clipRegion,
                                   SurfaceData srcData,
                                   SurfaceData dstData,
                                   SurfaceType srcType,
                                   SurfaceType dstType,
                                   int sx1, int sy1,
                                   int sx2, int sy2,
                                   double dx1, double dy1,
                                   double dx2, double dy2)
{
    CompositeType comp = sg.imageComp;
    if (CompositeType.SrcOverNoEa.equals(comp) &&
        (srcData.getTransparency() == Transparency.OPAQUE))
    {
        comp = CompositeType.SrcNoEa;
    }

    ScaledBlit blit = ScaledBlit.getFromCache(srcType, comp, dstType);
    if (blit != null) {
        blit.Scale(srcData, dstData, sg.composite, clipRegion,
                   sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2);
        return true;
    }
    return false;
}
 
Example 3
Project: jdk8u-jdk   File: BufferedRenderPipe.java   Source Code and License 6 votes vote down vote up
public void fillParallelogram(SunGraphics2D sg2d,
                              double ux1, double uy1,
                              double ux2, double uy2,
                              double x, double y,
                              double dx1, double dy1,
                              double dx2, double dy2)
{
    rq.lock();
    try {
        validateContext(sg2d);
        rq.ensureCapacity(28);
        buf.putInt(FILL_PARALLELOGRAM);
        buf.putFloat((float) x);
        buf.putFloat((float) y);
        buf.putFloat((float) dx1);
        buf.putFloat((float) dy1);
        buf.putFloat((float) dx2);
        buf.putFloat((float) dy2);
    } finally {
        rq.unlock();
    }
}
 
Example 4
Project: openjdk-jdk10   File: BufferedRenderPipe.java   Source Code and License 6 votes vote down vote up
protected void drawPath(SunGraphics2D sg2d,
                        Path2D.Float p2df, int transx, int transy)
{
    rq.lock();
    try {
        validateContext(sg2d);
        drawHandler.validate(sg2d);
        ProcessPath.drawPath(drawHandler, p2df, transx, transy);
    } finally {
        rq.unlock();
    }
}
 
Example 5
Project: OpenJSharp   File: X11Renderer.java   Source Code and License 6 votes vote down vote up
private final long validate(SunGraphics2D sg2d) {
    // NOTE: getCompClip() will revalidateAll() if the
    // surfaceData is invalid.  This should ensure that
    // the clip and pixel that we are validating against
    // are the most current.
    //
    // The assumption is that the pipeline after that
    // revalidation will either be another X11 pipe
    // (because the drawable format never changes on X11)
    // or a null pipeline if the surface is disposed.
    //
    // Since we do not get the ops structure of the SurfaceData
    // until the actual call down to the native level we will
    // pick up the most recently validated copy.
    // Note that if the surface is disposed, a NullSurfaceData
    // (with null native data structure) will be set in
    // sg2d, so we have to protect against it in native code.

    X11SurfaceData x11sd = (X11SurfaceData)sg2d.surfaceData;
    return x11sd.getRenderGC(sg2d.getCompClip(),
                             sg2d.compositeState, sg2d.composite,
                             sg2d.pixel);
}
 
Example 6
Project: OpenJSharp   File: D3DSurfaceData.java   Source Code and License 6 votes vote down vote up
@Override
public boolean copyArea(SunGraphics2D sg2d,
                        int x, int y, int w, int h, int dx, int dy)
{
    if (sg2d.transformState < sg2d.TRANSFORM_TRANSLATESCALE &&
        sg2d.compositeState < sg2d.COMP_XOR)
    {
        x += sg2d.transX;
        y += sg2d.transY;

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

        return true;
    }
    return false;
}
 
Example 7
Project: jdk8u-jdk   File: TransformSetGet.java   Source Code and License 6 votes vote down vote up
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");
    }
}
 
Example 8
Project: jdk8u-jdk   File: GlyphListPipe.java   Source Code and License 6 votes vote down vote up
public void drawGlyphVector(SunGraphics2D sg2d, GlyphVector gv,
                            float x, float y)
{
    FontRenderContext frc = gv.getFontRenderContext();
    FontInfo info = sg2d.getGVFontInfo(gv.getFont(), frc);
    if (info.pixelHeight > OutlineTextRenderer.THRESHHOLD) {
        SurfaceData.outlineTextRenderer.drawGlyphVector(sg2d, gv, x, y);
        return;
    }
    if (sg2d.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
        double origin[] = {x, y};
        sg2d.transform.transform(origin, 0, origin, 0, 1);
        x = (float) origin[0];
        y = (float) origin[1];
    } else {
        x += sg2d.transX; // don't use the glyph info origin, already in gv.
        y += sg2d.transY;
    }

    GlyphList gl = GlyphList.getInstance();
    gl.setFromGlyphVector(info, gv, x, y);
    drawGlyphList(sg2d, gl, info.aaHint);
    gl.dispose();
}
 
Example 9
Project: jdk8u-jdk   File: BufferedRenderPipe.java   Source Code and License 6 votes vote down vote up
protected void fillSpans(SunGraphics2D sg2d, SpanIterator si,
                         int transx, int transy)
{
    rq.lock();
    try {
        validateContext(sg2d);
        rq.ensureCapacity(24); // so that we have room for at least a span
        int newpos = fillSpans(rq, buf.getAddress(),
                               buf.position(), buf.capacity(),
                               si, si.getNativeIterator(),
                               transx, transy);
        buf.position(newpos);
    } finally {
        rq.unlock();
    }
}
 
Example 10
Project: openjdk-jdk10   File: XWindow.java   Source Code and License 6 votes vote down vote up
Graphics getGraphics(SurfaceData surfData, Color afore, Color aback, Font afont) {
    if (surfData == null) return null;

    Component target = this.target;

    /* Fix for bug 4746122. Color and Font shouldn't be null */
    Color bgColor = aback;
    if (bgColor == null) {
        bgColor = SystemColor.window;
    }
    Color fgColor = afore;
    if (fgColor == null) {
        fgColor = SystemColor.windowText;
    }
    Font font = afont;
    if (font == null) {
        font = XWindow.getDefaultFont();
    }
    return new SunGraphics2D(surfData, fgColor, bgColor, font);
}
 
Example 11
Project: OpenJSharp   File: D3DScreenUpdateManager.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 12
Project: openjdk-jdk10   File: OGLRenderer.java   Source Code and License 5 votes vote down vote up
@Override
protected void validateContext(SunGraphics2D sg2d) {
    int ctxflags =
        sg2d.paint.getTransparency() == Transparency.OPAQUE ?
            OGLContext.SRC_IS_OPAQUE : 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 13
Project: OpenJSharp   File: X11Renderer.java   Source Code and License 5 votes vote down vote up
public void fillRoundRect(SunGraphics2D sg2d,
                          int x, int y, int width, int height,
                          int arcWidth, int arcHeight)
{
    SunToolkit.awtLock();
    try {
        long xgc = validate(sg2d);
        XFillRoundRect(sg2d.surfaceData.getNativeOps(), xgc,
                       x+sg2d.transX, y+sg2d.transY, width, height,
                       arcWidth, arcHeight);
    } finally {
        SunToolkit.awtUnlock();
    }
}
 
Example 14
Project: openjdk-jdk10   File: GeneralCompositePipe.java   Source Code and License 5 votes vote down vote up
public TileContext(SunGraphics2D sg, PaintContext pCtx,
                   CompositeContext cCtx, ColorModel cModel) {
    sunG2D = sg;
    paintCtxt = pCtx;
    compCtxt = cCtx;
    compModel = cModel;
}
 
Example 15
Project: jdk8u-jdk   File: DrawPath.java   Source Code and License 5 votes vote down vote up
public void DrawPath(SunGraphics2D sg2d, SurfaceData sData,
                     int transX, int transY,
                     Path2D.Float p2df)
{
    tracePrimitive(target);
    target.DrawPath(sg2d, sData, transX, transY, p2df);
}
 
Example 16
Project: jdk8u-jdk   File: OGLRenderer.java   Source Code and License 5 votes vote down vote up
protected void drawPoly(SunGraphics2D sg2d,
                        int[] xPoints, int[] yPoints,
                        int nPoints, boolean isClosed)
{
    GraphicsPrimitive.tracePrimitive("OGLDrawPoly");
    oglr.drawPoly(sg2d, xPoints, yPoints, nPoints, isClosed);
}
 
Example 17
Project: jdk8u-jdk   File: GeneralRenderer.java   Source Code and License 5 votes vote down vote up
public static void doDrawRect(PixelWriter pw,
                              SunGraphics2D sg2d, SurfaceData sData,
                              int x, int y, int w, int h)
{
    if (w < 0 || h < 0) {
        return;
    }
    int x2 = Region.dimAdd(Region.dimAdd(x, w), 1);
    int y2 = Region.dimAdd(Region.dimAdd(y, h), 1);
    Region r = sg2d.getCompClip().getBoundsIntersectionXYXY(x, y, x2, y2);
    if (r.isEmpty()) {
        return;
    }
    int cx1 = r.getLoX();
    int cy1 = r.getLoY();
    int cx2 = r.getHiX();
    int cy2 = r.getHiY();

    if (w < 2 || h < 2) {
        doSetRect(sData, pw, cx1, cy1, cx2, cy2);
        return;
    }


    if (cy1 == y) {
        doSetRect(sData, pw,   cx1,   cy1,   cx2, cy1+1);
    }
    if (cx1 == x) {
        doSetRect(sData, pw,   cx1, cy1+1, cx1+1, cy2-1);
    }
    if (cx2 == x2) {
        doSetRect(sData, pw, cx2-1, cy1+1,   cx2, cy2-1);
    }
    if (cy2 == y2) {
        doSetRect(sData, pw,   cx1, cy2-1,   cx2,   cy2);
    }
}
 
Example 18
Project: openjdk-jdk10   File: LoopPipe.java   Source Code and License 5 votes vote down vote up
public void fillParallelogram(SunGraphics2D sg2d,
                              double ux1, double uy1,
                              double ux2, double uy2,
                              double x, double y,
                              double dx1, double dy1,
                              double dx2, double dy2)
{
    FillParallelogram fp = sg2d.loops.fillParallelogramLoop;
    fp.FillParallelogram(sg2d, sg2d.getSurfaceData(),
                         x, y, dx1, dy1, dx2, dy2);
}
 
Example 19
Project: openjdk-jdk10   File: D3DDrawImage.java   Source Code and License 5 votes vote down vote up
@Override
protected void renderImageXform(SunGraphics2D sg, Image img,
                                AffineTransform tx, int interpType,
                                int sx1, int sy1, int sx2, int sy2,
                                Color bgColor)
{
    // punt to the MediaLib-based transformImage() in the superclass if:
    //     - bicubic interpolation is specified
    //     - a background color is specified and will be used
    //     - an appropriate TransformBlit primitive could not be found
    if (interpType != AffineTransformOp.TYPE_BICUBIC) {
        SurfaceData dstData = sg.surfaceData;
        SurfaceData srcData =
            dstData.getSourceSurfaceData(img,
                                         SunGraphics2D.TRANSFORM_GENERIC,
                                         sg.imageComp,
                                         bgColor);

        if (srcData != null && !isBgOperation(srcData, bgColor)) {
            SurfaceType srcType = srcData.getSurfaceType();
            SurfaceType dstType = dstData.getSurfaceType();
            TransformBlit blit = TransformBlit.getFromCache(srcType,
                                                            sg.imageComp,
                                                            dstType);

            if (blit != null) {
                blit.Transform(srcData, dstData,
                               sg.composite, sg.getCompClip(),
                               tx, interpType,
                               sx1, sy1, 0, 0, sx2-sx1, sy2-sy1);
                return;
            }
        }
    }

    super.renderImageXform(sg, img, tx, interpType,
                           sx1, sy1, sx2, sy2, bgColor);
}
 
Example 20
Project: OpenJSharp   File: GeneralRenderer.java   Source Code and License 5 votes vote down vote up
public void DrawRect(SunGraphics2D sg2d, SurfaceData sData,
                     int x, int y, int w, int h)
{
    PixelWriter pw = GeneralRenderer.createXorPixelWriter(sg2d, sData);

    GeneralRenderer.doDrawRect(pw, sg2d, sData, x, y, w, h);
}
 
Example 21
Project: jdk8u-jdk   File: ValidatePipe.java   Source Code and License 5 votes vote down vote up
public void fillArc(SunGraphics2D sg,
                    int x, int y, int width, int height,
                    int startAngle, int arcAngle) {
    if (validate(sg)) {
        sg.fillpipe.fillArc(sg, x, y, width, height, startAngle, arcAngle);
    }
}
 
Example 22
Project: jdk8u-jdk   File: PixelToParallelogramConverter.java   Source Code and License 5 votes vote down vote up
public void fillRectangle(SunGraphics2D sg2d,
                          double rx, double ry,
                          double rw, double rh)
{
    double px, py;
    double dx1, dy1, dx2, dy2;
    AffineTransform txform = sg2d.transform;
    dx1 = txform.getScaleX();
    dy1 = txform.getShearY();
    dx2 = txform.getShearX();
    dy2 = txform.getScaleY();
    px = rx * dx1 + ry * dx2 + txform.getTranslateX();
    py = rx * dy1 + ry * dy2 + txform.getTranslateY();
    dx1 *= rw;
    dy1 *= rw;
    dx2 *= rh;
    dy2 *= rh;
    if (adjustfill &&
        sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM &&
        sg2d.strokeHint != SunHints.INTVAL_STROKE_PURE)
    {
        double newx = normalize(px);
        double newy = normalize(py);
        dx1 = normalize(px + dx1) - newx;
        dy1 = normalize(py + dy1) - newy;
        dx2 = normalize(px + dx2) - newx;
        dy2 = normalize(py + dy2) - newy;
        px = newx;
        py = newy;
    }
    outrenderer.fillParallelogram(sg2d, rx, ry, rx+rw, ry+rh,
                                  px, py, dx1, dy1, dx2, dy2);
}
 
Example 23
Project: jdk8u-jdk   File: X11Renderer.java   Source Code and License 5 votes vote down vote up
public void draw(SunGraphics2D sg2d, Shape s) {
    if (sg2d.strokeState == SunGraphics2D.STROKE_THIN) {
        // Delegate to drawPolygon() if possible...
        if (s instanceof Polygon &&
            sg2d.transformState < SunGraphics2D.TRANSFORM_TRANSLATESCALE)
        {
            Polygon p = (Polygon) s;
            drawPolygon(sg2d, p.xpoints, p.ypoints, p.npoints);
            return;
        }

        // Otherwise we will use drawPath() for
        // high-quality thin paths.
        doPath(sg2d, s, false);
    } else if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM) {
        // REMIND: X11 can handle uniform scaled wide lines
        // and dashed lines itself if we set the appropriate
        // XGC attributes (TBD).
        ShapeSpanIterator si = LoopPipe.getStrokeSpans(sg2d, s);
        try {
            SunToolkit.awtLock();
            try {
                long xgc = validate(sg2d);
                XFillSpans(sg2d.surfaceData.getNativeOps(), xgc,
                           si, si.getNativeIterator(),
                           0, 0);
            } finally {
                SunToolkit.awtUnlock();
            }
        } finally {
            si.dispose();
        }
    } else {
        fill(sg2d, sg2d.stroke.createStrokedShape(s));
    }
}
 
Example 24
Project: OpenJSharp   File: PixelToParallelogramConverter.java   Source Code and License 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
Project: openjdk-jdk10   File: LoopPipe.java   Source Code and License 5 votes vote down vote up
public void drawRoundRect(SunGraphics2D sg2d,
                          int x, int y, int width, int height,
                          int arcWidth, int arcHeight)
{
    sg2d.shapepipe.draw(sg2d,
                        new RoundRectangle2D.Float(x, y, width, height,
                                                   arcWidth, arcHeight));
}
 
Example 26
Project: OpenJSharp   File: FillParallelogram.java   Source Code and License 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 27
Project: OpenJSharp   File: GDIRenderer.java   Source Code and License 5 votes vote down vote up
public void draw(SunGraphics2D sg2d, Shape s) {
    if (sg2d.strokeState == sg2d.STROKE_THIN) {
        doShape(sg2d, s, false);
    } else if (sg2d.strokeState < sg2d.STROKE_CUSTOM) {
        ShapeSpanIterator si = LoopPipe.getStrokeSpans(sg2d, s);
        try {
            doFillSpans(sg2d, si);
        } finally {
            si.dispose();
        }
    } else {
        doShape(sg2d, sg2d.stroke.createStrokedShape(s), true);
    }
}
 
Example 28
Project: OpenJSharp   File: OGLUtilities.java   Source Code and License 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 29
Project: openjdk-jdk10   File: OutlineTextRenderer.java   Source Code and License 5 votes vote down vote up
public void drawGlyphVector(SunGraphics2D g2d, GlyphVector gv,
                            float x, float y) {


    Shape s = gv.getOutline(x, y);
    int prevaaHint = - 1;
    FontRenderContext frc = gv.getFontRenderContext();
    boolean aa = frc.isAntiAliased();

    /* aa will be true if any AA mode has been specified.
     * ie for LCD and 'gasp' modes too.
     * We will check if 'gasp' has resolved AA to be "OFF", and
     * in all other cases (ie AA ON and all LCD modes) use AA outlines.
     */
    if (aa) {
        if (g2d.getGVFontInfo(gv.getFont(), frc).aaHint ==
            SunHints.INTVAL_TEXT_ANTIALIAS_OFF) {
            aa = false;
        }
    }

    if (aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
        prevaaHint = g2d.antialiasHint;
        g2d.antialiasHint =  SunHints.INTVAL_ANTIALIAS_ON;
        g2d.validatePipe();
    } else if (!aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) {
        prevaaHint = g2d.antialiasHint;
        g2d.antialiasHint =  SunHints.INTVAL_ANTIALIAS_OFF;
        g2d.validatePipe();
    }

    g2d.fill(s);

    if (prevaaHint != -1) {
         g2d.antialiasHint = prevaaHint;
         g2d.validatePipe();
    }
}
 
Example 30
Project: OpenJSharp   File: DrawPolygons.java   Source Code and License 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 31
Project: jdk8u-jdk   File: X11SurfaceDataProxy.java   Source Code and License 5 votes vote down vote up
@Override
public boolean isSupportedOperation(SurfaceData srcData,
                                    int txtype,
                                    CompositeType comp,
                                    Color bgColor)
{
    return (txtype < SunGraphics2D.TRANSFORM_TRANSLATESCALE &&
            (CompositeType.SrcOverNoEa.equals(comp) ||
             CompositeType.SrcNoEa.equals(comp)));
}
 
Example 32
Project: OpenJSharp   File: ValidatePipe.java   Source Code and License 5 votes vote down vote up
public void drawPolygon(SunGraphics2D sg,
                        int xPoints[], int yPoints[],
                        int nPoints) {
    if (validate(sg)) {
        sg.drawpipe.drawPolygon(sg, xPoints, yPoints, nPoints);
    }
}
 
Example 33
Project: openjdk-jdk10   File: GeneralRenderer.java   Source Code and License 5 votes vote down vote up
public void DrawPath(SunGraphics2D sg2d, SurfaceData sData,
                     int transx, int transy, Path2D.Float p2df)
{
    PixelWriter pw = GeneralRenderer.createXorPixelWriter(sg2d, sData);
    ProcessPath.drawPath(
        new PixelWriterDrawHandler(sData, pw, sg2d.getCompClip(),
                                   sg2d.strokeHint),
        p2df, transx, transy
    );
}
 
Example 34
Project: openjdk-jdk10   File: OGLUtilities.java   Source Code and License 5 votes vote down vote up
/**
 * Returns the Rectangle describing the OpenGL scissor box on the
 * Java 2D surface associated with the given Graphics object.  When a
 * third-party library is performing OpenGL rendering directly
 * into the visible region of the associated surface, this scissor box
 * must be set to avoid drawing over existing rendering results.
 *
 * Note that the x/y values in the returned Rectangle object represent
 * the lower-left corner of the scissor region, relative to the
 * lower-left corner of the given surface.
 *
 * @param g the Graphics object for the corresponding destination surface;
 * cannot be null
 * @return a Rectangle describing the OpenGL scissor box for the given
 * Graphics object and corresponding destination surface, or null if the
 * given Graphics object is invalid or the clip region is non-rectangular
 */
public static Rectangle getOGLScissorBox(Graphics g) {
    if (!(g instanceof SunGraphics2D)) {
        return null;
    }

    SunGraphics2D sg2d = (SunGraphics2D)g;
    SurfaceData sData = sg2d.surfaceData;
    Region r = sg2d.getCompClip();
    if (!r.isRectangular()) {
        // caller probably doesn't know how to handle shape clip
        // appropriately, so just return null (Swing currently never
        // sets a shape clip, but that could change in the future)
        return null;
    }

    // this is the upper-left origin of the scissor box relative to the
    // upper-left origin of the surface (in Java 2D coordinates)
    int x0 = r.getLoX();
    int y0 = r.getLoY();

    // this is the width and height of the scissor region
    int w = r.getWidth();
    int h = r.getHeight();

    // this is the lower-left origin of the scissor box relative to the
    // lower-left origin of the surface (in OpenGL coordinates)
    Rectangle surfaceBounds = sData.getBounds();
    int x1 = x0;
    int y1 = surfaceBounds.height - (y0 + h);

    return new Rectangle(x1, y1, w, h);
}
 
Example 35
Project: OpenJSharp   File: MaskFill.java   Source Code and License 5 votes vote down vote up
public void FillAAPgram(SunGraphics2D sg2d, SurfaceData sData,
                        Composite comp,
                        double x, double y,
                        double dx1, double dy1,
                        double dx2, double dy2)
{
    tracePrimitive(fillPgramTarget);
    target.FillAAPgram(sg2d, sData, comp,
                       x, y, dx1, dy1, dx2, dy2);
}
 
Example 36
Project: jdk8u-jdk   File: DrawGlyphListAA.java   Source Code and License 5 votes vote down vote up
public void DrawGlyphListAA(SunGraphics2D sg2d, SurfaceData dest,
                            GlyphList gl)
{
    gl.getBounds(); // Don't delete, bug 4895493
    int num = gl.getNumGlyphs();
    Region clip = sg2d.getCompClip();
    int cx1 = clip.getLoX();
    int cy1 = clip.getLoY();
    int cx2 = clip.getHiX();
    int cy2 = clip.getHiY();
    for (int i = 0; i < num; i++) {
        gl.setGlyphIndex(i);
        int metrics[] = gl.getMetrics();
        int gx1 = metrics[0];
        int gy1 = metrics[1];
        int w = metrics[2];
        int gx2 = gx1 + w;
        int gy2 = gy1 + metrics[3];
        int off = 0;
        if (gx1 < cx1) {
            off = cx1 - gx1;
            gx1 = cx1;
        }
        if (gy1 < cy1) {
            off += (cy1 - gy1) * w;
            gy1 = cy1;
        }
        if (gx2 > cx2) gx2 = cx2;
        if (gy2 > cy2) gy2 = cy2;
        if (gx2 > gx1 && gy2 > gy1) {
            byte alpha[] = gl.getGrayBits();
            maskop.MaskFill(sg2d, dest, sg2d.composite,
                            gx1, gy1, gx2 - gx1, gy2 - gy1,
                            alpha, off, w);
        }
    }
}
 
Example 37
Project: openjdk-jdk10   File: OGLRenderer.java   Source Code and License 5 votes vote down vote up
public void drawParallelogram(SunGraphics2D sg2d,
                              double ux1, double uy1,
                              double ux2, double uy2,
                              double x, double y,
                              double dx1, double dy1,
                              double dx2, double dy2,
                              double lw1, double lw2)
{
    GraphicsPrimitive.tracePrimitive("OGLDrawParallelogram");
    oglr.drawParallelogram(sg2d,
                           ux1, uy1, ux2, uy2,
                           x, y, dx1, dy1, dx2, dy2, lw1, lw2);
}
 
Example 38
Project: openjdk-jdk10   File: BufferedRenderPipe.java   Source Code and License 5 votes vote down vote up
public void fillArc(SunGraphics2D sg2d,
                    int x, int y, int width, int height,
                    int startAngle, int arcAngle)
{
    fill(sg2d, new Arc2D.Float(x, y, width, height,
                               startAngle, arcAngle,
                               Arc2D.PIE));
}
 
Example 39
Project: openjdk-jdk10   File: GDIRenderer.java   Source Code and License 5 votes vote down vote up
public void drawPolyline(SunGraphics2D sg2d,
                         int xpoints[], int ypoints[],
                         int npoints)
{
    try {
        doDrawPoly((GDIWindowSurfaceData)sg2d.surfaceData,
                   sg2d.getCompClip(), sg2d.composite, sg2d.eargb,
                   sg2d.transX, sg2d.transY, xpoints, ypoints, npoints, false);
    } catch (ClassCastException e) {
        throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
    }
}
 
Example 40
Project: jdk8u-jdk   File: GeneralRenderer.java   Source Code and License 5 votes vote down vote up
public void FillSpans(SunGraphics2D sg2d, SurfaceData sData,
                      SpanIterator si)
{
    PixelWriter pw = GeneralRenderer.createSolidPixelWriter(sg2d, sData);

    int span[] = new int[4];
    while (si.nextSpan(span)) {
        GeneralRenderer.doSetRect(sData, pw,
                                  span[0], span[1], span[2], span[3]);
    }
}