ANativeWindow_acquire usage

803 views
Skip to first unread message

Ratamovic

unread,
May 19, 2014, 7:22:51 PM5/19/14
to andro...@googlegroups.com
Hi all,

There is a function ANativeWindow_acquire in native_window.h that allows acquiring a reference to an Android Surface. However, I never see it called in the NDK samples except the native-media-jni example which uses ANativeWindow_fromSurface() (which itself acquires a reference).

So when should acquire() be used and when it is not required? What's the right practice, more specifically when using the window given to NativeActivity?

Thanks in advance.

Philippe Simons

unread,
May 20, 2014, 3:17:17 AM5/20/14
to android-ndk
ANativeWindow_acquire is for access to the Surface pixel buffer.
It can be used if you want to draw something by "editing" the buffer.

If you want to draw something using OGLES, you don't have to use this function.


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-ndk.
For more options, visit https://groups.google.com/d/optout.

Ratamovic

unread,
May 20, 2014, 5:25:31 AM5/20/14
to andro...@googlegroups.com
Hi Philippe,

Thanks for your answer. Actually I'm not really interested in OpenGL ES, just in understanding the ANativeWindow API :-).
Are you talking about ANativeWindow_acquire or ANativeWindow_lock?

Because I agree that ANativeWindow_lock gives access to the surface.
But
ANativeWindow_acquire seems to only increment the reference counter. But it doesn't seem "required" as I don't see it often used, for example, with the window given by a NativeActivity.
The only example I found is in the native-media-jni.

Is it a bad practice not to use it? Or are there some cases were it is really not needed? (I guess the answer is when we have a guarantee the Surface will be released after native code has done its job... But when does this kind of cases happens?)

Thanks again.

J Decker

unread,
May 20, 2014, 5:39:36 AM5/20/14
to andro...@googlegroups.com
I'll toss out, I don't think it's required.
Only api I use is get with/height/format and set width/height/format then when I'm drawing, lock and postandupdate.
Think the aquire is more for internal use (part of the nativeactivity setup)
Reply all
Reply to author
Forward
0 new messages