Commit e9ce3577 authored by Alex Newcomer's avatar Alex Newcomer Committed by Commit Bot

CrOS: Prevent blur from showing during hotseat animations

This disables blur during animations, which improves the performance
of hotseat animations.

Bug: 1031266
Change-Id: I6f0fc2dc4a5a8f552d244ac5bd877761261c6799
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2044766
Commit-Queue: Alex Newcomer <newcomer@chromium.org>
Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Reviewed-by: default avatarManu Cornet <manucornet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740382}
parent 67a0f6c3
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "ash/public/cpp/shelf_config.h" #include "ash/public/cpp/shelf_config.h"
#include "ash/public/cpp/shelf_model.h" #include "ash/public/cpp/shelf_model.h"
#include "ash/public/cpp/wallpaper_controller_observer.h" #include "ash/public/cpp/wallpaper_controller_observer.h"
#include "ash/shelf/hotseat_transition_animator.h"
#include "ash/shelf/scrollable_shelf_view.h" #include "ash/shelf/scrollable_shelf_view.h"
#include "ash/shelf/shelf_layout_manager.h" #include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_navigation_widget.h" #include "ash/shelf/shelf_navigation_widget.h"
...@@ -83,7 +84,8 @@ class HotseatWindowTargeter : public aura::WindowTargeter { ...@@ -83,7 +84,8 @@ class HotseatWindowTargeter : public aura::WindowTargeter {
} // namespace } // namespace
class HotseatWidget::DelegateView : public views::WidgetDelegateView, class HotseatWidget::DelegateView : public HotseatTransitionAnimator::Observer,
public views::WidgetDelegateView,
public WallpaperControllerObserver { public WallpaperControllerObserver {
public: public:
explicit DelegateView(WallpaperControllerImpl* wallpaper_controller) explicit DelegateView(WallpaperControllerImpl* wallpaper_controller)
...@@ -102,9 +104,19 @@ class HotseatWidget::DelegateView : public views::WidgetDelegateView, ...@@ -102,9 +104,19 @@ class HotseatWidget::DelegateView : public views::WidgetDelegateView,
void SetTranslucentBackground(const gfx::Rect& translucent_background_bounds); void SetTranslucentBackground(const gfx::Rect& translucent_background_bounds);
// Sets whether the background should be blurred as requested by the argument,
// unless the feature flag is disabled or |disable_blur_for_animations_| is
// true, in which case this disables background blur.
void SetBackgroundBlur(bool enable_blur);
// Updates the hotseat background when tablet mode changes. // Updates the hotseat background when tablet mode changes.
void OnTabletModeChanged(); void OnTabletModeChanged();
// HotseatTransitionAnimator::Observer:
void OnHotseatTransitionAnimationStarted(HotseatState from_state,
HotseatState to_state) override;
void OnHotseatTransitionAnimationEnded(HotseatState from_state,
HotseatState to_state) override;
// views::WidgetDelegateView: // views::WidgetDelegateView:
bool CanActivate() const override; bool CanActivate() const override;
void ReorderChildLayers(ui::Layer* parent_layer) override; void ReorderChildLayers(ui::Layer* parent_layer) override;
...@@ -116,6 +128,10 @@ class HotseatWidget::DelegateView : public views::WidgetDelegateView, ...@@ -116,6 +128,10 @@ class HotseatWidget::DelegateView : public views::WidgetDelegateView,
focus_cycler_ = focus_cycler; focus_cycler_ = focus_cycler;
} }
int background_blur() const {
return translucent_background_.background_blur();
}
private: private:
void SetParentLayer(ui::Layer* layer); void SetParentLayer(ui::Layer* layer);
...@@ -125,6 +141,8 @@ class HotseatWidget::DelegateView : public views::WidgetDelegateView, ...@@ -125,6 +141,8 @@ class HotseatWidget::DelegateView : public views::WidgetDelegateView,
ScrollableShelfView* scrollable_shelf_view_ = nullptr; // unowned. ScrollableShelfView* scrollable_shelf_view_ = nullptr; // unowned.
// The WallpaperController, responsible for providing proper colors. // The WallpaperController, responsible for providing proper colors.
WallpaperControllerImpl* wallpaper_controller_; WallpaperControllerImpl* wallpaper_controller_;
// Blur is disabled during animations to improve performance.
bool blur_lock_ = false;
// The most recent color that the |translucent_background_| has been animated // The most recent color that the |translucent_background_| has been animated
// to. // to.
...@@ -158,8 +176,7 @@ void HotseatWidget::DelegateView::Init( ...@@ -158,8 +176,7 @@ void HotseatWidget::DelegateView::Init(
void HotseatWidget::DelegateView::UpdateTranslucentBackground() { void HotseatWidget::DelegateView::UpdateTranslucentBackground() {
if (!HotseatWidget::ShouldShowHotseatBackground()) { if (!HotseatWidget::ShouldShowHotseatBackground()) {
translucent_background_.SetVisible(false); translucent_background_.SetVisible(false);
if (features::IsBackgroundBlurEnabled()) SetBackgroundBlur(false);
translucent_background_.SetBackgroundBlur(0);
return; return;
} }
...@@ -172,6 +189,7 @@ void HotseatWidget::DelegateView::SetTranslucentBackground( ...@@ -172,6 +189,7 @@ void HotseatWidget::DelegateView::SetTranslucentBackground(
DCHECK(HotseatWidget::ShouldShowHotseatBackground()); DCHECK(HotseatWidget::ShouldShowHotseatBackground());
translucent_background_.SetVisible(true); translucent_background_.SetVisible(true);
SetBackgroundBlur(/*enable_blur=*/true);
// Animate the bounds change if we're changing the background, or if there's // Animate the bounds change if we're changing the background, or if there's
// a change of width (for instance when dragging an app into, or out of, // a change of width (for instance when dragging an app into, or out of,
...@@ -200,17 +218,36 @@ void HotseatWidget::DelegateView::SetTranslucentBackground( ...@@ -200,17 +218,36 @@ void HotseatWidget::DelegateView::SetTranslucentBackground(
if (translucent_background_.bounds() != background_bounds) if (translucent_background_.bounds() != background_bounds)
translucent_background_.SetBounds(background_bounds); translucent_background_.SetBounds(background_bounds);
}
if (features::IsBackgroundBlurEnabled()) { void HotseatWidget::DelegateView::SetBackgroundBlur(bool enable_blur) {
translucent_background_.SetBackgroundBlur( if (!features::IsBackgroundBlurEnabled() || blur_lock_)
ShelfConfig::Get()->shelf_blur_radius()); return;
}
const int blur_radius =
enable_blur ? ShelfConfig::Get()->shelf_blur_radius() : 0;
if (translucent_background_.background_blur() != blur_radius)
translucent_background_.SetBackgroundBlur(blur_radius);
} }
void HotseatWidget::DelegateView::OnTabletModeChanged() { void HotseatWidget::DelegateView::OnTabletModeChanged() {
UpdateTranslucentBackground(); UpdateTranslucentBackground();
} }
void HotseatWidget::DelegateView::OnHotseatTransitionAnimationStarted(
HotseatState from_state,
HotseatState to_state) {
SetBackgroundBlur(false);
blur_lock_ = true;
}
void HotseatWidget::DelegateView::OnHotseatTransitionAnimationEnded(
HotseatState from_state,
HotseatState to_state) {
blur_lock_ = false;
SetBackgroundBlur(true);
}
bool HotseatWidget::DelegateView::CanActivate() const { bool HotseatWidget::DelegateView::CanActivate() const {
// We don't want mouse clicks to activate us, but we need to allow // We don't want mouse clicks to activate us, but we need to allow
// activation when the user is using the keyboard (FocusCycler). // activation when the user is using the keyboard (FocusCycler).
...@@ -241,6 +278,8 @@ HotseatWidget::HotseatWidget() ...@@ -241,6 +278,8 @@ HotseatWidget::HotseatWidget()
HotseatWidget::~HotseatWidget() { HotseatWidget::~HotseatWidget() {
ShelfConfig::Get()->RemoveObserver(this); ShelfConfig::Get()->RemoveObserver(this);
shelf_->shelf_widget()->hotseat_transition_animator()->RemoveObserver(
delegate_view_);
} }
bool HotseatWidget::ShouldShowHotseatBackground() { bool HotseatWidget::ShouldShowHotseatBackground() {
...@@ -279,6 +318,12 @@ void HotseatWidget::Initialize(aura::Window* container, Shelf* shelf) { ...@@ -279,6 +318,12 @@ void HotseatWidget::Initialize(aura::Window* container, Shelf* shelf) {
delegate_view_->Init(scrollable_shelf_view(), GetLayer()); delegate_view_->Init(scrollable_shelf_view(), GetLayer());
} }
void HotseatWidget::OnHotseatTransitionAnimatorCreated(
HotseatTransitionAnimator* animator) {
shelf_->shelf_widget()->hotseat_transition_animator()->AddObserver(
delegate_view_);
}
void HotseatWidget::OnMouseEvent(ui::MouseEvent* event) { void HotseatWidget::OnMouseEvent(ui::MouseEvent* event) {
if (event->type() == ui::ET_MOUSE_PRESSED) if (event->type() == ui::ET_MOUSE_PRESSED)
keyboard::KeyboardUIController::Get()->HideKeyboardImplicitlyByUser(); keyboard::KeyboardUIController::Get()->HideKeyboardImplicitlyByUser();
...@@ -408,6 +453,10 @@ ShelfView* HotseatWidget::GetShelfView() { ...@@ -408,6 +453,10 @@ ShelfView* HotseatWidget::GetShelfView() {
return shelf_view_; return shelf_view_;
} }
int HotseatWidget::GetHotseatBackgroundBlurForTest() const {
return delegate_view_->background_blur();
}
bool HotseatWidget::IsShowingShelfMenu() const { bool HotseatWidget::IsShowingShelfMenu() const {
return GetShelfView()->IsShowingMenu(); return GetShelfView()->IsShowingMenu();
} }
......
...@@ -21,6 +21,7 @@ class FocusCycler; ...@@ -21,6 +21,7 @@ class FocusCycler;
class ScrollableShelfView; class ScrollableShelfView;
class Shelf; class Shelf;
class ShelfView; class ShelfView;
class HotseatTransitionAnimator;
// The hotseat widget is part of the shelf and hosts app shortcuts. // The hotseat widget is part of the shelf and hosts app shortcuts.
class ASH_EXPORT HotseatWidget : public ShelfComponent, class ASH_EXPORT HotseatWidget : public ShelfComponent,
...@@ -36,6 +37,11 @@ class ASH_EXPORT HotseatWidget : public ShelfComponent, ...@@ -36,6 +37,11 @@ class ASH_EXPORT HotseatWidget : public ShelfComponent,
// Initializes the widget, sets its contents view and basic properties. // Initializes the widget, sets its contents view and basic properties.
void Initialize(aura::Window* container, Shelf* shelf); void Initialize(aura::Window* container, Shelf* shelf);
// Initializes the animation metrics reporter responsible for recording
// animation performance during hotseat state changes, and attaches
// |delegate_view_| as an observer.
void OnHotseatTransitionAnimatorCreated(HotseatTransitionAnimator* animator);
// views::Widget: // views::Widget:
void OnMouseEvent(ui::MouseEvent* event) override; void OnMouseEvent(ui::MouseEvent* event) override;
void OnGestureEvent(ui::GestureEvent* event) override; void OnGestureEvent(ui::GestureEvent* event) override;
...@@ -82,6 +88,9 @@ class ASH_EXPORT HotseatWidget : public ShelfComponent, ...@@ -82,6 +88,9 @@ class ASH_EXPORT HotseatWidget : public ShelfComponent,
ShelfView* GetShelfView(); ShelfView* GetShelfView();
const ShelfView* GetShelfView() const; const ShelfView* GetShelfView() const;
// Returns the background blur of the |translucent_background_| for test.
int GetHotseatBackgroundBlurForTest() const;
void SetState(HotseatState state); void SetState(HotseatState state);
HotseatState state() const { return state_; } HotseatState state() const { return state_; }
......
...@@ -1846,4 +1846,27 @@ TEST_P(HotseatWidgetTest, HotseatRemainsHiddenIfPopupLaunched) { ...@@ -1846,4 +1846,27 @@ TEST_P(HotseatWidgetTest, HotseatRemainsHiddenIfPopupLaunched) {
EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state()); EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
} }
// Tests that blur is not showing during animations.
TEST_P(HotseatWidgetTest, NoBlurDuringAnimations) {
TabletModeControllerTestApi().EnterTabletMode();
ASSERT_EQ(
ShelfConfig::Get()->shelf_blur_radius(),
GetShelfWidget()->hotseat_widget()->GetHotseatBackgroundBlurForTest());
ui::ScopedAnimationDurationScaleMode regular_animations(
ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
// Open a window, as the hotseat animates to kHidden, it should lose its blur.
std::unique_ptr<aura::Window> window =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window.get());
EXPECT_EQ(
0, GetShelfWidget()->hotseat_widget()->GetHotseatBackgroundBlurForTest());
// Wait for the animation to finish, hotseat blur should return.
ShellTestApi().WaitForWindowFinishAnimating(window.get());
EXPECT_EQ(
ShelfConfig::Get()->shelf_blur_radius(),
GetShelfWidget()->hotseat_widget()->GetHotseatBackgroundBlurForTest());
}
} // namespace ash } // namespace ash
...@@ -504,8 +504,8 @@ ScrollableShelfView::~ScrollableShelfView() { ...@@ -504,8 +504,8 @@ ScrollableShelfView::~ScrollableShelfView() {
void ScrollableShelfView::Init() { void ScrollableShelfView::Init() {
// Although there is no animation for ScrollableShelfView, a layer is still // Although there is no animation for ScrollableShelfView, a layer is still
// needed. Otherwise, the child view without its own layer will be painted on // needed. Otherwise, the child view without its own layer will be painted on
// RootView and RootView is beneath |opaque_background_| in ShelfWidget. As a // RootView which is beneath |translucent_background_| in ShelfWidget.
// result, the child view will not show. // As a result, the child view will not show.
SetPaintToLayer(); SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false); layer()->SetFillsBoundsOpaquely(false);
......
...@@ -582,6 +582,8 @@ void ShelfWidget::RegisterHotseatWidget(HotseatWidget* hotseat_widget) { ...@@ -582,6 +582,8 @@ void ShelfWidget::RegisterHotseatWidget(HotseatWidget* hotseat_widget) {
delegate_view_->set_context_menu_controller(hotseat_widget->GetShelfView()); delegate_view_->set_context_menu_controller(hotseat_widget->GetShelfView());
hotseat_transition_animator_.reset(new HotseatTransitionAnimator(this)); hotseat_transition_animator_.reset(new HotseatTransitionAnimator(this));
hotseat_transition_animator_->AddObserver(delegate_view_); hotseat_transition_animator_->AddObserver(delegate_view_);
shelf_->hotseat_widget()->OnHotseatTransitionAnimatorCreated(
hotseat_transition_animator());
} }
void ShelfWidget::OnTabletModeChanged() { void ShelfWidget::OnTabletModeChanged() {
......
...@@ -158,7 +158,7 @@ class ASH_EXPORT ShelfWidget : public AccessibilityObserver, ...@@ -158,7 +158,7 @@ class ASH_EXPORT ShelfWidget : public AccessibilityObserver,
return &background_animator_; return &background_animator_;
} }
HotseatTransitionAnimator* hotseat_transition_animator_for_testing() { HotseatTransitionAnimator* hotseat_transition_animator() {
return hotseat_transition_animator_.get(); return hotseat_transition_animator_.get();
} }
......
...@@ -417,7 +417,7 @@ TEST_F(ShelfWidgetTest, OpaqueBackgroundAndDragHandleTransition) { ...@@ -417,7 +417,7 @@ TEST_F(ShelfWidgetTest, OpaqueBackgroundAndDragHandleTransition) {
{ {
TransitionAnimationWaiter waiter( TransitionAnimationWaiter waiter(
GetShelfWidget()->hotseat_transition_animator_for_testing()); GetShelfWidget()->hotseat_transition_animator());
waiter.Wait(); waiter.Wait();
} }
......
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