use of sun.java2d.pipe.Region in project jdk8u_jdk by JetBrains.
the class SunGraphics2D method validateCompClip.
protected void validateCompClip() {
int origClipState = clipState;
if (usrClip == null) {
clipState = CLIP_DEVICE;
clipRegion = devClip;
} else if (usrClip instanceof Rectangle2D) {
clipState = CLIP_RECTANGULAR;
if (usrClip instanceof Rectangle) {
clipRegion = devClip.getIntersection((Rectangle) usrClip);
} else {
clipRegion = devClip.getIntersection(usrClip.getBounds());
}
} else {
PathIterator cpi = usrClip.getPathIterator(null);
int[] box = new int[4];
ShapeSpanIterator sr = LoopPipe.getFillSSI(this);
try {
sr.setOutputArea(devClip);
sr.appendPath(cpi);
sr.getPathBox(box);
Region r = Region.getInstance(box);
r.appendSpans(sr);
clipRegion = r;
clipState = r.isRectangular() ? CLIP_RECTANGULAR : CLIP_SHAPE;
} finally {
sr.dispose();
}
}
if (origClipState != clipState && (clipState == CLIP_SHAPE || origClipState == CLIP_SHAPE)) {
validFontInfo = false;
invalidatePipe();
}
}
use of sun.java2d.pipe.Region in project jdk8u_jdk by JetBrains.
the class SunGraphics2D method drawRenderedImage.
/**
* Draws an image, applying a transform from image space into user space
* before drawing.
* The transformation from user space into device space is done with
* the current transform in the Graphics2D.
* The given transformation is applied to the image before the
* transform attribute in the Graphics2D state is applied.
* The rendering attributes applied include the clip, transform,
* and composite attributes. Note that the result is
* undefined, if the given transform is noninvertible.
* @param img The image to be drawn. Does nothing if img is null.
* @param xform The transformation from image space into user space.
* @see #transform
* @see #setTransform
* @see #setComposite
* @see #clip
* @see #setClip
*/
public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
if (img == null) {
return;
}
// BufferedImage case: use a simple drawImage call
if (img instanceof BufferedImage) {
BufferedImage bufImg = (BufferedImage) img;
drawImage(bufImg, xform, null);
return;
}
// transformState tracks the state of transform and
// transX, transY contain the integer casts of the
// translation factors
boolean isIntegerTranslate = (transformState <= TRANSFORM_INT_TRANSLATE) && isIntegerTranslation(xform);
// Include padding for interpolation/antialiasing if necessary
int pad = isIntegerTranslate ? 0 : 3;
Region clip;
try {
clip = getCompClip();
} catch (InvalidPipeException e) {
return;
}
// Determine the region of the image that may contribute to
// the clipped drawing area
Rectangle region = getImageRegion(img, clip, transform, xform, pad, pad);
if (region.width <= 0 || region.height <= 0) {
return;
}
// where both are integer translations.
if (isIntegerTranslate) {
// Use optimized code
// Note that drawTranslatedRenderedImage calls copyImage
// which takes the user space to device space transform into
// account, but we need to provide the image space to user space
// translations.
drawTranslatedRenderedImage(img, region, (int) xform.getTranslateX(), (int) xform.getTranslateY());
return;
}
// General case: cobble the necessary region into a single Raster
Raster raster = img.getData(region);
// Make a new Raster with the same contents as raster
// but starting at (0, 0). This raster is thus in the same
// coordinate system as the SampleModel of the original raster.
WritableRaster wRaster = Raster.createWritableRaster(raster.getSampleModel(), raster.getDataBuffer(), null);
// If the original raster was in a different coordinate
// system than its SampleModel, we need to perform an
// additional translation in order to get the (minX, minY)
// pixel of raster to be pixel (0, 0) of wRaster. We also
// have to have the correct width and height.
int minX = raster.getMinX();
int minY = raster.getMinY();
int width = raster.getWidth();
int height = raster.getHeight();
int px = minX - raster.getSampleModelTranslateX();
int py = minY - raster.getSampleModelTranslateY();
if (px != 0 || py != 0 || width != wRaster.getWidth() || height != wRaster.getHeight()) {
wRaster = wRaster.createWritableChild(px, py, width, height, 0, 0, null);
}
// Now we have a BufferedImage starting at (0, 0)
// with the same contents that started at (minX, minY)
// in raster. So we must draw the BufferedImage with a
// translation of (minX, minY).
AffineTransform transXform = (AffineTransform) xform.clone();
transXform.translate(minX, minY);
ColorModel cm = img.getColorModel();
BufferedImage bufImg = new BufferedImage(cm, wRaster, cm.isAlphaPremultiplied(), null);
drawImage(bufImg, transXform, null);
}
use of sun.java2d.pipe.Region in project jdk8u_jdk by JetBrains.
the class SunGraphics2D method doCopyArea.
private void doCopyArea(int x, int y, int w, int h, int dx, int dy) {
if (w <= 0 || h <= 0) {
return;
}
SurfaceData theData = surfaceData;
if (theData.copyArea(this, x, y, w, h, dx, dy)) {
return;
}
if (transformState > TRANSFORM_TRANSLATESCALE) {
throw new InternalError("transformed copyArea not implemented yet");
}
// REMIND: This method does not deal with missing data from the
// source object (i.e. it does not send exposure events...)
Region clip = getCompClip();
Composite comp = composite;
if (lastCAcomp != comp) {
SurfaceType dsttype = theData.getSurfaceType();
CompositeType comptype = imageComp;
if (CompositeType.SrcOverNoEa.equals(comptype) && theData.getTransparency() == Transparency.OPAQUE) {
comptype = CompositeType.SrcNoEa;
}
lastCAblit = Blit.locate(dsttype, comptype, dsttype);
lastCAcomp = comp;
}
double[] coords = { x, y, x + w, y + h, x + dx, y + dy };
transform.transform(coords, 0, coords, 0, 3);
x = (int) Math.ceil(coords[0] - 0.5);
y = (int) Math.ceil(coords[1] - 0.5);
w = ((int) Math.ceil(coords[2] - 0.5)) - x;
h = ((int) Math.ceil(coords[3] - 0.5)) - y;
dx = ((int) Math.ceil(coords[4] - 0.5)) - x;
dy = ((int) Math.ceil(coords[5] - 0.5)) - y;
// In case of negative scale transform, reflect the rect coords.
if (w < 0) {
w *= -1;
x -= w;
}
if (h < 0) {
h *= -1;
y -= h;
}
Blit ob = lastCAblit;
if (dy == 0 && dx > 0 && dx < w) {
while (w > 0) {
int partW = Math.min(w, dx);
w -= partW;
int sx = x + w;
ob.Blit(theData, theData, comp, clip, sx, y, sx + dx, y + dy, partW, h);
}
return;
}
if (dy > 0 && dy < h && dx > -w && dx < w) {
while (h > 0) {
int partH = Math.min(h, dy);
h -= partH;
int sy = y + h;
ob.Blit(theData, theData, comp, clip, x, sy, x + dx, sy + dy, w, partH);
}
return;
}
ob.Blit(theData, theData, comp, clip, x, y, x + dx, y + dy, w, h);
}
use of sun.java2d.pipe.Region in project jdk8u_jdk by JetBrains.
the class SunGraphics2D method setDevClip.
public void setDevClip(int x, int y, int w, int h) {
Region c = constrainClip;
if (c == null) {
devClip = Region.getInstanceXYWH(x, y, w, h);
} else {
devClip = c.getIntersectionXYWH(x, y, w, h);
}
validateCompClip();
}
use of sun.java2d.pipe.Region in project jdk8u_jdk by JetBrains.
the class LWComponentPeer method findPeerAt.
// ---- UTILITY METHODS ---- //
/**
* Finds a top-most visible component for the given point. The location is
* specified relative to the peer's parent.
*/
LWComponentPeer<?, ?> findPeerAt(final int x, final int y) {
final Rectangle r = getBounds();
final Region sh = getRegion();
final boolean found = isVisible() && sh.contains(x - r.x, y - r.y);
return found ? this : null;
}
Aggregations