diff --git a/changelog.md b/changelog.md index d86b98d8c..cdfcf327a 100644 --- a/changelog.md +++ b/changelog.md @@ -166,6 +166,8 @@ For a closer look at breaking changes and how to migrate from SFML 2, check out - [Android] Removed use of deprecated `ALooper_pollAll` (#3181, #3189) - [macOS] Fix how macOS fullscreen video modes are detected (#2300, #3151) - [macOS] Prevent unnecessary macOS input monitoring permission prompts (#2843, #3235) +- [Linux] Fix DRM mode setting to use SFML window dimensions (#3136) +- [Android] Fix wrong fullscreen resolution (#1349, #1559, #2396) ### Graphics diff --git a/src/SFML/Main/MainAndroid.cpp b/src/SFML/Main/MainAndroid.cpp index 49a01c6fb..04b2feed5 100644 --- a/src/SFML/Main/MainAndroid.cpp +++ b/src/SFML/Main/MainAndroid.cpp @@ -221,6 +221,53 @@ void getScreenSizeInPixels(ANativeActivity& activity, int& width, int& height) height = lJNIEnv->GetIntField(objectDisplayMetrics, fieldHeightPixels); } + +//////////////////////////////////////////////////////////// +void getFullScreenSizeInPixels(ANativeActivity& activity, int& width, int& height) +{ + // Perform the following Java code: + // + // DisplayMetrics dm = new DisplayMetrics(); + // getWindowManager().getDefaultDisplay().getRealMetrics(dm); + + JNIEnv* lJNIEnv = activity.env; + + jobject objectActivity = activity.clazz; + jclass classActivity = lJNIEnv->GetObjectClass(objectActivity); + + jclass classDisplayMetrics = lJNIEnv->FindClass("android/util/DisplayMetrics"); + jmethodID initDisplayMetrics = lJNIEnv->GetMethodID(classDisplayMetrics, "", "()V"); + jobject objectDisplayMetrics = lJNIEnv->NewObject(classDisplayMetrics, initDisplayMetrics); + + jmethodID methodGetWindowManager = lJNIEnv->GetMethodID(classActivity, + "getWindowManager", + "()Landroid/view/WindowManager;"); + jobject objectWindowManager = lJNIEnv->CallObjectMethod(objectActivity, methodGetWindowManager); + + jclass classWindowManager = lJNIEnv->FindClass("android/view/WindowManager"); + jmethodID methodGetDefaultDisplay = lJNIEnv->GetMethodID(classWindowManager, + "getDefaultDisplay", + "()Landroid/view/Display;"); + jobject objectDisplay = lJNIEnv->CallObjectMethod(objectWindowManager, methodGetDefaultDisplay); + + jclass classDisplay = lJNIEnv->FindClass("android/view/Display"); + jmethodID methodGetMetrics = nullptr; + + // getRealMetrics is only supported on API level 17 and above, if we are below that, we will fall back to getMetrics + if (getAndroidApiLevel(activity) >= 17) + methodGetMetrics = lJNIEnv->GetMethodID(classDisplay, "getRealMetrics", "(Landroid/util/DisplayMetrics;)V"); + else + methodGetMetrics = lJNIEnv->GetMethodID(classDisplay, "getMetrics", "(Landroid/util/DisplayMetrics;)V"); + lJNIEnv->CallVoidMethod(objectDisplay, methodGetMetrics, objectDisplayMetrics); + + jfieldID fieldWidthPixels = lJNIEnv->GetFieldID(classDisplayMetrics, "widthPixels", "I"); + jfieldID fieldHeightPixels = lJNIEnv->GetFieldID(classDisplayMetrics, "heightPixels", "I"); + + width = lJNIEnv->GetIntField(objectDisplayMetrics, fieldWidthPixels); + height = lJNIEnv->GetIntField(objectDisplayMetrics, fieldHeightPixels); +} + + //////////////////////////////////////////////////////////// void onResume(ANativeActivity* activity) { @@ -502,6 +549,7 @@ JNIEXPORT void ANativeActivity_onCreate(ANativeActivity* activity, void* savedSt eglInitialize(states->display, nullptr, nullptr); getScreenSizeInPixels(*activity, states->screenSize.x, states->screenSize.y); + getFullScreenSizeInPixels(*activity, states->fullScreenSize.x, states->fullScreenSize.y); // Redirect error messages to logcat sf::err().rdbuf(&states->logcat); diff --git a/src/SFML/System/Android/Activity.hpp b/src/SFML/System/Android/Activity.hpp index 910f5cc83..f2650f8df 100644 --- a/src/SFML/System/Android/Activity.hpp +++ b/src/SFML/System/Android/Activity.hpp @@ -82,6 +82,7 @@ struct ActivityStates bool mainOver{}; Vector2i screenSize; + Vector2i fullScreenSize; bool initialized{}; bool terminated{}; diff --git a/src/SFML/Window/Android/VideoModeImpl.cpp b/src/SFML/Window/Android/VideoModeImpl.cpp index 55d72c55f..f573867f4 100644 --- a/src/SFML/Window/Android/VideoModeImpl.cpp +++ b/src/SFML/Window/Android/VideoModeImpl.cpp @@ -38,7 +38,11 @@ namespace sf::priv //////////////////////////////////////////////////////////// std::vector VideoModeImpl::getFullscreenModes() { - const VideoMode desktop = getDesktopMode(); + // Get the activity states + priv::ActivityStates& states = priv::getActivity(); + + const std::lock_guard lock(states.mutex); + const auto desktop = VideoMode(Vector2u(states.fullScreenSize)); // Return both portrait and landscape resolutions return {desktop, VideoMode(Vector2u(desktop.size.y, desktop.size.x), desktop.bitsPerPixel)};