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

Commit

Permalink
Utilize external surf id to decide using which external VR surface.
Browse files Browse the repository at this point in the history
  • Loading branch information
daoshengmu committed Jul 19, 2019
1 parent d17f3ba commit ffedf1e
Show file tree
Hide file tree
Showing 7 changed files with 499 additions and 437 deletions.
13 changes: 12 additions & 1 deletion app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,10 +1149,11 @@ BrowserWorld::DrawImmersive() {
m.device->StartFrame();
VRB_GL_CHECK(glDepthMask(GL_FALSE));
m.externalVR->PushFramePoses(m.device->GetHeadTransform(), m.controllers->GetControllers(), m.context->GetTimestamp());
mozilla::gfx::VRLayerTextureType surfaceType;
int32_t surfaceHandle, textureWidth, textureHeight = 0;
device::EyeRect leftEye, rightEye;
bool aDiscardFrame = !m.externalVR->WaitFrameResult();
m.externalVR->GetFrameResult(surfaceHandle, textureWidth, textureHeight, leftEye, rightEye);
m.externalVR->GetFrameResult(surfaceType, surfaceHandle, textureWidth, textureHeight, leftEye, rightEye);
ExternalVR::VRState state = m.externalVR->GetVRState();
if (state == ExternalVR::VRState::Rendering) {
if (!aDiscardFrame) {
Expand All @@ -1171,13 +1172,23 @@ BrowserWorld::DrawImmersive() {
#endif // !defined(VRBROWSER_NO_VR_API)
}
}

if (surfaceType == mozilla::gfx::VRLayerTextureType::LayerTextureType_ExternalVRSurface) {
m.device->SetExternalSurfId(surfaceHandle);
}
m.device->EndFrame(aDiscardFrame);
m.blitter->EndFrame();
} else {
if (surfaceHandle != 0) {
m.blitter->CancelFrame(surfaceHandle);
}
DrawLoadingAnimation();

if ((m.device->GetDeviceType() != device::OculusGo) &&
(m.device->GetDeviceType() != device::OculusQuest)) {
// Reset surface id when existing the external immersive mode.
m.device->SetExternalSurfId(-1);
}
m.device->EndFrame(false);
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/cpp/DeviceDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class DeviceDelegate {
virtual void StartFrame() = 0;
virtual void BindEye(const device::Eye aWhich) = 0;
virtual void EndFrame(bool aDiscard = false) = 0;
virtual void SetExternalSurfId(int32_t aSurfId) {}
virtual VRLayerQuadPtr CreateLayerQuad(int32_t aWidth, int32_t aHeight,
VRLayerSurface::SurfaceType aSurfaceType) { return nullptr; }
virtual VRLayerQuadPtr CreateLayerQuad(const VRLayerSurfacePtr& aMoveLayer) { return nullptr; }
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/cpp/ExternalVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,9 @@ ExternalVR::CompleteEnumeration()


void
ExternalVR::GetFrameResult(int32_t& aSurfaceHandle, int32_t& aTextureWidth, int32_t& aTextureHeight,
ExternalVR::GetFrameResult(mozilla::gfx::VRLayerTextureType& aSurfaceType, int32_t& aSurfaceHandle, int32_t& aTextureWidth, int32_t& aTextureHeight,
device::EyeRect& aLeftEye, device::EyeRect& aRightEye) const {
aSurfaceType = m.browser.layerState[0].layer_stereo_immersive.textureType;
aSurfaceHandle = (int32_t)m.browser.layerState[0].layer_stereo_immersive.textureHandle;
mozilla::gfx::VRLayerEyeRect& left = m.browser.layerState[0].layer_stereo_immersive.leftEyeRect;
mozilla::gfx::VRLayerEyeRect& right = m.browser.layerState[0].layer_stereo_immersive.rightEyeRect;
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/cpp/ExternalVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "Controller.h"
#include "DeviceDelegate.h"
#include "Device.h"
#include "moz_external_vr.h"
#include <memory>
#include <string>
#include <vector>
Expand Down Expand Up @@ -54,7 +55,8 @@ class ExternalVR : public ImmersiveDisplay {
VRState GetVRState() const;
void PushFramePoses(const vrb::Matrix& aHeadTransform, const std::vector<Controller>& aControllers, const double aTimestamp);
bool WaitFrameResult();
void GetFrameResult(int32_t& aSurfaceHandle,
void GetFrameResult(mozilla::gfx::VRLayerTextureType& aSurfaceType,
int32_t& aSurfaceHandle,
int32_t& aTextureWidth,
int32_t& aTextureHeight,
device::EyeRect& aLeftEye,
Expand Down
Loading

0 comments on commit ffedf1e

Please sign in to comment.