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

Unified Diff: ui/gfx/icon_util.cc

Issue 1424913007: Added ImageFamily::CreateExact, which scales the best image to size. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master-plus
Patch Set: Added test for CreateExact on an non-N32 bitmap. Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: ui/gfx/icon_util.cc
diff --git a/ui/gfx/icon_util.cc b/ui/gfx/icon_util.cc
index f9758d39f67626b02bf8a1f470ff8338452ed793..68ab27922f576668e61079d538dc8f20bafb8bb5 100644
--- a/ui/gfx/icon_util.cc
+++ b/ui/gfx/icon_util.cc
@@ -49,42 +49,28 @@ bool BuildResizedImageFamily(const gfx::ImageFamily& image_family,
DCHECK(resized_image_family);
DCHECK(resized_image_family->empty());
+ // Determine whether there is an image bigger than 48x48 (kMediumIconSize).
+ const gfx::Image* biggest =
+ image_family.GetBest(IconUtil::kLargeIconSize, IconUtil::kLargeIconSize);
+ bool bigger_than_medium = biggest->Width() > IconUtil::kMediumIconSize ||
danakj 2015/11/05 19:03:10 Do you need to worry about biggest being null (or
Matt Giuca 2015/11/06 04:15:18 Yes, good catch. (Actually this was already caught
+ biggest->Height() > IconUtil::kMediumIconSize;
+
for (size_t i = 0; i < IconUtil::kNumIconDimensions; ++i) {
int dimension = IconUtil::kIconDimensions[i];
- gfx::Size size(dimension, dimension);
- const gfx::Image* best = image_family.GetBest(size);
- if (!best || best->IsEmpty()) {
- // Either |image_family| is empty, or all images have size 0x0.
- return false;
- }
-
- // Optimize for the "Large icons" view in Windows Vista+. This view displays
danakj 2015/11/05 19:03:10 Perhaps this comment is worth saving? Or merging i
Matt Giuca 2015/11/06 04:15:18 Done. (Removed the mention of "Windows Vista+", si
- // icons at full size if only if there is a 256x256 (kLargeIconSize) image
- // in the .ico file. Otherwise, it shrinks icons to 48x48 (kMediumIconSize).
- if (dimension > IconUtil::kMediumIconSize &&
- best->Width() <= IconUtil::kMediumIconSize &&
- best->Height() <= IconUtil::kMediumIconSize) {
+ if (!bigger_than_medium && dimension > IconUtil::kMediumIconSize) {
danakj 2015/11/05 19:03:10 nit: bigger_than_medium_exists? makes this read cl
Matt Giuca 2015/11/06 04:15:18 Done (close enough).
// There is no source icon larger than 48x48, so do not create any
// images larger than 48x48. kIconDimensions is sorted in ascending
// order, so it is safe to break here.
break;
}
- if (best->Size() == size) {
- resized_image_family->Add(*best);
- } else {
- // There is no |dimension|x|dimension| source image.
- // Resize this one to the desired size, and insert it.
- SkBitmap best_bitmap = best->AsBitmap();
- // Only kARGB_8888 images are supported.
- // This will also filter out images with no pixels.
- if (best_bitmap.colorType() != kN32_SkColorType)
- return false;
- SkBitmap resized_bitmap = skia::ImageOperations::Resize(
- best_bitmap, skia::ImageOperations::RESIZE_LANCZOS3,
- dimension, dimension);
- resized_image_family->Add(gfx::Image::CreateFrom1xBitmap(resized_bitmap));
+ gfx::Image best = image_family.CreateExact(dimension, dimension);
+ if (best.IsEmpty()) {
danakj 2015/11/05 19:03:10 If you null/empty check biggest above, then would
Matt Giuca 2015/11/06 04:15:18 Not quite -- CreateExact can still fail due to an
+ // Either |image_family| is empty, or all images have size 0x0.
+ return false;
}
+
+ resized_image_family->Add(best);
}
return true;
}

Powered by Google App Engine
This is Rietveld 408576698