Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Update Android Editor default display scale #59868

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ String EditorSettings::get_editor_layouts_config() const {
}

float EditorSettings::get_auto_display_scale() const {
#ifdef OSX_ENABLED
#if defined(OSX_ENABLED) || defined(ANDROID_ENABLED)
return OS::get_singleton()->get_screen_max_scale();
#else
const int screen = OS::get_singleton()->get_current_screen();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,18 @@ public void onNewGodotInstanceRequested(String[] args) {
Intent newInstance = new Intent(this, targetClass).putExtra(COMMAND_LINE_PARAMS, args);
startActivity(newInstance);
}

@Override
public void setRequestedOrientation(int requestedOrientation) {
if (!overrideOrientationRequest()) {
super.setRequestedOrientation(requestedOrientation);
}
}

/**
* The Godot Android Editor sets its own orientation via its AndroidManifest
*/
protected boolean overrideOrientationRequest() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@
* Drives the 'run project' window of the Godot Editor.
*/
public class GodotGame extends GodotEditor {
protected boolean overrideOrientationRequest() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,14 @@ public String getModel() {
}

public int getScreenDPI() {
DisplayMetrics metrics = activity.getApplicationContext().getResources().getDisplayMetrics();
DisplayMetrics metrics = activity.getResources().getDisplayMetrics();
return (int)(metrics.density * 160f);
}

public float getScaledDensity() {
return activity.getResources().getDisplayMetrics().scaledDensity;
}

public double getScreenRefreshRate(double fallback) {
Display display = activity.getWindowManager().getDefaultDisplay();
if (display != null) {
Expand Down
11 changes: 11 additions & 0 deletions platform/android/java_godot_io_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ GodotIOJavaWrapper::GodotIOJavaWrapper(JNIEnv *p_env, jobject p_godot_io_instanc
_get_locale = p_env->GetMethodID(cls, "getLocale", "()Ljava/lang/String;");
_get_model = p_env->GetMethodID(cls, "getModel", "()Ljava/lang/String;");
_get_screen_DPI = p_env->GetMethodID(cls, "getScreenDPI", "()I");
_get_scaled_density = p_env->GetMethodID(cls, "getScaledDensity", "()F");
_get_screen_refresh_rate = p_env->GetMethodID(cls, "getScreenRefreshRate", "(D)D");
_get_window_safe_area = p_env->GetMethodID(cls, "getWindowSafeArea", "()[I"),
_get_unique_id = p_env->GetMethodID(cls, "getUniqueID", "()Ljava/lang/String;");
Expand Down Expand Up @@ -137,6 +138,16 @@ int GodotIOJavaWrapper::get_screen_dpi() {
}
}

float GodotIOJavaWrapper::get_scaled_density() {
if (_get_scaled_density) {
JNIEnv *env = get_jni_env();
ERR_FAIL_COND_V(env == nullptr, 1.0f);
return env->CallFloatMethod(godot_io_instance, _get_scaled_density);
} else {
return 1.0f;
}
}

float GodotIOJavaWrapper::get_screen_refresh_rate(float p_fallback) {
if (_get_screen_refresh_rate) {
JNIEnv *env = get_jni_env();
Expand Down
2 changes: 2 additions & 0 deletions platform/android/java_godot_io_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class GodotIOJavaWrapper {
jmethodID _get_locale = 0;
jmethodID _get_model = 0;
jmethodID _get_screen_DPI = 0;
jmethodID _get_scaled_density = 0;
jmethodID _get_screen_refresh_rate = 0;
jmethodID _get_window_safe_area = 0;
jmethodID _get_unique_id = 0;
Expand All @@ -72,6 +73,7 @@ class GodotIOJavaWrapper {
String get_locale();
String get_model();
int get_screen_dpi();
float get_scaled_density();
void get_window_safe_area(int (&p_rect_xywh)[4]);
float get_screen_refresh_rate(float p_fallback);
String get_unique_id();
Expand Down
8 changes: 8 additions & 0 deletions platform/android/os_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,14 @@ int OS_Android::get_screen_dpi(int p_screen) const {
return godot_io_java->get_screen_dpi();
}

float OS_Android::get_screen_scale(int p_screen) const {
return godot_io_java->get_scaled_density();
}

float OS_Android::get_screen_max_scale() const {
return get_screen_scale();
}

float OS_Android::get_screen_refresh_rate(int p_screen) const {
return godot_io_java->get_screen_refresh_rate(OS::get_singleton()->SCREEN_REFRESH_RATE_FALLBACK);
}
Expand Down
2 changes: 2 additions & 0 deletions platform/android/os_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ class OS_Android : public OS_Unix {
virtual bool has_clipboard() const;
virtual String get_model_name() const;
virtual int get_screen_dpi(int p_screen = 0) const;
virtual float get_screen_scale(int p_screen = -1) const;
virtual float get_screen_max_scale() const;
virtual float get_screen_refresh_rate(int p_screen = 0) const;

virtual bool get_window_per_pixel_transparency_enabled() const { return transparency_enabled; }
Expand Down