Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: ash/display/display_animator_chromeos.cc

Issue 1594683002: Introduce DisplayConfigurationController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue_576375_display1b1
Patch Set: DisplayAnimator -> DisplayAnimatorChromeOS Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/display/display_animator.h" 5 #include "ash/display/display_animator_chromeos.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h" 8 #include "ash/shell_window_ids.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "ui/aura/window.h" 12 #include "ui/aura/window.h"
13 #include "ui/aura/window_event_dispatcher.h" 13 #include "ui/aura/window_event_dispatcher.h"
14 #include "ui/compositor/layer.h" 14 #include "ui/compositor/layer.h"
15 #include "ui/compositor/layer_animation_observer.h" 15 #include "ui/compositor/layer_animation_observer.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 size_t completed_counter_; 84 size_t completed_counter_;
85 bool animation_aborted_; 85 bool animation_aborted_;
86 ScopedVector<Observer> observer_list_; 86 ScopedVector<Observer> observer_list_;
87 base::Closure callback_; 87 base::Closure callback_;
88 88
89 DISALLOW_COPY_AND_ASSIGN(CallbackRunningObserver); 89 DISALLOW_COPY_AND_ASSIGN(CallbackRunningObserver);
90 }; 90 };
91 91
92 } // namespace 92 } // namespace
93 93
94 DisplayAnimator::DisplayAnimator() : weak_ptr_factory_(this) {} 94 DisplayAnimatorChromeOS::DisplayAnimatorChromeOS() : weak_ptr_factory_(this) {
95 Shell::GetInstance()->display_configurator()->AddObserver(this);
96 }
95 97
96 DisplayAnimator::~DisplayAnimator() { 98 DisplayAnimatorChromeOS::~DisplayAnimatorChromeOS() {
99 Shell::GetInstance()->display_configurator()->RemoveObserver(this);
97 ClearHidingLayers(); 100 ClearHidingLayers();
98 } 101 }
99 102
100 void DisplayAnimator::StartFadeOutAnimation(base::Closure callback) { 103 void DisplayAnimatorChromeOS::StartFadeOutAnimation(base::Closure callback) {
101 CallbackRunningObserver* observer = new CallbackRunningObserver(callback); 104 CallbackRunningObserver* observer = new CallbackRunningObserver(callback);
102 ClearHidingLayers(); 105 ClearHidingLayers();
103 106
104 // Make the fade-out animation for all root windows. Instead of actually 107 // Make the fade-out animation for all root windows. Instead of actually
105 // hiding the root windows, we put a black layer over a root window for 108 // hiding the root windows, we put a black layer over a root window for
106 // safety. These layers remain to hide root windows and will be deleted 109 // safety. These layers remain to hide root windows and will be deleted
107 // after the animation of OnDisplayModeChanged(). 110 // after the animation of OnDisplayModeChanged().
108 for (aura::Window* root_window : Shell::GetInstance()->GetAllRootWindows()) { 111 for (aura::Window* root_window : Shell::GetInstance()->GetAllRootWindows()) {
109 ui::Layer* hiding_layer = new ui::Layer(ui::LAYER_SOLID_COLOR); 112 ui::Layer* hiding_layer = new ui::Layer(ui::LAYER_SOLID_COLOR);
110 hiding_layer->SetColor(SK_ColorBLACK); 113 hiding_layer->SetColor(SK_ColorBLACK);
(...skipping 13 matching lines...) Expand all
124 hiding_layer->SetVisible(true); 127 hiding_layer->SetVisible(true);
125 hiding_layers_[root_window] = hiding_layer; 128 hiding_layers_[root_window] = hiding_layer;
126 } 129 }
127 130
128 // In case that OnDisplayModeChanged() isn't called or its animator is 131 // In case that OnDisplayModeChanged() isn't called or its animator is
129 // canceled due to some unknown errors, we set a timer to clear these 132 // canceled due to some unknown errors, we set a timer to clear these
130 // hiding layers. 133 // hiding layers.
131 timer_.reset(new base::OneShotTimer()); 134 timer_.reset(new base::OneShotTimer());
132 timer_->Start(FROM_HERE, 135 timer_->Start(FROM_HERE,
133 base::TimeDelta::FromSeconds(kFadingTimeoutDurationInSeconds), 136 base::TimeDelta::FromSeconds(kFadingTimeoutDurationInSeconds),
134 this, &DisplayAnimator::ClearHidingLayers); 137 this, &DisplayAnimatorChromeOS::ClearHidingLayers);
135 } 138 }
136 139
137 void DisplayAnimator::StartFadeInAnimation() { 140 void DisplayAnimatorChromeOS::StartFadeInAnimation() {
138 // We want to make sure clearing all of hiding layers after the animation 141 // We want to make sure clearing all of hiding layers after the animation
139 // finished. Note that this callback can be canceled, but the cancel only 142 // finished. Note that this callback can be canceled, but the cancel only
140 // happens when the next animation is scheduled. Thus the hiding layers 143 // happens when the next animation is scheduled. Thus the hiding layers
141 // should be deleted eventually. 144 // should be deleted eventually.
142 CallbackRunningObserver* observer = new CallbackRunningObserver(base::Bind( 145 CallbackRunningObserver* observer = new CallbackRunningObserver(
143 &DisplayAnimator::ClearHidingLayers, weak_ptr_factory_.GetWeakPtr())); 146 base::Bind(&DisplayAnimatorChromeOS::ClearHidingLayers,
147 weak_ptr_factory_.GetWeakPtr()));
144 148
145 // Ensure that layers are not animating. 149 // Ensure that layers are not animating.
146 for (std::map<aura::Window*, ui::Layer*>::value_type& e : hiding_layers_) { 150 for (std::map<aura::Window*, ui::Layer*>::value_type& e : hiding_layers_) {
147 ui::LayerAnimator* animator = e.second->GetAnimator(); 151 ui::LayerAnimator* animator = e.second->GetAnimator();
148 if (animator->is_animating()) 152 if (animator->is_animating())
149 animator->StopAnimating(); 153 animator->StopAnimating();
150 } 154 }
151 155
152 // Schedules the fade-in effect for all root windows. Because we put the 156 // Schedules the fade-in effect for all root windows. Because we put the
153 // black layers for fade-out, here we actually turn those black layers 157 // black layers for fade-out, here we actually turn those black layers
(...skipping 22 matching lines...) Expand all
176 180
177 ui::ScopedLayerAnimationSettings settings(hiding_layer->GetAnimator()); 181 ui::ScopedLayerAnimationSettings settings(hiding_layer->GetAnimator());
178 settings.SetTransitionDuration( 182 settings.SetTransitionDuration(
179 base::TimeDelta::FromMilliseconds(kFadingAnimationDurationInMS)); 183 base::TimeDelta::FromMilliseconds(kFadingAnimationDurationInMS));
180 observer->AddNewAnimator(hiding_layer->GetAnimator()); 184 observer->AddNewAnimator(hiding_layer->GetAnimator());
181 hiding_layer->SetOpacity(0.0f); 185 hiding_layer->SetOpacity(0.0f);
182 hiding_layer->SetVisible(false); 186 hiding_layer->SetVisible(false);
183 } 187 }
184 } 188 }
185 189
186 void DisplayAnimator::OnDisplayModeChanged( 190 void DisplayAnimatorChromeOS::OnDisplayModeChanged(
187 const ui::DisplayConfigurator::DisplayStateList& displays) { 191 const ui::DisplayConfigurator::DisplayStateList& displays) {
188 if (!hiding_layers_.empty()) 192 if (!hiding_layers_.empty())
189 StartFadeInAnimation(); 193 StartFadeInAnimation();
190 } 194 }
191 195
192 void DisplayAnimator::OnDisplayModeChangeFailed( 196 void DisplayAnimatorChromeOS::OnDisplayModeChangeFailed(
193 const ui::DisplayConfigurator::DisplayStateList& displays, 197 const ui::DisplayConfigurator::DisplayStateList& displays,
194 ui::MultipleDisplayState failed_new_state) { 198 ui::MultipleDisplayState failed_new_state) {
195 if (!hiding_layers_.empty()) 199 if (!hiding_layers_.empty())
196 StartFadeInAnimation(); 200 StartFadeInAnimation();
197 } 201 }
198 202
199 void DisplayAnimator::ClearHidingLayers() { 203 void DisplayAnimatorChromeOS::ClearHidingLayers() {
200 if (timer_) { 204 if (timer_) {
201 timer_->Stop(); 205 timer_->Stop();
202 timer_.reset(); 206 timer_.reset();
203 } 207 }
204 STLDeleteContainerPairSecondPointers(hiding_layers_.begin(), 208 STLDeleteContainerPairSecondPointers(hiding_layers_.begin(),
205 hiding_layers_.end()); 209 hiding_layers_.end());
206 hiding_layers_.clear(); 210 hiding_layers_.clear();
207 } 211 }
208 212
209 } // namespace ash 213 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698