Question

I want to feed buffer of the surface from Native code. So I get the surface from SurfaceView's SurfaceHolder's getSurface method. Now all I want is to use it from the native to feed buffer to render image. I have included SurfaceClinger/Surface.h. But when I try to get mSurface property, it throws error saying java.lang.NoSuchFieldException for mSurface. Any suggestion in this regard will be helpful.

code snippet:

Surface       mSurface;
SurfaceHolder mSurfaceHolder;

mSurface = mSurfaceHolder.getSurface();

try{
    class myClass = mSurface.getClass();
    String fieldName = "mSurface";
    Field field = myClass.getDeclaredField(fieldName);
    field.setAccesssible(true);
    int surfacePtr = field.getInt(mSurface);
    nativeInterface.DrawOnSurface(surfacePtr);
}
catch(Exception ex){}

Thanks.

Was it helpful?

Solution

From gingerbread onwards, the field name is different. By replacing fieldname from 'mSurface' to 'mNativeSurface' the problem is solved. for froyo and below 'mSurface' will work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top