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);
}