Index: device/vr/android/google_vr/google_vr_device_provider.cc |
diff --git a/device/vr/android/google_vr/google_vr_device_provider.cc b/device/vr/android/google_vr/google_vr_device_provider.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0fc7bd4ba64079780405da9f97633a130a0a4d86 |
--- /dev/null |
+++ b/device/vr/android/google_vr/google_vr_device_provider.cc |
@@ -0,0 +1,51 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "device/vr/android/google_vr/google_vr_device_provider.h" |
+ |
+#include "base/android/context_utils.h" |
+#include "base/android/jni_android.h" |
+#include "base/android/jni_utils.h" |
+#include "base/android/scoped_java_ref.h" |
+#include "device/vr/android/google_vr/google_vr_device.h" |
+#include "jni/GoogleVRDeviceProvider_jni.h" |
+ |
+using base::android::AttachCurrentThread; |
+using base::android::GetApplicationContext; |
+using base::android::GetClassLoader; |
+ |
+namespace device { |
+ |
+GoogleVRDeviceProvider::GoogleVRDeviceProvider() : VRDeviceProvider() {} |
+ |
+GoogleVRDeviceProvider::~GoogleVRDeviceProvider() { |
+ if (gvr_) { |
+ JNIEnv* env = AttachCurrentThread(); |
+ Java_GoogleVRDeviceProvider_shutdown(env, j_device_.obj()); |
+ } |
+} |
+ |
+void GoogleVRDeviceProvider::GetDevices(std::vector<VRDevice*>* devices) { |
+ Initialize(); |
+ |
+ if (!vr_device_ && gvr_) { |
+ vr_device_.reset(new GoogleVRDevice(this, gvr_.get())); |
+ devices->push_back(vr_device_.get()); |
+ } |
+} |
+ |
+void GoogleVRDeviceProvider::Initialize() { |
+ if (!gvr_) { |
+ JNIEnv* env = AttachCurrentThread(); |
+ |
+ // Java Route. |
+ j_device_.Reset( |
+ Java_GoogleVRDeviceProvider_create(env, GetApplicationContext())); |
+ jlong gvr_api = |
+ Java_GoogleVRDeviceProvider_getNativeContext(env, j_device_.obj()); |
+ gvr_ = gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(gvr_api)); |
+ } |
+} |
+ |
+} // namespace device |