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 25a374e commit 6cea36d
Show file tree
Hide file tree
Showing 7 changed files with 504 additions and 454 deletions.
20 changes: 14 additions & 6 deletions app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1174,23 +1174,29 @@ 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) {
if (textureWidth > 0 && textureHeight > 0) {
m.device->SetImmersiveSize((uint32_t) textureWidth/2, (uint32_t) textureHeight);
}
m.blitter->StartFrame(surfaceHandle, leftEye, rightEye);
m.device->BindEye(device::Eye::Left);
m.blitter->Draw(device::Eye::Left);
// In Oculus platform, we can render WebGL immersive frames info AndroidSurface.
if (surfaceType != mozilla::gfx::VRLayerTextureType::LayerTextureType_ExternalVRSurface) {
m.blitter->StartFrame(surfaceHandle, leftEye, rightEye);
m.device->BindEye(device::Eye::Left);
m.blitter->Draw(device::Eye::Left);
#if !defined(VRBROWSER_NO_VR_API)
m.device->BindEye(device::Eye::Right);
m.blitter->Draw(device::Eye::Right);
m.device->BindEye(device::Eye::Right);
m.blitter->Draw(device::Eye::Right);
#endif // !defined(VRBROWSER_NO_VR_API)
} else {
m.device->SetExternalSurfId(surfaceHandle);
}
}
m.device->EndFrame(aDiscardFrame);
m.blitter->EndFrame();
Expand All @@ -1199,6 +1205,8 @@ BrowserWorld::DrawImmersive() {
m.blitter->CancelFrame(surfaceHandle);
}
DrawLoadingAnimation();

m.device->SetExternalSurfId(DeviceDelegate::DEFAULT_EXTERNAL_SURFACE_ID);
m.device->EndFrame(false);
}
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/cpp/DeviceDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class ImmersiveDisplay {

class DeviceDelegate {
public:
static const int32_t DEFAULT_EXTERNAL_SURFACE_ID = -1;

virtual device::DeviceType GetDeviceType() { return device::UnknownType; }
virtual void SetRenderMode(const device::RenderMode aMode) = 0;
virtual device::RenderMode GetRenderMode() = 0;
Expand All @@ -67,6 +69,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 6cea36d

Please sign in to comment.