Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: ui/app_list/icon_cache.cc

Issue 10699065: chromeos: Fix pixelated icons in app list and launcher (part 1) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, move Resize/CreateDropShadow into ImageSkiaSource Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 10
11 namespace { 11 namespace {
12 12
13 // Gets cache key based on |image| contents and desired |size|. 13 // Gets cache key based on |image| contents and desired |size|.
14 std::string GetKey(const SkBitmap& image, const gfx::Size& size) { 14 std::string GetKey(const gfx::ImageSkia& image, const gfx::Size& size) {
15 SkAutoLockPixels image_lock(image); 15 const SkBitmap* bitmap = image.bitmap();
pkotwicz 2012/07/04 00:19:50 I think you should call GetRepresentation(ui::SCAL
xiyuan 2012/07/10 20:02:13 We will have to call GetRepresentation in ResizeAn
pkotwicz 2012/07/11 00:12:44 I understand now. The code as you have written is
16 SkAutoLockPixels image_lock(*bitmap);
16 base::MD5Digest digest; 17 base::MD5Digest digest;
17 MD5Sum(image.getPixels(), image.getSize(), &digest); 18 MD5Sum(bitmap->getPixels(), bitmap->getSize(), &digest);
18 19
19 return MD5DigestToBase16(digest) + "." + size.ToString(); 20 return MD5DigestToBase16(digest) + "." + size.ToString();
20 } 21 }
21 22
22 } // namespace 23 } // namespace
23 24
24 namespace app_list { 25 namespace app_list {
25 26
26 // static 27 // static
27 IconCache* IconCache::instance_ = NULL; 28 IconCache* IconCache::instance_ = NULL;
(...skipping 24 matching lines...) Expand all
52 53
53 void IconCache::PurgeAllUnused() { 54 void IconCache::PurgeAllUnused() {
54 for (Cache::iterator i = cache_.begin(); i != cache_.end();) { 55 for (Cache::iterator i = cache_.begin(); i != cache_.end();) {
55 Cache::iterator current(i); 56 Cache::iterator current(i);
56 ++i; 57 ++i;
57 if (!current->second.used) 58 if (!current->second.used)
58 cache_.erase(current); 59 cache_.erase(current);
59 } 60 }
60 } 61 }
61 62
62 bool IconCache::Get(const SkBitmap& src, 63 bool IconCache::Get(const gfx::ImageSkia& src,
63 const gfx::Size& size, 64 const gfx::Size& size,
64 SkBitmap* processed) { 65 gfx::ImageSkia* processed) {
65 Cache::iterator it = cache_.find(GetKey(src, size)); 66 Cache::iterator it = cache_.find(GetKey(src, size));
66 if (it == cache_.end()) 67 if (it == cache_.end())
67 return false; 68 return false;
68 69
69 it->second.used = true; 70 it->second.used = true;
70 71
71 if (processed) 72 if (processed)
72 *processed = it->second.image; 73 *processed = it->second.image;
73 return true; 74 return true;
74 } 75 }
75 76
76 void IconCache::Put(const SkBitmap& src, 77 void IconCache::Put(const gfx::ImageSkia& src,
77 const gfx::Size& size, 78 const gfx::Size& size,
78 const SkBitmap& processed) { 79 const gfx::ImageSkia& processed) {
79 const std::string key = GetKey(src, size); 80 const std::string key = GetKey(src, size);
80 cache_[key].image = processed; 81 cache_[key].image = processed;
81 cache_[key].used = true; 82 cache_[key].used = true;
82 } 83 }
83 84
84 IconCache::IconCache() { 85 IconCache::IconCache() {
85 } 86 }
86 87
87 IconCache::~IconCache() { 88 IconCache::~IconCache() {
88 } 89 }
89 90
90 } // namespace app_list 91 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698