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

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

Issue 2358803007: Refactor LabelButtonAssetBorder to avoid SkArithmeticMode (Closed)
Patch Set: review 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..6c3f3ea7c84076038ec248dc822d0249e0e2710d 100644
--- a/ui/views/controls/button/label_button_border.cc
+++ b/ui/views/controls/button/label_button_border.cc
@@ -139,20 +139,28 @@ 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 =
+ static_cast<uint8_t>(animation->CurrentValueBetween(0, 255));
+
const SkRect sk_rect = gfx::RectToSkRect(rect);
- canvas->sk_canvas()->saveLayer(&sk_rect, NULL);
- state = native_theme_delegate->GetBackgroundThemeState(&extra);
- PaintHelper(this, canvas, state, rect, extra);
+ SkAutoCanvasRestore auto_restore(canvas->sk_canvas(), false);
+ canvas->sk_canvas()->saveLayer(&sk_rect, nullptr);
+
+ {
+ // First, modulate the background by 1 - alpha.
+ SkAutoCanvasRestore auto_restore(canvas->sk_canvas(), false);
+ canvas->sk_canvas()->saveLayerAlpha(&sk_rect, 255 - fg_alpha);
+ state = native_theme_delegate->GetBackgroundThemeState(&extra);
+ PaintHelper(this, canvas, state, rect, extra);
+ }
+ // 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);
- canvas->sk_canvas()->restore();
-
- canvas->sk_canvas()->restore();
} else {
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