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

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

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