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

Commit ffedf1e

Browse files
committed
Utilize external surf id to decide using which external VR surface.
1 parent d17f3ba commit ffedf1e

File tree

7 files changed

+499
-437
lines changed

7 files changed

+499
-437
lines changed

app/src/main/cpp/BrowserWorld.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,10 +1149,11 @@ BrowserWorld::DrawImmersive() {
11491149
m.device->StartFrame();
11501150
VRB_GL_CHECK(glDepthMask(GL_FALSE));
11511151
m.externalVR->PushFramePoses(m.device->GetHeadTransform(), m.controllers->GetControllers(), m.context->GetTimestamp());
1152+
mozilla::gfx::VRLayerTextureType surfaceType;
11521153
int32_t surfaceHandle, textureWidth, textureHeight = 0;
11531154
device::EyeRect leftEye, rightEye;
11541155
bool aDiscardFrame = !m.externalVR->WaitFrameResult();
1155-
m.externalVR->GetFrameResult(surfaceHandle, textureWidth, textureHeight, leftEye, rightEye);
1156+
m.externalVR->GetFrameResult(surfaceType, surfaceHandle, textureWidth, textureHeight, leftEye, rightEye);
11561157
ExternalVR::VRState state = m.externalVR->GetVRState();
11571158
if (state == ExternalVR::VRState::Rendering) {
11581159
if (!aDiscardFrame) {
@@ -1171,13 +1172,23 @@ BrowserWorld::DrawImmersive() {
11711172
#endif // !defined(VRBROWSER_NO_VR_API)
11721173
}
11731174
}
1175+
1176+
if (surfaceType == mozilla::gfx::VRLayerTextureType::LayerTextureType_ExternalVRSurface) {
1177+
m.device->SetExternalSurfId(surfaceHandle);
1178+
}
11741179
m.device->EndFrame(aDiscardFrame);
11751180
m.blitter->EndFrame();
11761181
} else {
11771182
if (surfaceHandle != 0) {
11781183
m.blitter->CancelFrame(surfaceHandle);
11791184
}
11801185
DrawLoadingAnimation();
1186+
1187+
if ((m.device->GetDeviceType() != device::OculusGo) &&
1188+
(m.device->GetDeviceType() != device::OculusQuest)) {
1189+
// Reset surface id when existing the external immersive mode.
1190+
m.device->SetExternalSurfId(-1);
1191+
}
11811192
m.device->EndFrame(false);
11821193
}
11831194
}

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 SetExternalSurfId(int32_t aSurfId) {}
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,9 @@ ExternalVR::CompleteEnumeration()
478478

479479

480480
void
481-
ExternalVR::GetFrameResult(int32_t& aSurfaceHandle, int32_t& aTextureWidth, int32_t& aTextureHeight,
481+
ExternalVR::GetFrameResult(mozilla::gfx::VRLayerTextureType& aSurfaceType, int32_t& aSurfaceHandle, int32_t& aTextureWidth, int32_t& aTextureHeight,
482482
device::EyeRect& aLeftEye, device::EyeRect& aRightEye) const {
483+
aSurfaceType = m.browser.layerState[0].layer_stereo_immersive.textureType;
483484
aSurfaceHandle = (int32_t)m.browser.layerState[0].layer_stereo_immersive.textureHandle;
484485
mozilla::gfx::VRLayerEyeRect& left = m.browser.layerState[0].layer_stereo_immersive.leftEyeRect;
485486
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,

0 commit comments

Comments
 (0)