Java Code Examples for sun.java2d.SunGraphics2D#getCompClip()

The following examples show how to use sun.java2d.SunGraphics2D#getCompClip() . 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: XRRenderer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void drawLine(SunGraphics2D sg2d, int x1, int y1, int x2, int y2) {
    Region compClip = sg2d.getCompClip();
    int transX1 = Region.clipAdd(x1, sg2d.transX);
    int transY1 = Region.clipAdd(y1, sg2d.transY);
    int transX2 = Region.clipAdd(x2, sg2d.transX);
    int transY2 = Region.clipAdd(y2, sg2d.transY);

    SunToolkit.awtLock();
    try {
        validateSurface(sg2d);
        lineGen.rasterizeLine(rectBuffer, transX1, transY1,
                transX2, transY2, compClip.getLoX(), compClip.getLoY(),
                compClip.getHiX(), compClip.getHiY(), true, true);
        tileManager.fillMask((XRSurfaceData) sg2d.surfaceData);
    } finally {
        SunToolkit.awtUnlock();
    }
}
 
Example 2
Source File: AAShapePipe.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public void fillParallelogram(SunGraphics2D sg,
                              double ux1, double uy1,
                              double ux2, double uy2,
                              double x, double y,
                              double dx1, double dy1,
                              double dx2, double dy2)
{
    Region clip = sg.getCompClip();
    int abox[] = new int[4];
    AATileGenerator aatg =
        renderengine.getAATileGenerator(x, y, dx1, dy1, dx2, dy2, 0, 0,
                                        clip, abox);
    if (aatg == null) {
        // Nothing to render
        return;
    }

    renderTiles(sg, computeBBox(ux1, uy1, ux2, uy2), aatg, abox);
}
 
Example 3
Source File: GeneralRenderer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 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)
{
    PixelWriter pw = GeneralRenderer.createSolidPixelWriter(sg2d, sData);

    int off = 0;
    Region clip = sg2d.getCompClip();
    for (int i = 0; i < numPolys; i++) {
        int numpts = nPoints[i];
        GeneralRenderer.doDrawPoly(sData, pw,
                                   xPoints, yPoints, off, numpts,
                                   clip, transx, transy, close);
        off += numpts;
    }
}
 
Example 4
Source File: AAShapePipe.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public void fillParallelogram(SunGraphics2D sg,
                              double ux1, double uy1,
                              double ux2, double uy2,
                              double x, double y,
                              double dx1, double dy1,
                              double dx2, double dy2)
{
    Region clip = sg.getCompClip();
    int abox[] = new int[4];
    AATileGenerator aatg =
        renderengine.getAATileGenerator(x, y, dx1, dy1, dx2, dy2, 0, 0,
                                        clip, abox);
    if (aatg == null) {
        // Nothing to render
        return;
    }

    renderTiles(sg, computeBBox(ux1, uy1, ux2, uy2), aatg, abox);
}
 
Example 5
Source File: XRRenderer.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void drawLine(SunGraphics2D sg2d, int x1, int y1, int x2, int y2) {
    Region compClip = sg2d.getCompClip();
    int transX1 = Region.clipAdd(x1, sg2d.transX);
    int transY1 = Region.clipAdd(y1, sg2d.transY);
    int transX2 = Region.clipAdd(x2, sg2d.transX);
    int transY2 = Region.clipAdd(y2, sg2d.transY);

    SunToolkit.awtLock();
    try {
        validateSurface(sg2d);
        lineGen.rasterizeLine(rectBuffer, transX1, transY1,
                transX2, transY2, compClip.getLoX(), compClip.getLoY(),
                compClip.getHiX(), compClip.getHiY(), true, true);
        tileManager.fillMask((XRSurfaceData) sg2d.surfaceData);
    } finally {
        SunToolkit.awtUnlock();
    }
}
 
Example 6
Source File: SpanShapeRenderer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void fill(SunGraphics2D sg, Shape s) {
    if (s instanceof Rectangle2D &&
        (sg.transform.getType() & NON_RECTILINEAR_TRANSFORM_MASK) == 0)
    {
        renderRect(sg, (Rectangle2D) s);
        return;
    }

    Region clipRegion = sg.getCompClip();
    ShapeSpanIterator sr = LoopPipe.getFillSSI(sg);
    try {
        sr.setOutputArea(clipRegion);
        sr.appendPath(s.getPathIterator(sg.transform));
        renderSpans(sg, clipRegion, s, sr);
    } finally {
        sr.dispose();
    }
}
 
Example 7
Source File: GeneralRenderer.java    From hottub with GNU General Public License v2.0 6 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)
{
    PixelWriter pw = GeneralRenderer.createSolidPixelWriter(sg2d, sData);

    int off = 0;
    Region clip = sg2d.getCompClip();
    for (int i = 0; i < numPolys; i++) {
        int numpts = nPoints[i];
        GeneralRenderer.doDrawPoly(sData, pw,
                                   xPoints, yPoints, off, numpts,
                                   clip, transx, transy, close);
        off += numpts;
    }
}
 
Example 8
Source File: AAShapePipe.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void drawParallelogram(SunGraphics2D sg,
                              double ux1, double uy1,
                              double ux2, double uy2,
                              double x, double y,
                              double dx1, double dy1,
                              double dx2, double dy2,
                              double lw1, double lw2)
{
    Region clip = sg.getCompClip();
    int abox[] = new int[4];
    AATileGenerator aatg =
        renderengine.getAATileGenerator(x, y, dx1, dy1, dx2, dy2, lw1, lw2,
                                        clip, abox);
    if (aatg == null) {
        // Nothing to render
        return;
    }

    // Note that bbox is of the original shape, not the wide path.
    // This is appropriate for handing to Paint methods...
    renderTiles(sg, computeBBox(ux1, uy1, ux2, uy2), aatg, abox);
}
 
Example 9
Source File: AAShapePipe.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public void drawParallelogram(SunGraphics2D sg,
                              double ux1, double uy1,
                              double ux2, double uy2,
                              double x, double y,
                              double dx1, double dy1,
                              double dx2, double dy2,
                              double lw1, double lw2)
{
    Region clip = sg.getCompClip();
    int abox[] = new int[4];
    AATileGenerator aatg =
        renderengine.getAATileGenerator(x, y, dx1, dy1, dx2, dy2, lw1, lw2,
                                        clip, abox);
    if (aatg == null) {
        // Nothing to render
        return;
    }

    // Note that bbox is of the original shape, not the wide path.
    // This is appropriate for handing to Paint methods...
    renderTiles(sg, computeBBox(ux1, uy1, ux2, uy2), aatg, abox);
}
 
Example 10
Source File: GeneralRenderer.java    From jdk8u-jdk with GNU General Public License v2.0 6 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)
{
    PixelWriter pw = GeneralRenderer.createXorPixelWriter(sg2d, sData);

    int off = 0;
    Region clip = sg2d.getCompClip();
    for (int i = 0; i < numPolys; i++) {
        int numpts = nPoints[i];
        GeneralRenderer.doDrawPoly(sData, pw,
                                   xPoints, yPoints, off, numpts,
                                   clip, transx, transy, close);
        off += numpts;
    }
}
 
Example 11
Source File: GeneralRenderer.java    From openjdk-8-source with GNU General Public License v2.0 6 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)
{
    PixelWriter pw = GeneralRenderer.createSolidPixelWriter(sg2d, sData);

    int off = 0;
    Region clip = sg2d.getCompClip();
    for (int i = 0; i < numPolys; i++) {
        int numpts = nPoints[i];
        GeneralRenderer.doDrawPoly(sData, pw,
                                   xPoints, yPoints, off, numpts,
                                   clip, transx, transy, close);
        off += numpts;
    }
}
 
Example 12
Source File: XRRenderer.java    From openjdk-jdk9 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 13
Source File: XRRenderer.java    From openjdk-8 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: GDIWindowSurfaceData.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)
{
    CompositeType comptype = sg2d.imageComp;
    if (sg2d.transformState < sg2d.TRANSFORM_TRANSLATESCALE &&
        sg2d.clipState != sg2d.CLIP_SHAPE &&
        (CompositeType.SrcOverNoEa.equals(comptype) ||
         CompositeType.SrcNoEa.equals(comptype)))
    {
        x += sg2d.transX;
        y += sg2d.transY;
        int dstx1 = x + dx;
        int dsty1 = y + dy;
        int dstx2 = dstx1 + w;
        int dsty2 = dsty1 + h;
        Region clip = sg2d.getCompClip();
        if (dstx1 < clip.getLoX()) dstx1 = clip.getLoX();
        if (dsty1 < clip.getLoY()) dsty1 = clip.getLoY();
        if (dstx2 > clip.getHiX()) dstx2 = clip.getHiX();
        if (dsty2 > clip.getHiY()) dsty2 = clip.getHiY();
        if (dstx1 < dstx2 && dsty1 < dsty2) {
            gdiPipe.devCopyArea(this, dstx1 - dx, dsty1 - dy,
                                dx, dy,
                                dstx2 - dstx1, dsty2 - dsty1);
        }
        return true;
    }
    return false;
}
 
Example 15
Source File: OGLUtilities.java    From jdk8u60 with GNU General Public License v2.0 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 = (SurfaceData)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 16
Source File: TextRenderer.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected void drawGlyphList(SunGraphics2D sg2d, GlyphList gl) {
    int num = gl.getNumGlyphs();
    Region clipRegion = sg2d.getCompClip();
    int cx1 = clipRegion.getLoX();
    int cy1 = clipRegion.getLoY();
    int cx2 = clipRegion.getHiX();
    int cy2 = clipRegion.getHiY();
    Object ctx = null;
    try {
        int[] bounds = gl.getBounds();
        Rectangle r = new Rectangle(bounds[0], bounds[1],
                                    bounds[2] - bounds[0],
                                    bounds[3] - bounds[1]);
        Shape s = sg2d.untransformShape(r);
        ctx = outpipe.startSequence(sg2d, s, r, bounds);
        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 &&
                outpipe.needTile(ctx, gx1, gy1, gx2 - gx1, gy2 - gy1))
            {
                byte alpha[] = gl.getGrayBits();
                outpipe.renderPathTile(ctx, alpha, off, w,
                                       gx1, gy1, gx2 - gx1, gy2 - gy1);
            } else {
                outpipe.skipTile(ctx, gx1, gy1);
            }
        }
    } finally {
        if (ctx != null) {
            outpipe.endSequence(ctx);
        }
    }
}
 
Example 17
Source File: TextRenderer.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
protected void drawGlyphList(SunGraphics2D sg2d, GlyphList gl) {
    int num = gl.getNumGlyphs();
    Region clipRegion = sg2d.getCompClip();
    int cx1 = clipRegion.getLoX();
    int cy1 = clipRegion.getLoY();
    int cx2 = clipRegion.getHiX();
    int cy2 = clipRegion.getHiY();
    Object ctx = null;
    try {
        int[] bounds = gl.getBounds();
        Rectangle r = new Rectangle(bounds[0], bounds[1],
                                    bounds[2] - bounds[0],
                                    bounds[3] - bounds[1]);
        Shape s = sg2d.untransformShape(r);
        ctx = outpipe.startSequence(sg2d, s, r, bounds);
        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 &&
                outpipe.needTile(ctx, gx1, gy1, gx2 - gx1, gy2 - gy1))
            {
                byte alpha[] = gl.getGrayBits();
                outpipe.renderPathTile(ctx, alpha, off, w,
                                       gx1, gy1, gx2 - gx1, gy2 - gy1);
            } else {
                outpipe.skipTile(ctx, gx1, gy1);
            }
        }
    } finally {
        if (ctx != null) {
            outpipe.endSequence(ctx);
        }
    }
}
 
Example 18
Source File: BufferedRenderPipe.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void fill(SunGraphics2D sg2d, Shape s) {
    int transx, transy;

    if (sg2d.strokeState == SunGraphics2D.STROKE_THIN) {
        // Here we are able to use fillPath() for
        // high-quality fills.
        Path2D.Float p2df;
        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;
        }
        fillPath(sg2d, p2df, transx, transy);
        return;
    }

    AffineTransform at;
    if (sg2d.transformState <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) {
        // Transform (translation) will be done by FillSpans (we could
        // delegate to fillPolygon() here, but most hardware accelerated
        // libraries cannot handle non-convex polygons, so we will use
        // the FillSpans approach by default)
        at = null;
        transx = sg2d.transX;
        transy = sg2d.transY;
    } else {
        // Transform will be done by the PathIterator
        at = sg2d.transform;
        transx = transy = 0;
    }

    ShapeSpanIterator ssi = LoopPipe.getFillSSI(sg2d);
    try {
        // Subtract transx/y from the SSI clip to match the
        // (potentially untranslated) geometry fed to it
        Region clip = sg2d.getCompClip();
        ssi.setOutputAreaXYXY(clip.getLoX() - transx,
                              clip.getLoY() - transy,
                              clip.getHiX() - transx,
                              clip.getHiY() - transy);
        ssi.appendPath(s.getPathIterator(at));
        fillSpans(sg2d, ssi, transx, transy);
    } finally {
        ssi.dispose();
    }
}
 
Example 19
Source File: TextRenderer.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
protected void drawGlyphList(SunGraphics2D sg2d, GlyphList gl) {
    int num = gl.getNumGlyphs();
    Region clipRegion = sg2d.getCompClip();
    int cx1 = clipRegion.getLoX();
    int cy1 = clipRegion.getLoY();
    int cx2 = clipRegion.getHiX();
    int cy2 = clipRegion.getHiY();
    Object ctx = null;
    try {
        int[] bounds = gl.getBounds();
        Rectangle r = new Rectangle(bounds[0], bounds[1],
                                    bounds[2] - bounds[0],
                                    bounds[3] - bounds[1]);
        Shape s = sg2d.untransformShape(r);
        ctx = outpipe.startSequence(sg2d, s, r, bounds);
        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 &&
                outpipe.needTile(ctx, gx1, gy1, gx2 - gx1, gy2 - gy1))
            {
                byte[] alpha = gl.getGrayBits();
                outpipe.renderPathTile(ctx, alpha, off, w,
                                       gx1, gy1, gx2 - gx1, gy2 - gy1);
            } else {
                outpipe.skipTile(ctx, gx1, gy1);
            }
        }
    } finally {
        if (ctx != null) {
            outpipe.endSequence(ctx);
        }
    }
}
 
Example 20
Source File: BufferedRenderPipe.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public void fill(SunGraphics2D sg2d, Shape s) {
    int transx, transy;

    if (sg2d.strokeState == SunGraphics2D.STROKE_THIN) {
        // Here we are able to use fillPath() for
        // high-quality fills.
        Path2D.Float p2df;
        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;
        }
        fillPath(sg2d, p2df, transx, transy);
        return;
    }

    AffineTransform at;
    if (sg2d.transformState <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) {
        // Transform (translation) will be done by FillSpans (we could
        // delegate to fillPolygon() here, but most hardware accelerated
        // libraries cannot handle non-convex polygons, so we will use
        // the FillSpans approach by default)
        at = null;
        transx = sg2d.transX;
        transy = sg2d.transY;
    } else {
        // Transform will be done by the PathIterator
        at = sg2d.transform;
        transx = transy = 0;
    }

    ShapeSpanIterator ssi = LoopPipe.getFillSSI(sg2d);
    try {
        // Subtract transx/y from the SSI clip to match the
        // (potentially untranslated) geometry fed to it
        Region clip = sg2d.getCompClip();
        ssi.setOutputAreaXYXY(clip.getLoX() - transx,
                              clip.getLoY() - transy,
                              clip.getHiX() - transx,
                              clip.getHiY() - transy);
        ssi.appendPath(s.getPathIterator(at));
        fillSpans(sg2d, ssi, transx, transy);
    } finally {
        ssi.dispose();
    }
}