| 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/gvr/gvr_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/gvr/gvr_device.h" | |
| 12 #include "jni/GvrDeviceProvider_jni.h" | |
| 13 | |
| 14 using base::android::AttachCurrentThread; | |
| 15 using base::android::GetApplicationContext; | |
| 16 | |
| 17 namespace device { | |
| 18 | |
| 19 GvrDeviceProvider::GvrDeviceProvider() : VRDeviceProvider() { | |
| 20 GvrApiManager::GetInstance()->AddClient(this); | |
| 21 } | |
| 22 | |
| 23 GvrDeviceProvider::~GvrDeviceProvider() { | |
| 24 // TODO: This should eventually be handled by an actual GvrLayout instance in | |
| 25 // the view tree. | |
| 26 GvrApiManager::GetInstance()->Shutdown(); | |
| 27 if (!j_device_.is_null()) { | |
| 28 JNIEnv* env = AttachCurrentThread(); | |
| 29 Java_GvrDeviceProvider_shutdown(env, j_device_.obj()); | |
| 30 } | |
| 31 | |
| 32 GvrApiManager::GetInstance()->RemoveClient(this); | |
| 33 } | |
| 34 | |
| 35 void GvrDeviceProvider::GetDevices(std::vector<VRDevice*>* devices) { | |
| 36 Initialize(); | |
| 37 | |
| 38 if (vr_device_) | |
| 39 devices->push_back(vr_device_.get()); | |
| 40 } | |
| 41 | |
| 42 void GvrDeviceProvider::Initialize() { | |
| 43 // TODO: This should eventually be handled by an actual GvrLayout instance in | |
| 44 // the view tree. | |
| 45 if (j_device_.is_null()) { | |
| 46 JNIEnv* env = AttachCurrentThread(); | |
| 47 | |
| 48 j_device_.Reset( | |
| 49 Java_GvrDeviceProvider_create(env, GetApplicationContext())); | |
| 50 jlong gvr_api = | |
| 51 Java_GvrDeviceProvider_getNativeContext(env, j_device_.obj()); | |
| 52 | |
| 53 if (!gvr_api) | |
| 54 return; | |
| 55 | |
| 56 GvrApiManager::GetInstance()->Initialize( | |
| 57 reinterpret_cast<gvr_context*>(gvr_api)); | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 void GvrDeviceProvider::OnGvrApiInitialized(gvr::GvrApi* gvr_api) { | |
| 62 if (!vr_device_) | |
| 63 vr_device_.reset(new GvrDevice(this, gvr_api)); | |
| 64 | |
| 65 // Should fire a vrdisplayconnected event here. | |
| 66 } | |
| 67 | |
| 68 void GvrDeviceProvider::OnGvrApiShutdown() { | |
| 69 // Nothing to do here just yet. Eventually want to shut down the VRDevice | |
| 70 } | |
| 71 | |
| 72 } // namespace device | |
| OLD | NEW |