Skip to content

Commit 37e2d10

Browse files
committed
Add support for enabling XR_FB_composition_layer_secure_content on the projection layer
1 parent 685c794 commit 37e2d10

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

doc_classes/OpenXRFbCompositionLayerSecureContentExtension.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,28 @@
88
</description>
99
<tutorials>
1010
</tutorials>
11+
<methods>
12+
<method name="is_enabled" qualifiers="const">
13+
<return type="bool" />
14+
<description>
15+
Checks if the extension is enabled or not.
16+
</description>
17+
</method>
18+
</methods>
19+
<members>
20+
<member name="projection_layer_external_output" type="int" setter="set_projection_layer_external_output" getter="get_projection_layer_external_output" enum="OpenXRFbCompositionLayerSecureContentExtension.ExternalOutput" default="0">
21+
Specifies how the projection layer should be rendered to external outputs. This setting will have [b]no effect[/b] on the projection layer when viewed from inside the device, but will take effect when casting to another device.
22+
</member>
23+
</members>
24+
<constants>
25+
<constant name="EXTERNAL_OUTPUT_DISPLAY" value="0" enum="ExternalOutput">
26+
Display the content without any changes to external outputs.
27+
</constant>
28+
<constant name="EXTERNAL_OUTPUT_EXCLUDE" value="1" enum="ExternalOutput">
29+
Hide this composition layer from external outputs, revealing content behind it.
30+
</constant>
31+
<constant name="EXTERNAL_OUTPUT_REPLACE" value="2" enum="ExternalOutput">
32+
Replace the content on this composition layer with a black screen.
33+
</constant>
34+
</constants>
1135
</class>

plugin/src/main/cpp/extensions/openxr_fb_composition_layer_secure_content_extension.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,48 @@ OpenXRFbCompositionLayerSecureContentExtension::~OpenXRFbCompositionLayerSecureC
5858
}
5959

6060
void OpenXRFbCompositionLayerSecureContentExtension::_bind_methods() {
61+
ClassDB::bind_method(D_METHOD("is_enabled"), &OpenXRFbCompositionLayerSecureContentExtension::is_enabled);
62+
63+
ClassDB::bind_method(D_METHOD("set_projection_layer_external_output", "external_output"), &OpenXRFbCompositionLayerSecureContentExtension::set_projection_layer_external_output);
64+
ClassDB::bind_method(D_METHOD("get_projection_layer_external_output"), &OpenXRFbCompositionLayerSecureContentExtension::get_projection_layer_external_output);
65+
66+
ADD_PROPERTY(PropertyInfo(Variant::INT, "projection_layer_external_output", PROPERTY_HINT_ENUM, "Display,Exclude,Replace"), "set_projection_layer_external_output", "get_projection_layer_external_output");
67+
68+
BIND_ENUM_CONSTANT(EXTERNAL_OUTPUT_DISPLAY);
69+
BIND_ENUM_CONSTANT(EXTERNAL_OUTPUT_EXCLUDE);
70+
BIND_ENUM_CONSTANT(EXTERNAL_OUTPUT_REPLACE);
6171
}
6272

6373
void OpenXRFbCompositionLayerSecureContentExtension::cleanup() {
6474
fb_composition_layer_secure_content = false;
75+
projection_layer_external_output = EXTERNAL_OUTPUT_DISPLAY;
76+
}
77+
78+
void OpenXRFbCompositionLayerSecureContentExtension::_on_session_created(uint64_t p_session) {
79+
if (!fb_composition_layer_secure_content) {
80+
return;
81+
}
82+
get_openxr_api()->register_projection_layer_extension(this);
83+
}
84+
85+
void OpenXRFbCompositionLayerSecureContentExtension::_on_session_destroyed() {
86+
if (!fb_composition_layer_secure_content) {
87+
return;
88+
}
89+
get_openxr_api()->unregister_projection_layer_extension(this);
90+
}
91+
92+
bool OpenXRFbCompositionLayerSecureContentExtension::is_enabled() const {
93+
return fb_composition_layer_secure_content;
94+
}
95+
96+
void OpenXRFbCompositionLayerSecureContentExtension::set_projection_layer_external_output(ExternalOutput p_external_output) {
97+
ERR_FAIL_COND_MSG(!fb_composition_layer_secure_content, "XR_FB_composition_layer_secure_content is not enabled");
98+
projection_layer_external_output = p_external_output;
99+
}
100+
101+
OpenXRFbCompositionLayerSecureContentExtension::ExternalOutput OpenXRFbCompositionLayerSecureContentExtension::get_projection_layer_external_output() const {
102+
return projection_layer_external_output;
65103
}
66104

67105
Dictionary OpenXRFbCompositionLayerSecureContentExtension::_get_requested_extensions(uint64_t p_xr_version) {
@@ -73,6 +111,27 @@ Dictionary OpenXRFbCompositionLayerSecureContentExtension::_get_requested_extens
73111
return result;
74112
}
75113

114+
uint64_t OpenXRFbCompositionLayerSecureContentExtension::_set_projection_layer_and_get_next_pointer(void *p_next_pointer) {
115+
if (!fb_composition_layer_secure_content) {
116+
return reinterpret_cast<uint64_t>(p_next_pointer);
117+
}
118+
119+
switch (projection_layer_external_output) {
120+
case EXTERNAL_OUTPUT_DISPLAY: {
121+
return reinterpret_cast<uint64_t>(p_next_pointer);
122+
}
123+
case EXTERNAL_OUTPUT_EXCLUDE: {
124+
projection_layer_secure_content.flags = XR_COMPOSITION_LAYER_SECURE_CONTENT_EXCLUDE_LAYER_BIT_FB;
125+
} break;
126+
case EXTERNAL_OUTPUT_REPLACE: {
127+
projection_layer_secure_content.flags = XR_COMPOSITION_LAYER_SECURE_CONTENT_REPLACE_LAYER_BIT_FB;
128+
} break;
129+
}
130+
131+
projection_layer_secure_content.next = p_next_pointer;
132+
return reinterpret_cast<uint64_t>(&projection_layer_secure_content);
133+
}
134+
76135
uint64_t OpenXRFbCompositionLayerSecureContentExtension::_set_viewport_composition_layer_and_get_next_pointer(const void *p_layer, const Dictionary &p_property_values, void *p_next_pointer) {
77136
if (!fb_composition_layer_secure_content) {
78137
return reinterpret_cast<uint64_t>(p_next_pointer);

plugin/src/main/cpp/include/extensions/openxr_fb_composition_layer_secure_content_extension.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,19 @@ class OpenXRFbCompositionLayerSecureContentExtension : public OpenXRExtensionWra
5252
};
5353

5454
virtual uint64_t _set_viewport_composition_layer_and_get_next_pointer(const void *p_layer, const Dictionary &p_property_values, void *p_next_pointer) override;
55+
virtual uint64_t _set_projection_layer_and_get_next_pointer(void *p_next_pointer) override;
5556
virtual void _on_viewport_composition_layer_destroyed(const void *p_layer) override;
5657
virtual TypedArray<Dictionary> _get_viewport_composition_layer_extension_properties() override;
5758
virtual Dictionary _get_viewport_composition_layer_extension_property_defaults() override;
5859

60+
virtual void _on_session_created(uint64_t p_session) override;
61+
virtual void _on_session_destroyed() override;
62+
5963
bool is_enabled() const;
6064

65+
void set_projection_layer_external_output(ExternalOutput p_external_output);
66+
ExternalOutput get_projection_layer_external_output() const;
67+
6168
OpenXRFbCompositionLayerSecureContentExtension();
6269
~OpenXRFbCompositionLayerSecureContentExtension();
6370

@@ -74,4 +81,14 @@ class OpenXRFbCompositionLayerSecureContentExtension : public OpenXRExtensionWra
7481
bool fb_composition_layer_secure_content = false;
7582

7683
HashMap<const XrCompositionLayerBaseHeader *, XrCompositionLayerSecureContentFB> layer_structs;
84+
85+
XrCompositionLayerSecureContentFB projection_layer_secure_content = {
86+
XR_TYPE_COMPOSITION_LAYER_SECURE_CONTENT_FB, // type
87+
nullptr, // next
88+
0 // flags
89+
};
90+
91+
ExternalOutput projection_layer_external_output = EXTERNAL_OUTPUT_DISPLAY;
7792
};
93+
94+
VARIANT_ENUM_CAST(OpenXRFbCompositionLayerSecureContentExtension::ExternalOutput);

plugin/src/main/cpp/register_types.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ void initialize_plugin_module(ModuleInitializationLevel p_level) {
404404
_register_extension_as_singleton(OpenXRAndroidEnvironmentDepthExtension::get_singleton());
405405
_register_extension_as_singleton(OpenXRFbCompositionLayerDepthTestExtension::get_singleton());
406406
_register_extension_as_singleton(OpenXRFbCompositionLayerImageLayoutExtension::get_singleton());
407+
_register_extension_as_singleton(OpenXRFbCompositionLayerSecureContentExtension::get_singleton());
407408

408409
// @todo GH Issue 304: Remove check for meta headers when feature becomes part of OpenXR spec.
409410
#ifdef META_HEADERS_ENABLED

0 commit comments

Comments
 (0)