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 // TODO(xiyuan): Revisit this after ImageLoadingTracker DIP support is done. |
17 ui::ScaleFactor scale_factor = gfx::Screen::IsDIPEnabled() ? | |
18 ui::SCALE_FACTOR_200P : ui::SCALE_FACTOR_100P; | |
sky
2012/07/16 16:49:39
How come if dip is enabled this always scales by 2
xiyuan
2012/07/16 17:08:02
This is because we have not yet decided what is th
| |
19 const gfx::ImageSkiaRep& image_rep = image.GetRepresentation(scale_factor); | |
20 DCHECK(!image_rep.is_null()); | |
21 const SkBitmap& bitmap = image_rep.sk_bitmap(); | |
22 SkAutoLockPixels image_lock(bitmap); | |
16 base::MD5Digest digest; | 23 base::MD5Digest digest; |
17 MD5Sum(image.getPixels(), image.getSize(), &digest); | 24 MD5Sum(bitmap.getPixels(), bitmap.getSize(), &digest); |
18 | 25 |
19 return MD5DigestToBase16(digest) + "." + size.ToString(); | 26 return MD5DigestToBase16(digest) + "." + size.ToString(); |
20 } | 27 } |
21 | 28 |
22 } // namespace | 29 } // namespace |
23 | 30 |
24 namespace app_list { | 31 namespace app_list { |
25 | 32 |
26 // static | 33 // static |
27 IconCache* IconCache::instance_ = NULL; | 34 IconCache* IconCache::instance_ = NULL; |
(...skipping 24 matching lines...) Expand all Loading... | |
52 | 59 |
53 void IconCache::PurgeAllUnused() { | 60 void IconCache::PurgeAllUnused() { |
54 for (Cache::iterator i = cache_.begin(); i != cache_.end();) { | 61 for (Cache::iterator i = cache_.begin(); i != cache_.end();) { |
55 Cache::iterator current(i); | 62 Cache::iterator current(i); |
56 ++i; | 63 ++i; |
57 if (!current->second.used) | 64 if (!current->second.used) |
58 cache_.erase(current); | 65 cache_.erase(current); |
59 } | 66 } |
60 } | 67 } |
61 | 68 |
62 bool IconCache::Get(const SkBitmap& src, | 69 bool IconCache::Get(const gfx::ImageSkia& src, |
63 const gfx::Size& size, | 70 const gfx::Size& size, |
64 SkBitmap* processed) { | 71 gfx::ImageSkia* processed) { |
65 Cache::iterator it = cache_.find(GetKey(src, size)); | 72 Cache::iterator it = cache_.find(GetKey(src, size)); |
66 if (it == cache_.end()) | 73 if (it == cache_.end()) |
67 return false; | 74 return false; |
68 | 75 |
69 it->second.used = true; | 76 it->second.used = true; |
70 | 77 |
71 if (processed) | 78 if (processed) |
72 *processed = it->second.image; | 79 *processed = it->second.image; |
73 return true; | 80 return true; |
74 } | 81 } |
75 | 82 |
76 void IconCache::Put(const SkBitmap& src, | 83 void IconCache::Put(const gfx::ImageSkia& src, |
77 const gfx::Size& size, | 84 const gfx::Size& size, |
78 const SkBitmap& processed) { | 85 const gfx::ImageSkia& processed) { |
79 const std::string key = GetKey(src, size); | 86 const std::string key = GetKey(src, size); |
80 cache_[key].image = processed; | 87 cache_[key].image = processed; |
81 cache_[key].used = true; | 88 cache_[key].used = true; |
82 } | 89 } |
83 | 90 |
84 IconCache::IconCache() { | 91 IconCache::IconCache() { |
85 } | 92 } |
86 | 93 |
87 IconCache::~IconCache() { | 94 IconCache::~IconCache() { |
88 } | 95 } |
89 | 96 |
90 } // namespace app_list | 97 } // namespace app_list |
OLD | NEW |