Пример #1
0
 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);
 }
Пример #2
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;
 }
Пример #3
0
 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;
   }
 }
Пример #4
0
 public void replaceRegion(
     @ByVal MTLRegion region,
     @MachineSizedUInt long level,
     byte[] pixelBytes,
     @MachineSizedUInt long bytesPerRow) {
   replaceRegion(region, level, VM.getArrayValuesAddress(pixelBytes), bytesPerRow);
 }
Пример #5
0
 /*</constructors>*/
 public NSOutputStream(byte[] bytes) {
   super((SkipInit) null);
   if (bytes == null) {
     throw new NullPointerException("bytes");
   }
   initObject(init(VM.getArrayValuesAddress(bytes), bytes.length));
 }
Пример #6
0
 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);
 }
Пример #7
0
 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;
 }
Пример #8
0
 @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);
 }
Пример #9
0
 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;
 }
Пример #10
0
 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);
   }
 }
Пример #11
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);
   }
 }
Пример #12
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);
      }
    }
  }
Пример #13
0
 /** Returns the VM's version. */
 public String vmVersion() {
   // RoboVM note: This is native Android.
   return VM.vmVersion();
 }
Пример #14
0
 /** Returns the VM's class path. */
 public String classPath() {
   // RoboVM note: This is native Android.
   return VM.classPath();
 }
Пример #15
0
 /**
  * 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);
 }
Пример #16
0
 /*</members>*/
 public ByteBuffer getContents() {
   return VM.newDirectByteBuffer(getContents0(), (int) getLength());
 }