Skip to content

Fix transparency background issue on Android #106709

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

Merged
merged 1 commit into from
Jun 12, 2025

Conversation

m4gr3d
Copy link
Contributor

@m4gr3d m4gr3d commented May 22, 2025

Updates the logic to detect when transparency is required on Android using display/window/per_pixel_transparency/allowed, display/window/size/transparent, and rendering/viewport/transparent_background, which updates the render view configuration and the app's theme.

The requirement to update the app's theme means the feature is only available to gradle build exports.

Fixes #106703

Before

Screen_Recording_20250522_001406_GLTF.Viewer.mp4

After

Screen_Recording_20250522_001458_GLTF.Viewer.mp4

@m4gr3d m4gr3d added this to the 4.5 milestone May 22, 2025
@m4gr3d m4gr3d requested a review from a team as a code owner May 22, 2025 07:15
@m4gr3d
Copy link
Contributor Author

m4gr3d commented May 23, 2025

Switching to draft until #106724 is merged.

@m4gr3d m4gr3d force-pushed the fix_transparency_flags branch 2 times, most recently from 335cc7e to 7a15ea7 Compare May 28, 2025 14:25
@m4gr3d m4gr3d marked this pull request as ready for review May 28, 2025 14:25
Copy link
Member

@Alex2782 Alex2782 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test project: godot-demo-projects/.../window_management

DisplayServer.has_feature(DisplayServer.FEATURE_WINDOW_TRANSPARENCY)

//case FEATURE_WINDOW_TRANSPARENCY:

Can we activate that now too? Or evaluate android:windowIsTranslucent there?

Copy link
Member

@Alex2782 Alex2782 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test project: godot-demo-projects/.../window_management

display/window/size/transparent = true and disabled DisplayServer.has_feature check:

func _on_transparent_check_button_toggled(button_pressed: bool) -> void:
	#if not DisplayServer.has_feature(DisplayServer.FEATURE_WINDOW_TRANSPARENCY):
	#	OS.alert("Window transparency is not supported by the current display server (%s)." % DisplayServer.get_name())
	#	return
	get_viewport().transparent_bg = button_pressed
	DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_TRANSPARENT, button_pressed)

On Android 13, Samsung Tab S7 (Adreno 650).

OpenGL
glsl_Screen_recording_20250529_015017.mp4
Vulkan (Mobile)
mobile_Screen_recording_20250529_015358.mp4
on MacOS, Metal (Mobile) for comparison
Screen-2025-05-29-020905.mp4

At first glance OpenGL Renderer works correctly / as it should.
But after switching back and forth for the second time, the 3D scene is no longer rendered.
But these are other issues that have nothing to do with this PR. (i think)
image

Copy link
Member

@Alex2782 Alex2782 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test project: godot-demo-projects/.../window_management

In the test project, display/window/size/transparent isn't enabled, so I tried without it and didn't encounter any problems. Or is there anything wrong with that?


removed size/transparent from export_plugin.cpp

bool EditorExportPlatformAndroid::_should_be_transparent(const Ref<EditorExportPreset> &p_preset) const {
	return (bool)get_project_setting(p_preset, "display/window/per_pixel_transparency/allowed");
}

and Godot.kt

// Check whether the render view should be made transparent
val shouldBeTransparent = java.lang.Boolean.parseBoolean(GodotLib.getGlobal("display/window/per_pixel_transparency/allowed"))

@m4gr3d
Copy link
Contributor Author

m4gr3d commented May 29, 2025

In the test project, display/window/size/transparent isn't enabled, so I tried without it and didn't encounter any problems. Or is there anything wrong with that?

@Alex2782 That's because DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_TRANSPARENT, button_pressed) plays a similar role on desktop.
That method is not implemented on Android so instead we rely on the display/window/size/transparent property.

@m4gr3d m4gr3d force-pushed the fix_transparency_flags branch from 7a15ea7 to bdd0946 Compare May 29, 2025 06:36
@m4gr3d m4gr3d requested a review from a team as a code owner May 29, 2025 06:36
@m4gr3d
Copy link
Contributor Author

m4gr3d commented May 29, 2025

"display/window/per_pixel_transparency/allowed"

I've updated the logic to only check "display/window/per_pixel_transparency/allowed" in order to match the demo project.

@m4gr3d m4gr3d force-pushed the fix_transparency_flags branch from bdd0946 to a72586f Compare May 29, 2025 07:39
Copy link
Member

@Alex2782 Alex2782 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test project: godot-demo-projects/.../window_management

Tried again on the Samsung Tab S7 and the Pixel 4a. It looks fine during startup/initialization.

The Pixel 4a OpenGLES has other rendering issues; the 2D scene (UI) fades out after switching back and forth several times.

@m4gr3d
Copy link
Contributor Author

m4gr3d commented May 29, 2025

The Pixel 4a OpenGLES has other rendering issues; the 2D scene (UI) fades out after switching back and forth several times.

@Alex2782 I'm seeing the same issue on a Samsung Tab S8 when using the OpenGL renderer. I'll create a bug for the rendering team.

@m4gr3d m4gr3d force-pushed the fix_transparency_flags branch from a72586f to 3d8c372 Compare May 29, 2025 16:05
@m4gr3d
Copy link
Contributor Author

m4gr3d commented May 29, 2025

The Pixel 4a OpenGLES has other rendering issues; the 2D scene (UI) fades out after switching back and forth several times.

@Alex2782 I'm seeing the same issue on a Samsung Tab S8 when using the OpenGL renderer. I'll create a bug for the rendering team.

The issue is also reproducible on 4.4.1-stable after disabling the feature check, so it should not be a blocker for this PR:

func _on_transparent_check_button_toggled(button_pressed: bool) -> void:
	#if not DisplayServer.has_feature(DisplayServer.FEATURE_WINDOW_TRANSPARENCY):
	#	OS.alert("Window transparency is not supported by the current display server (%s)." % DisplayServer.get_name())
	#	return
	get_viewport().transparent_bg = button_pressed
	DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_TRANSPARENT, button_pressed)
Screen_Recording_20250529_090905_Window.Management.mp4

@syntaxerror247
Copy link
Member

syntaxerror247 commented May 29, 2025

I am running the demo directly from Android Editor and having the same issue in opengl renderer but also having issues in vulkan renderer. Notice that after toggled off transparent button, window is translucent instead of opaque But I think it's expected due to windowIsTranslucent attribute?

Screenrecorder-2025-05-29-23-00-53-465.mp4

@@ -67,6 +67,10 @@ public GodotVulkanRenderView(GodotHost host, Godot godot, GodotInputHandler inpu
setPointerIcon(PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_DEFAULT));
setFocusableInTouchMode(true);
setClickable(false);

if (shouldBeTranslucent) {
this.getHolder().setFormat(PixelFormat.TRANSLUCENT);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be set at runtime, if window transparent flag changes in Godot.

@m4gr3d m4gr3d force-pushed the fix_transparency_flags branch from 3d8c372 to 547450b Compare June 3, 2025 05:45
@akien-mga akien-mga requested a review from syntaxerror247 June 5, 2025 10:42
@akien-mga akien-mga merged commit ae33da9 into godotengine:master Jun 12, 2025
20 checks passed
@akien-mga
Copy link
Member

Thanks!

@m4gr3d m4gr3d deleted the fix_transparency_flags branch June 13, 2025 00:11
m4gr3d added a commit to m4gr3d/godot that referenced this pull request Jun 13, 2025
m4gr3d added a commit to m4gr3d/godot that referenced this pull request Jun 13, 2025
m4gr3d added a commit to m4gr3d/godot that referenced this pull request Jun 19, 2025
m4gr3d added a commit to m4gr3d/godot that referenced this pull request Jun 19, 2025
@Alex2782
Copy link
Member

Can these 2 issue reports for Godot 3.x also be closed?

#52725
#36860

... or cherrypick necessary?

@syntaxerror247
Copy link
Member

Can these 2 issue reports for Godot 3.x also be closed?

#52725 #36860

... or cherrypick necessary?

Cherry picking is not possible because it uses a new method for adding custom theme attributes during export. So, that would need to be implemented in 3.x first.

m4gr3d added a commit to m4gr3d/godot that referenced this pull request Jul 6, 2025
m4gr3d added a commit to m4gr3d/godot that referenced this pull request Jul 7, 2025
m4gr3d added a commit to m4gr3d/godot that referenced this pull request Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android GodotFragment can't have a transparent background
5 participants