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

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell_delegate.cc

Issue 2844833005: Tentatively goes into WebVR presentation mode if page listens to vrdisplayactivate. (Closed)
Patch Set: Fixed device unit tests Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" 5 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "chrome/browser/android/vr_shell/non_presenting_gvr_delegate.h" 11 #include "chrome/browser/android/vr_shell/non_presenting_gvr_delegate.h"
12 #include "device/vr/android/gvr/gvr_delegate.h" 12 #include "device/vr/android/gvr/gvr_delegate.h"
13 #include "device/vr/android/gvr/gvr_device.h" 13 #include "device/vr/android/gvr/gvr_device.h"
14 #include "device/vr/android/gvr/gvr_device_provider.h" 14 #include "device/vr/android/gvr/gvr_device_provider.h"
15 #include "jni/VrShellDelegate_jni.h" 15 #include "jni/VrShellDelegate_jni.h"
16 16
17 using base::android::JavaParamRef; 17 using base::android::JavaParamRef;
18 using base::android::AttachCurrentThread; 18 using base::android::AttachCurrentThread;
19 19
20 namespace vr_shell { 20 namespace vr_shell {
21 21
22 VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj) { 22 VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj)
23 : weak_ptr_factory_(this) {
23 DVLOG(1) << __FUNCTION__ << "=" << this; 24 DVLOG(1) << __FUNCTION__ << "=" << this;
24 j_vr_shell_delegate_.Reset(env, obj); 25 j_vr_shell_delegate_.Reset(env, obj);
25 } 26 }
26 27
27 VrShellDelegate::~VrShellDelegate() { 28 VrShellDelegate::~VrShellDelegate() {
28 DVLOG(1) << __FUNCTION__ << "=" << this; 29 DVLOG(1) << __FUNCTION__ << "=" << this;
29 if (device_provider_) { 30 if (device_provider_) {
30 device_provider_->Device()->OnExitPresent(); 31 device_provider_->Device()->OnExitPresent();
31 device_provider_->Device()->OnDelegateChanged(); 32 device_provider_->Device()->OnDelegateChanged();
32 } 33 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 101 }
101 102
102 base::ResetAndReturn(&present_callback_).Run(success); 103 base::ResetAndReturn(&present_callback_).Run(success);
103 pending_successful_present_request_ = false; 104 pending_successful_present_request_ = false;
104 } 105 }
105 106
106 void VrShellDelegate::DisplayActivate(JNIEnv* env, 107 void VrShellDelegate::DisplayActivate(JNIEnv* env,
107 const JavaParamRef<jobject>& obj) { 108 const JavaParamRef<jobject>& obj) {
108 if (device_provider_) { 109 if (device_provider_) {
109 device_provider_->Device()->OnActivate( 110 device_provider_->Device()->OnActivate(
110 device::mojom::VRDisplayEventReason::MOUNTED); 111 device::mojom::VRDisplayEventReason::MOUNTED,
112 base::Bind(&VrShellDelegate::OnActivateDisplayHandled,
113 weak_ptr_factory_.GetWeakPtr()));
111 } 114 }
112 } 115 }
113 116
114 void VrShellDelegate::UpdateVSyncInterval(JNIEnv* env, 117 void VrShellDelegate::UpdateVSyncInterval(JNIEnv* env,
115 const JavaParamRef<jobject>& obj, 118 const JavaParamRef<jobject>& obj,
116 jlong timebase_nanos, 119 jlong timebase_nanos,
117 jdouble interval_seconds) { 120 jdouble interval_seconds) {
118 timebase_nanos_ = timebase_nanos; 121 timebase_nanos_ = timebase_nanos;
119 interval_seconds_ = interval_seconds; 122 interval_seconds_ = interval_seconds;
120 if (presenting_delegate_) { 123 if (presenting_delegate_) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 JNIEnv* env = AttachCurrentThread(); 199 JNIEnv* env = AttachCurrentThread();
197 gvr_context* context = reinterpret_cast<gvr_context*>( 200 gvr_context* context = reinterpret_cast<gvr_context*>(
198 Java_VrShellDelegate_createNonPresentingNativeContext( 201 Java_VrShellDelegate_createNonPresentingNativeContext(
199 env, j_vr_shell_delegate_.obj())); 202 env, j_vr_shell_delegate_.obj()));
200 non_presenting_delegate_ = 203 non_presenting_delegate_ =
201 base::MakeUnique<NonPresentingGvrDelegate>(context); 204 base::MakeUnique<NonPresentingGvrDelegate>(context);
202 non_presenting_delegate_->UpdateVSyncInterval(timebase_nanos_, 205 non_presenting_delegate_->UpdateVSyncInterval(timebase_nanos_,
203 interval_seconds_); 206 interval_seconds_);
204 } 207 }
205 208
209 void VrShellDelegate::OnActivateDisplayHandled(bool present_requested) {
210 if (!present_requested) {
211 // WebVR page didn't request presentation in the vrdisplayactivate handler.
212 // Tell VrShell that we are in VR Browsing Mode.
213 ExitWebVRPresent();
214 }
215 }
216
206 device::GvrDelegate* VrShellDelegate::GetDelegate() { 217 device::GvrDelegate* VrShellDelegate::GetDelegate() {
207 if (presenting_delegate_) 218 if (presenting_delegate_)
208 return presenting_delegate_; 219 return presenting_delegate_;
209 return non_presenting_delegate_.get(); 220 return non_presenting_delegate_.get();
210 } 221 }
211 222
212 void VrShellDelegate::SetListeningForActivate(bool listening) { 223 void VrShellDelegate::SetListeningForActivate(bool listening) {
213 JNIEnv* env = AttachCurrentThread(); 224 JNIEnv* env = AttachCurrentThread();
214 Java_VrShellDelegate_setListeningForWebVrActivate( 225 Java_VrShellDelegate_setListeningForWebVrActivate(
215 env, j_vr_shell_delegate_.obj(), listening); 226 env, j_vr_shell_delegate_.obj(), listening);
(...skipping 10 matching lines...) Expand all
226 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 237 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
227 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj)); 238 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj));
228 } 239 }
229 240
230 static void OnLibraryAvailable(JNIEnv* env, const JavaParamRef<jclass>& clazz) { 241 static void OnLibraryAvailable(JNIEnv* env, const JavaParamRef<jclass>& clazz) {
231 device::GvrDelegateProvider::SetInstance( 242 device::GvrDelegateProvider::SetInstance(
232 base::Bind(&VrShellDelegate::CreateVrShellDelegate)); 243 base::Bind(&VrShellDelegate::CreateVrShellDelegate));
233 } 244 }
234 245
235 } // namespace vr_shell 246 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_delegate.h ('k') | device/vr/test/fake_vr_display_impl_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698