Commit 43afaff3 authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

Tray bubble animation improvements

FPS on arm+hires is now ~60fps even with bg blur (w/o notifications)

* Use layer clip during animation
* Remove unnecessary background paint
* Fine tune layer structures: Remove unnecessary texture layer,
  and use smaller layer, or change so that it require less
  repainting.

Refactoring:
* Consolidate the shield/blur/rounded code into TrayBubbleView.
* Introduce layer type to buggle dialog delegate.

Fix:
* Looks like we were painting bg twice which made blur darker.
  It happens once in TrayBubbleView's layer.

Bug: 1033986
Test: no functional change.

Change-Id: I6b31513b04c55c851e468f621b2d18a3183abd56
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1963234Reviewed-by: default avatarTim Song <tengs@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#724822}
parent 13d672ea
......@@ -4,7 +4,6 @@
#include "ash/system/accessibility/autoclick_menu_bubble_controller.h"
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
......@@ -225,15 +224,16 @@ void AutoclickMenuBubbleController::ShowBubble(AutoclickEventType type,
init_params.max_width = kAutoclickMenuWidth;
init_params.corner_radius = kUnifiedTrayCornerRadius;
init_params.has_shadow = false;
init_params.translucent = true;
bubble_view_ = new AutoclickMenuBubbleView(init_params);
menu_view_ = new AutoclickMenuView(type, position);
menu_view_->SetBackground(UnifiedSystemTrayView::CreateBackground());
menu_view_->SetBorder(
views::CreateEmptyBorder(kUnifiedTopShortcutSpacing, 0, 0, 0));
bubble_view_->AddChildView(menu_view_);
bubble_view_->set_color(SK_ColorTRANSPARENT);
bubble_view_->layer()->SetFillsBoundsOpaquely(false);
menu_view_->SetPaintToLayer();
menu_view_->layer()->SetFillsBoundsOpaquely(false);
bubble_widget_ = views::BubbleDialogDelegateView::CreateBubble(bubble_view_);
TrayBackgroundView::InitializeBubbleAnimations(bubble_widget_);
......@@ -242,11 +242,6 @@ void AutoclickMenuBubbleController::ShowBubble(AutoclickEventType type,
CollisionDetectionUtils::RelativePriority::kAutomaticClicksMenu);
bubble_view_->InitializeAndShowBubble();
if (features::IsBackgroundBlurEnabled()) {
bubble_widget_->client_view()->layer()->SetBackgroundBlur(
kUnifiedMenuBackgroundBlur);
}
SetPosition(position);
}
......
......@@ -4,7 +4,6 @@
#include "ash/system/accessibility/autoclick_scroll_bubble_controller.h"
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
......@@ -200,16 +199,16 @@ void AutoclickScrollBubbleController::ShowBubble(
init_params.max_height = kAutoclickScrollMenuSizeDips;
init_params.corner_radius = kUnifiedTrayCornerRadius;
init_params.has_shadow = false;
init_params.translucent = true;
bubble_view_ = new AutoclickScrollBubbleView(init_params);
bubble_view_->SetArrow(alignment);
scroll_view_ = new AutoclickScrollView();
scroll_view_->SetBackground(UnifiedSystemTrayView::CreateBackground());
scroll_view_->SetBorder(
views::CreateEmptyBorder(kUnifiedTopShortcutSpacing, 0, 0, 0));
bubble_view_->AddChildView(scroll_view_);
bubble_view_->set_color(SK_ColorTRANSPARENT);
bubble_view_->layer()->SetFillsBoundsOpaquely(false);
scroll_view_->SetPaintToLayer();
scroll_view_->layer()->SetFillsBoundsOpaquely(false);
bubble_widget_ = views::BubbleDialogDelegateView::CreateBubble(bubble_view_);
TrayBackgroundView::InitializeBubbleAnimations(bubble_widget_);
......@@ -217,11 +216,6 @@ void AutoclickScrollBubbleController::ShowBubble(
bubble_widget_->GetNativeWindow(),
CollisionDetectionUtils::RelativePriority::kAutomaticClicksScrollMenu);
bubble_view_->InitializeAndShowBubble();
if (features::IsBackgroundBlurEnabled()) {
bubble_widget_->client_view()->layer()->SetBackgroundBlur(
kUnifiedMenuBackgroundBlur);
}
}
void AutoclickScrollBubbleController::CloseBubble() {
......
......@@ -8,6 +8,8 @@
#include <numeric>
#include "ash/public/cpp/ash_features.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/unified/unified_system_tray_view.h"
#include "base/macros.h"
#include "base/numerics/ranges.h"
#include "third_party/skia/include/core/SkCanvas.h"
......@@ -237,7 +239,20 @@ TrayBubbleView::TrayBubbleView(const InitParams& init_params)
set_notify_enter_exit_on_child(true);
set_close_on_deactivate(init_params.close_on_deactivate);
set_margins(gfx::Insets());
SetPaintToLayer();
if (init_params.translucent) {
// The following code will not work with bubble's shadow.
DCHECK(!init_params.has_shadow);
SetPaintToLayer(ui::LAYER_SOLID_COLOR);
layer()->SetRoundedCornerRadius(
gfx::RoundedCornersF{kUnifiedTrayCornerRadius});
layer()->SetColor(UnifiedSystemTrayView::GetBackgroundColor());
layer()->SetFillsBoundsOpaquely(false);
layer()->SetIsFastRoundedCorner(true);
if (features::IsBackgroundBlurEnabled())
layer()->SetBackgroundBlur(kUnifiedMenuBackgroundBlur);
}
auto layout = std::make_unique<BottomAlignedBoxLayout>(this);
layout->SetDefaultFlex(1);
......@@ -266,10 +281,6 @@ bool TrayBubbleView::IsATrayBubbleOpen() {
}
void TrayBubbleView::InitializeAndShowBubble() {
int radius = bubble_border_->corner_radius();
layer()->parent()->SetRoundedCornerRadius({radius, radius, radius, radius});
layer()->parent()->SetIsFastRoundedCorner(true);
GetWidget()->Show();
UpdateBubble();
......@@ -384,6 +395,12 @@ void TrayBubbleView::OnWidgetActivationChanged(Widget* widget, bool active) {
BubbleDialogDelegateView::OnWidgetActivationChanged(widget, active);
}
ui::LayerType TrayBubbleView::GetLayerType() const {
if (params_.translucent)
return ui::LAYER_NOT_DRAWN;
return ui::LAYER_TEXTURED;
}
NonClientFrameView* TrayBubbleView::CreateNonClientFrameView(Widget* widget) {
BubbleFrameView* frame = static_cast<BubbleFrameView*>(
BubbleDialogDelegateView::CreateNonClientFrameView(widget));
......@@ -470,14 +487,6 @@ void TrayBubbleView::ChildPreferredSizeChanged(View* child) {
SizeToContents();
}
void TrayBubbleView::ViewHierarchyChanged(
const views::ViewHierarchyChangedDetails& details) {
if (details.is_add && details.child == this) {
details.parent->SetPaintToLayer();
details.parent->layer()->SetMasksToBounds(true);
}
}
void TrayBubbleView::SetBubbleBorderInsets(gfx::Insets insets) {
bubble_border_->set_insets(insets);
}
......
......@@ -95,6 +95,8 @@ class ASH_EXPORT TrayBubbleView : public views::BubbleDialogDelegateView,
base::Optional<int> corner_radius;
base::Optional<gfx::Insets> insets;
bool has_shadow = true;
// Use half opaque widget instead of fully opaque.
bool translucent = false;
};
explicit TrayBubbleView(const InitParams& init_params);
......@@ -160,6 +162,7 @@ class ASH_EXPORT TrayBubbleView : public views::BubbleDialogDelegateView,
views::Widget* bubble_widget) const override;
void OnWidgetClosing(views::Widget* widget) override;
void OnWidgetActivationChanged(views::Widget* widget, bool active) override;
ui::LayerType GetLayerType() const override;
// Overridden from views::View.
gfx::Size CalculatePreferredSize() const override;
......@@ -179,8 +182,6 @@ class ASH_EXPORT TrayBubbleView : public views::BubbleDialogDelegateView,
// Overridden from views::View.
void ChildPreferredSizeChanged(View* child) override;
void ViewHierarchyChanged(
const views::ViewHierarchyChangedDetails& details) override;
// Changes the insets from the bubble border. These were initially set using
// the InitParams.insets, but may need to be reset programmatically.
......
......@@ -169,11 +169,11 @@ PageIndicatorView::PageIndicatorView(UnifiedSystemTrayController* controller,
expanded_amount_(initially_expanded ? 1 : 0),
buttons_container_(new views::View) {
SetVisible(initially_expanded);
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
buttons_container_->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal, gfx::Insets()));
buttons_container_->SetPaintToLayer();
buttons_container_->layer()->SetFillsBoundsOpaquely(false);
AddChildView(buttons_container_);
......@@ -209,9 +209,11 @@ void PageIndicatorView::SetExpandedAmount(double expanded_amount) {
DCHECK(0.0 <= expanded_amount && expanded_amount <= 1.0);
SetVisible(expanded_amount > 0.0);
expanded_amount_ = expanded_amount;
InvalidateLayout();
// TODO(amehfooz): Confirm animation curve with UX.
layer()->SetOpacity(std::max(0., 6 * expanded_amount_ - 5.));
buttons_container_->layer()->SetOpacity(
std::max(0., 6 * expanded_amount_ - 5.));
if (CalculatePreferredSize() != size())
InvalidateLayout();
}
int PageIndicatorView::GetExpandedHeight() {
......
......@@ -4,7 +4,6 @@
#include "ash/system/unified/unified_slider_bubble_controller.h"
#include "ash/public/cpp/ash_features.h"
#include "ash/root_window_controller.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shelf/shelf.h"
......@@ -34,7 +33,6 @@ bool IsAnyMainBubbleShown() {
}
void ConfigureSliderViewStyle(views::View* slider_view) {
slider_view->SetBackground(UnifiedSystemTrayView::CreateBackground());
slider_view->SetBorder(views::CreateEmptyBorder(kUnifiedSliderBubblePadding));
}
......@@ -172,25 +170,19 @@ void UnifiedSliderBubbleController::ShowBubble(SliderType slider_type) {
kUnifiedMenuPadding - (base::i18n::IsRTL() ? 0 : 1));
init_params.corner_radius = kUnifiedTrayCornerRadius;
init_params.has_shadow = false;
init_params.translucent = true;
bubble_view_ = new TrayBubbleView(init_params);
UnifiedSliderView* slider_view =
static_cast<UnifiedSliderView*>(slider_controller_->CreateView());
ConfigureSliderViewStyle(slider_view);
bubble_view_->AddChildView(slider_view);
bubble_view_->set_color(SK_ColorTRANSPARENT);
bubble_view_->layer()->SetFillsBoundsOpaquely(false);
bubble_widget_ = views::BubbleDialogDelegateView::CreateBubble(bubble_view_);
TrayBackgroundView::InitializeBubbleAnimations(bubble_widget_);
bubble_view_->InitializeAndShowBubble();
if (features::IsBackgroundBlurEnabled()) {
bubble_widget_->client_view()->layer()->SetBackgroundBlur(
kUnifiedMenuBackgroundBlur);
}
// Notify value change accessibility event because the popup is triggered by
// changing value using an accessor key like VolUp.
slider_view->slider()->NotifyAccessibilityEvent(
......
......@@ -148,6 +148,9 @@ UnifiedSliderView::UnifiedSliderView(UnifiedSliderListener* listener,
layout->SetFlexForView(slider_, 1);
layout->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kCenter);
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
}
void UnifiedSliderView::SetSliderValue(float value, bool by_user) {
......
......@@ -93,6 +93,7 @@ UnifiedSystemTrayBubble::UnifiedSystemTrayBubble(UnifiedSystemTray* tray,
init_params.has_shadow = false;
init_params.show_by_click = show_by_click;
init_params.close_on_deactivate = false;
init_params.translucent = true;
bubble_view_ = new TrayBubbleView(init_params);
......@@ -105,20 +106,12 @@ UnifiedSystemTrayBubble::UnifiedSystemTrayBubble(UnifiedSystemTray* tray,
controller_->ResetToCollapsedIfRequired();
bubble_view_->AddChildView(new ContainerView(unified_view_));
bubble_view_->set_color(SK_ColorTRANSPARENT);
bubble_view_->layer()->SetFillsBoundsOpaquely(false);
bubble_widget_ = views::BubbleDialogDelegateView::CreateBubble(bubble_view_);
bubble_widget_->AddObserver(this);
TrayBackgroundView::InitializeBubbleAnimations(bubble_widget_);
bubble_view_->InitializeAndShowBubble();
if (features::IsBackgroundBlurEnabled()) {
bubble_widget_->client_view()->layer()->SetBackgroundBlur(
kUnifiedMenuBackgroundBlur);
}
tray->tray_event_filter()->AddBubble(this);
tray->shelf()->AddObserver(this);
Shell::Get()->tablet_mode_controller()->AddObserver(this);
......@@ -225,7 +218,7 @@ void UnifiedSystemTrayBubble::UpdateTransform() {
if (!unified_view_->IsTransformEnabled()) {
unified_view_->SetTransform(gfx::Transform());
DestroyBlurLayerForAnimation();
OnAnimationFinished();
SetFrameVisible(true);
return;
}
......@@ -242,13 +235,9 @@ void UnifiedSystemTrayBubble::UpdateTransform() {
transform.Translate(0, y_offset);
unified_view_->SetTransform(transform);
CreateBlurLayerForAnimation();
if (blur_layer_) {
gfx::Rect blur_bounds = bubble_widget_->client_view()->layer()->bounds();
blur_bounds.Inset(gfx::Insets(y_offset, 0, 0, 0));
blur_layer_->layer()->SetBounds(blur_bounds);
}
gfx::Rect blur_bounds = bubble_view_->bounds();
blur_bounds.Inset(gfx::Insets(y_offset, 0, 0, 0));
bubble_view_->layer()->SetClipRect(blur_bounds);
}
TrayBackgroundView* UnifiedSystemTrayBubble::GetTray() const {
......@@ -367,44 +356,8 @@ void UnifiedSystemTrayBubble::UpdateBubbleBounds() {
tray_->message_center_bubble()->UpdatePosition();
}
void UnifiedSystemTrayBubble::CreateBlurLayerForAnimation() {
if (!features::IsBackgroundBlurEnabled())
return;
if (blur_layer_)
return;
DCHECK(bubble_widget_);
bubble_widget_->client_view()->layer()->SetBackgroundBlur(0);
blur_layer_ = std::make_unique<ui::LayerOwner>(
std::make_unique<ui::Layer>(ui::LAYER_SOLID_COLOR));
blur_layer_->layer()->SetColor(SK_ColorTRANSPARENT);
blur_layer_->layer()->SetRoundedCornerRadius(
{kUnifiedTrayCornerRadius, kUnifiedTrayCornerRadius,
kUnifiedTrayCornerRadius, kUnifiedTrayCornerRadius});
blur_layer_->layer()->SetFillsBoundsOpaquely(false);
bubble_widget_->GetLayer()->Add(blur_layer_->layer());
bubble_widget_->GetLayer()->StackAtBottom(blur_layer_->layer());
blur_layer_->layer()->SetBounds(
bubble_widget_->client_view()->layer()->bounds());
blur_layer_->layer()->SetBackgroundBlur(kUnifiedMenuBackgroundBlur);
}
void UnifiedSystemTrayBubble::DestroyBlurLayerForAnimation() {
if (!features::IsBackgroundBlurEnabled())
return;
if (!blur_layer_)
return;
blur_layer_.reset();
bubble_widget_->client_view()->layer()->SetBackgroundBlur(
kUnifiedMenuBackgroundBlur);
void UnifiedSystemTrayBubble::OnAnimationFinished() {
bubble_widget_->GetNativeWindow()->layer()->SetClipRect(gfx::Rect());
}
void UnifiedSystemTrayBubble::SetFrameVisible(bool visible) {
......
......@@ -19,10 +19,6 @@
#include "ui/views/widget/widget_observer.h"
#include "ui/wm/public/activation_change_observer.h"
namespace ui {
class LayerOwner;
} // namespace ui
namespace views {
class Widget;
} // namespace views
......@@ -140,9 +136,8 @@ class ASH_EXPORT UnifiedSystemTrayBubble
void UpdateBubbleBounds();
// Create / destroy background blur layer that is used during animation.
void CreateBlurLayerForAnimation();
void DestroyBlurLayerForAnimation();
// Called when the tray animation is finished.
void OnAnimationFinished();
// Set visibility of bubble frame border. Used for disabling the border during
// animation.
......@@ -172,9 +167,6 @@ class ASH_EXPORT UnifiedSystemTrayBubble
// click (|show_by_click| in ctor is false), it is not set.
base::Optional<base::TimeTicks> time_shown_by_click_;
// Background blur layer that is used during animation.
std::unique_ptr<ui::LayerOwner> blur_layer_;
TrayBubbleView* bubble_view_ = nullptr;
UnifiedSystemTrayView* unified_view_ = nullptr;
......
......@@ -91,8 +91,6 @@ class SystemTrayContainer : public views::View {
SystemTrayContainer() {
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
SetBackground(UnifiedSystemTrayView::CreateBackground());
if (!features::IsUnifiedMessageCenterRefactorEnabled())
SetBorder(std::make_unique<TopCornerBorder>());
}
......@@ -113,8 +111,6 @@ class SystemTrayContainer : public views::View {
class DetailedViewContainer : public views::View {
public:
DetailedViewContainer() {
SetBackground(UnifiedSystemTrayView::CreateBackground());
if (!features::IsUnifiedMessageCenterRefactorEnabled())
SetBorder(std::make_unique<TopCornerBorder>());
}
......@@ -272,9 +268,11 @@ UnifiedSystemTrayView::UnifiedSystemTrayView(
auto* layout = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
SetBackground(CreateBackground());
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
auto add_layered_child = [](views::View* parent, views::View* child) {
parent->AddChildView(child);
child->SetPaintToLayer();
child->layer()->SetFillsBoundsOpaquely(false);
};
SessionControllerImpl* session_controller =
Shell::Get()->session_controller();
......@@ -282,7 +280,7 @@ UnifiedSystemTrayView::UnifiedSystemTrayView(
if (!features::IsUnifiedMessageCenterRefactorEnabled()) {
message_center_view_ = new UnifiedMessageCenterView(
this, controller->model(), nullptr /* message_center_bubble */);
AddChildView(message_center_view_);
add_layered_child(this, message_center_view_);
layout->SetFlexForView(message_center_view_, 1);
}
......@@ -290,15 +288,15 @@ UnifiedSystemTrayView::UnifiedSystemTrayView(
session_controller->GetUserSession(0) &&
session_controller->IsScreenLocked() &&
!AshMessageCenterLockScreenController::IsEnabled());
AddChildView(notification_hidden_view_);
add_layered_child(this, notification_hidden_view_);
AddChildView(system_tray_container_);
system_tray_container_->AddChildView(top_shortcuts_view_);
add_layered_child(system_tray_container_, top_shortcuts_view_);
system_tray_container_->AddChildView(feature_pods_container_);
system_tray_container_->AddChildView(page_indicator_view_);
system_tray_container_->AddChildView(sliders_container_);
system_tray_container_->AddChildView(system_info_view_);
add_layered_child(system_tray_container_, system_info_view_);
if (features::IsManagedDeviceUIRedesignEnabled()) {
managed_device_view_ = new UnifiedManagedDeviceView();
......@@ -306,7 +304,7 @@ UnifiedSystemTrayView::UnifiedSystemTrayView(
}
detailed_view_container_->SetVisible(false);
AddChildView(detailed_view_container_);
add_layered_child(this, detailed_view_container_);
// UnifiedSystemTrayView::FocusSearch makes focus traversal start from
// |system_tray_container_|, but we have to complete the cycle by setting
......
......@@ -91,6 +91,8 @@ Widget* CreateBubbleWidget(BubbleDialogDelegateView* bubble) {
: Widget::InitParams::WindowOpacity::kOpaque;
bubble_params.accept_events = bubble->accept_events();
bubble_params.remove_standard_frame = true;
bubble_params.layer_type = bubble->GetLayerType();
// Use a window default shadow if the bubble doesn't provides its own.
if (bubble->GetShadow() == BubbleBorder::NO_ASSETS)
bubble_params.shadow_type = Widget::InitParams::ShadowType::kDefault;
......@@ -300,6 +302,10 @@ void BubbleDialogDelegateView::OnBeforeBubbleWidgetInit(
Widget::InitParams* params,
Widget* widget) const {}
ui::LayerType BubbleDialogDelegateView::GetLayerType() const {
return ui::LAYER_TEXTURED;
}
void BubbleDialogDelegateView::UseCompactMargins() {
set_margins(gfx::Insets(6));
}
......
......@@ -136,6 +136,9 @@ class VIEWS_EXPORT BubbleDialogDelegateView : public DialogDelegateView,
virtual void OnBeforeBubbleWidgetInit(Widget::InitParams* params,
Widget* widget) const;
// The layer type of the bubble widget.
virtual ui::LayerType GetLayerType() const;
// Sets the content margins to a default picked for smaller bubbles.
void UseCompactMargins();
......
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