Index: device/vr/android/gvr/gvr_device_provider.cc |
diff --git a/device/vr/android/gvr/gvr_device_provider.cc b/device/vr/android/gvr/gvr_device_provider.cc |
index fd54be19b18fd25a5f2d2177b92c21e704801732..ad21151426db9f44117c538c14586b8f061e47e8 100644 |
--- a/device/vr/android/gvr/gvr_device_provider.cc |
+++ b/device/vr/android/gvr/gvr_device_provider.cc |
@@ -4,6 +4,8 @@ |
#include "device/vr/android/gvr/gvr_device_provider.h" |
+#include <jni.h> |
+ |
#include "base/android/context_utils.h" |
#include "base/android/jni_android.h" |
#include "base/android/jni_utils.h" |
@@ -16,20 +18,64 @@ using base::android::GetApplicationContext; |
namespace device { |
+// A temporary delegate till the VrShell is available. |
+class GvrDeviceProviderDelegate : public GvrDelegate { |
+ public: |
+ GvrDeviceProviderDelegate() { |
+ // TODO: This should eventually be handled by an actual GvrLayout instance |
+ // in the view tree. |
+ if (j_device_.is_null()) { |
+ JNIEnv* env = AttachCurrentThread(); |
+ |
+ j_device_.Reset( |
+ Java_GvrDeviceProvider_create(env, GetApplicationContext())); |
+ jlong context = |
+ Java_GvrDeviceProvider_getNativeContext(env, j_device_.obj()); |
+ |
+ if (!context) |
+ return; |
+ |
+ gvr_api_ = |
+ gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(context)); |
+ |
+ GvrDelegateManager::GetInstance()->Initialize(this); |
+ } |
+ } |
+ |
+ virtual ~GvrDeviceProviderDelegate() { |
+ // TODO: This should eventually be handled by an actual GvrLayout instance |
+ // in the view tree. |
+ GvrDelegateManager::GetInstance()->Shutdown(); |
+ if (!j_device_.is_null()) { |
+ JNIEnv* env = AttachCurrentThread(); |
+ Java_GvrDeviceProvider_shutdown(env, j_device_.obj()); |
+ } |
+ } |
+ |
+ // GvrDelegate implementation |
+ void RequestWebVRPresent() override {} |
+ void ExitWebVRPresent() override {} |
+ |
+ void SubmitWebVRFrame() override {} |
+ void UpdateWebVRTextureBounds(int eye, |
+ float left, |
+ float top, |
+ float width, |
+ float height) override {} |
+ |
+ gvr::GvrApi* gvr_api() override { return gvr_api_.get(); } |
+ |
+ private: |
+ base::android::ScopedJavaGlobalRef<jobject> j_device_; |
+ std::unique_ptr<gvr::GvrApi> gvr_api_; |
+}; |
+ |
GvrDeviceProvider::GvrDeviceProvider() : VRDeviceProvider() { |
- GvrApiManager::GetInstance()->AddClient(this); |
+ GvrDelegateManager::GetInstance()->AddClient(this); |
} |
GvrDeviceProvider::~GvrDeviceProvider() { |
- // TODO: This should eventually be handled by an actual GvrLayout instance in |
- // the view tree. |
- GvrApiManager::GetInstance()->Shutdown(); |
- if (!j_device_.is_null()) { |
- JNIEnv* env = AttachCurrentThread(); |
- Java_GvrDeviceProvider_shutdown(env, j_device_.obj()); |
- } |
- |
- GvrApiManager::GetInstance()->RemoveClient(this); |
+ GvrDelegateManager::GetInstance()->RemoveClient(this); |
} |
void GvrDeviceProvider::GetDevices(std::vector<VRDevice*>* devices) { |
@@ -40,33 +86,21 @@ void GvrDeviceProvider::GetDevices(std::vector<VRDevice*>* devices) { |
} |
void GvrDeviceProvider::Initialize() { |
- // TODO: This should eventually be handled by an actual GvrLayout instance in |
- // the view tree. |
- if (j_device_.is_null()) { |
- JNIEnv* env = AttachCurrentThread(); |
- |
- j_device_.Reset( |
- Java_GvrDeviceProvider_create(env, GetApplicationContext())); |
- jlong gvr_api = |
- Java_GvrDeviceProvider_getNativeContext(env, j_device_.obj()); |
- |
- if (!gvr_api) |
- return; |
- |
- GvrApiManager::GetInstance()->Initialize( |
- reinterpret_cast<gvr_context*>(gvr_api)); |
+ if (!delegate_) { |
+ delegate_.reset(new GvrDeviceProviderDelegate()); |
} |
} |
-void GvrDeviceProvider::OnGvrApiInitialized(gvr::GvrApi* gvr_api) { |
+void GvrDeviceProvider::OnDelegateInitialized(GvrDelegate* delegate) { |
if (!vr_device_) |
- vr_device_.reset(new GvrDevice(this, gvr_api)); |
+ vr_device_.reset(new GvrDevice(this, delegate)); |
// Should fire a vrdisplayconnected event here. |
} |
-void GvrDeviceProvider::OnGvrApiShutdown() { |
- // Nothing to do here just yet. Eventually want to shut down the VRDevice |
+void GvrDeviceProvider::OnDelegateShutdown() { |
+ // Nothing to do here just yet. Eventually want to shut down the VRDevice and |
+ // fire a vrdisplaydisconnected event. |
} |
} // namespace device |