| 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 exceptionState.throwTypeError( | 109 exceptionState.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 DOMFloat32Array* float32Array, | 118 NotShared<DOMFloat32Array> float32Array, |
| 119 ExceptionState& exceptionState) { | 119 ExceptionState& exceptionState) { |
| 120 if (float32Array->length() != 6 && float32Array->length() != 16) { | 120 if (float32Array.view()->length() != 6 && |
| 121 float32Array.view()->length() != 16) { |
| 121 exceptionState.throwTypeError( | 122 exceptionState.throwTypeError( |
| 122 "The sequence must contain 6 elements for a 2D matrix or 16 elements a " | 123 "The sequence must contain 6 elements for a 2D matrix or 16 elements a " |
| 123 "for 3D matrix."); | 124 "for 3D matrix."); |
| 124 return nullptr; | 125 return nullptr; |
| 125 } | 126 } |
| 126 return new DOMMatrixReadOnly(float32Array->data(), float32Array->length()); | 127 return new DOMMatrixReadOnly(float32Array.view()->data(), |
| 128 float32Array.view()->length()); |
| 127 } | 129 } |
| 128 | 130 |
| 129 DOMMatrixReadOnly* DOMMatrixReadOnly::fromFloat64Array( | 131 DOMMatrixReadOnly* DOMMatrixReadOnly::fromFloat64Array( |
| 130 DOMFloat64Array* float64Array, | 132 NotShared<DOMFloat64Array> float64Array, |
| 131 ExceptionState& exceptionState) { | 133 ExceptionState& exceptionState) { |
| 132 if (float64Array->length() != 6 && float64Array->length() != 16) { | 134 if (float64Array.view()->length() != 6 && |
| 135 float64Array.view()->length() != 16) { |
| 133 exceptionState.throwTypeError( | 136 exceptionState.throwTypeError( |
| 134 "The sequence must contain 6 elements for a 2D matrix or 16 elements " | 137 "The sequence must contain 6 elements for a 2D matrix or 16 elements " |
| 135 "for a 3D matrix."); | 138 "for a 3D matrix."); |
| 136 return nullptr; | 139 return nullptr; |
| 137 } | 140 } |
| 138 return new DOMMatrixReadOnly(float64Array->data(), float64Array->length()); | 141 return new DOMMatrixReadOnly(float64Array.view()->data(), |
| 142 float64Array.view()->length()); |
| 139 } | 143 } |
| 140 | 144 |
| 141 DOMMatrixReadOnly* DOMMatrixReadOnly::fromMatrix( | 145 DOMMatrixReadOnly* DOMMatrixReadOnly::fromMatrix( |
| 142 DOMMatrixInit& other, | 146 DOMMatrixInit& other, |
| 143 ExceptionState& exceptionState) { | 147 ExceptionState& exceptionState) { |
| 144 if (!validateAndFixup(other, exceptionState)) { | 148 if (!validateAndFixup(other, exceptionState)) { |
| 145 DCHECK(exceptionState.hadException()); | 149 DCHECK(exceptionState.hadException()); |
| 146 return nullptr; | 150 return nullptr; |
| 147 } | 151 } |
| 148 | 152 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 point.w() * m44(); | 272 point.w() * m44(); |
| 269 return DOMPoint::create(x, y, z, w); | 273 return DOMPoint::create(x, y, z, w); |
| 270 } | 274 } |
| 271 | 275 |
| 272 DOMMatrixReadOnly::DOMMatrixReadOnly(const TransformationMatrix& matrix, | 276 DOMMatrixReadOnly::DOMMatrixReadOnly(const TransformationMatrix& matrix, |
| 273 bool is2D) { | 277 bool is2D) { |
| 274 m_matrix = TransformationMatrix::create(matrix); | 278 m_matrix = TransformationMatrix::create(matrix); |
| 275 m_is2D = is2D; | 279 m_is2D = is2D; |
| 276 } | 280 } |
| 277 | 281 |
| 278 DOMFloat32Array* DOMMatrixReadOnly::toFloat32Array() const { | 282 NotShared<DOMFloat32Array> DOMMatrixReadOnly::toFloat32Array() const { |
| 279 float array[] = { | 283 float array[] = { |
| 280 static_cast<float>(m_matrix->m11()), static_cast<float>(m_matrix->m12()), | 284 static_cast<float>(m_matrix->m11()), static_cast<float>(m_matrix->m12()), |
| 281 static_cast<float>(m_matrix->m13()), static_cast<float>(m_matrix->m14()), | 285 static_cast<float>(m_matrix->m13()), static_cast<float>(m_matrix->m14()), |
| 282 static_cast<float>(m_matrix->m21()), static_cast<float>(m_matrix->m22()), | 286 static_cast<float>(m_matrix->m21()), static_cast<float>(m_matrix->m22()), |
| 283 static_cast<float>(m_matrix->m23()), static_cast<float>(m_matrix->m24()), | 287 static_cast<float>(m_matrix->m23()), static_cast<float>(m_matrix->m24()), |
| 284 static_cast<float>(m_matrix->m31()), static_cast<float>(m_matrix->m32()), | 288 static_cast<float>(m_matrix->m31()), static_cast<float>(m_matrix->m32()), |
| 285 static_cast<float>(m_matrix->m33()), static_cast<float>(m_matrix->m34()), | 289 static_cast<float>(m_matrix->m33()), static_cast<float>(m_matrix->m34()), |
| 286 static_cast<float>(m_matrix->m41()), static_cast<float>(m_matrix->m42()), | 290 static_cast<float>(m_matrix->m41()), static_cast<float>(m_matrix->m42()), |
| 287 static_cast<float>(m_matrix->m43()), static_cast<float>(m_matrix->m44())}; | 291 static_cast<float>(m_matrix->m43()), static_cast<float>(m_matrix->m44())}; |
| 288 | 292 |
| 289 return DOMFloat32Array::create(array, 16); | 293 return NotShared<DOMFloat32Array>(DOMFloat32Array::create(array, 16)); |
| 290 } | 294 } |
| 291 | 295 |
| 292 DOMFloat64Array* DOMMatrixReadOnly::toFloat64Array() const { | 296 NotShared<DOMFloat64Array> DOMMatrixReadOnly::toFloat64Array() const { |
| 293 double array[] = { | 297 double array[] = { |
| 294 m_matrix->m11(), m_matrix->m12(), m_matrix->m13(), m_matrix->m14(), | 298 m_matrix->m11(), m_matrix->m12(), m_matrix->m13(), m_matrix->m14(), |
| 295 m_matrix->m21(), m_matrix->m22(), m_matrix->m23(), m_matrix->m24(), | 299 m_matrix->m21(), m_matrix->m22(), m_matrix->m23(), m_matrix->m24(), |
| 296 m_matrix->m31(), m_matrix->m32(), m_matrix->m33(), m_matrix->m34(), | 300 m_matrix->m31(), m_matrix->m32(), m_matrix->m33(), m_matrix->m34(), |
| 297 m_matrix->m41(), m_matrix->m42(), m_matrix->m43(), m_matrix->m44()}; | 301 m_matrix->m41(), m_matrix->m42(), m_matrix->m43(), m_matrix->m44()}; |
| 298 | 302 |
| 299 return DOMFloat64Array::create(array, 16); | 303 return NotShared<DOMFloat64Array>(DOMFloat64Array::create(array, 16)); |
| 300 } | 304 } |
| 301 | 305 |
| 302 const String DOMMatrixReadOnly::toString() const { | 306 const String DOMMatrixReadOnly::toString() const { |
| 303 std::stringstream stream; | 307 std::stringstream stream; |
| 304 if (is2D()) { | 308 if (is2D()) { |
| 305 stream << "matrix(" << a() << ", " << b() << ", " << c() << ", " << d() | 309 stream << "matrix(" << a() << ", " << b() << ", " << c() << ", " << d() |
| 306 << ", " << e() << ", " << f(); | 310 << ", " << e() << ", " << f(); |
| 307 } else { | 311 } else { |
| 308 stream << "matrix3d(" << m11() << ", " << m12() << ", " << m13() << ", " | 312 stream << "matrix3d(" << m11() << ", " << m12() << ", " << m13() << ", " |
| 309 << m14() << ", " << m21() << ", " << m22() << ", " << m23() << ", " | 313 << m14() << ", " << m21() << ", " << m22() << ", " << m23() << ", " |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 | 393 |
| 390 m_matrix->makeIdentity(); | 394 m_matrix->makeIdentity(); |
| 391 operations.apply(FloatSize(0, 0), *m_matrix); | 395 operations.apply(FloatSize(0, 0), *m_matrix); |
| 392 | 396 |
| 393 m_is2D = !operations.has3DOperation(); | 397 m_is2D = !operations.has3DOperation(); |
| 394 | 398 |
| 395 return; | 399 return; |
| 396 } | 400 } |
| 397 | 401 |
| 398 } // namespace blink | 402 } // namespace blink |
| OLD | NEW |