10

I am asking this with reference to an answer for my question at How to improve opengl es display performance in android . I was trying to build the code which uses GraphicBuffer with ndk-r9d. but It is saying GraphicBuffer is not declared in this scope. The same comments for eglCreateImageKHR and glEGLImageTargetTexture2DOES.

I have added EGL/eglext.h and GLES2/gl2ext.h . I tried to include ui/GraphicBuffer.h but it is not taking it. Is there another header file to be added ?

The code given below I have added to avoid use of glTexSubImage2D().

  GraphicBuffer * pGraphicBuffer = new GraphicBuffer(frame_width, frame_height, PIXEL_FORMAT_RGB_565, GraphicBuffer::USAGE_SW_WRITE_OFTEN | GraphicBuffer::USAGE_HW_TEXTURE);

        // Lock the buffer to get a pointer
        unsigned char * pBitmap = NULL;
        pGraphicBuffer->lock(GraphicBuffer::USAGE_SW_WRITE_OFTEN,(void **)&pBitmap);

        // Write 2D image to pBitmap
        memcpy(pBitmap, frame_buffer, frame_width * frame_height * 3);

        // Unlock to allow OpenGL ES to use it
        pGraphicBuffer->unlock();

        EGLClientBuffer ClientBufferAddress = pGraphicBuffer->getNativeBuffer();
        EGLint SurfaceType = EGL_NATIVE_BUFFER_ANDROID;

        // Make an EGL Image at the same address of the native client buffer
        EGLDisplay eglDisplayHandle = eglGetDisplay(EGL_DEFAULT_DISPLAY);

        // Create an EGL Image with these attributes
        EGLint eglImageAttributes[] = {EGL_WIDTH, frame_width, EGL_HEIGHT, frame_height, EGL_MATCH_FORMAT_KHR,  EGL_FORMAT_RGB_565_KHR, EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};

        EGLImageKHR eglImageHandle = eglCreateImageKHR(eglDisplayHandle, EGL_NO_CONTEXT, SurfaceType, ClientBufferAddress, eglImageAttributes);

        // Create a texture and bind it to GL_TEXTURE_2D
/*        EGLint TextureHandle;
        glGenTextures(1, &TextureHandle);
        glBindTexture(GL_TEXTURE_2D, TextureHandle);
*/
        // Attach the EGL Image to the same texture
        glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, eglImageHandle);

What can I do to get it run......

Thanks in advance..

Community
  • 1
  • 1
Kevin K
  • 589
  • 2
  • 7
  • 28
  • 3
    GraphicBuffer.h is not part of the NDK. You need to extract the header from the AOSP sources, and use it with the understanding that this is an internal API that is subject to change between releases. FWIW, http://stackoverflow.com/questions/21151259/ may be relevant. – fadden Apr 24 '14 at 14:46
  • @ fadden Thanks for your reply.. I have asked this question to speed up my video frame display as in my question at http://stackoverflow.com/questions/23131472/how-to-improve-opengl-es-display-performance-in-android. Do you have a solution for it other than graphicBuffer. And how to extract the header from the AOSP sources – Kevin K Apr 25 '14 at 05:08
  • @fadden how can I extract the header from the AOSP sources – Kevin K Apr 25 '14 at 06:47
  • @Gorilla.Maguila Can you give me a suggestion.. – Kevin K Apr 25 '14 at 09:14

3 Answers3

8

I am working on this problem these days, too.

Many blogs said a copy of Android source code is needed to link along with your project. I believe it's more elegant to get function from libui.so in runtime, which is the "alternative approach" mentioned by Aleksandar Stojiljkovic.

I have written a simple library to do that. Here is it.

Eric Fu
  • 83
  • 1
  • 4
1

Unfortunately, it got removed from here but you could get some answers there: http://community.arm.com/groups/arm-mali-graphics/blog/2013/10/24/eglimage--updating-a-texture-without-copying-memory-under-android

In short, you'll need to build Android platform code and create library that would wrap access to GraphicBuffer and required API and build against android code base. As other stated, you'll need to maintain the library...

This is an alternative approach: https://code.google.com/p/chromium/codesearch#chromium/src/third_party/deqp/src/framework/platform/android/tcuAndroidInternals.cpp&l=167

  • 1
    It would really help to add some of the information from the links (even just some quotes). As it is, this is nearly a link-only answer, which is frowned upon and subject to deletion. – Null Oct 05 '15 at 15:36
0

GraphicBuffer is in the namespace android.

Either add:

using namespace android;

or refer to GraphicBuffer with android::GraphicBuffer

Doug Rogers
  • 21
  • 1
  • 3
  • Thanks for your reply. but the namespace is not defined in ndk as i am using native code. Have you tried it... – Kevin K Apr 29 '14 at 04:10
  • It is there. In GraphicBuffer.h you will find: namespace android { class GraphicBufferMapper; – Doug Rogers May 13 '14 at 20:41
  • 1
    @ Doug Rogers Thanks for reply. But GraphicBuffer.h is not part of ndk. And I tried to copy the file to my project but I should copy all the dependednt file too, and that might change in the next android release...... – Kevin K May 14 '14 at 04:19