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

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: doing texture patching on background task 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // should add a flag for disabling specific UI such as the keyboard (see 78 // should add a flag for disabling specific UI such as the keyboard (see
79 // VrTabHelper for details). 79 // VrTabHelper for details).
80 contents->GetRenderWidgetHostView()->SetIsInVR(is_in_vr); 80 contents->GetRenderWidgetHostView()->SetIsInVR(is_in_vr);
81 81
82 VrTabHelper* vr_tab_helper = VrTabHelper::FromWebContents(contents); 82 VrTabHelper* vr_tab_helper = VrTabHelper::FromWebContents(contents);
83 DCHECK(vr_tab_helper); 83 DCHECK(vr_tab_helper);
84 vr_tab_helper->SetIsInVr(is_in_vr); 84 vr_tab_helper->SetIsInVr(is_in_vr);
85 } 85 }
86 } 86 }
87 87
88 void LoadControllerModelTask(
89 base::WeakPtr<VrShell> weak_vr_shell,
90 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) {
91 auto controller_model = VrControllerModel::LoadFromComponent();
92 if (controller_model) {
93 main_thread_task_runner->PostTask(
94 FROM_HERE, base::Bind(&VrShell::SubmitControllerModel, weak_vr_shell,
95 base::Passed(&controller_model)));
96 }
97 }
98
99 } // namespace 88 } // namespace
100 89
101 VrShell::VrShell(JNIEnv* env, 90 VrShell::VrShell(JNIEnv* env,
102 jobject obj, 91 jobject obj,
103 ui::WindowAndroid* window, 92 ui::WindowAndroid* window,
104 bool for_web_vr, 93 bool for_web_vr,
105 bool in_cct, 94 bool in_cct,
106 VrShellDelegate* delegate, 95 VrShellDelegate* delegate,
107 gvr_context* gvr_api, 96 gvr_context* gvr_api,
108 bool reprojected_rendering) 97 bool reprojected_rendering)
109 : vr_shell_enabled_(base::FeatureList::IsEnabled(features::kVrShell)), 98 : vr_shell_enabled_(base::FeatureList::IsEnabled(features::kVrShell)),
110 window_(window), 99 window_(window),
111 compositor_(base::MakeUnique<VrCompositor>(window_)), 100 compositor_(base::MakeUnique<VrCompositor>(window_)),
112 delegate_provider_(delegate), 101 delegate_provider_(delegate),
113 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), 102 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
114 reprojected_rendering_(reprojected_rendering), 103 reprojected_rendering_(reprojected_rendering),
115 gvr_api_(gvr_api), 104 gvr_api_(gvr_api),
116 weak_ptr_factory_(this) { 105 weak_ptr_factory_(this) {
117 DVLOG(1) << __FUNCTION__ << "=" << this; 106 DVLOG(1) << __FUNCTION__ << "=" << this;
118 DCHECK(g_instance == nullptr); 107 DCHECK(g_instance == nullptr);
119 g_instance = this; 108 g_instance = this;
120 j_vr_shell_.Reset(env, obj); 109 j_vr_shell_.Reset(env, obj);
121 110
122 gl_thread_ = base::MakeUnique<VrGLThread>( 111 gl_thread_ = base::MakeUnique<VrGLThread>(
123 weak_ptr_factory_.GetWeakPtr(), main_thread_task_runner_, gvr_api, 112 weak_ptr_factory_.GetWeakPtr(), main_thread_task_runner_, gvr_api,
124 for_web_vr, in_cct, reprojected_rendering_); 113 for_web_vr, in_cct, reprojected_rendering_, HasDaydreamSupport(env));
125 ui_ = gl_thread_.get(); 114 ui_ = gl_thread_.get();
126 115
127 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0); 116 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0);
128 options.priority = base::ThreadPriority::DISPLAY; 117 options.priority = base::ThreadPriority::DISPLAY;
129 gl_thread_->StartWithOptions(options); 118 gl_thread_->StartWithOptions(options);
130
131
132 content::BrowserThread::PostTask(
133 content::BrowserThread::FILE, FROM_HERE,
134 base::Bind(LoadControllerModelTask, weak_ptr_factory_.GetWeakPtr(),
135 main_thread_task_runner_));
136 } 119 }
137 120
138 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { 121 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
139 delete this; 122 delete this;
140 } 123 }
141 124
142 void VrShell::SwapContents( 125 void VrShell::SwapContents(
143 JNIEnv* env, 126 JNIEnv* env,
144 const JavaParamRef<jobject>& obj, 127 const JavaParamRef<jobject>& obj,
145 const JavaParamRef<jobject>& web_contents, 128 const JavaParamRef<jobject>& web_contents,
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 350
368 void VrShell::SubmitWebVRFrame(int16_t frame_index, 351 void VrShell::SubmitWebVRFrame(int16_t frame_index,
369 const gpu::MailboxHolder& mailbox) { 352 const gpu::MailboxHolder& mailbox) {
370 TRACE_EVENT1("gpu", "SubmitWebVRFrame", "frame", frame_index); 353 TRACE_EVENT1("gpu", "SubmitWebVRFrame", "frame", frame_index);
371 WaitForGlThread(); 354 WaitForGlThread();
372 PostToGlThread(FROM_HERE, 355 PostToGlThread(FROM_HERE,
373 base::Bind(&VrShellGl::SubmitWebVRFrame, 356 base::Bind(&VrShellGl::SubmitWebVRFrame,
374 gl_thread_->GetVrShellGl(), frame_index, mailbox)); 357 gl_thread_->GetVrShellGl(), frame_index, mailbox));
375 } 358 }
376 359
377 void VrShell::SubmitControllerModel(std::unique_ptr<VrControllerModel> model) {
378 WaitForGlThread();
379 PostToGlThread(FROM_HERE,
380 base::Bind(&VrShellGl::SetControllerModel,
381 gl_thread_->GetVrShellGl(), base::Passed(&model)));
382 }
383
384 void VrShell::UpdateWebVRTextureBounds(int16_t frame_index, 360 void VrShell::UpdateWebVRTextureBounds(int16_t frame_index,
385 const gfx::RectF& left_bounds, 361 const gfx::RectF& left_bounds,
386 const gfx::RectF& right_bounds, 362 const gfx::RectF& right_bounds,
387 const gfx::Size& source_size) { 363 const gfx::Size& source_size) {
388 WaitForGlThread(); 364 WaitForGlThread();
389 PostToGlThread(FROM_HERE, base::Bind(&VrShellGl::UpdateWebVRTextureBounds, 365 PostToGlThread(FROM_HERE, base::Bind(&VrShellGl::UpdateWebVRTextureBounds,
390 gl_thread_->GetVrShellGl(), frame_index, 366 gl_thread_->GetVrShellGl(), frame_index,
391 left_bounds, right_bounds, source_size)); 367 left_bounds, right_bounds, source_size));
392 } 368 }
393 369
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 gamepad_data_fetcher_->SetGamepadData(pad); 606 gamepad_data_fetcher_->SetGamepadData(pad);
631 } 607 }
632 } 608 }
633 609
634 void VrShell::RegisterGamepadDataFetcher( 610 void VrShell::RegisterGamepadDataFetcher(
635 device::GvrGamepadDataFetcher* fetcher) { 611 device::GvrGamepadDataFetcher* fetcher) {
636 DVLOG(1) << __FUNCTION__ << "(" << fetcher << ")"; 612 DVLOG(1) << __FUNCTION__ << "(" << fetcher << ")";
637 gamepad_data_fetcher_ = fetcher; 613 gamepad_data_fetcher_ = fetcher;
638 } 614 }
639 615
616 bool VrShell::HasDaydreamSupport(JNIEnv* env) {
617 return Java_VrShellImpl_hasDaydreamSupport(env, j_vr_shell_.obj());
618 }
619
640 // ---------------------------------------------------------------------------- 620 // ----------------------------------------------------------------------------
641 // Native JNI methods 621 // Native JNI methods
642 // ---------------------------------------------------------------------------- 622 // ----------------------------------------------------------------------------
643 623
644 jlong Init(JNIEnv* env, 624 jlong Init(JNIEnv* env,
645 const JavaParamRef<jobject>& obj, 625 const JavaParamRef<jobject>& obj,
646 const JavaParamRef<jobject>& delegate, 626 const JavaParamRef<jobject>& delegate,
647 jlong window_android, 627 jlong window_android,
648 jboolean for_web_vr, 628 jboolean for_web_vr,
649 jboolean in_cct, 629 jboolean in_cct,
650 jlong gvr_api, 630 jlong gvr_api,
651 jboolean reprojected_rendering) { 631 jboolean reprojected_rendering) {
652 return reinterpret_cast<intptr_t>(new VrShell( 632 return reinterpret_cast<intptr_t>(new VrShell(
653 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), 633 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android),
654 for_web_vr, in_cct, 634 for_web_vr, in_cct,
655 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), 635 VrShellDelegate::GetNativeVrShellDelegate(env, delegate),
656 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); 636 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering));
657 } 637 }
658 638
659 } // namespace vr_shell 639 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell.h ('k') | chrome/browser/android/vr_shell/vr_shell_gl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698