public static CGGradient create(CGColorSpace space, float[] components, float[] locations) { if (space == null) { throw new NullPointerException("space"); } if (components == null) { throw new NullPointerException("components"); } return create( space, VM.getArrayValuesAddress(CoreGraphics.toMachineSizedFloatArray(components)), locations != null ? VM.getArrayValuesAddress(CoreGraphics.toMachineSizedFloatArray(locations)) : 0, locations != null ? locations.length : 0); }
@MarshalsValue public static Bits<?> toObject(Class<?> cls, long value, long flags) { Bits<?> f = (Bits<?>) VM.allocateObject(cls); f.value = value; f.mask = f.value == 0 ? -1 : f.value; return f; }
public static ObjCClass getByType(Class<? extends ObjCObject> type) { if (type == null) { throw new NullPointerException("type"); } synchronized (typeToClass) { ObjCClass c = typeToClass.get(type); if (c == null) { NativeClass nativeClassAnno = type.getAnnotation(NativeClass.class); String name = null; if (nativeClassAnno != null) { name = nativeClassAnno.value(); name = "".equals(name) ? type.getSimpleName() : name; } else { name = getCustomClassName(type); c = register(type, name); } if (c == null) { long classPtr = ObjCRuntime.objc_getClass(VM.getStringUTFChars(name)); if (classPtr == 0L) { throw new ObjCClassNotFoundException(name); } c = new ObjCClass(classPtr, type, name, false); } typeToClass.put(type, c); nameToClass.put(name, c); } return c; } }
public void replaceRegion( @ByVal MTLRegion region, @MachineSizedUInt long level, byte[] pixelBytes, @MachineSizedUInt long bytesPerRow) { replaceRegion(region, level, VM.getArrayValuesAddress(pixelBytes), bytesPerRow); }
/*</constructors>*/ public NSOutputStream(byte[] bytes) { super((SkipInit) null); if (bytes == null) { throw new NullPointerException("bytes"); } initObject(init(VM.getArrayValuesAddress(bytes), bytes.length)); }
public long write(byte[] bytes, int offset, int length) { NSMutableData.checkOffsetAndCount(bytes.length, offset, length); if (length == 0) { return 0; } return write(VM.getArrayValuesAddress(bytes) + offset, length); }
public byte[] getBytes( int length, @MachineSizedUInt long bytesPerRow, @ByVal MTLRegion region, @MachineSizedUInt long level) { byte[] bytes = new byte[length]; getBytes(VM.getArrayValuesAddress(bytes), bytesPerRow, region, level); return bytes; }
@SuppressWarnings("unchecked") private static ObjCClass register(Class<? extends ObjCObject> type, String name) { ObjCClass superclass = getByType((Class<? extends ObjCObject>) type.getSuperclass()); long handle = ObjCRuntime.objc_allocateClassPair(superclass.getHandle(), VM.getStringUTFChars(name), 0); if (handle == 0L) { throw new ObjCClassNotFoundException( "Failed to create custom Objective-C class for Java class: " + type); } for (Entry<String, Method> entry : getCallbacks(type).entrySet()) { String selName = entry.getKey(); Method method = entry.getValue(); Selector selector = Selector.register(selName); String encoding = null; TypeEncoding typeEncoding = method.getAnnotation(TypeEncoding.class); if (typeEncoding != null) { encoding = typeEncoding.value(); } else { long methodPtr = ObjCRuntime.class_getInstanceMethod(superclass.getHandle(), selector.getHandle()); if (methodPtr != 0L) { long encodingPtr = ObjCRuntime.method_getTypeEncoding(methodPtr); if (encodingPtr != 0L) { encoding = VM.newStringUTF(encodingPtr); } } } long impl = VM.getCallbackMethodImpl(method); if (!ObjCRuntime.class_addMethod( handle, selector.getHandle(), impl, encoding != null ? VM.getStringUTFChars(encoding) : 0L)) { throw new ObjCClassNotFoundException( "Failed to add method " + selName + " to custom Objective-C class for Java class: " + type); } } ObjCRuntime.objc_registerClassPair(handle); return new ObjCClass(handle, type, name, true); }
public static ObjCClass toObjCClass(final long handle) { long classPtr = handle; ObjCClass c = ObjCObject.getPeerObject(classPtr); if (c == null) { c = getByNameNotLoaded(VM.newStringUTF(ObjCRuntime.class_getName(classPtr))); } while (c == null && classPtr != 0L) { classPtr = ObjCRuntime.class_getSuperclass(classPtr); c = ObjCObject.getPeerObject(classPtr); if (c == null) { c = getByNameNotLoaded(VM.newStringUTF(ObjCRuntime.class_getName(classPtr))); } } if (c == null) { String name = VM.newStringUTF(ObjCRuntime.class_getName(handle)); throw new ObjCClassNotFoundException( "Could not find Java class corresponding to Objective-C class: " + name); } return c; }
private static CGGradient create(CGColorSpace space, CGColor[] colors, Object locations) { if (colors == null) { throw new NullPointerException("colors"); } try (CFArray colorsArray = CFArray.create(colors)) { return create( space, colorsArray, locations != null ? VM.getArrayValuesAddress(CoreGraphics.toMachineSizedFloatArray(locations)) : 0); } }
private static CGGradient create(CGColorSpace space, CGColor[] colors, Object locations) { if (colors == null) { throw new NullPointerException("colors"); } try (CFMutableArray colorsArray = CFMutableArray.createMutable(null, colors.length, CoreFoundation.TypeArrayCallBacks())) { for (CGColor c : colors) { colorsArray.appendValue(Struct.toStruct(VoidPtr.class, c.getHandle())); } return create( space, colorsArray, locations != null ? VM.getArrayValuesAddress(CoreGraphics.toMachineSizedFloatArray(locations)) : 0); } }
static { ObjCRuntime.bind(); @SuppressWarnings("unchecked") Class<? extends ObjCObject>[] classes = (Class<? extends ObjCObject>[]) VM.listClasses(ObjCObject.class, ClassLoader.getSystemClassLoader()); for (Class<? extends ObjCObject> cls : classes) { NativeClass nativeClassAnno = cls.getAnnotation(NativeClass.class); if (nativeClassAnno != null) { String name = nativeClassAnno.value(); if (name.length() == 0) { name = cls.getSimpleName(); } allNativeClasses.put(name, cls); } else { CustomClass customClassAnno = cls.getAnnotation(CustomClass.class); String name = cls.getName(); if (customClassAnno != null) { String value = customClassAnno.value(); if (value.length() > 0) { name = value; } } else if (name.indexOf('.') == -1) { name = "." + name; } allCustomClasses.put(name, cls); } if (isObjCProxy(cls)) { // Map protocol interface names to ObjC protocol proxy classes String name = cls.getName(); String protocolName = name.substring(0, name.length() - 10); allObjCProxyClasses.put(protocolName, cls); } } }
/** Returns the VM's version. */ public String vmVersion() { // RoboVM note: This is native Android. return VM.vmVersion(); }
/** Returns the VM's class path. */ public String classPath() { // RoboVM note: This is native Android. return VM.classPath(); }
/** * Returns the address of array[0]. This differs from using JNI in that JNI might lie and give you * the address of a copy of the array when in forcecopy mode. */ public long addressOf(Object array) { // RoboVM note: This is native in Android. return VM.getArrayValuesAddress(array); }
/*</members>*/ public ByteBuffer getContents() { return VM.newDirectByteBuffer(getContents0(), (int) getLength()); }