Commit f1d2878f authored by Walter Korman's avatar Walter Korman Committed by Commit Bot

Add simple ToString support for some animation related classes.

Bug: 709137
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I5afe52f29511fbb9cd93b086602c48d28eb9f301
Reviewed-on: https://chromium-review.googlesource.com/592291
Commit-Queue: Walter Korman <wkorman@chromium.org>
Reviewed-by: default avatarIan Vollick <vollick@chromium.org>
Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Reviewed-by: default avatarVladimir Levin <vmpstr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491441}
parent 69b90aa1
......@@ -8,6 +8,7 @@
#include "base/memory/ptr_util.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/trace_event/trace_event.h"
#include "cc/animation/animation_curve.h"
......@@ -267,4 +268,12 @@ void Animation::PushPropertiesTo(Animation* other) const {
}
}
std::string Animation::ToString() const {
return base::StringPrintf(
"Animation{id=%d, group=%d, target_property_id=%d, "
"run_state=%s}",
id_, group_, target_property_id_,
s_runStateNames[static_cast<int>(run_state_)]);
}
} // namespace cc
......@@ -145,6 +145,8 @@ class CC_ANIMATION_EXPORT Animation {
void PushPropertiesTo(Animation* other) const;
std::string ToString() const;
void set_is_impl_only(bool is_impl_only) { is_impl_only_ = is_impl_only; }
bool is_impl_only() const { return is_impl_only_; }
......
......@@ -7,6 +7,7 @@
#include <algorithm>
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "cc/animation/animation_delegate.h"
#include "cc/animation/animation_events.h"
#include "cc/animation/animation_host.h"
......@@ -1202,4 +1203,21 @@ void AnimationPlayer::PushPropertiesToImplThread(
scroll_offset_animation_was_interrupted_ = false;
}
std::string AnimationPlayer::ToString() const {
return base::StringPrintf(
"AnimationPlayer{id=%d, element_id=(%lu), animations=[%s]}", id_,
static_cast<unsigned long>(element_id_.id_),
AnimationsToString().c_str());
}
std::string AnimationPlayer::AnimationsToString() const {
std::string str;
for (size_t i = 0; i < animations_.size(); i++) {
if (i > 0)
str.append(", ");
str.append(animations_[i]->ToString());
}
return str;
}
} // namespace cc
......@@ -175,6 +175,8 @@ class CC_ANIMATION_EXPORT AnimationPlayer
return scroll_offset_animation_was_interrupted_;
}
std::string ToString() const;
private:
friend class base::RefCounted<AnimationPlayer>;
......@@ -200,6 +202,8 @@ class CC_ANIMATION_EXPORT AnimationPlayer
AnimationPlayer* animation_player_impl) const;
void PushPropertiesToImplThread(AnimationPlayer* animation_player_impl);
std::string AnimationsToString() const;
using Animations = std::vector<std::unique_ptr<Animation>>;
Animations animations_;
......
......@@ -410,5 +410,30 @@ TEST_F(AnimationPlayerTest, SwitchToLayer) {
EXPECT_EQ(player_impl_->element_id(), new_element_id);
}
TEST_F(AnimationPlayerTest, ToString) {
player_->AttachElement(element_id_);
EXPECT_EQ("AnimationPlayer{id=2, element_id=(1), animations=[]}",
player_->ToString());
player_->AddAnimation(
Animation::Create(base::MakeUnique<FakeFloatAnimationCurve>(15), 42, 73,
TargetProperty::OPACITY));
EXPECT_EQ(
"AnimationPlayer{id=2, element_id=(1), animations=[Animation{id=42, "
"group=73, target_property_id=1, "
"run_state=WAITING_FOR_TARGET_AVAILABILITY}]}",
player_->ToString());
player_->AddAnimation(
Animation::Create(base::MakeUnique<FakeFloatAnimationCurve>(18), 45, 76,
TargetProperty::BOUNDS));
EXPECT_EQ(
"AnimationPlayer{id=2, element_id=(1), animations=[Animation{id=42, "
"group=73, target_property_id=1, "
"run_state=WAITING_FOR_TARGET_AVAILABILITY}, Animation{id=45, group=76, "
"target_property_id=5, run_state=WAITING_FOR_TARGET_AVAILABILITY}]}",
player_->ToString());
}
} // namespace
} // namespace cc
......@@ -1002,5 +1002,14 @@ TEST(AnimationTest, InEffectFillModePlayback) {
EXPECT_TRUE(anim->InEffect(TicksFromSecondsF(1.0)));
}
TEST(AnimationTest, ToString) {
EXPECT_EQ(
"Animation{id=42, group=73, target_property_id=1, "
"run_state=WAITING_FOR_TARGET_AVAILABILITY}",
Animation::Create(base::MakeUnique<FakeFloatAnimationCurve>(15), 42, 73,
TargetProperty::OPACITY)
->ToString());
}
} // namespace
} // namespace cc
......@@ -9,6 +9,7 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/strings/stringprintf.h"
#include "cc/animation/animation.h"
#include "cc/animation/animation_id_provider.h"
#include "ui/compositor/float_animation_curve_adapter.h"
......@@ -39,6 +40,7 @@ class Pause : public LayerAnimationElement {
~Pause() override {}
private:
std::string DebugName() const override { return "Pause"; }
void OnStart(LayerAnimationDelegate* delegate) override {}
bool OnProgress(double t, LayerAnimationDelegate* delegate) override {
return false;
......@@ -61,6 +63,9 @@ class InterpolatedTransformTransition : public LayerAnimationElement {
~InterpolatedTransformTransition() override {}
protected:
std::string DebugName() const override {
return "InterpolatedTransformTransition";
}
void OnStart(LayerAnimationDelegate* delegate) override {}
bool OnProgress(double t, LayerAnimationDelegate* delegate) override {
......@@ -92,6 +97,7 @@ class BoundsTransition : public LayerAnimationElement {
~BoundsTransition() override {}
protected:
std::string DebugName() const override { return "BoundsTransition"; }
void OnStart(LayerAnimationDelegate* delegate) override {
start_ = delegate->GetBoundsForAnimation();
}
......@@ -127,6 +133,7 @@ class VisibilityTransition : public LayerAnimationElement {
~VisibilityTransition() override {}
protected:
std::string DebugName() const override { return "VisibilityTransition"; }
void OnStart(LayerAnimationDelegate* delegate) override {
start_ = delegate->GetVisibilityForAnimation();
}
......@@ -161,6 +168,7 @@ class BrightnessTransition : public LayerAnimationElement {
~BrightnessTransition() override {}
protected:
std::string DebugName() const override { return "BrightnessTransition"; }
void OnStart(LayerAnimationDelegate* delegate) override {
start_ = delegate->GetBrightnessForAnimation();
}
......@@ -196,6 +204,7 @@ class GrayscaleTransition : public LayerAnimationElement {
~GrayscaleTransition() override {}
protected:
std::string DebugName() const override { return "GrayscaleTransition"; }
void OnStart(LayerAnimationDelegate* delegate) override {
start_ = delegate->GetGrayscaleForAnimation();
}
......@@ -231,6 +240,7 @@ class ColorTransition : public LayerAnimationElement {
~ColorTransition() override {}
protected:
std::string DebugName() const override { return "ColorTransition"; }
void OnStart(LayerAnimationDelegate* delegate) override {
start_ = delegate->GetColorForAnimation();
}
......@@ -265,6 +275,7 @@ class TemperatureTransition : public LayerAnimationElement {
~TemperatureTransition() override {}
protected:
std::string DebugName() const override { return "TemperatureTransition"; }
void OnStart(LayerAnimationDelegate* delegate) override {
start_ = delegate->GetTemperatureFromAnimation();
}
......@@ -304,6 +315,9 @@ class ThreadedLayerAnimationElement : public LayerAnimationElement {
explicit ThreadedLayerAnimationElement(const LayerAnimationElement& element)
: LayerAnimationElement(element) {
}
std::string DebugName() const override {
return "ThreadedLayerAnimationElement";
}
bool OnProgress(double t, LayerAnimationDelegate* delegate) override {
if (t < 1.0)
......@@ -365,6 +379,7 @@ class ThreadedOpacityTransition : public ThreadedLayerAnimationElement {
~ThreadedOpacityTransition() override {}
protected:
std::string DebugName() const override { return "ThreadedOpacityTransition"; }
void OnStart(LayerAnimationDelegate* delegate) override {
start_ = delegate->GetOpacityForAnimation();
}
......@@ -416,6 +431,9 @@ class ThreadedTransformTransition : public ThreadedLayerAnimationElement {
~ThreadedTransformTransition() override {}
protected:
std::string DebugName() const override {
return "ThreadedTransformTransition";
}
void OnStart(LayerAnimationDelegate* delegate) override {
start_ = delegate->GetTransformForAnimation();
}
......@@ -621,6 +639,21 @@ void LayerAnimationElement::RequestEffectiveStart(
effective_start_time_ = requested_start_time_;
}
std::string LayerAnimationElement::ToString() const {
// TODO(wkorman): Add support for subclasses to tack on more info
// beyond just their name.
return base::StringPrintf(
"LayerAnimationElement{name=%s, id=%d, group=%d, "
"last_progressed_fraction=%0.2f, "
"start_frame_number=%d}",
DebugName().c_str(), animation_id_, animation_group_id_,
last_progressed_fraction_, start_frame_number_);
}
std::string LayerAnimationElement::DebugName() const {
return "Default";
}
// static
LayerAnimationElement::AnimatableProperty
LayerAnimationElement::ToAnimatableProperty(cc::TargetProperty::Type property) {
......@@ -635,6 +668,57 @@ LayerAnimationElement::ToAnimatableProperty(cc::TargetProperty::Type property) {
}
}
// static
std::string LayerAnimationElement::AnimatablePropertiesToString(
AnimatableProperties properties) {
std::string str;
int property_count = 0;
for (unsigned i = FIRST_PROPERTY; i != SENTINEL; i = i << 1) {
if (i & properties) {
LayerAnimationElement::AnimatableProperty property =
static_cast<LayerAnimationElement::AnimatableProperty>(i);
if (property_count > 0)
str.append("|");
// TODO(wkorman): Consider reworking enum definition to follow
// #define pattern that includes easier string output.
switch (property) {
case UNKNOWN:
str.append("UNKNOWN");
break;
case TRANSFORM:
str.append("TRANSFORM");
break;
case BOUNDS:
str.append("BOUNDS");
break;
case OPACITY:
str.append("OPACITY");
break;
case VISIBILITY:
str.append("VISIBILITY");
break;
case BRIGHTNESS:
str.append("BRIGHTNESS");
break;
case GRAYSCALE:
str.append("GRAYSCALE");
break;
case COLOR:
str.append("COLOR");
break;
case TEMPERATURE:
str.append("TEMPERATURE");
break;
case SENTINEL:
NOTREACHED();
break;
}
property_count++;
}
}
return str;
}
// static
base::TimeDelta LayerAnimationElement::GetEffectiveDuration(
const base::TimeDelta& duration) {
......
......@@ -78,6 +78,9 @@ class COMPOSITOR_EXPORT LayerAnimationElement {
virtual ~LayerAnimationElement();
static std::string AnimatablePropertiesToString(
AnimatableProperties properties);
// Creates an element that transitions to the given transform. The caller owns
// the return value.
static std::unique_ptr<LayerAnimationElement> CreateTransformElement(
......@@ -214,7 +217,11 @@ class COMPOSITOR_EXPORT LayerAnimationElement {
// call made to {Progress, ProgressToEnd}.
double last_progressed_fraction() const { return last_progressed_fraction_; }
std::string ToString() const;
protected:
virtual std::string DebugName() const;
// Called once each time the animation element is run before any call to
// OnProgress.
virtual void OnStart(LayerAnimationDelegate* delegate) = 0;
......
......@@ -400,6 +400,20 @@ TEST(LayerAnimationElementTest, AbortTransformElement) {
delegate.GetTransformForAnimation());
}
TEST(LayerAnimationElementTest, ToString) {
float target = 1.0;
base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
std::unique_ptr<LayerAnimationElement> element =
LayerAnimationElement::CreateOpacityElement(target, delta);
element->set_animation_group_id(42);
// TODO(wkorman): Test varying last_progressed_fraction and
// start_frame_number.
EXPECT_EQ(
"LayerAnimationElement{name=ThreadedOpacityTransition, id=1, group=42, "
"last_progressed_fraction=0.00, start_frame_number=0}",
element->ToString());
}
} // namespace
} // namespace ui
......@@ -7,6 +7,7 @@
#include <algorithm>
#include <iterator>
#include "base/strings/stringprintf.h"
#include "base/trace_event/trace_event.h"
#include "cc/animation/animation_id_provider.h"
#include "ui/compositor/layer_animation_delegate.h"
......@@ -290,4 +291,23 @@ LayerAnimationElement* LayerAnimationSequence::CurrentElement() const {
return elements_[current_index].get();
}
std::string LayerAnimationSequence::ElementsToString() const {
std::string str;
for (size_t i = 0; i < elements_.size(); i++) {
if (i > 0)
str.append(", ");
str.append(elements_[i]->ToString());
}
return str;
}
std::string LayerAnimationSequence::ToString() const {
return base::StringPrintf(
"LayerAnimationSequence{size=%zu, properties=%s, "
"elements=[%s], is_cyclic=%d, group_id=%d}",
size(),
LayerAnimationElement::AnimatablePropertiesToString(properties_).c_str(),
ElementsToString().c_str(), is_cyclic_, animation_group_id_);
}
} // namespace ui
......@@ -138,6 +138,8 @@ class COMPOSITOR_EXPORT LayerAnimationSequence
LayerAnimationElement* FirstElement() const;
std::string ToString() const;
private:
friend class LayerAnimatorTestController;
......@@ -146,6 +148,8 @@ class COMPOSITOR_EXPORT LayerAnimationSequence
FRIEND_TEST_ALL_PREFIXES(LayerAnimatorTest,
ObserverReleasedBeforeAnimationSequenceEnds);
std::string ElementsToString() const;
// Notifies the observers that this sequence has been scheduled.
void NotifyScheduled();
......
......@@ -268,6 +268,36 @@ TEST(LayerAnimationSequenceTest, AddObserver) {
}
}
TEST(LayerAnimationSequenceTest, ToString) {
base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
LayerAnimationSequence sequence;
EXPECT_EQ(
"LayerAnimationSequence{size=0, properties=, elements=[], is_cyclic=0, "
"group_id=0}",
sequence.ToString());
sequence.AddElement(
LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
EXPECT_EQ(
"LayerAnimationSequence{size=1, properties=BRIGHTNESS, "
"elements=[LayerAnimationElement{name=BrightnessTransition, id=1, "
"group=0, last_progressed_fraction=0.00, start_frame_number=0}], "
"is_cyclic=0, group_id=0}",
sequence.ToString());
sequence.AddElement(LayerAnimationElement::CreateOpacityElement(1.0f, delta));
sequence.set_is_cyclic(true);
sequence.set_animation_group_id(1973);
EXPECT_EQ(
"LayerAnimationSequence{size=2, properties=OPACITY|BRIGHTNESS, "
"elements=[LayerAnimationElement{name=BrightnessTransition, id=1, "
"group=0, last_progressed_fraction=0.00, start_frame_number=0}, "
"LayerAnimationElement{name=ThreadedOpacityTransition, id=2, group=0, "
"last_progressed_fraction=0.00, start_frame_number=0}], is_cyclic=1, "
"group_id=1973}",
sequence.ToString());
}
} // namespace
} // namespace ui
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