Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(948)

Unified Diff: device/vr/android/gvr/gvr_device_provider.cc

Issue 2309523003: Plumbing through more WebVR presentation code (Closed)
Patch Set: Addressed Michael's feedack Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/vr/android/gvr/gvr_device_provider.h ('k') | device/vr/vr_device.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « device/vr/android/gvr/gvr_device_provider.h ('k') | device/vr/vr_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698