summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorajuma@chromium.org <ajuma@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-02 01:52:11 +0000
committerajuma@chromium.org <ajuma@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-02 01:52:11 +0000
commit624034bda56f062a764df57a930c23acb7a223f7 (patch)
treecbb55f113f4eb6f75ff0cb21ade392dab9820d6e
parenta3bca5f30e0148527b5a2268fb2b4457e3c3d88a (diff)
downloadchromium_src-624034bda56f062a764df57a930c23acb7a223f7.zip
chromium_src-624034bda56f062a764df57a930c23acb7a223f7.tar.gz
chromium_src-624034bda56f062a764df57a930c23acb7a223f7.tar.bz2
Cache decomposed transforms used by cc::TransformOperations::Blend.
This prevents wasteful (and expensive) recomputation of the decompositions each time Blend is called. BUG=166561 Review URL: https://chromiumcodereview.appspot.com/12088093 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180230 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--cc/transform_operations.cc52
-rw-r--r--cc/transform_operations.h10
2 files changed, 58 insertions, 4 deletions
diff --git a/cc/transform_operations.cc b/cc/transform_operations.cc
index 0f06639..22054bd 100644
--- a/cc/transform_operations.cc
+++ b/cc/transform_operations.cc
@@ -3,15 +3,22 @@
// found in the LICENSE file.
#include "cc/transform_operations.h"
+#include "ui/gfx/transform_util.h"
#include "ui/gfx/vector3d_f.h"
namespace cc {
-TransformOperations::TransformOperations() {
+TransformOperations::TransformOperations()
+ : decomposed_transform_dirty_(true) {
}
TransformOperations::TransformOperations(const TransformOperations& other) {
operations_ = other.operations_;
+ decomposed_transform_dirty_ = other.decomposed_transform_dirty_;
+ if (!decomposed_transform_dirty_) {
+ decomposed_transform_.reset(
+ new gfx::DecomposedTransform(*other.decomposed_transform_.get()));
+ }
}
TransformOperations::~TransformOperations() {
@@ -62,6 +69,7 @@ void TransformOperations::AppendTranslate(double x, double y, double z) {
to_add.translate.y = y;
to_add.translate.z = z;
operations_.push_back(to_add);
+ decomposed_transform_dirty_ = true;
}
void TransformOperations::AppendRotate(double x, double y, double z,
@@ -74,6 +82,7 @@ void TransformOperations::AppendRotate(double x, double y, double z,
to_add.rotate.axis.z = z;
to_add.rotate.angle = degrees;
operations_.push_back(to_add);
+ decomposed_transform_dirty_ = true;
}
void TransformOperations::AppendScale(double x, double y, double z) {
@@ -84,6 +93,7 @@ void TransformOperations::AppendScale(double x, double y, double z) {
to_add.scale.y = y;
to_add.scale.z = z;
operations_.push_back(to_add);
+ decomposed_transform_dirty_ = true;
}
void TransformOperations::AppendSkew(double x, double y) {
@@ -94,6 +104,7 @@ void TransformOperations::AppendSkew(double x, double y) {
to_add.skew.x = x;
to_add.skew.y = y;
operations_.push_back(to_add);
+ decomposed_transform_dirty_ = true;
}
void TransformOperations::AppendPerspective(double depth) {
@@ -102,6 +113,7 @@ void TransformOperations::AppendPerspective(double depth) {
to_add.type = TransformOperation::TransformOperationPerspective;
to_add.perspective_depth = depth;
operations_.push_back(to_add);
+ decomposed_transform_dirty_ = true;
}
void TransformOperations::AppendMatrix(const gfx::Transform& matrix) {
@@ -109,6 +121,7 @@ void TransformOperations::AppendMatrix(const gfx::Transform& matrix) {
to_add.matrix = matrix;
to_add.type = TransformOperation::TransformOperationMatrix;
operations_.push_back(to_add);
+ decomposed_transform_dirty_ = true;
}
void TransformOperations::AppendIdentity() {
@@ -148,9 +161,40 @@ bool TransformOperations::BlendInternal(const TransformOperations& from,
return true;
}
- *result = Apply();
- gfx::Transform from_transform = from.Apply();
- return result->Blend(from_transform, progress);
+ if (progress <= 0.0) {
+ *result = from.Apply();
+ return true;
+ }
+
+ if (progress >= 1.0) {
+ *result = Apply();
+ return true;
+ }
+
+ if (!ComputeDecomposedTransform() || !from.ComputeDecomposedTransform())
+ return false;
+
+ gfx::DecomposedTransform to_return;
+ if (!gfx::BlendDecomposedTransforms(&to_return,
+ *decomposed_transform_.get(),
+ *from.decomposed_transform_.get(),
+ progress))
+ return false;
+
+ *result = ComposeTransform(to_return);
+ return true;
+}
+
+bool TransformOperations::ComputeDecomposedTransform() const {
+ if (decomposed_transform_dirty_) {
+ if (!decomposed_transform_)
+ decomposed_transform_.reset(new gfx::DecomposedTransform());
+ gfx::Transform transform = Apply();
+ if (!gfx::DecomposeTransform(decomposed_transform_.get(), transform))
+ return false;
+ decomposed_transform_dirty_ = false;
+ }
+ return true;
}
} // namespace cc
diff --git a/cc/transform_operations.h b/cc/transform_operations.h
index 78c7fb5..bd68b7b 100644
--- a/cc/transform_operations.h
+++ b/cc/transform_operations.h
@@ -12,6 +12,10 @@
#include "cc/transform_operation.h"
#include "ui/gfx/transform.h"
+namespace gfx {
+struct DecomposedTransform;
+}
+
namespace cc {
// Transform operations are a decomposed transformation matrix. It can be
@@ -64,6 +68,12 @@ class CC_EXPORT TransformOperations {
gfx::Transform* result) const;
std::vector<TransformOperation> operations_;
+
+ bool ComputeDecomposedTransform() const;
+
+ // For efficiency, we cache the decomposed transform.
+ mutable scoped_ptr<gfx::DecomposedTransform> decomposed_transform_;
+ mutable bool decomposed_transform_dirty_;
};
} // namespace cc