Merge change 618 into donut
* changes: Fixes #1816088. Avoid initializing empty Rects when they are useless, especially in Zygote.
This commit is contained in:
@@ -96,11 +96,12 @@ import android.util.TypedValue;
|
|||||||
* and Internationalization</a>.
|
* and Internationalization</a>.
|
||||||
*/
|
*/
|
||||||
public abstract class Drawable {
|
public abstract class Drawable {
|
||||||
|
private static final Rect ZERO_BOUNDS_RECT = new Rect();
|
||||||
|
|
||||||
private int[] mStateSet = StateSet.WILD_CARD;
|
private int[] mStateSet = StateSet.WILD_CARD;
|
||||||
private int mLevel = 0;
|
private int mLevel = 0;
|
||||||
private int mChangingConfigurations = 0;
|
private int mChangingConfigurations = 0;
|
||||||
private Rect mBounds = new Rect();
|
private Rect mBounds = ZERO_BOUNDS_RECT;
|
||||||
/*package*/ Callback mCallback = null;
|
/*package*/ Callback mCallback = null;
|
||||||
private boolean mVisible = true;
|
private boolean mVisible = true;
|
||||||
|
|
||||||
@@ -119,6 +120,10 @@ public abstract class Drawable {
|
|||||||
public void setBounds(int left, int top, int right, int bottom) {
|
public void setBounds(int left, int top, int right, int bottom) {
|
||||||
Rect oldBounds = mBounds;
|
Rect oldBounds = mBounds;
|
||||||
|
|
||||||
|
if (oldBounds == ZERO_BOUNDS_RECT) {
|
||||||
|
oldBounds = mBounds = new Rect();
|
||||||
|
}
|
||||||
|
|
||||||
if (oldBounds.left != left || oldBounds.top != top ||
|
if (oldBounds.left != left || oldBounds.top != top ||
|
||||||
oldBounds.right != right || oldBounds.bottom != bottom) {
|
oldBounds.right != right || oldBounds.bottom != bottom) {
|
||||||
mBounds.set(left, top, right, bottom);
|
mBounds.set(left, top, right, bottom);
|
||||||
@@ -150,7 +155,7 @@ public abstract class Drawable {
|
|||||||
* Return a copy of the drawable's bounds in a new Rect. This returns the
|
* Return a copy of the drawable's bounds in a new Rect. This returns the
|
||||||
* same values as getBounds(), but the returned object is guaranteed to not
|
* same values as getBounds(), but the returned object is guaranteed to not
|
||||||
* be changed later by the drawable (i.e. it retains no reference to this
|
* be changed later by the drawable (i.e. it retains no reference to this
|
||||||
* rect). If the caller already has a Rect allocated, call copyBounds(rect)
|
* rect). If the caller already has a Rect allocated, call copyBounds(rect).
|
||||||
*
|
*
|
||||||
* @return A copy of the drawable's bounds
|
* @return A copy of the drawable's bounds
|
||||||
*/
|
*/
|
||||||
@@ -163,11 +168,21 @@ public abstract class Drawable {
|
|||||||
* object may be the same object stored in the drawable (though this is not
|
* object may be the same object stored in the drawable (though this is not
|
||||||
* guaranteed), so if a persistent copy of the bounds is needed, call
|
* guaranteed), so if a persistent copy of the bounds is needed, call
|
||||||
* copyBounds(rect) instead.
|
* copyBounds(rect) instead.
|
||||||
|
* You should also not change the object returned by this method as it may
|
||||||
|
* be the same object stored in the drawable.
|
||||||
*
|
*
|
||||||
* @return The bounds of the drawable (which may change later, so caller
|
* @return The bounds of the drawable (which may change later, so caller
|
||||||
* beware).
|
* beware). DO NOT ALTER the returned object as it may change the
|
||||||
|
* stored bounds of this drawable.
|
||||||
|
*
|
||||||
|
* @see #copyBounds()
|
||||||
|
* @see #copyBounds(android.graphics.Rect)
|
||||||
*/
|
*/
|
||||||
public final Rect getBounds() {
|
public final Rect getBounds() {
|
||||||
|
if (mBounds == ZERO_BOUNDS_RECT) {
|
||||||
|
mBounds = new Rect();
|
||||||
|
}
|
||||||
|
|
||||||
return mBounds;
|
return mBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user