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