mercredi 10 avril 2019

How to create an Object with private creator under Oreo?

This class is defined under Android:

public abstract class EGLObjectHandle {
    private final long mHandle;

    /**
     * @deprecated Use {@link #EGLObjectHandle(long)} instead. Handles
     *     on 64 bit platforms will be wider than java ints.
     */
    @Deprecated
    protected EGLObjectHandle(int handle) {
        mHandle = handle;
    }
    protected EGLObjectHandle(long handle) {
        mHandle = handle;
    }
    /**
     * @deprecated Use {@link #getNativeHandle()} instead. Handles on
     *     64 bit platforms will be wider than java ints.
     */
    @Deprecated
    public int getHandle() {
        if ((mHandle & 0xffffffffL) != mHandle) {
            throw new UnsupportedOperationException();
        }
        return (int)mHandle;
    }
    /**
     * Returns the native handle of the wrapped EGL object. This handle can be
     * cast to the corresponding native type on the native side.
     *
     * For example, EGLDisplay dpy = (EGLDisplay)handle;
     *
     * @return the native handle of the wrapped EGL object.
     */
    public long getNativeHandle() {
        return mHandle;
    }
    @Override
    public int hashCode() {
        /*
         * Based on the algorithm suggested in
         * http://developer.android.com/reference/java/lang/Object.html
         */
        int result = 17;
        result = 31 * result + (int) (mHandle ^ (mHandle >>> 32));
        return result;
    }
}

and also

public class EGLContext extends EGLObjectHandle {
    private EGLContext(long handle) {
        super(handle);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof EGLContext)) return false;

        EGLContext that = (EGLContext) o;
        return getNativeHandle() == that.getNativeHandle();
    }
} 

now my problem is that I want to create an EGLContext with my handle. How to do this? before I do it with the function below but it's not working anymore under Oreo

  private android.opengl.EGLContext createSharedEGLContextObj(long handle) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
    Class<?> classType =Class.forName("android.opengl.EGLContext"); 
    Class<?>[] types = new Class[] { long.class };
    Constructor constructor=classType.getDeclaredConstructor(types);
    constructor.setAccessible(true);     
    Object object=constructor.newInstance(handle);
    return (android.opengl.EGLContext) object;
  }





Aucun commentaire:

Enregistrer un commentaire