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

Unified Diff: ui/gfx/icon_util.cc

Issue 1408063012: Replaced GetAppIconForSize with GetAppIconImageFamily. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master-plus
Patch Set: Split off ImageFamily stuff into CL 1424913007. 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
« chrome/browser/app_icon_win.cc ('K') | « ui/gfx/icon_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/icon_util.cc
diff --git a/ui/gfx/icon_util.cc b/ui/gfx/icon_util.cc
index 68ab27922f576668e61079d538dc8f20bafb8bb5..893b643fdd66b1d0bc7070236d8067a056e2f0af 100644
--- a/ui/gfx/icon_util.cc
+++ b/ui/gfx/icon_util.cc
@@ -231,24 +231,12 @@ SkBitmap* IconUtil::CreateSkBitmapFromHICON(HICON icon, const gfx::Size& s) {
return new SkBitmap(CreateSkBitmapFromHICONHelper(icon, s));
}
-scoped_ptr<SkBitmap> IconUtil::CreateSkBitmapFromIconResource(HMODULE module,
- int resource_id,
- int size) {
- DCHECK_LE(size, kLargeIconSize);
-
- // For everything except the Vista+ 256x256 icons, use |LoadImage()|.
- if (size != kLargeIconSize) {
- HICON icon_handle =
- static_cast<HICON>(LoadImage(module, MAKEINTRESOURCE(resource_id),
- IMAGE_ICON, size, size,
- LR_DEFAULTCOLOR | LR_DEFAULTSIZE));
- scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON(icon_handle));
- DestroyIcon(icon_handle);
- return bitmap.Pass();
- }
-
- // For Vista+ 256x256 PNG icons, read the resource directly and find
- // the corresponding icon entry to get its PNG bytes.
+// static
+scoped_ptr<gfx::ImageFamily> IconUtil::CreateImageFamilyFromIconResource(
+ HMODULE module,
+ int resource_id) {
+ // Read the resource directly so we can get the icon image sizes. This data
+ // will also be used to directly get the PNG bytes for large images.
void* icon_dir_data = NULL;
size_t icon_dir_size = 0;
if (!base::win::GetResourceFromModule(module, resource_id, RT_GROUP_ICON,
@@ -260,31 +248,39 @@ scoped_ptr<SkBitmap> IconUtil::CreateSkBitmapFromIconResource(HMODULE module,
const GRPICONDIR* icon_dir =
reinterpret_cast<const GRPICONDIR*>(icon_dir_data);
- const GRPICONDIRENTRY* large_icon_entry = NULL;
+ scoped_ptr<gfx::ImageFamily> result(new gfx::ImageFamily);
for (size_t i = 0; i < icon_dir->idCount; ++i) {
const GRPICONDIRENTRY* entry = &icon_dir->idEntries[i];
- // 256x256 icons are stored with width and height set to 0.
- // See: http://en.wikipedia.org/wiki/ICO_(file_format)
- if (entry->bWidth == 0 && entry->bHeight == 0) {
- large_icon_entry = entry;
- break;
+ if (entry->bWidth != 0 || entry->bHeight != 0) {
+ // Ignore the low-bit-depth versions of the icon.
+ if (entry->wBitCount != 32)
+ continue;
+
+ // For everything except the Vista+ 256x256 icons, use |LoadImage()|.
+ HICON icon_handle = static_cast<HICON>(LoadImage(
+ module, MAKEINTRESOURCE(resource_id), IMAGE_ICON, entry->bWidth,
+ entry->bHeight, LR_DEFAULTCOLOR | LR_DEFAULTSIZE));
+ scoped_ptr<SkBitmap> bitmap(
+ IconUtil::CreateSkBitmapFromHICON(icon_handle));
+ DestroyIcon(icon_handle);
+ result->Add(gfx::Image::CreateFrom1xBitmap(*bitmap));
+ } else {
+ // 256x256 icons are stored with width and height set to 0.
+ // See: http://en.wikipedia.org/wiki/ICO_(file_format)
+ void* png_data = NULL;
+ size_t png_size = 0;
+ if (!base::win::GetResourceFromModule(module, entry->nID, RT_ICON,
+ &png_data, &png_size)) {
+ return nullptr;
+ }
+ DCHECK(png_data);
+ DCHECK_EQ(png_size, entry->dwBytesInRes);
+
+ result->Add(gfx::Image::CreateFrom1xPNGBytes(
+ new base::RefCountedStaticMemory(png_data, png_size)));
}
}
- if (!large_icon_entry)
- return nullptr;
-
- void* png_data = NULL;
- size_t png_size = 0;
- if (!base::win::GetResourceFromModule(module, large_icon_entry->nID, RT_ICON,
- &png_data, &png_size)) {
- return nullptr;
- }
- DCHECK(png_data);
- DCHECK_EQ(png_size, large_icon_entry->dwBytesInRes);
-
- gfx::Image image = gfx::Image::CreateFrom1xPNGBytes(
- new base::RefCountedStaticMemory(png_data, png_size));
- return make_scoped_ptr(new SkBitmap(image.AsBitmap()));
+ return result;
}
SkBitmap* IconUtil::CreateSkBitmapFromHICON(HICON icon) {
« chrome/browser/app_icon_win.cc ('K') | « ui/gfx/icon_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698