Chromium Code Reviews| 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_gl.h" | 5 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" |
| 6 | 6 |
| 7 #include <chrono> | 7 #include <chrono> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
| 12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "cc/trees/frame_rate_counter.h" | |
| 16 #include "chrome/browser/android/vr_shell/mailbox_to_surface_bridge.h" | 17 #include "chrome/browser/android/vr_shell/mailbox_to_surface_bridge.h" |
| 17 #include "chrome/browser/android/vr_shell/ui_elements.h" | 18 #include "chrome/browser/android/vr_shell/ui_elements.h" |
| 18 #include "chrome/browser/android/vr_shell/ui_interface.h" | 19 #include "chrome/browser/android/vr_shell/ui_interface.h" |
| 19 #include "chrome/browser/android/vr_shell/ui_scene.h" | 20 #include "chrome/browser/android/vr_shell/ui_scene.h" |
| 20 #include "chrome/browser/android/vr_shell/vr_controller.h" | 21 #include "chrome/browser/android/vr_shell/vr_controller.h" |
| 21 #include "chrome/browser/android/vr_shell/vr_gl_util.h" | 22 #include "chrome/browser/android/vr_shell/vr_gl_util.h" |
| 22 #include "chrome/browser/android/vr_shell/vr_math.h" | 23 #include "chrome/browser/android/vr_shell/vr_math.h" |
| 23 #include "chrome/browser/android/vr_shell/vr_shell.h" | 24 #include "chrome/browser/android/vr_shell/vr_shell.h" |
| 24 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" | 25 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" |
| 25 #include "device/vr/android/gvr/gvr_delegate.h" | 26 #include "device/vr/android/gvr/gvr_delegate.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 static constexpr int kViewportListHeadlockedOffset = 2; | 78 static constexpr int kViewportListHeadlockedOffset = 2; |
| 78 | 79 |
| 79 // Buffer size large enough to handle the current backlog of poses which is | 80 // Buffer size large enough to handle the current backlog of poses which is |
| 80 // 2-3 frames. | 81 // 2-3 frames. |
| 81 static constexpr unsigned kPoseRingBufferSize = 8; | 82 static constexpr unsigned kPoseRingBufferSize = 8; |
| 82 | 83 |
| 83 // Criteria for considering holding the app button in combination with | 84 // Criteria for considering holding the app button in combination with |
| 84 // controller movement as a gesture. | 85 // controller movement as a gesture. |
| 85 static constexpr float kMinAppButtonGestureAngleRad = 0.25; | 86 static constexpr float kMinAppButtonGestureAngleRad = 0.25; |
| 86 | 87 |
| 88 // UI has no "impl" (i.e., separate compositor) thread. | |
| 89 static constexpr bool kHasImplThread = false; | |
| 90 | |
| 87 // Generate a quaternion representing the rotation from the negative Z axis | 91 // Generate a quaternion representing the rotation from the negative Z axis |
| 88 // (0, 0, -1) to a specified vector. This is an optimized version of a more | 92 // (0, 0, -1) to a specified vector. This is an optimized version of a more |
| 89 // general vector-to-vector calculation. | 93 // general vector-to-vector calculation. |
| 90 gvr::Quatf GetRotationFromZAxis(gvr::Vec3f vec) { | 94 gvr::Quatf GetRotationFromZAxis(gvr::Vec3f vec) { |
| 91 vr_shell::NormalizeVector(vec); | 95 vr_shell::NormalizeVector(vec); |
| 92 gvr::Quatf quat; | 96 gvr::Quatf quat; |
| 93 quat.qw = 1.0f - vec.z; | 97 quat.qw = 1.0f - vec.z; |
| 94 if (quat.qw < 1e-6f) { | 98 if (quat.qw < 1e-6f) { |
| 95 // Degenerate case: vectors are exactly opposite. Replace by an | 99 // Degenerate case: vectors are exactly opposite. Replace by an |
| 96 // arbitrary 180 degree rotation to avoid invalid normalization. | 100 // arbitrary 180 degree rotation to avoid invalid normalization. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, | 144 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, |
| 141 gvr_context* gvr_api, | 145 gvr_context* gvr_api, |
| 142 bool initially_web_vr, | 146 bool initially_web_vr, |
| 143 bool reprojected_rendering) | 147 bool reprojected_rendering) |
| 144 : web_vr_mode_(initially_web_vr), | 148 : web_vr_mode_(initially_web_vr), |
| 145 surfaceless_rendering_(reprojected_rendering), | 149 surfaceless_rendering_(reprojected_rendering), |
| 146 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 150 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 147 binding_(this), | 151 binding_(this), |
| 148 weak_vr_shell_(weak_vr_shell), | 152 weak_vr_shell_(weak_vr_shell), |
| 149 main_thread_task_runner_(std::move(main_thread_task_runner)), | 153 main_thread_task_runner_(std::move(main_thread_task_runner)), |
| 154 frame_rate_counter_(cc::FrameRateCounter::Create(kHasImplThread)), | |
| 150 weak_ptr_factory_(this) { | 155 weak_ptr_factory_(this) { |
| 151 GvrInit(gvr_api); | 156 GvrInit(gvr_api); |
| 152 } | 157 } |
| 153 | 158 |
| 154 VrShellGl::~VrShellGl() { | 159 VrShellGl::~VrShellGl() { |
| 155 vsync_task_.Cancel(); | 160 vsync_task_.Cancel(); |
| 156 // TODO(mthiesse): Can we omit the Close() here? Concern is that if | 161 // TODO(mthiesse): Can we omit the Close() here? Concern is that if |
| 157 // both ends of the connection ever live in the same process for | 162 // both ends of the connection ever live in the same process for |
| 158 // some reason, we could receive another VSync request in response | 163 // some reason, we could receive another VSync request in response |
| 159 // to the closing message in the destructor but fail to respond to | 164 // to the closing message in the destructor but fail to respond to |
| (...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 829 TRACE_EVENT0("gpu", "VrShellGl::Submit"); | 834 TRACE_EVENT0("gpu", "VrShellGl::Submit"); |
| 830 frame.Submit(*buffer_viewport_list_, head_pose); | 835 frame.Submit(*buffer_viewport_list_, head_pose); |
| 831 } | 836 } |
| 832 | 837 |
| 833 // No need to swap buffers for surfaceless rendering. | 838 // No need to swap buffers for surfaceless rendering. |
| 834 if (!surfaceless_rendering_) { | 839 if (!surfaceless_rendering_) { |
| 835 // TODO(mthiesse): Support asynchronous SwapBuffers. | 840 // TODO(mthiesse): Support asynchronous SwapBuffers. |
| 836 TRACE_EVENT0("gpu", "VrShellGl::SwapBuffers"); | 841 TRACE_EVENT0("gpu", "VrShellGl::SwapBuffers"); |
| 837 surface_->SwapBuffers(); | 842 surface_->SwapBuffers(); |
| 838 } | 843 } |
| 844 | |
| 845 // This is an unused parameter when we do not have a compositor thread. | |
| 846 bool unused_is_a_software_compositor = false; | |
| 847 | |
| 848 // After saving the timestamp, a reliable framerate should be available via | |
| 849 // GetAverageFPS(). | |
| 850 // TODO(vollick): enable rendering of this framerate in a HUD. | |
| 851 frame_rate_counter_->SaveTimeStamp(current_time, | |
|
mthiesse
2017/04/07 15:36:33
I know this is fairly lightweight, but we should p
| |
| 852 unused_is_a_software_compositor); | |
|
mthiesse
2017/04/07 15:36:33
nit: Definitely personal preference, but I think t
| |
| 839 } | 853 } |
| 840 | 854 |
| 841 void VrShellGl::DrawWorldElements(const gvr::Mat4f& head_pose) { | 855 void VrShellGl::DrawWorldElements(const gvr::Mat4f& head_pose) { |
| 842 TRACE_EVENT0("gpu", "VrShellGl::DrawWorldElements"); | 856 TRACE_EVENT0("gpu", "VrShellGl::DrawWorldElements"); |
| 843 | 857 |
| 844 if (ShouldDrawWebVr()) { | 858 if (ShouldDrawWebVr()) { |
| 845 // WebVR is incompatible with 3D world compositing since the | 859 // WebVR is incompatible with 3D world compositing since the |
| 846 // depth buffer was already populated with unknown scaling - the | 860 // depth buffer was already populated with unknown scaling - the |
| 847 // WebVR app has full control over zNear/zFar. Just leave the | 861 // WebVR app has full control over zNear/zFar. Just leave the |
| 848 // existing content in place in the primary buffer without | 862 // existing content in place in the primary buffer without |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1276 // InitializeGl. Revisit if the initialization order changes. | 1290 // InitializeGl. Revisit if the initialization order changes. |
| 1277 device::mojom::VRDisplayInfoPtr info = | 1291 device::mojom::VRDisplayInfoPtr info = |
| 1278 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), | 1292 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), |
| 1279 webvr_surface_size_, device_id); | 1293 webvr_surface_size_, device_id); |
| 1280 main_thread_task_runner_->PostTask( | 1294 main_thread_task_runner_->PostTask( |
| 1281 FROM_HERE, | 1295 FROM_HERE, |
| 1282 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); | 1296 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); |
| 1283 } | 1297 } |
| 1284 | 1298 |
| 1285 } // namespace vr_shell | 1299 } // namespace vr_shell |
| OLD | NEW |