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

Side by Side Diff: ui/gfx/image/image_skia.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: 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/gfx/image/image_skia.h" 5 #include "ui/gfx/image/image_skia.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "skia/ext/image_operations.h"
11 #include "ui/gfx/size.h" 12 #include "ui/gfx/size.h"
13 #include "ui/gfx/skbitmap_operations.h"
12 #include "ui/gfx/skia_util.h" 14 #include "ui/gfx/skia_util.h"
13 15
14 namespace gfx { 16 namespace gfx {
15 17
16 namespace internal { 18 namespace internal {
17 19
18 // A helper class such that ImageSkia can be cheaply copied. ImageSkia holds a 20 // A helper class such that ImageSkia can be cheaply copied. ImageSkia holds a
19 // refptr instance of ImageSkiaStorage, which in turn holds all of ImageSkia's 21 // refptr instance of ImageSkiaStorage, which in turn holds all of ImageSkia's
20 // information. 22 // information.
21 class ImageSkiaStorage : public base::RefCounted<ImageSkiaStorage> { 23 class ImageSkiaStorage : public base::RefCounted<ImageSkiaStorage> {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 image.AddRepresentation(ImageSkiaRep(dst_bitmap, 163 image.AddRepresentation(ImageSkiaRep(dst_bitmap,
162 image_rep.scale_factor())); 164 image_rep.scale_factor()));
163 } 165 }
164 if (image.empty()) 166 if (image.empty())
165 return false; 167 return false;
166 168
167 *dst = image; 169 *dst = image;
168 return true; 170 return true;
169 } 171 }
170 172
173 ImageSkia ImageSkia::Resize(const gfx::Size& size) const {
174 DCHECK(!empty());
175
176 if (width() == size.width() && height() == size.height())
177 return *this;
178
179 ImageSkia image;
180 ImageSkiaReps& image_reps = storage_->image_reps();
181 for (ImageSkiaReps::iterator it = image_reps.begin();
182 it != image_reps.end(); ++it) {
183 const ImageSkiaRep& image_rep = *it;
184 float dip_scale = image_rep.GetScale();
185
186 gfx::Size scaled_size(static_cast<int>(size.width() * dip_scale),
187 static_cast<int>(size.height() * dip_scale));
188 SkBitmap resized = skia::ImageOperations::Resize(image_rep.sk_bitmap(),
189 skia::ImageOperations::RESIZE_BEST,
190 scaled_size.width(),
191 scaled_size.height());
192 image.AddRepresentation(ImageSkiaRep(resized, image_rep.scale_factor()));
193 }
194
195 return image;
196 }
197
198 ImageSkia ImageSkia::CreateDropShadow(const gfx::ShadowValues& shadows) const {
199 DCHECK(!empty());
200
201 ImageSkia image;
202 ImageSkiaReps& image_reps = storage_->image_reps();
203 for (ImageSkiaReps::iterator it = image_reps.begin();
204 it != image_reps.end(); ++it) {
205 const ImageSkiaRep& image_rep = *it;
206 float dip_scale = image_rep.GetScale();
207
208 gfx::ShadowValues scaled_shadows;
209 for (size_t i = 0; i < shadows.size(); ++i)
210 scaled_shadows.push_back(shadows[i].GetScaled(dip_scale));
211
212 SkBitmap shadow_image = SkBitmapOperations::CreateDropShadow(
213 image_rep.sk_bitmap(),
214 scaled_shadows);
215 image.AddRepresentation(ImageSkiaRep(shadow_image,
216 image_rep.scale_factor()));
217 }
218
219 return image;
220 }
221
171 std::vector<ImageSkiaRep> ImageSkia::image_reps() const { 222 std::vector<ImageSkiaRep> ImageSkia::image_reps() const {
172 if (isNull()) 223 if (isNull())
173 return std::vector<ImageSkiaRep>(); 224 return std::vector<ImageSkiaRep>();
174 225
175 return storage_->image_reps(); 226 return storage_->image_reps();
176 } 227 }
177 228
178 const SkBitmap* ImageSkia::bitmap() const { 229 const SkBitmap* ImageSkia::bitmap() const {
179 if (isNull()) { 230 if (isNull()) {
180 // Callers expect a ImageSkiaRep even if it is |isNull()|. 231 // Callers expect a ImageSkiaRep even if it is |isNull()|.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 if (diff < smallest_diff) { 268 if (diff < smallest_diff) {
218 closest_iter = it; 269 closest_iter = it;
219 smallest_diff = diff; 270 smallest_diff = diff;
220 } 271 }
221 } 272 }
222 273
223 return closest_iter; 274 return closest_iter;
224 } 275 }
225 276
226 } // namespace gfx 277 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698