How to transfer Surface object to native c++ to be used by ANativeWindow_fromSurface ?

142 views
Skip to first unread message

Mark Hong

unread,
Aug 18, 2021, 10:33:47 AM8/18/21
to Java Native Access
My Android App need to show video using native c++ code.  So I want to transfer a Surface (which is returned from SurfaceView.getHolder().getSurface()) to the native c++ function.

I have search and find there too many examples using JNI like this:
static JNICALL setDisplaySurface(JNIEnv* env, jobject obj, jobject jsurface) {
        ........
}

win = ANativeWindow_fromSurface(get_jni_env(), (jobject)surface);

the 2nd param of ANativeWindow_fromSurface is as of type jobject. 

But  I can't find one using JNA, so frustrated.

How to do it using JNA ?

tnanks

Mark Hong

unread,
Aug 19, 2021, 8:28:48 PM8/19/21
to Java Native Access
It seems that can use OPTION_ALLOW_OBJECTS to solve this. Is there some code snippet ?
thanks

Matthias Bläsing

unread,
Aug 20, 2021, 2:04:34 PM8/20/21
to jna-...@googlegroups.com
Hi,

Am Donnerstag, dem 19.08.2021 um 17:28 -0700 schrieb 'Mark Hong' via Java Native Access:
> It seems that can use OPTION_ALLOW_OBJECTS to solve this. Is theres ome
> code snippet ?
> thanks
>

the unittests of JNA hav test code:

https://github.com/java-native-access/jna/blob/5ac61611f3c4a74ca3c6ed05c4ffafd7c6070e30/test/com/sun/jna/ReturnTypesTest.java#L154-L177
https://github.com/java-native-access/jna/blob/5ac61611f3c4a74ca3c6ed05c4ffafd7c6070e30/native/testlib.c#L271-L274

HTH

Matthias

Reply all
Reply to author
Forward
0 new messages