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

Android: bug in getSafeAreaRect calculations #1876

Closed
crazyhappygame opened this issue May 2, 2024 · 5 comments · Fixed by #1934
Closed

Android: bug in getSafeAreaRect calculations #1876

crazyhappygame opened this issue May 2, 2024 · 5 comments · Fixed by #1934
Labels
help wanted Extra attention is needed

Comments

@crazyhappygame
Copy link
Contributor

  • axmol version: 2.1.2
  • devices test on: Motorolla g54, Xiaomi Pro 12
  • developing environments
    • NDK version: r23c
    • Xcode version: 14.2+
    • Visual Studio:
      • VS version: 2022 (17.9+)
      • MSVC version: 19.39+
      • Windows SDK version: 10.0.22621.0+
    • cmake version:
      Steps to Reproduce:
  1. Draw auto safeAreaRect = _director->getSafeAreaRect();
  2. Bug: safeAreaRect does not take into account corners at the bottom of screen.

Please check screenshots below. Blue rectangle it is safeAreaRect. For Android devices with rounded corners blue is not drawn properly.

Android incorrect: moto G54 (the same issue on other Android devices with rounded corners)
WhatsApp Image 2024-05-02 at 22 02 29

IPhone correct: iPhone Max Pro 15
WhatsApp Image 2024-05-02 at 21 58 32

@rh101
Copy link
Contributor

rh101 commented May 3, 2024

Have you checked the Rect GLViewImpl::getSafeAreaRect() method in GLViewImpl-android.cpp when running on a device with rounded corners to see what is going on in there? Check if this line is returning true:
bool isScreenRound = JniHelper::callStaticBooleanMethod("org/axmol/lib/AxmolEngine", "isScreenRound");
Never mind, this is only for wearable devices.

@halx99 halx99 added the help wanted Extra attention is needed label May 5, 2024
@rh101
Copy link
Contributor

rh101 commented May 27, 2024

@crazyhappygame I just had a look at this, and on creating a new project, and displaying this on an Android device with rounded corners, and the result seems correct:
image

There is no information in your initial post regarding how you set up the resolution policy, or any sample code, so there is nothing to go off in order to reproduce the issue quickly. The above screenshot was taken with a the resolution policy set to ResolutionPolicy::SHOW_ALL.

@rh101
Copy link
Contributor

rh101 commented May 27, 2024

When using ResolutionPolicy::EXACT_FIT, this is the result:
image

It does go into the rounded corners on the right, which isn't optimal, but, it turns out that there is currently no way to determine if a device has rounded corners on Android. The left side of that screenshot is inset correctly because of the cutout (where the camera is etc.).

https://stackoverflow.com/a/50205832/1664652
https://developer.android.com/develop/ui/views/layout/display-cutout

The suggestion is that you have a list of device names and adjust the sizing based on that, which you can do in your own project as you come across more devices with the issue.

Alternatively, set a fixed cut-out size so it doesn't go all the way to the edge of the screen, regardless of what type of screen it is, assuming most screen released these days have rounded corners. This is the method I personally use for getting around this issue.

This is not a bug in Axmol.

@crazyhappygame
Copy link
Contributor Author

I used FIXED_WIDTH.
I think that safe area computation should be correct for all resolution policies.

Maybe we can use this:
https://developer.android.com/reference/android/view/WindowInsets#getRoundedCorner(int)

@rh101
Copy link
Contributor

rh101 commented May 28, 2024

I used FIXED_WIDTH. I think that safe area computation should be correct for all resolution policies.

Maybe we can use this: https://developer.android.com/reference/android/view/WindowInsets#getRoundedCorner(int)

This applies to API31 (Android12) or higher, and it's not as straightforward as it may seem. An attempt to utilize this is in PR #1934, so try it out when you can, and let me know if it works for you. I've tested all ResolutionPolicy types on it, and the safe area is correct on all when using the changes in that PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants