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

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

Issue 2616583002: Fix WebVR support for devices without Async Reprojection. (Closed)
Patch Set: Created 3 years, 11 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.h>
8 #include <android/native_window_jni.h>
9
7 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
8 #include "base/threading/platform_thread.h" 11 #include "base/threading/platform_thread.h"
9 #include "base/threading/thread.h" 12 #include "base/threading/thread.h"
10 #include "base/threading/thread_restrictions.h" 13 #include "base/threading/thread_restrictions.h"
11 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
12 #include "base/values.h" 15 #include "base/values.h"
13 #include "chrome/browser/android/vr_shell/ui_interface.h" 16 #include "chrome/browser/android/vr_shell/ui_interface.h"
14 #include "chrome/browser/android/vr_shell/vr_compositor.h" 17 #include "chrome/browser/android/vr_shell/vr_compositor.h"
15 #include "chrome/browser/android/vr_shell/vr_input_manager.h" 18 #include "chrome/browser/android/vr_shell/vr_input_manager.h"
16 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" 19 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h"
(...skipping 24 matching lines...) Expand all
41 44
42 static const char kVrShellUIURL[] = "chrome://vr-shell-ui"; 45 static const char kVrShellUIURL[] = "chrome://vr-shell-ui";
43 46
44 class GLThread : public base::Thread { 47 class GLThread : public base::Thread {
45 public: 48 public:
46 GLThread(const base::WeakPtr<VrShell>& weak_vr_shell, 49 GLThread(const base::WeakPtr<VrShell>& weak_vr_shell,
47 const base::WeakPtr<VrInputManager>& content_input_manager, 50 const base::WeakPtr<VrInputManager>& content_input_manager,
48 const base::WeakPtr<VrInputManager>& ui_input_manager, 51 const base::WeakPtr<VrInputManager>& ui_input_manager,
49 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, 52 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner,
50 gvr_context* gvr_api, 53 gvr_context* gvr_api,
51 bool initially_web_vr) 54 bool initially_web_vr,
55 bool reprojected_rendering)
52 : base::Thread("VrShellGL"), 56 : base::Thread("VrShellGL"),
53 weak_vr_shell_(weak_vr_shell), 57 weak_vr_shell_(weak_vr_shell),
54 content_input_manager_(content_input_manager), 58 content_input_manager_(content_input_manager),
55 ui_input_manager_(ui_input_manager), 59 ui_input_manager_(ui_input_manager),
56 main_thread_task_runner_(std::move(main_thread_task_runner)), 60 main_thread_task_runner_(std::move(main_thread_task_runner)),
57 gvr_api_(gvr_api), 61 gvr_api_(gvr_api),
58 initially_web_vr_(initially_web_vr) {} 62 initially_web_vr_(initially_web_vr),
63 reprojected_rendering_(reprojected_rendering) {}
59 64
60 ~GLThread() override { 65 ~GLThread() override {
61 Stop(); 66 Stop();
62 } 67 }
63 base::WeakPtr<VrShellGl> GetVrShellGl() { return weak_vr_shell_gl_; } 68 base::WeakPtr<VrShellGl> GetVrShellGl() { return weak_vr_shell_gl_; }
64 VrShellGl* GetVrShellGlUnsafe() { return vr_shell_gl_.get(); } 69 VrShellGl* GetVrShellGlUnsafe() { return vr_shell_gl_.get(); }
65 70
66 protected: 71 protected:
67 void Init() override { 72 void Init() override {
68 vr_shell_gl_.reset(new VrShellGl(std::move(weak_vr_shell_), 73 vr_shell_gl_.reset(new VrShellGl(std::move(weak_vr_shell_),
69 std::move(content_input_manager_), 74 std::move(content_input_manager_),
70 std::move(ui_input_manager_), 75 std::move(ui_input_manager_),
71 std::move(main_thread_task_runner_), 76 std::move(main_thread_task_runner_),
72 gvr_api_, 77 gvr_api_,
73 initially_web_vr_)); 78 initially_web_vr_,
79 reprojected_rendering_));
74 weak_vr_shell_gl_ = vr_shell_gl_->GetWeakPtr(); 80 weak_vr_shell_gl_ = vr_shell_gl_->GetWeakPtr();
75 if (!vr_shell_gl_->Initialize()) { 81 vr_shell_gl_->Initialize();
76 vr_shell_gl_.reset();
77 }
78 } 82 }
79 void CleanUp() override { 83 void CleanUp() override {
80 vr_shell_gl_.reset(); 84 vr_shell_gl_.reset();
81 } 85 }
82 86
83 private: 87 private:
84 // Created on GL thread. 88 // Created on GL thread.
85 std::unique_ptr<VrShellGl> vr_shell_gl_; 89 std::unique_ptr<VrShellGl> vr_shell_gl_;
86 base::WeakPtr<VrShellGl> weak_vr_shell_gl_; 90 base::WeakPtr<VrShellGl> weak_vr_shell_gl_;
87 91
88 base::WeakPtr<VrShell> weak_vr_shell_; 92 base::WeakPtr<VrShell> weak_vr_shell_;
89 base::WeakPtr<VrInputManager> content_input_manager_; 93 base::WeakPtr<VrInputManager> content_input_manager_;
90 base::WeakPtr<VrInputManager> ui_input_manager_; 94 base::WeakPtr<VrInputManager> ui_input_manager_;
91 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; 95 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
92 gvr_context* gvr_api_; 96 gvr_context* gvr_api_;
93 bool initially_web_vr_; 97 bool initially_web_vr_;
98 bool reprojected_rendering_;
94 }; 99 };
95 100
96 } // namespace 101 } // namespace
97 102
98 VrShell::VrShell(JNIEnv* env, 103 VrShell::VrShell(JNIEnv* env,
99 jobject obj, 104 jobject obj,
100 content::WebContents* main_contents, 105 content::WebContents* main_contents,
101 ui::WindowAndroid* content_window, 106 ui::WindowAndroid* content_window,
102 content::WebContents* ui_contents, 107 content::WebContents* ui_contents,
103 ui::WindowAndroid* ui_window, 108 ui::WindowAndroid* ui_window,
104 bool for_web_vr, 109 bool for_web_vr,
105 VrShellDelegate* delegate, 110 VrShellDelegate* delegate,
106 gvr_context* gvr_api) 111 gvr_context* gvr_api,
112 bool reprojected_rendering)
107 : WebContentsObserver(ui_contents), 113 : WebContentsObserver(ui_contents),
108 main_contents_(main_contents), 114 main_contents_(main_contents),
109 content_compositor_(new VrCompositor(content_window, false)), 115 content_compositor_(new VrCompositor(content_window, false)),
110 ui_contents_(ui_contents), 116 ui_contents_(ui_contents),
111 ui_compositor_(new VrCompositor(ui_window, true)), 117 ui_compositor_(new VrCompositor(ui_window, true)),
112 delegate_(delegate), 118 delegate_(delegate),
113 metrics_helper_(new VrMetricsHelper(main_contents_)), 119 metrics_helper_(new VrMetricsHelper(main_contents_)),
114 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), 120 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
121 reprojected_rendering_(reprojected_rendering),
115 weak_ptr_factory_(this) { 122 weak_ptr_factory_(this) {
116 DCHECK(g_instance == nullptr); 123 DCHECK(g_instance == nullptr);
117 g_instance = this; 124 g_instance = this;
118 j_vr_shell_.Reset(env, obj); 125 j_vr_shell_.Reset(env, obj);
119 126
120 content_input_manager_.reset(new VrInputManager(main_contents_)); 127 content_input_manager_.reset(new VrInputManager(main_contents_));
121 ui_input_manager_.reset(new VrInputManager(ui_contents_)); 128 ui_input_manager_.reset(new VrInputManager(ui_contents_));
122 129
123 content_compositor_->SetLayer(main_contents_); 130 content_compositor_->SetLayer(main_contents_);
124 ui_compositor_->SetLayer(ui_contents_); 131 ui_compositor_->SetLayer(ui_contents_);
125 132
126 gl_thread_.reset(new GLThread(weak_ptr_factory_.GetWeakPtr(), 133 gl_thread_.reset(new GLThread(weak_ptr_factory_.GetWeakPtr(),
127 content_input_manager_->GetWeakPtr(), 134 content_input_manager_->GetWeakPtr(),
128 ui_input_manager_->GetWeakPtr(), 135 ui_input_manager_->GetWeakPtr(),
129 main_thread_task_runner_, 136 main_thread_task_runner_,
130 gvr_api, 137 gvr_api, for_web_vr,
bshe 2017/01/04 16:40:23 nit: one parameter per line
mthiesse 2017/01/04 16:58:09 Done.
131 for_web_vr)); 138 reprojected_rendering_));
132 139
133 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0); 140 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0);
134 options.priority = base::ThreadPriority::DISPLAY; 141 options.priority = base::ThreadPriority::DISPLAY;
135 gl_thread_->StartWithOptions(options); 142 gl_thread_->StartWithOptions(options);
136 143
137 if (for_web_vr) 144 if (for_web_vr)
138 metrics_helper_->SetWebVREnabled(true); 145 metrics_helper_->SetWebVREnabled(true);
139 html_interface_.reset(new UiInterface( 146 html_interface_.reset(new UiInterface(
140 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD, 147 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD,
141 main_contents_->IsFullscreen())); 148 main_contents_->IsFullscreen()));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { 215 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) {
209 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 216 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
210 thread->task_runner()->PostTask( 217 thread->task_runner()->PostTask(
211 FROM_HERE, base::Bind(&VrShellGl::OnResume, thread->GetVrShellGl())); 218 FROM_HERE, base::Bind(&VrShellGl::OnResume, thread->GetVrShellGl()));
212 219
213 // exit vr session 220 // exit vr session
214 metrics_helper_->SetVRActive(true); 221 metrics_helper_->SetVRActive(true);
215 SetShowingOverscrollGlow(false); 222 SetShowingOverscrollGlow(false);
216 } 223 }
217 224
225 void VrShell::SetSurface(JNIEnv* env,
226 const JavaParamRef<jobject>& obj,
227 const JavaParamRef<jobject>& surface) {
228 CHECK(!reprojected_rendering_);
229 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
230 gfx::AcceleratedWidget window =
231 ANativeWindow_fromSurface(base::android::AttachCurrentThread(), surface);
232 PostToGlThreadWhenReady(base::Bind(&VrShellGl::InitializeGl,
233 thread->GetVrShellGl(),
234 base::Unretained(window)));
235 }
236
218 void VrShell::SetShowingOverscrollGlow(bool showing_glow) { 237 void VrShell::SetShowingOverscrollGlow(bool showing_glow) {
219 main_contents_->GetRenderWidgetHostView()->SetShowingOverscrollGlow( 238 main_contents_->GetRenderWidgetHostView()->SetShowingOverscrollGlow(
220 showing_glow); 239 showing_glow);
221 } 240 }
222 241
223 base::WeakPtr<VrShell> VrShell::GetWeakPtr( 242 base::WeakPtr<VrShell> VrShell::GetWeakPtr(
224 const content::WebContents* web_contents) { 243 const content::WebContents* web_contents) {
225 // Ensure that the WebContents requesting the VrShell instance is the one 244 // Ensure that the WebContents requesting the VrShell instance is the one
226 // we created. 245 // we created.
227 if (g_instance != nullptr && g_instance->ui_contents_ == web_contents) 246 if (g_instance != nullptr && g_instance->ui_contents_ == web_contents)
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 // ---------------------------------------------------------------------------- 465 // ----------------------------------------------------------------------------
447 // Native JNI methods 466 // Native JNI methods
448 // ---------------------------------------------------------------------------- 467 // ----------------------------------------------------------------------------
449 468
450 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj, 469 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj,
451 const JavaParamRef<jobject>& content_web_contents, 470 const JavaParamRef<jobject>& content_web_contents,
452 jlong content_window_android, 471 jlong content_window_android,
453 const JavaParamRef<jobject>& ui_web_contents, 472 const JavaParamRef<jobject>& ui_web_contents,
454 jlong ui_window_android, jboolean for_web_vr, 473 jlong ui_window_android, jboolean for_web_vr,
455 const base::android::JavaParamRef<jobject>& delegate, 474 const base::android::JavaParamRef<jobject>& delegate,
456 jlong gvr_api) { 475 jlong gvr_api, jboolean reprojected_rendering) {
457 return reinterpret_cast<intptr_t>(new VrShell( 476 return reinterpret_cast<intptr_t>(new VrShell(
458 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), 477 env, obj, content::WebContents::FromJavaWebContents(content_web_contents),
459 reinterpret_cast<ui::WindowAndroid*>(content_window_android), 478 reinterpret_cast<ui::WindowAndroid*>(content_window_android),
460 content::WebContents::FromJavaWebContents(ui_web_contents), 479 content::WebContents::FromJavaWebContents(ui_web_contents),
461 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), 480 reinterpret_cast<ui::WindowAndroid*>(ui_window_android),
462 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate), 481 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate),
463 reinterpret_cast<gvr_context*>(gvr_api))); 482 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering));
464 } 483 }
465 484
466 } // namespace vr_shell 485 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698