Commit 066e9b88 authored by Wei-Yin Chen (陳威尹)'s avatar Wei-Yin Chen (陳威尹) Committed by Commit Bot

Fix memory leak in RoundedCornerImageView

After calling #setImageDrawable(null), the Bitmap is still retained
in the BitmapShader of mPaint. This CL resets the Shader in that case.

Bug: 959886
Change-Id: I995f46940281eedd4160b139e67a5ee4e18b5c34
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1595292
Commit-Queue: Wei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659679}
parent 983ae99f
......@@ -114,6 +114,9 @@ public class RoundedCornerImageView extends ImageView {
mShader = null;
mApplyShader = false;
// Reset shader in Paint to avoid retaining the old Bitmap.
if (mPaint != null) mPaint.setShader(null);
maybeCreateShader();
updateApplyShader();
......@@ -151,8 +154,7 @@ public class RoundedCornerImageView extends ImageView {
*/
private void updateApplyShader() {
Drawable drawable = getDrawable();
if ((drawable == null) || !(drawable instanceof BitmapDrawable) || (mShader == null)
|| (mPaint == null)) {
if (!(drawable instanceof BitmapDrawable) || (mShader == null) || (mPaint == null)) {
// In this state we wouldn't use the shader anyway.
mApplyShader = false;
return;
......@@ -170,8 +172,8 @@ public class RoundedCornerImageView extends ImageView {
boolean drawFill = mFillPaint != null && localRoundedRect != null
&& !(drawable instanceof ColorDrawable);
boolean drawContent = drawable != null && localPaint != null && localRoundedRect != null
&& isSupportedDrawable(drawable);
boolean drawContent =
localPaint != null && localRoundedRect != null && isSupportedDrawable(drawable);
if (drawFill || drawContent) localRoundedRect.resize(getWidth(), getHeight());
......@@ -191,7 +193,9 @@ public class RoundedCornerImageView extends ImageView {
localPaint.setColor(colorDrawable.getColor());
}
if (mShader != null && mApplyShader) {
if (mApplyShader) {
assert mShader != null;
// Apply the matrix to the bitmap shader.
mShader.setLocalMatrix(getImageMatrix());
localPaint.setShader(mShader);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment