@@ -38,6 +38,7 @@ import android.content.pm.PackageManager
3838import android.content.res.Configuration
3939import android.content.res.Resources
4040import android.graphics.Color
41+ import android.graphics.PixelFormat
4142import android.hardware.Sensor
4243import android.hardware.SensorManager
4344import android.os.*
@@ -79,6 +80,7 @@ import java.io.FileInputStream
7980import java.io.InputStream
8081import java.security.MessageDigest
8182import java.util.*
83+ import java.util.concurrent.ConcurrentHashMap
8284import java.util.concurrent.atomic.AtomicBoolean
8385import java.util.concurrent.atomic.AtomicReference
8486
@@ -189,6 +191,13 @@ class Godot(private val context: Context) {
189191 private var containerLayout: FrameLayout ? = null
190192 var renderView: GodotRenderView ? = null
191193
194+ /* *
195+ * Stores the flags for the primary window.
196+ *
197+ * @see <a href="https://docs.godotengine.org/en/stable/classes/class_window.html#enum-window-flags">WindowFlags</a>
198+ */
199+ private val primaryWindowFlags = ConcurrentHashMap <Int , Boolean >()
200+
192201 /* *
193202 * Returns true if the native engine has been initialized through [onInitNativeLayer], false otherwise.
194203 */
@@ -481,21 +490,32 @@ class Godot(private val context: Context) {
481490
482491 // Check whether the render view should be made transparent
483492 val shouldBeTransparent =
484- ! isProjectManagerHint() && ! isEditorHint() && java.lang.Boolean .parseBoolean(GodotLib .getGlobal(" display/window/per_pixel_transparency/allowed" ))
493+ ! isProjectManagerHint() &&
494+ ! isEditorHint() &&
495+ java.lang.Boolean .parseBoolean(GodotLib .getGlobal(" display/window/per_pixel_transparency/allowed" )) &&
496+ java.lang.Boolean .parseBoolean(GodotLib .getGlobal(" display/window/size/transparent" ))
485497 Log .d(TAG , " Render view should be transparent: $shouldBeTransparent " )
486498 renderView = if (usesVulkan()) {
487499 if (meetsVulkanRequirements(activity.packageManager)) {
488- GodotVulkanRenderView (host, this , godotInputHandler, shouldBeTransparent )
500+ GodotVulkanRenderView (host, this , godotInputHandler)
489501 } else if (canFallbackToOpenGL()) {
490502 // Fallback to OpenGl.
491- GodotGLRenderView (host, this , godotInputHandler, xrMode, useDebugOpengl, shouldBeTransparent )
503+ GodotGLRenderView (host, this , godotInputHandler, xrMode, useDebugOpengl)
492504 } else {
493505 throw IllegalStateException (activity.getString(R .string.error_missing_vulkan_requirements_message))
494506 }
495507
496508 } else {
497509 // Fallback to OpenGl.
498- GodotGLRenderView (host, this , godotInputHandler, xrMode, useDebugOpengl, shouldBeTransparent)
510+ GodotGLRenderView (host, this , godotInputHandler, xrMode, useDebugOpengl)
511+ }
512+ if (shouldBeTransparent) {
513+ /* By default, GLSurfaceView() creates a RGB_565 opaque surface.
514+ * If we want a translucent one, we should change the surface's
515+ * format here, using PixelFormat.TRANSLUCENT for GL Surfaces
516+ * is interpreted as any 32-bit surface with alpha by SurfaceFlinger.
517+ */
518+ renderView?.setPixelFormat(PixelFormat .TRANSLUCENT )
499519 }
500520
501521 if (host == primaryHost) {
@@ -1204,4 +1224,23 @@ class Godot(private val context: Context) {
12041224 private fun nativeOnEditorWorkspaceSelected (workspace : String ) {
12051225 primaryHost?.onEditorWorkspaceSelected(workspace)
12061226 }
1227+
1228+ @Keep
1229+ private fun setWindowFlag (flag : Int , enabled : Boolean ) {
1230+ primaryWindowFlags[flag] = enabled
1231+ if (flag == 3 /* WINDOW_FLAG_TRANSPARENT */ ) {
1232+ runOnUiThread {
1233+ val pixelFormat = if (enabled) {
1234+ PixelFormat .TRANSLUCENT
1235+ } else {
1236+ PixelFormat .OPAQUE
1237+ }
1238+ Log .d(TAG , " Updating pixel format to $pixelFormat " )
1239+ renderView?.setPixelFormat(pixelFormat)
1240+ }
1241+ }
1242+ }
1243+
1244+ @Keep
1245+ private fun getWindowFlag (flag : Int ): Boolean = primaryWindowFlags[flag] ? : false
12071246}
0 commit comments