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; }
gboolean _gdart_marshaller_check_argument_array(GdartBridgeContext *self, Dart_Handle element, gpointer arg_type, const TypeInfoKlass *arg_type_klass, Dart_Handle *dart_error_out, GError **error) { gint fixed_length = 0; gboolean is_zero_terminated; if (!arg_type_klass->get_array_fixed_size(arg_type, self, &fixed_length, dart_error_out, error)) return FALSE; if (!arg_type_klass->is_zero_terminated(arg_type, self, &is_zero_terminated, dart_error_out, error)) return FALSE; if (fixed_length == -1 && !is_zero_terminated) { *dart_error_out = gdart_bridge_context_create_error_handle(self, "%s: the array did not have a fixed size or a null termination so I can't handle it", G_STRFUNC); g_set_error(error, GDART_ERROR, 1, "%s: the array did not have a fixed size or a null termination so I can't handle it", G_STRFUNC); goto error; } if (!Dart_IsList(element) && !Dart_IsNull(element)) { *dart_error_out = gdart_bridge_context_create_error_handle(self, "%s: expected string or null", G_STRFUNC); g_set_error(error, GDART_ERROR, 1, "%s: expected string or null", G_STRFUNC); goto error; } if (Dart_IsNull(element) && fixed_length == -1) return TRUE; return _gdart_marshaller_check_argument_in_array_parameters(self, element, arg_type, arg_type_klass, fixed_length, dart_error_out, error); error: return FALSE; }
gboolean _gdart_marshaller_check_argument_in_array(GdartBridgeContext *self, Dart_Handle dart_args, gint *dartarg_i, gpointer arg_type, const TypeInfoKlass *arg_type_klass, gint garg_i, Dart_Handle *dart_error_out, GError **error) { Dart_Handle element; gint arg_to_suppress, fixed_length = 0; gboolean is_zero_terminated; if (!arg_type_klass->get_array_length(arg_type, self, &arg_to_suppress, dart_error_out, error)) return FALSE; if (!arg_type_klass->get_array_fixed_size(arg_type, self, &fixed_length, dart_error_out, error)) return FALSE; if (!arg_type_klass->is_zero_terminated(arg_type, self, &is_zero_terminated, dart_error_out, error)) return FALSE; if (arg_to_suppress == -1 && fixed_length == -1 && !is_zero_terminated) { *dart_error_out = gdart_bridge_context_create_error_handle(self, "%s: the array did not have a length, a fixed size or a null termination so I can't handle it", G_STRFUNC); g_set_error(error, GDART_ERROR, 1, "%s: the array did not have a length, a fixed size or a null termination so I can't handle it", G_STRFUNC); return FALSE; } element = Dart_ListGetAt(dart_args, (*dartarg_i)++); if (Dart_IsError(element)) { *dart_error_out = element; g_set_error(error, GDART_ERROR, 1, "Error from Dart operation."); return FALSE; } if (!Dart_IsList(element) && !Dart_IsNull(element)) { *dart_error_out = gdart_bridge_context_create_error_handle(self, "%s: expected string or null", G_STRFUNC); g_set_error(error, GDART_ERROR, 1, "%s: expected string or null", G_STRFUNC); return FALSE; } if (Dart_IsNull(element) && fixed_length == -1) return TRUE; return _gdart_marshaller_check_argument_in_array_parameters(self, element, arg_type, arg_type_klass, fixed_length, dart_error_out, error); }