Commit 8dd8d584 authored by Jan Krcal's avatar Jan Krcal Committed by Commit Bot

Revert "[Profiles] Use new colored default avatars for taskbar badges"

This reverts commit 6b7290b3.

Reason for revert: memory regression on Mac (crbug.com/1146299)

Original change's description:
> [Profiles] Use new colored default avatars for taskbar badges
>
> Recently, all logic around profile avatars has been integrated into
> ProfileAttributesEntry::GetAvatarIcon() incl. new features such as
> colored default avatars.
>
> This CL updates code that generates taskbar badges on Windows to
> delegate most of its logic to GetAvatarIcon(). Only the pieces needed
> for obtaining ImageLoadStatus remained in this code.
>
> The only behavioral change is for non-GAIA avatars: high-res /
> 2x windows old avatars are returned instead of low-res avatars. This
> means more downscaling is needed than before. This will be addressed
> by further CLs that will make GetAvatarIcon() respect preferred_size in
> more cases.
>
> Bug: 1122559
> Change-Id: I5eecc7c6647dc78f9ff92d74edb64214a48e8e63
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2514153
> Commit-Queue: Jan Krcal <jkrcal@chromium.org>
> Reviewed-by: David Roger <droger@chromium.org>
> Auto-Submit: Jan Krcal <jkrcal@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#824494}

TBR=droger@chromium.org,jkrcal@chromium.org

Change-Id: I66f7b806a25b910d35b55f02805c4c8216049f55
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1122559, 1146299
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2521118Reviewed-by: default avatarJan Krcal <jkrcal@chromium.org>
Commit-Queue: Jan Krcal <jkrcal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824833}
parent d3d67d64
......@@ -111,11 +111,11 @@ class AvatarMenu :
~AvatarMenu() override;
// Sets |image| to the avatar corresponding to the profile at |profile_path|.
// Returns the image load status.
// For built-in profile avatars, returns the non-high res version. Returns the
// image load status.
static ImageLoadStatus GetImageForMenuButton(
const base::FilePath& profile_path,
gfx::Image* image,
int preferred_size);
gfx::Image* image);
// Opens a Browser with the specified profile in response to the user
// selecting an item. If |always_create| is true then a new window is created
......
......@@ -12,12 +12,12 @@
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "ui/base/resource/resource_bundle.h"
// static
AvatarMenu::ImageLoadStatus AvatarMenu::GetImageForMenuButton(
const base::FilePath& profile_path,
gfx::Image* image,
int preferred_size) {
gfx::Image* image) {
if (!g_browser_process->profile_manager())
return ImageLoadStatus::BROWSER_SHUTTING_DOWN;
ProfileAttributesEntry* entry;
......@@ -28,14 +28,30 @@ AvatarMenu::ImageLoadStatus AvatarMenu::GetImageForMenuButton(
}
ImageLoadStatus status = ImageLoadStatus::LOADED;
// We need to specifically report GAIA images that are not available yet.
if (entry->IsUsingGAIAPicture() && !entry->GetGAIAPicture()) {
// If there is a Gaia image available, try to use that.
if (entry->IsUsingGAIAPicture()) {
// The GetGAIAPicture API call will trigger an async image load from disk if
// it has not been loaded into memory.
const gfx::Image* gaia_image = entry->GetGAIAPicture();
if (gaia_image) {
*image = *gaia_image;
return ImageLoadStatus::LOADED;
}
if (entry->IsGAIAPictureLoaded())
status = ImageLoadStatus::MISSING;
else
status = ImageLoadStatus::LOADING;
}
*image = entry->GetAvatarIcon(preferred_size);
// Otherwise, use the default resource, not the downloaded high-res one.
const size_t icon_index = entry->GetAvatarIconIndex();
const int resource_id =
profiles::GetDefaultAvatarIconResourceIDAtIndex(icon_index);
*image =
ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id);
return status;
}
......@@ -54,9 +54,6 @@
namespace {
#if defined(OS_WIN)
const int kOldAvatarIconWidth = 38;
const int kOldAvatarIconHeight = 31;
// 2x sized versions of the old profile avatar icons.
// TODO(crbug.com/937834): Clean this up.
const int kProfileAvatarIconResources2x[] = {
......@@ -89,6 +86,9 @@ SkBitmap GetSkBitmapCopy(const gfx::Image& image) {
}
#endif // OS_WIN
const int kOldAvatarIconWidth = 38;
const int kOldAvatarIconHeight = 31;
// Determine what the scaled height of the avatar icon should be for a
// specified width, to preserve the aspect ratio.
int GetScaledAvatarHeightForWidth(int width, const gfx::ImageSkia& avatar) {
......@@ -419,15 +419,13 @@ gfx::Image GetAvatarIconForTitleBar(const gfx::Image& image,
#if defined(OS_MAC)
gfx::Image GetAvatarIconForNSMenu(const base::FilePath& profile_path) {
// TODO(crbug.com/857064): Call ProfileAttributesEntry::GetAvatarIcon()
// directly and pass in in larger desired size so that it can be smoothly
// clipped to a circle.
constexpr int kMenuAvatarIconSize = 38;
// Always use the low-res, small default avatars in the menu.
gfx::Image icon;
AvatarMenu::GetImageForMenuButton(profile_path, &icon, kMenuAvatarIconSize);
AvatarMenu::GetImageForMenuButton(profile_path, &icon);
// The image might be too large and need to be resized, e.g. if this is a
// signed-in user using the GAIA profile photo.
constexpr int kMenuAvatarIconSize = 38;
if (icon.Width() > kMenuAvatarIconSize ||
icon.Height() > kMenuAvatarIconSize) {
icon = profiles::GetSizedAvatarIcon(
......@@ -437,6 +435,26 @@ gfx::Image GetAvatarIconForNSMenu(const base::FilePath& profile_path) {
}
#endif
SkBitmap GetAvatarIconAsSquare(const SkBitmap& source_bitmap,
int scale_factor) {
SkBitmap square_bitmap;
if ((source_bitmap.width() == scale_factor * kOldAvatarIconWidth) &&
(source_bitmap.height() == scale_factor * kOldAvatarIconHeight)) {
// If |source_bitmap| matches the old avatar icon dimensions, i.e. it's an
// old avatar icon, shave a couple of columns so the |source_bitmap| is more
// square. So when resized to a square aspect ratio it looks pretty.
gfx::Rect frame(scale_factor * profiles::kAvatarIconSize,
scale_factor * profiles::kAvatarIconSize);
frame.Inset(scale_factor * 2, 0, scale_factor * 2, 0);
source_bitmap.extractSubset(&square_bitmap, gfx::RectToSkIRect(frame));
} else {
// If it's not an old avatar icon, the image should be square.
DCHECK_EQ(source_bitmap.width(), source_bitmap.height());
square_bitmap = source_bitmap;
}
return square_bitmap;
}
// Helper methods for accessing, transforming and drawing avatar icons.
size_t GetDefaultAvatarIconCount() {
return kDefaultAvatarIconsCount;
......@@ -711,30 +729,13 @@ SkBitmap GetWin2xAvatarImage(ProfileAttributesEntry* entry) {
return GetSkBitmapCopy(entry->GetAvatarIcon(IconUtil::kLargeIconSize));
}
SkBitmap GetWin2xAvatarIconAsSquare(const SkBitmap& source_bitmap) {
constexpr int kIconScaleFactor = 2;
if ((source_bitmap.width() != kIconScaleFactor * kOldAvatarIconWidth) ||
(source_bitmap.height() != kIconScaleFactor * kOldAvatarIconHeight)) {
// It's not an old avatar icon, the image should be square.
DCHECK_EQ(source_bitmap.width(), source_bitmap.height());
return source_bitmap;
}
// If |source_bitmap| matches the old avatar icon dimensions, i.e. it's an
// old avatar icon, shave a couple of columns so the |source_bitmap| is more
// square. So when resized to a square aspect ratio it looks pretty.
gfx::Rect frame(gfx::SkIRectToRect(source_bitmap.bounds()));
frame.Inset(/*horizontal=*/kIconScaleFactor * 2, /*vertical=*/0);
SkBitmap cropped_bitmap;
source_bitmap.extractSubset(&cropped_bitmap, gfx::RectToSkIRect(frame));
return cropped_bitmap;
}
SkBitmap GetBadgedWinIconBitmapForAvatar(const SkBitmap& app_icon_bitmap,
const SkBitmap& avatar_bitmap) {
constexpr int kAvatarBitmapScaleFactor = 2;
// TODO(dfried): This function often doesn't actually do the thing it claims
// to. We should probably fix it.
SkBitmap source_bitmap = profiles::GetWin2xAvatarIconAsSquare(avatar_bitmap);
SkBitmap source_bitmap =
profiles::GetAvatarIconAsSquare(avatar_bitmap, kAvatarBitmapScaleFactor);
int avatar_badge_width = kProfileAvatarBadgeSizeWin;
if (app_icon_bitmap.width() != kShortcutIconSizeWin) {
......
......@@ -92,6 +92,10 @@ gfx::Image GetAvatarIconForTitleBar(const gfx::Image& image,
gfx::Image GetAvatarIconForNSMenu(const base::FilePath& profile_path);
#endif
// Returns a bitmap with a couple of columns shaved off so it is more square,
// so that when resized to a square aspect ratio it looks pretty.
SkBitmap GetAvatarIconAsSquare(const SkBitmap& source_bitmap, int scale_factor);
// Gets the number of default avatar icons that exist.
size_t GetDefaultAvatarIconCount();
......@@ -163,10 +167,6 @@ size_t GetRandomAvatarIconIndex(
// Get the 2x avatar image for a ProfileAttributesEntry.
SkBitmap GetWin2xAvatarImage(ProfileAttributesEntry* entry);
// Returns a bitmap with a couple of columns shaved off so it is more square,
// so that when resized to a square aspect ratio it looks pretty.
SkBitmap GetWin2xAvatarIconAsSquare(const SkBitmap& source_bitmap);
// Badges |app_icon_bitmap| with |avatar_bitmap| at the bottom right corner and
// returns the resulting SkBitmap.
SkBitmap GetBadgedWinIconBitmapForAvatar(const SkBitmap& app_icon_bitmap,
......
......@@ -889,10 +889,8 @@ TEST_F(ProfileInfoCacheTest, GetGaiaImageForAvatarMenu) {
// Try to get the GAIA image. For the first time, it triggers an async image
// load from disk. The load status indicates the image is still being loaded.
constexpr int kArbitraryPreferredSize = 96;
EXPECT_EQ(AvatarMenu::ImageLoadStatus::LOADING,
AvatarMenu::GetImageForMenuButton(profile_path, &image_loaded,
kArbitraryPreferredSize));
AvatarMenu::GetImageForMenuButton(profile_path, &image_loaded));
EXPECT_FALSE(gfx::test::AreImagesEqual(gaia_image, image_loaded));
// Wait until the async image load finishes.
......@@ -900,8 +898,7 @@ TEST_F(ProfileInfoCacheTest, GetGaiaImageForAvatarMenu) {
// Since the GAIA image is loaded now, we can get it this time.
EXPECT_EQ(AvatarMenu::ImageLoadStatus::LOADED,
AvatarMenu::GetImageForMenuButton(profile_path, &image_loaded,
kArbitraryPreferredSize));
AvatarMenu::GetImageForMenuButton(profile_path, &image_loaded));
EXPECT_TRUE(gfx::test::AreImagesEqual(gaia_image, image_loaded));
}
#endif
......
......@@ -178,10 +178,8 @@ void DrawTaskbarDecoration(gfx::NativeWindow window, const gfx::Image* image) {
// gfx::Image isn't thread safe.
std::unique_ptr<SkBitmap> bitmap;
if (image) {
// If `image` is an old avatar, then it's guaranteed to by 2x by code in
// ProfileAttributesEntry::GetAvatarIcon().
bitmap.reset(new SkBitmap(
profiles::GetWin2xAvatarIconAsSquare(*image->ToSkBitmap())));
bitmap.reset(
new SkBitmap(profiles::GetAvatarIconAsSquare(*image->ToSkBitmap(), 1)));
}
PostSetOverlayIcon(hwnd, std::move(bitmap), "");
......@@ -206,8 +204,8 @@ void UpdateTaskbarDecoration(Profile* profile, gfx::NativeWindow window) {
// with the default shortcut being pinned, we add the runtime badge for
// safety. See crbug.com/313800.
gfx::Image decoration;
AvatarMenu::ImageLoadStatus status = AvatarMenu::GetImageForMenuButton(
profile->GetPath(), &decoration, kOverlayIconSize);
AvatarMenu::ImageLoadStatus status =
AvatarMenu::GetImageForMenuButton(profile->GetPath(), &decoration);
// If the user is using a Gaia picture and the picture is still being loaded,
// wait until the load finishes. This taskbar decoration will be triggered
......
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