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();
// System.out.println("Render: " + r);
WritableRaster dst = copyRaster.createWritableChild
(r.x, r.y, r.width, r.height, r.x, r.y, null);