[Scummvm-git-logs] scummvm master -> 27c7572bd786e9f08c99562f8c1ef443d103017a
lephilousophe
noreply at scummvm.org
Wed Jan 24 20:53:11 UTC 2024
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
27c7572bd7 ANDROID: Get HiDPI density from Android metrics
Commit: 27c7572bd786e9f08c99562f8c1ef443d103017a
https://github.com/scummvm/scummvm/commit/27c7572bd786e9f08c99562f8c1ef443d103017a
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2024-01-24T21:53:07+01:00
Commit Message:
ANDROID: Get HiDPI density from Android metrics
Changed paths:
backends/graphics/android/android-graphics.cpp
backends/graphics3d/android/android-graphics3d.cpp
backends/platform/android/android.cpp
backends/platform/android/jni-android.cpp
backends/platform/android/jni-android.h
backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java
diff --git a/backends/graphics/android/android-graphics.cpp b/backends/graphics/android/android-graphics.cpp
index db96fee9224..2199551e1a4 100644
--- a/backends/graphics/android/android-graphics.cpp
+++ b/backends/graphics/android/android-graphics.cpp
@@ -211,14 +211,11 @@ void AndroidGraphicsManager::hideOverlay() {
}
float AndroidGraphicsManager::getHiDPIScreenFactor() const {
- // TODO: Use JNI to get DisplayMetrics.density, which according to the documentation
- // seems to be what we want.
- // "On a medium-density screen, DisplayMetrics.density equals 1.0; on a high-density
- // screen it equals 1.5; on an extra-high-density screen, it equals 2.0; and on a
- // low-density screen, it equals 0.75. This figure is the factor by which you should
- // multiply the dp units in order to get the actual pixel count for the current screen."
-
- return 2.f;
+ JNI::DPIValues dpi;
+ JNI::getDPI(dpi);
+ // Scale down the Android factor else the GUI is too big and
+ // there is not much options to go smaller
+ return dpi[2] / 1.2;
}
bool AndroidGraphicsManager::loadVideoMode(uint requestedWidth, uint requestedHeight, const Graphics::PixelFormat &format) {
@@ -226,7 +223,6 @@ bool AndroidGraphicsManager::loadVideoMode(uint requestedWidth, uint requestedHe
// We get this whenever a new resolution is requested. Since Android is
// using a fixed output size we do nothing like that here.
- // TODO: Support screen rotation
return true;
}
diff --git a/backends/graphics3d/android/android-graphics3d.cpp b/backends/graphics3d/android/android-graphics3d.cpp
index b0aad055456..f9aa9fb1cfd 100644
--- a/backends/graphics3d/android/android-graphics3d.cpp
+++ b/backends/graphics3d/android/android-graphics3d.cpp
@@ -980,7 +980,7 @@ void AndroidGraphics3dManager::updateScreenRect() {
if (w && h && _ar_correction) {
- float dpi[2];
+ JNI::DPIValues dpi;
JNI::getDPI(dpi);
float screen_ar;
@@ -1069,14 +1069,11 @@ void AndroidGraphics3dManager::clearScreen(FixupType type, byte count) {
}
float AndroidGraphics3dManager::getHiDPIScreenFactor() const {
- // TODO: Use JNI to get DisplayMetrics.density, which according to the documentation
- // seems to be what we want.
- // "On a medium-density screen, DisplayMetrics.density equals 1.0; on a high-density
- // screen it equals 1.5; on an extra-high-density screen, it equals 2.0; and on a
- // low-density screen, it equals 0.75. This figure is the factor by which you should
- // multiply the dp units in order to get the actual pixel count for the current screen."
-
- return 2.f;
+ JNI::DPIValues dpi;
+ JNI::getDPI(dpi);
+ // Scale down the Android factor else the GUI is too big and
+ // there is not much options to go smaller
+ return dpi[2] / 1.2;
}
AndroidCommonGraphics::State AndroidGraphics3dManager::getState() const {
diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp
index 91427633e44..842ed6e822b 100644
--- a/backends/platform/android/android.cpp
+++ b/backends/platform/android/android.cpp
@@ -527,14 +527,6 @@ void OSystem_Android::initBackend() {
ConfMan.setPath("browser_lastpath", "/");
}
- if (!ConfMan.hasKey("gui_scale")) {
- // Until a proper scale detection is done (especially post PR https://github.com/scummvm/scummvm/pull/3264/commits/8646dfca329b6fbfdba65e0dc0802feb1382dab2),
- // set scale by default to large, if not set, and then let the user set it manually from the launcher -> Options -> Misc tab
- // Otherwise the screen may default to very tiny and indiscernible text and be barely usable.
- // TODO We need a proper scale detection for Android, see: (float) AndroidGraphicsManager::getHiDPIScreenFactor() in android/graphics.cpp
- ConfMan.setInt("gui_scale", 125); // "Large" (see gui/options.cpp and guiBaseValues[])
- }
-
Common::String basePath = JNI::getScummVMBasePath();
_savefileManager = new AndroidSaveFileManager(Common::Path(basePath, Common::Path::kNativeSeparator).joinInPlace("saves"));
diff --git a/backends/platform/android/jni-android.cpp b/backends/platform/android/jni-android.cpp
index 6ea15f70c26..30023a9d959 100644
--- a/backends/platform/android/jni-android.cpp
+++ b/backends/platform/android/jni-android.cpp
@@ -251,13 +251,15 @@ void JNI::throwRuntimeException(JNIEnv *env, const char *msg) {
// calls to the dark side
-void JNI::getDPI(float *values) {
- values[0] = 0.0;
- values[1] = 0.0;
+void JNI::getDPI(DPIValues &values) {
+ // Use sane defaults in case something goes wrong
+ values[0] = 160.0;
+ values[1] = 160.0;
+ values[2] = 1.0;
JNIEnv *env = JNI::getEnv();
- jfloatArray array = env->NewFloatArray(2);
+ jfloatArray array = env->NewFloatArray(3);
env->CallVoidMethod(_jobj, _MID_getDPI, array);
@@ -267,16 +269,15 @@ void JNI::getDPI(float *values) {
env->ExceptionDescribe();
env->ExceptionClear();
} else {
- jfloat *res = env->GetFloatArrayElements(array, 0);
+ env->GetFloatArrayRegion(array, 0, 3, values);
+ if (env->ExceptionCheck()) {
+ LOGE("Failed to get DPIs");
- if (res) {
- values[0] = res[0];
- values[1] = res[1];
-
- env->ReleaseFloatArrayElements(array, res, 0);
+ env->ExceptionDescribe();
+ env->ExceptionClear();
}
}
- LOGD("JNI::getDPI() xdpi: %f, ydpi: %f", values[0], values[1]);
+ LOGD("JNI::getDPI() xdpi: %f, ydpi: %f, density: %f", values[0], values[1], values[2]);
env->DeleteLocalRef(array);
}
diff --git a/backends/platform/android/jni-android.h b/backends/platform/android/jni-android.h
index 27476aed196..091ed332b9f 100644
--- a/backends/platform/android/jni-android.h
+++ b/backends/platform/android/jni-android.h
@@ -78,7 +78,12 @@ public:
static void wakeupForQuit();
static void setWindowCaption(const Common::U32String &caption);
- static void getDPI(float *values);
+
+ /**
+ * Array members of DPIValues are xdpi, ydpi, density
+ **/
+ typedef float DPIValues[3];
+ static void getDPI(DPIValues &values);
static void displayMessageOnOSD(const Common::U32String &msg);
static bool openUrl(const Common::String &url);
static bool hasTextInClipboard();
diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java
index de6f7529cee..5d57d2f6168 100644
--- a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java
+++ b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java
@@ -663,9 +663,18 @@ public class ScummVMActivity extends Activity implements OnKeyboardVisibilityLis
protected void getDPI(float[] values) {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
+ Configuration config = getResources().getConfiguration();
values[0] = metrics.xdpi;
values[1] = metrics.ydpi;
+ // "On a medium-density screen, DisplayMetrics.density equals 1.0; on a high-density
+ // screen it equals 1.5; on an extra-high-density screen, it equals 2.0; and on a
+ // low-density screen, it equals 0.75. This figure is the factor by which you should
+ // multiply the dp units in order to get the actual pixel count for the current screen."
+ // In addition, take into account the fontScale setting set by the user.
+ // We are not supposed to take this value directly because of non-linear scaling but
+ // as we are doing our own rendering there is not much choice
+ values[2] = metrics.density * config.fontScale;
}
@Override
@@ -974,9 +983,9 @@ public class ScummVMActivity extends Activity implements OnKeyboardVisibilityLis
}
});
- float[] dpiValues = new float[] { 0.0f, 0.0f };
+ float[] dpiValues = new float[] { 0.0f, 0.0f, 0.0f };
_scummvm.getDPI(dpiValues);
- Log.d(ScummVM.LOG_TAG, "Current xdpi: " + dpiValues[0] + " and ydpi: " + dpiValues[1]);
+ Log.d(ScummVM.LOG_TAG, "Current xdpi: " + dpiValues[0] + ", ydpi: " + dpiValues[1] + " and density: " + dpiValues[2]);
// Currently in release builds version string does not contain the revision info
// but in debug builds (daily builds) this should be there (see base/internal_version_h)
More information about the Scummvm-git-logs
mailing list