Commit 2ebf5f84 authored by Xiaoqian Dai's avatar Xiaoqian Dai Committed by Commit Bot

Remove window mask and shadow during window dragging.

It can improve the fps of overview window dragging about 4~5fps.

Bug: 925131, 925122
Change-Id: Ia76d1baf2e8a35f5dd53e1ec7bb325ab4f6c45eb
Reviewed-on: https://chromium-review.googlesource.com/c/1439930
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#626906}
parent 00ea1ee0
...@@ -521,6 +521,10 @@ void OverviewController::OnOverviewButtonTrayLongPressed( ...@@ -521,6 +521,10 @@ void OverviewController::OnOverviewButtonTrayLongPressed(
base::UserMetricsAction("Tablet_LongPressOverviewButtonEnterSplitView")); base::UserMetricsAction("Tablet_LongPressOverviewButtonEnterSplitView"));
} }
bool OverviewController::IsInStartAnimation() {
return !start_animations_.empty();
}
std::vector<aura::Window*> std::vector<aura::Window*>
OverviewController::GetWindowsListInOverviewGridsForTesting() { OverviewController::GetWindowsListInOverviewGridsForTesting() {
std::vector<aura::Window*> windows; std::vector<aura::Window*> windows;
...@@ -551,9 +555,10 @@ void OverviewController::OnSelectionEnded() { ...@@ -551,9 +555,10 @@ void OverviewController::OnSelectionEnded() {
OnStartingAnimationComplete(/*canceled=*/true); OnStartingAnimationComplete(/*canceled=*/true);
start_animations_.clear(); start_animations_.clear();
overview_session_->UpdateMaskAndShadow(/*show=*/false);
auto* overview_session = overview_session_.release(); auto* overview_session = overview_session_.release();
// Do not show mask and show during overview shutdown.
overview_session->UpdateMaskAndShadow();
Shell::Get()->NotifyOverviewModeEnding(overview_session); Shell::Get()->NotifyOverviewModeEnding(overview_session);
overview_session->Shutdown(); overview_session->Shutdown();
// Don't delete |overview_session_| yet since the stack is still using it. // Don't delete |overview_session_| yet since the stack is still using it.
......
...@@ -61,6 +61,9 @@ class ASH_EXPORT OverviewController : public OverviewDelegate, ...@@ -61,6 +61,9 @@ class ASH_EXPORT OverviewController : public OverviewDelegate,
// if device is not currently in overview mode. // if device is not currently in overview mode.
void OnOverviewButtonTrayLongPressed(const gfx::Point& event_location); void OnOverviewButtonTrayLongPressed(const gfx::Point& event_location);
// Returns true if we're in start-overview animation.
bool IsInStartAnimation();
// Gets the windows list that are shown in the overview windows grids if the // Gets the windows list that are shown in the overview windows grids if the
// overview mode is active for testing. // overview mode is active for testing.
std::vector<aura::Window*> GetWindowsListInOverviewGridsForTesting(); std::vector<aura::Window*> GetWindowsListInOverviewGridsForTesting();
......
...@@ -270,12 +270,8 @@ void OverviewItem::SetBounds(const gfx::Rect& target_bounds, ...@@ -270,12 +270,8 @@ void OverviewItem::SetBounds(const gfx::Rect& target_bounds,
// animations, manually set the shadow. Shadow relies on both the window // animations, manually set the shadow. Shadow relies on both the window
// transform and |item_widget_|'s new bounds so set it after SetItemBounds // transform and |item_widget_|'s new bounds so set it after SetItemBounds
// and UpdateHeaderLayout. Do not apply the shadow for drop target. // and UpdateHeaderLayout. Do not apply the shadow for drop target.
if (new_animation_type == OVERVIEW_ANIMATION_NONE) { if (new_animation_type == OVERVIEW_ANIMATION_NONE)
SetShadowBounds( UpdateMaskAndShadow();
overview_grid_->IsDropTargetWindow(GetWindow())
? base::nullopt
: base::make_optional(transform_window_.GetTransformedBounds()));
}
UpdateBackdropBounds(); UpdateBackdropBounds();
} }
...@@ -348,15 +344,19 @@ void OverviewItem::UpdateCannotSnapWarningVisibility() { ...@@ -348,15 +344,19 @@ void OverviewItem::UpdateCannotSnapWarningVisibility() {
} }
void OverviewItem::OnSelectorItemDragStarted(OverviewItem* item) { void OverviewItem::OnSelectorItemDragStarted(OverviewItem* item) {
is_being_dragged_ = (item == this);
caption_container_view_->SetHeaderVisibility( caption_container_view_->SetHeaderVisibility(
item == this is_being_dragged_
? CaptionContainerView::HeaderVisibility::kInvisible ? CaptionContainerView::HeaderVisibility::kInvisible
: CaptionContainerView::HeaderVisibility::kCloseButtonInvisibleOnly); : CaptionContainerView::HeaderVisibility::kCloseButtonInvisibleOnly);
UpdateMaskAndShadow();
} }
void OverviewItem::OnSelectorItemDragEnded() { void OverviewItem::OnSelectorItemDragEnded() {
is_being_dragged_ = false;
caption_container_view_->SetHeaderVisibility( caption_container_view_->SetHeaderVisibility(
CaptionContainerView::HeaderVisibility::kVisible); CaptionContainerView::HeaderVisibility::kVisible);
UpdateMaskAndShadow();
} }
ScopedOverviewTransformWindow::GridWindowFillMode ScopedOverviewTransformWindow::GridWindowFillMode
...@@ -557,16 +557,38 @@ void OverviewItem::SetShadowBounds(base::Optional<gfx::Rect> bounds_in_screen) { ...@@ -557,16 +557,38 @@ void OverviewItem::SetShadowBounds(base::Optional<gfx::Rect> bounds_in_screen) {
shadow_->SetContentBounds(bounds_in_item); shadow_->SetContentBounds(bounds_in_item);
} }
void OverviewItem::UpdateMaskAndShadow(bool show) { void OverviewItem::UpdateMaskAndShadow() {
transform_window_.UpdateMask(show); // Do not show mask and shadow if:
// 1) overview is shutting down or
// 2) this overview item is in an overview grid that contains more than 10
// windows. In this case don't apply rounded corner mask because it can
// push the compositor memory usage to the limit. TODO(oshima): Remove
// this once new rounded corner impl is available. (crbug.com/903486)
// 3) we're currently in entering overview animation or
// 4) this overview item is being dragged or
// 5) this overview item is the drop target window or
// 6) this overview item is in animation.
bool should_show = true;
OverviewController* overview_controller = Shell::Get()->overview_controller();
if (!overview_controller->IsSelecting() ||
overview_grid_->window_list().size() > 10 ||
overview_controller->IsInStartAnimation() || is_being_dragged_ ||
overview_grid_->IsDropTargetWindow(GetWindow()) ||
transform_window_.GetOverviewWindow()
->layer()
->GetAnimator()
->is_animating()) {
should_show = false;
}
// Do not apply the shadow for the drop target in overview. if (!should_show) {
if (!show || overview_grid_->IsDropTargetWindow(GetWindow())) { transform_window_.UpdateMask(false);
SetShadowBounds(base::nullopt); SetShadowBounds(base::nullopt);
DisableBackdrop(); DisableBackdrop();
return; return;
} }
transform_window_.UpdateMask(true);
SetShadowBounds(transform_window_.GetTransformedBounds()); SetShadowBounds(transform_window_.GetTransformedBounds());
EnableBackdropIfNeeded(); EnableBackdropIfNeeded();
} }
......
...@@ -191,8 +191,8 @@ class ASH_EXPORT OverviewItem : public views::ButtonListener, ...@@ -191,8 +191,8 @@ class ASH_EXPORT OverviewItem : public views::ButtonListener,
// the shadow is hidden. // the shadow is hidden.
void SetShadowBounds(base::Optional<gfx::Rect> bounds_in_screen); void SetShadowBounds(base::Optional<gfx::Rect> bounds_in_screen);
// Show or hide the mask and shadow on this window item. // Updates the mask and shadow on this overview window item.
void UpdateMaskAndShadow(bool show); void UpdateMaskAndShadow();
// Called when the starting animation is completed, or called immediately // Called when the starting animation is completed, or called immediately
// if there was no starting animation. // if there was no starting animation.
...@@ -336,6 +336,9 @@ class ASH_EXPORT OverviewItem : public views::ButtonListener, ...@@ -336,6 +336,9 @@ class ASH_EXPORT OverviewItem : public views::ButtonListener,
// OverviewGrid::PositionWindows. // OverviewGrid::PositionWindows.
bool animating_to_close_ = false; bool animating_to_close_ = false;
// True if this overview item is currently being dragged around.
bool is_being_dragged_ = false;
// The shadow around the overview window. Shadows the original window, not // The shadow around the overview window. Shadows the original window, not
// |item_widget_|. Done here instead of on the original window because of the // |item_widget_|. Done here instead of on the original window because of the
// rounded edges mask applied on entering overview window. // rounded edges mask applied on entering overview window.
......
...@@ -566,22 +566,15 @@ void OverviewSession::UpdateGridAtLocationYPositionAndOpacity( ...@@ -566,22 +566,15 @@ void OverviewSession::UpdateGridAtLocationYPositionAndOpacity(
grid->UpdateYPositionAndOpacity(new_y, opacity, work_area, callback); grid->UpdateYPositionAndOpacity(new_y, opacity, work_area, callback);
} }
void OverviewSession::UpdateMaskAndShadow(bool show) { void OverviewSession::UpdateMaskAndShadow() {
for (auto& grid : grid_list_) { for (auto& grid : grid_list_)
// Don't apply rounded corner mask if the grid has move than 10 windows
// because it can push the compositor memory usage to the limit.
// TODO(osima): Remove this once new rounded corner impl is available.
// (crbug.com/903486)
if (show && grid->window_list().size() > 10)
continue;
for (auto& window : grid->window_list()) for (auto& window : grid->window_list())
window->UpdateMaskAndShadow(show); window->UpdateMaskAndShadow();
}
} }
void OverviewSession::OnStartingAnimationComplete(bool canceled) { void OverviewSession::OnStartingAnimationComplete(bool canceled) {
if (!canceled) { if (!canceled) {
UpdateMaskAndShadow(!canceled); UpdateMaskAndShadow();
if (overview_focus_widget_) if (overview_focus_widget_)
overview_focus_widget_->Show(); overview_focus_widget_->Show();
for (auto& grid : grid_list_) for (auto& grid : grid_list_)
......
...@@ -201,8 +201,8 @@ class ASH_EXPORT OverviewSession : public display::DisplayObserver, ...@@ -201,8 +201,8 @@ class ASH_EXPORT OverviewSession : public display::DisplayObserver,
const gfx::Rect& work_area, const gfx::Rect& work_area,
UpdateAnimationSettingsCallback callback); UpdateAnimationSettingsCallback callback);
// Shows or hides all the window selector items' mask and shadow. // Updates all the window selector items' mask and shadow.
void UpdateMaskAndShadow(bool show); void UpdateMaskAndShadow();
// Called when the overview mode starting animation completes. // Called when the overview mode starting animation completes.
void OnStartingAnimationComplete(bool canceled); void OnStartingAnimationComplete(bool canceled);
......
...@@ -2234,8 +2234,9 @@ TEST_F(OverviewSessionTest, RoundedEdgeMaskVisibility) { ...@@ -2234,8 +2234,9 @@ TEST_F(OverviewSessionTest, RoundedEdgeMaskVisibility) {
ui::ScopedAnimationDurationScaleMode test_duration_mode( ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
// Drag the first window. Verify that the mask still exists for both items as // Drag the first window. Verify that the mask was removed for the first
// we do not apply any animation to the window items at this point. // window but still exists for the second window as we do not apply mask
// for a dragged window.
const gfx::Point start_drag = item1->target_bounds().CenterPoint(); const gfx::Point start_drag = item1->target_bounds().CenterPoint();
ui::test::EventGenerator* generator = GetEventGenerator(); ui::test::EventGenerator* generator = GetEventGenerator();
generator->MoveMouseTo(start_drag); generator->MoveMouseTo(start_drag);
...@@ -2243,7 +2244,7 @@ TEST_F(OverviewSessionTest, RoundedEdgeMaskVisibility) { ...@@ -2243,7 +2244,7 @@ TEST_F(OverviewSessionTest, RoundedEdgeMaskVisibility) {
EXPECT_FALSE(window1->layer()->GetAnimator()->is_animating()); EXPECT_FALSE(window1->layer()->GetAnimator()->is_animating());
EXPECT_FALSE(window2->layer()->GetAnimator()->is_animating()); EXPECT_FALSE(window2->layer()->GetAnimator()->is_animating());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(HasMaskForItem(item1)); EXPECT_FALSE(HasMaskForItem(item1));
EXPECT_TRUE(HasMaskForItem(item2)); EXPECT_TRUE(HasMaskForItem(item2));
// Drag to horizontally and then back to the start to avoid activating the // Drag to horizontally and then back to the start to avoid activating the
......
...@@ -188,6 +188,7 @@ ScopedOverviewTransformWindow::~ScopedOverviewTransformWindow() { ...@@ -188,6 +188,7 @@ ScopedOverviewTransformWindow::~ScopedOverviewTransformWindow() {
if (null_targeter_ == window_->targeter()) if (null_targeter_ == window_->targeter())
window_->SetEventTargeter(std::move(original_targeter_)); window_->SetEventTargeter(std::move(original_targeter_));
UpdateMask(/*show=*/false);
StopObservingImplicitAnimations(); StopObservingImplicitAnimations();
} }
...@@ -258,11 +259,6 @@ void ScopedOverviewTransformWindow::BeginScopedAnimation( ...@@ -258,11 +259,6 @@ void ScopedOverviewTransformWindow::BeginScopedAnimation(
if (animation_type == OVERVIEW_ANIMATION_NONE) if (animation_type == OVERVIEW_ANIMATION_NONE)
return; return;
// Remove the mask before animating because masks affect animation
// performance. Observe the animation and add the mask after animating if the
// animation type is layouting selector items during overview.
selector_item_->UpdateMaskAndShadow(/*show=*/false);
for (auto* window : wm::GetTransientTreeIterator(GetOverviewWindow())) { for (auto* window : wm::GetTransientTreeIterator(GetOverviewWindow())) {
auto settings = std::make_unique<ScopedOverviewAnimationSettings>( auto settings = std::make_unique<ScopedOverviewAnimationSettings>(
animation_type, window); animation_type, window);
...@@ -512,8 +508,15 @@ void ScopedOverviewTransformWindow::UpdateMinimizedWidget() { ...@@ -512,8 +508,15 @@ void ScopedOverviewTransformWindow::UpdateMinimizedWidget() {
minimized_widget_->SetContentsView(preview_view); minimized_widget_->SetContentsView(preview_view);
} }
void ScopedOverviewTransformWindow::OnLayerAnimationStarted(
ui::LayerAnimationSequence* sequence) {
// Remove the mask before animating because masks affect animation
// performance. The mask will be added back once the animation is completed.
selector_item_->UpdateMaskAndShadow();
}
void ScopedOverviewTransformWindow::OnImplicitAnimationsCompleted() { void ScopedOverviewTransformWindow::OnImplicitAnimationsCompleted() {
selector_item_->UpdateMaskAndShadow(/*show=*/true); selector_item_->UpdateMaskAndShadow();
selector_item_->OnDragAnimationCompleted(); selector_item_->OnDragAnimationCompleted();
} }
...@@ -551,6 +554,8 @@ void ScopedOverviewTransformWindow::CreateMirrorWindowForMinimizedState() { ...@@ -551,6 +554,8 @@ void ScopedOverviewTransformWindow::CreateMirrorWindowForMinimizedState() {
bounds.Inset(0, 0, 0, inset); bounds.Inset(0, 0, 0, inset);
} }
minimized_widget_->SetBounds(bounds); minimized_widget_->SetBounds(bounds);
minimized_widget_->SetVisibilityAnimationTransition(
views::Widget::ANIMATE_NONE);
minimized_widget_->Show(); minimized_widget_->Show();
// Stack the minimized window at the bottom since it is never transformed in // Stack the minimized window at the bottom since it is never transformed in
......
...@@ -178,6 +178,7 @@ class ASH_EXPORT ScopedOverviewTransformWindow ...@@ -178,6 +178,7 @@ class ASH_EXPORT ScopedOverviewTransformWindow
views::Widget* minimized_widget() { return minimized_widget_.get(); } views::Widget* minimized_widget() { return minimized_widget_.get(); }
// ui::ImplicitAnimationObserver: // ui::ImplicitAnimationObserver:
void OnLayerAnimationStarted(ui::LayerAnimationSequence* sequence) override;
void OnImplicitAnimationsCompleted() override; void OnImplicitAnimationsCompleted() override;
gfx::Rect GetMaskBoundsForTesting() const; gfx::Rect GetMaskBoundsForTesting() const;
......
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