Hello, all
When a view has a animation and is drawing it, I found the dirty region size to be redrawn is its parents' size, not its own size, the dirty region is too large, so the device will cost too much comsumption while drawing animation.
I checked the code(Android 4.2), I found the dirty region is its parents' size becase of the below code in View.java
boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) {
...
if (more && hardwareAccelerated) {
// invalidation is the trigger to recreate display lists, so if we're using
// display lists to render, force an invalidate to allow the animation to
// continue drawing another frame
parent.invalidate(true);
if (a.hasAlpha() && (mPrivateFlags & PFLAG_ALPHA_SET) == PFLAG_ALPHA_SET) {
// alpha animations should cause the child to recreate its display list
invalidate(true);
}
}
...
}
I deleted parent.invalidate(true) and tested animation again, I found everything is ok, drawing animation is ok, dirty region is small, comsumption is low.
So I have several questions.
#1 why should call parent.invalidate(true), because in View.drawAnimation, it has already called parent.invalidate(mLeft, mTop, mRight, mBottom) or parent.invalidate(left, top, left + (int) (region.width() + .5f),top + (int) (region.height() + .5f)), so called parent.invalidate(true) again seemed meaningless.
#2 If parent.invalidate(true) is really need to be called, what type of animation will behaviour badly if I deleted parent.invalidate(true)
Thanks and applogize for my poor English.