OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/transform_operations.h" |
| 6 |
| 7 using WebKit::WebTransformationMatrix; |
| 8 |
| 9 namespace cc { |
| 10 |
| 11 TransformOperations::TransformOperations() { |
| 12 } |
| 13 |
| 14 TransformOperations::TransformOperations(const TransformOperations& other) { |
| 15 operations_ = other.operations_; |
| 16 } |
| 17 |
| 18 TransformOperations::~TransformOperations() { |
| 19 } |
| 20 |
| 21 WebTransformationMatrix TransformOperations::Apply() const { |
| 22 WebTransformationMatrix to_return; |
| 23 for (size_t i = 0; i < operations_.size(); ++i) |
| 24 to_return.multiply(operations_[i].matrix); |
| 25 return to_return; |
| 26 } |
| 27 |
| 28 WebTransformationMatrix TransformOperations::Blend( |
| 29 const TransformOperations& from, double progress) const { |
| 30 WebTransformationMatrix to_return; |
| 31 BlendInternal(from, progress, to_return); |
| 32 return to_return; |
| 33 } |
| 34 |
| 35 bool TransformOperations::MatchesTypes(const TransformOperations& other) const { |
| 36 if (IsIdentity() || other.IsIdentity()) |
| 37 return true; |
| 38 |
| 39 if (operations_.size() != other.operations_.size()) |
| 40 return false; |
| 41 |
| 42 for (size_t i = 0; i < operations_.size(); ++i) { |
| 43 if (operations_[i].type != other.operations_[i].type |
| 44 && !operations_[i].IsIdentity() |
| 45 && !other.operations_[i].IsIdentity()) |
| 46 return false; |
| 47 } |
| 48 |
| 49 return true; |
| 50 } |
| 51 |
| 52 bool TransformOperations::CanBlendWith( |
| 53 const TransformOperations& other) const { |
| 54 WebTransformationMatrix dummy; |
| 55 return BlendInternal(other, 0.5, dummy); |
| 56 } |
| 57 |
| 58 void TransformOperations::AppendTranslate(double x, double y, double z) { |
| 59 TransformOperation to_add; |
| 60 to_add.matrix.translate3d(x, y, z); |
| 61 to_add.type = TransformOperation::TransformOperationTranslate; |
| 62 to_add.translate.x = x; |
| 63 to_add.translate.y = y; |
| 64 to_add.translate.z = z; |
| 65 operations_.push_back(to_add); |
| 66 } |
| 67 |
| 68 void TransformOperations::AppendRotate(double x, double y, double z, |
| 69 double degrees) { |
| 70 TransformOperation to_add; |
| 71 to_add.matrix.rotate3d(x, y, z, degrees); |
| 72 to_add.type = TransformOperation::TransformOperationRotate; |
| 73 to_add.rotate.axis.x = x; |
| 74 to_add.rotate.axis.y = y; |
| 75 to_add.rotate.axis.z = z; |
| 76 to_add.rotate.angle = degrees; |
| 77 operations_.push_back(to_add); |
| 78 } |
| 79 |
| 80 void TransformOperations::AppendScale(double x, double y, double z) { |
| 81 TransformOperation to_add; |
| 82 to_add.matrix.scale3d(x, y, z); |
| 83 to_add.type = TransformOperation::TransformOperationScale; |
| 84 to_add.scale.x = x; |
| 85 to_add.scale.y = y; |
| 86 to_add.scale.z = z; |
| 87 operations_.push_back(to_add); |
| 88 } |
| 89 |
| 90 void TransformOperations::AppendSkew(double x, double y) { |
| 91 TransformOperation to_add; |
| 92 to_add.matrix.skewX(x); |
| 93 to_add.matrix.skewY(y); |
| 94 to_add.type = TransformOperation::TransformOperationSkew; |
| 95 to_add.skew.x = x; |
| 96 to_add.skew.y = y; |
| 97 operations_.push_back(to_add); |
| 98 } |
| 99 |
| 100 void TransformOperations::AppendPerspective(double depth) { |
| 101 TransformOperation to_add; |
| 102 to_add.matrix.applyPerspective(depth); |
| 103 to_add.type = TransformOperation::TransformOperationPerspective; |
| 104 to_add.perspective_depth = depth; |
| 105 operations_.push_back(to_add); |
| 106 } |
| 107 |
| 108 void TransformOperations::AppendMatrix(const WebTransformationMatrix& matrix) { |
| 109 TransformOperation to_add; |
| 110 to_add.matrix = matrix; |
| 111 to_add.type = TransformOperation::TransformOperationMatrix; |
| 112 operations_.push_back(to_add); |
| 113 } |
| 114 |
| 115 void TransformOperations::AppendIdentity() { |
| 116 operations_.push_back(TransformOperation()); |
| 117 } |
| 118 |
| 119 bool TransformOperations::IsIdentity() const { |
| 120 for (size_t i = 0; i < operations_.size(); ++i) { |
| 121 if (!operations_[i].IsIdentity()) |
| 122 return false; |
| 123 } |
| 124 return true; |
| 125 } |
| 126 |
| 127 bool TransformOperations::BlendInternal(const TransformOperations& from, |
| 128 double progress, |
| 129 WebTransformationMatrix& result) const { |
| 130 bool from_identity = from.IsIdentity(); |
| 131 bool to_identity = IsIdentity(); |
| 132 if (from_identity && to_identity) |
| 133 return true; |
| 134 |
| 135 if (MatchesTypes(from)) { |
| 136 size_t num_operations = |
| 137 std::max(from_identity ? 0 : from.operations_.size(), |
| 138 to_identity ? 0 : operations_.size()); |
| 139 for (size_t i = 0; i < num_operations; ++i) { |
| 140 WebTransformationMatrix blended; |
| 141 if (!TransformOperation::BlendTransformOperations( |
| 142 from_identity ? 0 : &from.operations_[i], |
| 143 to_identity ? 0 : &operations_[i], |
| 144 progress, |
| 145 blended)) |
| 146 return false; |
| 147 result.multiply(blended); |
| 148 } |
| 149 return true; |
| 150 } |
| 151 |
| 152 result = Apply(); |
| 153 WebTransformationMatrix from_transform = from.Apply(); |
| 154 return result.blend(from_transform, progress); |
| 155 } |
| 156 |
| 157 } // namespace cc |
OLD | NEW |