Commit 4e118e53 authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

desks: For animation classes, store index instead of actual desk.

Requested in crrev.com/c/2354798. This will simplfy things down the line
as we use more index lookup and remove const from some parameters in
RootWindowDeskSwitchAnimator.

Test: manual, existing tests
Bug: 1111445
Change-Id: I7250d969b95f08da5819c73ca325bce2db0ea5bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2369518Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800828}
parent 0dce55ff
...@@ -33,13 +33,14 @@ ui::Compositor* GetSelectedCompositorForAnimationSmoothness() { ...@@ -33,13 +33,14 @@ ui::Compositor* GetSelectedCompositorForAnimationSmoothness() {
// DeskAnimationBase: // DeskAnimationBase:
DeskAnimationBase::DeskAnimationBase(DesksController* controller, DeskAnimationBase::DeskAnimationBase(DesksController* controller,
const Desk* ending_desk) int ending_desk_index)
: controller_(controller), : controller_(controller),
ending_desk_(ending_desk), ending_desk_index_(ending_desk_index),
throughput_tracker_(GetSelectedCompositorForAnimationSmoothness() throughput_tracker_(GetSelectedCompositorForAnimationSmoothness()
->RequestNewThroughputTracker()) { ->RequestNewThroughputTracker()) {
DCHECK(controller_); DCHECK(controller_);
DCHECK(ending_desk_); DCHECK_LE(ending_desk_index_, int{controller_->desks().size()});
DCHECK_GE(ending_desk_index_, 0);
} }
DeskAnimationBase::~DeskAnimationBase() = default; DeskAnimationBase::~DeskAnimationBase() = default;
...@@ -58,14 +59,14 @@ void DeskAnimationBase::Launch() { ...@@ -58,14 +59,14 @@ void DeskAnimationBase::Launch() {
// This window must be able to accept events (See // This window must be able to accept events (See
// `aura::Window::CanAcceptEvent()`) even though its desk is still being // `aura::Window::CanAcceptEvent()`) even though its desk is still being
// activated. https://crbug.com/1008574. // activated. https://crbug.com/1008574.
const_cast<Desk*>(ending_desk_)->PrepareForActivationAnimation(); controller_->desks()[ending_desk_index_]->PrepareForActivationAnimation();
DCHECK(!desk_switch_animators_.empty()); DCHECK(!desk_switch_animators_.empty());
for (auto& animator : desk_switch_animators_) for (auto& animator : desk_switch_animators_)
animator->TakeStartingDeskScreenshot(); animator->TakeStartingDeskScreenshot();
} }
void DeskAnimationBase::OnStartingDeskScreenshotTaken(const Desk* ending_desk) { void DeskAnimationBase::OnStartingDeskScreenshotTaken(int ending_desk_index) {
DCHECK(!desk_switch_animators_.empty()); DCHECK(!desk_switch_animators_.empty());
// Once all starting desk screenshots on all roots are taken and placed on // Once all starting desk screenshots on all roots are taken and placed on
...@@ -81,7 +82,7 @@ void DeskAnimationBase::OnStartingDeskScreenshotTaken(const Desk* ending_desk) { ...@@ -81,7 +82,7 @@ void DeskAnimationBase::OnStartingDeskScreenshotTaken(const Desk* ending_desk) {
for (auto* root : roots) for (auto* root : roots)
root->GetHost()->compositor()->SetAllowLocksToExtendTimeout(true); root->GetHost()->compositor()->SetAllowLocksToExtendTimeout(true);
OnStartingDeskScreenshotTakenInternal(ending_desk); OnStartingDeskScreenshotTakenInternal(ending_desk_index);
for (auto* root : roots) for (auto* root : roots)
root->GetHost()->compositor()->SetAllowLocksToExtendTimeout(false); root->GetHost()->compositor()->SetAllowLocksToExtendTimeout(false);
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
namespace ash { namespace ash {
class Desk;
class DesksController; class DesksController;
// An abstract class that handles the shared operations need to be performed // An abstract class that handles the shared operations need to be performed
...@@ -21,12 +20,12 @@ class DesksController; ...@@ -21,12 +20,12 @@ class DesksController;
// each animation type. // each animation type.
class DeskAnimationBase : public RootWindowDeskSwitchAnimator::Delegate { class DeskAnimationBase : public RootWindowDeskSwitchAnimator::Delegate {
public: public:
DeskAnimationBase(DesksController* controller, const Desk* ending_desk); DeskAnimationBase(DesksController* controller, int ending_desk_index);
DeskAnimationBase(const DeskAnimationBase&) = delete; DeskAnimationBase(const DeskAnimationBase&) = delete;
DeskAnimationBase& operator=(const DeskAnimationBase&) = delete; DeskAnimationBase& operator=(const DeskAnimationBase&) = delete;
~DeskAnimationBase() override; ~DeskAnimationBase() override;
const Desk* ending_desk() const { return ending_desk_; } int ending_desk_index() const { return ending_desk_index_; }
// Launches the animation. This should be done once all animators // Launches the animation. This should be done once all animators
// are created and added to `desk_switch_animators_`. This is to avoid any // are created and added to `desk_switch_animators_`. This is to avoid any
...@@ -35,7 +34,7 @@ class DeskAnimationBase : public RootWindowDeskSwitchAnimator::Delegate { ...@@ -35,7 +34,7 @@ class DeskAnimationBase : public RootWindowDeskSwitchAnimator::Delegate {
void Launch(); void Launch();
// RootWindowDeskSwitchAnimator::Delegate: // RootWindowDeskSwitchAnimator::Delegate:
void OnStartingDeskScreenshotTaken(const Desk* ending_desk) override; void OnStartingDeskScreenshotTaken(int ending_desk_index) override;
void OnEndingDeskScreenshotTaken() override; void OnEndingDeskScreenshotTaken() override;
void OnDeskSwitchAnimationFinished() override; void OnDeskSwitchAnimationFinished() override;
...@@ -44,8 +43,7 @@ class DeskAnimationBase : public RootWindowDeskSwitchAnimator::Delegate { ...@@ -44,8 +43,7 @@ class DeskAnimationBase : public RootWindowDeskSwitchAnimator::Delegate {
// things when phase (1), and phase (3) completes. Note that // things when phase (1), and phase (3) completes. Note that
// `OnDeskSwitchAnimationFinishedInternal()` will be called before the desks // `OnDeskSwitchAnimationFinishedInternal()` will be called before the desks
// screenshot layers, stored in `desk_switch_animators_`, are destroyed. // screenshot layers, stored in `desk_switch_animators_`, are destroyed.
virtual void OnStartingDeskScreenshotTakenInternal( virtual void OnStartingDeskScreenshotTakenInternal(int ending_desk_index) = 0;
const Desk* ending_desk) = 0;
virtual void OnDeskSwitchAnimationFinishedInternal() = 0; virtual void OnDeskSwitchAnimationFinishedInternal() = 0;
// Since performance here matters, we have to use the UMA histograms macros to // Since performance here matters, we have to use the UMA histograms macros to
...@@ -62,8 +60,8 @@ class DeskAnimationBase : public RootWindowDeskSwitchAnimator::Delegate { ...@@ -62,8 +60,8 @@ class DeskAnimationBase : public RootWindowDeskSwitchAnimator::Delegate {
std::vector<std::unique_ptr<RootWindowDeskSwitchAnimator>> std::vector<std::unique_ptr<RootWindowDeskSwitchAnimator>>
desk_switch_animators_; desk_switch_animators_;
// The desk that will be active after this animation ends. // The index of the desk that will be active after this animation ends.
const Desk* const ending_desk_; const int ending_desk_index_;
private: private:
// ThroughputTracker used for measuring this animation smoothness. // ThroughputTracker used for measuring this animation smoothness.
......
...@@ -27,22 +27,22 @@ constexpr char kDeskRemovalSmoothnessHistogramName[] = ...@@ -27,22 +27,22 @@ constexpr char kDeskRemovalSmoothnessHistogramName[] =
// DeskActivationAnimation: // DeskActivationAnimation:
DeskActivationAnimation::DeskActivationAnimation(DesksController* controller, DeskActivationAnimation::DeskActivationAnimation(DesksController* controller,
const Desk* ending_desk, int starting_desk_index,
bool move_left) int ending_desk_index)
: DeskAnimationBase(controller, ending_desk) { : DeskAnimationBase(controller, ending_desk_index) {
for (auto* root : Shell::GetAllRootWindows()) { for (auto* root : Shell::GetAllRootWindows()) {
desk_switch_animators_.emplace_back( desk_switch_animators_.emplace_back(
std::make_unique<RootWindowDeskSwitchAnimator>(root, ending_desk, this, std::make_unique<RootWindowDeskSwitchAnimator>(
move_left, root, starting_desk_index, ending_desk_index, this,
/*for_remove=*/false)); /*for_remove=*/false));
} }
} }
DeskActivationAnimation::~DeskActivationAnimation() = default; DeskActivationAnimation::~DeskActivationAnimation() = default;
void DeskActivationAnimation::OnStartingDeskScreenshotTakenInternal( void DeskActivationAnimation::OnStartingDeskScreenshotTakenInternal(
const Desk* ending_desk) { int ending_desk_index) {
DCHECK_EQ(ending_desk_, ending_desk); DCHECK_EQ(ending_desk_index_, ending_desk_index);
// The order here matters. Overview must end before ending tablet split view // The order here matters. Overview must end before ending tablet split view
// before switching desks. (If clamshell split view is active on one or more // before switching desks. (If clamshell split view is active on one or more
// displays, then it simply will end when we end overview.) That's because // displays, then it simply will end when we end overview.) That's because
...@@ -65,8 +65,9 @@ void DeskActivationAnimation::OnStartingDeskScreenshotTakenInternal( ...@@ -65,8 +65,9 @@ void DeskActivationAnimation::OnStartingDeskScreenshotTakenInternal(
split_view_controller->EndSplitView( split_view_controller->EndSplitView(
SplitViewController::EndReason::kDesksChange); SplitViewController::EndReason::kDesksChange);
controller_->ActivateDeskInternal(ending_desk, controller_->ActivateDeskInternal(
/*update_window_activation=*/true); controller_->desks()[ending_desk_index_].get(),
/*update_window_activation=*/true);
MaybeRestoreSplitView(/*refresh_snapped_windows=*/true); MaybeRestoreSplitView(/*refresh_snapped_windows=*/true);
} }
...@@ -83,30 +84,32 @@ metrics_util::ReportCallback DeskActivationAnimation::GetReportCallback() ...@@ -83,30 +84,32 @@ metrics_util::ReportCallback DeskActivationAnimation::GetReportCallback()
// DeskRemovalAnimation: // DeskRemovalAnimation:
DeskRemovalAnimation::DeskRemovalAnimation(DesksController* controller, DeskRemovalAnimation::DeskRemovalAnimation(DesksController* controller,
const Desk* desk_to_remove, int desk_to_remove_index,
const Desk* desk_to_activate, int desk_to_activate_index,
bool move_left,
DesksCreationRemovalSource source) DesksCreationRemovalSource source)
: DeskAnimationBase(controller, desk_to_activate), : DeskAnimationBase(controller, desk_to_activate_index),
desk_to_remove_(desk_to_remove), desk_to_remove_index_(desk_to_remove_index),
request_source_(source) { request_source_(source) {
DCHECK(!Shell::Get()->overview_controller()->InOverviewSession()); DCHECK(!Shell::Get()->overview_controller()->InOverviewSession());
DCHECK_EQ(controller_->active_desk(), desk_to_remove_); DCHECK_EQ(controller_->active_desk(),
controller_->desks()[desk_to_remove_index_].get());
for (auto* root : Shell::GetAllRootWindows()) { for (auto* root : Shell::GetAllRootWindows()) {
desk_switch_animators_.emplace_back( desk_switch_animators_.emplace_back(
std::make_unique<RootWindowDeskSwitchAnimator>(root, desk_to_activate, std::make_unique<RootWindowDeskSwitchAnimator>(
this, move_left, root, desk_to_remove_index_, desk_to_activate_index, this,
/*for_remove=*/true)); /*for_remove=*/true));
} }
} }
DeskRemovalAnimation::~DeskRemovalAnimation() = default; DeskRemovalAnimation::~DeskRemovalAnimation() = default;
void DeskRemovalAnimation::OnStartingDeskScreenshotTakenInternal( void DeskRemovalAnimation::OnStartingDeskScreenshotTakenInternal(
const Desk* ending_desk) { int ending_desk_index) {
DCHECK_EQ(ending_desk_, ending_desk); DCHECK_EQ(ending_desk_index_, ending_desk_index);
DCHECK_EQ(controller_->active_desk(), desk_to_remove_); DCHECK_EQ(controller_->active_desk(),
controller_->desks()[desk_to_remove_index_].get());
// We are removing the active desk, which may have tablet split view active. // We are removing the active desk, which may have tablet split view active.
// We will restore the split view state of the newly activated desk at the // We will restore the split view state of the newly activated desk at the
// end of the animation. Clamshell split view is impossible because // end of the animation. Clamshell split view is impossible because
...@@ -117,17 +120,19 @@ void DeskRemovalAnimation::OnStartingDeskScreenshotTakenInternal( ...@@ -117,17 +120,19 @@ void DeskRemovalAnimation::OnStartingDeskScreenshotTakenInternal(
SplitViewController::EndReason::kDesksChange); SplitViewController::EndReason::kDesksChange);
// At the end of phase (1), we activate the target desk (i.e. the desk that // At the end of phase (1), we activate the target desk (i.e. the desk that
// will be activated after the active desk `desk_to_remove_` is removed). // will be activated after the active desk `desk_to_remove_index_` is
// This means that phase (2) will take a screenshot of that desk before we // removed). This means that phase (2) will take a screenshot of that desk
// move the windows of `desk_to_remove_` to that target desk. // before we move the windows of `desk_to_remove_index_` to that target desk.
controller_->ActivateDeskInternal(ending_desk, controller_->ActivateDeskInternal(
/*update_window_activation=*/false); controller_->desks()[ending_desk_index_].get(),
/*update_window_activation=*/false);
} }
void DeskRemovalAnimation::OnDeskSwitchAnimationFinishedInternal() { void DeskRemovalAnimation::OnDeskSwitchAnimationFinishedInternal() {
// Do the actual desk removal behind the scenes before the screenshot layers // Do the actual desk removal behind the scenes before the screenshot layers
// are destroyed. // are destroyed.
controller_->RemoveDeskInternal(desk_to_remove_, request_source_); controller_->RemoveDeskInternal(
controller_->desks()[desk_to_remove_index_].get(), request_source_);
MaybeRestoreSplitView(/*refresh_snapped_windows=*/true); MaybeRestoreSplitView(/*refresh_snapped_windows=*/true);
} }
......
...@@ -11,20 +11,19 @@ ...@@ -11,20 +11,19 @@
namespace ash { namespace ash {
class Desk;
class DesksController; class DesksController;
class DeskActivationAnimation : public DeskAnimationBase { class DeskActivationAnimation : public DeskAnimationBase {
public: public:
DeskActivationAnimation(DesksController* controller, DeskActivationAnimation(DesksController* controller,
const Desk* ending_desk, int starting_desk_index,
bool move_left); int ending_desk_index);
DeskActivationAnimation(const DeskActivationAnimation&) = delete; DeskActivationAnimation(const DeskActivationAnimation&) = delete;
DeskActivationAnimation& operator=(const DeskActivationAnimation&) = delete; DeskActivationAnimation& operator=(const DeskActivationAnimation&) = delete;
~DeskActivationAnimation() override; ~DeskActivationAnimation() override;
// DeskAnimationBase: // DeskAnimationBase:
void OnStartingDeskScreenshotTakenInternal(const Desk* ending_desk) override; void OnStartingDeskScreenshotTakenInternal(int ending_desk_index) override;
void OnDeskSwitchAnimationFinishedInternal() override {} void OnDeskSwitchAnimationFinishedInternal() override {}
metrics_util::ReportCallback GetReportCallback() const override; metrics_util::ReportCallback GetReportCallback() const override;
}; };
...@@ -32,21 +31,20 @@ class DeskActivationAnimation : public DeskAnimationBase { ...@@ -32,21 +31,20 @@ class DeskActivationAnimation : public DeskAnimationBase {
class DeskRemovalAnimation : public DeskAnimationBase { class DeskRemovalAnimation : public DeskAnimationBase {
public: public:
DeskRemovalAnimation(DesksController* controller, DeskRemovalAnimation(DesksController* controller,
const Desk* desk_to_remove, int desk_to_remove_index,
const Desk* desk_to_activate, int desk_to_activate_index,
bool move_left,
DesksCreationRemovalSource source); DesksCreationRemovalSource source);
DeskRemovalAnimation(const DeskRemovalAnimation&) = delete; DeskRemovalAnimation(const DeskRemovalAnimation&) = delete;
DeskRemovalAnimation& operator=(const DeskRemovalAnimation&) = delete; DeskRemovalAnimation& operator=(const DeskRemovalAnimation&) = delete;
~DeskRemovalAnimation() override; ~DeskRemovalAnimation() override;
// DeskAnimationBase: // DeskAnimationBase:
void OnStartingDeskScreenshotTakenInternal(const Desk* ending_desk) override; void OnStartingDeskScreenshotTakenInternal(int ending_desk_index) override;
void OnDeskSwitchAnimationFinishedInternal() override; void OnDeskSwitchAnimationFinishedInternal() override;
metrics_util::ReportCallback GetReportCallback() const override; metrics_util::ReportCallback GetReportCallback() const override;
private: private:
const Desk* const desk_to_remove_; const int desk_to_remove_index_;
const DesksCreationRemovalSource request_source_; const DesksCreationRemovalSource request_source_;
}; };
......
...@@ -163,7 +163,7 @@ DesksController* DesksController::Get() { ...@@ -163,7 +163,7 @@ DesksController* DesksController::Get() {
const Desk* DesksController::GetTargetActiveDesk() const { const Desk* DesksController::GetTargetActiveDesk() const {
if (!animations_.empty()) if (!animations_.empty())
return animations_.back()->ending_desk(); return desks_[animations_.back()->ending_desk_index()].get();
return active_desk(); return active_desk();
} }
...@@ -255,9 +255,8 @@ void DesksController::RemoveDesk(const Desk* desk, ...@@ -255,9 +255,8 @@ void DesksController::RemoveDesk(const Desk* desk,
current_desk_index + ((current_desk_index > 0) ? -1 : 1); current_desk_index + ((current_desk_index > 0) ? -1 : 1);
DCHECK_GE(target_desk_index, 0); DCHECK_GE(target_desk_index, 0);
DCHECK_LT(target_desk_index, static_cast<int>(desks_.size())); DCHECK_LT(target_desk_index, static_cast<int>(desks_.size()));
const bool move_left = current_desk_index < target_desk_index;
animations_.emplace_back(std::make_unique<DeskRemovalAnimation>( animations_.emplace_back(std::make_unique<DeskRemovalAnimation>(
this, desk, desks_[target_desk_index].get(), move_left, source)); this, current_desk_index, target_desk_index, source));
animations_.back()->Launch(); animations_.back()->Launch();
return; return;
} }
...@@ -299,12 +298,9 @@ void DesksController::ActivateDesk(const Desk* desk, DesksSwitchSource source) { ...@@ -299,12 +298,9 @@ void DesksController::ActivateDesk(const Desk* desk, DesksSwitchSource source) {
return; return;
} }
// New desks are always added at the end of the list to the right of existing const int starting_desk_index = GetDeskIndex(active_desk());
// desks. Therefore, desks at lower indices are located on the left of desks animations_.emplace_back(std::make_unique<DeskActivationAnimation>(
// with higher indices. this, starting_desk_index, target_desk_index));
const bool move_left = GetDeskIndex(active_desk_) < target_desk_index;
animations_.emplace_back(
std::make_unique<DeskActivationAnimation>(this, desk, move_left));
animations_.back()->Launch(); animations_.back()->Launch();
} }
......
...@@ -102,21 +102,19 @@ std::unique_ptr<ui::Layer> CreateLayerFromScreenshotResult( ...@@ -102,21 +102,19 @@ std::unique_ptr<ui::Layer> CreateLayerFromScreenshotResult(
RootWindowDeskSwitchAnimator::RootWindowDeskSwitchAnimator( RootWindowDeskSwitchAnimator::RootWindowDeskSwitchAnimator(
aura::Window* root, aura::Window* root,
const Desk* ending_desk, int starting_desk_index,
int ending_desk_index,
Delegate* delegate, Delegate* delegate,
bool move_left,
bool for_remove) bool for_remove)
: root_window_(root), : root_window_(root),
starting_desk_(DesksController::Get()->active_desk()), starting_desk_index_(starting_desk_index),
ending_desk_(ending_desk), ending_desk_index_(ending_desk_index),
delegate_(delegate), delegate_(delegate),
animation_layer_owner_(CreateAnimationLayerOwner(root)), animation_layer_owner_(CreateAnimationLayerOwner(root)),
x_translation_offset_(root->layer()->size().width() + kDesksSpacing), x_translation_offset_(root->layer()->size().width() + kDesksSpacing),
move_left_(move_left),
for_remove_(for_remove) { for_remove_(for_remove) {
DCHECK(root_window_); DCHECK(root_window_);
DCHECK(starting_desk_); DCHECK_NE(starting_desk_index_, ending_desk_index_);
DCHECK(ending_desk_);
DCHECK(delegate_); DCHECK(delegate_);
} }
...@@ -133,8 +131,9 @@ void RootWindowDeskSwitchAnimator::TakeStartingDeskScreenshot() { ...@@ -133,8 +131,9 @@ void RootWindowDeskSwitchAnimator::TakeStartingDeskScreenshot() {
if (for_remove_) { if (for_remove_) {
// The active desk is about to be removed. Recreate and detach its old // The active desk is about to be removed. Recreate and detach its old
// layers to animate them in a jump-like animation. // layers to animate them in a jump-like animation.
auto* desk_container = auto* desk_container = DesksController::Get()
starting_desk_->GetDeskContainerForRoot(root_window_); ->desks()[starting_desk_index_]
->GetDeskContainerForRoot(root_window_);
old_windows_layer_tree_owner_ = wm::RecreateLayers(desk_container); old_windows_layer_tree_owner_ = wm::RecreateLayers(desk_container);
root_window_->layer()->Add(old_windows_layer_tree_owner_->root()); root_window_->layer()->Add(old_windows_layer_tree_owner_->root());
root_window_->layer()->StackAtTop(old_windows_layer_tree_owner_->root()); root_window_->layer()->StackAtTop(old_windows_layer_tree_owner_->root());
...@@ -170,7 +169,7 @@ void RootWindowDeskSwitchAnimator::StartAnimation() { ...@@ -170,7 +169,7 @@ void RootWindowDeskSwitchAnimator::StartAnimation() {
gfx::Transform animation_layer_ending_transfrom; gfx::Transform animation_layer_ending_transfrom;
if (move_left_) { if (starting_desk_index_ < ending_desk_index_) {
// Starting desk is one the left, so the ending transform of the parent // Starting desk is one the left, so the ending transform of the parent
// "animation layer" is then a translation to the left such that at the end, // "animation layer" is then a translation to the left such that at the end,
// the ending screenshot layer becomes the one visible on the screen. // the ending screenshot layer becomes the one visible on the screen.
...@@ -237,7 +236,7 @@ void RootWindowDeskSwitchAnimator::CompleteAnimationPhase1WithLayer( ...@@ -237,7 +236,7 @@ void RootWindowDeskSwitchAnimator::CompleteAnimationPhase1WithLayer(
gfx::Rect screenshot_bounds(root_window_->layer()->size()); gfx::Rect screenshot_bounds(root_window_->layer()->size());
gfx::Transform animation_layer_starting_transfrom; gfx::Transform animation_layer_starting_transfrom;
if (!move_left_) { if (starting_desk_index_ > ending_desk_index_) {
// Starting desk is one the right, so we need to offset the screenshot layer // Starting desk is one the right, so we need to offset the screenshot layer
// horizontally to the right by an amount equal to its width plus // horizontally to the right by an amount equal to its width plus
// kDesksSpacing (|x_translation_offset_|). // kDesksSpacing (|x_translation_offset_|).
...@@ -298,7 +297,7 @@ void RootWindowDeskSwitchAnimator::CompleteAnimationPhase1WithLayer( ...@@ -298,7 +297,7 @@ void RootWindowDeskSwitchAnimator::CompleteAnimationPhase1WithLayer(
} }
starting_desk_screenshot_taken_ = true; starting_desk_screenshot_taken_ = true;
delegate_->OnStartingDeskScreenshotTaken(ending_desk_); delegate_->OnStartingDeskScreenshotTaken(ending_desk_index_);
} }
void RootWindowDeskSwitchAnimator::OnStartingDeskScreenshotTaken( void RootWindowDeskSwitchAnimator::OnStartingDeskScreenshotTaken(
...@@ -313,7 +312,7 @@ void RootWindowDeskSwitchAnimator::OnStartingDeskScreenshotTaken( ...@@ -313,7 +312,7 @@ void RootWindowDeskSwitchAnimator::OnStartingDeskScreenshotTaken(
LOG(ERROR) << "Received multiple empty screenshots of the starting desk."; LOG(ERROR) << "Received multiple empty screenshots of the starting desk.";
NOTREACHED(); NOTREACHED();
starting_desk_screenshot_taken_ = true; starting_desk_screenshot_taken_ = true;
delegate_->OnStartingDeskScreenshotTaken(ending_desk_); delegate_->OnStartingDeskScreenshotTaken(ending_desk_index_);
} }
return; return;
...@@ -346,7 +345,7 @@ void RootWindowDeskSwitchAnimator::OnEndingDeskScreenshotTaken( ...@@ -346,7 +345,7 @@ void RootWindowDeskSwitchAnimator::OnEndingDeskScreenshotTaken(
gfx::Rect screenshot_bounds(root_window_->layer()->size()); gfx::Rect screenshot_bounds(root_window_->layer()->size());
if (move_left_) { if (starting_desk_index_ < ending_desk_index_) {
// Starting desk is one the left, so we need to offset the ending desk // Starting desk is one the left, so we need to offset the ending desk
// screenshot layer horizontally to the right by an amount equal to its // screenshot layer horizontally to the right by an amount equal to its
// width plus kDesksSpacing (|x_translation_offset_|). // width plus kDesksSpacing (|x_translation_offset_|).
......
...@@ -26,8 +26,6 @@ class CopyOutputResult; ...@@ -26,8 +26,6 @@ class CopyOutputResult;
namespace ash { namespace ash {
class Desk;
// Performs the desk switch animation on a root window (i.e. display). Since a // Performs the desk switch animation on a root window (i.e. display). Since a
// desk spans all displays, one instance of this object will be created for each // desk spans all displays, one instance of this object will be created for each
// display when a new desk is activated. // display when a new desk is activated.
...@@ -71,8 +69,8 @@ class Desk; ...@@ -71,8 +69,8 @@ class Desk;
// //
// - Phase (3) begins when StartAnimation() is called. // - Phase (3) begins when StartAnimation() is called.
// * The parent layer of both screenshot layers is animated, either: // * The parent layer of both screenshot layers is animated, either:
// - To the left (move_left_ == true); when the starting desk is on the // - To the left (starting_desk_index_ < ending_desk_index_); when the
// left. // starting desk is on the left.
// //
// <<<<<-------------------------- move left. // <<<<<-------------------------- move left.
// +-----------+ // +-----------+
...@@ -94,8 +92,8 @@ class Desk; ...@@ -94,8 +92,8 @@ class Desk;
// * End transform: Negative translation to the left to slide out starting // * End transform: Negative translation to the left to slide out starting
// desk, and slide in ending desk screenshots into the screen. // desk, and slide in ending desk screenshots into the screen.
// //
// - Or to the right (move_left_ == false), when the starting desk is on the // - Or to the right (starting_desk_index_ > ending_desk_index_), when the
// right. // starting desk is on the right.
// //
// move right. -------------------------->>>>> // move right. -------------------------->>>>>
// +-----------+ // +-----------+
...@@ -159,9 +157,10 @@ class RootWindowDeskSwitchAnimator : public ui::ImplicitAnimationObserver { ...@@ -159,9 +157,10 @@ class RootWindowDeskSwitchAnimator : public ui::ImplicitAnimationObserver {
class Delegate { class Delegate {
public: public:
// Called when phase (1) completes. The starting desk screenshot has been // Called when phase (1) completes. The starting desk screenshot has been
// taken and put on the screen. |ending_desk| is the desk that will be // taken and put on the screen. |ending_desk_index| is the index of the desk
// activated after all starting desk screenshots on all roots are taken. // that will be activated after all starting desk screenshots on all roots
virtual void OnStartingDeskScreenshotTaken(const Desk* ending_desk) = 0; // are taken.
virtual void OnStartingDeskScreenshotTaken(int ending_desk_index) = 0;
// Called when phase (2) completes. The ending desk screenshot has been // Called when phase (2) completes. The ending desk screenshot has been
// taken and put on the screen. // taken and put on the screen.
...@@ -176,9 +175,9 @@ class RootWindowDeskSwitchAnimator : public ui::ImplicitAnimationObserver { ...@@ -176,9 +175,9 @@ class RootWindowDeskSwitchAnimator : public ui::ImplicitAnimationObserver {
}; };
RootWindowDeskSwitchAnimator(aura::Window* root, RootWindowDeskSwitchAnimator(aura::Window* root,
const Desk* ending_desk, int starting_desk_index,
int ending_desk_index,
Delegate* delegate, Delegate* delegate,
bool move_left,
bool for_remove); bool for_remove);
~RootWindowDeskSwitchAnimator() override; ~RootWindowDeskSwitchAnimator() override;
...@@ -215,10 +214,11 @@ class RootWindowDeskSwitchAnimator : public ui::ImplicitAnimationObserver { ...@@ -215,10 +214,11 @@ class RootWindowDeskSwitchAnimator : public ui::ImplicitAnimationObserver {
// Completes the first phase of the animation using the given |layer| as the // Completes the first phase of the animation using the given |layer| as the
// screenshot layer of the starting desk. This layer will be parented to the // screenshot layer of the starting desk. This layer will be parented to the
// animation layer, which will be setup with its initial transform according // animation layer, which will be setup with its initial transform according
// to |move_left|. If |for_remove_| is true, the detached old layer tree of // to |starting_desk_index_| and |ending_desk_index_|. If |for_remove_| is
// the soon-to-be-removed-desk's windows will be translated up vertically to // true, the detached old layer tree of the soon-to-be-removed-desk's windows
// simulate a jump from the removed desk to the target desk. // will be translated up vertically to simulate a jump from the removed desk
// |Delegate::OnStartingDeskScreenshotTaken()| will be called at the end. // to the target desk. |Delegate::OnStartingDeskScreenshotTaken()| will be
// called at the end.
void CompleteAnimationPhase1WithLayer(std::unique_ptr<ui::Layer> layer); void CompleteAnimationPhase1WithLayer(std::unique_ptr<ui::Layer> layer);
void OnStartingDeskScreenshotTaken( void OnStartingDeskScreenshotTaken(
...@@ -229,11 +229,11 @@ class RootWindowDeskSwitchAnimator : public ui::ImplicitAnimationObserver { ...@@ -229,11 +229,11 @@ class RootWindowDeskSwitchAnimator : public ui::ImplicitAnimationObserver {
// The root window that this animator is associated with. // The root window that this animator is associated with.
aura::Window* const root_window_; aura::Window* const root_window_;
// The active desk at the start of the animation. // The index of the active desk at the start of the animation.
const Desk* const starting_desk_; const int starting_desk_index_;
// The desk to activate and animate to with this animator. // The index of the desk to activate and animate to with this animator.
const Desk* const ending_desk_; const int ending_desk_index_;
Delegate* const delegate_; Delegate* const delegate_;
...@@ -249,7 +249,7 @@ class RootWindowDeskSwitchAnimator : public ui::ImplicitAnimationObserver { ...@@ -249,7 +249,7 @@ class RootWindowDeskSwitchAnimator : public ui::ImplicitAnimationObserver {
// The amount by which the animation layer will be translated horizontally // The amount by which the animation layer will be translated horizontally
// either startingly or at the end of the animation, depending on the value of // either startingly or at the end of the animation, depending on the value of
// |move_left_|. // of the desk indices.
const int x_translation_offset_; const int x_translation_offset_;
// Number of retires for taking the starting and ending screenshots, if we // Number of retires for taking the starting and ending screenshots, if we
...@@ -257,10 +257,6 @@ class RootWindowDeskSwitchAnimator : public ui::ImplicitAnimationObserver { ...@@ -257,10 +257,6 @@ class RootWindowDeskSwitchAnimator : public ui::ImplicitAnimationObserver {
int starting_desk_screenshot_retries_ = 0; int starting_desk_screenshot_retries_ = 0;
int ending_desk_screenshot_retries_ = 0; int ending_desk_screenshot_retries_ = 0;
// True when the animation layer should be translated towards the left, which
// means the starting desk is on the left of the ending desk.
const bool move_left_;
// True if this animator is handling the remove-active-desk animation. // True if this animator is handling the remove-active-desk animation.
const bool for_remove_; const bool for_remove_;
......
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