// if (lastFrame != -1) {
// System.out.println("InterFrame time: " + (t0-lastFrame));
// }
// lastFrame = t0;
CachableRed cr;
WritableRaster syncRaster;
WritableRaster copyRaster;
updateWorkingBuffers();
if ((rootCR == null) ||
(workingBaseRaster == null)) {
// System.out.println("RootCR: " + rootCR);
// System.out.println("wrkBaseRaster: " + workingBaseRaster);
return;
}
cr = rootCR;
syncRaster = workingBaseRaster;
copyRaster = workingRaster;
Rectangle srcR = rootCR.getBounds();
// System.out.println("RootCR: " + srcR);
Rectangle dstR = workingRaster.getBounds();
if ((dstR.x < srcR.x) ||
(dstR.y < srcR.y) ||
(dstR.x+dstR.width > srcR.x+srcR.width) ||
(dstR.y+dstR.height > srcR.y+srcR.height))
cr = new PadRed(cr, dstR, PadMode.ZERO_PAD, null);
Rectangle [] devRects = new Rectangle[areas.size()];
Iterator iter = areas.iterator();
Rectangle dr = copyRaster.getBounds();
float dmgSz = 0f;
int sz=0;
// System.out.println("DR: " + dr);
while (iter.hasNext()) {
Shape s = (Shape)iter.next();
s = usr2dev.createTransformedShape(s);
Rectangle2D r2d = s.getBounds2D();
int x0 = (int)Math.floor(r2d.getX());
int y0 = (int)Math.floor(r2d.getY());
int x1 = (int)Math.ceil(r2d.getX()+r2d.getWidth());
int y1 = (int)Math.ceil(r2d.getY()+r2d.getHeight());
// Rectangle r = new Rectangle(x0, y0, x1-x0+1, y1-y0+1);
// This rectangle must be outset one pixel to ensure
// it includes the effects of anti-aliasing on object.s
Rectangle r = new Rectangle(x0-1, y0-1, x1-x0+3, y1-y0+3);
// System.out.println(" Rect [" + sz+ "]: " + r);
//System.out.println(" Rect2D [" + sz+ "]: " + r2d);
if (!dr.intersects(r)) continue;
r = dr.intersection(r);
devRects[sz++] = r;
dmgSz += r.width*(float)r.height;
}
RectListManager devRLM =null;
try {
devRLM = new RectListManager(devRects, 0, sz);
} catch(Exception e) {
e.printStackTrace();
}
// Merge the repaint rectangles...
devRLM.mergeRects(COPY_OVERHEAD, COPY_LINE_OVERHEAD);
boolean repaintAll = (dmgSz > offScreenWidth*offScreenHeight*0.9f);
// Ensure only one thread works on baseRaster at a time...
synchronized (syncRaster) {
// System.out.println("Dynamic:");
if (repaintAll) {
// System.out.println("Repainting All");
cr.copyData(copyRaster);
} else {
java.awt.Graphics2D g2d = null;
if (false) {
BufferedImage tmpBI = new BufferedImage
(workingOffScreen.getColorModel(),
copyRaster.createWritableTranslatedChild(0, 0),
workingOffScreen.isAlphaPremultiplied(), null);
g2d = GraphicsUtil.createGraphics(tmpBI);
g2d.translate(-copyRaster.getMinX(),
-copyRaster.getMinY());
}
if ((isDoubleBuffered) &&
(currentRaster != null) &&
(damagedAreas != null)) {
damagedAreas.subtract(devRLM, COPY_OVERHEAD,
COPY_LINE_OVERHEAD);
damagedAreas.mergeRects(COPY_OVERHEAD,
COPY_LINE_OVERHEAD);
iter = damagedAreas.iterator();
Rectangle sr = currentRaster.getBounds();
while (iter.hasNext()) {
Rectangle r = (Rectangle)iter.next();
// System.out.println("Copy: " + r);
Raster src = currentRaster.createWritableChild
(r.x, r.y, r.width, r.height, r.x, r.y, null);
GraphicsUtil.copyData(src, copyRaster);
if (g2d != null) {
g2d.setPaint(new java.awt.Color(0,0,255,50));
g2d.fill(r);
g2d.setPaint(new java.awt.Color(0,0,0,50));
g2d.draw(r);
}
}
}
iter = devRLM.iterator();
while (iter.hasNext()) {
Rectangle r = (Rectangle)iter.next();
WritableRaster dst = copyRaster.createWritableChild
(r.x, r.y, r.width, r.height, r.x, r.y, null);
cr.copyData(dst);
if (g2d != null) {
g2d.setPaint(new java.awt.Color(255,0,0,50));
g2d.fill(r);
g2d.setPaint(new java.awt.Color(0,0,0,50));
g2d.draw(r);