Commit 545b39f2 authored by Dana Fried's avatar Dana Fried Committed by Commit Bot

Update profile icon badging for shortcuts and taskbar on Windows, bump icon...

Update profile icon badging for shortcuts and taskbar on Windows, bump icon version to get automatic update.

Use circular profile icon when creating taskbar and desktop shortcut icons.

Image preview (new icons vs. old icons, showing both transparent and non-transparent avatars)
https://drive.google.com/file/d/1smDN3CBvlYWehIjtRwyIRYKax3_1_F3g/view?usp=sharing

R=droger@chromium.org, sky@chromium.org, tbergquist@chromium.org

Bug: 857069
Change-Id: Id41d68a7f6f56583801d6cd112cf4ed7fd3e35bb
Reviewed-on: https://chromium-review.googlesource.com/1185403Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Dana Fried <dfried@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585552}
parent 5c56e082
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "chrome/browser/profiles/profile_avatar_icon_util.h" #include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "skia/ext/image_operations.h" #include "skia/ext/image_operations.h"
#include "skia/ext/platform_canvas.h" #include "skia/ext/platform_canvas.h"
#include "third_party/skia/include/core/SkRRect.h"
#include "ui/gfx/icon_util.h" #include "ui/gfx/icon_util.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/views/win/hwnd_util.h" #include "ui/views/win/hwnd_util.h"
...@@ -23,6 +24,10 @@ namespace chrome { ...@@ -23,6 +24,10 @@ namespace chrome {
namespace { namespace {
constexpr int kOverlayIconSize = 16;
static const SkRRect kOverlayIconClip =
SkRRect::MakeOval(SkRect::MakeWH(kOverlayIconSize, kOverlayIconSize));
// Responsible for invoking TaskbarList::SetOverlayIcon(). The call to // Responsible for invoking TaskbarList::SetOverlayIcon(). The call to
// TaskbarList::SetOverlayIcon() runs a nested run loop that proves // TaskbarList::SetOverlayIcon() runs a nested run loop that proves
// problematic when called on the UI thread. Additionally it seems the call may // problematic when called on the UI thread. Additionally it seems the call may
...@@ -40,10 +45,13 @@ void SetOverlayIcon(HWND hwnd, std::unique_ptr<SkBitmap> bitmap) { ...@@ -40,10 +45,13 @@ void SetOverlayIcon(HWND hwnd, std::unique_ptr<SkBitmap> bitmap) {
base::win::ScopedGDIObject<HICON> icon; base::win::ScopedGDIObject<HICON> icon;
if (bitmap.get()) { if (bitmap.get()) {
DCHECK_GE(bitmap.get()->width(), bitmap.get()->height()); DCHECK_GE(bitmap.get()->width(), bitmap.get()->height());
// Maintain aspect ratio on resize.
const int kOverlayIconSize = 16; // Maintain aspect ratio on resize, but prefer more square.
int resized_height = // (We used to round down here, but rounding up produces nicer results.)
bitmap.get()->height() * kOverlayIconSize / bitmap.get()->width(); const int resized_height =
std::ceilf(kOverlayIconSize * (float{bitmap.get()->height()} /
float{bitmap.get()->width()}));
DCHECK_GE(kOverlayIconSize, resized_height); DCHECK_GE(kOverlayIconSize, resized_height);
// Since the target size is so small, we use our best resizer. // Since the target size is so small, we use our best resizer.
SkBitmap sk_icon = skia::ImageOperations::Resize( SkBitmap sk_icon = skia::ImageOperations::Resize(
...@@ -52,12 +60,21 @@ void SetOverlayIcon(HWND hwnd, std::unique_ptr<SkBitmap> bitmap) { ...@@ -52,12 +60,21 @@ void SetOverlayIcon(HWND hwnd, std::unique_ptr<SkBitmap> bitmap) {
kOverlayIconSize, resized_height); kOverlayIconSize, resized_height);
// Paint the resized icon onto a 16x16 canvas otherwise Windows will badly // Paint the resized icon onto a 16x16 canvas otherwise Windows will badly
// hammer it to 16x16. // hammer it to 16x16. We'll use a circular clip to be consistent with the
// way profile icons are rendered in the profile switcher.
SkBitmap offscreen_bitmap; SkBitmap offscreen_bitmap;
offscreen_bitmap.allocN32Pixels(kOverlayIconSize, kOverlayIconSize); offscreen_bitmap.allocN32Pixels(kOverlayIconSize, kOverlayIconSize);
SkCanvas offscreen_canvas(offscreen_bitmap); SkCanvas offscreen_canvas(offscreen_bitmap);
offscreen_canvas.clear(SK_ColorTRANSPARENT); offscreen_canvas.clear(SK_ColorTRANSPARENT);
offscreen_canvas.drawBitmap(sk_icon, 0, kOverlayIconSize - resized_height); offscreen_canvas.clipRRect(kOverlayIconClip, true);
// Note: the original code used kOverlayIconSize - resized_height, but in
// order to center the icon in the circle clip area, we're going to center
// it in the paintable region instead, rounding up to the closest pixel to
// avoid smearing.
const int y_offset = std::ceilf((kOverlayIconSize - resized_height) / 2.0f);
offscreen_canvas.drawBitmap(sk_icon, 0, y_offset);
icon = IconUtil::CreateHICONFromSkBitmap(offscreen_bitmap); icon = IconUtil::CreateHICONFromSkBitmap(offscreen_bitmap);
if (!icon.is_valid()) if (!icon.is_valid())
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment