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

Unified Diff: chrome/browser/ui/views/frame/browser_header_painter_ash.cc

Issue 2770943002: Remove ExtractImageRep from the browser frame header painting code. (Closed)
Patch Set: 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 | ui/gfx/canvas.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/frame/browser_header_painter_ash.cc
diff --git a/chrome/browser/ui/views/frame/browser_header_painter_ash.cc b/chrome/browser/ui/views/frame/browser_header_painter_ash.cc
index ba9f1f342e40bdbed68fecf73dfdd6d75db5a734..fc313242b6fe63b0deb8c391873c73787e8138e1 100644
--- a/chrome/browser/ui/views/frame/browser_header_painter_ash.cc
+++ b/chrome/browser/ui/views/frame/browser_header_painter_ash.cc
@@ -60,52 +60,43 @@ SkPath MakeRoundRectPath(const gfx::Rect& bounds,
void PaintFrameImagesInRoundRect(gfx::Canvas* canvas,
const gfx::ImageSkia& frame_image,
const gfx::ImageSkia& frame_overlay_image,
- const cc::PaintFlags& flags,
+ int alpha,
+ SkColor background_color,
const gfx::Rect& bounds,
int corner_radius,
int image_inset_x) {
SkPath frame_path = MakeRoundRectPath(bounds, corner_radius, corner_radius);
- // If |flags| is using an unusual SkBlendMode (this is the case while
- // crossfading), we must create a new canvas to overlay |frame_image| and
- // |frame_overlay_image| using |kSrcOver| and then paint the result
- // using the unusual mode. We try to avoid this because creating a new
- // browser-width canvas is expensive.
- bool fast_path = (frame_overlay_image.isNull() || flags.isSrcOver());
- if (fast_path) {
- if (frame_image.isNull()) {
- canvas->DrawPath(frame_path, flags);
- } else {
- canvas->DrawImageInPath(frame_image, -image_inset_x, 0, frame_path,
- flags);
- }
+ bool antialias = corner_radius > 0;
- if (!frame_overlay_image.isNull()) {
- // Adjust |bounds| such that |frame_overlay_image| is not tiled.
- gfx::Rect overlay_bounds = bounds;
- overlay_bounds.Intersect(
- gfx::Rect(bounds.origin(), frame_overlay_image.size()));
- int top_left_corner_radius = corner_radius;
- int top_right_corner_radius = corner_radius;
- if (overlay_bounds.width() < bounds.width() - corner_radius)
- top_right_corner_radius = 0;
- canvas->DrawImageInPath(
- frame_overlay_image, 0, 0,
- MakeRoundRectPath(overlay_bounds, top_left_corner_radius,
- top_right_corner_radius),
- flags);
- }
+ canvas->Save();
Peter Kasting 2017/03/22 22:25:57 Nit: Prefer ScopedCanvas to explicit Save()/Restor
danakj 2017/03/22 22:27:47 Oh thanks, I was looking for that.. but I thot it
+ canvas->ClipPath(frame_path, antialias);
+
+ cc::PaintFlags flags;
+ flags.setBlendMode(SkBlendMode::kPlus);
+ flags.setAntiAlias(antialias);
+
+ if (frame_image.isNull() && frame_overlay_image.isNull()) {
+ flags.setColor(background_color);
+ canvas->DrawRect(bounds, flags);
+ } else if (frame_overlay_image.isNull()) {
+ flags.setAlpha(alpha);
+ canvas->DrawImageInt(frame_image, -image_inset_x, 0, flags);
} else {
- gfx::Canvas temporary_canvas(bounds.size(), canvas->image_scale(), false);
+ flags.setAlpha(alpha);
+ canvas->SaveLayerWithFlags(flags);
+
if (frame_image.isNull()) {
- temporary_canvas.DrawColor(flags.getColor());
+ canvas->DrawColor(background_color);
} else {
- temporary_canvas.TileImageInt(frame_image, image_inset_x, 0, 0, 0,
- bounds.width(), bounds.height());
+ canvas->TileImageInt(frame_image, image_inset_x, 0, 0, 0, bounds.width(),
+ bounds.height());
}
- temporary_canvas.DrawImageInt(frame_overlay_image, 0, 0);
- canvas->DrawImageInPath(gfx::ImageSkia(temporary_canvas.ExtractImageRep()),
- 0, 0, frame_path, flags);
+ canvas->DrawImageInt(frame_overlay_image, 0, 0);
+
+ canvas->Restore();
}
+
+ canvas->Restore();
}
} // namespace
@@ -256,19 +247,17 @@ void BrowserHeaderPainterAsh::PaintFrameImages(gfx::Canvas* canvas,
if (alpha == 0)
return;
- bool round_corners = !frame_->IsMaximized() && !frame_->IsFullscreen();
gfx::ImageSkia frame_image = view_->GetFrameImage(active);
gfx::ImageSkia frame_overlay_image = view_->GetFrameOverlayImage(active);
+ SkColor background_color = SkColorSetA(view_->GetFrameColor(active), alpha);
+
+ int corner_radius = 0;
+ if (!frame_->IsMaximized() && !frame_->IsFullscreen())
+ corner_radius = ash::HeaderPainterUtil::GetTopCornerRadiusWhenRestored();
- cc::PaintFlags flags;
- flags.setBlendMode(SkBlendMode::kPlus);
- flags.setAlpha(alpha);
- flags.setColor(SkColorSetA(view_->GetFrameColor(active), alpha));
- flags.setAntiAlias(round_corners);
PaintFrameImagesInRoundRect(
- canvas, frame_image, frame_overlay_image, flags, GetPaintedBounds(),
- round_corners ? ash::HeaderPainterUtil::GetTopCornerRadiusWhenRestored()
- : 0,
+ canvas, frame_image, frame_overlay_image, alpha, background_color,
+ GetPaintedBounds(), corner_radius,
ash::HeaderPainterUtil::GetThemeBackgroundXInset());
}
« no previous file with comments | « no previous file | ui/gfx/canvas.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698