| OLD | NEW |
| 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 "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "chrome/browser/android/vr_shell/ui_elements.h" | 8 #include "chrome/browser/android/vr_shell/ui_elements.h" |
| 9 #include "chrome/browser/android/vr_shell/ui_interface.h" | 9 #include "chrome/browser/android/vr_shell/ui_interface.h" |
| 10 #include "chrome/browser/android/vr_shell/ui_scene.h" | 10 #include "chrome/browser/android/vr_shell/ui_scene.h" |
| 11 #include "chrome/browser/android/vr_shell/vr_compositor.h" | 11 #include "chrome/browser/android/vr_shell/vr_compositor.h" |
| 12 #include "chrome/browser/android/vr_shell/vr_controller.h" | 12 #include "chrome/browser/android/vr_shell/vr_controller.h" |
| 13 #include "chrome/browser/android/vr_shell/vr_gl_util.h" | 13 #include "chrome/browser/android/vr_shell/vr_gl_util.h" |
| 14 #include "chrome/browser/android/vr_shell/vr_input_manager.h" | 14 #include "chrome/browser/android/vr_shell/vr_input_manager.h" |
| 15 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" | 15 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" |
| 16 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" | 16 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" |
| 17 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" | 17 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" |
| 18 #include "content/public/browser/navigation_controller.h" | 18 #include "content/public/browser/navigation_controller.h" |
| 19 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
| 20 #include "content/public/browser/render_widget_host.h" | 20 #include "content/public/browser/render_widget_host.h" |
| 21 #include "content/public/browser/render_widget_host_view.h" | 21 #include "content/public/browser/render_widget_host_view.h" |
| 22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/common/referrer.h" | 23 #include "content/public/common/referrer.h" |
| 24 #include "device/vr/android/gvr/gvr_device_provider.h" |
| 24 #include "jni/VrShellImpl_jni.h" | 25 #include "jni/VrShellImpl_jni.h" |
| 25 #include "ui/android/view_android.h" | 26 #include "ui/android/view_android.h" |
| 26 #include "ui/android/window_android.h" | 27 #include "ui/android/window_android.h" |
| 27 #include "ui/base/page_transition_types.h" | 28 #include "ui/base/page_transition_types.h" |
| 28 #include "ui/display/display.h" | 29 #include "ui/display/display.h" |
| 29 #include "ui/display/screen.h" | 30 #include "ui/display/screen.h" |
| 30 #include "ui/gl/gl_bindings.h" | 31 #include "ui/gl/gl_bindings.h" |
| 31 #include "ui/gl/init/gl_factory.h" | 32 #include "ui/gl/init/gl_factory.h" |
| 32 | 33 |
| 33 using base::android::JavaParamRef; | 34 using base::android::JavaParamRef; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 namespace vr_shell { | 131 namespace vr_shell { |
| 131 | 132 |
| 132 VrShell::VrShell(JNIEnv* env, jobject obj, | 133 VrShell::VrShell(JNIEnv* env, jobject obj, |
| 133 content::WebContents* main_contents, | 134 content::WebContents* main_contents, |
| 134 ui::WindowAndroid* content_window, | 135 ui::WindowAndroid* content_window, |
| 135 content::WebContents* ui_contents, | 136 content::WebContents* ui_contents, |
| 136 ui::WindowAndroid* ui_window) | 137 ui::WindowAndroid* ui_window) |
| 137 : WebContentsObserver(ui_contents), | 138 : WebContentsObserver(ui_contents), |
| 138 main_contents_(main_contents), | 139 main_contents_(main_contents), |
| 139 ui_contents_(ui_contents), | 140 ui_contents_(ui_contents), |
| 141 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 140 weak_ptr_factory_(this) { | 142 weak_ptr_factory_(this) { |
| 141 DCHECK(g_instance == nullptr); | 143 DCHECK(g_instance == nullptr); |
| 142 g_instance = this; | 144 g_instance = this; |
| 143 j_vr_shell_.Reset(env, obj); | 145 j_vr_shell_.Reset(env, obj); |
| 144 scene_.reset(new UiScene); | 146 scene_.reset(new UiScene); |
| 145 html_interface_.reset(new UiInterface); | 147 html_interface_.reset(new UiInterface); |
| 146 content_compositor_.reset(new VrCompositor(content_window, false)); | 148 content_compositor_.reset(new VrCompositor(content_window, false)); |
| 147 ui_compositor_.reset(new VrCompositor(ui_window, true)); | 149 ui_compositor_.reset(new VrCompositor(ui_window, true)); |
| 148 vr_web_contents_observer_.reset( | 150 vr_web_contents_observer_.reset( |
| 149 new VrWebContentsObserver(main_contents, html_interface_.get())); | 151 new VrWebContentsObserver(main_contents, html_interface_.get())); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 170 ui_contents_->GetController().LoadURL( | 172 ui_contents_->GetController().LoadURL( |
| 171 url, content::Referrer(), | 173 url, content::Referrer(), |
| 172 ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string("")); | 174 ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string("")); |
| 173 } | 175 } |
| 174 | 176 |
| 175 bool RegisterVrShell(JNIEnv* env) { | 177 bool RegisterVrShell(JNIEnv* env) { |
| 176 return RegisterNativesImpl(env); | 178 return RegisterNativesImpl(env); |
| 177 } | 179 } |
| 178 | 180 |
| 179 VrShell::~VrShell() { | 181 VrShell::~VrShell() { |
| 182 if (delegate_ && delegate_->GetDeviceProvider()) { |
| 183 delegate_->GetDeviceProvider()->OnGvrDelegateRemoved(); |
| 184 } |
| 180 g_instance = nullptr; | 185 g_instance = nullptr; |
| 181 gl::init::ClearGLBindings(); | 186 gl::init::ClearGLBindings(); |
| 182 } | 187 } |
| 183 | 188 |
| 184 void VrShell::SetDelegate(JNIEnv* env, | 189 void VrShell::SetDelegate(JNIEnv* env, |
| 185 const base::android::JavaParamRef<jobject>& obj, | 190 const base::android::JavaParamRef<jobject>& obj, |
| 186 const base::android::JavaParamRef<jobject>& delegate) { | 191 const base::android::JavaParamRef<jobject>& delegate) { |
| 187 delegate_ = VrShellDelegate::getNativeDelegate(env, delegate); | 192 base::AutoLock lock(gvr_init_lock_); |
| 193 delegate_ = VrShellDelegate::GetNativeDelegate(env, delegate); |
| 194 if (gvr_api_) { |
| 195 main_thread_task_runner_->PostTask( |
| 196 FROM_HERE, base::Bind(&device::GvrDeviceProvider::OnGvrDelegateReady, |
| 197 delegate_->GetDeviceProvider(), |
| 198 weak_ptr_factory_.GetWeakPtr())); |
| 199 } |
| 188 } | 200 } |
| 189 | 201 |
| 190 enum class ViewerType | 202 enum class ViewerType { |
| 191 { | |
| 192 UNKNOWN_TYPE = 0, | 203 UNKNOWN_TYPE = 0, |
| 193 CARDBOARD = 1, | 204 CARDBOARD = 1, |
| 194 DAYDREAM = 2, | 205 DAYDREAM = 2, |
| 195 VIEWER_TYPE_MAX, | 206 VIEWER_TYPE_MAX, |
| 196 }; | 207 }; |
| 197 | 208 |
| 198 void VrShell::GvrInit(JNIEnv* env, | 209 void VrShell::GvrInit(JNIEnv* env, |
| 199 const JavaParamRef<jobject>& obj, | 210 const JavaParamRef<jobject>& obj, |
| 200 jlong native_gvr_api) { | 211 jlong native_gvr_api) { |
| 212 base::AutoLock lock(gvr_init_lock_); |
| 201 gvr_api_ = | 213 gvr_api_ = |
| 202 gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(native_gvr_api)); | 214 gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(native_gvr_api)); |
| 203 | 215 |
| 204 if (delegate_) | 216 if (delegate_) { |
| 205 delegate_->OnVrShellReady(this); | 217 main_thread_task_runner_->PostTask( |
| 218 FROM_HERE, base::Bind(&device::GvrDeviceProvider::OnGvrDelegateReady, |
| 219 delegate_->GetDeviceProvider(), |
| 220 weak_ptr_factory_.GetWeakPtr())); |
| 221 } |
| 206 controller_.reset( | 222 controller_.reset( |
| 207 new VrController(reinterpret_cast<gvr_context*>(native_gvr_api))); | 223 new VrController(reinterpret_cast<gvr_context*>(native_gvr_api))); |
| 208 content_input_manager_ = new VrInputManager(main_contents_); | 224 content_input_manager_ = new VrInputManager(main_contents_); |
| 209 ui_input_manager_ = new VrInputManager(ui_contents_); | 225 ui_input_manager_ = new VrInputManager(ui_contents_); |
| 210 | 226 |
| 211 ViewerType viewerType; | 227 ViewerType viewerType; |
| 212 switch (gvr_api_->GetViewerType()) | 228 switch (gvr_api_->GetViewerType()) { |
| 213 { | |
| 214 case gvr::ViewerType::GVR_VIEWER_TYPE_DAYDREAM: | 229 case gvr::ViewerType::GVR_VIEWER_TYPE_DAYDREAM: |
| 215 viewerType = ViewerType::DAYDREAM; | 230 viewerType = ViewerType::DAYDREAM; |
| 216 break; | 231 break; |
| 217 case gvr::ViewerType::GVR_VIEWER_TYPE_CARDBOARD: | 232 case gvr::ViewerType::GVR_VIEWER_TYPE_CARDBOARD: |
| 218 viewerType = ViewerType::CARDBOARD; | 233 viewerType = ViewerType::CARDBOARD; |
| 219 break; | 234 break; |
| 220 default: | 235 default: |
| 221 NOTREACHED(); | 236 NOTREACHED(); |
| 222 viewerType = ViewerType::UNKNOWN_TYPE; | 237 viewerType = ViewerType::UNKNOWN_TYPE; |
| 223 break; | 238 break; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 new gvr::BufferViewport(gvr_api_->CreateBufferViewport())); | 280 new gvr::BufferViewport(gvr_api_->CreateBufferViewport())); |
| 266 buffer_viewport_list_->GetBufferViewport(GVR_RIGHT_EYE, | 281 buffer_viewport_list_->GetBufferViewport(GVR_RIGHT_EYE, |
| 267 headlocked_right_viewport_.get()); | 282 headlocked_right_viewport_.get()); |
| 268 headlocked_right_viewport_->SetSourceBufferIndex(kFrameHeadlockedBuffer); | 283 headlocked_right_viewport_->SetSourceBufferIndex(kFrameHeadlockedBuffer); |
| 269 headlocked_right_viewport_->SetReprojection(GVR_REPROJECTION_NONE); | 284 headlocked_right_viewport_->SetReprojection(GVR_REPROJECTION_NONE); |
| 270 } | 285 } |
| 271 | 286 |
| 272 void VrShell::UpdateController(const gvr::Vec3f& forward_vector) { | 287 void VrShell::UpdateController(const gvr::Vec3f& forward_vector) { |
| 273 controller_->UpdateState(); | 288 controller_->UpdateState(); |
| 274 | 289 |
| 290 #if defined(ENABLE_VR_SHELL) |
| 291 // Note that button up/down state is transient, so IsButtonUp only returns |
| 292 // true for a single frame (and we're guaranteed not to miss it). |
| 293 if (controller_->IsButtonUp( |
| 294 gvr::ControllerButton::GVR_CONTROLLER_BUTTON_APP)) { |
| 295 if (html_interface_->GetMode() == UiInterface::Mode::MENU) { |
| 296 // Temporary: Hit app button a second time to exit menu mode. |
| 297 if (webvr_mode_) { |
| 298 html_interface_->SetMode(UiInterface::Mode::WEB_VR); |
| 299 main_thread_task_runner_->PostTask( |
| 300 FROM_HERE, base::Bind(&device::GvrDeviceProvider::OnDisplayFocus, |
| 301 delegate_->GetDeviceProvider())); |
| 302 } else { |
| 303 html_interface_->SetMode(UiInterface::Mode::STANDARD); |
| 304 } |
| 305 } else { |
| 306 if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) { |
| 307 main_thread_task_runner_->PostTask( |
| 308 FROM_HERE, base::Bind(&device::GvrDeviceProvider::OnDisplayBlur, |
| 309 delegate_->GetDeviceProvider())); |
| 310 } |
| 311 html_interface_->SetMode(UiInterface::Mode::MENU); |
| 312 // TODO(mthiesse): The page is no longer visible here. We should unfocus |
| 313 // or otherwise let it know it's hidden. |
| 314 } |
| 315 } |
| 316 #endif |
| 317 if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) { |
| 318 return; |
| 319 } |
| 320 |
| 275 gvr::Vec3f ergo_neutral_pose; | 321 gvr::Vec3f ergo_neutral_pose; |
| 276 if (!controller_->IsConnected()) { | 322 if (!controller_->IsConnected()) { |
| 277 // No controller detected, set up a gaze cursor that tracks the | 323 // No controller detected, set up a gaze cursor that tracks the |
| 278 // forward direction. | 324 // forward direction. |
| 279 ergo_neutral_pose = {0.0f, 0.0f, -1.0f}; | 325 ergo_neutral_pose = {0.0f, 0.0f, -1.0f}; |
| 280 controller_quat_ = GetRotationFromZAxis(forward_vector); | 326 controller_quat_ = GetRotationFromZAxis(forward_vector); |
| 281 } else { | 327 } else { |
| 282 ergo_neutral_pose = {0.0f, -sin(kErgoAngleOffset), -cos(kErgoAngleOffset)}; | 328 ergo_neutral_pose = {0.0f, -sin(kErgoAngleOffset), -cos(kErgoAngleOffset)}; |
| 283 controller_quat_ = controller_->Orientation(); | 329 controller_quat_ = controller_->Orientation(); |
| 284 } | 330 } |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 void VrShell::SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) { | 468 void VrShell::SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) { |
| 423 webvr_head_pose_[pose_num % kPoseRingBufferSize] = pose; | 469 webvr_head_pose_[pose_num % kPoseRingBufferSize] = pose; |
| 424 } | 470 } |
| 425 | 471 |
| 426 uint32_t GetPixelEncodedPoseIndex() { | 472 uint32_t GetPixelEncodedPoseIndex() { |
| 427 // Read the pose index encoded in a bottom left pixel as color values. | 473 // Read the pose index encoded in a bottom left pixel as color values. |
| 428 // See also third_party/WebKit/Source/modules/vr/VRDisplay.cpp which | 474 // See also third_party/WebKit/Source/modules/vr/VRDisplay.cpp which |
| 429 // encodes the pose index, and device/vr/android/gvr/gvr_device.cc | 475 // encodes the pose index, and device/vr/android/gvr/gvr_device.cc |
| 430 // which tracks poses. | 476 // which tracks poses. |
| 431 uint8_t pixels[4]; | 477 uint8_t pixels[4]; |
| 432 // Assume we're reading from the frambebuffer we just wrote to. | 478 // Assume we're reading from the framebuffer we just wrote to. |
| 433 // That's true currently, we may need to use glReadBuffer(GL_BACK) | 479 // That's true currently, we may need to use glReadBuffer(GL_BACK) |
| 434 // or equivalent if the rendering setup changes in the future. | 480 // or equivalent if the rendering setup changes in the future. |
| 435 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); | 481 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 436 return pixels[0] | (pixels[1] << 8) | (pixels[2] << 16); | 482 return pixels[0] | (pixels[1] << 8) | (pixels[2] << 16); |
| 437 } | 483 } |
| 438 | 484 |
| 439 void VrShell::DrawFrame(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 485 void VrShell::DrawFrame(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 440 buffer_viewport_list_->SetToRecommendedBufferViewports(); | 486 buffer_viewport_list_->SetToRecommendedBufferViewports(); |
| 441 | 487 |
| 442 gvr::Frame frame = swap_chain_->AcquireFrame(); | 488 gvr::Frame frame = swap_chain_->AcquireFrame(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 460 frame.BindBuffer(kFramePrimaryBuffer); | 506 frame.BindBuffer(kFramePrimaryBuffer); |
| 461 | 507 |
| 462 HandleQueuedTasks(); | 508 HandleQueuedTasks(); |
| 463 | 509 |
| 464 // Update the render position of all UI elements (including desktop). | 510 // Update the render position of all UI elements (including desktop). |
| 465 const float screen_tilt = kDesktopScreenTiltDefault * M_PI / 180.0f; | 511 const float screen_tilt = kDesktopScreenTiltDefault * M_PI / 180.0f; |
| 466 scene_->UpdateTransforms(screen_tilt, UiScene::TimeInMicroseconds()); | 512 scene_->UpdateTransforms(screen_tilt, UiScene::TimeInMicroseconds()); |
| 467 | 513 |
| 468 UpdateController(GetForwardVector(head_pose)); | 514 UpdateController(GetForwardVector(head_pose)); |
| 469 | 515 |
| 470 if (webvr_mode_) { | 516 if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) { |
| 471 DrawWebVr(); | 517 DrawWebVr(); |
| 472 | 518 |
| 473 // When using async reprojection, we need to know which pose was used in | 519 // When using async reprojection, we need to know which pose was used in |
| 474 // the WebVR app for drawing this frame. Due to unknown amounts of | 520 // the WebVR app for drawing this frame. Due to unknown amounts of |
| 475 // buffering in the compositor and SurfaceTexture, we read the pose number | 521 // buffering in the compositor and SurfaceTexture, we read the pose number |
| 476 // from a corner pixel. There's no point in doing this for legacy | 522 // from a corner pixel. There's no point in doing this for legacy |
| 477 // distortion rendering since that doesn't need a pose, and reading back | 523 // distortion rendering since that doesn't need a pose, and reading back |
| 478 // pixels is an expensive operation. TODO(klausw): stop doing this once we | 524 // pixels is an expensive operation. TODO(klausw): stop doing this once we |
| 479 // have working no-compositor rendering for WebVR. | 525 // have working no-compositor rendering for WebVR. |
| 480 if (gvr_api_->GetAsyncReprojectionEnabled()) { | 526 if (gvr_api_->GetAsyncReprojectionEnabled()) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 497 if (!rect->visible) { | 543 if (!rect->visible) { |
| 498 continue; | 544 continue; |
| 499 } | 545 } |
| 500 if (rect->lock_to_fov) { | 546 if (rect->lock_to_fov) { |
| 501 head_locked_elements.push_back(rect.get()); | 547 head_locked_elements.push_back(rect.get()); |
| 502 } else { | 548 } else { |
| 503 world_elements.push_back(rect.get()); | 549 world_elements.push_back(rect.get()); |
| 504 } | 550 } |
| 505 } | 551 } |
| 506 | 552 |
| 507 if (!webvr_mode_) { | 553 bool not_web_vr = html_interface_->GetMode() != UiInterface::Mode::WEB_VR; |
| 554 |
| 555 if (not_web_vr) { |
| 508 glEnable(GL_CULL_FACE); | 556 glEnable(GL_CULL_FACE); |
| 509 glEnable(GL_DEPTH_TEST); | 557 glEnable(GL_DEPTH_TEST); |
| 510 glEnable(GL_SCISSOR_TEST); | 558 glEnable(GL_SCISSOR_TEST); |
| 511 glClearColor(0.1f, 0.1f, 0.1f, 1.0f); | 559 glClearColor(0.1f, 0.1f, 0.1f, 1.0f); |
| 512 } | 560 } |
| 513 | 561 |
| 514 if (!world_elements.empty()) { | 562 DrawUiView(&head_pose, world_elements, not_web_vr); |
| 515 DrawUiView(&head_pose, world_elements); | |
| 516 } | |
| 517 | 563 |
| 518 if (!head_locked_elements.empty()) { | 564 if (!head_locked_elements.empty()) { |
| 519 // Switch to head-locked viewports. | 565 // Switch to head-locked viewports. |
| 520 size_t last_viewport = buffer_viewport_list_->GetSize(); | 566 size_t last_viewport = buffer_viewport_list_->GetSize(); |
| 521 buffer_viewport_list_->SetBufferViewport(last_viewport++, | 567 buffer_viewport_list_->SetBufferViewport(last_viewport++, |
| 522 *headlocked_left_viewport_); | 568 *headlocked_left_viewport_); |
| 523 buffer_viewport_list_->SetBufferViewport(last_viewport++, | 569 buffer_viewport_list_->SetBufferViewport(last_viewport++, |
| 524 *headlocked_right_viewport_); | 570 *headlocked_right_viewport_); |
| 525 | 571 |
| 526 // Bind the headlocked framebuffer. | 572 // Bind the headlocked framebuffer. |
| 527 frame.BindBuffer(kFrameHeadlockedBuffer); | 573 frame.BindBuffer(kFrameHeadlockedBuffer); |
| 528 glClear(GL_COLOR_BUFFER_BIT); | 574 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 529 | 575 DrawUiView(nullptr, head_locked_elements, true); |
| 530 DrawUiView(nullptr, head_locked_elements); | |
| 531 } | 576 } |
| 532 } | 577 } |
| 533 | 578 |
| 534 void VrShell::DrawUiView(const gvr::Mat4f* head_pose, | 579 void VrShell::DrawUiView(const gvr::Mat4f* head_pose, |
| 535 const std::vector<const ContentRectangle*>& elements) { | 580 const std::vector<const ContentRectangle*>& elements, |
| 581 bool clear) { |
| 536 for (auto eye : {GVR_LEFT_EYE, GVR_RIGHT_EYE}) { | 582 for (auto eye : {GVR_LEFT_EYE, GVR_RIGHT_EYE}) { |
| 537 buffer_viewport_list_->GetBufferViewport(eye, buffer_viewport_.get()); | 583 buffer_viewport_list_->GetBufferViewport(eye, buffer_viewport_.get()); |
| 538 | 584 |
| 539 gvr::Mat4f view_matrix = gvr_api_->GetEyeFromHeadMatrix(eye); | 585 gvr::Mat4f view_matrix = gvr_api_->GetEyeFromHeadMatrix(eye); |
| 540 if (head_pose != nullptr) { | 586 if (head_pose != nullptr) { |
| 541 view_matrix = MatrixMul(view_matrix, *head_pose); | 587 view_matrix = MatrixMul(view_matrix, *head_pose); |
| 542 } | 588 } |
| 543 | 589 |
| 544 gvr::Recti pixel_rect = | 590 gvr::Recti pixel_rect = |
| 545 CalculatePixelSpaceRect(render_size_, buffer_viewport_->GetSourceUv()); | 591 CalculatePixelSpaceRect(render_size_, buffer_viewport_->GetSourceUv()); |
| 546 glViewport(pixel_rect.left, pixel_rect.bottom, | 592 glViewport(pixel_rect.left, pixel_rect.bottom, |
| 547 pixel_rect.right - pixel_rect.left, | 593 pixel_rect.right - pixel_rect.left, |
| 548 pixel_rect.top - pixel_rect.bottom); | 594 pixel_rect.top - pixel_rect.bottom); |
| 549 glScissor(pixel_rect.left, pixel_rect.bottom, | 595 glScissor(pixel_rect.left, pixel_rect.bottom, |
| 550 pixel_rect.right - pixel_rect.left, | 596 pixel_rect.right - pixel_rect.left, |
| 551 pixel_rect.top - pixel_rect.bottom); | 597 pixel_rect.top - pixel_rect.bottom); |
| 552 | 598 |
| 553 if (!webvr_mode_) { | 599 if (clear) { |
| 554 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | 600 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 555 } | 601 } |
| 556 | 602 |
| 557 const gvr::Mat4f render_matrix = MatrixMul( | 603 const gvr::Mat4f render_matrix = MatrixMul( |
| 558 PerspectiveMatrixFromView( | 604 PerspectiveMatrixFromView( |
| 559 buffer_viewport_->GetSourceFov(), kZNear, kZFar), | 605 buffer_viewport_->GetSourceFov(), kZNear, kZFar), |
| 560 view_matrix); | 606 view_matrix); |
| 561 | 607 |
| 562 DrawElements(render_matrix, elements); | 608 DrawElements(render_matrix, elements); |
| 563 if (head_pose != nullptr) { | 609 if (head_pose != nullptr && |
| 610 html_interface_->GetMode() != UiInterface::Mode::WEB_VR) { |
| 564 DrawCursor(render_matrix); | 611 DrawCursor(render_matrix); |
| 565 } | 612 } |
| 566 } | 613 } |
| 567 } | 614 } |
| 568 | 615 |
| 569 void VrShell::DrawElements( | 616 void VrShell::DrawElements( |
| 570 const gvr::Mat4f& render_matrix, | 617 const gvr::Mat4f& render_matrix, |
| 571 const std::vector<const ContentRectangle*>& elements) { | 618 const std::vector<const ContentRectangle*>& elements) { |
| 572 for (const auto& rect : elements) { | 619 for (const auto& rect : elements) { |
| 573 Rectf copy_rect; | 620 Rectf copy_rect; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 | 713 |
| 667 void VrShell::DrawWebVr() { | 714 void VrShell::DrawWebVr() { |
| 668 // Don't need face culling, depth testing, blending, etc. Turn it all off. | 715 // Don't need face culling, depth testing, blending, etc. Turn it all off. |
| 669 glDisable(GL_CULL_FACE); | 716 glDisable(GL_CULL_FACE); |
| 670 glDepthMask(GL_FALSE); | 717 glDepthMask(GL_FALSE); |
| 671 glDisable(GL_DEPTH_TEST); | 718 glDisable(GL_DEPTH_TEST); |
| 672 glDisable(GL_SCISSOR_TEST); | 719 glDisable(GL_SCISSOR_TEST); |
| 673 glDisable(GL_BLEND); | 720 glDisable(GL_BLEND); |
| 674 glDisable(GL_POLYGON_OFFSET_FILL); | 721 glDisable(GL_POLYGON_OFFSET_FILL); |
| 675 | 722 |
| 676 // Don't need to clear, since we're drawing over the entire render target. | |
| 677 glClear(GL_COLOR_BUFFER_BIT); | |
| 678 | |
| 679 glViewport(0, 0, render_size_.width, render_size_.height); | 723 glViewport(0, 0, render_size_.width, render_size_.height); |
| 680 vr_shell_renderer_->GetWebVrRenderer()->Draw(content_texture_id_); | 724 vr_shell_renderer_->GetWebVrRenderer()->Draw(content_texture_id_); |
| 681 } | 725 } |
| 682 | 726 |
| 683 void VrShell::OnTriggerEvent(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 727 void VrShell::OnTriggerEvent(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 684 // Set a flag to handle this on the render thread at the next frame. | 728 // Set a flag to handle this on the render thread at the next frame. |
| 685 touch_pending_ = true; | 729 touch_pending_ = true; |
| 686 } | 730 } |
| 687 | 731 |
| 688 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 732 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 const JavaParamRef<jobject>& ui_web_contents, | 888 const JavaParamRef<jobject>& ui_web_contents, |
| 845 jlong ui_window_android) { | 889 jlong ui_window_android) { |
| 846 return reinterpret_cast<intptr_t>(new VrShell( | 890 return reinterpret_cast<intptr_t>(new VrShell( |
| 847 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), | 891 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), |
| 848 reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 892 reinterpret_cast<ui::WindowAndroid*>(content_window_android), |
| 849 content::WebContents::FromJavaWebContents(ui_web_contents), | 893 content::WebContents::FromJavaWebContents(ui_web_contents), |
| 850 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); | 894 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); |
| 851 } | 895 } |
| 852 | 896 |
| 853 } // namespace vr_shell | 897 } // namespace vr_shell |
| OLD | NEW |