Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 52a1b7f

Browse files
committed
Release external VR surfaces when leaving VR.
1 parent e624187 commit 52a1b7f

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,14 +889,16 @@ public void confirm(int button) {
889889
}
890890

891891
public void setExternalVRSurface(int aIndex, Surface aSurface) {
892-
// Calling GeckoVRManager ...
893892
if (aSurface == null) {
894893
Log.e(LOGTAG, "aSurface is null in setExternalVRSurface...");
895894
}
896-
Log.i(LOGTAG, "setExternalVRSurface...");
897895
GeckoVRManager.insertExternalSurface(aIndex, aSurface);
898896
}
899897

898+
public void releaseExternalVRSurfaces() {
899+
GeckoVRManager.releaseExternalSurfaces();
900+
}
901+
900902
void createOffscreenDisplay() {
901903
int[] ids = new int[1];
902904
GLES20.glGenTextures(1, ids, 0);

app/src/main/cpp/VRBrowser.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ const char* kHaltActivitySignature = "(I)V";
5151
const char* kHandlePoorPerformance = "handlePoorPerformance";
5252
const char* kHandlePoorPerformanceSignature = "()V";
5353
const char* kSetExternalVRSurface = "setExternalVRSurface";
54-
const char* kSetExternalVRSurfaceSignature = "(ILandroid/view/Surface;)V";//"(ILandroid/view/Surface;)Z";
54+
const char* kSetExternalVRSurfaceSignature = "(ILandroid/view/Surface;)V";
55+
const char* kReleaseExternalSurfaces = "releaseExternalVRSurfaces";
56+
const char* kReleaseExternalSurfacesSignature = "()V";
5557

5658
JNIEnv* sEnv = nullptr;
5759
jclass sBrowserClass = nullptr;
@@ -76,7 +78,8 @@ jmethodID sAreLayersEnabled = nullptr;
7678
jmethodID sSetDeviceType = nullptr;
7779
jmethodID sHaltActivity = nullptr;
7880
jmethodID sHandlePoorPerformance = nullptr;
79-
jmethodID sSetExternalVRSurface;
81+
jmethodID sSetExternalVRSurface = nullptr;
82+
jmethodID sReleaseExternalSurfaces = nullptr;
8083
}
8184

8285
namespace crow {
@@ -117,6 +120,7 @@ VRBrowser::InitializeJava(JNIEnv* aEnv, jobject aActivity) {
117120
sHaltActivity = FindJNIMethodID(sEnv, sBrowserClass, kHaltActivity, kHaltActivitySignature);
118121
sHandlePoorPerformance = FindJNIMethodID(sEnv, sBrowserClass, kHandlePoorPerformance, kHandlePoorPerformanceSignature);
119122
sSetExternalVRSurface = FindJNIMethodID(sEnv, sBrowserClass, kSetExternalVRSurface, kSetExternalVRSurfaceSignature);
123+
sReleaseExternalSurfaces = FindJNIMethodID(sEnv, sBrowserClass, kReleaseExternalSurfaces, kReleaseExternalSurfacesSignature);
120124
}
121125

122126
void
@@ -338,4 +342,11 @@ VRBrowser::SetExternalVRSurface(jint aIndex, jobject aSurface) {
338342
sEnv->CallVoidMethod(sActivity, sSetExternalVRSurface, aIndex, aSurface);
339343
CheckJNIException(sEnv, __FUNCTION__);
340344
}
345+
346+
void
347+
VRBrowser::ReleaseExternalVRSurfaces() {
348+
if (!ValidateMethodID(sEnv, sActivity, sReleaseExternalSurfaces, __FUNCTION__)) { return; }
349+
sEnv->CallVoidMethod(sActivity, sReleaseExternalSurfaces);
350+
CheckJNIException(sEnv, __FUNCTION__);
351+
}
341352
} // namespace crow

app/src/main/cpp/VRBrowser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ void SetDeviceType(const jint aType);
3939
void HaltActivity(const jint aReason);
4040
void HandlePoorPerformance();
4141
void SetExternalVRSurface(jint aIndex, jobject aSurface);
42+
void ReleaseExternalVRSurfaces();
4243
} // namespace VRBrowser;
4344

4445
} // namespace crow

app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,7 @@ DeviceDelegateOculusVR::LeaveVR() {
16981698
if (m.eyeSurfaceSwapChain[i]) {
16991699
vrapi_DestroyTextureSwapChain(m.eyeSurfaceSwapChain[i]);
17001700
m.eyeSurfaceSwapChain[i] = nullptr;
1701+
VRBrowser::ReleaseExternalVRSurfaces();
17011702
}
17021703
}
17031704
if (m.cubeLayer) {

0 commit comments

Comments
 (0)