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

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

Issue 2891243002: VR: Loading DD controller model after GL is initialized (Closed)
Patch Set: 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.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 <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // should add a flag for disabling specific UI such as the keyboard (see 75 // should add a flag for disabling specific UI such as the keyboard (see
76 // VrTabHelper for details). 76 // VrTabHelper for details).
77 contents->GetRenderWidgetHostView()->SetIsInVR(is_in_vr); 77 contents->GetRenderWidgetHostView()->SetIsInVR(is_in_vr);
78 78
79 VrTabHelper* vr_tab_helper = VrTabHelper::FromWebContents(contents); 79 VrTabHelper* vr_tab_helper = VrTabHelper::FromWebContents(contents);
80 DCHECK(vr_tab_helper); 80 DCHECK(vr_tab_helper);
81 vr_tab_helper->SetIsInVr(is_in_vr); 81 vr_tab_helper->SetIsInVr(is_in_vr);
82 } 82 }
83 } 83 }
84 84
85 void LoadControllerModelTask(
86 base::WeakPtr<VrShell> weak_vr_shell,
87 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) {
88 auto controller_model = VrControllerModel::LoadFromComponent();
89 if (controller_model) {
90 main_thread_task_runner->PostTask(
91 FROM_HERE, base::Bind(&VrShell::SubmitControllerModel, weak_vr_shell,
92 base::Passed(&controller_model)));
93 }
94 }
95
96 } // namespace 85 } // namespace
97 86
98 VrShell::VrShell(JNIEnv* env, 87 VrShell::VrShell(JNIEnv* env,
99 jobject obj, 88 jobject obj,
100 ui::WindowAndroid* window, 89 ui::WindowAndroid* window,
101 bool for_web_vr, 90 bool for_web_vr,
102 bool in_cct, 91 bool in_cct,
103 VrShellDelegate* delegate, 92 VrShellDelegate* delegate,
104 gvr_context* gvr_api, 93 gvr_context* gvr_api,
105 bool reprojected_rendering) 94 bool reprojected_rendering)
106 : vr_shell_enabled_(base::FeatureList::IsEnabled(features::kVrShell)), 95 : vr_shell_enabled_(base::FeatureList::IsEnabled(features::kVrShell)),
107 window_(window), 96 window_(window),
108 compositor_(base::MakeUnique<VrCompositor>(window_)), 97 compositor_(base::MakeUnique<VrCompositor>(window_)),
109 delegate_provider_(delegate), 98 delegate_provider_(delegate),
110 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), 99 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
111 reprojected_rendering_(reprojected_rendering), 100 reprojected_rendering_(reprojected_rendering),
112 gvr_api_(gvr_api), 101 gvr_api_(gvr_api),
113 weak_ptr_factory_(this) { 102 weak_ptr_factory_(this) {
114 DVLOG(1) << __FUNCTION__ << "=" << this; 103 DVLOG(1) << __FUNCTION__ << "=" << this;
115 DCHECK(g_instance == nullptr); 104 DCHECK(g_instance == nullptr);
116 g_instance = this; 105 g_instance = this;
117 j_vr_shell_.Reset(env, obj); 106 j_vr_shell_.Reset(env, obj);
118 107
119 gl_thread_ = base::MakeUnique<VrGLThread>( 108 gl_thread_ = base::MakeUnique<VrGLThread>(
120 weak_ptr_factory_.GetWeakPtr(), main_thread_task_runner_, gvr_api, 109 weak_ptr_factory_.GetWeakPtr(), main_thread_task_runner_, gvr_api,
121 for_web_vr, in_cct, reprojected_rendering_); 110 for_web_vr, in_cct, reprojected_rendering_, HasDaydreamSupport());
122 ui_ = gl_thread_.get(); 111 ui_ = gl_thread_.get();
123 112
124 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0); 113 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0);
125 options.priority = base::ThreadPriority::DISPLAY; 114 options.priority = base::ThreadPriority::DISPLAY;
126 gl_thread_->StartWithOptions(options); 115 gl_thread_->StartWithOptions(options);
127
128
129 content::BrowserThread::PostTask(
130 content::BrowserThread::FILE, FROM_HERE,
131 base::Bind(LoadControllerModelTask, weak_ptr_factory_.GetWeakPtr(),
132 main_thread_task_runner_));
133 } 116 }
134 117
135 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { 118 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
136 delete this; 119 delete this;
137 } 120 }
138 121
139 void VrShell::SwapContents( 122 void VrShell::SwapContents(
140 JNIEnv* env, 123 JNIEnv* env,
141 const JavaParamRef<jobject>& obj, 124 const JavaParamRef<jobject>& obj,
142 const JavaParamRef<jobject>& web_contents, 125 const JavaParamRef<jobject>& web_contents,
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 347
365 void VrShell::SubmitWebVRFrame(int16_t frame_index, 348 void VrShell::SubmitWebVRFrame(int16_t frame_index,
366 const gpu::MailboxHolder& mailbox) { 349 const gpu::MailboxHolder& mailbox) {
367 TRACE_EVENT1("gpu", "SubmitWebVRFrame", "frame", frame_index); 350 TRACE_EVENT1("gpu", "SubmitWebVRFrame", "frame", frame_index);
368 WaitForGlThread(); 351 WaitForGlThread();
369 PostToGlThread(FROM_HERE, 352 PostToGlThread(FROM_HERE,
370 base::Bind(&VrShellGl::SubmitWebVRFrame, 353 base::Bind(&VrShellGl::SubmitWebVRFrame,
371 gl_thread_->GetVrShellGl(), frame_index, mailbox)); 354 gl_thread_->GetVrShellGl(), frame_index, mailbox));
372 } 355 }
373 356
374 void VrShell::SubmitControllerModel(std::unique_ptr<VrControllerModel> model) {
375 WaitForGlThread();
376 PostToGlThread(FROM_HERE,
377 base::Bind(&VrShellGl::SetControllerModel,
378 gl_thread_->GetVrShellGl(), base::Passed(&model)));
379 }
380
381 void VrShell::UpdateWebVRTextureBounds(int16_t frame_index, 357 void VrShell::UpdateWebVRTextureBounds(int16_t frame_index,
382 const gfx::RectF& left_bounds, 358 const gfx::RectF& left_bounds,
383 const gfx::RectF& right_bounds, 359 const gfx::RectF& right_bounds,
384 const gfx::Size& source_size) { 360 const gfx::Size& source_size) {
385 WaitForGlThread(); 361 WaitForGlThread();
386 PostToGlThread(FROM_HERE, base::Bind(&VrShellGl::UpdateWebVRTextureBounds, 362 PostToGlThread(FROM_HERE, base::Bind(&VrShellGl::UpdateWebVRTextureBounds,
387 gl_thread_->GetVrShellGl(), frame_index, 363 gl_thread_->GetVrShellGl(), frame_index,
388 left_bounds, right_bounds, source_size)); 364 left_bounds, right_bounds, source_size));
389 } 365 }
390 366
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 gamepad_data_fetcher_->SetGamepadData(pad); 595 gamepad_data_fetcher_->SetGamepadData(pad);
620 } 596 }
621 } 597 }
622 598
623 void VrShell::RegisterGamepadDataFetcher( 599 void VrShell::RegisterGamepadDataFetcher(
624 device::GvrGamepadDataFetcher* fetcher) { 600 device::GvrGamepadDataFetcher* fetcher) {
625 DVLOG(1) << __FUNCTION__ << "(" << fetcher << ")"; 601 DVLOG(1) << __FUNCTION__ << "(" << fetcher << ")";
626 gamepad_data_fetcher_ = fetcher; 602 gamepad_data_fetcher_ = fetcher;
627 } 603 }
628 604
605 bool VrShell::HasDaydreamSupport() {
606 JNIEnv* env = base::android::AttachCurrentThread();
mthiesse 2017/05/19 14:32:42 nit: take env as an argument, since the callsite a
acondor_ 2017/05/19 16:06:49 Done.
607 return Java_VrShellImpl_hasDaydreamSupport(env, j_vr_shell_.obj());
608 }
609
629 // ---------------------------------------------------------------------------- 610 // ----------------------------------------------------------------------------
630 // Native JNI methods 611 // Native JNI methods
631 // ---------------------------------------------------------------------------- 612 // ----------------------------------------------------------------------------
632 613
633 jlong Init(JNIEnv* env, 614 jlong Init(JNIEnv* env,
634 const JavaParamRef<jobject>& obj, 615 const JavaParamRef<jobject>& obj,
635 const JavaParamRef<jobject>& delegate, 616 const JavaParamRef<jobject>& delegate,
636 jlong window_android, 617 jlong window_android,
637 jboolean for_web_vr, 618 jboolean for_web_vr,
638 jboolean in_cct, 619 jboolean in_cct,
639 jlong gvr_api, 620 jlong gvr_api,
640 jboolean reprojected_rendering) { 621 jboolean reprojected_rendering) {
641 return reinterpret_cast<intptr_t>(new VrShell( 622 return reinterpret_cast<intptr_t>(new VrShell(
642 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), 623 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android),
643 for_web_vr, in_cct, 624 for_web_vr, in_cct,
644 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), 625 VrShellDelegate::GetNativeVrShellDelegate(env, delegate),
645 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); 626 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering));
646 } 627 }
647 628
648 } // namespace vr_shell 629 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698