Example #1
0
// Convert dart_xform._value[0...3] ==> RSTransform
RSTransform DartConverter<RSTransform>::FromDart(Dart_Handle dart_xform) {
  RSTransform result;
  result.is_null = true;
  if (Dart_IsNull(dart_xform))
    return result;

  Dart_Handle value =
      Dart_GetField(dart_xform, DOMDartState::Current()->value_handle());
  if (Dart_IsNull(value))
    return result;

  Dart_TypedData_Type type;
  float* data = nullptr;
  intptr_t num_elements = 0;
  Dart_TypedDataAcquireData(
      value, &type, reinterpret_cast<void**>(&data), &num_elements);
  DCHECK(!LogIfError(value));
  ASSERT(type == Dart_TypedData_kFloat32 && num_elements == 4);

  SkScalar* dest[] = {
    &result.sk_xform.fSCos,
    &result.sk_xform.fSSin,
    &result.sk_xform.fTx,
    &result.sk_xform.fTy
  };
  for (intptr_t i = 0; i < 4; ++i)
    *dest[i] = data[i];

  Dart_TypedDataReleaseData(value);

  result.is_null = false;
  return result;
}
Example #2
0
// Construct an SkRRect from a Dart RRect object.
// The Dart RRect has a _value field which is a Float32List containing
//   [left, top, right, bottom, xRad, yRad]
RRect DartConverter<RRect>::FromDart(Dart_Handle dart_rrect) {
  RRect result;
  result.is_null = true;
  if (Dart_IsNull(dart_rrect))
    return result;

  Dart_Handle value =
    Dart_GetField(dart_rrect, UIDartState::Current()->value_handle());
  if (Dart_IsNull(value))
    return result;

  Dart_TypedData_Type type;
  float* data = nullptr;
  intptr_t num_elements = 0;
  Dart_TypedDataAcquireData(
      value, &type, reinterpret_cast<void**>(&data), &num_elements);
  DCHECK(!LogIfError(value));
  ASSERT(type == Dart_TypedData_kFloat32 && num_elements == 6);

  result.sk_rrect.setRectXY(
      SkRect::MakeLTRB(data[0], data[1], data[2], data[3]),
      data[4], data[5]);

  Dart_TypedDataReleaseData(value);

  result.is_null = false;
  return result;
}