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

Side by Side Diff: chrome/browser/ui/views/frame/browser_header_painter_ash.cc

Issue 2717943002: Fix cc/paint skia type mismatches (Closed)
Patch Set: Rebase 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/frame/browser_header_painter_ash.h" 5 #include "chrome/browser/ui/views/frame/browser_header_painter_ash.h"
6 6
7 #include "ash/common/ash_layout_constants.h" 7 #include "ash/common/ash_layout_constants.h"
8 #include "ash/common/frame/caption_buttons/frame_caption_button_container_view.h " 8 #include "ash/common/frame/caption_buttons/frame_caption_button_container_view.h "
9 #include "ash/common/frame/header_painter_util.h" 9 #include "ash/common/frame/header_painter_util.h"
10 #include "ash/resources/vector_icons/vector_icons.h" 10 #include "ash/resources/vector_icons/vector_icons.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 SkPath path; 53 SkPath path;
54 path.addRoundRect(rect, radii, SkPath::kCW_Direction); 54 path.addRoundRect(rect, radii, SkPath::kCW_Direction);
55 return path; 55 return path;
56 } 56 }
57 57
58 // Tiles |frame_image| and |frame_overlay_image| into an area, rounding the top 58 // Tiles |frame_image| and |frame_overlay_image| into an area, rounding the top
59 // corners. 59 // corners.
60 void PaintFrameImagesInRoundRect(gfx::Canvas* canvas, 60 void PaintFrameImagesInRoundRect(gfx::Canvas* canvas,
61 const gfx::ImageSkia& frame_image, 61 const gfx::ImageSkia& frame_image,
62 const gfx::ImageSkia& frame_overlay_image, 62 const gfx::ImageSkia& frame_overlay_image,
63 const SkPaint& paint, 63 const cc::PaintFlags& flags,
64 const gfx::Rect& bounds, 64 const gfx::Rect& bounds,
65 int corner_radius, 65 int corner_radius,
66 int image_inset_x) { 66 int image_inset_x) {
67 SkPath frame_path = MakeRoundRectPath(bounds, corner_radius, corner_radius); 67 SkPath frame_path = MakeRoundRectPath(bounds, corner_radius, corner_radius);
68 // If |paint| is using an unusual SkBlendMode (this is the case while 68 // If |flags| is using an unusual SkBlendMode (this is the case while
69 // crossfading), we must create a new canvas to overlay |frame_image| and 69 // crossfading), we must create a new canvas to overlay |frame_image| and
70 // |frame_overlay_image| using |kSrcOver| and then paint the result 70 // |frame_overlay_image| using |kSrcOver| and then paint the result
71 // using the unusual mode. We try to avoid this because creating a new 71 // using the unusual mode. We try to avoid this because creating a new
72 // browser-width canvas is expensive. 72 // browser-width canvas is expensive.
73 bool fast_path = (frame_overlay_image.isNull() || paint.isSrcOver()); 73 bool fast_path = (frame_overlay_image.isNull() || flags.isSrcOver());
74 if (fast_path) { 74 if (fast_path) {
75 if (frame_image.isNull()) { 75 if (frame_image.isNull()) {
76 canvas->DrawPath(frame_path, paint); 76 canvas->DrawPath(frame_path, flags);
77 } else { 77 } else {
78 canvas->DrawImageInPath(frame_image, -image_inset_x, 0, frame_path, 78 canvas->DrawImageInPath(frame_image, -image_inset_x, 0, frame_path,
79 paint); 79 flags);
80 } 80 }
81 81
82 if (!frame_overlay_image.isNull()) { 82 if (!frame_overlay_image.isNull()) {
83 // Adjust |bounds| such that |frame_overlay_image| is not tiled. 83 // Adjust |bounds| such that |frame_overlay_image| is not tiled.
84 gfx::Rect overlay_bounds = bounds; 84 gfx::Rect overlay_bounds = bounds;
85 overlay_bounds.Intersect( 85 overlay_bounds.Intersect(
86 gfx::Rect(bounds.origin(), frame_overlay_image.size())); 86 gfx::Rect(bounds.origin(), frame_overlay_image.size()));
87 int top_left_corner_radius = corner_radius; 87 int top_left_corner_radius = corner_radius;
88 int top_right_corner_radius = corner_radius; 88 int top_right_corner_radius = corner_radius;
89 if (overlay_bounds.width() < bounds.width() - corner_radius) 89 if (overlay_bounds.width() < bounds.width() - corner_radius)
90 top_right_corner_radius = 0; 90 top_right_corner_radius = 0;
91 canvas->DrawImageInPath( 91 canvas->DrawImageInPath(
92 frame_overlay_image, 0, 0, 92 frame_overlay_image, 0, 0,
93 MakeRoundRectPath(overlay_bounds, top_left_corner_radius, 93 MakeRoundRectPath(overlay_bounds, top_left_corner_radius,
94 top_right_corner_radius), 94 top_right_corner_radius),
95 paint); 95 flags);
96 } 96 }
97 } else { 97 } else {
98 gfx::Canvas temporary_canvas(bounds.size(), canvas->image_scale(), false); 98 gfx::Canvas temporary_canvas(bounds.size(), canvas->image_scale(), false);
99 if (frame_image.isNull()) { 99 if (frame_image.isNull()) {
100 temporary_canvas.DrawColor(paint.getColor()); 100 temporary_canvas.DrawColor(flags.getColor());
101 } else { 101 } else {
102 temporary_canvas.TileImageInt(frame_image, image_inset_x, 0, 0, 0, 102 temporary_canvas.TileImageInt(frame_image, image_inset_x, 0, 0, 0,
103 bounds.width(), bounds.height()); 103 bounds.width(), bounds.height());
104 } 104 }
105 temporary_canvas.DrawImageInt(frame_overlay_image, 0, 0); 105 temporary_canvas.DrawImageInt(frame_overlay_image, 0, 0);
106 canvas->DrawImageInPath(gfx::ImageSkia(temporary_canvas.ExtractImageRep()), 106 canvas->DrawImageInPath(gfx::ImageSkia(temporary_canvas.ExtractImageRep()),
107 0, 0, frame_path, paint); 107 0, 0, frame_path, flags);
108 } 108 }
109 } 109 }
110 110
111 } // namespace 111 } // namespace
112 112
113 /////////////////////////////////////////////////////////////////////////////// 113 ///////////////////////////////////////////////////////////////////////////////
114 // BrowserHeaderPainterAsh, public: 114 // BrowserHeaderPainterAsh, public:
115 115
116 BrowserHeaderPainterAsh::BrowserHeaderPainterAsh() 116 BrowserHeaderPainterAsh::BrowserHeaderPainterAsh()
117 : frame_(nullptr), 117 : frame_(nullptr),
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 if (!active) 253 if (!active)
254 alpha = 0xFF - alpha; 254 alpha = 0xFF - alpha;
255 255
256 if (alpha == 0) 256 if (alpha == 0)
257 return; 257 return;
258 258
259 bool round_corners = !frame_->IsMaximized() && !frame_->IsFullscreen(); 259 bool round_corners = !frame_->IsMaximized() && !frame_->IsFullscreen();
260 gfx::ImageSkia frame_image = view_->GetFrameImage(active); 260 gfx::ImageSkia frame_image = view_->GetFrameImage(active);
261 gfx::ImageSkia frame_overlay_image = view_->GetFrameOverlayImage(active); 261 gfx::ImageSkia frame_overlay_image = view_->GetFrameOverlayImage(active);
262 262
263 SkPaint paint; 263 cc::PaintFlags flags;
264 paint.setBlendMode(SkBlendMode::kPlus); 264 flags.setBlendMode(SkBlendMode::kPlus);
265 paint.setAlpha(alpha); 265 flags.setAlpha(alpha);
266 paint.setColor(SkColorSetA(view_->GetFrameColor(active), alpha)); 266 flags.setColor(SkColorSetA(view_->GetFrameColor(active), alpha));
267 paint.setAntiAlias(round_corners); 267 flags.setAntiAlias(round_corners);
268 PaintFrameImagesInRoundRect( 268 PaintFrameImagesInRoundRect(
269 canvas, frame_image, frame_overlay_image, paint, GetPaintedBounds(), 269 canvas, frame_image, frame_overlay_image, flags, GetPaintedBounds(),
270 round_corners ? ash::HeaderPainterUtil::GetTopCornerRadiusWhenRestored() 270 round_corners ? ash::HeaderPainterUtil::GetTopCornerRadiusWhenRestored()
271 : 0, 271 : 0,
272 ash::HeaderPainterUtil::GetThemeBackgroundXInset()); 272 ash::HeaderPainterUtil::GetThemeBackgroundXInset());
273 } 273 }
274 274
275 void BrowserHeaderPainterAsh::PaintTitleBar(gfx::Canvas* canvas) { 275 void BrowserHeaderPainterAsh::PaintTitleBar(gfx::Canvas* canvas) {
276 // The window icon is painted by its own views::View. 276 // The window icon is painted by its own views::View.
277 gfx::Rect title_bounds = GetTitleBounds(); 277 gfx::Rect title_bounds = GetTitleBounds();
278 title_bounds.set_x(view_->GetMirroredXForRect(title_bounds)); 278 title_bounds.set_x(view_->GetMirroredXForRect(title_bounds));
279 canvas->DrawStringRectWithFlags(frame_->widget_delegate()->GetWindowTitle(), 279 canvas->DrawStringRectWithFlags(frame_->widget_delegate()->GetWindowTitle(),
(...skipping 30 matching lines...) Expand all
310 } 310 }
311 311
312 gfx::Rect BrowserHeaderPainterAsh::GetPaintedBounds() const { 312 gfx::Rect BrowserHeaderPainterAsh::GetPaintedBounds() const {
313 return gfx::Rect(view_->width(), painted_height_); 313 return gfx::Rect(view_->width(), painted_height_);
314 } 314 }
315 315
316 gfx::Rect BrowserHeaderPainterAsh::GetTitleBounds() const { 316 gfx::Rect BrowserHeaderPainterAsh::GetTitleBounds() const {
317 return ash::HeaderPainterUtil::GetTitleBounds(window_icon_, 317 return ash::HeaderPainterUtil::GetTitleBounds(window_icon_,
318 caption_button_container_, BrowserFrame::GetTitleFontList()); 318 caption_button_container_, BrowserFrame::GetTitleFontList());
319 } 319 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698