Chromium Code Reviews| Index: chrome/browser/renderer_context_menu/render_view_context_menu.cc |
| diff --git a/chrome/browser/renderer_context_menu/render_view_context_menu.cc b/chrome/browser/renderer_context_menu/render_view_context_menu.cc |
| index e55c14ed5a20f5d9adfa9be68a3a9e107c4471f1..f2c055c6c6c70376b384f5857c77bede1ff179c7 100644 |
| --- a/chrome/browser/renderer_context_menu/render_view_context_menu.cc |
| +++ b/chrome/browser/renderer_context_menu/render_view_context_menu.cc |
| @@ -117,11 +117,8 @@ |
| #include "ui/base/clipboard/clipboard.h" |
| #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| #include "ui/base/l10n/l10n_util.h" |
| -#include "ui/gfx/canvas.h" |
| #include "ui/gfx/favicon_size.h" |
| #include "ui/gfx/geometry/point.h" |
| -#include "ui/gfx/geometry/size.h" |
| -#include "ui/gfx/path.h" |
| #include "ui/gfx/text_elider.h" |
| #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| @@ -442,6 +439,8 @@ bool g_custom_id_ranges_initialized = false; |
| #if !defined(OS_CHROMEOS) |
| void AddAvatarToLastMenuItem(gfx::Image icon, ui::SimpleMenuModel* menu) { |
| + // NOTE: On high dpi this will cause fuzzy output. |
| + const float raster_scale = 1.f; |
| int width = icon.Width(); |
| int height = icon.Height(); |
| @@ -451,19 +450,28 @@ void AddAvatarToLastMenuItem(gfx::Image icon, ui::SimpleMenuModel* menu) { |
| // Profile avatars are supposed to be displayed with a circular mask, so apply |
| // one. |
| - gfx::Path circular_mask; |
| - gfx::Canvas canvas(icon.Size(), 1.0f, true); |
| - canvas.FillRect(gfx::Rect(icon.Size()), SK_ColorTRANSPARENT, |
| - SkBlendMode::kClear); |
| + SkBitmap bitmap; |
| + bitmap.allocN32Pixels(width, height, false /* opaque */); |
| + SkCanvas canvas(bitmap); |
| + |
| + canvas.clear(SK_ColorTRANSPARENT); |
| + |
| + SkPath circular_mask; |
| circular_mask.addCircle(SkIntToScalar(width) / 2, SkIntToScalar(height) / 2, |
| SkIntToScalar(std::min(width, height)) / 2); |
| - canvas.ClipPath(circular_mask, true); |
| - canvas.DrawImageInt(*icon.ToImageSkia(), 0, 0); |
| + canvas.clipPath(circular_mask, true /* antialias */); |
| + |
| + const gfx::ImageSkiaRep& rep = |
| + icon.ToImageSkia()->GetRepresentation(raster_scale); |
|
Peter Kasting
2017/03/22 00:04:15
Rather than used this fixed-scale representation,
|
| + canvas.save(); |
| + canvas.scale(raster_scale / rep.scale(), raster_scale / rep.scale()); |
| + canvas.drawBitmap(rep.sk_bitmap(), 0, 0); |
| + canvas.restore(); |
| gfx::CalculateFaviconTargetSize(&width, &height); |
|
danakj
2017/03/22 14:41:42
I had some trouble understanding if the width/heig
|
| gfx::Image sized_icon = profiles::GetSizedAvatarIcon( |
| - gfx::Image(gfx::ImageSkia(canvas.ExtractImageRep())), true, width, |
| - height); |
| + gfx::Image(gfx::ImageSkia(gfx::ImageSkiaRep(bitmap, raster_scale))), true, |
| + width, height); |
| menu->SetIcon(menu->GetItemCount() - 1, sized_icon); |
| } |
| #endif // !defined(OS_CHROMEOS) |