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

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 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
« no previous file with comments | « ui/app_list/icon_cache.h ('k') | ui/gfx/image/image_skia_operations.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm>
8
7 #include "base/logging.h" 9 #include "base/logging.h"
8 #include "base/md5.h" 10 #include "base/md5.h"
9 #include "ui/gfx/size.h" 11 #include "ui/gfx/size.h"
10 12
11 namespace { 13 namespace {
12 14
15 // Predicator for sorting ImageSkiaRep by scale factor.
16 bool ImageRepScaleFactorCompare(const gfx::ImageSkiaRep& rep1,
17 const gfx::ImageSkiaRep& rep2) {
18 return rep1.scale_factor() < rep2.scale_factor();
19 }
20
13 // Gets cache key based on |image| contents and desired |size|. 21 // Gets cache key based on |image| contents and desired |size|.
14 std::string GetKey(const SkBitmap& image, const gfx::Size& size) { 22 std::string GetKey(const gfx::ImageSkia& image, const gfx::Size& size) {
15 SkAutoLockPixels image_lock(image); 23 gfx::ImageSkia::ImageSkiaReps image_reps = image.image_reps();
24 DCHECK_GT(image_reps.size(), 0u);
25
26 std::sort(image_reps.begin(), image_reps.end(), &ImageRepScaleFactorCompare);
27
28 base::MD5Context ctx;
29 base::MD5Init(&ctx);
30 for (gfx::ImageSkia::ImageSkiaReps::const_iterator it = image_reps.begin();
31 it != image_reps.end(); ++it) {
32 const SkBitmap& bitmap = it->sk_bitmap();
33 SkAutoLockPixels image_lock(bitmap);
34
35 base::MD5Update(
36 &ctx,
37 base::StringPiece(reinterpret_cast<const char*>(bitmap.getPixels()),
38 bitmap.getSize()));
39 }
40
16 base::MD5Digest digest; 41 base::MD5Digest digest;
17 MD5Sum(image.getPixels(), image.getSize(), &digest); 42 base::MD5Final(&digest, &ctx);
18 43
19 return MD5DigestToBase16(digest) + "." + size.ToString(); 44 return MD5DigestToBase16(digest) + "." + size.ToString();
20 } 45 }
21 46
22 } // namespace 47 } // namespace
23 48
24 namespace app_list { 49 namespace app_list {
25 50
26 // static 51 // static
27 IconCache* IconCache::instance_ = NULL; 52 IconCache* IconCache::instance_ = NULL;
(...skipping 24 matching lines...) Expand all
52 77
53 void IconCache::PurgeAllUnused() { 78 void IconCache::PurgeAllUnused() {
54 for (Cache::iterator i = cache_.begin(); i != cache_.end();) { 79 for (Cache::iterator i = cache_.begin(); i != cache_.end();) {
55 Cache::iterator current(i); 80 Cache::iterator current(i);
56 ++i; 81 ++i;
57 if (!current->second.used) 82 if (!current->second.used)
58 cache_.erase(current); 83 cache_.erase(current);
59 } 84 }
60 } 85 }
61 86
62 bool IconCache::Get(const SkBitmap& src, 87 bool IconCache::Get(const gfx::ImageSkia& src,
63 const gfx::Size& size, 88 const gfx::Size& size,
64 SkBitmap* processed) { 89 gfx::ImageSkia* processed) {
65 Cache::iterator it = cache_.find(GetKey(src, size)); 90 Cache::iterator it = cache_.find(GetKey(src, size));
66 if (it == cache_.end()) 91 if (it == cache_.end())
67 return false; 92 return false;
68 93
69 it->second.used = true; 94 it->second.used = true;
70 95
71 if (processed) 96 if (processed)
72 *processed = it->second.image; 97 *processed = it->second.image;
73 return true; 98 return true;
74 } 99 }
75 100
76 void IconCache::Put(const SkBitmap& src, 101 void IconCache::Put(const gfx::ImageSkia& src,
77 const gfx::Size& size, 102 const gfx::Size& size,
78 const SkBitmap& processed) { 103 const gfx::ImageSkia& processed) {
79 const std::string key = GetKey(src, size); 104 const std::string key = GetKey(src, size);
80 cache_[key].image = processed; 105 cache_[key].image = processed;
81 cache_[key].used = true; 106 cache_[key].used = true;
82 } 107 }
83 108
84 IconCache::IconCache() { 109 IconCache::IconCache() {
85 } 110 }
86 111
87 IconCache::~IconCache() { 112 IconCache::~IconCache() {
88 } 113 }
89 114
90 } // namespace app_list 115 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/icon_cache.h ('k') | ui/gfx/image/image_skia_operations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698