MCPcopy Create free account
hub / github.com/SFML/SFML / getFullScreenSizeInPixels

Function getFullScreenSizeInPixels

src/SFML/Main/MainAndroid.cpp:223–265  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

221
222////////////////////////////////////////////////////////////
223void getFullScreenSizeInPixels(ANativeActivity& activity, int& width, int& height)
224{
225 // Perform the following Java code:
226 //
227 // DisplayMetrics dm = new DisplayMetrics();
228 // getWindowManager().getDefaultDisplay().getRealMetrics(dm);
229
230 JNIEnv& lJNIEnv = *activity.env;
231
232 jobject objectActivity = activity.clazz;
233 jclass classActivity = lJNIEnv.GetObjectClass(objectActivity);
234
235 jclass classDisplayMetrics = lJNIEnv.FindClass("android/util/DisplayMetrics");
236 jmethodID initDisplayMetrics = lJNIEnv.GetMethodID(classDisplayMetrics, "<init>", "()V");
237 jobject objectDisplayMetrics = lJNIEnv.NewObject(classDisplayMetrics, initDisplayMetrics);
238
239 jmethodID methodGetWindowManager = lJNIEnv.GetMethodID(classActivity,
240 "getWindowManager",
241 "()Landroid/view/WindowManager;");
242 jobject objectWindowManager = lJNIEnv.CallObjectMethod(objectActivity, methodGetWindowManager);
243
244 jclass classWindowManager = lJNIEnv.FindClass("android/view/WindowManager");
245 jmethodID methodGetDefaultDisplay = lJNIEnv.GetMethodID(classWindowManager,
246 "getDefaultDisplay",
247 "()Landroid/view/Display;");
248 jobject objectDisplay = lJNIEnv.CallObjectMethod(objectWindowManager, methodGetDefaultDisplay);
249
250 jclass classDisplay = lJNIEnv.FindClass("android/view/Display");
251 jmethodID methodGetMetrics = nullptr;
252
253 // getRealMetrics is only supported on API level 17 and above, if we are below that, we will fall back to getMetrics
254 if (getAndroidApiLevel(activity) >= 17)
255 methodGetMetrics = lJNIEnv.GetMethodID(classDisplay, "getRealMetrics", "(Landroid/util/DisplayMetrics;)V");
256 else
257 methodGetMetrics = lJNIEnv.GetMethodID(classDisplay, "getMetrics", "(Landroid/util/DisplayMetrics;)V");
258 lJNIEnv.CallVoidMethod(objectDisplay, methodGetMetrics, objectDisplayMetrics);
259
260 jfieldID fieldWidthPixels = lJNIEnv.GetFieldID(classDisplayMetrics, "widthPixels", "I");
261 jfieldID fieldHeightPixels = lJNIEnv.GetFieldID(classDisplayMetrics, "heightPixels", "I");
262
263 width = lJNIEnv.GetIntField(objectDisplayMetrics, fieldWidthPixels);
264 height = lJNIEnv.GetIntField(objectDisplayMetrics, fieldHeightPixels);
265}
266
267
268////////////////////////////////////////////////////////////

Callers 1

ANativeActivity_onCreateFunction · 0.85

Calls 1

getAndroidApiLevelFunction · 0.85

Tested by

no test coverage detected