summaryrefslogtreecommitdiffstats
path: root/ui/compositor
diff options
context:
space:
mode:
authorajuma@chromium.org <ajuma@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-15 15:21:35 +0000
committerajuma@chromium.org <ajuma@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-15 15:21:35 +0000
commitf86eb4c26140ee1dae2ba115d2cdc05d3854d905 (patch)
tree4b17e8b29073d13ebce7c738036da6b00e60e776 /ui/compositor
parent8c912dfcc234786ed8bef10d73917968d2afd330 (diff)
downloadchromium_src-f86eb4c26140ee1dae2ba115d2cdc05d3854d905.zip
chromium_src-f86eb4c26140ee1dae2ba115d2cdc05d3854d905.tar.gz
chromium_src-f86eb4c26140ee1dae2ba115d2cdc05d3854d905.tar.bz2
Define adapters for converting ui::Tweens to cc::AnimationCurves
This is needed for threading ui animations. BUG=164206 Review URL: https://chromiumcodereview.appspot.com/11571063 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176903 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/compositor')
-rw-r--r--ui/compositor/compositor.gyp4
-rw-r--r--ui/compositor/float_animation_curve_adapter.cc44
-rw-r--r--ui/compositor/float_animation_curve_adapter.h37
-rw-r--r--ui/compositor/transform_animation_curve_adapter.cc82
-rw-r--r--ui/compositor/transform_animation_curve_adapter.h42
5 files changed, 209 insertions, 0 deletions
diff --git a/ui/compositor/compositor.gyp b/ui/compositor/compositor.gyp
index 9f9b6a6..13278f8 100644
--- a/ui/compositor/compositor.gyp
+++ b/ui/compositor/compositor.gyp
@@ -35,6 +35,8 @@
'debug_utils.h',
'dip_util.cc',
'dip_util.h',
+ 'float_animation_curve_adapter.cc',
+ 'float_animation_curve_adapter.h',
'layer.cc',
'layer.h',
'layer_animation_delegate.h',
@@ -55,6 +57,8 @@
# UI tests need TestWebGraphicsContext3D, so we always build it.
'test_web_graphics_context_3d.cc',
'test_web_graphics_context_3d.h',
+ 'transform_animation_curve_adapter.cc',
+ 'transform_animation_curve_adapter.h',
],
'conditions': [
['OS == "win" and use_aura == 1', {
diff --git a/ui/compositor/float_animation_curve_adapter.cc b/ui/compositor/float_animation_curve_adapter.cc
new file mode 100644
index 0000000..72949659
--- /dev/null
+++ b/ui/compositor/float_animation_curve_adapter.cc
@@ -0,0 +1,44 @@
+// Copyright (c) 2012 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 "ui/compositor/float_animation_curve_adapter.h"
+
+namespace ui {
+
+FloatAnimationCurveAdapter::FloatAnimationCurveAdapter(
+ Tween::Type tween_type,
+ float initial_value,
+ float target_value,
+ base::TimeDelta duration)
+ : tween_type_(tween_type),
+ initial_value_(initial_value),
+ target_value_(target_value),
+ duration_(duration) {
+}
+
+double FloatAnimationCurveAdapter::duration() const {
+ return duration_.InSecondsF();
+}
+
+scoped_ptr<cc::AnimationCurve> FloatAnimationCurveAdapter::clone() const {
+ scoped_ptr<FloatAnimationCurveAdapter> to_return(
+ new FloatAnimationCurveAdapter(tween_type_,
+ initial_value_,
+ target_value_,
+ duration_));
+ return to_return.PassAs<cc::AnimationCurve>();
+}
+
+float FloatAnimationCurveAdapter::getValue(double t) const {
+ if (t >= duration_.InSecondsF())
+ return target_value_;
+ if (t <= 0.0)
+ return initial_value_;
+ double progress = t / duration_.InSecondsF();
+ return Tween::ValueBetween(Tween::CalculateValue(tween_type_, progress),
+ initial_value_,
+ target_value_);
+}
+
+} // namespace ui
diff --git a/ui/compositor/float_animation_curve_adapter.h b/ui/compositor/float_animation_curve_adapter.h
new file mode 100644
index 0000000..36509ec
--- /dev/null
+++ b/ui/compositor/float_animation_curve_adapter.h
@@ -0,0 +1,37 @@
+// Copyright (c) 2012 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 UI_COMPOSITOR_FLOAT_ANIMATION_CURVE_ADAPTER_H_
+#define UI_COMPOSITOR_FLOAT_ANIMATION_CURVE_ADAPTER_H_
+
+#include "base/time.h"
+#include "cc/animation_curve.h"
+#include "ui/base/animation/tween.h"
+
+namespace ui {
+
+class FloatAnimationCurveAdapter : public cc::FloatAnimationCurve {
+ public:
+ FloatAnimationCurveAdapter(Tween::Type tween_type,
+ float initial_value,
+ float target_value,
+ base::TimeDelta duration);
+
+ virtual ~FloatAnimationCurveAdapter() { }
+
+ // FloatAnimationCurve implementation.
+ virtual double duration() const OVERRIDE;
+ virtual scoped_ptr<cc::AnimationCurve> clone() const OVERRIDE;
+ virtual float getValue(double t) const OVERRIDE;
+
+ private:
+ Tween::Type tween_type_;
+ float initial_value_;
+ float target_value_;
+ base::TimeDelta duration_;
+};
+
+} // namespace ui
+
+#endif // UI_COMPOSITOR_FLOAT_ANIMATION_CURVE_ADAPTER_H_
diff --git a/ui/compositor/transform_animation_curve_adapter.cc b/ui/compositor/transform_animation_curve_adapter.cc
new file mode 100644
index 0000000..5700ffd
--- /dev/null
+++ b/ui/compositor/transform_animation_curve_adapter.cc
@@ -0,0 +1,82 @@
+// Copyright (c) 2012 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 "ui/compositor/transform_animation_curve_adapter.h"
+
+using WebKit::WebTransformationMatrix;
+
+namespace {
+// TODO(ajuma): Remove this once the return type of
+// cc::TransformAnimationCurve::getValue is changed to gfx::Transform.
+WebTransformationMatrix convertTransformToWebTransformationMatrix(
+ const gfx::Transform& transform) {
+ return WebTransformationMatrix(transform.matrix().getDouble(0, 0),
+ transform.matrix().getDouble(1, 0),
+ transform.matrix().getDouble(2, 0),
+ transform.matrix().getDouble(3, 0),
+ transform.matrix().getDouble(0, 1),
+ transform.matrix().getDouble(1, 1),
+ transform.matrix().getDouble(2, 1),
+ transform.matrix().getDouble(3, 1),
+ transform.matrix().getDouble(0, 2),
+ transform.matrix().getDouble(1, 2),
+ transform.matrix().getDouble(2, 2),
+ transform.matrix().getDouble(3, 2),
+ transform.matrix().getDouble(0, 3),
+ transform.matrix().getDouble(1, 3),
+ transform.matrix().getDouble(2, 3),
+ transform.matrix().getDouble(3, 3));
+
+}
+} // namespace
+
+namespace ui {
+
+TransformAnimationCurveAdapter::TransformAnimationCurveAdapter(
+ Tween::Type tween_type,
+ gfx::Transform initial_value,
+ gfx::Transform target_value,
+ base::TimeDelta duration)
+ : tween_type_(tween_type),
+ initial_value_(initial_value),
+ target_value_(target_value),
+ duration_(duration) {
+ gfx::DecomposeTransform(&decomposed_initial_value_, initial_value_);
+ gfx::DecomposeTransform(&decomposed_target_value_, target_value_);
+}
+
+TransformAnimationCurveAdapter::~TransformAnimationCurveAdapter() {
+}
+
+double TransformAnimationCurveAdapter::duration() const {
+ return duration_.InSecondsF();
+}
+
+scoped_ptr<cc::AnimationCurve> TransformAnimationCurveAdapter::clone() const {
+ scoped_ptr<TransformAnimationCurveAdapter> to_return(
+ new TransformAnimationCurveAdapter(tween_type_,
+ initial_value_,
+ target_value_,
+ duration_));
+ return to_return.PassAs<cc::AnimationCurve>();
+}
+
+WebTransformationMatrix TransformAnimationCurveAdapter::getValue(
+ double t) const {
+ if (t >= duration_.InSecondsF())
+ return convertTransformToWebTransformationMatrix(target_value_);
+ if (t <= 0.0)
+ return convertTransformToWebTransformationMatrix(initial_value_);
+ double progress = t / duration_.InSecondsF();
+
+ gfx::DecomposedTransform to_return;
+ gfx::BlendDecomposedTransforms(&to_return,
+ decomposed_initial_value_,
+ decomposed_target_value_,
+ Tween::CalculateValue(tween_type_, progress));
+ return convertTransformToWebTransformationMatrix(
+ gfx::ComposeTransform(to_return));
+}
+
+} // namespace ui
diff --git a/ui/compositor/transform_animation_curve_adapter.h b/ui/compositor/transform_animation_curve_adapter.h
new file mode 100644
index 0000000..073cbfe
--- /dev/null
+++ b/ui/compositor/transform_animation_curve_adapter.h
@@ -0,0 +1,42 @@
+// Copyright (c) 2012 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 UI_COMPOSITOR_TRANSFORM_ANIMATION_CURVE_ADAPTER_H_
+#define UI_COMPOSITOR_TRANSFORM_ANIMATION_CURVE_ADAPTER_H_
+
+#include "base/time.h"
+#include "cc/animation_curve.h"
+#include "ui/base/animation/tween.h"
+#include "ui/gfx/transform.h"
+#include "ui/gfx/transform_util.h"
+
+namespace ui {
+
+class TransformAnimationCurveAdapter :public cc::TransformAnimationCurve {
+ public:
+ TransformAnimationCurveAdapter(Tween::Type tween_type,
+ gfx::Transform intial_value,
+ gfx::Transform target_value,
+ base::TimeDelta duration);
+
+ virtual ~TransformAnimationCurveAdapter();
+
+ // TransformAnimationCurve implementation.
+ virtual double duration() const OVERRIDE;
+ virtual scoped_ptr<AnimationCurve> clone() const OVERRIDE;
+ virtual WebKit::WebTransformationMatrix getValue(double t) const OVERRIDE;
+
+ private:
+ Tween::Type tween_type_;
+ gfx::Transform initial_value_;
+ gfx::Transform target_value_;
+ gfx::DecomposedTransform decomposed_initial_value_;
+ gfx::DecomposedTransform decomposed_target_value_;
+ base::TimeDelta duration_;
+};
+
+} // namespace ui
+
+#endif // UI_COMPOSITOR_TRANSFORM_ANIMATION_CURVE_ADAPTER_H_
+