use of sun.java2d.SunGraphics2D in project jdk8u_jdk by JetBrains.
the class OGLUtilities method getOGLScissorBox.
/**
* 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()) {
// 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);
}
use of sun.java2d.SunGraphics2D in project jdk8u_jdk by JetBrains.
the class OGLUtilities method getOGLViewport.
/**
* 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);
}
use of sun.java2d.SunGraphics2D in project jdk8u_jdk by JetBrains.
the class GeneralCompositePipe method renderPathTile.
/**
* GeneralCompositePipe.renderPathTile works with custom composite operator
* provided by an application
*/
public void renderPathTile(Object ctx, byte[] atile, int offset, int tilesize, int x, int y, int w, int h) {
TileContext context = (TileContext) ctx;
PaintContext paintCtxt = context.paintCtxt;
CompositeContext compCtxt = context.compCtxt;
SunGraphics2D sg = context.sunG2D;
Raster srcRaster = paintCtxt.getRaster(x, y, w, h);
ColorModel paintModel = paintCtxt.getColorModel();
Raster dstRaster;
Raster dstIn;
WritableRaster dstOut;
SurfaceData sd = sg.getSurfaceData();
dstRaster = sd.getRaster(x, y, w, h);
if (dstRaster instanceof WritableRaster && atile == null) {
dstOut = (WritableRaster) dstRaster;
dstOut = dstOut.createWritableChild(x, y, w, h, 0, 0, null);
dstIn = dstOut;
} else {
dstIn = dstRaster.createChild(x, y, w, h, 0, 0, null);
dstOut = dstIn.createCompatibleWritableRaster();
}
compCtxt.compose(srcRaster, dstIn, dstOut);
if (dstRaster != dstOut && dstOut.getParent() != dstRaster) {
if (dstRaster instanceof WritableRaster && atile == null) {
((WritableRaster) dstRaster).setDataElements(x, y, dstOut);
} else {
ColorModel cm = sg.getDeviceColorModel();
BufferedImage resImg = new BufferedImage(cm, dstOut, cm.isAlphaPremultiplied(), null);
SurfaceData resData = BufImgSurfaceData.createData(resImg);
if (atile == null) {
Blit blit = Blit.getFromCache(resData.getSurfaceType(), CompositeType.SrcNoEa, sd.getSurfaceType());
blit.Blit(resData, sd, AlphaComposite.Src, null, 0, 0, x, y, w, h);
} else {
MaskBlit blit = MaskBlit.getFromCache(resData.getSurfaceType(), CompositeType.SrcNoEa, sd.getSurfaceType());
blit.MaskBlit(resData, sd, AlphaComposite.Src, null, 0, 0, x, y, w, h, atile, offset, tilesize);
}
}
}
}
use of sun.java2d.SunGraphics2D in project jdk8u_jdk by JetBrains.
the class DrawImage method makeBufferedImage.
/**
* Return a non-accelerated BufferedImage of the requested type with the
* indicated subimage of the original image located at 0,0 in the new image.
* If a bgColor is supplied, composite the original image over that color
* with a SrcOver operation, otherwise make a SrcNoEa copy.
* <p>
* Returned BufferedImage is not accelerated for two reasons:
* <ul>
* <li> Types of the image and surface are predefined, because these types
* correspond to the TransformHelpers, which we know we have. And
* acceleration can change the type of the surface
* <li> Image will be used only once and acceleration caching wouldn't help
* </ul>
*/
BufferedImage makeBufferedImage(Image img, Color bgColor, int type, int sx1, int sy1, int sx2, int sy2) {
final int width = sx2 - sx1;
final int height = sy2 - sy1;
final BufferedImage bimg = new BufferedImage(width, height, type);
final SunGraphics2D g2d = (SunGraphics2D) bimg.createGraphics();
g2d.setComposite(AlphaComposite.Src);
bimg.setAccelerationPriority(0);
if (bgColor != null) {
g2d.setColor(bgColor);
g2d.fillRect(0, 0, width, height);
g2d.setComposite(AlphaComposite.SrcOver);
}
g2d.copyImage(img, 0, 0, sx1, sy1, width, height, null, null);
g2d.dispose();
return bimg;
}
use of sun.java2d.SunGraphics2D in project jdk8u_jdk by JetBrains.
the class WGLGraphicsConfig method flip.
/**
* Performs the native WGL flip operation for the given target Component.
*/
@Override
public void flip(WComponentPeer peer, Component target, VolatileImage backBuffer, int x1, int y1, int x2, int y2, BufferCapabilities.FlipContents flipAction) {
if (flipAction == BufferCapabilities.FlipContents.COPIED) {
SurfaceManager vsm = SurfaceManager.getManager(backBuffer);
SurfaceData sd = vsm.getPrimarySurfaceData();
if (sd instanceof WGLVSyncOffScreenSurfaceData) {
WGLVSyncOffScreenSurfaceData vsd = (WGLVSyncOffScreenSurfaceData) sd;
SurfaceData bbsd = vsd.getFlipSurface();
Graphics2D bbg = new SunGraphics2D(bbsd, Color.black, Color.white, null);
try {
bbg.drawImage(backBuffer, 0, 0, null);
} finally {
bbg.dispose();
}
} else {
Graphics g = peer.getGraphics();
try {
g.drawImage(backBuffer, x1, y1, x2, y2, x1, y1, x2, y2, null);
} finally {
g.dispose();
}
return;
}
} else if (flipAction == BufferCapabilities.FlipContents.PRIOR) {
// not supported by WGL...
return;
}
OGLSurfaceData.swapBuffers(peer.getData());
if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {
Graphics g = backBuffer.getGraphics();
try {
g.setColor(target.getBackground());
g.fillRect(0, 0, backBuffer.getWidth(), backBuffer.getHeight());
} finally {
g.dispose();
}
}
}
Aggregations