Here is a part of the patch for HARMONY-5026 responsible for dirty
regions calculations:
=== cut ===
public void addDirtyRegion(Rectangle r){
if (dirtyRegions == null) {
dirtyRegions = new MultiRectArea(r);
} else {
Rectangle rects[] = dirtyRegions.getRectangles();
if (rects.length == 1){
if (rects[0].contains(r)) return;
}
dirtyRegions.add(r);
}
invalidate();
}
public int[] getDirtyRegions(){
if(dirtyRegions != null) return dirtyRegions.rect;
else return null;
}
=== cut ===
As we can see MultiRectArea.add method is used here for adding a new region.
Here is the MultiRectArea.add method:
=== cut ===
public void add(Rectangle rect) {
setRect(union(this, new MultiRectArea(rect)).rect, false);
invalidate();
}
=== cut ===
I would say that this is probably too heavy method to call very often.
I can suggest the following strategy to use here:
1. Store all the dirty rectangles in some list (array, Vector or something)
2. Create MultiRectArea only once in getDirtyRegions methods. This
will theoretically save us a lot of object creations and array copying
in MultiRectArea.add method.
Thoughts?
SY, Alexey