#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include <algorithm>
#include <memory>
#include <string_view>
#include <utility>
#include <vector>
#include "base/feature_list.h"
#include "base/files/file_util.h"
#include "base/format_macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/path_service.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "cc/paint/paint_flags.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/avatar_menu.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/profiles/profile_colors_util.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h"
#include "components/prefs/pref_service.h"
#include "components/signin/public/base/signin_switches.h"
#include "components/vector_icons/vector_icons.h"
#include "skia/ext/image_operations.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkScalar.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_features.h"
#include "ui/base/webui/web_ui_util.h"
#include "ui/color/color_id.h"
#include "ui/color/color_provider_key.h"
#include "ui/color/dynamic_color/palette_factory.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/favicon_size.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/skia_conversions.h"
#include "ui/gfx/image/canvas_image_source.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/native_theme/native_theme.h"
#include "url/url_canon.h"
#if BUILDFLAG(IS_WIN)
#include "base/win/windows_version.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/grit/chrome_unscaled_resources.h"
#include "ui/gfx/icon_util.h"
#endif
#if BUILDFLAG(IS_MAC)
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_manager.h"
#endif
namespace {
constexpr float kIconToneDark = …;
constexpr float kIconToneLight = …;
#if BUILDFLAG(IS_WIN)
const int kOldAvatarIconWidth = 38;
const int kOldAvatarIconHeight = 31;
const int kProfileAvatarIconResources2x[] = {
IDR_PROFILE_AVATAR_2X_0, IDR_PROFILE_AVATAR_2X_1,
IDR_PROFILE_AVATAR_2X_2, IDR_PROFILE_AVATAR_2X_3,
IDR_PROFILE_AVATAR_2X_4, IDR_PROFILE_AVATAR_2X_5,
IDR_PROFILE_AVATAR_2X_6, IDR_PROFILE_AVATAR_2X_7,
IDR_PROFILE_AVATAR_2X_8, IDR_PROFILE_AVATAR_2X_9,
IDR_PROFILE_AVATAR_2X_10, IDR_PROFILE_AVATAR_2X_11,
IDR_PROFILE_AVATAR_2X_12, IDR_PROFILE_AVATAR_2X_13,
IDR_PROFILE_AVATAR_2X_14, IDR_PROFILE_AVATAR_2X_15,
IDR_PROFILE_AVATAR_2X_16, IDR_PROFILE_AVATAR_2X_17,
IDR_PROFILE_AVATAR_2X_18, IDR_PROFILE_AVATAR_2X_19,
IDR_PROFILE_AVATAR_2X_20, IDR_PROFILE_AVATAR_2X_21,
IDR_PROFILE_AVATAR_2X_22, IDR_PROFILE_AVATAR_2X_23,
IDR_PROFILE_AVATAR_2X_24, IDR_PROFILE_AVATAR_2X_25,
IDR_PROFILE_AVATAR_2X_26,
};
SkBitmap GetSkBitmapCopy(const gfx::Image& image) {
DCHECK(!image.IsEmpty());
const SkBitmap* image_bitmap = image.ToSkBitmap();
SkBitmap bitmap_copy;
if (bitmap_copy.tryAllocPixels(image_bitmap->info()))
image_bitmap->readPixels(bitmap_copy.info(), bitmap_copy.getPixels(),
bitmap_copy.rowBytes(), 0, 0);
return bitmap_copy;
}
#endif
int GetScaledAvatarHeightForWidth(int width, const gfx::ImageSkia& avatar) { … }
class AvatarImageSource : public gfx::CanvasImageSource { … };
AvatarImageSource::AvatarImageSource(gfx::ImageSkia avatar,
const gfx::Size& canvas_size,
int width,
AvatarPosition position,
profiles::AvatarShape shape)
: … { … }
AvatarImageSource::AvatarImageSource(gfx::ImageSkia avatar,
const gfx::Size& canvas_size,
int width,
AvatarPosition position)
: … { … }
AvatarImageSource::~AvatarImageSource() { … }
void AvatarImageSource::Draw(gfx::Canvas* canvas) { … }
class ImageWithBackgroundSource : public gfx::CanvasImageSource { … };
const gfx::ImageSkia CreatePaddedIcon(const gfx::VectorIcon& icon,
int size,
SkColor color,
float icon_to_image_ratio) { … }
gfx::Image GetLegacyPlaceholderAvatarIconWithColors(SkColor fill_color,
SkColor stroke_color,
int size) { … }
}
profiles