I wrote an Activity which shows only one custom view.
The view is simple, draw a random color and invalidate a smaller region, and draw a random color, and invalidate a even smaller region, and so on...
The expected result should be like this. It works well by using software render, and getClipBounds() returns the region I just passed into invalidate. But when hardware acceleration is enabled, the entire view is always redrawn by a new color, and getClipBounds() return the entire view's region.
I know there are some posts like this and this. Answers said that getClipBounds() returns the entire view's region with hardware acceleration but only the ones intersecting the dirty region will be redrawn.
Is there anything wrong or my misunderstanding?
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
// random color
int color = Color.rgb((int) (Math.random() * 255),
(int) (Math.random() * 255), (int) (Math.random() * 255));
canvas.drawColor(color);
canvas.getClipBounds(rect);
// smaller dirty region
invalidate(0, 0, rect.width() - 1, rect.height() - 1);
}