X Tutup
Skip to content

Use of XrSwapchainCreateFlags for OpenXRCompositionLayer#108644

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
bnjmntmm:secure-android-surface
Oct 6, 2025
Merged

Use of XrSwapchainCreateFlags for OpenXRCompositionLayer#108644
Repiteo merged 1 commit intogodotengine:masterfrom
bnjmntmm:secure-android-surface

Conversation

@bnjmntmm
Copy link
Contributor

Introduces SwapchainCreateFlags enum to control swapchain creation (NORMAL, STATIC, PROTECTED) in OpenXR composition layers.
This allows the user to set SwapChainCreate Flags to either have one static image on the composition layer or set the protected content flag which allows stuff like Widevine DRM protected videos to be displayed on the composition layer

As this is the first time ever creating something with c++, i am open for feedback, will try my best to answer to your guys' feedback and improve the code.

A question I have already: Should I rename the values in the enum, as "normal", "static" and "protected" are not that informative and "normal" is just not normal. it just sets a 0 as bit

Thanks ^^

@bnjmntmm bnjmntmm requested a review from a team as a code owner July 15, 2025 20:41
@dsnopek
Copy link
Contributor

dsnopek commented Jul 15, 2025

Thanks!

I don't think it makes sense to have "static" as an option, because we already support that for Viewport-based composition layers automatically, and I don't think there is really a use case for it with Android surfaces. Just adding the ability to toggle "protected" should be enough.

Also, you need to make sure that this flag is used for Viewport-based layers as well. That would be done in OpenXRViewportCompositionLayerProvider::update_and_acquire_swapchain()

@dsnopek dsnopek added this to the 4.x milestone Jul 15, 2025
@bnjmntmm bnjmntmm requested review from a team as code owners July 16, 2025 08:03
@bnjmntmm
Copy link
Contributor Author

I've changed the enum to a simple bool. Also tested it and it still works. Off = pink screen, On = video is shown
Also added some basic documentation but that can be changed however you guys like :D

Also a question regarding the viewport based layers. Is there even the need to create a protected layer? I don't think it can be used properly but idk. I just added an extra if.
Maybe the if should be an extra check so it can't be static and protected.. idk if that even works

@bnjmntmm
Copy link
Contributor Author

I think I have to change something in this pr.. as I rebased based on the docs and now it wanna also merge the other files.

@bnjmntmm bnjmntmm force-pushed the secure-android-surface branch from 0501d88 to a9c31b1 Compare July 16, 2025 09:19
Copy link
Contributor

@dsnopek dsnopek left a comment

Choose a reason for hiding this comment

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

Thanks!

At a high-level, this is looking good. I've mostly got notes about naming, and one functional note with regard to recreating the swapchain when the source of the content is a subviewport

Oh, and in the end, you'll need to squash everything into a single commit per Godot's pull request worflow. See https://docs.godotengine.org/en/latest/contributing/workflow/pr_workflow.html#the-interactive-rebase

@bnjmntmm
Copy link
Contributor Author

tried to address all of your feedback. Will squash if youre satisfied at the end

Copy link
Contributor

@m4gr3d m4gr3d left a comment

Choose a reason for hiding this comment

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

Haven't tested the changes but the code looks good.

@bnjmntmm
Copy link
Contributor Author

What does the one failed Linux / Editor with Mono mean?
Will squash later in the evening

@dsnopek
Copy link
Contributor

dsnopek commented Jul 16, 2025

What does the one failed Linux / Editor with Mono mean?

It wants you to change the order if the property in the XML docs - I think it alphabetizes them?

Here's the patch it gives:

diff --git a/modules/openxr/doc_classes/OpenXRCompositionLayer.xml b/modules/openxr/doc_classes/OpenXRCompositionLayer.xml
index 38ade44..8921f8e 100644
--- a/modules/openxr/doc_classes/OpenXRCompositionLayer.xml
+++ b/modules/openxr/doc_classes/OpenXRCompositionLayer.xml
@@ -49,6 +49,10 @@
 		<member name="layer_viewport" type="SubViewport" setter="set_layer_viewport" getter="get_layer_viewport">
 			The [SubViewport] to render on the composition layer.
 		</member>
+		<member name="protected_content" type="bool" setter="set_protected_content" getter="is_protected_content" default="false">
+			If enabled, the OpenXR swapchain will be created with the [code]XR_SWAPCHAIN_CREATE_PROTECTED_CONTENT_BIT[/code] flag, which will protect its contents from CPU access.
+			When used with an Android Surface, this may allow DRM content to be presented, and will only take effect when the Surface is first created; later changes to this property will have no effect.
+		</member>
 		<member name="sort_order" type="int" setter="set_sort_order" getter="get_sort_order" default="1">
 			The sort order for this composition layer. Higher numbers will be shown in front of lower numbers.
 			[b]Note:[/b] This will have no effect if a fallback mesh is being used.
@@ -102,10 +106,6 @@
 			See [method get_android_surface] for information about how to get the surface so that your application can draw to it.
 			[b]Note:[/b] This will only work in Android builds.
 		</member>
-		<member name="protected_content" type="bool" setter="set_protected_content" getter="is_protected_content" default="false">
-			If enabled, the OpenXR swapchain will be created with the [code]XR_SWAPCHAIN_CREATE_PROTECTED_CONTENT_BIT[/code] flag, which will protect its contents from CPU access.
-			When used with an Android Surface, this may allow DRM content to be presented, and will only take effect when the Surface is first created; later changes to this property will have no effect.
-		</member>
 	</members>
 	<constants>
 		<constant name="FILTER_NEAREST" value="0" enum="Filter">

So, just moving that section up to be below layer_viewport

Copy link
Contributor

@dsnopek dsnopek left a comment

Choose a reason for hiding this comment

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

Thanks, this looks great! Just two tiny notes, and this needs to be squashed, but after that I'd be happy to approve :-)

@dsnopek dsnopek modified the milestones: 4.x, 4.6 Jul 16, 2025
@bnjmntmm bnjmntmm force-pushed the secure-android-surface branch from 98e59cf to 7f7e96a Compare July 16, 2025 15:27
@bnjmntmm
Copy link
Contributor Author

I'm stupid.. forgot to remove the old part in the docs

@bnjmntmm bnjmntmm force-pushed the secure-android-surface branch from 1bfb6d4 to bc60036 Compare July 17, 2025 07:42
@bnjmntmm
Copy link
Contributor Author

OKay.. squashing annoyed me so much because it reverted some changes, but I think every proposed change is in there.. I hope i didn't miss anything.

Copy link
Contributor

@dsnopek dsnopek left a comment

Choose a reason for hiding this comment

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

Thanks! I haven't tested, but the code looks great to me :-)

@AThousandShips AThousandShips changed the title Usage of XrSwapchainCreateFlags for OpenXRCompositionLayer Use of XrSwapchainCreateFlags for OpenXRCompositionLayer Jul 28, 2025
- Introduced SwapchainCreateFlags enum to control swapchain creation (NORMAL, STATIC, PROTECTED) in OpenXR composition layers.
- Allows creation of static layers (never change after creation) and protected layers (for DRM-protected content).
- Changed internal logic from enum to bool for simplicity; users now select "protected" or not.
- Added support for protected content in viewport-based layers.
- Refactored naming, documentation, and improved reusability.
- Minor cleanup: removed unused variable and added missing space.
@bnjmntmm bnjmntmm force-pushed the secure-android-surface branch from beef8e3 to ecfb962 Compare July 28, 2025 14:49
@bnjmntmm
Copy link
Contributor Author

Done.. i hope 🫡

@Repiteo Repiteo merged commit 788745e into godotengine:master Oct 6, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Oct 6, 2025

Thanks! Congratulations on your first merged contribution! 🎉

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.

5 participants

X Tutup