Search code examples
androidopengl-esandroid-ndkegl

Only some specific display width works when using GraphicBuffer (EGL) in Android NDK


I am trying to replace glReadPixels() with EGL things to make it faster.

Refering to this post, I have successfully make it works in my project. The code of mine is nearly the same with that post.

However, the strange thing is -- The width must be some specific pixels, for example, 384, 640, 720, 1280, etc. If the width I set not among these, the image is actually rendered in some other width among these, so would be distorted if display with cv::Mat, etc.

It looks like Android system make some restrictions on width of EGLImage. Sadly I am not familiar with Android development...

How this happens? How to fix it?

Thanks in advance.


Solution

  • In general system graphics buffers allocated via gralloc are not portable; gralloc allocations are designed to handle lots of system-specifics, such as use of optimal memory layouts for efficient use by video / graphics / display subsystems. In some cases you may even get really invasive effects such as framebuffer compression.

    If I had to guess it sounds like you are not factoring in the surface row stride when reading the image in your application.