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

Commit aaa220f

Browse files
committed
Using Surface from swap chains to render immersive frames instead of framebuffer textures.
1 parent d75fa4f commit aaa220f

File tree

11 files changed

+182
-41
lines changed

11 files changed

+182
-41
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.mozilla.geckoview.GeckoRuntime;
4242
import org.mozilla.geckoview.GeckoSession;
4343
import org.mozilla.geckoview.GeckoVRManager;
44+
import org.mozilla.gecko.gfx.ExternalVRSurface;
4445
import org.mozilla.vrbrowser.audio.AudioEngine;
4546
import org.mozilla.vrbrowser.browser.Accounts;
4647
import org.mozilla.vrbrowser.browser.PermissionDelegate;
@@ -1070,6 +1071,21 @@ public void dismiss() {
10701071
});
10711072
}
10721073

1074+
public void setExternalVRSurfaceIndex(int aIndex) {
1075+
GeckoVRManager.setExternalSurfaceIndex(aIndex);
1076+
}
1077+
1078+
public void insertExternalSurface(int aWidth, int aHeight, int aIndex, Surface aSurface) {
1079+
if (aSurface == null) {
1080+
Log.e(LOGTAG, "aSurface is null in setExternalVRSurface...");
1081+
}
1082+
GeckoVRManager.insertExternalSurface(new ExternalVRSurface(aIndex, aWidth, aHeight, aSurface));
1083+
}
1084+
1085+
public void releaseExternalVRSurfaces() {
1086+
GeckoVRManager.releaseExternalSurfaces();
1087+
}
1088+
10731089
private SurfaceTexture createSurfaceTexture() {
10741090
int[] ids = new int[1];
10751091
GLES20.glGenTextures(1, ids, 0);

app/src/common/shared/org/mozilla/vrbrowser/browser/engine/SessionUtils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.mozilla.gecko.GeckoProfile;
1111
import org.mozilla.vrbrowser.browser.SettingsStore;
1212
import org.mozilla.vrbrowser.utils.SystemUtils;
13+
import org.mozilla.vrbrowser.utils.DeviceType;
1314

1415
import java.io.File;
1516
import java.io.FileNotFoundException;
@@ -56,6 +57,12 @@ public static void vrPrefsWorkAround(Context aContext, Bundle aExtras) {
5657
out.write("pref(\"media.autoplay.enabled.ask-permission\", false);\n".getBytes());
5758
out.write("pref(\"media.autoplay.default\", 0);\n".getBytes());
5859
}
60+
// In Oculus platform, we can render WebGL immersive frames info AndroidSurface.
61+
if (DeviceType.isOculusBuild()) {
62+
out.write("pref(\"webgl.enable-externalvr-surface\", true);\n".getBytes());
63+
} else {
64+
out.write("pref(\"webgl.enable-externalvr-surface\", false);\n".getBytes());
65+
}
5966
} catch (FileNotFoundException e) {
6067
Log.e(LOGTAG, "Unable to create file: '" + prefFileName + "' got exception: " + e.toString());
6168
} catch (IOException e) {

app/src/main/cpp/BrowserWorld.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,7 @@ void
12991299
BrowserWorld::DrawWorld() {
13001300
m.externalVR->SetCompositorEnabled(true);
13011301
m.device->SetRenderMode(device::RenderMode::StandAlone);
1302+
m.device->EnableExternalSurfaceRender(false);
13021303
if (m.fadeAnimation) {
13031304
m.fadeAnimation->UpdateAnimation();
13041305
}
@@ -1363,23 +1364,29 @@ BrowserWorld::DrawImmersive() {
13631364
m.device->StartFrame();
13641365
VRB_GL_CHECK(glDepthMask(GL_FALSE));
13651366
m.externalVR->PushFramePoses(m.device->GetHeadTransform(), m.controllers->GetControllers(), m.context->GetTimestamp());
1367+
mozilla::gfx::VRLayerTextureType surfaceType;
13661368
int32_t surfaceHandle, textureWidth, textureHeight = 0;
13671369
device::EyeRect leftEye, rightEye;
13681370
bool aDiscardFrame = !m.externalVR->WaitFrameResult();
1369-
m.externalVR->GetFrameResult(surfaceHandle, textureWidth, textureHeight, leftEye, rightEye);
1371+
m.externalVR->GetFrameResult(surfaceType, surfaceHandle, textureWidth, textureHeight, leftEye, rightEye);
13701372
ExternalVR::VRState state = m.externalVR->GetVRState();
13711373
if (state == ExternalVR::VRState::Rendering) {
13721374
if (!aDiscardFrame) {
13731375
if (textureWidth > 0 && textureHeight > 0) {
13741376
m.device->SetImmersiveSize((uint32_t) textureWidth/2, (uint32_t) textureHeight);
13751377
}
1376-
m.blitter->StartFrame(surfaceHandle, leftEye, rightEye);
1377-
m.device->BindEye(device::Eye::Left);
1378-
m.blitter->Draw(device::Eye::Left);
1378+
m.device->EnableExternalSurfaceRender(surfaceType ==
1379+
mozilla::gfx::VRLayerTextureType::LayerTextureType_ExternalVRSurface);
1380+
// In Oculus platform, we can render WebGL immersive frames info AndroidSurface.
1381+
if (surfaceType != mozilla::gfx::VRLayerTextureType::LayerTextureType_ExternalVRSurface) {
1382+
m.blitter->StartFrame(surfaceHandle, leftEye, rightEye);
1383+
m.device->BindEye(device::Eye::Left);
1384+
m.blitter->Draw(device::Eye::Left);
13791385
#if !defined(VRBROWSER_NO_VR_API)
1380-
m.device->BindEye(device::Eye::Right);
1381-
m.blitter->Draw(device::Eye::Right);
1386+
m.device->BindEye(device::Eye::Right);
1387+
m.blitter->Draw(device::Eye::Right);
13821388
#endif // !defined(VRBROWSER_NO_VR_API)
1389+
}
13831390
}
13841391
m.device->EndFrame(aDiscardFrame);
13851392
m.blitter->EndFrame();

app/src/main/cpp/DeviceDelegate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class DeviceDelegate {
6767
virtual void StartFrame() = 0;
6868
virtual void BindEye(const device::Eye aWhich) = 0;
6969
virtual void EndFrame(bool aDiscard = false) = 0;
70+
virtual void EnableExternalSurfaceRender(bool aEnable) {}
7071
virtual VRLayerQuadPtr CreateLayerQuad(int32_t aWidth, int32_t aHeight,
7172
VRLayerSurface::SurfaceType aSurfaceType) { return nullptr; }
7273
virtual VRLayerQuadPtr CreateLayerQuad(const VRLayerSurfacePtr& aMoveLayer) { return nullptr; }

app/src/main/cpp/ExternalVR.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,10 @@ ExternalVR::CompleteEnumeration()
476476
m.system.enumerationCompleted = true;
477477
}
478478

479-
480479
void
481-
ExternalVR::GetFrameResult(int32_t& aSurfaceHandle, int32_t& aTextureWidth, int32_t& aTextureHeight,
480+
ExternalVR::GetFrameResult(mozilla::gfx::VRLayerTextureType& aSurfaceType, int32_t& aSurfaceHandle, int32_t& aTextureWidth, int32_t& aTextureHeight,
482481
device::EyeRect& aLeftEye, device::EyeRect& aRightEye) const {
482+
aSurfaceType = m.browser.layerState[0].layer_stereo_immersive.textureType;
483483
aSurfaceHandle = (int32_t)m.browser.layerState[0].layer_stereo_immersive.textureHandle;
484484
mozilla::gfx::VRLayerEyeRect& left = m.browser.layerState[0].layer_stereo_immersive.leftEyeRect;
485485
mozilla::gfx::VRLayerEyeRect& right = m.browser.layerState[0].layer_stereo_immersive.rightEyeRect;

app/src/main/cpp/ExternalVR.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "Controller.h"
1111
#include "DeviceDelegate.h"
1212
#include "Device.h"
13+
#include "moz_external_vr.h"
1314
#include <memory>
1415
#include <string>
1516
#include <vector>
@@ -54,7 +55,8 @@ class ExternalVR : public ImmersiveDisplay {
5455
VRState GetVRState() const;
5556
void PushFramePoses(const vrb::Matrix& aHeadTransform, const std::vector<Controller>& aControllers, const double aTimestamp);
5657
bool WaitFrameResult();
57-
void GetFrameResult(int32_t& aSurfaceHandle,
58+
void GetFrameResult(mozilla::gfx::VRLayerTextureType& aSurfaceType,
59+
int32_t& aSurfaceHandle,
5860
int32_t& aTextureWidth,
5961
int32_t& aTextureHeight,
6062
device::EyeRect& aLeftEye,

app/src/main/cpp/VRBrowser.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ const char* kHaltActivity = "haltActivity";
5252
const char* kHaltActivitySignature = "(I)V";
5353
const char* kHandlePoorPerformance = "handlePoorPerformance";
5454
const char* kHandlePoorPerformanceSignature = "()V";
55+
const char* kSetExternalVRSurfaceIndex = "setExternalVRSurfaceIndex";
56+
const char* kSetExternalVRSurfaceIndexSignature = "(I)V";
57+
const char* kInsertExternalVRSurface = "insertExternalSurface";
58+
const char* kInsertExternalVRSurfaceSignature = "(IIILandroid/view/Surface;)V";
59+
const char* kReleaseExternalSurfaces = "releaseExternalVRSurfaces";
60+
const char* kReleaseExternalSurfacesSignature = "()V";
5561

5662
JNIEnv* sEnv = nullptr;
5763
jclass sBrowserClass = nullptr;
@@ -77,6 +83,9 @@ jmethodID sAreLayersEnabled = nullptr;
7783
jmethodID sSetDeviceType = nullptr;
7884
jmethodID sHaltActivity = nullptr;
7985
jmethodID sHandlePoorPerformance = nullptr;
86+
jmethodID sSetExternalVRSurfaceIndex = nullptr;
87+
jmethodID sInsertExternalVRSurface = nullptr;
88+
jmethodID sReleaseExternalSurfaces = nullptr;
8089
}
8190

8291
namespace crow {
@@ -117,6 +126,9 @@ VRBrowser::InitializeJava(JNIEnv* aEnv, jobject aActivity) {
117126
sSetDeviceType = FindJNIMethodID(sEnv, sBrowserClass, kSetDeviceType, kSetDeviceTypeSignature);
118127
sHaltActivity = FindJNIMethodID(sEnv, sBrowserClass, kHaltActivity, kHaltActivitySignature);
119128
sHandlePoorPerformance = FindJNIMethodID(sEnv, sBrowserClass, kHandlePoorPerformance, kHandlePoorPerformanceSignature);
129+
sInsertExternalVRSurface = FindJNIMethodID(sEnv, sBrowserClass, kInsertExternalVRSurface, kInsertExternalVRSurfaceSignature);
130+
sSetExternalVRSurfaceIndex = FindJNIMethodID(sEnv, sBrowserClass, kSetExternalVRSurfaceIndex, kSetExternalVRSurfaceIndexSignature);
131+
sReleaseExternalSurfaces = FindJNIMethodID(sEnv, sBrowserClass, kReleaseExternalSurfaces, kReleaseExternalSurfacesSignature);
120132
}
121133

122134
void
@@ -151,6 +163,7 @@ VRBrowser::ShutdownJava() {
151163
sAreLayersEnabled = nullptr;
152164
sSetDeviceType = nullptr;
153165
sHaltActivity = nullptr;
166+
sInsertExternalVRSurface = nullptr;
154167
sEnv = nullptr;
155168
}
156169

@@ -339,4 +352,24 @@ VRBrowser::HandlePoorPerformance() {
339352
CheckJNIException(sEnv, __FUNCTION__);
340353
}
341354

355+
void
356+
VRBrowser::SetExternalVRSurfaceId(jint aId) {
357+
if (!ValidateMethodID(sEnv, sActivity, sSetExternalVRSurfaceIndex, __FUNCTION__)) { return; }
358+
sEnv->CallVoidMethod(sActivity, sSetExternalVRSurfaceIndex, aId);
359+
CheckJNIException(sEnv, __FUNCTION__);
360+
}
361+
362+
void
363+
VRBrowser::InsertExternalVRSurface(jint aWidth, jint aHeight, jint aIndex, jobject aSurface) {
364+
if (!ValidateMethodID(sEnv, sActivity, sInsertExternalVRSurface, __FUNCTION__)) { return; }
365+
sEnv->CallVoidMethod(sActivity, sInsertExternalVRSurface, aWidth, aHeight, aIndex, aSurface);
366+
CheckJNIException(sEnv, __FUNCTION__);
367+
}
368+
369+
void
370+
VRBrowser::ReleaseExternalVRSurfaces() {
371+
if (!ValidateMethodID(sEnv, sActivity, sReleaseExternalSurfaces, __FUNCTION__)) { return; }
372+
sEnv->CallVoidMethod(sActivity, sReleaseExternalSurfaces);
373+
CheckJNIException(sEnv, __FUNCTION__);
374+
}
342375
} // namespace crow

app/src/main/cpp/VRBrowser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ bool AreLayersEnabled();
3939
void SetDeviceType(const jint aType);
4040
void HaltActivity(const jint aReason);
4141
void HandlePoorPerformance();
42+
void SetExternalVRSurfaceId(jint aId);
43+
void InsertExternalVRSurface(jint aWidth, jint aHeight, jint aIndex, jobject aSurface);
44+
void ReleaseExternalVRSurfaces();
4245
} // namespace VRBrowser;
4346

4447
} // namespace crow

app/src/main/cpp/moz_external_vr.h

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ namespace gfx {
4747
// and mapped files if we have both release and nightlies
4848
// running at the same time? Or...what if we have multiple
4949
// release builds running on same machine? (Bug 1563232)
50-
#define SHMEM_VERSION "0.0.4"
51-
static const int32_t kVRExternalVersion = 11;
50+
#define SHMEM_VERSION "0.0.5"
51+
static const int32_t kVRExternalVersion = 12;
5252

5353
// We assign VR presentations to groups with a bitmask.
5454
// Currently, we will only display either content or chrome.
@@ -102,26 +102,26 @@ enum class ControllerCapabilityFlags : uint16_t {
102102
/**
103103
* Cap_Position is set if the Gamepad is capable of tracking its position.
104104
*/
105-
Cap_Position = 1 << 1,
105+
Cap_Position = 1 << 1,
106106
/**
107107
* Cap_Orientation is set if the Gamepad is capable of tracking its
108108
* orientation.
109109
*/
110-
Cap_Orientation = 1 << 2,
110+
Cap_Orientation = 1 << 2,
111111
/**
112112
* Cap_AngularAcceleration is set if the Gamepad is capable of tracking its
113113
* angular acceleration.
114114
*/
115-
Cap_AngularAcceleration = 1 << 3,
115+
Cap_AngularAcceleration = 1 << 3,
116116
/**
117117
* Cap_LinearAcceleration is set if the Gamepad is capable of tracking its
118118
* linear acceleration.
119119
*/
120-
Cap_LinearAcceleration = 1 << 4,
120+
Cap_LinearAcceleration = 1 << 4,
121121
/**
122122
* Cap_All used for validity checking during IPC serialization
123123
*/
124-
Cap_All = (1 << 5) - 1
124+
Cap_All = (1 << 5) - 1
125125
};
126126

127127
#endif // ifndef MOZILLA_INTERNAL_API
@@ -133,75 +133,75 @@ enum class VRDisplayCapabilityFlags : uint16_t {
133133
/**
134134
* Cap_Position is set if the VRDisplay is capable of tracking its position.
135135
*/
136-
Cap_Position = 1 << 1,
136+
Cap_Position = 1 << 1,
137137
/**
138138
* Cap_Orientation is set if the VRDisplay is capable of tracking its
139139
* orientation.
140140
*/
141-
Cap_Orientation = 1 << 2,
141+
Cap_Orientation = 1 << 2,
142142
/**
143143
* Cap_Present is set if the VRDisplay is capable of presenting content to an
144144
* HMD or similar device. Can be used to indicate "magic window" devices that
145145
* are capable of 6DoF tracking but for which requestPresent is not
146146
* meaningful. If false then calls to requestPresent should always fail, and
147147
* getEyeParameters should return null.
148148
*/
149-
Cap_Present = 1 << 3,
149+
Cap_Present = 1 << 3,
150150
/**
151151
* Cap_External is set if the VRDisplay is separate from the device's
152152
* primary display. If presenting VR content will obscure
153153
* other content on the device, this should be un-set. When
154154
* un-set, the application should not attempt to mirror VR content
155155
* or update non-VR UI because that content will not be visible.
156156
*/
157-
Cap_External = 1 << 4,
157+
Cap_External = 1 << 4,
158158
/**
159159
* Cap_AngularAcceleration is set if the VRDisplay is capable of tracking its
160160
* angular acceleration.
161161
*/
162-
Cap_AngularAcceleration = 1 << 5,
162+
Cap_AngularAcceleration = 1 << 5,
163163
/**
164164
* Cap_LinearAcceleration is set if the VRDisplay is capable of tracking its
165165
* linear acceleration.
166166
*/
167-
Cap_LinearAcceleration = 1 << 6,
167+
Cap_LinearAcceleration = 1 << 6,
168168
/**
169169
* Cap_StageParameters is set if the VRDisplay is capable of room scale VR
170170
* and can report the StageParameters to describe the space.
171171
*/
172-
Cap_StageParameters = 1 << 7,
172+
Cap_StageParameters = 1 << 7,
173173
/**
174174
* Cap_MountDetection is set if the VRDisplay is capable of sensing when the
175175
* user is wearing the device.
176176
*/
177-
Cap_MountDetection = 1 << 8,
177+
Cap_MountDetection = 1 << 8,
178178
/**
179179
* Cap_PositionEmulated is set if the VRDisplay is capable of setting a
180180
* emulated position (e.g. neck model) even if still doesn't support 6DOF
181181
* tracking.
182182
*/
183-
Cap_PositionEmulated = 1 << 9,
183+
Cap_PositionEmulated = 1 << 9,
184184
/**
185185
* Cap_Inline is set if the device can be used for WebXR inline sessions
186186
* where the content is displayed within an element on the page.
187187
*/
188-
Cap_Inline = 1 << 10,
188+
Cap_Inline = 1 << 10,
189189
/**
190190
* Cap_ImmersiveVR is set if the device can give exclusive access to the
191191
* XR device display and that content is not intended to be integrated
192192
* with the user's environment
193193
*/
194-
Cap_ImmersiveVR = 1 << 11,
194+
Cap_ImmersiveVR = 1 << 11,
195195
/**
196196
* Cap_ImmersiveAR is set if the device can give exclusive access to the
197197
* XR device display and that content is intended to be integrated with
198198
* the user's environment.
199199
*/
200-
Cap_ImmersiveAR = 1 << 12,
200+
Cap_ImmersiveAR = 1 << 12,
201201
/**
202202
* Cap_All used for validity checking during IPC serialization
203203
*/
204-
Cap_All = (1 << 13) - 1
204+
Cap_All = (1 << 13) - 1
205205
};
206206

207207
#ifdef MOZILLA_INTERNAL_API
@@ -372,7 +372,8 @@ enum class VRLayerTextureType : uint16_t {
372372
LayerTextureType_None = 0,
373373
LayerTextureType_D3D10SurfaceDescriptor = 1,
374374
LayerTextureType_MacIOSurface = 2,
375-
LayerTextureType_GeckoSurfaceTexture = 3
375+
LayerTextureType_GeckoSurfaceTexture = 3,
376+
LayerTextureType_ExternalVRSurface = 4
376377
};
377378

378379
struct VRLayer_2D_Content {

0 commit comments

Comments
 (0)