Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/rotator/screen_rotation_animator.h" | 5 #include "ash/rotator/screen_rotation_animator.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/display/window_tree_host_manager.h" | 8 #include "ash/display/window_tree_host_manager.h" |
| 9 #include "ash/public/cpp/shell_window_ids.h" | 9 #include "ash/public/cpp/shell_window_ids.h" |
| 10 #include "ash/rotator/screen_rotation_animation.h" | 10 #include "ash/rotator/screen_rotation_animation.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 return inverse; | 127 return inverse; |
| 128 } | 128 } |
| 129 | 129 |
| 130 // The |request_id| changed since last copy request, which means a | 130 // The |request_id| changed since last copy request, which means a |
| 131 // new rotation stated, we need to ignore this copy result. | 131 // new rotation stated, we need to ignore this copy result. |
| 132 bool IgnoreCopyResult(int64_t request_id, int64_t current_request_id) { | 132 bool IgnoreCopyResult(int64_t request_id, int64_t current_request_id) { |
| 133 DCHECK(request_id <= current_request_id); | 133 DCHECK(request_id <= current_request_id); |
| 134 return request_id < current_request_id; | 134 return request_id < current_request_id; |
| 135 } | 135 } |
| 136 | 136 |
| 137 // Creates a black mask layer and returns the |layer_owner|. | 137 bool RootWindowChangedForDisplayId(aura::Window* root_window, |
| 138 std::unique_ptr<ui::LayerOwner> CreateBlackMaskLayerOwner( | 138 int64_t display_id) { |
| 139 return root_window != GetRootWindow(display_id); | |
| 140 } | |
| 141 | |
| 142 // Creates a mask layer and returns the |mask_layer_tree_owner|. | |
| 143 std::unique_ptr<ui::LayerTreeOwner> CreateMaskLayerTreeOwner( | |
| 139 const gfx::Rect& rect) { | 144 const gfx::Rect& rect) { |
| 140 std::unique_ptr<ui::Layer> black_mask_layer = | 145 std::unique_ptr<ui::Layer> mask_layer = |
| 141 base::MakeUnique<ui::Layer>(ui::LAYER_SOLID_COLOR); | 146 base::MakeUnique<ui::Layer>(ui::LAYER_SOLID_COLOR); |
| 142 black_mask_layer->SetBounds(rect); | 147 mask_layer->SetBounds(rect); |
| 143 black_mask_layer->SetColor(SK_ColorBLACK); | 148 mask_layer->SetColor(SK_ColorBLACK); |
| 144 std::unique_ptr<ui::LayerOwner> black_mask_layer_owner = | 149 return base::MakeUnique<ui::LayerTreeOwner>(std::move(mask_layer)); |
| 145 base::MakeUnique<ui::LayerOwner>(); | |
| 146 black_mask_layer_owner->SetLayer(std::move(black_mask_layer)); | |
| 147 return black_mask_layer_owner; | |
| 148 } | 150 } |
| 149 | 151 |
| 150 class ScreenRotationAnimationMetricsReporter | 152 class ScreenRotationAnimationMetricsReporter |
| 151 : public ui::AnimationMetricsReporter { | 153 : public ui::AnimationMetricsReporter { |
| 152 public: | 154 public: |
| 153 ScreenRotationAnimationMetricsReporter() = default; | 155 ScreenRotationAnimationMetricsReporter() = default; |
| 154 ~ScreenRotationAnimationMetricsReporter() override = default; | 156 ~ScreenRotationAnimationMetricsReporter() override = default; |
| 155 | 157 |
| 156 void Report(int value) override { | 158 void Report(int value) override { |
| 157 UMA_HISTOGRAM_PERCENTAGE("Ash.Rotation.AnimationSmoothness", value); | 159 UMA_HISTOGRAM_PERCENTAGE("Ash.Rotation.AnimationSmoothness", value); |
| 158 } | 160 } |
| 159 | 161 |
| 160 private: | 162 private: |
| 161 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimationMetricsReporter); | 163 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimationMetricsReporter); |
| 162 }; | 164 }; |
| 163 | 165 |
| 164 } // namespace | 166 } // namespace |
| 165 | 167 |
| 166 ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id) | 168 ScreenRotationAnimator::ScreenRotationAnimator(aura::Window* root_window) |
| 167 : display_id_(display_id), | 169 : root_window_(root_window), |
| 170 screen_rotation_container_layer_( | |
| 171 GetScreenRotationContainer(root_window_)->layer()), | |
| 168 screen_rotation_state_(IDLE), | 172 screen_rotation_state_(IDLE), |
| 169 rotation_request_id_(0), | 173 rotation_request_id_(0), |
| 170 metrics_reporter_( | 174 metrics_reporter_( |
| 171 base::MakeUnique<ScreenRotationAnimationMetricsReporter>()), | 175 base::MakeUnique<ScreenRotationAnimationMetricsReporter>()), |
| 172 disable_animation_timers_for_test_(false), | 176 disable_animation_timers_for_test_(false), |
| 173 has_switch_ash_disable_smooth_screen_rotation_( | 177 has_switch_ash_disable_smooth_screen_rotation_( |
| 174 base::CommandLine::ForCurrentProcess()->HasSwitch( | 178 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 175 switches::kAshDisableSmoothScreenRotation)), | 179 switches::kAshDisableSmoothScreenRotation)), |
| 176 root_window_(GetRootWindow(display_id_)), | |
| 177 screen_rotation_container_layer_( | |
| 178 GetScreenRotationContainer(root_window_)->layer()), | |
| 179 weak_factory_(this) {} | 180 weak_factory_(this) {} |
| 180 | 181 |
| 181 ScreenRotationAnimator::~ScreenRotationAnimator() { | 182 ScreenRotationAnimator::~ScreenRotationAnimator() { |
| 182 // To prevent a call to |AnimationEndedCallback()| from calling a method on | 183 // To prevent a call to |AnimationEndedCallback()| from calling a method on |
| 183 // the |animator_|. | 184 // the |animator_|. |
| 184 weak_factory_.InvalidateWeakPtrs(); | 185 weak_factory_.InvalidateWeakPtrs(); |
| 185 | 186 |
| 186 // Explicitly reset the |old_layer_tree_owner_| and |metrics_reporter_| in | 187 // Explicitly reset the |old_layer_tree_owner_| and |metrics_reporter_| in |
| 187 // order to make sure |metrics_reporter_| outlives the attached animation | 188 // order to make sure |metrics_reporter_| outlives the attached animation |
| 188 // sequence. | 189 // sequence. |
| 189 old_layer_tree_owner_.reset(); | 190 old_layer_tree_owner_.reset(); |
| 190 metrics_reporter_.reset(); | 191 metrics_reporter_.reset(); |
| 191 } | 192 } |
| 192 | 193 |
| 193 void ScreenRotationAnimator::StartRotationAnimation( | 194 void ScreenRotationAnimator::StartRotationAnimation( |
| 194 std::unique_ptr<ScreenRotationRequest> rotation_request) { | 195 std::unique_ptr<ScreenRotationRequest> rotation_request) { |
| 195 const display::Display::Rotation current_rotation = | 196 const display::Display::Rotation current_rotation = |
| 196 GetCurrentScreenRotation(display_id_); | 197 GetCurrentScreenRotation(rotation_request->display_id); |
| 197 if (current_rotation == rotation_request->new_rotation) { | 198 if (current_rotation == rotation_request->new_rotation) { |
| 198 // We need to call |ProcessAnimationQueue()| to prepare for next rotation | 199 // We need to call |ProcessAnimationQueue()| to prepare for next rotation |
| 199 // request. | 200 // request. |
| 200 ProcessAnimationQueue(); | 201 ProcessAnimationQueue(); |
| 201 return; | 202 return; |
| 202 } | 203 } |
| 203 | 204 |
| 204 rotation_request->old_rotation = current_rotation; | 205 rotation_request->old_rotation = current_rotation; |
| 205 if (has_switch_ash_disable_smooth_screen_rotation_) { | 206 if (has_switch_ash_disable_smooth_screen_rotation_) { |
| 206 StartSlowAnimation(std::move(rotation_request)); | 207 StartSlowAnimation(std::move(rotation_request)); |
| 207 } else { | 208 } else { |
| 208 std::unique_ptr<cc::CopyOutputRequest> copy_output_request = | 209 std::unique_ptr<cc::CopyOutputRequest> copy_output_request = |
| 209 cc::CopyOutputRequest::CreateRequest( | 210 cc::CopyOutputRequest::CreateRequest( |
| 210 CreateAfterCopyCallbackBeforeRotation(std::move(rotation_request))); | 211 CreateAfterCopyCallbackBeforeRotation(std::move(rotation_request))); |
| 211 RequestCopyScreenRotationContainerLayer(std::move(copy_output_request)); | 212 RequestCopyScreenRotationContainerLayer(std::move(copy_output_request)); |
| 212 screen_rotation_state_ = COPY_REQUESTED; | 213 screen_rotation_state_ = COPY_REQUESTED; |
| 213 } | 214 } |
| 214 } | 215 } |
| 215 | 216 |
| 216 void ScreenRotationAnimator::StartSlowAnimation( | 217 void ScreenRotationAnimator::StartSlowAnimation( |
| 217 std::unique_ptr<ScreenRotationRequest> rotation_request) { | 218 std::unique_ptr<ScreenRotationRequest> rotation_request) { |
| 218 CreateOldLayerTreeForSlowAnimation(); | 219 CreateOldLayerTreeForSlowAnimation(); |
| 219 SetRotation(rotation_request->old_rotation, rotation_request->new_rotation, | 220 SetRotation(rotation_request->display_id, rotation_request->old_rotation, |
| 220 rotation_request->source); | 221 rotation_request->new_rotation, rotation_request->source); |
| 221 AnimateRotation(std::move(rotation_request)); | 222 AnimateRotation(std::move(rotation_request)); |
| 222 } | 223 } |
| 223 | 224 |
| 224 void ScreenRotationAnimator::SetRotation( | 225 void ScreenRotationAnimator::SetRotation( |
| 226 int64_t display_id, | |
| 225 display::Display::Rotation old_rotation, | 227 display::Display::Rotation old_rotation, |
| 226 display::Display::Rotation new_rotation, | 228 display::Display::Rotation new_rotation, |
| 227 display::Display::RotationSource source) { | 229 display::Display::RotationSource source) { |
| 228 // Allow compositor locks to extend timeout, so that screen rotation only | 230 // Allow compositor locks to extend timeout, so that screen rotation only |
| 229 // takes output copy after contents are properlly resized, such as wallpaper | 231 // takes output copy after contents are properlly resized, such as wallpaper |
| 230 // and ARC apps. | 232 // and ARC apps. |
| 231 ui::Compositor* compositor = root_window_->layer()->GetCompositor(); | 233 ui::Compositor* compositor = root_window_->layer()->GetCompositor(); |
| 232 compositor->set_allow_locks_to_extend_timeout(true); | 234 compositor->set_allow_locks_to_extend_timeout(true); |
| 233 Shell::Get()->display_manager()->SetDisplayRotation(display_id_, new_rotation, | 235 Shell::Get()->display_manager()->SetDisplayRotation(display_id, new_rotation, |
| 234 source); | 236 source); |
| 235 compositor->set_allow_locks_to_extend_timeout(false); | 237 compositor->set_allow_locks_to_extend_timeout(false); |
| 236 const display::Display display = | 238 const display::Display display = |
| 237 Shell::Get()->display_manager()->GetDisplayForId(display_id_); | 239 Shell::Get()->display_manager()->GetDisplayForId(display_id); |
| 238 old_layer_tree_owner_->root()->SetTransform( | 240 old_layer_tree_owner_->root()->SetTransform( |
| 239 CreateScreenRotationOldLayerTransformForDisplay(old_rotation, | 241 CreateScreenRotationOldLayerTransformForDisplay(old_rotation, |
| 240 new_rotation, display)); | 242 new_rotation, display)); |
| 241 } | 243 } |
| 242 | 244 |
| 243 void ScreenRotationAnimator::RequestCopyScreenRotationContainerLayer( | 245 void ScreenRotationAnimator::RequestCopyScreenRotationContainerLayer( |
| 244 std::unique_ptr<cc::CopyOutputRequest> copy_output_request) { | 246 std::unique_ptr<cc::CopyOutputRequest> copy_output_request) { |
| 245 copy_output_request->set_area( | 247 copy_output_request->set_area( |
| 246 gfx::Rect(screen_rotation_container_layer_->size())); | 248 gfx::Rect(screen_rotation_container_layer_->size())); |
| 247 screen_rotation_container_layer_->RequestCopyOfOutput( | 249 screen_rotation_container_layer_->RequestCopyOfOutput( |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 264 OnScreenRotationContainerLayerCopiedAfterRotation, | 266 OnScreenRotationContainerLayerCopiedAfterRotation, |
| 265 weak_factory_.GetWeakPtr(), | 267 weak_factory_.GetWeakPtr(), |
| 266 base::Passed(&rotation_request)); | 268 base::Passed(&rotation_request)); |
| 267 } | 269 } |
| 268 | 270 |
| 269 void ScreenRotationAnimator::OnScreenRotationContainerLayerCopiedBeforeRotation( | 271 void ScreenRotationAnimator::OnScreenRotationContainerLayerCopiedBeforeRotation( |
| 270 std::unique_ptr<ScreenRotationRequest> rotation_request, | 272 std::unique_ptr<ScreenRotationRequest> rotation_request, |
| 271 std::unique_ptr<cc::CopyOutputResult> result) { | 273 std::unique_ptr<cc::CopyOutputResult> result) { |
| 272 if (IgnoreCopyResult(rotation_request->id, rotation_request_id_)) | 274 if (IgnoreCopyResult(rotation_request->id, rotation_request_id_)) |
| 273 return; | 275 return; |
| 274 // Abort rotation and animation if the display was removed. | 276 // Abort rotation and animation if the display was removed or the |
| 275 if (!IsDisplayIdValid(display_id_)) { | 277 // |root_window| was changed for |display_id|. |
| 278 if (!IsDisplayIdValid(rotation_request->display_id) || | |
|
oshima
2017/06/01 15:54:59
you should be able t remove this because if it's i
wutao
2017/06/01 22:48:03
Done.
| |
| 279 RootWindowChangedForDisplayId(root_window_, | |
| 280 rotation_request->display_id)) { | |
| 276 ProcessAnimationQueue(); | 281 ProcessAnimationQueue(); |
| 277 return; | 282 return; |
| 278 } | 283 } |
| 279 // Abort animation and set the rotation to target rotation when the copy | 284 // Abort animation and set the rotation to target rotation when the copy |
| 280 // request has been canceled or failed. It would fail if, for examples: a) The | 285 // request has been canceled or failed. It would fail if, for examples: a) The |
| 281 // layer is removed from the compositor and destroye before committing the | 286 // layer is removed from the compositor and destroye before committing the |
| 282 // request to the compositor. b) The compositor is shutdown. | 287 // request to the compositor. b) The compositor is shutdown. |
| 283 if (result->IsEmpty()) { | 288 if (result->IsEmpty()) { |
| 284 Shell::Get()->display_manager()->SetDisplayRotation( | 289 Shell::Get()->display_manager()->SetDisplayRotation( |
| 285 display_id_, rotation_request->new_rotation, rotation_request->source); | 290 rotation_request->display_id, rotation_request->new_rotation, |
| 291 rotation_request->source); | |
| 286 ProcessAnimationQueue(); | 292 ProcessAnimationQueue(); |
| 287 return; | 293 return; |
| 288 } | 294 } |
| 289 | 295 |
| 290 old_layer_tree_owner_ = CopyLayerTree(std::move(result)); | 296 old_layer_tree_owner_ = CopyLayerTree(std::move(result)); |
| 291 AddLayerAtTopOfWindowLayers(root_window_, old_layer_tree_owner_->root()); | 297 AddLayerAtTopOfWindowLayers(root_window_, old_layer_tree_owner_->root()); |
| 292 SetRotation(rotation_request->old_rotation, rotation_request->new_rotation, | 298 SetRotation(rotation_request->display_id, rotation_request->old_rotation, |
| 293 rotation_request->source); | 299 rotation_request->new_rotation, rotation_request->source); |
| 294 std::unique_ptr<cc::CopyOutputRequest> copy_output_request = | 300 std::unique_ptr<cc::CopyOutputRequest> copy_output_request = |
| 295 cc::CopyOutputRequest::CreateRequest( | 301 cc::CopyOutputRequest::CreateRequest( |
| 296 CreateAfterCopyCallbackAfterRotation(std::move(rotation_request))); | 302 CreateAfterCopyCallbackAfterRotation(std::move(rotation_request))); |
| 297 RequestCopyScreenRotationContainerLayer(std::move(copy_output_request)); | 303 RequestCopyScreenRotationContainerLayer(std::move(copy_output_request)); |
| 298 } | 304 } |
| 299 | 305 |
| 300 void ScreenRotationAnimator::OnScreenRotationContainerLayerCopiedAfterRotation( | 306 void ScreenRotationAnimator::OnScreenRotationContainerLayerCopiedAfterRotation( |
| 301 std::unique_ptr<ScreenRotationRequest> rotation_request, | 307 std::unique_ptr<ScreenRotationRequest> rotation_request, |
| 302 std::unique_ptr<cc::CopyOutputResult> result) { | 308 std::unique_ptr<cc::CopyOutputResult> result) { |
| 303 if (IgnoreCopyResult(rotation_request->id, rotation_request_id_)) | 309 if (IgnoreCopyResult(rotation_request->id, rotation_request_id_)) |
| 304 return; | 310 return; |
| 305 // In the following cases, abort animation: | 311 // In the following cases, abort animation: |
| 306 // 1) if the display was removed, | 312 // 1) if the display was removed, |
| 307 // 2) the copy request has been canceled or failed. It would fail if, | 313 // 2) if the |root_window| was changed for |display_id|, |
| 314 // 3) the copy request has been canceled or failed. It would fail if, | |
| 308 // for examples: a) The layer is removed from the compositor and destroye | 315 // for examples: a) The layer is removed from the compositor and destroye |
| 309 // before committing the request to the compositor. b) The compositor is | 316 // before committing the request to the compositor. b) The compositor is |
| 310 // shutdown. | 317 // shutdown. |
| 311 if (!IsDisplayIdValid(display_id_) || result->IsEmpty()) { | 318 if (!IsDisplayIdValid(rotation_request->display_id) || |
|
oshima
2017/06/01 15:54:59
ditto
wutao
2017/06/01 22:48:03
Done.
| |
| 319 RootWindowChangedForDisplayId(root_window_, | |
| 320 rotation_request->display_id) || | |
| 321 result->IsEmpty()) { | |
| 312 ProcessAnimationQueue(); | 322 ProcessAnimationQueue(); |
| 313 return; | 323 return; |
| 314 } | 324 } |
| 315 | 325 |
| 316 new_layer_tree_owner_ = CopyLayerTree(std::move(result)); | 326 new_layer_tree_owner_ = CopyLayerTree(std::move(result)); |
| 317 AddLayerBelowWindowLayer(root_window_, old_layer_tree_owner_->root(), | 327 AddLayerBelowWindowLayer(root_window_, old_layer_tree_owner_->root(), |
| 318 new_layer_tree_owner_->root()); | 328 new_layer_tree_owner_->root()); |
| 319 AnimateRotation(std::move(rotation_request)); | 329 AnimateRotation(std::move(rotation_request)); |
| 320 } | 330 } |
| 321 | 331 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 const gfx::Point pivot = gfx::Point(rotated_screen_bounds.width() / 2, | 366 const gfx::Point pivot = gfx::Point(rotated_screen_bounds.width() / 2, |
| 357 rotated_screen_bounds.height() / 2); | 367 rotated_screen_bounds.height() / 2); |
| 358 | 368 |
| 359 ui::Layer* new_root_layer; | 369 ui::Layer* new_root_layer; |
| 360 if (!new_layer_tree_owner_ || | 370 if (!new_layer_tree_owner_ || |
| 361 has_switch_ash_disable_smooth_screen_rotation_) { | 371 has_switch_ash_disable_smooth_screen_rotation_) { |
| 362 new_root_layer = screen_rotation_container_layer_; | 372 new_root_layer = screen_rotation_container_layer_; |
| 363 } else { | 373 } else { |
| 364 new_root_layer = new_layer_tree_owner_->root(); | 374 new_root_layer = new_layer_tree_owner_->root(); |
| 365 // Add a black mask layer on top of |screen_rotation_container_layer_|. | 375 // Add a black mask layer on top of |screen_rotation_container_layer_|. |
| 366 black_mask_layer_owner_ = CreateBlackMaskLayerOwner( | 376 mask_layer_tree_owner_ = CreateMaskLayerTreeOwner( |
| 367 gfx::Rect(screen_rotation_container_layer_->size())); | 377 gfx::Rect(screen_rotation_container_layer_->size())); |
| 368 AddLayerBelowWindowLayer(root_window_, new_root_layer, | 378 AddLayerBelowWindowLayer(root_window_, new_root_layer, |
| 369 black_mask_layer_owner_->layer()); | 379 mask_layer_tree_owner_->root()); |
| 370 } | 380 } |
| 371 | 381 |
| 372 std::unique_ptr<ScreenRotationAnimation> new_layer_screen_rotation = | 382 std::unique_ptr<ScreenRotationAnimation> new_layer_screen_rotation = |
| 373 base::MakeUnique<ScreenRotationAnimation>( | 383 base::MakeUnique<ScreenRotationAnimation>( |
| 374 new_root_layer, kRotationDegrees * rotation_factor, | 384 new_root_layer, kRotationDegrees * rotation_factor, |
| 375 0 /* end_degrees */, new_root_layer->opacity(), | 385 0 /* end_degrees */, new_root_layer->opacity(), |
| 376 new_root_layer->opacity() /* target_opacity */, pivot, duration, | 386 new_root_layer->opacity() /* target_opacity */, pivot, duration, |
| 377 tween_type); | 387 tween_type); |
| 378 | 388 |
| 379 ui::LayerAnimator* new_layer_animator = new_root_layer->GetAnimator(); | 389 ui::LayerAnimator* new_layer_animator = new_root_layer->GetAnimator(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 new ui::CallbackLayerAnimationObserver( | 436 new ui::CallbackLayerAnimationObserver( |
| 427 base::Bind(&AnimationEndedCallback, weak_factory_.GetWeakPtr())); | 437 base::Bind(&AnimationEndedCallback, weak_factory_.GetWeakPtr())); |
| 428 if (new_layer_tree_owner_) | 438 if (new_layer_tree_owner_) |
| 429 new_layer_animator->AddObserver(observer); | 439 new_layer_animator->AddObserver(observer); |
| 430 new_layer_animator->StartAnimation(new_layer_animation_sequence.release()); | 440 new_layer_animator->StartAnimation(new_layer_animation_sequence.release()); |
| 431 old_layer_animator->AddObserver(observer); | 441 old_layer_animator->AddObserver(observer); |
| 432 old_layer_animator->StartAnimation(old_layer_animation_sequence.release()); | 442 old_layer_animator->StartAnimation(old_layer_animation_sequence.release()); |
| 433 observer->SetActive(); | 443 observer->SetActive(); |
| 434 } | 444 } |
| 435 | 445 |
| 436 void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation, | 446 void ScreenRotationAnimator::Rotate(int64_t display_id, |
|
oshima
2017/06/01 15:54:59
Use the display id of the root window instead.
wutao
2017/06/01 22:48:04
Done.
| |
| 447 display::Display::Rotation new_rotation, | |
| 437 display::Display::RotationSource source) { | 448 display::Display::RotationSource source) { |
| 438 // |rotation_request_id_| is used to skip stale requests. Before the layer | 449 // |rotation_request_id_| is used to skip stale requests. Before the layer |
| 439 // CopyOutputResult callback called, there could have new rotation request. | 450 // CopyOutputResult callback called, there could have new rotation request. |
| 440 // Increases |rotation_request_id_| for each new request and in the callback, | 451 // Increases |rotation_request_id_| for each new request and in the callback, |
| 441 // we compare the |rotation_request.id| and |rotation_request_id_| to | 452 // we compare the |rotation_request.id| and |rotation_request_id_| to |
| 442 // determine the stale status. | 453 // determine the stale status. |
| 443 rotation_request_id_++; | 454 rotation_request_id_++; |
| 444 std::unique_ptr<ScreenRotationRequest> rotation_request = | 455 std::unique_ptr<ScreenRotationRequest> rotation_request = |
| 445 base::MakeUnique<ScreenRotationRequest>(rotation_request_id_, | 456 base::MakeUnique<ScreenRotationRequest>(rotation_request_id_, display_id, |
| 446 new_rotation, source); | 457 new_rotation, source); |
| 447 switch (screen_rotation_state_) { | 458 switch (screen_rotation_state_) { |
| 448 case IDLE: | 459 case IDLE: |
| 449 case COPY_REQUESTED: | 460 case COPY_REQUESTED: |
| 450 StartRotationAnimation(std::move(rotation_request)); | 461 StartRotationAnimation(std::move(rotation_request)); |
| 451 break; | 462 break; |
| 452 case ROTATING: | 463 case ROTATING: |
| 453 last_pending_request_ = std::move(rotation_request); | 464 last_pending_request_ = std::move(rotation_request); |
| 454 // The pending request will be processed when the | 465 // The pending request will be processed when the |
| 455 // |AnimationEndedCallback()| should be called after |StopAnimating()|. | 466 // |AnimationEndedCallback()| should be called after |StopAnimating()|. |
| 456 StopAnimating(); | 467 StopAnimating(); |
| 457 break; | 468 break; |
| 458 } | 469 } |
| 459 } | 470 } |
| 460 | 471 |
| 461 void ScreenRotationAnimator::AddScreenRotationAnimatorObserver( | 472 void ScreenRotationAnimator::AddScreenRotationAnimatorObserver( |
| 462 ScreenRotationAnimatorObserver* observer) { | 473 ScreenRotationAnimatorObserver* observer) { |
| 463 screen_rotation_animator_observers_.AddObserver(observer); | 474 screen_rotation_animator_observers_.AddObserver(observer); |
| 464 } | 475 } |
| 465 | 476 |
| 466 void ScreenRotationAnimator::RemoveScreenRotationAnimatorObserver( | 477 void ScreenRotationAnimator::RemoveScreenRotationAnimatorObserver( |
| 467 ScreenRotationAnimatorObserver* observer) { | 478 ScreenRotationAnimatorObserver* observer) { |
| 468 screen_rotation_animator_observers_.RemoveObserver(observer); | 479 screen_rotation_animator_observers_.RemoveObserver(observer); |
| 469 } | 480 } |
| 470 | 481 |
| 471 void ScreenRotationAnimator::ProcessAnimationQueue() { | 482 void ScreenRotationAnimator::ProcessAnimationQueue() { |
| 472 screen_rotation_state_ = IDLE; | 483 screen_rotation_state_ = IDLE; |
| 473 if (IsDisplayIdValid(display_id_) && black_mask_layer_owner_) | |
| 474 root_window_->layer()->Remove(black_mask_layer_owner_->layer()); | |
| 475 old_layer_tree_owner_.reset(); | 484 old_layer_tree_owner_.reset(); |
| 476 new_layer_tree_owner_.reset(); | 485 new_layer_tree_owner_.reset(); |
| 477 black_mask_layer_owner_.reset(); | 486 mask_layer_tree_owner_.reset(); |
| 478 if (last_pending_request_ && IsDisplayIdValid(display_id_)) { | 487 if (last_pending_request_ && |
| 488 IsDisplayIdValid(last_pending_request_->display_id) && | |
|
oshima
2017/06/01 15:54:59
ditto
wutao
2017/06/01 22:48:03
Done.
| |
| 489 !RootWindowChangedForDisplayId(root_window_, | |
| 490 last_pending_request_->display_id)) { | |
| 479 StartRotationAnimation(std::move(last_pending_request_)); | 491 StartRotationAnimation(std::move(last_pending_request_)); |
| 480 return; | 492 return; |
| 481 } | 493 } |
| 482 | 494 |
| 483 // This is only used in test to notify animator observer. | 495 // This is only used in test to notify animator observer. |
| 484 for (auto& observer : screen_rotation_animator_observers_) | 496 for (auto& observer : screen_rotation_animator_observers_) |
| 485 observer.OnScreenRotationAnimationFinished(this); | 497 observer.OnScreenRotationAnimationFinished(this); |
| 486 } | 498 } |
| 487 | 499 |
| 488 void ScreenRotationAnimator::StopAnimating() { | 500 void ScreenRotationAnimator::StopAnimating() { |
| 489 // |old_layer_tree_owner_| new_layer_tree_owner_| could be nullptr if another | 501 // |old_layer_tree_owner_| new_layer_tree_owner_| could be nullptr if another |
| 490 // the rotation request comes before the copy request finished. | 502 // the rotation request comes before the copy request finished. |
| 491 if (old_layer_tree_owner_) | 503 if (old_layer_tree_owner_) |
| 492 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating(); | 504 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating(); |
| 493 if (new_layer_tree_owner_) | 505 if (new_layer_tree_owner_) |
| 494 new_layer_tree_owner_->root()->GetAnimator()->StopAnimating(); | 506 new_layer_tree_owner_->root()->GetAnimator()->StopAnimating(); |
| 495 if (IsDisplayIdValid(display_id_) && black_mask_layer_owner_) | 507 mask_layer_tree_owner_.reset(); |
| 496 root_window_->layer()->Remove(black_mask_layer_owner_->layer()); | |
| 497 } | 508 } |
| 498 | 509 |
| 499 } // namespace ash | 510 } // namespace ash |
| OLD | NEW |