Fixed wrong fullscreen resolution

This commit is contained in:
acsbendi 2019-02-20 19:21:31 +01:00 committed by Lukas Dürrenberger
parent 34b6bda233
commit 15e001608a
3 changed files with 53 additions and 1 deletions

View File

@ -243,6 +243,48 @@ void getScreenSizeInPixels(ANativeActivity* activity, int* width, int* height)
}
////////////////////////////////////////////////////////////
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, "<init>", "()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;
// getRealMetrics is only supported on API level 17 and above, if we are below that, we will fall back to getMetrics
if(sf::priv::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);
}
////////////////////////////////////////////////////////////
static void onStart(ANativeActivity* activity)
{
@ -563,6 +605,7 @@ JNIEXPORT void ANativeActivity_onCreate(ANativeActivity* activity, void* savedSt
eglInitialize(states->display, NULL, NULL);
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);

View File

@ -80,6 +80,7 @@ struct ActivityStates
bool mainOver;
Vector2i screenSize;
Vector2i fullScreenSize;
bool initialized;
bool terminated;

View File

@ -38,7 +38,15 @@ namespace priv
////////////////////////////////////////////////////////////
std::vector<VideoMode> VideoModeImpl::getFullscreenModes()
{
VideoMode desktop = getDesktopMode();
// Get the activity states
priv::ActivityStates& states = priv::getActivity();
VideoMode desktop;
{
Lock lock(states.mutex);
desktop = VideoMode(static_cast<unsigned int>(states.fullScreenSize.x), static_cast<unsigned int>(states.fullScreenSize.y));
}
// Return both portrait and landscape resolutions
std::vector<VideoMode> modes;