Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detecting screen orientation chage #36

Closed
TheMostDiligent opened this issue Apr 27, 2020 · 5 comments
Closed

Detecting screen orientation chage #36

TheMostDiligent opened this issue Apr 27, 2020 · 5 comments

Comments

@TheMostDiligent
Copy link

Hello!

I was reading an article about surface rotation, and it was very helpful - thank you. However, I am struggling with rotation detection. The article suggests to handle APP_CMD_CONTENT_RECT_CHANGED event, however if you take a look at native_app_glue.c file from the most recent NDK (21.1), you will find out that the event is never generated. Similarly, APP_CMD_WINDOW_RESIZED is also a dead event.
The only one that is really generated is APP_CMD_CONFIG_CHANGED, but this one is very inconsistent: on some devices it is generated before the surface has been rotated, on others - after.
I was trying to compare window dimensions, but, again, on some devices the window size changes before the surface size changes.

I can handle SUBOPTIMAL error code, but I am looking for the method that will also work for GLES.

Thank you!

@PavelRudko-ARM
Copy link

PavelRudko-ARM commented Apr 28, 2020

Hi!
Yes APP_CMD_CONTENT_RECT_CHANGED is not generated by default. This is already reported here and looks like it will work properly in NDK 22.
However, this works:
app->activity->callbacks->onContentRectChanged = on_content_rect_changed;
You can see this in our AndroidPlatform class. In this callback the event APP_CMD_CONTENT_RECT_CHANGED is then dispatched and handled in on_app_cmd.
So try using onContentRectChanged.
Please note, that this repository is now moved to KhronosGroup/Vulkan-Samples.
The tutorial and code was updated, so check out the new repository.
I have also created an issue related to your question.
Hope that helps!

@TheMostDiligent
Copy link
Author

TheMostDiligent commented Apr 28, 2020

@PavelRudko-ARM Thanks, this is very useful! Is APP_CMD_CONTENT_RECT_CHANGED guaranteed to be generated after the surface orientation has actually changed so that the swap chain can be resized?

@TomAtkinsonArm
Copy link
Contributor

Hi @TheMostDiligent, onContentRectChanged Is called when "The rectangle in the window in which content should be placed has changed."

onContentRectChanged is transformed to APP_CMD_CONTENT_RECT_CHANGED by android_native_app_glue.h in ndk version 22+. If you would like to still use APP_CMD_CONTENT_RECT_CHANGED you could always re-implement the ndk 22 version for older versions of the ndk. It would require a check to see if the callback is set, if not then set the re-implemented version :)

@TomAtkinsonArm
Copy link
Contributor

TomAtkinsonArm commented Apr 29, 2020

So to answer your question. When this event fires the Swapchain can be resized

@TomAtkinsonArm
Copy link
Contributor

This said after reviewing both the ndk implementation and the on_content_rect_changed implementation in this project both methods are effectively doing the same thing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants