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

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

Issue 2624633002: Remove Sync GetPose VRService call, implement VRVSyncProvider (Closed)
Patch Set: oops Created 3 years, 10 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 "base/memory/ptr_util.h"
9 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
10 #include "base/threading/platform_thread.h" 11 #include "base/threading/platform_thread.h"
11 #include "base/threading/thread.h" 12 #include "base/threading/thread.h"
12 #include "base/threading/thread_restrictions.h" 13 #include "base/threading/thread_restrictions.h"
13 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 #include "chrome/browser/android/vr_shell/ui_interface.h" 16 #include "chrome/browser/android/vr_shell/ui_interface.h"
16 #include "chrome/browser/android/vr_shell/vr_compositor.h" 17 #include "chrome/browser/android/vr_shell/vr_compositor.h"
18 #include "chrome/browser/android/vr_shell/vr_gl_thread.h"
17 #include "chrome/browser/android/vr_shell/vr_input_manager.h" 19 #include "chrome/browser/android/vr_shell/vr_input_manager.h"
18 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" 20 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h"
19 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" 21 #include "chrome/browser/android/vr_shell/vr_shell_gl.h"
20 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" 22 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h"
21 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" 23 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h"
22 #include "content/public/browser/navigation_controller.h" 24 #include "content/public/browser/navigation_controller.h"
23 #include "content/public/browser/render_view_host.h" 25 #include "content/public/browser/render_view_host.h"
24 #include "content/public/browser/render_widget_host.h" 26 #include "content/public/browser/render_widget_host.h"
25 #include "content/public/browser/render_widget_host_view.h" 27 #include "content/public/browser/render_widget_host_view.h"
26 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
27 #include "content/public/common/referrer.h" 29 #include "content/public/common/referrer.h"
28 #include "device/vr/android/gvr/gvr_device_provider.h" 30 #include "device/vr/android/gvr/gvr_device_provider.h"
29 #include "jni/VrShellImpl_jni.h" 31 #include "jni/VrShellImpl_jni.h"
30 #include "third_party/WebKit/public/platform/WebInputEvent.h" 32 #include "third_party/WebKit/public/platform/WebInputEvent.h"
31 #include "ui/android/view_android.h" 33 #include "ui/android/view_android.h"
32 #include "ui/android/window_android.h" 34 #include "ui/android/window_android.h"
33 #include "ui/base/page_transition_types.h" 35 #include "ui/base/page_transition_types.h"
34 #include "ui/display/display.h" 36 #include "ui/display/display.h"
35 #include "ui/display/screen.h" 37 #include "ui/display/screen.h"
38 #include "ui/gfx/transform.h"
39 #include "ui/gfx/transform_util.h"
36 40
37 using base::android::JavaParamRef; 41 using base::android::JavaParamRef;
38 using base::android::JavaRef; 42 using base::android::JavaRef;
39 43
40 namespace vr_shell { 44 namespace vr_shell {
41 45
42 namespace { 46 namespace {
43 vr_shell::VrShell* g_instance; 47 vr_shell::VrShell* g_instance;
44 48
45 static const char kVrShellUIURL[] = "chrome://vr-shell-ui"; 49 static const char kVrShellUIURL[] = "chrome://vr-shell-ui";
46 50
47 class GLThread : public base::Thread {
48 public:
49 GLThread(const base::WeakPtr<VrShell>& weak_vr_shell,
50 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner,
51 gvr_context* gvr_api,
52 bool initially_web_vr,
53 bool reprojected_rendering)
54 : base::Thread("VrShellGL"),
55 weak_vr_shell_(weak_vr_shell),
56 main_thread_task_runner_(std::move(main_thread_task_runner)),
57 gvr_api_(gvr_api),
58 initially_web_vr_(initially_web_vr),
59 reprojected_rendering_(reprojected_rendering) {}
60
61 ~GLThread() override {
62 Stop();
63 }
64 base::WeakPtr<VrShellGl> GetVrShellGl() { return weak_vr_shell_gl_; }
65 VrShellGl* GetVrShellGlUnsafe() { return vr_shell_gl_.get(); }
66
67 protected:
68 void Init() override {
69 vr_shell_gl_.reset(new VrShellGl(std::move(weak_vr_shell_),
70 std::move(main_thread_task_runner_),
71 gvr_api_,
72 initially_web_vr_,
73 reprojected_rendering_));
74 weak_vr_shell_gl_ = vr_shell_gl_->GetWeakPtr();
75 vr_shell_gl_->Initialize();
76 }
77 void CleanUp() override {
78 vr_shell_gl_.reset();
79 }
80
81 private:
82 // Created on GL thread.
83 std::unique_ptr<VrShellGl> vr_shell_gl_;
84 base::WeakPtr<VrShellGl> weak_vr_shell_gl_;
85
86 base::WeakPtr<VrShell> weak_vr_shell_;
87 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
88 gvr_context* gvr_api_;
89 bool initially_web_vr_;
90 bool reprojected_rendering_;
91 };
92
93 void SetIsInVR(content::WebContents* contents, bool is_in_vr) { 51 void SetIsInVR(content::WebContents* contents, bool is_in_vr) {
94 if (contents->GetRenderWidgetHostView()) 52 if (contents->GetRenderWidgetHostView())
95 contents->GetRenderWidgetHostView()->SetIsInVR(is_in_vr); 53 contents->GetRenderWidgetHostView()->SetIsInVR(is_in_vr);
96 } 54 }
97 55
98 } // namespace 56 } // namespace
99 57
100 VrShell::VrShell(JNIEnv* env, 58 VrShell::VrShell(JNIEnv* env,
101 jobject obj, 59 jobject obj,
102 content::WebContents* main_contents, 60 content::WebContents* main_contents,
103 ui::WindowAndroid* content_window, 61 ui::WindowAndroid* content_window,
104 content::WebContents* ui_contents, 62 content::WebContents* ui_contents,
105 ui::WindowAndroid* ui_window, 63 ui::WindowAndroid* ui_window,
106 bool for_web_vr, 64 bool for_web_vr,
107 VrShellDelegate* delegate, 65 VrShellDelegate* delegate,
108 gvr_context* gvr_api, 66 gvr_context* gvr_api,
109 bool reprojected_rendering) 67 bool reprojected_rendering)
110 : WebContentsObserver(ui_contents), 68 : WebContentsObserver(ui_contents),
111 main_contents_(main_contents), 69 main_contents_(main_contents),
112 content_compositor_( 70 content_compositor_(
113 base::MakeUnique<VrCompositor>(content_window, false)), 71 base::MakeUnique<VrCompositor>(content_window, false)),
114 ui_contents_(ui_contents), 72 ui_contents_(ui_contents),
115 ui_compositor_(base::MakeUnique<VrCompositor>(ui_window, true)), 73 ui_compositor_(base::MakeUnique<VrCompositor>(ui_window, true)),
116 delegate_(delegate), 74 delegate_provider_(delegate),
117 metrics_helper_(base::MakeUnique<VrMetricsHelper>(main_contents_)), 75 metrics_helper_(base::MakeUnique<VrMetricsHelper>(main_contents_)),
118 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), 76 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
119 reprojected_rendering_(reprojected_rendering), 77 reprojected_rendering_(reprojected_rendering),
120 weak_ptr_factory_(this) { 78 weak_ptr_factory_(this) {
121 DCHECK(g_instance == nullptr); 79 DCHECK(g_instance == nullptr);
122 g_instance = this; 80 g_instance = this;
123 j_vr_shell_.Reset(env, obj); 81 j_vr_shell_.Reset(env, obj);
124 82
125 content_input_manager_ = base::MakeUnique<VrInputManager>(main_contents_); 83 content_input_manager_ = base::MakeUnique<VrInputManager>(main_contents_);
126 ui_input_manager_ = base::MakeUnique<VrInputManager>(ui_contents_); 84 ui_input_manager_ = base::MakeUnique<VrInputManager>(ui_contents_);
127 85
128 content_compositor_->SetLayer(main_contents_); 86 content_compositor_->SetLayer(main_contents_);
129 ui_compositor_->SetLayer(ui_contents_); 87 ui_compositor_->SetLayer(ui_contents_);
130 88
131 gl_thread_ = base::MakeUnique<GLThread>(weak_ptr_factory_.GetWeakPtr(), 89 gl_thread_ = base::MakeUnique<VrGLThread>(
132 main_thread_task_runner_, gvr_api, 90 weak_ptr_factory_.GetWeakPtr(), delegate_provider_->GetWeakPtr(),
133 for_web_vr, reprojected_rendering_); 91 main_thread_task_runner_, gvr_api, for_web_vr, reprojected_rendering_);
134 92
135 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0); 93 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0);
136 options.priority = base::ThreadPriority::DISPLAY; 94 options.priority = base::ThreadPriority::DISPLAY;
137 gl_thread_->StartWithOptions(options); 95 gl_thread_->StartWithOptions(options);
138 96
139 if (for_web_vr) 97 if (for_web_vr)
140 metrics_helper_->SetWebVREnabled(true); 98 metrics_helper_->SetWebVREnabled(true);
141 html_interface_ = base::MakeUnique<UiInterface>( 99 html_interface_ = base::MakeUnique<UiInterface>(
142 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD, 100 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD,
143 main_contents_->IsFullscreen()); 101 main_contents_->IsFullscreen());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // we need to block shutting down the GvrLayout on stopping our GL thread 149 // we need to block shutting down the GvrLayout on stopping our GL thread
192 // from using the GvrApi instance. 150 // from using the GvrApi instance.
193 // base::Thread::Stop, which is called when destroying the thread, asserts 151 // base::Thread::Stop, which is called when destroying the thread, asserts
194 // that IO is allowed to prevent jank, but there shouldn't be any concerns 152 // that IO is allowed to prevent jank, but there shouldn't be any concerns
195 // regarding jank in this case, because we're switching from 3D to 2D, 153 // regarding jank in this case, because we're switching from 3D to 2D,
196 // adding/removing a bunch of Java views, and probably changing device 154 // adding/removing a bunch of Java views, and probably changing device
197 // orientation here. 155 // orientation here.
198 base::ThreadRestrictions::ScopedAllowIO allow_io; 156 base::ThreadRestrictions::ScopedAllowIO allow_io;
199 gl_thread_.reset(); 157 gl_thread_.reset();
200 } 158 }
201 delegate_->RemoveDelegate(); 159 delegate_provider_->RemoveDelegate();
202 g_instance = nullptr; 160 g_instance = nullptr;
203 } 161 }
204 162
205 void VrShell::PostToGlThreadWhenReady(const base::Closure& task) { 163 void VrShell::PostToGlThreadWhenReady(const base::Closure& task) {
206 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't 164 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't
207 // finished starting? 165 // finished starting?
208 gl_thread_->WaitUntilThreadStarted(); 166 gl_thread_->WaitUntilThreadStarted();
209 gl_thread_->task_runner()->PostTask(FROM_HERE, task); 167 gl_thread_->task_runner()->PostTask(FROM_HERE, task);
210 } 168 }
211 169
212 void VrShell::OnTriggerEvent(JNIEnv* env, 170 void VrShell::OnTriggerEvent(JNIEnv* env,
213 const JavaParamRef<jobject>& obj) { 171 const JavaParamRef<jobject>& obj) {
214 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 172 gl_thread_->task_runner()->PostTask(
215 thread->task_runner()->PostTask(FROM_HERE, 173 FROM_HERE,
216 base::Bind(&VrShellGl::OnTriggerEvent, 174 base::Bind(&VrShellGl::OnTriggerEvent, gl_thread_->GetVrShellGl()));
217 thread->GetVrShellGl()));
218 } 175 }
219 176
220 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { 177 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) {
221 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 178 gl_thread_->task_runner()->PostTask(
222 thread->task_runner()->PostTask( 179 FROM_HERE, base::Bind(&VrShellGl::OnPause, gl_thread_->GetVrShellGl()));
223 FROM_HERE, base::Bind(&VrShellGl::OnPause, thread->GetVrShellGl()));
224 180
225 // exit vr session 181 // exit vr session
226 metrics_helper_->SetVRActive(false); 182 metrics_helper_->SetVRActive(false);
227 SetIsInVR(main_contents_, false); 183 SetIsInVR(main_contents_, false);
228 } 184 }
229 185
230 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { 186 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) {
231 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 187 gl_thread_->task_runner()->PostTask(
232 thread->task_runner()->PostTask( 188 FROM_HERE, base::Bind(&VrShellGl::OnResume, gl_thread_->GetVrShellGl()));
233 FROM_HERE, base::Bind(&VrShellGl::OnResume, thread->GetVrShellGl()));
234 189
235 metrics_helper_->SetVRActive(true); 190 metrics_helper_->SetVRActive(true);
236 SetIsInVR(main_contents_, true); 191 SetIsInVR(main_contents_, true);
237 } 192 }
238 193
239 void VrShell::SetSurface(JNIEnv* env, 194 void VrShell::SetSurface(JNIEnv* env,
240 const JavaParamRef<jobject>& obj, 195 const JavaParamRef<jobject>& obj,
241 const JavaParamRef<jobject>& surface) { 196 const JavaParamRef<jobject>& surface) {
242 CHECK(!reprojected_rendering_); 197 CHECK(!reprojected_rendering_);
243 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
244 gfx::AcceleratedWidget window = 198 gfx::AcceleratedWidget window =
245 ANativeWindow_fromSurface(base::android::AttachCurrentThread(), surface); 199 ANativeWindow_fromSurface(base::android::AttachCurrentThread(), surface);
246 PostToGlThreadWhenReady(base::Bind(&VrShellGl::InitializeGl, 200 PostToGlThreadWhenReady(base::Bind(&VrShellGl::InitializeGl,
247 thread->GetVrShellGl(), 201 gl_thread_->GetVrShellGl(),
248 base::Unretained(window))); 202 base::Unretained(window)));
249 } 203 }
250 204
251 base::WeakPtr<VrShell> VrShell::GetWeakPtr( 205 base::WeakPtr<VrShell> VrShell::GetWeakPtr(
252 const content::WebContents* web_contents) { 206 const content::WebContents* web_contents) {
253 // Ensure that the WebContents requesting the VrShell instance is the one 207 // Ensure that the WebContents requesting the VrShell instance is the one
254 // we created. 208 // we created.
255 if (g_instance != nullptr && g_instance->ui_contents_ == web_contents) 209 if (g_instance != nullptr && g_instance->ui_contents_ == web_contents)
256 return g_instance->weak_ptr_factory_.GetWeakPtr(); 210 return g_instance->weak_ptr_factory_.GetWeakPtr();
257 return base::WeakPtr<VrShell>(nullptr); 211 return base::WeakPtr<VrShell>(nullptr);
258 } 212 }
259 213
260 void VrShell::OnDomContentsLoaded() { 214 void VrShell::OnDomContentsLoaded() {
261 html_interface_->SetURL(main_contents_->GetVisibleURL()); 215 html_interface_->SetURL(main_contents_->GetVisibleURL());
262 html_interface_->SetLoading(main_contents_->IsLoading()); 216 html_interface_->SetLoading(main_contents_->IsLoading());
263 html_interface_->OnDomContentsLoaded(); 217 html_interface_->OnDomContentsLoaded();
264 } 218 }
265 219
266 void VrShell::SetWebVrMode(JNIEnv* env, 220 void VrShell::SetWebVrMode(JNIEnv* env,
267 const base::android::JavaParamRef<jobject>& obj, 221 const base::android::JavaParamRef<jobject>& obj,
268 bool enabled) { 222 bool enabled) {
269 metrics_helper_->SetWebVREnabled(enabled); 223 metrics_helper_->SetWebVREnabled(enabled);
270 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 224 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetWebVrMode,
271 PostToGlThreadWhenReady( 225 gl_thread_->GetVrShellGl(), enabled));
272 base::Bind(&VrShellGl::SetWebVrMode, thread->GetVrShellGl(), enabled));
273 if (enabled) { 226 if (enabled) {
274 html_interface_->SetMode(UiInterface::Mode::WEB_VR); 227 html_interface_->SetMode(UiInterface::Mode::WEB_VR);
275 } else { 228 } else {
276 html_interface_->SetMode(UiInterface::Mode::STANDARD); 229 html_interface_->SetMode(UiInterface::Mode::STANDARD);
277 } 230 }
278 } 231 }
279 232
280 void VrShell::OnLoadProgressChanged( 233 void VrShell::OnLoadProgressChanged(
281 JNIEnv* env, 234 JNIEnv* env,
282 const base::android::JavaParamRef<jobject>& obj, 235 const base::android::JavaParamRef<jobject>& obj,
283 double progress) { 236 double progress) {
284 html_interface_->SetLoadProgress(progress); 237 html_interface_->SetLoadProgress(progress);
285 } 238 }
286 239
287 void VrShell::SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) {
288 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
289 if (thread->IsRunning()) {
290 thread->task_runner()->PostTask(
291 FROM_HERE, base::Bind(&VrShellGl::SetGvrPoseForWebVr,
292 thread->GetVrShellGl(), pose, pose_num));
293 }
294 }
295
296 void VrShell::SetWebVRRenderSurfaceSize(int width, int height) { 240 void VrShell::SetWebVRRenderSurfaceSize(int width, int height) {
297 // TODO(klausw,crbug.com/655722): Change the GVR render size and set the WebVR 241 // TODO(klausw,crbug.com/655722): Change the GVR render size and set the WebVR
298 // render surface size. 242 // render surface size.
299 } 243 }
300 244
301 gvr::Sizei VrShell::GetWebVRCompositorSurfaceSize() { 245 gvr::Sizei VrShell::GetWebVRCompositorSurfaceSize() {
302 const gfx::Size& size = content_compositor_->GetWindowBounds(); 246 const gfx::Size& size = content_compositor_->GetWindowBounds();
303 return {size.width(), size.height()}; 247 return {size.width(), size.height()};
304 } 248 }
305 249
306 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { 250 void VrShell::SetWebVRSecureOrigin(bool secure_origin) {
307 // TODO(cjgrant): Align this state with the logic that drives the omnibox. 251 // TODO(cjgrant): Align this state with the logic that drives the omnibox.
308 html_interface_->SetWebVRSecureOrigin(secure_origin); 252 html_interface_->SetWebVRSecureOrigin(secure_origin);
309 } 253 }
310 254
311 void VrShell::SubmitWebVRFrame() {} 255 void VrShell::SubmitWebVRFrame() {}
312 256
313 void VrShell::UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds, 257 void VrShell::UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds,
314 const gvr::Rectf& right_bounds) { 258 const gvr::Rectf& right_bounds) {
315 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
316 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateWebVRTextureBounds, 259 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateWebVRTextureBounds,
317 thread->GetVrShellGl(), left_bounds, 260 gl_thread_->GetVrShellGl(), left_bounds,
318 right_bounds)); 261 right_bounds));
319 } 262 }
320 263
321 // TODO(mthiesse): Do not expose GVR API outside of GL thread. 264 // TODO(mthiesse): Do not expose GVR API outside of GL thread.
322 // It's not thread-safe. 265 // It's not thread-safe.
323 gvr::GvrApi* VrShell::gvr_api() { 266 gvr::GvrApi* VrShell::gvr_api() {
324 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 267 if (gl_thread_->GetVrShellGlUnsafe()) {
325 if (thread->GetVrShellGlUnsafe()) { 268 return gl_thread_->GetVrShellGlUnsafe()->gvr_api();
326 return thread->GetVrShellGlUnsafe()->gvr_api();
327 } 269 }
328 CHECK(false); 270 CHECK(false);
329 return nullptr; 271 return nullptr;
330 } 272 }
331 273
332 void VrShell::SurfacesChanged(jobject content_surface, jobject ui_surface) { 274 void VrShell::SurfacesChanged(jobject content_surface, jobject ui_surface) {
333 content_compositor_->SurfaceChanged(content_surface); 275 content_compositor_->SurfaceChanged(content_surface);
334 ui_compositor_->SurfaceChanged(ui_surface); 276 ui_compositor_->SurfaceChanged(ui_surface);
335 } 277 }
336 278
337 void VrShell::GvrDelegateReady() { 279 void VrShell::GvrDelegateReady() {
338 delegate_->SetDelegate(this); 280 delegate_provider_->SetDelegate(this);
339 } 281 }
340 282
341 void VrShell::AppButtonPressed() { 283 void VrShell::AppButtonPressed() {
342 #if defined(ENABLE_VR_SHELL) 284 #if defined(ENABLE_VR_SHELL)
343 html_interface_->SetMenuMode(!html_interface_->GetMenuMode()); 285 html_interface_->SetMenuMode(!html_interface_->GetMenuMode());
344 286
345 // TODO(mthiesse): The page is no longer visible when in menu mode. We 287 // TODO(mthiesse): The page is no longer visible when in menu mode. We
346 // should unfocus or otherwise let it know it's hidden. 288 // should unfocus or otherwise let it know it's hidden.
347 if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) { 289 if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) {
348 if (delegate_->device_provider()) { 290 if (delegate_provider_->device_provider()) {
349 if (html_interface_->GetMenuMode()) { 291 if (html_interface_->GetMenuMode()) {
350 delegate_->device_provider()->OnDisplayBlur(); 292 delegate_provider_->device_provider()->OnDisplayBlur();
351 } else { 293 } else {
352 delegate_->device_provider()->OnDisplayFocus(); 294 delegate_provider_->device_provider()->OnDisplayFocus();
353 } 295 }
354 } 296 }
355 } 297 }
356 #endif 298 #endif
357 } 299 }
358 300
359 void VrShell::ContentPhysicalBoundsChanged(JNIEnv* env, 301 void VrShell::ContentPhysicalBoundsChanged(JNIEnv* env,
360 const JavaParamRef<jobject>& object, 302 const JavaParamRef<jobject>& object,
361 jint width, jint height, 303 jint width, jint height,
362 jfloat dpr) { 304 jfloat dpr) {
363 TRACE_EVENT0("gpu", "VrShell::ContentPhysicalBoundsChanged"); 305 TRACE_EVENT0("gpu", "VrShell::ContentPhysicalBoundsChanged");
364 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
365 PostToGlThreadWhenReady(base::Bind(&VrShellGl::ContentPhysicalBoundsChanged, 306 PostToGlThreadWhenReady(base::Bind(&VrShellGl::ContentPhysicalBoundsChanged,
366 thread->GetVrShellGl(), width, height)); 307 gl_thread_->GetVrShellGl(), width,
308 height));
367 content_compositor_->SetWindowBounds(gfx::Size(width, height)); 309 content_compositor_->SetWindowBounds(gfx::Size(width, height));
368 } 310 }
369 311
370 void VrShell::UIPhysicalBoundsChanged(JNIEnv* env, 312 void VrShell::UIPhysicalBoundsChanged(JNIEnv* env,
371 const JavaParamRef<jobject>& object, 313 const JavaParamRef<jobject>& object,
372 jint width, jint height, jfloat dpr) { 314 jint width, jint height, jfloat dpr) {
373 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
374 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UIPhysicalBoundsChanged, 315 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UIPhysicalBoundsChanged,
375 thread->GetVrShellGl(), width, height)); 316 gl_thread_->GetVrShellGl(), width,
317 height));
376 ui_compositor_->SetWindowBounds(gfx::Size(width, height)); 318 ui_compositor_->SetWindowBounds(gfx::Size(width, height));
377 } 319 }
378 320
379 UiInterface* VrShell::GetUiInterface() { 321 UiInterface* VrShell::GetUiInterface() {
380 return html_interface_.get(); 322 return html_interface_.get();
381 } 323 }
382 324
383 void VrShell::UpdateScene(const base::ListValue* args) { 325 void VrShell::UpdateScene(const base::ListValue* args) {
384 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
385 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateScene, 326 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateScene,
386 thread->GetVrShellGl(), 327 gl_thread_->GetVrShellGl(),
387 base::Passed(args->CreateDeepCopy()))); 328 base::Passed(args->CreateDeepCopy())));
388 } 329 }
389 330
390 void VrShell::DoUiAction(const UiAction action) { 331 void VrShell::DoUiAction(const UiAction action) {
391 content::NavigationController& controller = main_contents_->GetController(); 332 content::NavigationController& controller = main_contents_->GetController();
392 switch (action) { 333 switch (action) {
393 case HISTORY_BACK: 334 case HISTORY_BACK:
394 if (main_contents_->IsFullscreen()) { 335 if (main_contents_->IsFullscreen()) {
395 main_contents_->ExitFullscreen(false); 336 main_contents_->ExitFullscreen(false);
396 } else if (controller.CanGoBack()) { 337 } else if (controller.CanGoBack()) {
(...skipping 24 matching lines...) Expand all
421 } 362 }
422 363
423 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host, 364 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host,
424 content::RenderViewHost* new_host) { 365 content::RenderViewHost* new_host) {
425 new_host->GetWidget()->GetView()->SetBackgroundColor(SK_ColorTRANSPARENT); 366 new_host->GetWidget()->GetView()->SetBackgroundColor(SK_ColorTRANSPARENT);
426 } 367 }
427 368
428 void VrShell::MainFrameWasResized(bool width_changed) { 369 void VrShell::MainFrameWasResized(bool width_changed) {
429 display::Display display = display::Screen::GetScreen() 370 display::Display display = display::Screen::GetScreen()
430 ->GetDisplayNearestWindow(ui_contents_->GetNativeView()); 371 ->GetDisplayNearestWindow(ui_contents_->GetNativeView());
431 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
432 PostToGlThreadWhenReady( 372 PostToGlThreadWhenReady(
433 base::Bind(&VrShellGl::UIBoundsChanged, thread->GetVrShellGl(), 373 base::Bind(&VrShellGl::UIBoundsChanged, gl_thread_->GetVrShellGl(),
434 display.size().width(), display.size().height())); 374 display.size().width(), display.size().height()));
435 } 375 }
436 376
437 void VrShell::ContentFrameWasResized(bool width_changed) { 377 void VrShell::ContentFrameWasResized(bool width_changed) {
438 display::Display display = display::Screen::GetScreen() 378 display::Display display = display::Screen::GetScreen()
439 ->GetDisplayNearestWindow(main_contents_->GetNativeView()); 379 ->GetDisplayNearestWindow(main_contents_->GetNativeView());
440 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
441 PostToGlThreadWhenReady( 380 PostToGlThreadWhenReady(
442 base::Bind(&VrShellGl::ContentBoundsChanged, thread->GetVrShellGl(), 381 base::Bind(&VrShellGl::ContentBoundsChanged, gl_thread_->GetVrShellGl(),
443 display.size().width(), display.size().height())); 382 display.size().width(), display.size().height()));
444 } 383 }
445 384
446 void VrShell::WebContentsDestroyed() { 385 void VrShell::WebContentsDestroyed() {
447 ui_input_manager_.reset(); 386 ui_input_manager_.reset();
448 ui_contents_ = nullptr; 387 ui_contents_ = nullptr;
449 // TODO(mthiesse): Handle web contents being destroyed. 388 // TODO(mthiesse): Handle web contents being destroyed.
450 ForceExitVr(); 389 ForceExitVr();
451 } 390 }
452 391
453 void VrShell::ContentWebContentsDestroyed() { 392 void VrShell::ContentWebContentsDestroyed() {
454 content_input_manager_.reset(); 393 content_input_manager_.reset();
455 main_contents_ = nullptr; 394 main_contents_ = nullptr;
456 // TODO(mthiesse): Handle web contents being destroyed. 395 // TODO(mthiesse): Handle web contents being destroyed.
457 ForceExitVr(); 396 ForceExitVr();
458 } 397 }
459 398
460 void VrShell::ContentWasHidden() { 399 void VrShell::ContentWasHidden() {
461 // Ensure we don't continue sending input to it. 400 // Ensure we don't continue sending input to it.
462 content_input_manager_ = nullptr; 401 content_input_manager_ = nullptr;
463 } 402 }
464 403
465 void VrShell::ContentWasShown() { 404 void VrShell::ContentWasShown() {
466 content_input_manager_ = base::MakeUnique<VrInputManager>(main_contents_); 405 content_input_manager_ = base::MakeUnique<VrInputManager>(main_contents_);
467 } 406 }
468 407
469 void VrShell::ForceExitVr() { 408 void VrShell::ForceExitVr() {
470 delegate_->ForceExitVr(); 409 delegate_provider_->ForceExitVr();
410 }
411
412 void VrShell::OnVRVsyncProviderRequest(
413 device::mojom::VRVSyncProviderRequest request) {
414 PostToGlThreadWhenReady(base::Bind(&VrShellGl::OnRequest,
415 gl_thread_->GetVrShellGl(),
416 base::Passed(&request)));
417 }
418
419 void VrShell::UpdateVSyncInterval(long timebase_nanos,
420 double interval_seconds) {
421 PostToGlThreadWhenReady(
422 base::Bind(&VrShellGl::UpdateVSyncInterval,
423 gl_thread_->GetVrShellGl(), timebase_nanos, interval_seconds));
471 } 424 }
472 425
473 void VrShell::SetContentCssSize(float width, float height, float dpr) { 426 void VrShell::SetContentCssSize(float width, float height, float dpr) {
474 JNIEnv* env = base::android::AttachCurrentThread(); 427 JNIEnv* env = base::android::AttachCurrentThread();
475 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height, 428 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height,
476 dpr); 429 dpr);
477 } 430 }
478 431
479 void VrShell::SetUiCssSize(float width, float height, float dpr) { 432 void VrShell::SetUiCssSize(float width, float height, float dpr) {
480 JNIEnv* env = base::android::AttachCurrentThread(); 433 JNIEnv* env = base::android::AttachCurrentThread();
481 Java_VrShellImpl_setUiCssSize(env, j_vr_shell_.obj(), width, height, dpr); 434 Java_VrShellImpl_setUiCssSize(env, j_vr_shell_.obj(), width, height, dpr);
482 } 435 }
483 436
484 void VrShell::ProcessUIGesture(std::unique_ptr<blink::WebInputEvent> event) { 437 void VrShell::ProcessUIGesture(std::unique_ptr<blink::WebInputEvent> event) {
485 if (ui_input_manager_) { 438 if (ui_input_manager_) {
486 ui_input_manager_->ProcessUpdatedGesture(std::move(event)); 439 ui_input_manager_->ProcessUpdatedGesture(std::move(event));
487 } 440 }
488 441
489 } 442 }
490 443
491 void VrShell::ProcessContentGesture( 444 void VrShell::ProcessContentGesture(
492 std::unique_ptr<blink::WebInputEvent> event) { 445 std::unique_ptr<blink::WebInputEvent> event) {
493 if (content_input_manager_) { 446 if (content_input_manager_) {
494 content_input_manager_->ProcessUpdatedGesture(std::move(event)); 447 content_input_manager_->ProcessUpdatedGesture(std::move(event));
495 } 448 }
496 } 449 }
497 450
451 device::mojom::VRPosePtr VrShell::VRPosePtrFromGvrPose(gvr::Mat4f head_mat,
452 uint32_t pose_index) {
453 device::mojom::VRPosePtr pose = device::mojom::VRPose::New();
454
455 pose->timestamp = base::Time::Now().ToJsTime();
456
457 pose->poseIndex = pose_index;
458 pose->orientation.emplace(4);
459
460 gfx::Transform inv_transform(
461 head_mat.m[0][0], head_mat.m[0][1], head_mat.m[0][2], head_mat.m[0][3],
462 head_mat.m[1][0], head_mat.m[1][1], head_mat.m[1][2], head_mat.m[1][3],
463 head_mat.m[2][0], head_mat.m[2][1], head_mat.m[2][2], head_mat.m[2][3],
464 head_mat.m[3][0], head_mat.m[3][1], head_mat.m[3][2], head_mat.m[3][3]);
465
466 gfx::Transform transform;
467 if (inv_transform.GetInverse(&transform)) {
468 gfx::DecomposedTransform decomposed_transform;
469 gfx::DecomposeTransform(&decomposed_transform, transform);
470
471 pose->orientation.value()[0] = decomposed_transform.quaternion[0];
472 pose->orientation.value()[1] = decomposed_transform.quaternion[1];
473 pose->orientation.value()[2] = decomposed_transform.quaternion[2];
474 pose->orientation.value()[3] = decomposed_transform.quaternion[3];
475
476 pose->position.emplace(3);
477 pose->position.value()[0] = decomposed_transform.translate[0];
478 pose->position.value()[1] = decomposed_transform.translate[1];
479 pose->position.value()[2] = decomposed_transform.translate[2];
480 }
481
482 return pose;
483 }
498 484
499 // ---------------------------------------------------------------------------- 485 // ----------------------------------------------------------------------------
500 // Native JNI methods 486 // Native JNI methods
501 // ---------------------------------------------------------------------------- 487 // ----------------------------------------------------------------------------
502 488
503 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj, 489 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj,
504 const JavaParamRef<jobject>& content_web_contents, 490 const JavaParamRef<jobject>& content_web_contents,
505 jlong content_window_android, 491 jlong content_window_android,
506 const JavaParamRef<jobject>& ui_web_contents, 492 const JavaParamRef<jobject>& ui_web_contents,
507 jlong ui_window_android, jboolean for_web_vr, 493 jlong ui_window_android, jboolean for_web_vr,
508 const base::android::JavaParamRef<jobject>& delegate, 494 const base::android::JavaParamRef<jobject>& delegate,
509 jlong gvr_api, jboolean reprojected_rendering) { 495 jlong gvr_api, jboolean reprojected_rendering) {
510 return reinterpret_cast<intptr_t>(new VrShell( 496 return reinterpret_cast<intptr_t>(new VrShell(
511 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), 497 env, obj, content::WebContents::FromJavaWebContents(content_web_contents),
512 reinterpret_cast<ui::WindowAndroid*>(content_window_android), 498 reinterpret_cast<ui::WindowAndroid*>(content_window_android),
513 content::WebContents::FromJavaWebContents(ui_web_contents), 499 content::WebContents::FromJavaWebContents(ui_web_contents),
514 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), 500 reinterpret_cast<ui::WindowAndroid*>(ui_window_android),
515 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate), 501 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate),
516 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); 502 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering));
517 } 503 }
518 504
519 } // namespace vr_shell 505 } // 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_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698