// 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; }
// 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; }
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; }
/* Native methods. */ void IfNull(Dart_NativeArguments arguments) { Dart_Handle object = Dart_GetNativeArgument(arguments, 0); if (Dart_IsNull(object)) { Dart_SetReturnValue(arguments, Dart_GetNativeArgument(arguments, 1)); } else { Dart_SetReturnValue(arguments, object); } }
gboolean _gdart_marshaller_check_argument_string(GdartBridgeContext *self, Dart_Handle element, gpointer arg_type, const TypeInfoKlass *arg_type_klass, Dart_Handle *dart_error_out, GError **error) { if (!Dart_IsString(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; } return TRUE; 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); }
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, >ype, 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; }
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; }