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

Side by Side Diff: chrome/browser/icon_loader_chromeos.cc

Issue 10823358: image: Specify the resize-method when resizing ImageSkia. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 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 "chrome/browser/icon_loader.h" 5 #include "chrome/browser/icon_loader.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 // |dip_size| is |kDoNotResize|, returns an unmodified copy of |source|. 150 // |dip_size| is |kDoNotResize|, returns an unmodified copy of |source|.
151 // |source| must be a square image (width == height). 151 // |source| must be a square image (width == height).
152 gfx::ImageSkia ResizeImage(const gfx::ImageSkia& source, int dip_size) { 152 gfx::ImageSkia ResizeImage(const gfx::ImageSkia& source, int dip_size) {
153 DCHECK(!source.isNull()); 153 DCHECK(!source.isNull());
154 DCHECK(source.width() == source.height()); 154 DCHECK(source.width() == source.height());
155 155
156 if (dip_size == kDoNotResize || source.width() == dip_size) 156 if (dip_size == kDoNotResize || source.width() == dip_size)
157 return source; 157 return source;
158 158
159 return gfx::ImageSkiaOperations::CreateResizedImage(source, 159 return gfx::ImageSkiaOperations::CreateResizedImage(source,
160 gfx::Size(dip_size, dip_size)); 160 skia::ImageOperations::RESIZE_BEST, gfx::Size(dip_size, dip_size));
161 } 161 }
162 162
163 int IconSizeToDIPSize(IconLoader::IconSize size) { 163 int IconSizeToDIPSize(IconLoader::IconSize size) {
164 switch (size) { 164 switch (size) {
165 case IconLoader::SMALL: return 16; 165 case IconLoader::SMALL: return 16;
166 case IconLoader::NORMAL: return 32; 166 case IconLoader::NORMAL: return 32;
167 case IconLoader::LARGE: // fallthrough 167 case IconLoader::LARGE: // fallthrough
168 // On ChromeOS, we consider LARGE to mean "the largest image we have." 168 // On ChromeOS, we consider LARGE to mean "the largest image we have."
169 // Since we have already chosen the largest applicable image resource, we 169 // Since we have already chosen the largest applicable image resource, we
170 // return the image as-is. 170 // return the image as-is.
171 case IconLoader::ALL: // fallthrough 171 case IconLoader::ALL: // fallthrough
172 default: 172 default:
173 return kDoNotResize; 173 return kDoNotResize;
174 } 174 }
175 } 175 }
176 176
177 } // namespace 177 } // namespace
178 178
179 void IconLoader::ReadIcon() { 179 void IconLoader::ReadIcon() {
180 static base::LazyInstance<IconMapper>::Leaky icon_mapper = 180 static base::LazyInstance<IconMapper>::Leaky icon_mapper =
181 LAZY_INSTANCE_INITIALIZER; 181 LAZY_INSTANCE_INITIALIZER;
182 int idr = icon_mapper.Get().Lookup(group_, icon_size_); 182 int idr = icon_mapper.Get().Lookup(group_, icon_size_);
183 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 183 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
184 const gfx::ImageSkia* image_skia = rb.GetImageNamed(idr).ToImageSkia(); 184 const gfx::ImageSkia* image_skia = rb.GetImageNamed(idr).ToImageSkia();
185 image_.reset(new gfx::Image( 185 image_.reset(new gfx::Image(
186 ResizeImage(*image_skia, IconSizeToDIPSize(icon_size_)))); 186 ResizeImage(*image_skia, IconSizeToDIPSize(icon_size_))));
187 target_message_loop_->PostTask( 187 target_message_loop_->PostTask(
188 FROM_HERE, base::Bind(&IconLoader::NotifyDelegate, this)); 188 FROM_HERE, base::Bind(&IconLoader::NotifyDelegate, this));
189 } 189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698