OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "device/vr/android/google_vr/google_vr_device_provider.h" |
| 6 |
| 7 #include "base/android/context_utils.h" |
| 8 #include "base/android/jni_android.h" |
| 9 #include "base/android/jni_utils.h" |
| 10 #include "base/android/scoped_java_ref.h" |
| 11 #include "device/vr/android/google_vr/google_vr_device.h" |
| 12 #include "jni/GoogleVRDeviceProvider_jni.h" |
| 13 |
| 14 using base::android::AttachCurrentThread; |
| 15 using base::android::GetApplicationContext; |
| 16 using base::android::GetClassLoader; |
| 17 |
| 18 namespace device { |
| 19 |
| 20 GoogleVRDeviceProvider::GoogleVRDeviceProvider() : VRDeviceProvider() {} |
| 21 |
| 22 GoogleVRDeviceProvider::~GoogleVRDeviceProvider() { |
| 23 if (gvr_) { |
| 24 JNIEnv* env = AttachCurrentThread(); |
| 25 Java_GoogleVRDeviceProvider_shutdown(env, j_device_.obj()); |
| 26 } |
| 27 } |
| 28 |
| 29 void GoogleVRDeviceProvider::GetDevices(std::vector<VRDevice*>* devices) { |
| 30 Initialize(); |
| 31 |
| 32 if (!vr_device_ && gvr_) { |
| 33 vr_device_.reset(new GoogleVRDevice(this, gvr_.get())); |
| 34 devices->push_back(vr_device_.get()); |
| 35 } |
| 36 } |
| 37 |
| 38 void GoogleVRDeviceProvider::Initialize() { |
| 39 if (!gvr_) { |
| 40 JNIEnv* env = AttachCurrentThread(); |
| 41 |
| 42 // Java Route. |
| 43 j_device_.Reset( |
| 44 Java_GoogleVRDeviceProvider_create(env, GetApplicationContext())); |
| 45 jlong gvr_api = |
| 46 Java_GoogleVRDeviceProvider_getNativeContext(env, j_device_.obj()); |
| 47 gvr_ = gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(gvr_api)); |
| 48 } |
| 49 } |
| 50 |
| 51 } // namespace device |
OLD | NEW |