summaryrefslogtreecommitdiffstats
path: root/core/java/android/view/View.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android/view/View.java')
-rw-r--r--core/java/android/view/View.java47
1 files changed, 28 insertions, 19 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 406fad8..5ed3a7e 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -57,7 +57,6 @@ import com.android.internal.view.menu.MenuBuilder;
import java.util.ArrayList;
import java.util.Arrays;
-import java.lang.ref.SoftReference;
/**
* <p>
@@ -1564,7 +1563,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback {
private int[] mDrawableState = null;
- private SoftReference<Bitmap> mDrawingCache;
+ private Bitmap mDrawingCache;
/**
* When this view has focus and the next focus is {@link #FOCUS_LEFT},
@@ -3951,16 +3950,25 @@ public class View implements Drawable.Callback, KeyEvent.Callback {
}
if ((changed & WILL_NOT_CACHE_DRAWING) != 0) {
- destroyDrawingCache();
+ if (mDrawingCache != null) {
+ mDrawingCache.recycle();
+ }
+ mDrawingCache = null;
}
if ((changed & DRAWING_CACHE_ENABLED) != 0) {
- destroyDrawingCache();
+ if (mDrawingCache != null) {
+ mDrawingCache.recycle();
+ }
+ mDrawingCache = null;
mPrivateFlags &= ~DRAWING_CACHE_VALID;
}
if ((changed & DRAWING_CACHE_QUALITY_MASK) != 0) {
- destroyDrawingCache();
+ if (mDrawingCache != null) {
+ mDrawingCache.recycle();
+ }
+ mDrawingCache = null;
mPrivateFlags &= ~DRAWING_CACHE_VALID;
}
@@ -5407,10 +5415,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback {
if ((mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING) {
return null;
}
- if ((mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED) {
+ if ((mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED &&
+ ((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || mDrawingCache == null)) {
buildDrawingCache();
}
- return mDrawingCache == null ? null : mDrawingCache.get();
+ return mDrawingCache;
}
/**
@@ -5425,8 +5434,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback {
*/
public void destroyDrawingCache() {
if (mDrawingCache != null) {
- final Bitmap bitmap = mDrawingCache.get();
- if (bitmap != null) bitmap.recycle();
+ mDrawingCache.recycle();
mDrawingCache = null;
}
}
@@ -5466,9 +5474,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback {
* @see #destroyDrawingCache()
*/
public void buildDrawingCache() {
- if ((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || mDrawingCache == null ||
- mDrawingCache.get() == null) {
-
+ if ((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || mDrawingCache == null) {
if (ViewDebug.TRACE_HIERARCHY) {
ViewDebug.trace(this, ViewDebug.HierarchyTraceType.BUILD_CACHE);
}
@@ -5486,12 +5492,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback {
if (width <= 0 || height <= 0 ||
(width * height * (opaque ? 2 : 4) >= // Projected bitmap size in bytes
ViewConfiguration.get(mContext).getScaledMaximumDrawingCacheSize())) {
- destroyDrawingCache();
+ if (mDrawingCache != null) {
+ mDrawingCache.recycle();
+ }
+ mDrawingCache = null;
return;
}
boolean clear = true;
- Bitmap bitmap = mDrawingCache == null ? null : mDrawingCache.get();
+ Bitmap bitmap = mDrawingCache;
if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) {
@@ -5516,11 +5525,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback {
}
// Try to cleanup memory
- if (bitmap != null) bitmap.recycle();
+ if (mDrawingCache != null) {
+ mDrawingCache.recycle();
+ }
try {
- bitmap = Bitmap.createBitmap(width, height, quality);
- mDrawingCache = new SoftReference<Bitmap>(bitmap);
+ mDrawingCache = bitmap = Bitmap.createBitmap(width, height, quality);
} catch (OutOfMemoryError e) {
// If there is not enough memory to create the bitmap cache, just
// ignore the issue as bitmap caches are not required to draw the
@@ -8050,8 +8060,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback {
shader = new LinearGradient(0, 0, 0, 1, color, 0, Shader.TileMode.CLAMP);
paint.setShader(shader);
- // Restore the default transfer mode (src_over)
- paint.setXfermode(null);
+ paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
}
}
}