Commit de421dc1 authored by Ian Vollick's avatar Ian Vollick Committed by Commit Bot

[vr] Add transition to content quad transform

This should cause animations when entering and exiting
fullscreen mode.

Bug: None
Change-Id: I348e6283b3060abd98162878c5cb4b566e81cf13
Reviewed-on: https://chromium-review.googlesource.com/575879
Commit-Queue: Ian Vollick <vollick@chromium.org>
Reviewed-by: default avatarChristopher Grant <cjgrant@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488071}
parent e36abbc2
...@@ -143,6 +143,14 @@ void AnimationPlayer::Tick(base::TimeTicks monotonic_time) { ...@@ -143,6 +143,14 @@ void AnimationPlayer::Tick(base::TimeTicks monotonic_time) {
StartAnimations(monotonic_time); StartAnimations(monotonic_time);
} }
void AnimationPlayer::SetTransitionedProperties(
const std::vector<cc::TargetProperty::Type>& properties) {
transition_.target_properties.reset();
for (auto property : properties) {
transition_.target_properties[property] = true;
}
}
void AnimationPlayer::TransitionOpacityTo(base::TimeTicks monotonic_time, void AnimationPlayer::TransitionOpacityTo(base::TimeTicks monotonic_time,
float current, float current,
float target) { float target) {
...@@ -256,17 +264,24 @@ void AnimationPlayer::TransitionBoundsTo(base::TimeTicks monotonic_time, ...@@ -256,17 +264,24 @@ void AnimationPlayer::TransitionBoundsTo(base::TimeTicks monotonic_time,
} }
cc::Animation* AnimationPlayer::GetRunningAnimationForProperty( cc::Animation* AnimationPlayer::GetRunningAnimationForProperty(
cc::TargetProperty::Type target_property) { cc::TargetProperty::Type target_property) const {
auto it = std::find_if( for (auto& animation : animations_) {
animations_.begin(), animations_.end(), if ((animation->run_state() == cc::Animation::RUNNING ||
[target_property](const std::unique_ptr<cc::Animation>& animation) { animation->run_state() == cc::Animation::PAUSED) &&
if (animation->run_state() != cc::Animation::RUNNING && animation->target_property() == target_property) {
animation->run_state() != cc::Animation::PAUSED) { return animation.get();
return false; }
} }
return animation->target_property() == target_property; return nullptr;
}); }
return it == animations_.end() ? nullptr : it->get();
bool AnimationPlayer::IsAnimatingProperty(
cc::TargetProperty::Type property) const {
for (auto& animation : animations_) {
if (animation->target_property() == property)
return true;
}
return false;
} }
} // namespace vr } // namespace vr
...@@ -60,6 +60,9 @@ class AnimationPlayer final { ...@@ -60,6 +60,9 @@ class AnimationPlayer final {
transition_ = transition; transition_ = transition;
} }
void SetTransitionedProperties(
const std::vector<cc::TargetProperty::Type>& properties);
void TransitionOpacityTo(base::TimeTicks monotonic_time, void TransitionOpacityTo(base::TimeTicks monotonic_time,
float current, float current,
float target); float target);
...@@ -70,10 +73,12 @@ class AnimationPlayer final { ...@@ -70,10 +73,12 @@ class AnimationPlayer final {
const gfx::SizeF& current, const gfx::SizeF& current,
const gfx::SizeF& target); const gfx::SizeF& target);
bool IsAnimatingProperty(cc::TargetProperty::Type property) const;
private: private:
void StartAnimations(base::TimeTicks monotonic_time); void StartAnimations(base::TimeTicks monotonic_time);
cc::Animation* GetRunningAnimationForProperty( cc::Animation* GetRunningAnimationForProperty(
cc::TargetProperty::Type target_property); cc::TargetProperty::Type target_property) const;
cc::AnimationTarget* target_ = nullptr; cc::AnimationTarget* target_ = nullptr;
Animations animations_; Animations animations_;
......
...@@ -45,4 +45,12 @@ base::TimeDelta UsToDelta(uint64_t us) { ...@@ -45,4 +45,12 @@ base::TimeDelta UsToDelta(uint64_t us) {
return base::TimeDelta::FromInternalValue(us); return base::TimeDelta::FromInternalValue(us);
} }
base::TimeTicks MsToTicks(uint64_t ms) {
return UsToTicks(1000 * ms);
}
base::TimeDelta MsToDelta(uint64_t ms) {
return UsToDelta(1000 * ms);
}
} // namespace vr } // namespace vr
...@@ -26,6 +26,9 @@ std::unique_ptr<cc::Animation> CreateBoundsAnimation(int id, ...@@ -26,6 +26,9 @@ std::unique_ptr<cc::Animation> CreateBoundsAnimation(int id,
base::TimeTicks UsToTicks(uint64_t us); base::TimeTicks UsToTicks(uint64_t us);
base::TimeDelta UsToDelta(uint64_t us); base::TimeDelta UsToDelta(uint64_t us);
base::TimeTicks MsToTicks(uint64_t us);
base::TimeDelta MsToDelta(uint64_t us);
} // namespace vr } // namespace vr
#endif // CHROME_BROWSER_VR_TEST_ANIMATION_UTILS_H_ #endif // CHROME_BROWSER_VR_TEST_ANIMATION_UTILS_H_
...@@ -58,4 +58,24 @@ bool UiSceneManagerTest::VerifyVisibility( ...@@ -58,4 +58,24 @@ bool UiSceneManagerTest::VerifyVisibility(
return true; return true;
} }
void UiSceneManagerTest::AnimateBy(base::TimeDelta delta) {
base::TimeTicks target_time = current_time_ + delta;
base::TimeDelta frame_time = base::TimeDelta::FromSecondsD(1.0 / 60.0);
for (; current_time_ < target_time; current_time_ += frame_time) {
scene_->OnBeginFrame(current_time_);
}
current_time_ = target_time;
scene_->OnBeginFrame(current_time_);
}
bool UiSceneManagerTest::IsAnimating(
UiElement* element,
const std::vector<cc::TargetProperty::Type>& properties) {
for (auto property : properties) {
if (!element->animation_player().IsAnimatingProperty(property))
return false;
}
return true;
}
} // namespace vr } // namespace vr
...@@ -5,14 +5,18 @@ ...@@ -5,14 +5,18 @@
#ifndef CHROME_BROWSER_VR_TEST_UI_SCENE_MANAGER_TEST_H_ #ifndef CHROME_BROWSER_VR_TEST_UI_SCENE_MANAGER_TEST_H_
#define CHROME_BROWSER_VR_TEST_UI_SCENE_MANAGER_TEST_H_ #define CHROME_BROWSER_VR_TEST_UI_SCENE_MANAGER_TEST_H_
#include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "cc/trees/target_property.h"
#include "chrome/browser/vr/elements/ui_element_debug_id.h" #include "chrome/browser/vr/elements/ui_element_debug_id.h"
#include "chrome/browser/vr/test/mock_browser_interface.h" #include "chrome/browser/vr/test/mock_browser_interface.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace vr { namespace vr {
class UiElement;
class UiScene; class UiScene;
class UiSceneManager; class UiSceneManager;
...@@ -52,10 +56,19 @@ class UiSceneManagerTest : public testing::Test { ...@@ -52,10 +56,19 @@ class UiSceneManagerTest : public testing::Test {
bool VerifyVisibility(const std::set<UiElementDebugId>& debug_ids, bool VerifyVisibility(const std::set<UiElementDebugId>& debug_ids,
bool visible); bool visible);
// Advances current_time_ by delta. This is done in frame increments and
// UiScene::OnBeginFrame is called at each increment.
void AnimateBy(base::TimeDelta delta);
// Returns true if the given properties are being animated by the element.
bool IsAnimating(UiElement* element,
const std::vector<cc::TargetProperty::Type>& properties);
base::MessageLoop message_loop_; base::MessageLoop message_loop_;
std::unique_ptr<MockBrowserInterface> browser_; std::unique_ptr<MockBrowserInterface> browser_;
std::unique_ptr<UiScene> scene_; std::unique_ptr<UiScene> scene_;
std::unique_ptr<UiSceneManager> manager_; std::unique_ptr<UiSceneManager> manager_;
base::TimeTicks current_time_;
}; };
} // namespace vr } // namespace vr
......
...@@ -6,7 +6,14 @@ ...@@ -6,7 +6,14 @@
namespace vr { namespace vr {
Transition::Transition() {} namespace {
static constexpr int kDefaultTransitionDurationMs = 225;
} // namespace
Transition::Transition()
: duration(
base::TimeDelta::FromMilliseconds(kDefaultTransitionDurationMs)) {}
Transition::~Transition() {} Transition::~Transition() {}
} // namespace vr } // namespace vr
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
#include "components/vector_icons/vector_icons.h" #include "components/vector_icons/vector_icons.h"
#include "ui/gfx/transform_util.h" #include "ui/gfx/transform_util.h"
using cc::TargetProperty::BOUNDS;
using cc::TargetProperty::TRANSFORM;
namespace vr { namespace vr {
namespace { namespace {
...@@ -271,6 +274,7 @@ void UiSceneManager::CreateContentQuad() { ...@@ -271,6 +274,7 @@ void UiSceneManager::CreateContentQuad() {
element->SetTranslate(0, kContentVerticalOffset, -kContentDistance); element->SetTranslate(0, kContentVerticalOffset, -kContentDistance);
element->set_visible(false); element->set_visible(false);
element->set_corner_radius(kContentCornerRadius); element->set_corner_radius(kContentCornerRadius);
element->animation_player().SetTransitionedProperties({TRANSFORM, BOUNDS});
main_content_ = element.get(); main_content_ = element.get();
content_elements_.push_back(element.get()); content_elements_.push_back(element.get());
scene_->AddUiElement(std::move(element)); scene_->AddUiElement(std::move(element));
......
...@@ -9,12 +9,16 @@ ...@@ -9,12 +9,16 @@
#include "base/test/scoped_mock_time_message_loop_task_runner.h" #include "base/test/scoped_mock_time_message_loop_task_runner.h"
#include "chrome/browser/vr/elements/ui_element.h" #include "chrome/browser/vr/elements/ui_element.h"
#include "chrome/browser/vr/elements/ui_element_debug_id.h" #include "chrome/browser/vr/elements/ui_element_debug_id.h"
#include "chrome/browser/vr/test/animation_utils.h"
#include "chrome/browser/vr/test/mock_browser_interface.h" #include "chrome/browser/vr/test/mock_browser_interface.h"
#include "chrome/browser/vr/test/ui_scene_manager_test.h" #include "chrome/browser/vr/test/ui_scene_manager_test.h"
#include "chrome/browser/vr/ui_scene.h" #include "chrome/browser/vr/ui_scene.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using cc::TargetProperty::BOUNDS;
using cc::TargetProperty::TRANSFORM;
namespace vr { namespace vr {
namespace { namespace {
...@@ -266,24 +270,36 @@ TEST_F(UiSceneManagerTest, UiUpdatesForFullscreenChanges) { ...@@ -266,24 +270,36 @@ TEST_F(UiSceneManagerTest, UiUpdatesForFullscreenChanges) {
// Hold onto the background color to make sure it changes. // Hold onto the background color to make sure it changes.
SkColor initial_background = scene_->GetWorldBackgroundColor(); SkColor initial_background = scene_->GetWorldBackgroundColor();
VerifyElementsVisible("Initial", kElementsVisibleInBrowsing); VerifyElementsVisible("Initial", kElementsVisibleInBrowsing);
UiElement* content_quad = scene_->GetUiElementByDebugId(kContentQuad);
gfx::SizeF initial_content_size = content_quad->size();
gfx::Transform initial_position =
content_quad->transform_operations().Apply();
// In fullscreen mode, content elements should be visible, control elements // In fullscreen mode, content elements should be visible, control elements
// should be hidden. // should be hidden.
manager_->SetFullscreen(true); manager_->SetFullscreen(true);
VerifyElementsVisible("In fullscreen", visible_in_fullscreen); VerifyElementsVisible("In fullscreen", visible_in_fullscreen);
{ // Make sure background has changed for fullscreen.
SCOPED_TRACE("Entered Fullsceen"); EXPECT_NE(initial_background, scene_->GetWorldBackgroundColor());
// Make sure background has changed for fullscreen. // Should have started transition.
EXPECT_NE(initial_background, scene_->GetWorldBackgroundColor()); EXPECT_TRUE(IsAnimating(content_quad, {TRANSFORM, BOUNDS}));
} // Finish the transition.
AnimateBy(MsToDelta(1000));
EXPECT_FALSE(IsAnimating(content_quad, {TRANSFORM, BOUNDS}));
EXPECT_NE(initial_content_size, content_quad->size());
EXPECT_NE(initial_position, content_quad->transform_operations().Apply());
// Everything should return to original state after leaving fullscreen. // Everything should return to original state after leaving fullscreen.
manager_->SetFullscreen(false); manager_->SetFullscreen(false);
VerifyElementsVisible("Restore initial", kElementsVisibleInBrowsing); VerifyElementsVisible("Restore initial", kElementsVisibleInBrowsing);
{ EXPECT_EQ(initial_background, scene_->GetWorldBackgroundColor());
SCOPED_TRACE("Exited Fullsceen"); // Should have started transition.
EXPECT_EQ(initial_background, scene_->GetWorldBackgroundColor()); EXPECT_TRUE(IsAnimating(content_quad, {TRANSFORM, BOUNDS}));
} // Finish the transition.
AnimateBy(MsToDelta(1000));
EXPECT_FALSE(IsAnimating(content_quad, {TRANSFORM, BOUNDS}));
EXPECT_EQ(initial_content_size, content_quad->size());
EXPECT_EQ(initial_position, content_quad->transform_operations().Apply());
} }
TEST_F(UiSceneManagerTest, UiUpdatesExitPrompt) { TEST_F(UiSceneManagerTest, UiUpdatesExitPrompt) {
......
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