Exemplo n.º 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;
}
Exemplo n.º 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;
}
Exemplo n.º 3
0
// Convert handle.x,y ==> SkSize.
Offset DartConverter<Offset>::FromDart(Dart_Handle handle) {
  DCHECK(!LogIfError(handle));
  Dart_Handle dx_value =
      Dart_GetField(handle, DOMDartState::Current()->dx_handle());
  Dart_Handle dy_value =
      Dart_GetField(handle, DOMDartState::Current()->dy_handle());
  double dx = 0.0, dy = 0.0;
  Dart_Handle err = Dart_DoubleValue(dx_value, &dx);
  DCHECK(!LogIfError(err));
  err = Dart_DoubleValue(dy_value, &dy);
  DCHECK(!LogIfError(err));

  Offset result;
  result.sk_size.set(dx, dy);
  result.is_null = false;
  return result;
}
Exemplo n.º 4
0
Paint DartConverter<Paint>::FromDart(Dart_Handle dart_paint) {
  Paint result;
  result.is_null = true;
  if (Dart_IsNull(dart_paint))
    return result;

  Dart_Handle value_handle = UIDartState::Current()->value_handle();
  Dart_Handle data = Dart_GetField(dart_paint, value_handle);

  if (Dart_IsInteger(data)) {
    // This is a simple Paint object that just contains a color with
    // anti-aliasing enabled. The data is the color, represented as an
    // int in the same format as SkColor.
    result.sk_paint.setColor(DartConverter<SkColor>::FromDart(data));
    result.sk_paint.setAntiAlias(true);
    result.is_null = false;
    return result;
  }

  DCHECK(Dart_IsList(data));

  intptr_t length;
  Dart_ListLength(data, &length);

  CHECK_EQ(length, kNumberOfPaintFields);
  Dart_Handle values[kNumberOfPaintFields];
  Dart_Handle range_result = Dart_ListGetRange(data, 0, kNumberOfPaintFields,
					       values);
  if (Dart_IsError(range_result)) {
    return result;
  }

  SkPaint& paint = result.sk_paint;

  if (!Dart_IsNull(values[kStyle]))
    paint.setStyle(static_cast<SkPaint::Style>(DartConverter<int>::FromDart(values[kStyle])));
  if (!Dart_IsNull(values[kStrokeWidth]))
    paint.setStrokeWidth(DartConverter<SkScalar>::FromDart(values[kStrokeWidth]));
  if (!Dart_IsNull(values[kStrokeCap]))
    paint.setStrokeCap(static_cast<SkPaint::Cap>(DartConverter<int>::FromDart(values[kStrokeCap])));
  if (!Dart_IsNull(values[kIsAntiAlias]))
    paint.setAntiAlias(DartConverter<bool>::FromDart(values[kIsAntiAlias]));
  if (!Dart_IsNull(values[kColor]))
    paint.setColor(static_cast<SkColor>(DartConverter<int>::FromDart(values[kColor])));
  if (!Dart_IsNull(values[kTransferMode]))
    paint.setXfermodeMode(static_cast<SkXfermode::Mode>(DartConverter<int>::FromDart(values[kTransferMode])));
  if (!Dart_IsNull(values[kColorFilter]))
    paint.setColorFilter(DartConverter<ColorFilter*>::FromDart(values[kColorFilter])->filter());
  if (!Dart_IsNull(values[kMaskFilter]))
    paint.setMaskFilter(DartConverter<MaskFilter*>::FromDart(values[kMaskFilter])->filter());
  if (!Dart_IsNull(values[kFilterQuality]))
    paint.setFilterQuality(static_cast<SkFilterQuality>(DartConverter<int>::FromDart(values[kFilterQuality])));
  if (!Dart_IsNull(values[kShader]))
    paint.setShader(DartConverter<Shader*>::FromDart(values[kShader])->shader());

  result.is_null = false;
  return result;
}
Exemplo n.º 5
0
// Convert handle.x,y ==> SkPoint.
Point DartConverter<Point>::FromDart(Dart_Handle handle) {
  Point result;
  result.is_null = true;

  DCHECK(!LogIfError(handle));

  Dart_Handle x_value =
      Dart_GetField(handle, DOMDartState::Current()->x_handle());
  Dart_Handle y_value =
      Dart_GetField(handle, DOMDartState::Current()->y_handle());

  double x = 0.0, y = 0.0;
  Dart_Handle err = Dart_DoubleValue(x_value, &x);
  DCHECK(!LogIfError(err));
  err = Dart_DoubleValue(y_value, &y);
  DCHECK(!LogIfError(err));
  result.sk_point.set(x, y);
  result.is_null = false;
  return result;
}
gboolean _gdart_marshaller_check_argument_flags(
  GdartBridgeContext *self,
  Dart_Handle element,
    gpointer type,
    const EnumInfoKlass *type_klass,
  Dart_Handle *dart_error_out,
  GError **error)
{
  Dart_Handle base_object_class, temp_result, inner_container, name_handle;
  bool is_proper_type;
  int64_t raw_result;
  base_object_class = gdart_bridge_context_get_base_enum_class(self, dart_error_out, error);
  if (base_object_class == NULL) {
    return false;
  }
  temp_result = Dart_ObjectIsType(element, base_object_class, &is_proper_type);
  if (Dart_IsError(temp_result)) {
    *dart_error_out = temp_result;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    goto error;
  }
  if (!is_proper_type) {
    *dart_error_out = gdart_bridge_context_create_error_handle(self,
                      "%s: received an unexpected base info type", G_STRFUNC);
    g_set_error(error, GDART_ERROR, 1,
                "%s: received an unexpected base info type", G_STRFUNC);
    goto error;
  }
  name_handle = Dart_NewStringFromCString("index");
  if (Dart_IsError(name_handle)) {
    *dart_error_out = name_handle;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    return FALSE;
  }
  inner_container = Dart_GetField(element, name_handle);
  if (Dart_IsError(inner_container)) {
    *dart_error_out = inner_container;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    return FALSE;
  }
  temp_result = Dart_IntegerToInt64(inner_container, &raw_result);
  if (Dart_IsError(temp_result)) {
    *dart_error_out = temp_result;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    return FALSE;
  }
  return TRUE;
error:
  return FALSE;
}
Exemplo n.º 7
0
void VM::loadCinderDartLib()
{
	string script = getCinderDartScript();
	Dart_Handle source = toDart( script );
	CIDART_CHECK( source );

	Dart_Handle cinderDartLib = Dart_LoadLibrary( toDart( "cinder.dart" ), source, 0, 0 );
	if( Dart_IsError( cinderDartLib ) ) {
		throw DartException( string( "failed to load cinder.dart, error message: " ) + Dart_GetError( cinderDartLib ) );
	}

	CIDART_CHECK( Dart_SetNativeResolver( cinderDartLib, Script::resolveNameHandler, NULL ) );

	// finalize any scripts loaded, needs to be done before the libs can be looked up and modified below
	CIDART_CHECK( Dart_FinalizeLoading( false ) );

	// swap in custom _printClosure to enable print() in dart
	Dart_Handle internalLib = Dart_LookupLibrary( toDart( "dart:_internal" ) );
	CIDART_CHECK( internalLib );
	Dart_Handle print = Dart_GetField( cinderDartLib, toDart( "_printClosure" ) );
	CIDART_CHECK( print );
	CIDART_CHECK( Dart_SetField( internalLib, toDart( "_printClosure" ), print ) );
}
gboolean _gdart_marshaller_check_argument_object(
  GdartBridgeContext *self,
  Dart_Handle element,
    gpointer type,
    const ObjectInfoKlass *type_klass,
  Dart_Handle *dart_error_out,
  GError **error)
{
  Dart_Handle base_object_class, temp_result, inner_container, name_handle;
  bool is_proper_type;
  RawPointerContainer* raw_pointer;
  GdartBridgeContextWrappedObject* object_info;
  GObject* object;
  GType gtype;
  GIInfoType object_info_type;
  
  base_object_class = gdart_bridge_context_get_base_object_class(self, dart_error_out, error);
  if (base_object_class == NULL) {
    return false;
  }
  if (Dart_IsNull(element)) {
    return TRUE;
  }
  temp_result = Dart_ObjectIsType(element, base_object_class, &is_proper_type);
  if (Dart_IsError(temp_result)) {
    *dart_error_out = temp_result;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    goto error;
  }
  if (!is_proper_type) {
    *dart_error_out = gdart_bridge_context_create_error_handle(self,
                      "%s: received an unexpected base info type", G_STRFUNC);
    g_set_error(error, GDART_ERROR, 1,
                "%s: received an unexpected base info type", G_STRFUNC);
    goto error;
  }
  name_handle = Dart_NewStringFromCString("_internal");
  if (Dart_IsError(name_handle)) {
    *dart_error_out = name_handle;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    return FALSE;
  }
  inner_container = Dart_GetField(element, name_handle);
  if (Dart_IsError(inner_container)) {
    *dart_error_out = inner_container;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    return FALSE;
  }
  temp_result = Dart_GetNativeInstanceField(inner_container, 0, (intptr_t*) &raw_pointer);
  if (Dart_IsError(temp_result)) {
    *dart_error_out = temp_result;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    return FALSE;
  }
  object_info = (GdartBridgeContextWrappedObject*) raw_pointer->raw_pointer;
  if (!object_info->object_info_klass.get_type(object_info->object_info,
                                               self,
					       &object_info_type,
					       dart_error_out,
					       error))
    return FALSE;
  if (object_info_type != GI_INFO_TYPE_OBJECT) {
    *dart_error_out = gdart_bridge_context_create_error_handle(self,
                      "%s: expected an object but got a struct", G_STRFUNC);
    g_set_error(error, GDART_ERROR, 1,
                "%s: expected an object but got a struct", G_STRFUNC);
    goto error;
  }
  object = (GObject*) object_info->object;
  if (!type_klass->get_gtype(type,
                             self,
			     &gtype,
			     dart_error_out,
			     error))
    return FALSE;
  if (!g_type_is_a(G_OBJECT_TYPE(object), gtype)) {
    *dart_error_out = gdart_bridge_context_create_error_handle(self,
                      "%s: expected an object of one type but got another", G_STRFUNC);
    g_set_error(error, GDART_ERROR, 1,
                "%s: expected an object of one type but got another", G_STRFUNC);
    goto error;
  }
  return TRUE;
error:
  return FALSE;
}
gboolean _gdart_marshaller_check_argument_struct_from_gtype(
  GdartBridgeContext *self,
  Dart_Handle element,
  GType type,
  Dart_Handle *dart_error_out,
  GError **error)
{
  Dart_Handle base_object_class, temp_result, inner_container, name_handle;
  bool is_proper_type;
  RawPointerContainer* raw_pointer;
  GdartBridgeContextWrappedObject* object_info;
  base_object_class = gdart_bridge_context_get_base_object_class(self, dart_error_out, error);
  if (base_object_class == NULL) {
    return false;
  }
  if (Dart_IsNull(element)) {
    return TRUE;
  }
  temp_result = Dart_ObjectIsType(element, base_object_class, &is_proper_type);
  if (Dart_IsError(temp_result)) {
    *dart_error_out = temp_result;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    goto error;
  }
  if (!is_proper_type) {
    *dart_error_out = gdart_bridge_context_create_error_handle(self,
                      "%s: received an unexpected base info type", G_STRFUNC);
    g_set_error(error, GDART_ERROR, 1,
                "%s: received an unexpected base info type", G_STRFUNC);
    goto error;
  }
  name_handle = Dart_NewStringFromCString("_internal");
  if (Dart_IsError(name_handle)) {
    *dart_error_out = name_handle;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    return FALSE;
  }
  inner_container = Dart_GetField(element, name_handle);
  if (Dart_IsError(inner_container)) {
    *dart_error_out = inner_container;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    return FALSE;
  }
  temp_result = Dart_GetNativeInstanceField(inner_container, 0, (intptr_t*) &raw_pointer);
  if (Dart_IsError(temp_result)) {
    *dart_error_out = temp_result;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    return FALSE;
  }
  object_info = (GdartBridgeContextWrappedObject*) raw_pointer->raw_pointer;
  /* TODO: This is super-unreliable because there is no way to trust the gtype
   * given.
   * 
  if (object_info->type != type) {
    *dart_error_out = gdart_bridge_context_create_error_handle(self,
                      "%s: got an argument of the wrong type. This might be due to a problem in the GIR file", G_STRFUNC);
    g_set_error(error, GDART_ERROR, 1,
                "%s: got an argument of the wrong type. This might be due to a problem in the GIR file", G_STRFUNC);
    goto error;
  }
  */
  return TRUE;
error:
  return FALSE;
}