Skip to content

Commit fe455af

Browse files
author
Romain Guy
committed
Add a compile time condition to remove unnecessary code
Change-Id: Ia44916af8e22e548fbb62cb2b53da285d5959102
1 parent b04f7e9 commit fe455af

File tree

2 files changed

+116
-111
lines changed

2 files changed

+116
-111
lines changed

core/java/android/view/View.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6818,8 +6818,8 @@ void setFlags(int flags, int mask) {
68186818

68196819
if ((changed & VISIBILITY_MASK) != 0) {
68206820
if (mParent instanceof ViewGroup) {
6821-
((ViewGroup) mParent).onChildVisibilityChanged(this, (changed & VISIBILITY_MASK),
6822-
(flags & VISIBILITY_MASK));
6821+
((ViewGroup) mParent).onChildVisibilityChanged(this,
6822+
(changed & VISIBILITY_MASK), (flags & VISIBILITY_MASK));
68236823
((View) mParent).invalidate(true);
68246824
} else if (mParent != null) {
68256825
mParent.invalidateChild(this, null);

core/java/android/view/ViewGroup.java

Lines changed: 114 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -3601,130 +3601,135 @@ public final void invalidateChild(View child, final Rect dirty) {
36013601
// through
36023602
final boolean drawAnimation = (child.mPrivateFlags & DRAW_ANIMATION) == DRAW_ANIMATION;
36033603

3604-
if (dirty == null) {
3605-
if (child.mLayerType != LAYER_TYPE_NONE) {
3606-
mPrivateFlags |= INVALIDATED;
3607-
mPrivateFlags &= ~DRAWING_CACHE_VALID;
3608-
child.mLocalDirtyRect.setEmpty();
3609-
}
3610-
do {
3611-
View view = null;
3612-
if (parent instanceof View) {
3613-
view = (View) parent;
3614-
if (view.mLayerType != LAYER_TYPE_NONE) {
3615-
view.mLocalDirtyRect.setEmpty();
3616-
if (view.getParent() instanceof View) {
3617-
final View grandParent = (View) view.getParent();
3618-
grandParent.mPrivateFlags |= INVALIDATED;
3619-
grandParent.mPrivateFlags &= ~DRAWING_CACHE_VALID;
3604+
//noinspection PointlessBooleanExpression
3605+
if (!HardwareRenderer.RENDER_DIRTY_REGIONS) {
3606+
if (dirty == null) {
3607+
if (child.mLayerType != LAYER_TYPE_NONE) {
3608+
mPrivateFlags |= INVALIDATED;
3609+
mPrivateFlags &= ~DRAWING_CACHE_VALID;
3610+
child.mLocalDirtyRect.setEmpty();
3611+
}
3612+
do {
3613+
View view = null;
3614+
if (parent instanceof View) {
3615+
view = (View) parent;
3616+
if (view.mLayerType != LAYER_TYPE_NONE) {
3617+
view.mLocalDirtyRect.setEmpty();
3618+
if (view.getParent() instanceof View) {
3619+
final View grandParent = (View) view.getParent();
3620+
grandParent.mPrivateFlags |= INVALIDATED;
3621+
grandParent.mPrivateFlags &= ~DRAWING_CACHE_VALID;
3622+
}
3623+
}
3624+
if ((view.mPrivateFlags & DIRTY_MASK) != 0) {
3625+
// already marked dirty - we're done
3626+
break;
36203627
}
36213628
}
3622-
if ((view.mPrivateFlags & DIRTY_MASK) != 0) {
3623-
// already marked dirty - we're done
3624-
break;
3625-
}
3626-
}
3627-
3628-
if (drawAnimation) {
3629-
if (view != null) {
3630-
view.mPrivateFlags |= DRAW_ANIMATION;
3631-
} else if (parent instanceof ViewRootImpl) {
3632-
((ViewRootImpl) parent).mIsAnimating = true;
3629+
3630+
if (drawAnimation) {
3631+
if (view != null) {
3632+
view.mPrivateFlags |= DRAW_ANIMATION;
3633+
} else if (parent instanceof ViewRootImpl) {
3634+
((ViewRootImpl) parent).mIsAnimating = true;
3635+
}
36333636
}
3634-
}
3635-
3636-
if (parent instanceof ViewRootImpl) {
3637-
((ViewRootImpl) parent).invalidate();
3638-
parent = null;
3639-
} else if (view != null) {
3640-
if ((view.mPrivateFlags & DRAWN) == DRAWN ||
3641-
(view.mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID) {
3642-
view.mPrivateFlags &= ~DRAWING_CACHE_VALID;
3643-
view.mPrivateFlags |= DIRTY;
3644-
parent = view.mParent;
3645-
} else {
3637+
3638+
if (parent instanceof ViewRootImpl) {
3639+
((ViewRootImpl) parent).invalidate();
36463640
parent = null;
3641+
} else if (view != null) {
3642+
if ((view.mPrivateFlags & DRAWN) == DRAWN ||
3643+
(view.mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID) {
3644+
view.mPrivateFlags &= ~DRAWING_CACHE_VALID;
3645+
view.mPrivateFlags |= DIRTY;
3646+
parent = view.mParent;
3647+
} else {
3648+
parent = null;
3649+
}
36473650
}
3648-
}
3649-
} while (parent != null);
3650-
} else {
3651-
// Check whether the child that requests the invalidate is fully opaque
3652-
// Views being animated or transformed are not considered opaque because we may
3653-
// be invalidating their old position and need the parent to paint behind them.
3654-
Matrix childMatrix = child.getMatrix();
3655-
final boolean isOpaque = child.isOpaque() && !drawAnimation &&
3656-
child.getAnimation() == null && childMatrix.isIdentity();
3657-
// Mark the child as dirty, using the appropriate flag
3658-
// Make sure we do not set both flags at the same time
3659-
int opaqueFlag = isOpaque ? DIRTY_OPAQUE : DIRTY;
3660-
3661-
if (child.mLayerType != LAYER_TYPE_NONE) {
3662-
mPrivateFlags |= INVALIDATED;
3663-
mPrivateFlags &= ~DRAWING_CACHE_VALID;
3664-
child.mLocalDirtyRect.union(dirty);
3651+
} while (parent != null);
36653652
}
36663653

3667-
final int[] location = attachInfo.mInvalidateChildLocation;
3668-
location[CHILD_LEFT_INDEX] = child.mLeft;
3669-
location[CHILD_TOP_INDEX] = child.mTop;
3670-
if (!childMatrix.isIdentity()) {
3671-
RectF boundingRect = attachInfo.mTmpTransformRect;
3672-
boundingRect.set(dirty);
3673-
//boundingRect.inset(-0.5f, -0.5f);
3674-
childMatrix.mapRect(boundingRect);
3675-
dirty.set((int) (boundingRect.left - 0.5f),
3676-
(int) (boundingRect.top - 0.5f),
3677-
(int) (boundingRect.right + 0.5f),
3678-
(int) (boundingRect.bottom + 0.5f));
3679-
}
3654+
return;
3655+
}
36803656

3681-
do {
3682-
View view = null;
3683-
if (parent instanceof View) {
3684-
view = (View) parent;
3685-
if (view.mLayerType != LAYER_TYPE_NONE &&
3686-
view.getParent() instanceof View) {
3687-
final View grandParent = (View) view.getParent();
3688-
grandParent.mPrivateFlags |= INVALIDATED;
3689-
grandParent.mPrivateFlags &= ~DRAWING_CACHE_VALID;
3690-
}
3691-
}
3657+
// Check whether the child that requests the invalidate is fully opaque
3658+
// Views being animated or transformed are not considered opaque because we may
3659+
// be invalidating their old position and need the parent to paint behind them.
3660+
Matrix childMatrix = child.getMatrix();
3661+
final boolean isOpaque = child.isOpaque() && !drawAnimation &&
3662+
child.getAnimation() == null && childMatrix.isIdentity();
3663+
// Mark the child as dirty, using the appropriate flag
3664+
// Make sure we do not set both flags at the same time
3665+
int opaqueFlag = isOpaque ? DIRTY_OPAQUE : DIRTY;
3666+
3667+
if (child.mLayerType != LAYER_TYPE_NONE) {
3668+
mPrivateFlags |= INVALIDATED;
3669+
mPrivateFlags &= ~DRAWING_CACHE_VALID;
3670+
child.mLocalDirtyRect.union(dirty);
3671+
}
36923672

3693-
if (drawAnimation) {
3694-
if (view != null) {
3695-
view.mPrivateFlags |= DRAW_ANIMATION;
3696-
} else if (parent instanceof ViewRootImpl) {
3697-
((ViewRootImpl) parent).mIsAnimating = true;
3698-
}
3673+
final int[] location = attachInfo.mInvalidateChildLocation;
3674+
location[CHILD_LEFT_INDEX] = child.mLeft;
3675+
location[CHILD_TOP_INDEX] = child.mTop;
3676+
if (!childMatrix.isIdentity()) {
3677+
RectF boundingRect = attachInfo.mTmpTransformRect;
3678+
boundingRect.set(dirty);
3679+
//boundingRect.inset(-0.5f, -0.5f);
3680+
childMatrix.mapRect(boundingRect);
3681+
dirty.set((int) (boundingRect.left - 0.5f),
3682+
(int) (boundingRect.top - 0.5f),
3683+
(int) (boundingRect.right + 0.5f),
3684+
(int) (boundingRect.bottom + 0.5f));
3685+
}
3686+
3687+
do {
3688+
View view = null;
3689+
if (parent instanceof View) {
3690+
view = (View) parent;
3691+
if (view.mLayerType != LAYER_TYPE_NONE &&
3692+
view.getParent() instanceof View) {
3693+
final View grandParent = (View) view.getParent();
3694+
grandParent.mPrivateFlags |= INVALIDATED;
3695+
grandParent.mPrivateFlags &= ~DRAWING_CACHE_VALID;
36993696
}
3697+
}
37003698

3701-
// If the parent is dirty opaque or not dirty, mark it dirty with the opaque
3702-
// flag coming from the child that initiated the invalidate
3699+
if (drawAnimation) {
37033700
if (view != null) {
3704-
if ((view.mViewFlags & FADING_EDGE_MASK) != 0 &&
3705-
view.getSolidColor() == 0) {
3706-
opaqueFlag = DIRTY;
3707-
}
3708-
if ((view.mPrivateFlags & DIRTY_MASK) != DIRTY) {
3709-
view.mPrivateFlags = (view.mPrivateFlags & ~DIRTY_MASK) | opaqueFlag;
3710-
}
3701+
view.mPrivateFlags |= DRAW_ANIMATION;
3702+
} else if (parent instanceof ViewRootImpl) {
3703+
((ViewRootImpl) parent).mIsAnimating = true;
37113704
}
3705+
}
37123706

3713-
parent = parent.invalidateChildInParent(location, dirty);
3714-
if (view != null) {
3715-
// Account for transform on current parent
3716-
Matrix m = view.getMatrix();
3717-
if (!m.isIdentity()) {
3718-
RectF boundingRect = attachInfo.mTmpTransformRect;
3719-
boundingRect.set(dirty);
3720-
m.mapRect(boundingRect);
3721-
dirty.set((int) boundingRect.left, (int) boundingRect.top,
3722-
(int) (boundingRect.right + 0.5f),
3723-
(int) (boundingRect.bottom + 0.5f));
3724-
}
3707+
// If the parent is dirty opaque or not dirty, mark it dirty with the opaque
3708+
// flag coming from the child that initiated the invalidate
3709+
if (view != null) {
3710+
if ((view.mViewFlags & FADING_EDGE_MASK) != 0 &&
3711+
view.getSolidColor() == 0) {
3712+
opaqueFlag = DIRTY;
37253713
}
3726-
} while (parent != null);
3727-
}
3714+
if ((view.mPrivateFlags & DIRTY_MASK) != DIRTY) {
3715+
view.mPrivateFlags = (view.mPrivateFlags & ~DIRTY_MASK) | opaqueFlag;
3716+
}
3717+
}
3718+
3719+
parent = parent.invalidateChildInParent(location, dirty);
3720+
if (view != null) {
3721+
// Account for transform on current parent
3722+
Matrix m = view.getMatrix();
3723+
if (!m.isIdentity()) {
3724+
RectF boundingRect = attachInfo.mTmpTransformRect;
3725+
boundingRect.set(dirty);
3726+
m.mapRect(boundingRect);
3727+
dirty.set((int) boundingRect.left, (int) boundingRect.top,
3728+
(int) (boundingRect.right + 0.5f),
3729+
(int) (boundingRect.bottom + 0.5f));
3730+
}
3731+
}
3732+
} while (parent != null);
37283733
}
37293734
}
37303735

0 commit comments

Comments
 (0)