1
\$\begingroup\$

On every single android device {emulators} from ldpi to xxhdpi, both DisplayMetrics and native JNI EGL return width:320 and height:526. Even on actual HTC ONE mobile it returns something like 320x526. This is annoying. I need to know the exact pixel dimensions of the GL rendering surface {framebuffer/renderbuffer etc}. How can I do that ?

From Java activity class I am doing:

DisplayMetrics metrics = getResources().getDisplayMetrics();        
int widthPixels = metrics.widthPixels;
int heightPixels = metrics.heightPixels;

From the JNI C++ code I am going following with NO luck (again output: Size = 320 x 526):

int W, H;
EGLDisplay display = eglGetCurrentDisplay();
EGLSurface surface = eglGetCurrentSurface(EGL_READ);
eglQuerySurface(display, surface, EGL_WIDTH, &W);
eglQuerySurface(display, surface, EGL_HEIGHT, &H);

LOGI("JNIGlue.cpp:Init:EGL-Width : %d", W);
LOGI("JNIGlue.cpp:Init:EGL-Height: %d", H);

glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &W);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &H);

LOGI("JNIGlue.cpp:Init:RB-Width : %d", W);
LOGI("JNIGlue.cpp:Init:RB-Height: %d", H);

So how do I get the exact OpenGL rendering surface/buffer size ?

\$\endgroup\$
1
  • \$\begingroup\$ If EGL was initialized properly then eglQuerySurface should return the correct result. Any chance you have a layout xml with a scaled size that might be restricting your window resolution? \$\endgroup\$ Jan 22, 2015 at 15:08

2 Answers 2

2
\$\begingroup\$

Not sure about doing it with JNI/C++ but in Java I just query the GLSurfaceView for it's size with surface.getWidth() and surface.getHeight(). This provides the exact pixel dimensions of the view/surface.

\$\endgroup\$
-1
\$\begingroup\$

Does this work for you ?

    sp<IBinder> mainDpy = SurfaceComposerClient::getBuiltInDisplay(
                        ISurfaceComposer::eDisplayIdMain);
    DisplayInfo mainDpyInfo;
    err = SurfaceComposerClient::getDisplayInfo(mainDpy,
                                                &mainDpyInfo);

Essentially what we are doing here is:

  1. Getting a reference to the built in display (main screen) in the form of a binder (a mechanism for IPC)

  2. Then we query the display subsystem about the properties of the display that we queried in Step 1. This returns the data in the form of a structure DisplayInfo which has the following members:

    struct DisplayInfo { uint32_t w; uint32_t h; PixelFormatInfo pixelFormatInfo; uint8_t orientation; uint8_t reserved[3]; float fps; float density; float xdpi; float ydpi; };

You should have the info you require. See this

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Could you explain what your actually doing, here, and why it should work? \$\endgroup\$
    – Gnemlock
    Jun 13, 2017 at 7:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .