| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/geometry/DOMMatrixReadOnly.h" | 5 #include "core/geometry/DOMMatrixReadOnly.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/V8ObjectBuilder.h" | 7 #include "bindings/core/v8/V8ObjectBuilder.h" |
| 8 #include "core/css/CSSIdentifierValue.h" | 8 #include "core/css/CSSIdentifierValue.h" |
| 9 #include "core/css/CSSToLengthConversionData.h" | 9 #include "core/css/CSSToLengthConversionData.h" |
| 10 #include "core/css/CSSValueList.h" | 10 #include "core/css/CSSValueList.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 if (sequence.size() != 6 && sequence.size() != 16) { | 108 if (sequence.size() != 6 && sequence.size() != 16) { |
| 109 exception_state.ThrowTypeError( | 109 exception_state.ThrowTypeError( |
| 110 "The sequence must contain 6 elements for a 2D matrix or 16 elements " | 110 "The sequence must contain 6 elements for a 2D matrix or 16 elements " |
| 111 "for a 3D matrix."); | 111 "for a 3D matrix."); |
| 112 return nullptr; | 112 return nullptr; |
| 113 } | 113 } |
| 114 return new DOMMatrixReadOnly(sequence, sequence.size()); | 114 return new DOMMatrixReadOnly(sequence, sequence.size()); |
| 115 } | 115 } |
| 116 | 116 |
| 117 DOMMatrixReadOnly* DOMMatrixReadOnly::fromFloat32Array( | 117 DOMMatrixReadOnly* DOMMatrixReadOnly::fromFloat32Array( |
| 118 NotShared<DOMFloat32Array> float32_array, | 118 DOMFloat32Array* float32_array, |
| 119 ExceptionState& exception_state) { | 119 ExceptionState& exception_state) { |
| 120 if (float32_array.View()->length() != 6 && | 120 if (float32_array->length() != 6 && float32_array->length() != 16) { |
| 121 float32_array.View()->length() != 16) { | |
| 122 exception_state.ThrowTypeError( | 121 exception_state.ThrowTypeError( |
| 123 "The sequence must contain 6 elements for a 2D matrix or 16 elements a " | 122 "The sequence must contain 6 elements for a 2D matrix or 16 elements a " |
| 124 "for 3D matrix."); | 123 "for 3D matrix."); |
| 125 return nullptr; | 124 return nullptr; |
| 126 } | 125 } |
| 127 return new DOMMatrixReadOnly(float32_array.View()->Data(), | 126 return new DOMMatrixReadOnly(float32_array->Data(), float32_array->length()); |
| 128 float32_array.View()->length()); | |
| 129 } | 127 } |
| 130 | 128 |
| 131 DOMMatrixReadOnly* DOMMatrixReadOnly::fromFloat64Array( | 129 DOMMatrixReadOnly* DOMMatrixReadOnly::fromFloat64Array( |
| 132 NotShared<DOMFloat64Array> float64_array, | 130 DOMFloat64Array* float64_array, |
| 133 ExceptionState& exception_state) { | 131 ExceptionState& exception_state) { |
| 134 if (float64_array.View()->length() != 6 && | 132 if (float64_array->length() != 6 && float64_array->length() != 16) { |
| 135 float64_array.View()->length() != 16) { | |
| 136 exception_state.ThrowTypeError( | 133 exception_state.ThrowTypeError( |
| 137 "The sequence must contain 6 elements for a 2D matrix or 16 elements " | 134 "The sequence must contain 6 elements for a 2D matrix or 16 elements " |
| 138 "for a 3D matrix."); | 135 "for a 3D matrix."); |
| 139 return nullptr; | 136 return nullptr; |
| 140 } | 137 } |
| 141 return new DOMMatrixReadOnly(float64_array.View()->Data(), | 138 return new DOMMatrixReadOnly(float64_array->Data(), float64_array->length()); |
| 142 float64_array.View()->length()); | |
| 143 } | 139 } |
| 144 | 140 |
| 145 DOMMatrixReadOnly* DOMMatrixReadOnly::fromMatrix( | 141 DOMMatrixReadOnly* DOMMatrixReadOnly::fromMatrix( |
| 146 DOMMatrixInit& other, | 142 DOMMatrixInit& other, |
| 147 ExceptionState& exception_state) { | 143 ExceptionState& exception_state) { |
| 148 if (!ValidateAndFixup(other, exception_state)) { | 144 if (!ValidateAndFixup(other, exception_state)) { |
| 149 DCHECK(exception_state.HadException()); | 145 DCHECK(exception_state.HadException()); |
| 150 return nullptr; | 146 return nullptr; |
| 151 } | 147 } |
| 152 | 148 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 point.w() * m44(); | 268 point.w() * m44(); |
| 273 return DOMPoint::Create(x, y, z, w); | 269 return DOMPoint::Create(x, y, z, w); |
| 274 } | 270 } |
| 275 | 271 |
| 276 DOMMatrixReadOnly::DOMMatrixReadOnly(const TransformationMatrix& matrix, | 272 DOMMatrixReadOnly::DOMMatrixReadOnly(const TransformationMatrix& matrix, |
| 277 bool is2d) { | 273 bool is2d) { |
| 278 matrix_ = TransformationMatrix::Create(matrix); | 274 matrix_ = TransformationMatrix::Create(matrix); |
| 279 is2d_ = is2d; | 275 is2d_ = is2d; |
| 280 } | 276 } |
| 281 | 277 |
| 282 NotShared<DOMFloat32Array> DOMMatrixReadOnly::toFloat32Array() const { | 278 DOMFloat32Array* DOMMatrixReadOnly::toFloat32Array() const { |
| 283 float array[] = { | 279 float array[] = { |
| 284 static_cast<float>(matrix_->M11()), static_cast<float>(matrix_->M12()), | 280 static_cast<float>(matrix_->M11()), static_cast<float>(matrix_->M12()), |
| 285 static_cast<float>(matrix_->M13()), static_cast<float>(matrix_->M14()), | 281 static_cast<float>(matrix_->M13()), static_cast<float>(matrix_->M14()), |
| 286 static_cast<float>(matrix_->M21()), static_cast<float>(matrix_->M22()), | 282 static_cast<float>(matrix_->M21()), static_cast<float>(matrix_->M22()), |
| 287 static_cast<float>(matrix_->M23()), static_cast<float>(matrix_->M24()), | 283 static_cast<float>(matrix_->M23()), static_cast<float>(matrix_->M24()), |
| 288 static_cast<float>(matrix_->M31()), static_cast<float>(matrix_->M32()), | 284 static_cast<float>(matrix_->M31()), static_cast<float>(matrix_->M32()), |
| 289 static_cast<float>(matrix_->M33()), static_cast<float>(matrix_->M34()), | 285 static_cast<float>(matrix_->M33()), static_cast<float>(matrix_->M34()), |
| 290 static_cast<float>(matrix_->M41()), static_cast<float>(matrix_->M42()), | 286 static_cast<float>(matrix_->M41()), static_cast<float>(matrix_->M42()), |
| 291 static_cast<float>(matrix_->M43()), static_cast<float>(matrix_->M44())}; | 287 static_cast<float>(matrix_->M43()), static_cast<float>(matrix_->M44())}; |
| 292 | 288 |
| 293 return NotShared<DOMFloat32Array>(DOMFloat32Array::Create(array, 16)); | 289 return DOMFloat32Array::Create(array, 16); |
| 294 } | 290 } |
| 295 | 291 |
| 296 NotShared<DOMFloat64Array> DOMMatrixReadOnly::toFloat64Array() const { | 292 DOMFloat64Array* DOMMatrixReadOnly::toFloat64Array() const { |
| 297 double array[] = { | 293 double array[] = { |
| 298 matrix_->M11(), matrix_->M12(), matrix_->M13(), matrix_->M14(), | 294 matrix_->M11(), matrix_->M12(), matrix_->M13(), matrix_->M14(), |
| 299 matrix_->M21(), matrix_->M22(), matrix_->M23(), matrix_->M24(), | 295 matrix_->M21(), matrix_->M22(), matrix_->M23(), matrix_->M24(), |
| 300 matrix_->M31(), matrix_->M32(), matrix_->M33(), matrix_->M34(), | 296 matrix_->M31(), matrix_->M32(), matrix_->M33(), matrix_->M34(), |
| 301 matrix_->M41(), matrix_->M42(), matrix_->M43(), matrix_->M44()}; | 297 matrix_->M41(), matrix_->M42(), matrix_->M43(), matrix_->M44()}; |
| 302 | 298 |
| 303 return NotShared<DOMFloat64Array>(DOMFloat64Array::Create(array, 16)); | 299 return DOMFloat64Array::Create(array, 16); |
| 304 } | 300 } |
| 305 | 301 |
| 306 const String DOMMatrixReadOnly::toString() const { | 302 const String DOMMatrixReadOnly::toString() const { |
| 307 std::stringstream stream; | 303 std::stringstream stream; |
| 308 if (is2D()) { | 304 if (is2D()) { |
| 309 stream << "matrix(" << a() << ", " << b() << ", " << c() << ", " << d() | 305 stream << "matrix(" << a() << ", " << b() << ", " << c() << ", " << d() |
| 310 << ", " << e() << ", " << f(); | 306 << ", " << e() << ", " << f(); |
| 311 } else { | 307 } else { |
| 312 stream << "matrix3d(" << m11() << ", " << m12() << ", " << m13() << ", " | 308 stream << "matrix3d(" << m11() << ", " << m12() << ", " << m13() << ", " |
| 313 << m14() << ", " << m21() << ", " << m22() << ", " << m23() << ", " | 309 << m14() << ", " << m21() << ", " << m22() << ", " << m23() << ", " |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 | 389 |
| 394 matrix_->MakeIdentity(); | 390 matrix_->MakeIdentity(); |
| 395 operations.Apply(FloatSize(0, 0), *matrix_); | 391 operations.Apply(FloatSize(0, 0), *matrix_); |
| 396 | 392 |
| 397 is2d_ = !operations.Has3DOperation(); | 393 is2d_ = !operations.Has3DOperation(); |
| 398 | 394 |
| 399 return; | 395 return; |
| 400 } | 396 } |
| 401 | 397 |
| 402 } // namespace blink | 398 } // namespace blink |
| OLD | NEW |