 Chromium Code Reviews
 Chromium Code Reviews Issue 1408063012:
  Replaced GetAppIconForSize with GetAppIconImageFamily.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master-plus
    
  
    Issue 1408063012:
  Replaced GetAppIconForSize with GetAppIconImageFamily.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master-plus| Index: chrome/browser/app_icon_win.cc | 
| diff --git a/chrome/browser/app_icon_win.cc b/chrome/browser/app_icon_win.cc | 
| index 6f1424e4977b5c54e3ad1045be78dc010264c421..7c67d9a8d73aa3022ae2bcd77810139997e6afb5 100644 | 
| --- a/chrome/browser/app_icon_win.cc | 
| +++ b/chrome/browser/app_icon_win.cc | 
| @@ -7,7 +7,9 @@ | 
| #include "chrome/app/chrome_dll_resource.h" | 
| #include "chrome/common/chrome_constants.h" | 
| #include "third_party/skia/include/core/SkBitmap.h" | 
| +#include "ui/gfx/geometry/size.h" | 
| #include "ui/gfx/icon_util.h" | 
| +#include "ui/gfx/image/image_family.h" | 
| #if defined(GOOGLE_CHROME_BUILD) | 
| #include "chrome/installer/util/install_util.h" | 
| @@ -28,6 +30,8 @@ int GetAppIconResourceId() { | 
| } // namespace | 
| HICON GetAppIcon() { | 
| + // TODO(mgiuca): Use GetAppIconForSize instead of LoadIcon, to get correct | 
| + // scaling. (See http://crbug.com/551256) | 
| const int icon_id = GetAppIconResourceId(); | 
| // HICON returned from LoadIcon do not leak and do not have to be destroyed. | 
| return LoadIcon(GetModuleHandle(chrome::kBrowserResourcesDll), | 
| @@ -35,16 +39,43 @@ HICON GetAppIcon() { | 
| } | 
| HICON GetSmallAppIcon() { | 
| + // TODO(mgiuca): Use GetAppIconForSize instead of LoadImage, to get correct | 
| + // scaling. (See http://crbug.com/551256) | 
| const int icon_id = GetAppIconResourceId(); | 
| + gfx::Size size = GetSmallAppIconSize(); | 
| // HICON returned from LoadImage must be released using DestroyIcon. | 
| return static_cast<HICON>(LoadImage( | 
| GetModuleHandle(chrome::kBrowserResourcesDll), MAKEINTRESOURCE(icon_id), | 
| - IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), | 
| - LR_DEFAULTCOLOR | LR_SHARED)); | 
| + IMAGE_ICON, size.width(), size.height(), LR_DEFAULTCOLOR | LR_SHARED)); | 
| } | 
| -scoped_ptr<SkBitmap> GetAppIconForSize(int size) { | 
| +gfx::Size GetAppIconSize() { | 
| + return gfx::Size(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)); | 
| +} | 
| + | 
| +gfx::Size GetSmallAppIconSize() { | 
| + return gfx::Size(GetSystemMetrics(SM_CXSMICON), | 
| + GetSystemMetrics(SM_CYSMICON)); | 
| +} | 
| + | 
| +scoped_ptr<gfx::ImageFamily> GetAppIconImageFamily() { | 
| const int icon_id = GetAppIconResourceId(); | 
| - return IconUtil::CreateSkBitmapFromIconResource( | 
| - GetModuleHandle(chrome::kBrowserResourcesDll), icon_id, size); | 
| + return IconUtil::CreateImageFamilyFromIconResource( | 
| + GetModuleHandle(chrome::kBrowserResourcesDll), icon_id); | 
| +} | 
| + | 
| +scoped_ptr<SkBitmap> GetAppIconForSize(const gfx::Size& size) { | 
| + scoped_ptr<gfx::ImageFamily> family = GetAppIconImageFamily(); | 
| + if (!family) | 
| + return scoped_ptr<SkBitmap>(); | 
| + | 
| + // Note: We could just use the LoadImage function from the Windows API, but | 
| + // that does a *terrible* job scaling images. Therefore, we fetch the original | 
| + // images and do our own high-quality scaling. | 
| + gfx::Image image = family->CreateExact(size); | 
| 
Nico
2015/11/10 07:13:31
gfx::Image can contain several versions of the sam
 
Matt Giuca
2015/11/11 02:36:22
Short answer: no, we don't use gfx::Image scale fa
 | 
| + return make_scoped_ptr(new SkBitmap(image.AsBitmap())); | 
| +} | 
| + | 
| +scoped_ptr<SkBitmap> GetAppIconForSize(int size) { | 
| + return GetAppIconForSize(gfx::Size(size, size)); | 
| } |