src/core/android/SDL_android.c
changeset 11662 a996f135cc81
parent 11655 ccf47d584003
child 11665 861f42ecf09a
     1.1 --- a/src/core/android/SDL_android.c	Tue Oct 24 13:21:11 2017 -0400
     1.2 +++ b/src/core/android/SDL_android.c	Tue Oct 31 13:49:59 2017 -0700
     1.3 @@ -214,6 +214,7 @@
     1.4  static jmethodID midClipboardHasText;
     1.5  static jmethodID midOpenAPKExpansionInputStream;
     1.6  static jmethodID midGetManifestEnvironmentVariable;
     1.7 +static jmethodID midGetDisplayDPI;
     1.8  
     1.9  /* audio manager */
    1.10  static jclass mAudioManagerClass;
    1.11 @@ -316,11 +317,13 @@
    1.12      midGetManifestEnvironmentVariable = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    1.13                                  "getManifestEnvironmentVariable", "(Ljava/lang/String;)Ljava/lang/String;");
    1.14  
    1.15 +    midGetDisplayDPI = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "getDisplayDPI", "()Landroid/util/DisplayMetrics;");
    1.16 +
    1.17      if (!midGetNativeSurface ||
    1.18         !midSetActivityTitle || !midSetOrientation || !midGetContext || !midInputGetInputDeviceIds ||
    1.19         !midSendMessage || !midShowTextInput || !midIsScreenKeyboardShown || 
    1.20         !midClipboardSetText || !midClipboardGetText || !midClipboardHasText ||
    1.21 -       !midOpenAPKExpansionInputStream || !midGetManifestEnvironmentVariable) {
    1.22 +       !midOpenAPKExpansionInputStream || !midGetManifestEnvironmentVariable || !midGetDisplayDPI) {
    1.23          __android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLActivity.java?");
    1.24      }
    1.25  
    1.26 @@ -1047,6 +1050,28 @@
    1.27      return audioBufferFrames;
    1.28  }
    1.29  
    1.30 +int Android_JNI_GetDisplayDPI(float *ddpi, float *xdpi, float *ydpi)
    1.31 +{
    1.32 +    JNIEnv *env = Android_JNI_GetEnv();
    1.33 +
    1.34 +    jobject jDisplayObj = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetDisplayDPI);
    1.35 +    jclass jDisplayClass = (*env)->GetObjectClass(env, jDisplayObj);
    1.36 +
    1.37 +    jfieldID fidXdpi = (*env)->GetFieldID(env, jDisplayClass, "xdpi", "F");
    1.38 +    jfieldID fidYdpi = (*env)->GetFieldID(env, jDisplayClass, "ydpi", "F");
    1.39 +    jfieldID fidDdpi = (*env)->GetFieldID(env, jDisplayClass, "densityDpi", "I");
    1.40 +
    1.41 +    float nativeXdpi = (*env)->GetFloatField(env, jDisplayObj, fidXdpi);
    1.42 +    float nativeYdpi = (*env)->GetFloatField(env, jDisplayObj, fidYdpi);
    1.43 +    int nativeDdpi = (*env)->GetIntField(env, jDisplayObj, fidDdpi);
    1.44 +
    1.45 +    *ddpi = (float)nativeDdpi;
    1.46 +    *xdpi = nativeXdpi;
    1.47 +    *ydpi = nativeYdpi;
    1.48 +
    1.49 +    return 0;
    1.50 +}
    1.51 +
    1.52  void * Android_JNI_GetAudioBuffer(void)
    1.53  {
    1.54      return audioBufferPinned;