packages/apps/Gallery2
修订版 | 0bc3fa751f69c81978b7ba28f7de5ddcd1ae1c10 (tree) |
---|---|
时间 | 2010-01-28 09:52:24 |
作者 | Chih-Chung Chang <chihchung@goog...> |
Commiter | Android (Google) Code Review |
Merge "Fix to prevent auto-thumbnailer to run on images whose decoding has failed (causing CPU cycles being wasted resulting in sometimes affecting performance of CPU intensive applications such as the video player)" into eclair
@@ -58,6 +58,7 @@ public class BootReceiver extends BroadcastReceiver { | ||
58 | 58 | PicasaDataSource.sThumbnailCache.close(); |
59 | 59 | CacheService.sAlbumCache.close(); |
60 | 60 | CacheService.sMetaAlbumCache.close(); |
61 | + CacheService.sSkipThumbnailIds.flush(); | |
61 | 62 | } |
62 | 63 | } |
63 | 64 | } |
@@ -57,6 +57,7 @@ public final class CacheService extends IntentService { | ||
57 | 57 | public static final String ACTION_CACHE = "com.cooliris.cache.action.CACHE"; |
58 | 58 | public static final DiskCache sAlbumCache = new DiskCache("local-album-cache"); |
59 | 59 | public static final DiskCache sMetaAlbumCache = new DiskCache("local-meta-cache"); |
60 | + public static final DiskCache sSkipThumbnailIds = new DiskCache("local-skip-cache"); | |
60 | 61 | |
61 | 62 | private static final String TAG = "CacheService"; |
62 | 63 | private static ImageList sList = null; |
@@ -603,14 +604,36 @@ public final class CacheService extends IntentService { | ||
603 | 604 | final long id = ids[i]; |
604 | 605 | final long timeModifiedInSec = timestamp[i]; |
605 | 606 | final long thumbnailId = thumbnailIds[i]; |
606 | - if (!thumbnailCache.isDataAvailable(thumbnailId, timeModifiedInSec * 1000)) { | |
607 | - buildThumbnailForId(context, thumbnailCache, thumbnailId, id, false, DEFAULT_THUMBNAIL_WIDTH, | |
608 | - DEFAULT_THUMBNAIL_HEIGHT, timeModifiedInSec * 1000); | |
607 | + if (!isInThumbnailerSkipList(thumbnailId)) { | |
608 | + if (!thumbnailCache.isDataAvailable(thumbnailId, timeModifiedInSec * 1000)) { | |
609 | + byte[] retVal = buildThumbnailForId(context, thumbnailCache, thumbnailId, id, false, DEFAULT_THUMBNAIL_WIDTH, | |
610 | + DEFAULT_THUMBNAIL_HEIGHT, timeModifiedInSec * 1000); | |
611 | + if (retVal == null || retVal.length == 0) { | |
612 | + // There was an error in building the thumbnail. | |
613 | + // We record this thumbnail id | |
614 | + addToThumbnailerSkipList(thumbnailId); | |
615 | + } | |
616 | + } | |
609 | 617 | } |
610 | 618 | } |
611 | 619 | Log.i(TAG, "DiskCache ready for all thumbnails."); |
612 | 620 | } |
613 | 621 | |
622 | + private static void addToThumbnailerSkipList(long thumbnailId) { | |
623 | + sSkipThumbnailIds.put(thumbnailId, sDummyData, 0); | |
624 | + sSkipThumbnailIds.flush(); | |
625 | + } | |
626 | + | |
627 | + private static boolean isInThumbnailerSkipList(long thumbnailId) { | |
628 | + if (sSkipThumbnailIds.isDataAvailable(thumbnailId, 0)) { | |
629 | + byte[] data = sSkipThumbnailIds.get(thumbnailId, 0); | |
630 | + if (data.length > 0) { | |
631 | + return true; | |
632 | + } | |
633 | + } | |
634 | + return false; | |
635 | + } | |
636 | + | |
614 | 637 | private static final byte[] buildThumbnailForId(final Context context, final DiskCache thumbnailCache, final long thumbId, |
615 | 638 | final long origId, final boolean isVideo, final int thumbnailWidth, final int thumbnailHeight, final long timestamp) { |
616 | 639 | if (origId == Shared.INVALID) { |
@@ -650,7 +673,8 @@ public final class CacheService extends IntentService { | ||
650 | 673 | if (bitmap == null) { |
651 | 674 | return null; |
652 | 675 | } |
653 | - final byte[] retVal = writeBitmapToCache(thumbnailCache, thumbId, origId, bitmap, thumbnailWidth, thumbnailHeight, timestamp); | |
676 | + final byte[] retVal = writeBitmapToCache(thumbnailCache, thumbId, origId, bitmap, thumbnailWidth, thumbnailHeight, | |
677 | + timestamp); | |
654 | 678 | return retVal; |
655 | 679 | } catch (InterruptedException e) { |
656 | 680 | return null; |