Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eglQuerySurface gives wrong size

When I rotate my device and my app recieves APP_CMD_CONFIG_CHANGED, I attempt to update my OpenGL viewport with the following:

EGLint width;
EGLint height;
eglQuerySurface(display,surface,EGL_WIDTH,&width);
eglQuerySurface(display,surface,EGL_HEIGHT,&height);

glViewport(0,0,width,height);

MY_LOG_MACRO2("New window size: %d x %d",width,height);

This works about 20% of the time. The other 80% of the time the width and height are the previous values. In other words, most of the time when I turn my device to landscape mode, the portrait size is logged. And when I go back to portrait, the landscape size is logged.

I haven't had much luck with getting the size from the ANativeWindow either.

What should I be doing to get correct window size after rotation?

Update:

By waiting a few frames after APP_CMD_CONFIG_CHANGED, the size is always correct. Querying the size every frame, without regard for APP_CMD_CONFIG_CHANGED, and checking if it has changed seems to work as well but feels wrong.

like image 498
IronMensan Avatar asked Oct 24 '22 23:10

IronMensan


1 Answers

For detecting screen orientation changing I've decided do not catch APP_CMD_CONFIG_CHANGED, but call eglQuerySurface() every frame. If screen size values mismatch saved values, screen orientation has been changed.

Two calls of eglQuerySurface() for getting width and height take about 10 microseconds (100 milliseconds when called 10000 times) so it doesn't reduce performance and it give 100% guarantee that screen rotation will be handled.

I think this solution is better than waiting several frames after APP_CMD_CONFIG_CHANGED. By the way, rotating device to 180 degree (upside down) cause getting APP_CMD_CONFIG_CHANGED event but actually no screen orientation has been changed and no resize-depended actions should be performed.

like image 79
Roman Shuvalov Avatar answered Oct 31 '22 10:10

Roman Shuvalov