Commit 5982f8d2 authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

overview: Move blur logic to separate file.

We are gonna add a flag to introduce a new type of blur animation on
the wallpaper for overview usages. This is a start to make the logics
more encapsulated. No functional changes.

Test: ash_unittests
Bug: none
Change-Id: I98ef63f957f6ebbcc2315a0f9472fcc536128c09
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1838683
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702995}
parent abaf4c65
...@@ -1185,6 +1185,8 @@ component("ash") { ...@@ -1185,6 +1185,8 @@ component("ash") {
"wm/overview/overview_test_api.cc", "wm/overview/overview_test_api.cc",
"wm/overview/overview_utils.cc", "wm/overview/overview_utils.cc",
"wm/overview/overview_utils.h", "wm/overview/overview_utils.h",
"wm/overview/overview_wallpaper_controller.cc",
"wm/overview/overview_wallpaper_controller.h",
"wm/overview/overview_window_drag_controller.cc", "wm/overview/overview_window_drag_controller.cc",
"wm/overview/overview_window_drag_controller.h", "wm/overview/overview_window_drag_controller.h",
"wm/overview/rounded_label_widget.cc", "wm/overview/rounded_label_widget.cc",
......
This diff is collapsed.
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
namespace ash { namespace ash {
class OverviewWallpaperController;
// Manages a overview session which displays an overview of all windows and // Manages a overview session which displays an overview of all windows and
// allows selecting a window to activate it. // allows selecting a window to activate it.
class ASH_EXPORT OverviewController : public OverviewDelegate, class ASH_EXPORT OverviewController : public OverviewDelegate,
...@@ -110,7 +112,6 @@ class ASH_EXPORT OverviewController : public OverviewDelegate, ...@@ -110,7 +112,6 @@ class ASH_EXPORT OverviewController : public OverviewDelegate,
std::vector<aura::Window*> GetItemWindowListInOverviewGridsForTest(); std::vector<aura::Window*> GetItemWindowListInOverviewGridsForTest();
private: private:
class OverviewWallpaperController;
friend class OverviewSessionTest; friend class OverviewSessionTest;
FRIEND_TEST_ALL_PREFIXES(TabletModeControllerTest, FRIEND_TEST_ALL_PREFIXES(TabletModeControllerTest,
DisplayDisconnectionDuringOverview); DisplayDisconnectionDuringOverview);
...@@ -120,9 +121,6 @@ class ASH_EXPORT OverviewController : public OverviewDelegate, ...@@ -120,9 +121,6 @@ class ASH_EXPORT OverviewController : public OverviewDelegate,
void ToggleOverview(OverviewSession::EnterExitOverviewType type = void ToggleOverview(OverviewSession::EnterExitOverviewType type =
OverviewSession::EnterExitOverviewType::kNormal); OverviewSession::EnterExitOverviewType::kNormal);
// There is no need to blur or dim the wallpaper for tests.
static void SetDoNotChangeWallpaperForTests();
// Returns true if it's possible to enter or exit overview mode in the current // Returns true if it's possible to enter or exit overview mode in the current
// configuration. This can be false at certain times, such as when the lock // configuration. This can be false at certain times, such as when the lock
// screen is visible we can't overview mode. // screen is visible we can't overview mode.
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "ash/wm/overview/overview_item.h" #include "ash/wm/overview/overview_item.h"
#include "ash/wm/overview/overview_test_util.h" #include "ash/wm/overview/overview_test_util.h"
#include "ash/wm/overview/overview_utils.h" #include "ash/wm/overview/overview_utils.h"
#include "ash/wm/overview/overview_wallpaper_controller.h"
#include "ash/wm/overview/overview_window_drag_controller.h" #include "ash/wm/overview/overview_window_drag_controller.h"
#include "ash/wm/overview/rounded_label_widget.h" #include "ash/wm/overview/rounded_label_widget.h"
#include "ash/wm/overview/rounded_rect_view.h" #include "ash/wm/overview/rounded_rect_view.h"
...@@ -157,7 +158,7 @@ class OverviewSessionTest : public MultiDisplayOverviewAndSplitViewTest { ...@@ -157,7 +158,7 @@ class OverviewSessionTest : public MultiDisplayOverviewAndSplitViewTest {
shelf_view_test_api_->SetAnimationDuration( shelf_view_test_api_->SetAnimationDuration(
base::TimeDelta::FromMilliseconds(1)); base::TimeDelta::FromMilliseconds(1));
ScopedOverviewTransformWindow::SetImmediateCloseForTests(); ScopedOverviewTransformWindow::SetImmediateCloseForTests();
OverviewController::SetDoNotChangeWallpaperForTests(); OverviewWallpaperController::SetDoNotChangeWallpaperForTests();
FpsCounter::SetForceReportZeroAnimationForTest(true); FpsCounter::SetForceReportZeroAnimationForTest(true);
ash::PresentationTimeRecorder::SetReportPresentationTimeImmediatelyForTest( ash::PresentationTimeRecorder::SetReportPresentationTimeImmediatelyForTest(
true); true);
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/wm/overview/overview_wallpaper_controller.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/wallpaper/wallpaper_controller_impl.h"
#include "ash/wallpaper/wallpaper_view.h"
#include "ash/wallpaper/wallpaper_widget_controller.h"
#include "ash/wm/overview/overview_constants.h"
#include "ash/wm/overview/overview_controller.h"
#include "ash/wm/overview/overview_grid.h"
#include "ui/aura/window_tree_host.h"
namespace ash {
namespace {
// Do not change the wallpaper when entering or exiting overview mode when this
// is true.
bool g_disable_wallpaper_change_for_tests = false;
constexpr int kBlurSlideDurationMs = 250;
bool IsWallpaperChangeAllowed() {
return !g_disable_wallpaper_change_for_tests &&
Shell::Get()->wallpaper_controller()->IsBlurAllowed();
}
} // namespace
OverviewWallpaperController::OverviewWallpaperController() = default;
OverviewWallpaperController::~OverviewWallpaperController() {
if (compositor_)
compositor_->RemoveAnimationObserver(this);
for (aura::Window* root : roots_to_animate_)
root->RemoveObserver(this);
}
// static
void OverviewWallpaperController::SetDoNotChangeWallpaperForTests() {
g_disable_wallpaper_change_for_tests = true;
}
void OverviewWallpaperController::Blur(bool animate_only) {
if (!IsWallpaperChangeAllowed())
return;
OnBlurChange(WallpaperAnimationState::kAddingBlur, animate_only);
}
void OverviewWallpaperController::Unblur() {
if (!IsWallpaperChangeAllowed())
return;
OnBlurChange(WallpaperAnimationState::kRemovingBlur,
/*animate_only=*/false);
}
void OverviewWallpaperController::Stop() {
if (compositor_) {
compositor_->RemoveAnimationObserver(this);
compositor_ = nullptr;
}
state_ = WallpaperAnimationState::kNormal;
}
void OverviewWallpaperController::Start() {
DCHECK(!compositor_);
compositor_ = Shell::GetPrimaryRootWindow()->GetHost()->compositor();
compositor_->AddAnimationObserver(this);
start_time_ = base::TimeTicks();
}
void OverviewWallpaperController::AnimationProgressed(float value) {
// Animate only to even numbers to reduce the load.
int ivalue = static_cast<int>(value * kWallpaperBlurSigma) / 2 * 2;
for (aura::Window* root : roots_to_animate_)
ApplyBlurAndOpacity(root, ivalue);
}
void OverviewWallpaperController::OnAnimationStep(base::TimeTicks timestamp) {
if (start_time_ == base::TimeTicks()) {
start_time_ = timestamp;
return;
}
const float progress = (timestamp - start_time_).InMilliseconds() /
static_cast<float>(kBlurSlideDurationMs);
const bool adding = state_ == WallpaperAnimationState::kAddingBlur;
if (progress > 1.0f) {
AnimationProgressed(adding ? 1.0f : 0.f);
Stop();
} else {
AnimationProgressed(adding ? progress : 1.f - progress);
}
}
void OverviewWallpaperController::OnCompositingShuttingDown(
ui::Compositor* compositor) {
if (compositor_ == compositor)
Stop();
}
void OverviewWallpaperController::OnWindowDestroying(aura::Window* window) {
window->RemoveObserver(this);
auto it =
std::find(roots_to_animate_.begin(), roots_to_animate_.end(), window);
if (it != roots_to_animate_.end())
roots_to_animate_.erase(it);
}
void OverviewWallpaperController::ApplyBlurAndOpacity(aura::Window* root,
int value) {
DCHECK_GE(value, 0);
DCHECK_LE(value, 10);
const float opacity =
gfx::Tween::FloatValueBetween(value / 10.0, 1.f, kShieldOpacity);
auto* wallpaper_widget_controller =
RootWindowController::ForWindow(root)->wallpaper_widget_controller();
if (wallpaper_widget_controller->wallpaper_view()) {
wallpaper_widget_controller->wallpaper_view()->RepaintBlurAndOpacity(
value, opacity);
}
}
void OverviewWallpaperController::OnBlurChange(WallpaperAnimationState state,
bool animate_only) {
Stop();
for (aura::Window* root : roots_to_animate_)
root->RemoveObserver(this);
roots_to_animate_.clear();
state_ = state;
const bool should_blur = state_ == WallpaperAnimationState::kAddingBlur;
if (animate_only)
DCHECK(should_blur);
const float value =
should_blur ? kWallpaperBlurSigma : kWallpaperClearBlurSigma;
OverviewSession* overview_session =
Shell::Get()->overview_controller()->overview_session();
for (aura::Window* root : Shell::Get()->GetAllRootWindows()) {
// No need to animate the blur on exiting as this should only be called
// after overview animations are finished.
if (should_blur) {
DCHECK(overview_session);
OverviewGrid* grid = overview_session->GetGridWithRootWindow(root);
bool should_animate = grid && grid->ShouldAnimateWallpaper();
auto* wallpaper_view = RootWindowController::ForWindow(root)
->wallpaper_widget_controller()
->wallpaper_view();
float blur_sigma = wallpaper_view ? wallpaper_view->repaint_blur() : 0.f;
if (should_animate && animate_only && blur_sigma != kWallpaperBlurSigma) {
root->AddObserver(this);
roots_to_animate_.push_back(root);
continue;
}
if (should_animate == animate_only)
ApplyBlurAndOpacity(root, value);
} else {
ApplyBlurAndOpacity(root, value);
}
}
// Run the animation if one of the roots needs to be animated.
if (roots_to_animate_.empty())
state_ = WallpaperAnimationState::kNormal;
else
Start();
}
} // namespace ash
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_WM_OVERVIEW_OVERVIEW_WALLPAPER_CONTROLLER_H_
#define ASH_WM_OVERVIEW_OVERVIEW_WALLPAPER_CONTROLLER_H_
#include "ash/ash_export.h"
#include "base/macros.h"
#include "ui/aura/window_observer.h"
#include "ui/compositor/compositor_animation_observer.h"
namespace ui {
class Compositor;
class Window;
} // namespace ui
namespace ash {
// Class that handles of blurring and dimming wallpaper upon entering and
// exiting overview mode. Blurs the wallpaper automatically if the wallpaper is
// not visible prior to entering overview mode (covered by a window), otherwise
// animates the blur and dim.
class ASH_EXPORT OverviewWallpaperController
: public ui::CompositorAnimationObserver,
public aura::WindowObserver {
public:
OverviewWallpaperController();
~OverviewWallpaperController() override;
// There is no need to blur or dim the wallpaper for tests.
static void SetDoNotChangeWallpaperForTests();
void Blur(bool animate_only);
void Unblur();
bool has_blur() const { return state_ != WallpaperAnimationState::kNormal; }
bool has_blur_animation() const { return !!compositor_; }
private:
enum class WallpaperAnimationState {
kAddingBlur,
kRemovingBlur,
kNormal,
};
void Stop();
void Start();
void AnimationProgressed(float value);
// ui::CompositorAnimationObserver:
void OnAnimationStep(base::TimeTicks timestamp) override;
void OnCompositingShuttingDown(ui::Compositor* compositor) override;
// aura::WindowObserver:
void OnWindowDestroying(aura::Window* window) override;
void ApplyBlurAndOpacity(aura::Window* root, int value);
// Called when the wallpaper is to be changed. Checks to see which root
// windows should have their wallpaper blurs animated and fills
// |roots_to_animate_| accordingly. Applies blur or unblur immediately if
// the wallpaper does not need blur animation.
// When |animate_only| is true, it'll apply blur only to the root windows that
// requires animation.
void OnBlurChange(WallpaperAnimationState state, bool animate_only);
ui::Compositor* compositor_ = nullptr;
base::TimeTicks start_time_;
WallpaperAnimationState state_ = WallpaperAnimationState::kNormal;
// Vector which contains the root windows, if any, whose wallpaper should have
// blur animated after Blur or Unblur is called.
std::vector<aura::Window*> roots_to_animate_;
DISALLOW_COPY_AND_ASSIGN(OverviewWallpaperController);
};
} // namespace ash
#endif // ASH_WM_OVERVIEW_OVERVIEW_WALLPAPER_CONTROLLER_H_
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "ash/wm/overview/overview_controller.h" #include "ash/wm/overview/overview_controller.h"
#include "ash/wm/overview/overview_wallpaper_controller.h"
#include "ash/wm/splitview/multi_display_overview_and_split_view_test.h" #include "ash/wm/splitview/multi_display_overview_and_split_view_test.h"
#include "ash/wm/splitview/split_view_controller.h" #include "ash/wm/splitview/split_view_controller.h"
#include "ash/wm/splitview/split_view_utils.h" #include "ash/wm/splitview/split_view_utils.h"
...@@ -546,7 +547,7 @@ TEST_P(TabletModeControllerTest, VerticalHingeTest) { ...@@ -546,7 +547,7 @@ TEST_P(TabletModeControllerTest, VerticalHingeTest) {
// Test if this case does not crash. See http://crbug.com/462806 // Test if this case does not crash. See http://crbug.com/462806
TEST_P(TabletModeControllerTest, DisplayDisconnectionDuringOverview) { TEST_P(TabletModeControllerTest, DisplayDisconnectionDuringOverview) {
// Do not animate wallpaper on entering overview. // Do not animate wallpaper on entering overview.
OverviewController::SetDoNotChangeWallpaperForTests(); OverviewWallpaperController::SetDoNotChangeWallpaperForTests();
UpdateDisplay("800x600,800x600"); UpdateDisplay("800x600,800x600");
std::unique_ptr<aura::Window> w1( std::unique_ptr<aura::Window> w1(
......
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