Getting ANativeWindowBuffer from ANativeWindow_Buffer

To get quick access to OpenGL ES 2.0 texture pixels on the Android NDK, I want to use the eglCreateImageKHR() extension.

According to the EGL_NATIVE_BUFFER_ANDROID docs :

This extension allows you to use the Android window buffer (struct ANativeWindowBuffer ) as an EGLImage source.

ANativeWindowBuffer is an internal struct used by built-in infrastructure classes such as GraphicBuffer . Unfortunately, since I am in the NDK, I do not have direct access to these classes.

NDK's native_window allows native_window to pass a Java Surface object through the NDK. Then I can use ANativeWindow_fromSurface() to get the opaque handle ANativeWindow* . With this pointer, I can call ANativeWindow_lock() to populate a structure of type ANativeWindow_Buffer (Note _ ).

If I try to use this &ANativeWindow_Buffer object with eglCreateImageKHR() , it fails with EGL_BAD_NATIVE_WINDOW .

My question is: how can I use ANativeWindow_Buffer with eglCreateImageKHR() or, alternatively, how to get ANativeWindowBuffer from ANativeWindow_Buffer or from ANativeWindow* .

+5
source share
1 answer

From what I found out by walking along this road, ANativeWindow_Buffer and ANativeWindowBuffer are completely different types. Well, they are somewhat similar, but definitely so different that they cannot be used interchangeably.

If you want to compare, here are the definitions:

You will notice that they have several common fields ( width , height , stride , format ). The big difference is that ANativeWindow_Buffer contains a pointer to the actual data, and ANativeWindowBuffer contains an opaque handle of type buffer_handle_t .

So, if you learned how to get ANativeWindow_Buffer , and hoped that you were on your way to ANativeWindowBuffer , you ... probably not. At least that was my conclusion. I think very similar names are just teasing.

I have not found a way to create ANativeWindowBuffer from NDK code. At least using only supported APIs, I find this impossible. My research was with KitKat.

+2
source

Source: https://habr.com/ru/post/1209346/


All Articles