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

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

Issue 2729523002: Re-land^2 WebVR compositor bypass via BrowserMain context + mailbox (Closed)
Patch Set: Merge mthiesse@'s submitFrameClient fix from crrev.com/2734003002/#ps60001 Created 3 years, 9 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 18 matching lines...) Expand all
29 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" 29 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h"
30 #include "content/public/browser/navigation_controller.h" 30 #include "content/public/browser/navigation_controller.h"
31 #include "content/public/browser/render_view_host.h" 31 #include "content/public/browser/render_view_host.h"
32 #include "content/public/browser/render_widget_host.h" 32 #include "content/public/browser/render_widget_host.h"
33 #include "content/public/browser/render_widget_host_view.h" 33 #include "content/public/browser/render_widget_host_view.h"
34 #include "content/public/browser/web_contents.h" 34 #include "content/public/browser/web_contents.h"
35 #include "content/public/common/content_features.h" 35 #include "content/public/common/content_features.h"
36 #include "content/public/common/referrer.h" 36 #include "content/public/common/referrer.h"
37 #include "device/vr/android/gvr/gvr_device.h" 37 #include "device/vr/android/gvr/gvr_device.h"
38 #include "device/vr/android/gvr/gvr_device_provider.h" 38 #include "device/vr/android/gvr/gvr_device_provider.h"
39 #include "gpu/command_buffer/common/mailbox.h"
39 #include "jni/VrShellImpl_jni.h" 40 #include "jni/VrShellImpl_jni.h"
40 #include "third_party/WebKit/public/platform/WebInputEvent.h" 41 #include "third_party/WebKit/public/platform/WebInputEvent.h"
41 #include "ui/android/view_android.h" 42 #include "ui/android/view_android.h"
42 #include "ui/android/window_android.h" 43 #include "ui/android/window_android.h"
43 #include "ui/base/page_transition_types.h" 44 #include "ui/base/page_transition_types.h"
44 #include "ui/display/display.h" 45 #include "ui/display/display.h"
45 #include "ui/display/screen.h" 46 #include "ui/display/screen.h"
46 #include "ui/gfx/transform.h" 47 #include "ui/gfx/transform.h"
47 #include "ui/gfx/transform_util.h" 48 #include "ui/gfx/transform_util.h"
48 49
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 ui_contents_->GetController().LoadURL( 164 ui_contents_->GetController().LoadURL(
164 url, content::Referrer(), 165 url, content::Referrer(),
165 ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string("")); 166 ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string(""));
166 } 167 }
167 168
168 bool RegisterVrShell(JNIEnv* env) { 169 bool RegisterVrShell(JNIEnv* env) {
169 return RegisterNativesImpl(env); 170 return RegisterNativesImpl(env);
170 } 171 }
171 172
172 VrShell::~VrShell() { 173 VrShell::~VrShell() {
174 delegate_provider_->RemoveDelegate();
173 { 175 {
174 // The GvrLayout is, and must always be, used only on the UI thread, and the 176 // The GvrLayout is, and must always be, used only on the UI thread, and the
175 // GvrApi used for rendering should only be used from the GL thread as it's 177 // GvrApi used for rendering should only be used from the GL thread as it's
176 // not thread safe. However, the GvrLayout owns the GvrApi instance, and 178 // not thread safe. However, the GvrLayout owns the GvrApi instance, and
177 // when it gets shut down it deletes the GvrApi instance with it. Therefore, 179 // when it gets shut down it deletes the GvrApi instance with it. Therefore,
178 // we need to block shutting down the GvrLayout on stopping our GL thread 180 // we need to block shutting down the GvrLayout on stopping our GL thread
179 // from using the GvrApi instance. 181 // from using the GvrApi instance.
180 // base::Thread::Stop, which is called when destroying the thread, asserts 182 // base::Thread::Stop, which is called when destroying the thread, asserts
181 // that IO is allowed to prevent jank, but there shouldn't be any concerns 183 // that IO is allowed to prevent jank, but there shouldn't be any concerns
182 // regarding jank in this case, because we're switching from 3D to 2D, 184 // regarding jank in this case, because we're switching from 3D to 2D,
183 // adding/removing a bunch of Java views, and probably changing device 185 // adding/removing a bunch of Java views, and probably changing device
184 // orientation here. 186 // orientation here.
185 base::ThreadRestrictions::ScopedAllowIO allow_io; 187 base::ThreadRestrictions::ScopedAllowIO allow_io;
186 gl_thread_.reset(); 188 gl_thread_.reset();
187 } 189 }
188 delegate_provider_->RemoveDelegate();
189 g_instance = nullptr; 190 g_instance = nullptr;
190 } 191 }
191 192
192 void VrShell::PostToGlThreadWhenReady(const base::Closure& task) { 193 void VrShell::PostToGlThreadWhenReady(const base::Closure& task) {
193 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't 194 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't
194 // finished starting? 195 // finished starting?
195 gl_thread_->WaitUntilThreadStarted(); 196 gl_thread_->WaitUntilThreadStarted();
196 gl_thread_->task_runner()->PostTask(FROM_HERE, task); 197 gl_thread_->task_runner()->PostTask(FROM_HERE, task);
197 } 198 }
198 199
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 265 }
265 266
266 void VrShell::SetWebVrMode(JNIEnv* env, 267 void VrShell::SetWebVrMode(JNIEnv* env,
267 const base::android::JavaParamRef<jobject>& obj, 268 const base::android::JavaParamRef<jobject>& obj,
268 bool enabled) { 269 bool enabled) {
269 webvr_mode_ = enabled; 270 webvr_mode_ = enabled;
270 if (metrics_helper_) 271 if (metrics_helper_)
271 metrics_helper_->SetWebVREnabled(enabled); 272 metrics_helper_->SetWebVREnabled(enabled);
272 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetWebVrMode, 273 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetWebVrMode,
273 gl_thread_->GetVrShellGl(), enabled)); 274 gl_thread_->GetVrShellGl(), enabled));
275
274 html_interface_->SetMode(enabled ? UiInterface::Mode::WEB_VR 276 html_interface_->SetMode(enabled ? UiInterface::Mode::WEB_VR
275 : UiInterface::Mode::STANDARD); 277 : UiInterface::Mode::STANDARD);
276 } 278 }
277 279
278 void VrShell::OnLoadProgressChanged(JNIEnv* env, 280 void VrShell::OnLoadProgressChanged(JNIEnv* env,
279 const JavaParamRef<jobject>& obj, 281 const JavaParamRef<jobject>& obj,
280 double progress) { 282 double progress) {
281 html_interface_->SetLoadProgress(progress); 283 html_interface_->SetLoadProgress(progress);
282 } 284 }
283 285
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 jboolean incognito, 319 jboolean incognito,
318 jint id) { 320 jint id) {
319 html_interface_->RemoveTab(incognito, id); 321 html_interface_->RemoveTab(incognito, id);
320 } 322 }
321 323
322 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { 324 void VrShell::SetWebVRSecureOrigin(bool secure_origin) {
323 // TODO(cjgrant): Align this state with the logic that drives the omnibox. 325 // TODO(cjgrant): Align this state with the logic that drives the omnibox.
324 html_interface_->SetWebVRSecureOrigin(secure_origin); 326 html_interface_->SetWebVRSecureOrigin(secure_origin);
325 } 327 }
326 328
327 void VrShell::SubmitWebVRFrame() {} 329 void VrShell::SubmitWebVRFrame(int16_t frame_index,
330 const gpu::MailboxHolder& mailbox) {
331 TRACE_EVENT1("gpu", "SubmitWebVRFrame", "frame", frame_index);
332
333 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SubmitWebVRFrame,
334 gl_thread_->GetVrShellGl(), frame_index,
335 mailbox));
336 }
328 337
329 void VrShell::UpdateWebVRTextureBounds(int16_t frame_index, 338 void VrShell::UpdateWebVRTextureBounds(int16_t frame_index,
330 const gvr::Rectf& left_bounds, 339 const gvr::Rectf& left_bounds,
331 const gvr::Rectf& right_bounds) { 340 const gvr::Rectf& right_bounds,
341 const gvr::Sizei& source_size) {
332 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateWebVRTextureBounds, 342 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateWebVRTextureBounds,
333 gl_thread_->GetVrShellGl(), frame_index, 343 gl_thread_->GetVrShellGl(), frame_index,
334 left_bounds, right_bounds)); 344 left_bounds, right_bounds, source_size));
335 } 345 }
336 346
337 bool VrShell::SupportsPresentation() { 347 bool VrShell::SupportsPresentation() {
338 return true; 348 return true;
339 } 349 }
340 350
341 void VrShell::ResetPose() { 351 void VrShell::ResetPose() {
342 gl_thread_->task_runner()->PostTask( 352 gl_thread_->task_runner()->PostTask(
343 FROM_HERE, base::Bind(&VrShellGl::ResetPose, gl_thread_->GetVrShellGl())); 353 FROM_HERE, base::Bind(&VrShellGl::ResetPose, gl_thread_->GetVrShellGl()));
344 } 354 }
(...skipping 26 matching lines...) Expand all
371 } 381 }
372 382
373 void VrShell::ContentSurfaceChanged(jobject surface) { 383 void VrShell::ContentSurfaceChanged(jobject surface) {
374 content_surface_ = surface; 384 content_surface_ = surface;
375 content_compositor_->SurfaceChanged(surface); 385 content_compositor_->SurfaceChanged(surface);
376 JNIEnv* env = base::android::AttachCurrentThread(); 386 JNIEnv* env = base::android::AttachCurrentThread();
377 Java_VrShellImpl_contentSurfaceChanged(env, j_vr_shell_.obj()); 387 Java_VrShellImpl_contentSurfaceChanged(env, j_vr_shell_.obj());
378 } 388 }
379 389
380 void VrShell::GvrDelegateReady() { 390 void VrShell::GvrDelegateReady() {
391 PostToGlThreadWhenReady(base::Bind(
392 &VrShellGl::SetSubmitClient, gl_thread_->GetVrShellGl(),
393 base::Passed(
394 delegate_provider_->TakeSubmitFrameClient().PassInterface())));
381 delegate_provider_->SetDelegate(this, gvr_api_); 395 delegate_provider_->SetDelegate(this, gvr_api_);
382 } 396 }
383 397
384 void VrShell::AppButtonPressed() { 398 void VrShell::AppButtonPressed() {
385 if (vr_shell_enabled_) 399 if (vr_shell_enabled_)
386 html_interface_->HandleAppButtonClicked(); 400 html_interface_->HandleAppButtonClicked();
387 } 401 }
388 402
389 void VrShell::ContentPhysicalBoundsChanged(JNIEnv* env, 403 void VrShell::ContentPhysicalBoundsChanged(JNIEnv* env,
390 const JavaParamRef<jobject>& object, 404 const JavaParamRef<jobject>& object,
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 pose->position.value()[0] = decomposed_transform.translate[0]; 630 pose->position.value()[0] = decomposed_transform.translate[0];
617 pose->position.value()[1] = decomposed_transform.translate[1]; 631 pose->position.value()[1] = decomposed_transform.translate[1];
618 pose->position.value()[2] = decomposed_transform.translate[2]; 632 pose->position.value()[2] = decomposed_transform.translate[2];
619 } 633 }
620 634
621 return pose; 635 return pose;
622 } 636 }
623 637
624 device::mojom::VRDisplayInfoPtr VrShell::CreateVRDisplayInfo( 638 device::mojom::VRDisplayInfoPtr VrShell::CreateVRDisplayInfo(
625 gvr::GvrApi* gvr_api, 639 gvr::GvrApi* gvr_api,
626 gvr::Sizei compositor_size, 640 gvr::Sizei recommended_size,
627 uint32_t device_id) { 641 uint32_t device_id) {
628 TRACE_EVENT0("input", "GvrDevice::GetVRDevice"); 642 TRACE_EVENT0("input", "GvrDevice::GetVRDevice");
629 643
630 device::mojom::VRDisplayInfoPtr device = device::mojom::VRDisplayInfo::New(); 644 device::mojom::VRDisplayInfoPtr device = device::mojom::VRDisplayInfo::New();
631 645
632 device->index = device_id; 646 device->index = device_id;
633 647
634 device->capabilities = device::mojom::VRDisplayCapabilities::New(); 648 device->capabilities = device::mojom::VRDisplayCapabilities::New();
635 device->capabilities->hasOrientation = true; 649 device->capabilities->hasOrientation = true;
636 device->capabilities->hasPosition = false; 650 device->capabilities->hasPosition = false;
637 device->capabilities->hasExternalDisplay = false; 651 device->capabilities->hasExternalDisplay = false;
638 device->capabilities->canPresent = true; 652 device->capabilities->canPresent = true;
639 653
640 std::string vendor = gvr_api->GetViewerVendor(); 654 std::string vendor = gvr_api->GetViewerVendor();
641 std::string model = gvr_api->GetViewerModel(); 655 std::string model = gvr_api->GetViewerModel();
642 device->displayName = vendor + " " + model; 656 device->displayName = vendor + " " + model;
643 657
644 gvr::BufferViewportList gvr_buffer_viewports = 658 gvr::BufferViewportList gvr_buffer_viewports =
645 gvr_api->CreateEmptyBufferViewportList(); 659 gvr_api->CreateEmptyBufferViewportList();
646 gvr_buffer_viewports.SetToRecommendedBufferViewports(); 660 gvr_buffer_viewports.SetToRecommendedBufferViewports();
647 661
648 device->leftEye = device::mojom::VREyeParameters::New(); 662 device->leftEye = device::mojom::VREyeParameters::New();
649 device->rightEye = device::mojom::VREyeParameters::New(); 663 device->rightEye = device::mojom::VREyeParameters::New();
650 for (auto eye : {GVR_LEFT_EYE, GVR_RIGHT_EYE}) { 664 for (auto eye : {GVR_LEFT_EYE, GVR_RIGHT_EYE}) {
651 device::mojom::VREyeParametersPtr& eye_params = 665 device::mojom::VREyeParametersPtr& eye_params =
652 (eye == GVR_LEFT_EYE) ? device->leftEye : device->rightEye; 666 (eye == GVR_LEFT_EYE) ? device->leftEye : device->rightEye;
653 eye_params->fieldOfView = device::mojom::VRFieldOfView::New(); 667 eye_params->fieldOfView = device::mojom::VRFieldOfView::New();
654 eye_params->offset.resize(3); 668 eye_params->offset.resize(3);
655 eye_params->renderWidth = compositor_size.width / 2; 669 eye_params->renderWidth = recommended_size.width / 2;
656 eye_params->renderHeight = compositor_size.height; 670 eye_params->renderHeight = recommended_size.height;
657 671
658 gvr::BufferViewport eye_viewport = gvr_api->CreateBufferViewport(); 672 gvr::BufferViewport eye_viewport = gvr_api->CreateBufferViewport();
659 gvr_buffer_viewports.GetBufferViewport(eye, &eye_viewport); 673 gvr_buffer_viewports.GetBufferViewport(eye, &eye_viewport);
660 gvr::Rectf eye_fov = eye_viewport.GetSourceFov(); 674 gvr::Rectf eye_fov = eye_viewport.GetSourceFov();
661 eye_params->fieldOfView->upDegrees = eye_fov.top; 675 eye_params->fieldOfView->upDegrees = eye_fov.top;
662 eye_params->fieldOfView->downDegrees = eye_fov.bottom; 676 eye_params->fieldOfView->downDegrees = eye_fov.bottom;
663 eye_params->fieldOfView->leftDegrees = eye_fov.left; 677 eye_params->fieldOfView->leftDegrees = eye_fov.left;
664 eye_params->fieldOfView->rightDegrees = eye_fov.right; 678 eye_params->fieldOfView->rightDegrees = eye_fov.right;
665 679
666 gvr::Mat4f eye_mat = gvr_api->GetEyeFromHeadMatrix(eye); 680 gvr::Mat4f eye_mat = gvr_api->GetEyeFromHeadMatrix(eye);
(...skipping 20 matching lines...) Expand all
687 jboolean reprojected_rendering) { 701 jboolean reprojected_rendering) {
688 return reinterpret_cast<intptr_t>(new VrShell( 702 return reinterpret_cast<intptr_t>(new VrShell(
689 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android), 703 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android),
690 content::WebContents::FromJavaWebContents(ui_web_contents), 704 content::WebContents::FromJavaWebContents(ui_web_contents),
691 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr, 705 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr,
692 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), 706 VrShellDelegate::GetNativeVrShellDelegate(env, delegate),
693 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); 707 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering));
694 } 708 }
695 709
696 } // namespace vr_shell 710 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698