Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerBitmapViewHolder.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerBitmapViewHolder.java b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerBitmapViewHolder.java |
| index bd8dba0de3b4683aba1e342f1edd57a12cc7ec72..b43506aeab6ea49799f025addef278f7e8e3b001 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerBitmapViewHolder.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerBitmapViewHolder.java |
| @@ -15,6 +15,9 @@ import java.util.List; |
| */ |
| public class PickerBitmapViewHolder |
| extends ViewHolder implements DecoderServiceHost.ImageDecodedCallback { |
| + // The size (in pixels) of the low-res thumbnails. |
| + private static final int GRAINY_THUMBNAIL_SIZE_PX = 40; |
|
Theresa
2017/05/04 16:53:13
40px on an xxxhdpi is going to be a very different
Finnur
2017/05/05 20:41:45
Good idea. Done.
|
| + |
| // Our parent category. |
| private PickerCategoryView mCategoryView; |
| @@ -41,6 +44,16 @@ public class PickerBitmapViewHolder |
| return; |
| } |
| + if (mCategoryView.getHighResBitmaps().get(filePath) == null) { |
| + mCategoryView.getHighResBitmaps().put(filePath, bitmap); |
| + } |
| + |
| + if (mCategoryView.getLowResBitmaps().get(filePath) == null) { |
| + // Scaling the image down takes between 0-1 ms on average (Nexus 6 phone debug build). |
|
Theresa
2017/05/04 16:53:13
The Nexus 6 is a relatively good device. Did we ta
Finnur
2017/05/05 20:41:45
0-2 ms on my Evercross Svelte device.
|
| + Bitmap lowres = BitmapUtils.scale(bitmap, GRAINY_THUMBNAIL_SIZE_PX, false); |
|
Theresa
2017/05/04 16:53:13
Can this be done on an async background thread rat
Finnur
2017/05/05 20:41:45
Done.
|
| + mCategoryView.getLowResBitmaps().put(filePath, lowres); |
| + } |
| + |
| if (!TextUtils.equals(mBitmapDetails.getFilePath(), filePath)) { |
| return; |
| } |
| @@ -65,11 +78,23 @@ public class PickerBitmapViewHolder |
| return; |
| } |
| - // TODO(finnur): Use cached image, if available. |
| - |
| - mItemView.initialize(mBitmapDetails, null, true); |
| + String filePath = mBitmapDetails.getFilePath(); |
| + Bitmap original = mCategoryView.getHighResBitmaps().get(filePath); |
| + if (original != null) { |
| + mItemView.initialize(mBitmapDetails, original, false); |
| + return; |
| + } |
| int size = mCategoryView.getImageSize(); |
| + Bitmap placeholder = mCategoryView.getLowResBitmaps().get(filePath); |
| + if (placeholder != null) { |
| + // Scaling the image up takes between 3-4 ms on average (Nexus 6 phone debug build). |
| + placeholder = BitmapUtils.scale(placeholder, size, false); |
| + mItemView.initialize(mBitmapDetails, placeholder, true); |
| + } else { |
| + mItemView.initialize(mBitmapDetails, null, true); |
| + } |
| + |
| mCategoryView.getDecoderServiceHost().decodeImage(mBitmapDetails.getFilePath(), size, this); |
| } |