diff options
author | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-31 03:39:05 +0000 |
---|---|---|
committer | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-31 03:39:05 +0000 |
commit | 19544b20ba420f75d613c38035140c4c12db0d7f (patch) | |
tree | a85766d2fe79863a198511d08da0ebba947e48e9 /ash/app_list/icon_cache.cc | |
parent | c288ca0597d6259501104da2f804b9359cab86bb (diff) | |
download | chromium_src-19544b20ba420f75d613c38035140c4c12db0d7f.zip chromium_src-19544b20ba420f75d613c38035140c4c12db0d7f.tar.gz chromium_src-19544b20ba420f75d613c38035140c4c12db0d7f.tar.bz2 |
Reland 129925 - ash: Icon cache for app list to save shadow generation time.
- Add an IconCache that stores processed (resized and shadow-generated) image,
keyed by source image + desired size;
- The cache is created with AppList controller and destroyed when controller is
gone;
- Controller marks all entries in cache unused before showing the UI and purges
all unused entry after dismissing UI;
- In item view, try cache first to get processed image before scheduling job,
and update cache when background processing comes back;
BUG=120961
TEST=Verify fix for issue 120961.
Review URL: http://codereview.chromium.org/9934006
TBR=sky@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9968024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130035 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/app_list/icon_cache.cc')
-rw-r--r-- | ash/app_list/icon_cache.cc | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/ash/app_list/icon_cache.cc b/ash/app_list/icon_cache.cc new file mode 100644 index 0000000..92fdd90 --- /dev/null +++ b/ash/app_list/icon_cache.cc @@ -0,0 +1,90 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/app_list/icon_cache.h" + +#include "base/logging.h" +#include "base/md5.h" +#include "ui/gfx/size.h" + +namespace { + +// Gets cache key based on |image| contents and desired |size|. +std::string GetKey(const SkBitmap& image, const gfx::Size& size) { + SkAutoLockPixels image_lock(image); + base::MD5Digest digest; + MD5Sum(image.getPixels(), image.getSize(), &digest); + + return MD5DigestToBase16(digest) + "." + size.ToString(); +} + +} // namespace + +namespace ash { + +// static +IconCache* IconCache::instance_ = NULL; + +// static +void IconCache::CreateInstance() { + DCHECK(!instance_); + instance_ = new IconCache; +} + +// static +void IconCache::DeleteInstance() { + DCHECK(instance_); + delete instance_; + instance_ = NULL; +} + +// static +IconCache* IconCache::GetInstance() { + DCHECK(instance_); + return instance_; +} + +void IconCache::MarkAllEntryUnused() { + for (Cache::iterator i = cache_.begin(); i != cache_.end(); ++i) + i->second.used = false; +} + +void IconCache::PurgeAllUnused() { + for (Cache::iterator i = cache_.begin(); i != cache_.end();) { + Cache::iterator current(i); + ++i; + if (!current->second.used) + cache_.erase(current); + } +} + +bool IconCache::Get(const SkBitmap& src, + const gfx::Size& size, + SkBitmap* processed) { + Cache::iterator it = cache_.find(GetKey(src, size)); + if (it == cache_.end()) + return false; + + it->second.used = true; + + if (processed) + *processed = it->second.image; + return true; +} + +void IconCache::Put(const SkBitmap& src, + const gfx::Size& size, + const SkBitmap& processed) { + const std::string key = GetKey(src, size); + cache_[key].image = processed; + cache_[key].used = true; +} + +IconCache::IconCache() { +} + +IconCache::~IconCache() { +} + +} // namespace ash |