template <typename T> void write_sparse_matrix(T* writer, const SkMatrix& matrix) { SkMatrix::TypeMask tm = matrix.getType(); SkScalar tmp[9]; if (tm & SkMatrix::kPerspective_Mask) { matrix.get9(tmp); writer->write(tmp, 9 * sizeof(SkScalar)); } else if (tm & SkMatrix::kAffine_Mask) { tmp[0] = matrix[SkMatrix::kMScaleX]; tmp[1] = matrix[SkMatrix::kMSkewX]; tmp[2] = matrix[SkMatrix::kMTransX]; tmp[3] = matrix[SkMatrix::kMScaleY]; tmp[4] = matrix[SkMatrix::kMSkewY]; tmp[5] = matrix[SkMatrix::kMTransY]; writer->write(tmp, 6 * sizeof(SkScalar)); } else if (tm & SkMatrix::kScale_Mask) { tmp[0] = matrix[SkMatrix::kMScaleX]; tmp[1] = matrix[SkMatrix::kMTransX]; tmp[2] = matrix[SkMatrix::kMScaleY]; tmp[3] = matrix[SkMatrix::kMTransY]; writer->write(tmp, 4 * sizeof(SkScalar)); } else if (tm & SkMatrix::kTranslate_Mask) { tmp[0] = matrix[SkMatrix::kMTransX]; tmp[1] = matrix[SkMatrix::kMTransY]; writer->write(tmp, 2 * sizeof(SkScalar)); } // else write nothing for Identity }
static void assert9(skiatest::Reporter* reporter, const SkMatrix& m, SkScalar a, SkScalar b, SkScalar c, SkScalar d, SkScalar e, SkScalar f, SkScalar g, SkScalar h, SkScalar i) { SkScalar buffer[9]; m.get9(buffer); REPORTER_ASSERT(reporter, buffer[0] == a); REPORTER_ASSERT(reporter, buffer[1] == b); REPORTER_ASSERT(reporter, buffer[2] == c); REPORTER_ASSERT(reporter, buffer[3] == d); REPORTER_ASSERT(reporter, buffer[4] == e); REPORTER_ASSERT(reporter, buffer[5] == f); REPORTER_ASSERT(reporter, buffer[6] == g); REPORTER_ASSERT(reporter, buffer[7] == h); REPORTER_ASSERT(reporter, buffer[8] == i); }