Index: chrome/browser/android/vr_shell/vr_shell_delegate.cc |
diff --git a/chrome/browser/android/vr_shell/vr_shell_delegate.cc b/chrome/browser/android/vr_shell/vr_shell_delegate.cc |
index 606a641702abb96ca529c98b09e560d021e38e8e..af69ba1a03620671880aa90cf4f915f72e35e64e 100644 |
--- a/chrome/browser/android/vr_shell/vr_shell_delegate.cc |
+++ b/chrome/browser/android/vr_shell/vr_shell_delegate.cc |
@@ -13,6 +13,32 @@ using base::android::AttachCurrentThread; |
namespace vr_shell { |
+// A non presenting delegate for magic window mode. |
+class GvrNonPresentingDelegate : public device::GvrDelegate { |
+ public: |
+ explicit GvrNonPresentingDelegate(jlong context) { |
+ gvr_api_ = |
+ gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(context)); |
+ } |
+ |
+ virtual ~GvrNonPresentingDelegate() = default; |
+ |
+ // GvrDelegate implementation |
+ void SetWebVRSecureOrigin(bool secure_origin) override {} |
+ void SubmitWebVRFrame() override {} |
+ void UpdateWebVRTextureBounds(int eye, |
+ float left, |
+ float top, |
+ float width, |
+ float height) override {} |
+ void SetGvrPoseForWebVr(const gvr::Mat4f& pose, |
+ uint32_t pose_index) override {} |
+ gvr::GvrApi* gvr_api() override { return gvr_api_.get(); } |
+ |
+ private: |
+ std::unique_ptr<gvr::GvrApi> gvr_api_; |
+}; |
+ |
VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj) |
: device_provider_(nullptr) { |
j_vr_shell_delegate_.Reset(env, obj); |
@@ -62,6 +88,26 @@ void VrShellDelegate::ExitWebVRPresent() { |
Java_VrShellDelegate_exitWebVR(env, j_vr_shell_delegate_.obj()); |
} |
+device::GvrDelegate* VrShellDelegate::GetNonPresentingDelegate() { |
+ if (!non_presenting_delegate_) { |
+ JNIEnv* env = AttachCurrentThread(); |
+ jlong context = Java_VrShellDelegate_createNonPresentingNativeContext( |
+ env, j_vr_shell_delegate_.obj()); |
+ if (!context) |
+ return nullptr; |
+ |
+ non_presenting_delegate_.reset(new GvrNonPresentingDelegate(context)); |
+ } |
+ return non_presenting_delegate_.get(); |
+} |
+ |
+void VrShellDelegate::DestroyNonPresentingDelegate() { |
+ non_presenting_delegate_.reset(nullptr); |
+ JNIEnv* env = AttachCurrentThread(); |
+ Java_VrShellDelegate_shutdownNonPresentingNativeContext( |
+ env, j_vr_shell_delegate_.obj()); |
+} |
+ |
void VrShellDelegate::OnVrShellReady(VrShell* vr_shell) { |
if (device_provider_) |
device_provider_->OnGvrDelegateReady(vr_shell); |