OLD | NEW |
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.h" | 5 #include "chrome/browser/android/vr_shell/vr_shell.h" |
6 | 6 |
7 #include <android/native_window_jni.h> | 7 #include <android/native_window_jni.h> |
8 | 8 |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 gl_thread_->StartWithOptions(options); | 142 gl_thread_->StartWithOptions(options); |
143 | 143 |
144 if (for_web_vr) | 144 if (for_web_vr) |
145 metrics_helper_->SetWebVREnabled(true); | 145 metrics_helper_->SetWebVREnabled(true); |
146 html_interface_.reset(new UiInterface( | 146 html_interface_.reset(new UiInterface( |
147 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD, | 147 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD, |
148 main_contents_->IsFullscreen())); | 148 main_contents_->IsFullscreen())); |
149 vr_web_contents_observer_.reset(new VrWebContentsObserver( | 149 vr_web_contents_observer_.reset(new VrWebContentsObserver( |
150 main_contents, html_interface_.get(), this)); | 150 main_contents, html_interface_.get(), this)); |
151 | 151 |
152 SetShowingOverscrollGlow(false); | 152 SetIsInVR(true); |
153 } | 153 } |
154 | 154 |
155 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 155 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
156 delete this; | 156 delete this; |
157 } | 157 } |
158 | 158 |
159 void VrShell::LoadUIContent(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 159 void VrShell::LoadUIContent(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
160 GURL url(kVrShellUIURL); | 160 GURL url(kVrShellUIURL); |
161 ui_contents_->GetController().LoadURL( | 161 ui_contents_->GetController().LoadURL( |
162 url, content::Referrer(), | 162 url, content::Referrer(), |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 thread->GetVrShellGl())); | 202 thread->GetVrShellGl())); |
203 } | 203 } |
204 | 204 |
205 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 205 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
206 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); | 206 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
207 thread->task_runner()->PostTask( | 207 thread->task_runner()->PostTask( |
208 FROM_HERE, base::Bind(&VrShellGl::OnPause, thread->GetVrShellGl())); | 208 FROM_HERE, base::Bind(&VrShellGl::OnPause, thread->GetVrShellGl())); |
209 | 209 |
210 // exit vr session | 210 // exit vr session |
211 metrics_helper_->SetVRActive(false); | 211 metrics_helper_->SetVRActive(false); |
212 SetShowingOverscrollGlow(true); | 212 SetIsInVR(false); |
213 } | 213 } |
214 | 214 |
215 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 215 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
216 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); | 216 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
217 thread->task_runner()->PostTask( | 217 thread->task_runner()->PostTask( |
218 FROM_HERE, base::Bind(&VrShellGl::OnResume, thread->GetVrShellGl())); | 218 FROM_HERE, base::Bind(&VrShellGl::OnResume, thread->GetVrShellGl())); |
219 | 219 |
220 // exit vr session | |
221 metrics_helper_->SetVRActive(true); | 220 metrics_helper_->SetVRActive(true); |
222 SetShowingOverscrollGlow(false); | 221 SetIsInVR(true); |
223 } | 222 } |
224 | 223 |
225 void VrShell::SetSurface(JNIEnv* env, | 224 void VrShell::SetSurface(JNIEnv* env, |
226 const JavaParamRef<jobject>& obj, | 225 const JavaParamRef<jobject>& obj, |
227 const JavaParamRef<jobject>& surface) { | 226 const JavaParamRef<jobject>& surface) { |
228 CHECK(!reprojected_rendering_); | 227 CHECK(!reprojected_rendering_); |
229 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); | 228 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
230 gfx::AcceleratedWidget window = | 229 gfx::AcceleratedWidget window = |
231 ANativeWindow_fromSurface(base::android::AttachCurrentThread(), surface); | 230 ANativeWindow_fromSurface(base::android::AttachCurrentThread(), surface); |
232 PostToGlThreadWhenReady(base::Bind(&VrShellGl::InitializeGl, | 231 PostToGlThreadWhenReady(base::Bind(&VrShellGl::InitializeGl, |
233 thread->GetVrShellGl(), | 232 thread->GetVrShellGl(), |
234 base::Unretained(window))); | 233 base::Unretained(window))); |
235 } | 234 } |
236 | 235 |
237 void VrShell::SetShowingOverscrollGlow(bool showing_glow) { | 236 void VrShell::SetIsInVR(bool is_in_vr) { |
238 main_contents_->GetRenderWidgetHostView()->SetShowingOverscrollGlow( | 237 main_contents_->GetRenderWidgetHostView()->SetIsInVR(is_in_vr); |
239 showing_glow); | |
240 } | 238 } |
241 | 239 |
242 base::WeakPtr<VrShell> VrShell::GetWeakPtr( | 240 base::WeakPtr<VrShell> VrShell::GetWeakPtr( |
243 const content::WebContents* web_contents) { | 241 const content::WebContents* web_contents) { |
244 // Ensure that the WebContents requesting the VrShell instance is the one | 242 // Ensure that the WebContents requesting the VrShell instance is the one |
245 // we created. | 243 // we created. |
246 if (g_instance != nullptr && g_instance->ui_contents_ == web_contents) | 244 if (g_instance != nullptr && g_instance->ui_contents_ == web_contents) |
247 return g_instance->weak_ptr_factory_.GetWeakPtr(); | 245 return g_instance->weak_ptr_factory_.GetWeakPtr(); |
248 return base::WeakPtr<VrShell>(nullptr); | 246 return base::WeakPtr<VrShell>(nullptr); |
249 } | 247 } |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 return reinterpret_cast<intptr_t>(new VrShell( | 482 return reinterpret_cast<intptr_t>(new VrShell( |
485 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), | 483 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), |
486 reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 484 reinterpret_cast<ui::WindowAndroid*>(content_window_android), |
487 content::WebContents::FromJavaWebContents(ui_web_contents), | 485 content::WebContents::FromJavaWebContents(ui_web_contents), |
488 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), | 486 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), |
489 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate), | 487 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate), |
490 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 488 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
491 } | 489 } |
492 | 490 |
493 } // namespace vr_shell | 491 } // namespace vr_shell |
OLD | NEW |