Commit 1dd58b26 authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

nudges: Paint gradient background on view instead of using mask layer.

The view is quite large, so removing the mask will improve draw times
and use less GPU memory. Also changed the end gradient colour to match
the spec; personally I think using transparent as the end gradient
looked better.

Test: manual
Bug: 1056967
Change-Id: I254e11bca1a85c6bf19a74e8e5e852d00f568f15
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2079687Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745569}
parent e946a56d
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/compositor/layer_animation_observer.h" #include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/paint_recorder.h"
#include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
...@@ -26,8 +25,10 @@ namespace { ...@@ -26,8 +25,10 @@ namespace {
// Width of the contextual nudge. // Width of the contextual nudge.
constexpr int kBackgroundWidth = 160; constexpr int kBackgroundWidth = 160;
// Color of the contextual nudge. // Colors of the contextual nudge background gradient.
constexpr SkColor kBackgroundColor = SkColorSetA(SK_ColorBLACK, 153); // 60% constexpr SkColor kBackgroundStartColor =
SkColorSetA(SK_ColorBLACK, 153); // 60%
constexpr SkColor kBackgroundEndColor = SkColorSetARGB(0, 168, 168, 168);
// Radius of the circle in the middle of the contextual nudge. // Radius of the circle in the middle of the contextual nudge.
constexpr int kCircleRadius = 20; constexpr int kCircleRadius = 20;
...@@ -92,40 +93,6 @@ std::unique_ptr<views::Widget> CreateWidget() { ...@@ -92,40 +93,6 @@ std::unique_ptr<views::Widget> CreateWidget() {
return widget; return widget;
} }
class GradientLayerDelegate : public ui::LayerDelegate {
public:
GradientLayerDelegate() : layer_(ui::LAYER_TEXTURED) {
layer_.set_delegate(this);
layer_.SetFillsBoundsOpaquely(false);
}
~GradientLayerDelegate() override { layer_.set_delegate(nullptr); }
ui::Layer* layer() { return &layer_; }
private:
// ui::LayerDelegate:
void OnPaintLayer(const ui::PaintContext& context) override {
const gfx::Size size = layer()->size();
ui::PaintRecorder recorder(context, size);
cc::PaintFlags flags;
flags.setBlendMode(SkBlendMode::kSrc);
flags.setAntiAlias(false);
flags.setShader(
gfx::CreateGradientShader(gfx::Point(), gfx::Point(size.width(), 0),
SK_ColorBLACK, SK_ColorTRANSPARENT));
recorder.canvas()->DrawRect(gfx::Rect(gfx::Point(), size), flags);
}
void OnDeviceScaleFactorChanged(float old_device_scale_factor,
float new_device_scale_factor) override {}
ui::Layer layer_;
GradientLayerDelegate(const GradientLayerDelegate&) = delete;
GradientLayerDelegate& operator=(const GradientLayerDelegate&) = delete;
};
} // namespace } // namespace
class BackGestureContextualNudge::ContextualNudgeView class BackGestureContextualNudge::ContextualNudgeView
...@@ -133,15 +100,11 @@ class BackGestureContextualNudge::ContextualNudgeView ...@@ -133,15 +100,11 @@ class BackGestureContextualNudge::ContextualNudgeView
public ui::ImplicitAnimationObserver { public ui::ImplicitAnimationObserver {
public: public:
explicit ContextualNudgeView(base::OnceClosure callback) explicit ContextualNudgeView(base::OnceClosure callback)
: suggestion_view_(new SuggestionView(this)), : callback_(std::move(callback)) {
callback_(std::move(callback)) {
SetPaintToLayer(); SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false); layer()->SetFillsBoundsOpaquely(false);
gradient_layer_delegate_ = std::make_unique<GradientLayerDelegate>(); suggestion_view_ = AddChildView(std::make_unique<SuggestionView>(this));
layer()->SetMaskLayer(gradient_layer_delegate_->layer());
AddChildView(suggestion_view_);
show_timer_.Start( show_timer_.Start(
FROM_HERE, kPauseBeforeShowAnimationDuration, this, FROM_HERE, kPauseBeforeShowAnimationDuration, this,
...@@ -308,10 +271,7 @@ class BackGestureContextualNudge::ContextualNudgeView ...@@ -308,10 +271,7 @@ class BackGestureContextualNudge::ContextualNudgeView
// views::View: // views::View:
void Layout() override { void Layout() override {
const gfx::Rect bounds = GetLocalBounds(); gfx::Rect rect = GetLocalBounds();
gradient_layer_delegate_->layer()->SetBounds(bounds);
gfx::Rect rect(bounds);
rect.ClampToCenteredSize(gfx::Size(kBackgroundWidth, kBackgroundWidth)); rect.ClampToCenteredSize(gfx::Size(kBackgroundWidth, kBackgroundWidth));
rect.set_x(-kCircleRadius); rect.set_x(-kCircleRadius);
suggestion_view_->SetBoundsRect(rect); suggestion_view_->SetBoundsRect(rect);
...@@ -320,7 +280,15 @@ class BackGestureContextualNudge::ContextualNudgeView ...@@ -320,7 +280,15 @@ class BackGestureContextualNudge::ContextualNudgeView
// views::View: // views::View:
void OnPaint(gfx::Canvas* canvas) override { void OnPaint(gfx::Canvas* canvas) override {
views::View::OnPaint(canvas); views::View::OnPaint(canvas);
canvas->DrawColor(kBackgroundColor);
// Draw the gradient background.
cc::PaintFlags flags;
flags.setAntiAlias(true);
flags.setStyle(cc::PaintFlags::kFill_Style);
flags.setShader(
gfx::CreateGradientShader(gfx::Point(), gfx::Point(width(), 0),
kBackgroundStartColor, kBackgroundEndColor));
canvas->DrawRect(gfx::Rect(size()), flags);
} }
// ui::ImplicitAnimationObserver: // ui::ImplicitAnimationObserver:
...@@ -341,8 +309,6 @@ class BackGestureContextualNudge::ContextualNudgeView ...@@ -341,8 +309,6 @@ class BackGestureContextualNudge::ContextualNudgeView
} }
} }
std::unique_ptr<GradientLayerDelegate> gradient_layer_delegate_;
// Created by ContextualNudgeView. Owned by views hierarchy. // Created by ContextualNudgeView. Owned by views hierarchy.
SuggestionView* suggestion_view_ = nullptr; SuggestionView* suggestion_view_ = nullptr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment