Java Code Examples for sun.java2d.SurfaceData#getBounds()

The following examples show how to use sun.java2d.SurfaceData#getBounds() . 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: GraphicsPrimitive.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected static SurfaceData convertFrom(Blit ob, SurfaceData srcData,
                                         int srcX, int srcY, int w, int h,
                                         SurfaceData dstData, int type)
{
    if (dstData != null) {
        Rectangle r = dstData.getBounds();
        if (w > r.width || h > r.height) {
            dstData = null;
        }
    }
    if (dstData == null) {
        BufferedImage dstBI = new BufferedImage(w, h, type);
        dstData = BufImgSurfaceData.createData(dstBI);
    }
    ob.Blit(srcData, dstData, AlphaComposite.Src, null,
            srcX, srcY, 0, 0, w, h);
    return dstData;
}
 
Example 2
Source File: GraphicsPrimitive.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
protected static SurfaceData convertFrom(Blit ob, SurfaceData srcData,
                                         int srcX, int srcY, int w, int h,
                                         SurfaceData dstData, int type)
{
    if (dstData != null) {
        Rectangle r = dstData.getBounds();
        if (w > r.width || h > r.height) {
            dstData = null;
        }
    }
    if (dstData == null) {
        BufferedImage dstBI = new BufferedImage(w, h, type);
        dstData = BufImgSurfaceData.createData(dstBI);
    }
    ob.Blit(srcData, dstData, AlphaComposite.Src, null,
            srcX, srcY, 0, 0, w, h);
    return dstData;
}
 
Example 3
Source File: GraphicsPrimitive.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected static SurfaceData convertFrom(Blit ob, SurfaceData srcData,
                                         int srcX, int srcY, int w, int h,
                                         SurfaceData dstData, int type)
{
    if (dstData != null) {
        Rectangle r = dstData.getBounds();
        if (w > r.width || h > r.height) {
            dstData = null;
        }
    }
    if (dstData == null) {
        BufferedImage dstBI = new BufferedImage(w, h, type);
        dstData = BufImgSurfaceData.createData(dstBI);
    }
    ob.Blit(srcData, dstData, AlphaComposite.Src, null,
            srcX, srcY, 0, 0, w, h);
    return dstData;
}
 
Example 4
Source File: GraphicsPrimitive.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
protected static SurfaceData convertFrom(Blit ob, SurfaceData srcData,
                                         int srcX, int srcY, int w, int h,
                                         SurfaceData dstData, int type)
{
    if (dstData != null) {
        Rectangle r = dstData.getBounds();
        if (w > r.width || h > r.height) {
            dstData = null;
        }
    }
    if (dstData == null) {
        BufferedImage dstBI = new BufferedImage(w, h, type);
        dstData = BufImgSurfaceData.createData(dstBI);
    }
    ob.Blit(srcData, dstData, AlphaComposite.Src, null,
            srcX, srcY, 0, 0, w, h);
    return dstData;
}
 
Example 5
Source File: GraphicsPrimitive.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected static SurfaceData convertFrom(Blit ob, SurfaceData srcData,
                                         int srcX, int srcY, int w, int h,
                                         SurfaceData dstData, int type)
{
    if (dstData != null) {
        Rectangle r = dstData.getBounds();
        if (w > r.width || h > r.height) {
            dstData = null;
        }
    }
    if (dstData == null) {
        BufferedImage dstBI = new BufferedImage(w, h, type);
        dstData = BufImgSurfaceData.createData(dstBI);
    }
    ob.Blit(srcData, dstData, AlphaComposite.Src, null,
            srcX, srcY, 0, 0, w, h);
    return dstData;
}
 
Example 6
Source File: GraphicsPrimitive.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected static SurfaceData convertFrom(Blit ob, SurfaceData srcData,
                                         int srcX, int srcY, int w, int h,
                                         SurfaceData dstData, int type)
{
    if (dstData != null) {
        Rectangle r = dstData.getBounds();
        if (w > r.width || h > r.height) {
            dstData = null;
        }
    }
    if (dstData == null) {
        BufferedImage dstBI = new BufferedImage(w, h, type);
        dstData = BufImgSurfaceData.createData(dstBI);
    }
    ob.Blit(srcData, dstData, AlphaComposite.Src, null,
            srcX, srcY, 0, 0, w, h);
    return dstData;
}
 
Example 7
Source File: GraphicsPrimitive.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected static SurfaceData convertFrom(Blit ob, SurfaceData srcData,
                                         int srcX, int srcY, int w, int h,
                                         SurfaceData dstData, int type)
{
    if (dstData != null) {
        Rectangle r = dstData.getBounds();
        if (w > r.width || h > r.height) {
            dstData = null;
        }
    }
    if (dstData == null) {
        BufferedImage dstBI = new BufferedImage(w, h, type);
        dstData = BufImgSurfaceData.createData(dstBI);
    }
    ob.Blit(srcData, dstData, AlphaComposite.Src, null,
            srcX, srcY, 0, 0, w, h);
    return dstData;
}
 
Example 8
Source File: CustomComponent.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static Region getRegionOfInterest(SurfaceData src, SurfaceData dst,
                                         Region clip,
                                         int srcx, int srcy,
                                         int dstx, int dsty,
                                         int w, int h)
{
    /*
     * Intersect all of:
     *   - operation area (dstx, dsty, w, h)
     *   - destination bounds
     *   - (translated) src bounds
     *   - supplied clip (may be non-rectangular)
     * Intersect the rectangular regions first since those are
     * simpler operations.
     */
    Region ret = Region.getInstanceXYWH(dstx, dsty, w, h);
    ret = ret.getIntersection(dst.getBounds());
    Rectangle r = src.getBounds();
    // srcxy in src space maps to dstxy in dst space
    r.translate(dstx - srcx, dsty - srcy);
    ret = ret.getIntersection(r);
    if (clip != null) {
        // Intersect with clip last since it may be non-rectangular
        ret = ret.getIntersection(clip);
    }
    return ret;
}
 
Example 9
Source File: CustomComponent.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static Region getRegionOfInterest(SurfaceData src, SurfaceData dst,
                                         Region clip,
                                         int srcx, int srcy,
                                         int dstx, int dsty,
                                         int w, int h)
{
    /*
     * Intersect all of:
     *   - operation area (dstx, dsty, w, h)
     *   - destination bounds
     *   - (translated) src bounds
     *   - supplied clip (may be non-rectangular)
     * Intersect the rectangular regions first since those are
     * simpler operations.
     */
    Region ret = Region.getInstanceXYWH(dstx, dsty, w, h);
    ret = ret.getIntersection(dst.getBounds());
    Rectangle r = src.getBounds();
    // srcxy in src space maps to dstxy in dst space
    r.translate(dstx - srcx, dsty - srcy);
    ret = ret.getIntersection(r);
    if (clip != null) {
        // Intersect with clip last since it may be non-rectangular
        ret = ret.getIntersection(clip);
    }
    return ret;
}
 
Example 10
Source File: OGLUtilities.java    From TencentKona-8 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 11
Source File: OGLUtilities.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the Rectangle describing the OpenGL viewport on the
 * Java 2D surface associated with the given Graphics object and
 * component width and height. When a third-party library is
 * performing OpenGL rendering directly into the visible region of
 * the associated surface, this viewport helps the application
 * position the OpenGL output correctly on that surface.
 *
 * Note that the x/y values in the returned Rectangle object represent
 * the lower-left corner of the viewport region, relative to the
 * lower-left corner of the given surface.
 *
 * @param g the Graphics object for the corresponding destination surface;
 * cannot be null
 * @param componentWidth width of the component to be painted
 * @param componentHeight height of the component to be painted
 * @return a Rectangle describing the OpenGL viewport for the given
 * destination surface and component dimensions, or null if the given
 * Graphics object is invalid
 */
public static Rectangle getOGLViewport(Graphics g,
                                       int componentWidth,
                                       int componentHeight)
{
    if (!(g instanceof SunGraphics2D)) {
        return null;
    }

    SunGraphics2D sg2d = (SunGraphics2D)g;
    SurfaceData sData = (SurfaceData)sg2d.surfaceData;

    // this is the upper-left origin of the region to be painted,
    // relative to the upper-left origin of the surface
    // (in Java2D coordinates)
    int x0 = sg2d.transX;
    int y0 = sg2d.transY;

    // this is the lower-left origin of the region to be painted,
    // relative to the lower-left origin of the surface
    // (in OpenGL coordinates)
    Rectangle surfaceBounds = sData.getBounds();
    int x1 = x0;
    int y1 = surfaceBounds.height - (y0 + componentHeight);

    return new Rectangle(x1, y1, componentWidth, componentHeight);
}
 
Example 12
Source File: CustomComponent.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static Region getRegionOfInterest(SurfaceData src, SurfaceData dst,
                                         Region clip,
                                         int srcx, int srcy,
                                         int dstx, int dsty,
                                         int w, int h)
{
    /*
     * Intersect all of:
     *   - operation area (dstx, dsty, w, h)
     *   - destination bounds
     *   - (translated) src bounds
     *   - supplied clip (may be non-rectangular)
     * Intersect the rectangular regions first since those are
     * simpler operations.
     */
    Region ret = Region.getInstanceXYWH(dstx, dsty, w, h);
    ret = ret.getIntersection(dst.getBounds());
    Rectangle r = src.getBounds();
    // srcxy in src space maps to dstxy in dst space
    r.translate(dstx - srcx, dsty - srcy);
    ret = ret.getIntersection(r);
    if (clip != null) {
        // Intersect with clip last since it may be non-rectangular
        ret = ret.getIntersection(clip);
    }
    return ret;
}
 
Example 13
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 14
Source File: OGLUtilities.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the Rectangle describing the OpenGL viewport on the
 * Java 2D surface associated with the given Graphics object and
 * component width and height. When a third-party library is
 * performing OpenGL rendering directly into the visible region of
 * the associated surface, this viewport helps the application
 * position the OpenGL output correctly on that surface.
 *
 * Note that the x/y values in the returned Rectangle object represent
 * the lower-left corner of the viewport region, relative to the
 * lower-left corner of the given surface.
 *
 * @param g the Graphics object for the corresponding destination surface;
 * cannot be null
 * @param componentWidth width of the component to be painted
 * @param componentHeight height of the component to be painted
 * @return a Rectangle describing the OpenGL viewport for the given
 * destination surface and component dimensions, or null if the given
 * Graphics object is invalid
 */
public static Rectangle getOGLViewport(Graphics g,
                                       int componentWidth,
                                       int componentHeight)
{
    if (!(g instanceof SunGraphics2D)) {
        return null;
    }

    SunGraphics2D sg2d = (SunGraphics2D)g;
    SurfaceData sData = (SurfaceData)sg2d.surfaceData;

    // this is the upper-left origin of the region to be painted,
    // relative to the upper-left origin of the surface
    // (in Java2D coordinates)
    int x0 = sg2d.transX;
    int y0 = sg2d.transY;

    // this is the lower-left origin of the region to be painted,
    // relative to the lower-left origin of the surface
    // (in OpenGL coordinates)
    Rectangle surfaceBounds = sData.getBounds();
    int x1 = x0;
    int y1 = surfaceBounds.height - (y0 + componentHeight);

    return new Rectangle(x1, y1, componentWidth, componentHeight);
}
 
Example 15
Source File: OGLUtilities.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the Rectangle describing the OpenGL viewport on the
 * Java 2D surface associated with the given Graphics object and
 * component width and height. When a third-party library is
 * performing OpenGL rendering directly into the visible region of
 * the associated surface, this viewport helps the application
 * position the OpenGL output correctly on that surface.
 *
 * Note that the x/y values in the returned Rectangle object represent
 * the lower-left corner of the viewport region, relative to the
 * lower-left corner of the given surface.
 *
 * @param g the Graphics object for the corresponding destination surface;
 * cannot be null
 * @param componentWidth width of the component to be painted
 * @param componentHeight height of the component to be painted
 * @return a Rectangle describing the OpenGL viewport for the given
 * destination surface and component dimensions, or null if the given
 * Graphics object is invalid
 */
public static Rectangle getOGLViewport(Graphics g,
                                       int componentWidth,
                                       int componentHeight)
{
    if (!(g instanceof SunGraphics2D)) {
        return null;
    }

    SunGraphics2D sg2d = (SunGraphics2D)g;
    SurfaceData sData = (SurfaceData)sg2d.surfaceData;

    // this is the upper-left origin of the region to be painted,
    // relative to the upper-left origin of the surface
    // (in Java2D coordinates)
    int x0 = sg2d.transX;
    int y0 = sg2d.transY;

    // this is the lower-left origin of the region to be painted,
    // relative to the lower-left origin of the surface
    // (in OpenGL coordinates)
    Rectangle surfaceBounds = sData.getBounds();
    int x1 = x0;
    int y1 = surfaceBounds.height - (y0 + componentHeight);

    return new Rectangle(x1, y1, componentWidth, componentHeight);
}
 
Example 16
Source File: OGLUtilities.java    From jdk8u-dev-jdk 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 17
Source File: CustomComponent.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static Region getRegionOfInterest(SurfaceData src, SurfaceData dst,
                                         Region clip,
                                         int srcx, int srcy,
                                         int dstx, int dsty,
                                         int w, int h)
{
    /*
     * Intersect all of:
     *   - operation area (dstx, dsty, w, h)
     *   - destination bounds
     *   - (translated) src bounds
     *   - supplied clip (may be non-rectangular)
     * Intersect the rectangular regions first since those are
     * simpler operations.
     */
    Region ret = Region.getInstanceXYWH(dstx, dsty, w, h);
    ret = ret.getIntersection(dst.getBounds());
    Rectangle r = src.getBounds();
    // srcxy in src space maps to dstxy in dst space
    r.translate(dstx - srcx, dsty - srcy);
    ret = ret.getIntersection(r);
    if (clip != null) {
        // Intersect with clip last since it may be non-rectangular
        ret = ret.getIntersection(clip);
    }
    return ret;
}
 
Example 18
Source File: OGLUtilities.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the Rectangle describing the OpenGL viewport on the
 * Java 2D surface associated with the given Graphics object and
 * component width and height. When a third-party library is
 * performing OpenGL rendering directly into the visible region of
 * the associated surface, this viewport helps the application
 * position the OpenGL output correctly on that surface.
 *
 * Note that the x/y values in the returned Rectangle object represent
 * the lower-left corner of the viewport region, relative to the
 * lower-left corner of the given surface.
 *
 * @param g the Graphics object for the corresponding destination surface;
 * cannot be null
 * @param componentWidth width of the component to be painted
 * @param componentHeight height of the component to be painted
 * @return a Rectangle describing the OpenGL viewport for the given
 * destination surface and component dimensions, or null if the given
 * Graphics object is invalid
 */
public static Rectangle getOGLViewport(Graphics g,
                                       int componentWidth,
                                       int componentHeight)
{
    if (!(g instanceof SunGraphics2D)) {
        return null;
    }

    SunGraphics2D sg2d = (SunGraphics2D)g;
    SurfaceData sData = (SurfaceData)sg2d.surfaceData;

    // this is the upper-left origin of the region to be painted,
    // relative to the upper-left origin of the surface
    // (in Java2D coordinates)
    int x0 = sg2d.transX;
    int y0 = sg2d.transY;

    // this is the lower-left origin of the region to be painted,
    // relative to the lower-left origin of the surface
    // (in OpenGL coordinates)
    Rectangle surfaceBounds = sData.getBounds();
    int x1 = x0;
    int y1 = surfaceBounds.height - (y0 + componentHeight);

    return new Rectangle(x1, y1, componentWidth, componentHeight);
}
 
Example 19
Source File: OGLUtilities.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the Rectangle describing the OpenGL viewport on the
 * Java 2D surface associated with the given Graphics object and
 * component width and height. When a third-party library is
 * performing OpenGL rendering directly into the visible region of
 * the associated surface, this viewport helps the application
 * position the OpenGL output correctly on that surface.
 *
 * Note that the x/y values in the returned Rectangle object represent
 * the lower-left corner of the viewport region, relative to the
 * lower-left corner of the given surface.
 *
 * @param g the Graphics object for the corresponding destination surface;
 * cannot be null
 * @param componentWidth width of the component to be painted
 * @param componentHeight height of the component to be painted
 * @return a Rectangle describing the OpenGL viewport for the given
 * destination surface and component dimensions, or null if the given
 * Graphics object is invalid
 */
public static Rectangle getOGLViewport(Graphics g,
                                       int componentWidth,
                                       int componentHeight)
{
    if (!(g instanceof SunGraphics2D)) {
        return null;
    }

    SunGraphics2D sg2d = (SunGraphics2D)g;
    SurfaceData sData = (SurfaceData)sg2d.surfaceData;

    // this is the upper-left origin of the region to be painted,
    // relative to the upper-left origin of the surface
    // (in Java2D coordinates)
    int x0 = sg2d.transX;
    int y0 = sg2d.transY;

    // this is the lower-left origin of the region to be painted,
    // relative to the lower-left origin of the surface
    // (in OpenGL coordinates)
    Rectangle surfaceBounds = sData.getBounds();
    int x1 = x0;
    int y1 = surfaceBounds.height - (y0 + componentHeight);

    return new Rectangle(x1, y1, componentWidth, componentHeight);
}
 
Example 20
Source File: OGLUtilities.java    From openjdk-jdk8u-backup 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);
}