Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/app_list/icon_cache.h" | 5 #include "ui/app_list/icon_cache.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/md5.h" | 8 #include "base/md5.h" |
| 9 #include "ui/gfx/size.h" | 9 #include "ui/gfx/size.h" |
| 10 #include "ui/gfx/screen.h" | |
| 10 | 11 |
| 11 namespace { | 12 namespace { |
| 12 | 13 |
| 13 // Gets cache key based on |image| contents and desired |size|. | 14 // Gets cache key based on |image| contents and desired |size|. |
| 14 std::string GetKey(const SkBitmap& image, const gfx::Size& size) { | 15 std::string GetKey(const gfx::ImageSkia& image, const gfx::Size& size) { |
| 15 SkAutoLockPixels image_lock(image); | 16 ui::ScaleFactor scale_factor = gfx::Screen::IsDIPEnabled() ? |
| 17 ui::SCALE_FACTOR_200P : ui::SCALE_FACTOR_NONE; | |
|
oshima
2012/07/11 23:11:16
I think ui::SCALE_FACTOR_100P is good enough.
xiyuan
2012/07/11 23:21:25
Done.
| |
| 18 const gfx::ImageSkiaRep& image_rep = image.GetRepresentation(scale_factor); | |
| 19 DCHECK(!image_rep.is_null()); | |
| 20 const SkBitmap& bitmap = image_rep.sk_bitmap(); | |
| 21 SkAutoLockPixels image_lock(bitmap); | |
| 16 base::MD5Digest digest; | 22 base::MD5Digest digest; |
| 17 MD5Sum(image.getPixels(), image.getSize(), &digest); | 23 MD5Sum(bitmap.getPixels(), bitmap.getSize(), &digest); |
| 18 | 24 |
| 19 return MD5DigestToBase16(digest) + "." + size.ToString(); | 25 return MD5DigestToBase16(digest) + "." + size.ToString(); |
| 20 } | 26 } |
| 21 | 27 |
| 22 } // namespace | 28 } // namespace |
| 23 | 29 |
| 24 namespace app_list { | 30 namespace app_list { |
| 25 | 31 |
| 26 // static | 32 // static |
| 27 IconCache* IconCache::instance_ = NULL; | 33 IconCache* IconCache::instance_ = NULL; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 52 | 58 |
| 53 void IconCache::PurgeAllUnused() { | 59 void IconCache::PurgeAllUnused() { |
| 54 for (Cache::iterator i = cache_.begin(); i != cache_.end();) { | 60 for (Cache::iterator i = cache_.begin(); i != cache_.end();) { |
| 55 Cache::iterator current(i); | 61 Cache::iterator current(i); |
| 56 ++i; | 62 ++i; |
| 57 if (!current->second.used) | 63 if (!current->second.used) |
| 58 cache_.erase(current); | 64 cache_.erase(current); |
| 59 } | 65 } |
| 60 } | 66 } |
| 61 | 67 |
| 62 bool IconCache::Get(const SkBitmap& src, | 68 bool IconCache::Get(const gfx::ImageSkia& src, |
| 63 const gfx::Size& size, | 69 const gfx::Size& size, |
| 64 SkBitmap* processed) { | 70 gfx::ImageSkia* processed) { |
| 65 Cache::iterator it = cache_.find(GetKey(src, size)); | 71 Cache::iterator it = cache_.find(GetKey(src, size)); |
| 66 if (it == cache_.end()) | 72 if (it == cache_.end()) |
| 67 return false; | 73 return false; |
| 68 | 74 |
| 69 it->second.used = true; | 75 it->second.used = true; |
| 70 | 76 |
| 71 if (processed) | 77 if (processed) |
| 72 *processed = it->second.image; | 78 *processed = it->second.image; |
| 73 return true; | 79 return true; |
| 74 } | 80 } |
| 75 | 81 |
| 76 void IconCache::Put(const SkBitmap& src, | 82 void IconCache::Put(const gfx::ImageSkia& src, |
| 77 const gfx::Size& size, | 83 const gfx::Size& size, |
| 78 const SkBitmap& processed) { | 84 const gfx::ImageSkia& processed) { |
| 79 const std::string key = GetKey(src, size); | 85 const std::string key = GetKey(src, size); |
| 80 cache_[key].image = processed; | 86 cache_[key].image = processed; |
| 81 cache_[key].used = true; | 87 cache_[key].used = true; |
| 82 } | 88 } |
| 83 | 89 |
| 84 IconCache::IconCache() { | 90 IconCache::IconCache() { |
| 85 } | 91 } |
| 86 | 92 |
| 87 IconCache::~IconCache() { | 93 IconCache::~IconCache() { |
| 88 } | 94 } |
| 89 | 95 |
| 90 } // namespace app_list | 96 } // namespace app_list |
| OLD | NEW |