Skip to content

Commit 9e4e54d

Browse files
Merge pull request #320 from ReactVision/metahorizon-support
feat: add Meta Horizon OS support
2 parents 03c24b5 + f228522 commit 9e4e54d

46 files changed

Lines changed: 19327 additions & 20 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ViroRenderer/VROInputControllerBase.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,9 @@ void VROInputControllerBase::onScroll(int source, float x, float y) {
454454
}
455455

456456
void VROInputControllerBase::processGazeEvent(int source) {
457+
if (_hitResult == nullptr) {
458+
return;
459+
}
457460
std::shared_ptr<VRONode> newNode = getNodeToHandleEvent(VROEventDelegate::EventAction::OnHover,
458461
_hitResult->getNode());
459462
for (std::shared_ptr<VROEventDelegate> delegate : _delegates) {

ViroRenderer/VROInputType.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,17 @@ namespace ViroCardBoard{
5757

5858
namespace ViroOculus{
5959
enum InputSource{
60-
Controller = 1,
61-
TouchPad = 2,
62-
BackButton = 3
60+
Controller = 1, // right controller primary ray (legacy alias for RightController)
61+
TouchPad = 2,
62+
BackButton = 3, // menu (left) and B (right) buttons — navigation / back
63+
LeftController = 4, // left controller primary ray
64+
AButton = 5, // right-hand A button
65+
XButton = 6, // left-hand X button
66+
YButton = 7, // left-hand Y button
67+
LeftGrip = 8, // left grip / squeeze
68+
RightGrip = 9, // right grip / squeeze
69+
LeftThumbstick = 10, // left thumbstick scroll axis
70+
RightThumbstick = 11, // right thumbstick scroll axis
6371
};
6472
}
6573
#endif

ViroRenderer/VROPlatformUtil.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ std::string VROPlatformDownloadURLToFile(std::string url, bool *temp, bool *succ
572572
JNIEnv *env = VROPlatformGetJNIEnv();
573573
VRO_STRING jurl = VRO_NEW_STRING(url.c_str());
574574

575-
jclass cls = env->FindClass("com/viro/core/internal/PlatformUtil");
575+
jclass cls = env->GetObjectClass(sPlatformUtil);
576576
jmethodID jmethod = env->GetMethodID(cls, "downloadURLToTempFile", "(Ljava/lang/String;)Ljava/lang/String;");
577577
VRO_STRING jpath = (VRO_STRING) env->CallObjectMethod(sPlatformUtil, jmethod, jurl);
578578

@@ -1069,14 +1069,42 @@ void VROPlatformDispatchAsyncBackground(std::function<void()> fcn) {
10691069
JNIEnv *env;
10701070
getJNIEnv(&env);
10711071

1072-
jclass cls = env->FindClass("com/viro/core/internal/PlatformUtil");
1072+
// GetObjectClass works on any thread (no class-loader dependency).
1073+
// FindClass("com/viro/core/...") fails on pure-native threads that only
1074+
// have the bootstrap class loader (e.g. the OpenXR render thread).
1075+
jclass cls = env->GetObjectClass(sPlatformUtil);
10731076
jmethodID jmethod = env->GetMethodID(cls, "dispatchAsyncBackground", "(I)V");
10741077
env->CallVoidMethod(sPlatformUtil, jmethod, task);
10751078

10761079
env->DeleteLocalRef(cls);
10771080
}
10781081

1082+
// ── Direct renderer queue (for OpenXR / renderers without GLSurfaceView) ──────
1083+
static std::atomic<bool> sUseDirectRendererQueue { false };
1084+
static std::mutex sDirectRendererQueueMutex;
1085+
static std::vector<std::function<void()>> sDirectRendererQueue;
1086+
1087+
void VROPlatformSetUseDirectRendererQueue(bool use) {
1088+
sUseDirectRendererQueue.store(use);
1089+
}
1090+
1091+
void VROPlatformDrainRendererQueue() {
1092+
std::vector<std::function<void()>> tasks;
1093+
{
1094+
std::lock_guard<std::mutex> guard(sDirectRendererQueueMutex);
1095+
tasks.swap(sDirectRendererQueue);
1096+
}
1097+
for (auto &task : tasks) {
1098+
task();
1099+
}
1100+
}
1101+
10791102
void VROPlatformDispatchAsyncRenderer(std::function<void()> fcn) {
1103+
if (sUseDirectRendererQueue.load()) {
1104+
std::lock_guard<std::mutex> guard(sDirectRendererQueueMutex);
1105+
sDirectRendererQueue.push_back(std::move(fcn));
1106+
return;
1107+
}
10801108
int task = VROPlatformGenerateTask(fcn);
10811109
if (!sPlatformUtil) {
10821110
std::lock_guard<std::mutex> guard(sRendererQueueMutex);
@@ -1105,7 +1133,7 @@ void VROPlatformFlushTaskQueues() {
11051133
JNIEnv *env;
11061134
getJNIEnv(&env);
11071135

1108-
jclass cls = env->FindClass("com/viro/core/internal/PlatformUtil");
1136+
jclass cls = env->GetObjectClass(sPlatformUtil);
11091137
jmethodID jmethod = env->GetMethodID(cls, "dispatchAsyncBackground", "(I)V");
11101138
env->CallVoidMethod(sPlatformUtil, jmethod, task);
11111139

@@ -1299,7 +1327,7 @@ std::string VROPlatformGetCacheDirectory() {
12991327
JNIEnv *env;
13001328
getJNIEnv(&env);
13011329

1302-
jclass cls = env->FindClass("com/viro/core/internal/PlatformUtil");
1330+
jclass cls = env->GetObjectClass(sPlatformUtil);
13031331
jmethodID jmethod = env->GetMethodID(cls, "getCacheDirectory", "()Ljava/lang/String;");
13041332
VRO_STRING jpath = (VRO_STRING) env->CallObjectMethod(sPlatformUtil, jmethod);
13051333

ViroRenderer/VROPlatformUtil.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ enum class VROPlatformType {
5353
Unknown,
5454
AndroidGVR,
5555
AndroidOVR,
56+
AndroidOpenXR,
5657
AndroidARCore,
5758
AndroidSceneView,
5859
iOSCardboard,
@@ -163,6 +164,18 @@ VROTextureFormat VROPlatformGetBitmapFormat(jobject jbitmap);
163164
*/
164165
void VROPlatformDispatchAsyncRenderer(std::function<void()> fcn);
165166

167+
/*
168+
OpenXR / headless-GL renderers that own their own render thread should call
169+
VROPlatformSetUseDirectRendererQueue(true) during initialisation. All
170+
subsequent VROPlatformDispatchAsyncRenderer calls will enqueue into a C++
171+
queue instead of going through the GLSurfaceView Java path.
172+
173+
The render thread must call VROPlatformDrainRendererQueue() every frame to
174+
execute queued work (e.g. setSceneController, texture uploads).
175+
*/
176+
void VROPlatformSetUseDirectRendererQueue(bool use);
177+
void VROPlatformDrainRendererQueue();
178+
166179
/*
167180
Run the given function on a background thread. The thread can be pooled,
168181
or spun up fresh. The caller should make no assumptions.

ViroRenderer/VRORenderer.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,14 @@ class VRORenderer {
282282

283283
#pragma mark - Camera
284284

285+
/*
286+
Returns true if the render context has been initialized (initRenderer called).
287+
Safe to call before any scene is set.
288+
*/
289+
bool hasRenderContext() const {
290+
return _context != nullptr;
291+
}
292+
285293
/*
286294
Get the camera used in the last frame.
287295
*/

android/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ allprojects {
1818
mavenCentral()
1919
google()
2020
maven { url 'https://jitpack.io' }
21+
// OpenXR loader — downloaded from Khronos GitHub releases (not on Maven Central)
22+
maven { url "${rootProject.projectDir}/openxr_sdk/maven" }
2123
}
2224
}
2325

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>org.khronos.openxr</groupId>
6+
<artifactId>openxr_loader_for_android</artifactId>
7+
<version>1.1.38</version>
8+
<packaging>aar</packaging>
9+
<name>OpenXR Loader for Android</name>
10+
<description>The AAR for the OpenXR Loader as used on Android.</description>
11+
<url>https://github.com/KhronosGroup/OpenXR-SDK-Source</url>
12+
<licenses>
13+
<license>
14+
<name>Apache-2.0</name>
15+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
16+
</license>
17+
</licenses>
18+
<developers>
19+
<developer>
20+
<name>The Khronos Group, Inc. OpenXR Working Group</name>
21+
<email>openxr-speceditor AT khronos DOT org</email>
22+
<url>https://khronos.org/openxr</url>
23+
</developer>
24+
</developers>
25+
<scm>
26+
<connection>scm:git:https://github.com/KhronosGroup/OpenXR-SDK-Source.git</connection>
27+
<developerConnection>scm:git:https://github.com/KhronosGroup/OpenXR-SDK-Source.git</developerConnection>
28+
<url>https://github.com/KhronosGroup/OpenXR-SDK-Source</url>
29+
</scm>
30+
<issueManagement>
31+
<system>GitHub Issues</system>
32+
<url>https://github.com/KhronosGroup/OpenXR-SDK-Source/issues</url>
33+
</issueManagement>
34+
</project>
1.87 MB
Binary file not shown.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>org.khronos.openxr</groupId>
6+
<artifactId>openxr_loader_for_android</artifactId>
7+
<version>1.1.38</version>
8+
<packaging>aar</packaging>
9+
<name>OpenXR Loader for Android</name>
10+
<description>The AAR for the OpenXR Loader as used on Android.</description>
11+
<url>https://github.com/KhronosGroup/OpenXR-SDK-Source</url>
12+
<licenses>
13+
<license>
14+
<name>Apache-2.0</name>
15+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
16+
</license>
17+
</licenses>
18+
<developers>
19+
<developer>
20+
<name>The Khronos Group, Inc. OpenXR Working Group</name>
21+
<email>openxr-speceditor AT khronos DOT org</email>
22+
<url>https://khronos.org/openxr</url>
23+
</developer>
24+
</developers>
25+
<scm>
26+
<connection>scm:git:https://github.com/KhronosGroup/OpenXR-SDK-Source.git</connection>
27+
<developerConnection>scm:git:https://github.com/KhronosGroup/OpenXR-SDK-Source.git</developerConnection>
28+
<url>https://github.com/KhronosGroup/OpenXR-SDK-Source</url>
29+
</scm>
30+
<issueManagement>
31+
<system>GitHub Issues</system>
32+
<url>https://github.com/KhronosGroup/OpenXR-SDK-Source/issues</url>
33+
</issueManagement>
34+
</project>

0 commit comments

Comments
 (0)