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 <thread> | 7 #include <thread> |
8 | 8 |
9 #include "chrome/browser/android/vr_shell/ui_scene.h" | 9 #include "chrome/browser/android/vr_shell/ui_scene.h" |
10 #include "chrome/browser/android/vr_shell/vr_compositor.h" | 10 #include "chrome/browser/android/vr_shell/vr_compositor.h" |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 gvr::Frame frame = swap_chain_->AcquireFrame(); | 219 gvr::Frame frame = swap_chain_->AcquireFrame(); |
220 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); | 220 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); |
221 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; | 221 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; |
222 head_pose_ = gvr_api_->GetHeadPoseInStartSpace(target_time); | 222 head_pose_ = gvr_api_->GetHeadPoseInStartSpace(target_time); |
223 | 223 |
224 // Bind back to the default framebuffer. | 224 // Bind back to the default framebuffer. |
225 frame.BindBuffer(0); | 225 frame.BindBuffer(0); |
226 | 226 |
227 if (webvr_mode_) { | 227 if (webvr_mode_) { |
228 DrawWebVr(); | 228 DrawWebVr(); |
229 if (!webvr_secure_origin_) { | |
230 DrawWebVrOverlay(); | |
231 } | |
229 } else { | 232 } else { |
230 DrawVrShell(target_time.monotonic_system_time_nanos); | 233 DrawVrShell(target_time.monotonic_system_time_nanos); |
231 } | 234 } |
232 | 235 |
233 frame.Unbind(); | 236 frame.Unbind(); |
234 frame.Submit(*buffer_viewport_list_, head_pose_); | 237 frame.Submit(*buffer_viewport_list_, head_pose_); |
235 } | 238 } |
236 | 239 |
237 void VrShell::DrawVrShell(int64_t time) { | 240 void VrShell::DrawVrShell(int64_t time) { |
238 float screen_tilt = desktop_screen_tilt_ * M_PI / 180.0f; | 241 float screen_tilt = desktop_screen_tilt_ * M_PI / 180.0f; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 glDepthMask(GL_FALSE); | 384 glDepthMask(GL_FALSE); |
382 glDisable(GL_DEPTH_TEST); | 385 glDisable(GL_DEPTH_TEST); |
383 glDisable(GL_SCISSOR_TEST); | 386 glDisable(GL_SCISSOR_TEST); |
384 glDisable(GL_BLEND); | 387 glDisable(GL_BLEND); |
385 glDisable(GL_POLYGON_OFFSET_FILL); | 388 glDisable(GL_POLYGON_OFFSET_FILL); |
386 | 389 |
387 // Don't need to clear, since we're drawing over the entire render target. | 390 // Don't need to clear, since we're drawing over the entire render target. |
388 | 391 |
389 glViewport(0, 0, render_size_.width, render_size_.height); | 392 glViewport(0, 0, render_size_.width, render_size_.height); |
390 vr_shell_renderer_->GetWebVrRenderer()->Draw(content_texture_id_); | 393 vr_shell_renderer_->GetWebVrRenderer()->Draw(content_texture_id_); |
394 } | |
391 | 395 |
392 if (!webvr_secure_origin_) { | 396 void VrShell::DrawWebVrOverlay() { |
393 // TODO(klausw): Draw the insecure origin warning here. | 397 // Draw WebVR security warning overlays for each eye. This uses |
398 // the eye-from-head matrices but not the pose, goal is to place | |
399 // the icons in an eye-relative position so that they follow along | |
400 // with head rotations. | |
401 | |
402 gvr::Mat4f left_eye_view_matrix = | |
403 gvr_api_->GetEyeFromHeadMatrix(GVR_LEFT_EYE); | |
404 gvr::Mat4f right_eye_view_matrix = | |
405 gvr_api_->GetEyeFromHeadMatrix(GVR_RIGHT_EYE); | |
406 | |
407 buffer_viewport_list_->GetBufferViewport(GVR_LEFT_EYE, | |
408 buffer_viewport_.get()); | |
409 DrawWebVrEye(left_eye_view_matrix, *buffer_viewport_); | |
410 buffer_viewport_list_->GetBufferViewport(GVR_RIGHT_EYE, | |
411 buffer_viewport_.get()); | |
412 DrawWebVrEye(right_eye_view_matrix, *buffer_viewport_); | |
413 } | |
414 | |
415 void VrShell::DrawWebVrEye(const gvr::Mat4f& view_matrix, | |
416 const gvr::BufferViewport& params) { | |
417 gvr::Recti pixel_rect = | |
418 CalculatePixelSpaceRect(render_size_, params.GetSourceUv()); | |
419 glViewport(pixel_rect.left, pixel_rect.bottom, | |
420 pixel_rect.right - pixel_rect.left, | |
421 pixel_rect.top - pixel_rect.bottom); | |
422 glScissor(pixel_rect.left, pixel_rect.bottom, | |
423 pixel_rect.right - pixel_rect.left, | |
424 pixel_rect.top - pixel_rect.bottom); | |
425 | |
426 gvr::Mat4f projection_matrix = | |
427 PerspectiveMatrixFromView(params.GetSourceFov(), kZNear, kZFar); | |
428 | |
429 // Draw insecure content warning icons. | |
430 const float warning_depth = 0.7f; // Distance in meters. | |
431 | |
432 // Show IDS_WEBSITE_SETTINGS_INSECURE_WEBVR_CONTENT_PERMANENT text. | |
433 gvr::Mat4f icon_pos; | |
434 SetIdentityM(icon_pos); | |
435 const float small_icon_width = 0.15f * warning_depth; | |
436 const float small_icon_height = small_icon_width / 2.0f; // 2:1 aspect. | |
437 const float small_icon_angle = 20.0f * M_PI / 180.f; // Degrees to radians. | |
438 ScaleM(icon_pos, icon_pos, small_icon_width, small_icon_height, 1.0f); | |
439 TranslateM(icon_pos, icon_pos, 0.0f, 0.0f, -warning_depth); | |
440 icon_pos = MatrixMul( | |
441 QuatToMatrix(QuatFromAxisAngle(1.f, 0.f, 0.f, small_icon_angle)), | |
442 icon_pos); | |
443 gvr::Mat4f combined = MatrixMul(projection_matrix, | |
444 MatrixMul(view_matrix, icon_pos)); | |
445 vr_shell_renderer_->GetOverlayIconRenderer()->Draw( | |
446 combined, ICON_INSECURE_PERMANENT); | |
447 | |
448 // Do we need to show the transient warning also? | |
449 if (webvr_warning_frames_ == 0) { | |
450 return; | |
394 } | 451 } |
452 --webvr_warning_frames_; | |
453 | |
454 // Show IDS_WEBSITE_SETTINGS_INSECURE_WEBVR_CONTENT_TRANSIENT text. | |
455 SetIdentityM(icon_pos); | |
456 const float large_icon_width = 0.25f * warning_depth; | |
457 const float large_icon_height = large_icon_width / 2.0f; // 2:1 aspect. | |
458 ScaleM(icon_pos, icon_pos, large_icon_width, large_icon_height, 1.0f); | |
459 TranslateM(icon_pos, icon_pos, 0.0f, 0.0f, -warning_depth); | |
460 combined = MatrixMul(projection_matrix, | |
461 MatrixMul(view_matrix, icon_pos)); | |
462 vr_shell_renderer_->GetOverlayIconRenderer()->Draw( | |
463 combined, ICON_INSECURE_TRANSIENT); | |
395 } | 464 } |
396 | 465 |
397 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 466 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
398 if (gvr_api_ == nullptr) | 467 if (gvr_api_ == nullptr) |
399 return; | 468 return; |
400 gvr_api_->PauseTracking(); | 469 gvr_api_->PauseTracking(); |
401 } | 470 } |
402 | 471 |
403 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 472 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
404 if (gvr_api_ == nullptr) | 473 if (gvr_api_ == nullptr) |
(...skipping 18 matching lines...) Expand all Loading... | |
423 // TODO(bshe): ui_text_width_ and ui_tex_height_ should be only used on render | 492 // TODO(bshe): ui_text_width_ and ui_tex_height_ should be only used on render |
424 // thread. | 493 // thread. |
425 ui_tex_width_ = width; | 494 ui_tex_width_ = width; |
426 ui_tex_height_ = height; | 495 ui_tex_height_ = height; |
427 } | 496 } |
428 | 497 |
429 void VrShell::SetWebVrMode(JNIEnv* env, | 498 void VrShell::SetWebVrMode(JNIEnv* env, |
430 const base::android::JavaParamRef<jobject>& obj, | 499 const base::android::JavaParamRef<jobject>& obj, |
431 bool enabled) { | 500 bool enabled) { |
432 webvr_mode_ = enabled; | 501 webvr_mode_ = enabled; |
502 if (enabled) { | |
503 const int warning_seconds = 30; | |
504 webvr_warning_frames_ = warning_seconds * 60; | |
billorr
2016/09/23 17:52:11
how often do we miss frames? can we keep the warn
| |
505 } else { | |
506 webvr_warning_frames_ = 0; | |
507 } | |
433 } | 508 } |
434 | 509 |
435 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { | 510 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { |
436 webvr_secure_origin_ = secure_origin; | 511 webvr_secure_origin_ = secure_origin; |
437 } | 512 } |
438 | 513 |
439 void VrShell::SubmitWebVRFrame() { | 514 void VrShell::SubmitWebVRFrame() { |
440 } | 515 } |
441 | 516 |
442 void VrShell::UpdateWebVRTextureBounds( | 517 void VrShell::UpdateWebVRTextureBounds( |
(...skipping 28 matching lines...) Expand all Loading... | |
471 const JavaParamRef<jobject>& content_web_contents, | 546 const JavaParamRef<jobject>& content_web_contents, |
472 jlong content_window_android) { | 547 jlong content_window_android) { |
473 content::ContentViewCore* c_core = content::ContentViewCore::FromWebContents( | 548 content::ContentViewCore* c_core = content::ContentViewCore::FromWebContents( |
474 content::WebContents::FromJavaWebContents(content_web_contents)); | 549 content::WebContents::FromJavaWebContents(content_web_contents)); |
475 return reinterpret_cast<intptr_t>(new VrShell( | 550 return reinterpret_cast<intptr_t>(new VrShell( |
476 env, obj, c_core, | 551 env, obj, c_core, |
477 reinterpret_cast<ui::WindowAndroid*>(content_window_android))); | 552 reinterpret_cast<ui::WindowAndroid*>(content_window_android))); |
478 } | 553 } |
479 | 554 |
480 } // namespace vr_shell | 555 } // namespace vr_shell |
OLD | NEW |