Index: ash/rotator/screen_rotation_animator.cc |
diff --git a/ash/rotator/screen_rotation_animator.cc b/ash/rotator/screen_rotation_animator.cc |
index 102b8d0e7b3082f7ff25656d2f1243ecad206e22..23ac85dad0b5259676f465d3ad2a3285479020ed 100644 |
--- a/ash/rotator/screen_rotation_animator.cc |
+++ b/ash/rotator/screen_rotation_animator.cc |
@@ -8,6 +8,7 @@ |
#include <utility> |
#include <vector> |
+#include "ash/common/ash_switches.h" |
#include "ash/display/window_tree_host_manager.h" |
#include "ash/rotator/screen_rotation_animation.h" |
#include "ash/rotator/screen_rotation_animator_observer.h" |
@@ -16,6 +17,8 @@ |
#include "base/memory/ptr_util.h" |
#include "base/metrics/histogram_macros.h" |
#include "base/time/time.h" |
+#include "cc/output/copy_output_request.h" |
+#include "cc/output/copy_output_result.h" |
#include "ui/aura/window.h" |
#include "ui/compositor/layer.h" |
#include "ui/compositor/layer_animation_element.h" |
@@ -213,9 +216,70 @@ ScreenRotationAnimator::~ScreenRotationAnimator() { |
metrics_reporter_.reset(); |
} |
+void ScreenRotationAnimator::StartRotationAnimation( |
+ std::unique_ptr<ScreenRotationRequest> rotation_request) { |
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kAshEnableSmoothScreenRotationAnimation)) { |
+ RequestCopyRootLayerAndAnimateRotation(std::move(rotation_request)); |
+ } else { |
+ CreateOldLayerTree(); |
+ AnimateRotation(std::move(rotation_request)); |
+ } |
+} |
+ |
+void ScreenRotationAnimator::RequestCopyRootLayerAndAnimateRotation( |
+ std::unique_ptr<ScreenRotationRequest> rotation_request) { |
+ std::unique_ptr<cc::CopyOutputRequest> copy_output_request = |
+ cc::CopyOutputRequest::CreateRequest(base::Bind( |
+ &ScreenRotationAnimator::OnRootLayerCopiedBeforeRotation, |
+ weak_factory_.GetWeakPtr(), base::Passed(&rotation_request))); |
oshima
2017/03/31 00:14:34
do we still need to use ::Passed? Didn't std::move
wutao
2017/04/03 16:16:03
Cannot, it prompts: 'unique_ptr' has been explicit
danakj
2017/04/03 16:25:04
Passed() changes behaviour of how the variable is
|
+ ui::Layer* layer = GetRootWindow(display_id_)->layer(); |
+ layer->RequestCopyOfOutput(std::move(copy_output_request)); |
+} |
+ |
+void ScreenRotationAnimator::OnRootLayerCopiedBeforeRotation( |
+ std::unique_ptr<ScreenRotationRequest> rotation_request, |
+ std::unique_ptr<cc::CopyOutputResult> result) { |
+ // If copy request does not succeeded, fall back to recreate layers solution. |
oshima
2017/03/31 00:14:34
can you mention when and how it can fail?
wutao
2017/04/03 16:16:04
One situation is that the user cancel the request.
danakj
2017/04/03 16:23:30
It would fail if, for example..
- The layer is rem
|
+ if (result->IsEmpty() || result->size().IsEmpty() || !result->HasTexture()) |
+ CreateOldLayerTree(); |
+ else |
+ CopyOldLayerTree(std::move(result)); |
+ AnimateRotation(std::move(rotation_request)); |
+} |
+ |
+void ScreenRotationAnimator::CreateOldLayerTree() { |
+ old_layer_tree_owner_ = ::wm::RecreateLayers(GetRootWindow(display_id_)); |
+} |
+ |
+void ScreenRotationAnimator::CopyOldLayerTree( |
+ std::unique_ptr<cc::CopyOutputResult> result) { |
+ cc::TextureMailbox texture_mailbox; |
+ std::unique_ptr<cc::SingleReleaseCallback> release_callback; |
+ result->TakeTexture(&texture_mailbox, &release_callback); |
+ DCHECK(texture_mailbox.IsTexture()); |
+ |
+ aura::Window* root_window = GetRootWindow(display_id_); |
+ gfx::Rect rect(0, 0, root_window->layer()->size().width(), |
+ root_window->layer()->size().height()); |
oshima
2017/03/31 00:14:34
gfx::Rect rect(..->size());
wutao
2017/04/03 16:16:04
Done.
|
+ std::unique_ptr<ui::Layer> copy_layer = base::MakeUnique<ui::Layer>(); |
+ copy_layer->SetBounds(rect); |
oshima
2017/03/31 00:14:34
what happens if
a) the display bounds changed duri
wutao
2017/04/03 16:16:04
a) The display bounds changed during animation wil
oshima
2017/04/03 16:36:11
My concerns are:
1) it shouldn't crash or leave c
wutao
2017/04/03 17:53:38
I archive your comments and add TODO. We can add c
|
+ copy_layer->SetTextureMailbox(texture_mailbox, std::move(release_callback), |
+ rect.size()); |
+ old_layer_tree_owner_ = |
+ base::MakeUnique<ui::LayerTreeOwner>(std::move(copy_layer)); |
+} |
+ |
void ScreenRotationAnimator::AnimateRotation( |
std::unique_ptr<ScreenRotationRequest> rotation_request) { |
aura::Window* root_window = GetRootWindow(display_id_); |
+ std::unique_ptr<LayerCleanupObserver> old_layer_cleanup_observer( |
+ new LayerCleanupObserver(weak_factory_.GetWeakPtr())); |
+ ui::Layer* old_root_layer = old_layer_tree_owner_->root(); |
+ old_root_layer->set_name("ScreenRotationAnimator:old_layer_tree"); |
+ // Add the cloned layer tree in to the root, so it will be rendered. |
+ root_window->layer()->Add(old_root_layer); |
+ root_window->layer()->StackAtTop(old_root_layer); |
const gfx::Rect original_screen_bounds = root_window->GetTargetBounds(); |
@@ -230,18 +294,6 @@ void ScreenRotationAnimator::AnimateRotation( |
const gfx::Tween::Type tween_type = gfx::Tween::FAST_OUT_LINEAR_IN; |
- std::unique_ptr<ui::LayerTreeOwner> old_layer_tree = |
- ::wm::RecreateLayers(root_window); |
- old_layer_tree->root()->set_name("ScreenRotationAnimator:old_layer_tree"); |
- |
- // Add the cloned layer tree in to the root, so it will be rendered. |
- root_window->layer()->Add(old_layer_tree->root()); |
- root_window->layer()->StackAtTop(old_layer_tree->root()); |
- |
- old_layer_tree_owner_ = std::move(old_layer_tree); |
- std::unique_ptr<LayerCleanupObserver> old_layer_cleanup_observer( |
- new LayerCleanupObserver(weak_factory_.GetWeakPtr())); |
- |
Shell::GetInstance()->display_manager()->SetDisplayRotation( |
display_id_, rotation_request->new_rotation, rotation_request->source); |
@@ -249,7 +301,6 @@ void ScreenRotationAnimator::AnimateRotation( |
const gfx::Point pivot = gfx::Point(rotated_screen_bounds.width() / 2, |
rotated_screen_bounds.height() / 2); |
- ui::Layer* old_root_layer = old_layer_tree_owner_->root(); |
// We must animate each non-cloned child layer individually because the cloned |
// layer was added as a child to |root_window|'s layer so that it will be |
// rendered. |
@@ -328,7 +379,7 @@ void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation, |
StopAnimating(); |
} else { |
is_rotating_ = true; |
- AnimateRotation(std::move(rotation_request)); |
+ StartRotationAnimation(std::move(rotation_request)); |
} |
} |