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

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

Issue 2774933003: Fixes WebVR presentation from within VRShell. (Closed)
Patch Set: Rebased on ToT, nits Created 3 years, 8 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 "chrome/browser/android/vr_shell/non_presenting_gvr_delegate.h" 11 #include "chrome/browser/android/vr_shell/non_presenting_gvr_delegate.h"
11 #include "device/vr/android/gvr/gvr_device.h" 12 #include "device/vr/android/gvr/gvr_device.h"
12 #include "device/vr/android/gvr/gvr_device_provider.h" 13 #include "device/vr/android/gvr/gvr_device_provider.h"
13 #include "jni/VrShellDelegate_jni.h" 14 #include "jni/VrShellDelegate_jni.h"
14 15
15 using base::android::JavaParamRef; 16 using base::android::JavaParamRef;
16 using base::android::AttachCurrentThread; 17 using base::android::AttachCurrentThread;
17 18
18 namespace vr_shell { 19 namespace vr_shell {
19 20
20 VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj) { 21 VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj) {
21 DVLOG(1) << __FUNCTION__ << "=" << this; 22 DVLOG(1) << __FUNCTION__ << "=" << this;
22 j_vr_shell_delegate_.Reset(env, obj); 23 j_vr_shell_delegate_.Reset(env, obj);
23 } 24 }
24 25
25 VrShellDelegate::~VrShellDelegate() { 26 VrShellDelegate::~VrShellDelegate() {
26 DVLOG(1) << __FUNCTION__ << "=" << this; 27 DVLOG(1) << __FUNCTION__ << "=" << this;
27 if (device_provider_) { 28 if (device_provider_) {
28 device_provider_->Device()->OnExitPresent(); 29 device_provider_->Device()->OnExitPresent();
29 device_provider_->Device()->OnDelegateChanged(); 30 device_provider_->Device()->OnDelegateChanged();
30 } 31 }
32 if (!present_callback_.is_null()) {
33 base::ResetAndReturn(&present_callback_).Run(false);
34 }
31 } 35 }
32 36
33 device::GvrDelegateProvider* VrShellDelegate::CreateVrShellDelegate() { 37 device::GvrDelegateProvider* VrShellDelegate::CreateVrShellDelegate() {
34 JNIEnv* env = AttachCurrentThread(); 38 JNIEnv* env = AttachCurrentThread();
35 base::android::ScopedJavaLocalRef<jobject> jdelegate = 39 base::android::ScopedJavaLocalRef<jobject> jdelegate =
36 Java_VrShellDelegate_getInstance(env); 40 Java_VrShellDelegate_getInstance(env);
37 if (!jdelegate.is_null()) 41 if (!jdelegate.is_null())
38 return GetNativeVrShellDelegate(env, jdelegate.obj()); 42 return GetNativeVrShellDelegate(env, jdelegate.obj());
39 return nullptr; 43 return nullptr;
40 } 44 }
(...skipping 14 matching lines...) Expand all
55 JNIEnv* env = AttachCurrentThread(); 59 JNIEnv* env = AttachCurrentThread();
56 Java_VrShellDelegate_shutdownNonPresentingNativeContext( 60 Java_VrShellDelegate_shutdownNonPresentingNativeContext(
57 env, j_vr_shell_delegate_.obj()); 61 env, j_vr_shell_delegate_.obj());
58 } 62 }
59 if (device_provider_) { 63 if (device_provider_) {
60 device::GvrDevice* device = device_provider_->Device(); 64 device::GvrDevice* device = device_provider_->Device();
61 device->OnDelegateChanged(); 65 device->OnDelegateChanged();
62 } 66 }
63 67
64 presenting_delegate_->UpdateVSyncInterval(timebase_nanos_, interval_seconds_); 68 presenting_delegate_->UpdateVSyncInterval(timebase_nanos_, interval_seconds_);
69
70 if (pending_successful_present_request_) {
71 presenting_delegate_->SetSubmitClient(std::move(submit_client_));
72 base::ResetAndReturn(&present_callback_).Run(true);
73 pending_successful_present_request_ = false;
74 }
65 } 75 }
66 76
67 void VrShellDelegate::RemoveDelegate() { 77 void VrShellDelegate::RemoveDelegate() {
68 presenting_delegate_ = nullptr; 78 presenting_delegate_ = nullptr;
69 if (device_provider_) { 79 if (device_provider_) {
70 CreateNonPresentingDelegate(); 80 CreateNonPresentingDelegate();
71 device_provider_->Device()->OnExitPresent(); 81 device_provider_->Device()->OnExitPresent();
72 device_provider_->Device()->OnDelegateChanged(); 82 device_provider_->Device()->OnDelegateChanged();
73 } 83 }
74 } 84 }
75 85
76 void VrShellDelegate::SetPresentResult(JNIEnv* env, 86 void VrShellDelegate::SetPresentResult(JNIEnv* env,
77 const JavaParamRef<jobject>& obj, 87 const JavaParamRef<jobject>& obj,
78 jboolean result) { 88 jboolean success) {
79 CHECK(!present_callback_.is_null()); 89 CHECK(!present_callback_.is_null());
80 present_callback_.Run(result); 90 if (success && !presenting_delegate_) {
81 present_callback_.Reset(); 91 // We have to wait until the GL thread is ready since we have to pass it
92 // the VRSubmitFrameClient.
93 pending_successful_present_request_ = true;
94 return;
95 }
96
97 if (success) {
98 presenting_delegate_->SetSubmitClient(std::move(submit_client_));
99 }
100
101 base::ResetAndReturn(&present_callback_).Run(success);
102 pending_successful_present_request_ = false;
82 } 103 }
83 104
84 void VrShellDelegate::DisplayActivate(JNIEnv* env, 105 void VrShellDelegate::DisplayActivate(JNIEnv* env,
85 const JavaParamRef<jobject>& obj) { 106 const JavaParamRef<jobject>& obj) {
86 if (device_provider_) { 107 if (device_provider_) {
87 device_provider_->Device()->OnActivate( 108 device_provider_->Device()->OnActivate(
88 device::mojom::VRDisplayEventReason::MOUNTED); 109 device::mojom::VRDisplayEventReason::MOUNTED);
89 } 110 }
90 } 111 }
91 112
(...skipping 22 matching lines...) Expand all
114 void VrShellDelegate::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { 135 void VrShellDelegate::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) {
115 if (non_presenting_delegate_) { 136 if (non_presenting_delegate_) {
116 non_presenting_delegate_->Resume(); 137 non_presenting_delegate_->Resume();
117 } 138 }
118 } 139 }
119 140
120 void VrShellDelegate::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { 141 void VrShellDelegate::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
121 delete this; 142 delete this;
122 } 143 }
123 144
124 device::mojom::VRSubmitFrameClientPtr VrShellDelegate::TakeSubmitFrameClient() {
125 return std::move(submit_client_);
126 }
127
128 void VrShellDelegate::SetDeviceProvider( 145 void VrShellDelegate::SetDeviceProvider(
129 device::GvrDeviceProvider* device_provider) { 146 device::GvrDeviceProvider* device_provider) {
130 if (device_provider_ == device_provider) 147 if (device_provider_ == device_provider)
131 return; 148 return;
132 if (device_provider_) 149 if (device_provider_)
133 ClearDeviceProvider(); 150 ClearDeviceProvider();
134 CHECK(!device_provider_); 151 CHECK(!device_provider_);
135 device_provider_ = device_provider; 152 device_provider_ = device_provider;
136 if (!presenting_delegate_) { 153 if (!presenting_delegate_) {
137 CreateNonPresentingDelegate(); 154 CreateNonPresentingDelegate();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 223 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
207 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj)); 224 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj));
208 } 225 }
209 226
210 static void OnLibraryAvailable(JNIEnv* env, const JavaParamRef<jclass>& clazz) { 227 static void OnLibraryAvailable(JNIEnv* env, const JavaParamRef<jclass>& clazz) {
211 device::GvrDelegateProvider::SetInstance( 228 device::GvrDelegateProvider::SetInstance(
212 base::Bind(&VrShellDelegate::CreateVrShellDelegate)); 229 base::Bind(&VrShellDelegate::CreateVrShellDelegate));
213 } 230 }
214 231
215 } // namespace vr_shell 232 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_delegate.h ('k') | device/vr/android/gvr/gvr_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698