Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(897)

Unified Diff: chrome/browser/renderer_context_menu/render_view_context_menu.cc

Issue 2767803003: Replace Canvas::ExtractImageRep in render_view_context_menu.cc (Closed)
Patch Set: menu-bitmap: . Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698