Adam Barth 8cf43b65d2 Moves from vector_math to vector_math_64
* Moves from vector_math to vector_math_64
* Adds support for Float64List in Dart bindings
2015-10-01 14:46:13 -07:00

40 lines
1.1 KiB
C++

// Copyright 2015 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 "sky/engine/core/painting/Matrix.h"
namespace blink {
// Mappings from SkMatrix-index to input-index.
static const int kSkMatrixIndexToMatrix4Index[] = {
0, 4, 12,
1, 5, 13,
3, 7, 15,
};
SkMatrix toSkMatrix(const Float64List& matrix4, ExceptionState& es)
{
ASSERT(matrix4.data());
SkMatrix sk_matrix;
if (matrix4.num_elements() != 16) {
es.ThrowTypeError("Incorrect number of elements in matrix.");
return sk_matrix;
}
for (intptr_t i = 0; i < 9; ++i)
sk_matrix[i] = matrix4[kSkMatrixIndexToMatrix4Index[i]];
return sk_matrix;
}
Float64List toMatrix4(const SkMatrix& sk_matrix)
{
Float64List matrix4(Dart_NewTypedData(Dart_TypedData_kFloat64, 16));
for (intptr_t i = 0; i < 9; ++i)
matrix4[kSkMatrixIndexToMatrix4Index[i]] = sk_matrix[i];
matrix4[10] = 1.0; // Identity along the z axis.
return matrix4;
}
} // namespace blink