Skip to content

Commit

Permalink
Implemented screen rotation animation experiment.
Browse files Browse the repository at this point in the history
This patch implements 2 different animations for when the  screen orientation changes.  These animations are still experimental and will be disabled by default.

Depends on: https://codereview.chromium.org/983933002/

BUG=337596

Review URL: https://codereview.chromium.org/975943002

Cr-Commit-Position: refs/heads/master@{#320391}
  • Loading branch information
bruthig-chromium authored and Commit bot committed Mar 12, 2015
1 parent febbefc commit 37f9cad
Show file tree
Hide file tree
Showing 15 changed files with 581 additions and 30 deletions.
9 changes: 5 additions & 4 deletions ash/accelerators/accelerator_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#include "ash/multi_profile_uma.h"
#include "ash/new_window_delegate.h"
#include "ash/root_window_controller.h"
#include "ash/rotator/screen_rotation.h"
#include "ash/rotator/screen_rotation_animator.h"
#include "ash/rotator/window_rotation.h"
#include "ash/screenshot_delegate.h"
#include "ash/session/session_state_delegate.h"
#include "ash/shelf/shelf.h"
Expand Down Expand Up @@ -293,8 +294,8 @@ void HandleRotateScreen() {
gfx::Display display = Shell::GetScreen()->GetDisplayNearestPoint(point);
const DisplayInfo& display_info =
Shell::GetInstance()->display_manager()->GetDisplayInfo(display.id());
Shell::GetInstance()->display_manager()->SetDisplayRotation(
display.id(), GetNextRotation(display_info.rotation()));
ash::ScreenRotationAnimator(display.id())
.Rotate(GetNextRotation(display_info.rotation()));
}

// Rotate the active window.
Expand All @@ -310,7 +311,7 @@ void HandleRotateActiveWindow() {
set_preemption_strategy(ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
active_window->layer()->GetAnimator()->StartAnimation(
new ui::LayerAnimationSequence(
new ash::ScreenRotation(360, active_window->layer())));
new ash::WindowRotation(360, active_window->layer())));
}
}

Expand Down
8 changes: 6 additions & 2 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,12 @@
'root_window_controller.h',
'root_window_settings.cc',
'root_window_settings.h',
'rotator/screen_rotation.cc',
'rotator/screen_rotation.h',
'rotator/screen_rotation_animation.cc',
'rotator/screen_rotation_animation.h',
'rotator/screen_rotation_animator.cc',
'rotator/screen_rotation_animator.h',
'rotator/window_rotation.cc',
'rotator/window_rotation.h',
'scoped_target_root_window.cc',
'scoped_target_root_window.h',
'screen_util.cc',
Expand Down
7 changes: 7 additions & 0 deletions ash/ash_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ const char kAshEnableMirroredScreen[] = "ash-enable-mirrored-screen";
const char kAshEnablePowerButtonQuickLock[] =
"ash-enable-power-button-quick-lock";

// Specifies the screen rotation animation to use. Possible values are:
// "partial-rotation", "partial-rotation-slow", "full-rotation", and
// "full-rotation-slow". See ash/rotator/screen_rotation_animator.cc for more
// details.
const char kAshEnableScreenRotationAnimation[] =
"ash-screen-rotation-animation";

// Enables software based mirroring.
const char kAshEnableSoftwareMirroring[] = "ash-enable-software-mirroring";

Expand Down
1 change: 1 addition & 0 deletions ash/ash_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ASH_EXPORT extern const char kAshEnableMagnifierKeyScroller[];
#endif
ASH_EXPORT extern const char kAshEnableMirroredScreen[];
ASH_EXPORT extern const char kAshEnablePowerButtonQuickLock[];
ASH_EXPORT extern const char kAshEnableScreenRotationAnimation[];
ASH_EXPORT extern const char kAshEnableSoftwareMirroring[];
ASH_EXPORT extern const char kAshEnableSystemSounds[];
ASH_EXPORT extern const char kAshEnableTouchViewTesting[];
Expand Down
5 changes: 3 additions & 2 deletions ash/content/display/screen_orientation_controller_chromeos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ash/ash_switches.h"
#include "ash/display/display_info.h"
#include "ash/display/display_manager.h"
#include "ash/rotator/screen_rotation_animator.h"
#include "ash/shell.h"
#include "ash/wm/maximize_mode/maximize_mode_controller.h"
#include "base/auto_reset.h"
Expand Down Expand Up @@ -118,8 +119,8 @@ void ScreenOrientationController::SetDisplayRotation(
current_rotation_ = rotation;
base::AutoReset<bool> auto_ignore_display_configuration_updates(
&ignore_display_configuration_updates_, true);
display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(),
rotation);
ash::ScreenRotationAnimator(gfx::Display::InternalDisplayId())
.Rotate(rotation);
}

void ScreenOrientationController::OnWindowActivated(aura::Window* gained_active,
Expand Down
73 changes: 73 additions & 0 deletions ash/rotator/screen_rotation_animation.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2015 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/rotator/screen_rotation_animation.h"

#include "base/time/time.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animation_delegate.h"
#include "ui/gfx/animation/tween.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/interpolated_transform.h"
#include "ui/gfx/transform.h"

namespace ash {

ScreenRotationAnimation::ScreenRotationAnimation(
ui::Layer* layer,
int start_degrees,
int end_degrees,
float initial_opacity,
float target_opacity,
const gfx::Point3F& initial_scale,
const gfx::Point3F& target_scale,
gfx::Point pivot,
base::TimeDelta duration,
gfx::Tween::Type tween_type)
: ui::LayerAnimationElement(
LayerAnimationElement::TRANSFORM | LayerAnimationElement::OPACITY,
duration),
tween_type_(tween_type),
initial_opacity_(initial_opacity),
target_opacity_(target_opacity) {
scoped_ptr<ui::InterpolatedTransform> scale(
new ui::InterpolatedTransformAboutPivot(
pivot, new ui::InterpolatedScale(initial_scale, target_scale)));

scoped_ptr<ui::InterpolatedTransform> rotation(
new ui::InterpolatedTransformAboutPivot(
pivot, new ui::InterpolatedRotation(start_degrees, end_degrees)));

// Use the target transform/bounds in case the layer is already animating.
gfx::Transform current_transform = layer->GetTargetTransform();
interpolated_transform_.reset(
new ui::InterpolatedConstantTransform(current_transform));
scale->SetChild(rotation.release());
interpolated_transform_->SetChild(scale.release());
}

ScreenRotationAnimation::~ScreenRotationAnimation() {
}

void ScreenRotationAnimation::OnStart(ui::LayerAnimationDelegate* delegate) {
}

bool ScreenRotationAnimation::OnProgress(double current,
ui::LayerAnimationDelegate* delegate) {
const double tweened = gfx::Tween::CalculateValue(tween_type_, current);
delegate->SetTransformFromAnimation(
interpolated_transform_->Interpolate(tweened));
delegate->SetOpacityFromAnimation(gfx::Tween::FloatValueBetween(
tweened, initial_opacity_, target_opacity_));
return true;
}

void ScreenRotationAnimation::OnGetTarget(TargetValue* target) const {
target->transform = interpolated_transform_->Interpolate(1.0);
}

void ScreenRotationAnimation::OnAbort(ui::LayerAnimationDelegate* delegate) {
}

} // namespace ash
70 changes: 70 additions & 0 deletions ash/rotator/screen_rotation_animation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2015 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_ROTATOR_SCREEN_ROTATION_ANIMATION_H_
#define ASH_ROTATOR_SCREEN_ROTATION_ANIMATION_H_

#include <stdint.h>

#include "ash/ash_export.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "ui/compositor/layer_animation_element.h"
#include "ui/gfx/animation/tween.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point3_f.h"

namespace ui {
class InterpolatedTransform;
class Layer;
}

namespace ash {

// A LayerAnimationElement that will animate a layer by rotating it around a
// pivot point.
class ASH_EXPORT ScreenRotationAnimation : public ui::LayerAnimationElement {
public:
// Creates an animation element that will rotate |layer| from |start_degrees|
// to |end_degrees| around the given |pivot|. The animation will take
// |duration| amount of time and |layer| will be scaled as defined by the
// |initial_scale| and |target_scale| values.
ScreenRotationAnimation(ui::Layer* layer,
int start_degrees,
int end_degrees,
float initial_opacity,
float target_opacity,
const gfx::Point3F& initial_scale,
const gfx::Point3F& target_scale,
gfx::Point pivot,
base::TimeDelta duration,
gfx::Tween::Type twen_type);
~ScreenRotationAnimation() override;

private:
// Implementation of ui::LayerAnimationDelegate
void OnStart(ui::LayerAnimationDelegate* delegate) override;
bool OnProgress(double current,
ui::LayerAnimationDelegate* delegate) override;
void OnGetTarget(TargetValue* target) const override;
void OnAbort(ui::LayerAnimationDelegate* delegate) override;

// The root InterpolatedTransform that defines the animation.
scoped_ptr<ui::InterpolatedTransform> interpolated_transform_;

// The Tween type to use for the animation.
gfx::Tween::Type tween_type_;

// The initial layer opacity to start the animation with.
float initial_opacity_;

// The target layer opacity to end the animation with.
float target_opacity_;

DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimation);
};

} // namespace ash

#endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATION_H_
Loading

0 comments on commit 37f9cad

Please sign in to comment.