Chromium Code Reviews| Index: chrome/browser/android/vr_shell/vr_shell_gl.cc |
| diff --git a/chrome/browser/android/vr_shell/vr_shell_gl.cc b/chrome/browser/android/vr_shell/vr_shell_gl.cc |
| index fa661b91ab0d9c2e56d4aac07beda06bd65507fe..b98da29058a14aa6260485b3346d0cd4f79c9bd7 100644 |
| --- a/chrome/browser/android/vr_shell/vr_shell_gl.cc |
| +++ b/chrome/browser/android/vr_shell/vr_shell_gl.cc |
| @@ -475,7 +475,7 @@ void VrShellGl::InitializeRenderer() { |
| void VrShellGl::UpdateController(const gvr::Vec3f& forward_vector) { |
| controller_->UpdateState(); |
| - if (web_vr_mode_) { |
| + if (ShouldDrawWebVr()) { |
| // Process screen touch events for Cardboard button compatibility. |
| // Also send tap events for controller "touchpad click" events. |
| if (touch_pending_ || |
| @@ -717,9 +717,10 @@ void VrShellGl::DrawFrame(int16_t frame_index) { |
| // If needed, resize the primary buffer for use with WebVR. Resizing |
| // needs to happen before acquiring a frame. |
| - if (web_vr_mode_) { |
| + if (ShouldDrawWebVr()) { |
| // Process all pending_bounds_ changes targeted for before this |
| // frame, being careful of wrapping frame indices. |
| + // TODO(crbug.com/680253): Do not compare the constants on every frame. |
|
mthiesse
2017/03/20 17:32:16
Note that this is a static assert and is checked b
cjgrant
2017/03/20 17:57:22
Done. Sweet, I learned something cool today!
|
| static constexpr unsigned max = |
| std::numeric_limits<decltype(frame_index_)>::max(); |
| static_assert(max > kPoseRingBufferSize * 2, |
| @@ -779,7 +780,7 @@ void VrShellGl::DrawFrame(int16_t frame_index) { |
| } |
| frame.BindBuffer(kFramePrimaryBuffer); |
| - if (web_vr_mode_) { |
| + if (ShouldDrawWebVr()) { |
| DrawWebVr(); |
| } |
| @@ -790,7 +791,8 @@ void VrShellGl::DrawFrame(int16_t frame_index) { |
| // submitting. Technically we don't need a pose if not reprojecting, |
| // but keeping it uninitialized seems likely to cause problems down |
| // the road. Copying it is cheaper than fetching a new one. |
| - if (web_vr_mode_) { |
| + if (ShouldDrawWebVr()) { |
| + // TODO(crbug.com/680253): Do not compare the constants on every frame. |
|
mthiesse
2017/03/20 17:32:16
Same as above.
|
| static_assert(!((kPoseRingBufferSize - 1) & kPoseRingBufferSize), |
| "kPoseRingBufferSize must be a power of 2"); |
| head_pose = webvr_head_pose_[frame_index % kPoseRingBufferSize]; |
| @@ -851,7 +853,7 @@ void VrShellGl::DrawVrShellAndUnbind(const gvr::Mat4f& head_pose, |
| } |
| } |
| - if (web_vr_mode_) { |
| + if (ShouldDrawWebVr()) { |
| // WebVR is incompatible with 3D world compositing since the |
| // depth buffer was already populated with unknown scaling - the |
| // WebVR app has full control over zNear/zFar. Just leave the |
| @@ -871,8 +873,8 @@ void VrShellGl::DrawVrShellAndUnbind(const gvr::Mat4f& head_pose, |
| glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| } |
| if (!world_elements.empty()) { |
| - DrawUiView(&head_pose, world_elements, render_size_primary_, |
| - kViewportListPrimaryOffset); |
| + DrawUiView(head_pose, world_elements, render_size_primary_, |
| + kViewportListPrimaryOffset, !ShouldDrawWebVr()); |
| } |
| frame.Unbind(); // Done with the primary buffer. |
| @@ -890,32 +892,29 @@ void VrShellGl::DrawVrShellAndUnbind(const gvr::Mat4f& head_pose, |
| frame.BindBuffer(kFrameHeadlockedBuffer); |
| glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| - DrawUiView(nullptr, head_locked_elements, render_size_headlocked_, |
| - kViewportListHeadlockedOffset); |
| + gvr::Mat4f identity_matrix; |
| + SetIdentityM(identity_matrix); |
| + DrawUiView(identity_matrix, head_locked_elements, render_size_headlocked_, |
| + kViewportListHeadlockedOffset, false); |
| frame.Unbind(); // Done with the headlocked buffer. |
| } |
| } |
| -void VrShellGl::DrawUiView(const gvr::Mat4f* head_pose, |
| +void VrShellGl::DrawUiView(const gvr::Mat4f& head_pose, |
| const std::vector<const ContentRectangle*>& elements, |
| const gvr::Sizei& render_size, |
| - int viewport_offset) { |
| + int viewport_offset, |
| + bool draw_cursor) { |
| TRACE_EVENT0("gpu", "VrShellGl::DrawUiView"); |
| - gvr::Mat4f view_matrix; |
| - if (head_pose) { |
| - view_matrix = *head_pose; |
| - } else { |
| - SetIdentityM(view_matrix); |
| - } |
| - auto elementsInDrawOrder = GetElementsInDrawOrder(view_matrix, elements); |
| + auto elementsInDrawOrder = GetElementsInDrawOrder(head_pose, elements); |
| for (auto eye : {GVR_LEFT_EYE, GVR_RIGHT_EYE}) { |
| buffer_viewport_list_->GetBufferViewport(eye + viewport_offset, |
| buffer_viewport_.get()); |
| const gvr::Mat4f eye_view_matrix = |
| - MatrixMul(gvr_api_->GetEyeFromHeadMatrix(eye), view_matrix); |
| + MatrixMul(gvr_api_->GetEyeFromHeadMatrix(eye), head_pose); |
| gvr::Recti pixel_rect = |
| CalculatePixelSpaceRect(render_size, buffer_viewport_->GetSourceUv()); |
| @@ -928,8 +927,8 @@ void VrShellGl::DrawUiView(const gvr::Mat4f* head_pose, |
| kZNear, kZFar), |
| eye_view_matrix); |
| - DrawElements(render_matrix, eye_view_matrix, elementsInDrawOrder); |
| - if (head_pose != nullptr && !web_vr_mode_) { |
| + DrawElements(render_matrix, elementsInDrawOrder); |
| + if (draw_cursor) { |
| DrawCursor(render_matrix); |
| } |
| } |
| @@ -937,7 +936,6 @@ void VrShellGl::DrawUiView(const gvr::Mat4f* head_pose, |
| void VrShellGl::DrawElements( |
| const gvr::Mat4f& view_proj_matrix, |
| - const gvr::Mat4f& view_matrix, |
| const std::vector<const ContentRectangle*>& elements) { |
| for (const auto* rect : elements) { |
| gvr::Mat4f transform = MatrixMul(view_proj_matrix, rect->TransformMatrix()); |
| @@ -1092,6 +1090,10 @@ void VrShellGl::DrawCursor(const gvr::Mat4f& render_matrix) { |
| } |
| } |
| +bool VrShellGl::ShouldDrawWebVr() { |
| + return web_vr_mode_ && scene_->GetWebVrRenderingEnabled(); |
| +} |
| + |
| void VrShellGl::DrawWebVr() { |
| TRACE_EVENT0("gpu", "VrShellGl::DrawWebVr"); |
| // Don't need face culling, depth testing, blending, etc. Turn it all off. |
| @@ -1208,7 +1210,7 @@ void VrShellGl::OnVSync() { |
| pending_vsync_ = true; |
| pending_time_ = time; |
| } |
| - if (!web_vr_mode_) { |
| + if (!ShouldDrawWebVr()) { |
| DrawFrame(-1); |
| } |
| } |