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

Unified Diff: ui/views/controls/button/label_button_border.cc

Issue 2358803007: Refactor LabelButtonAssetBorder to avoid SkArithmeticMode (Closed)
Patch Set: use kPlus xfermode Created 4 years, 3 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: ui/views/controls/button/label_button_border.cc
diff --git a/ui/views/controls/button/label_button_border.cc b/ui/views/controls/button/label_button_border.cc
index e8347bb9c7938f539cc00f0222c1b1b0885eac04..b911faa8ab0a1eab2d410f882c6d8037547cbe43 100644
--- a/ui/views/controls/button/label_button_border.cc
+++ b/ui/views/controls/button/label_button_border.cc
@@ -139,14 +139,22 @@ void LabelButtonAssetBorder::Paint(const View& view, gfx::Canvas* canvas) {
if (animation && animation->is_animating()) {
// Linearly interpolate background and foreground painters during animation.
+ uint8_t fg_alpha =
+ SkToU8(SkScalarRoundToInt(0xff * animation->GetCurrentValue()));
sky 2016/09/29 16:05:17 CurrentValueBetween(0, 255)?
f(malita) 2016/09/29 16:35:28 Done.
+
const SkRect sk_rect = gfx::RectToSkRect(rect);
- canvas->sk_canvas()->saveLayer(&sk_rect, NULL);
+ canvas->sk_canvas()->saveLayer(&sk_rect, nullptr);
+
+ // First, modulate the background by 1 - alpha.
+ canvas->sk_canvas()->saveLayerAlpha(&sk_rect, 0xff - fg_alpha);
state = native_theme_delegate->GetBackgroundThemeState(&extra);
PaintHelper(this, canvas, state, rect, extra);
+ canvas->sk_canvas()->restore();
sky 2016/09/29 16:05:17 All these raw save/restore make me nervous as they
f(malita) 2016/09/29 16:35:28 We have SkAutoCanvasRestore, which restores to the
+ // Then modulate the foreground by alpha, and blend using kPlus_Mode.
SkPaint paint;
- double scale = animation->GetCurrentValue();
- paint.setXfermode(SkArithmeticMode::Make(0.0f, scale, 1.0 - scale, 0.0));
+ paint.setAlpha(fg_alpha);
+ paint.setXfermodeMode(SkXfermode::kPlus_Mode);
canvas->sk_canvas()->saveLayer(&sk_rect, &paint);
state = native_theme_delegate->GetForegroundThemeState(&extra);
PaintHelper(this, canvas, state, rect, extra);
« 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