use of sun.java2d.SurfaceData 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.SurfaceData 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.SurfaceData in project jdk8u_jdk by JetBrains.
the class DrawImage method renderImageScale.
// Render an image using only integer scaling (no transform).
protected boolean renderImageScale(SunGraphics2D sg, Image img, Color bgColor, int interpType, int sx1, int sy1, int sx2, int sy2, double dx1, double dy1, double dx2, double dy2) {
// for ScaledBlit operations.
if (interpType != AffineTransformOp.TYPE_NEAREST_NEIGHBOR) {
return false;
}
Region clip = sg.getCompClip();
SurfaceData dstData = sg.surfaceData;
int attempts = 0;
// and try it once more
while (true) {
SurfaceData srcData = dstData.getSourceSurfaceData(img, SunGraphics2D.TRANSFORM_TRANSLATESCALE, sg.imageComp, bgColor);
if (srcData == null || isBgOperation(srcData, bgColor)) {
return false;
}
try {
SurfaceType srcType = srcData.getSurfaceType();
SurfaceType dstType = dstData.getSurfaceType();
return scaleSurfaceData(sg, clip, srcData, dstData, srcType, dstType, sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2);
} catch (NullPointerException e) {
if (!SurfaceData.isNull(dstData)) {
// Something else caused the exception, throw it...
throw e;
}
return false;
// NOP if we have been disposed
} catch (InvalidPipeException e) {
// Always catch the exception; try this a couple of times
// and fail silently if the system is not yet ready to
// revalidate the source or dest surfaceData objects.
++attempts;
// ensures sg.surfaceData is valid
clip = sg.getCompClip();
dstData = sg.surfaceData;
if (SurfaceData.isNull(dstData) || SurfaceData.isNull(srcData) || (attempts > 1)) {
return false;
}
}
}
}
use of sun.java2d.SurfaceData 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.SurfaceData in project jdk8u_jdk by JetBrains.
the class LoopPipe method fillSpans.
private static void fillSpans(SunGraphics2D sg2d, SpanIterator si) {
// loop implemented for any destination type...
if (sg2d.clipState == SunGraphics2D.CLIP_SHAPE) {
si = sg2d.clipRegion.filter(si);
// REMIND: Region.filter produces a Java-only iterator
// with no native counterpart...
} else {
sun.java2d.loops.FillSpans fs = sg2d.loops.fillSpansLoop;
if (fs != null) {
fs.FillSpans(sg2d, sg2d.getSurfaceData(), si);
return;
}
}
int[] spanbox = new int[4];
SurfaceData sd = sg2d.getSurfaceData();
while (si.nextSpan(spanbox)) {
int x = spanbox[0];
int y = spanbox[1];
int w = spanbox[2] - x;
int h = spanbox[3] - y;
sg2d.loops.fillRectLoop.FillRect(sg2d, sd, x, y, w, h);
}
}
Aggregations