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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 float screen_height = kScreenHeightRatio * desktop_height_; | 149 float screen_height = kScreenHeightRatio * desktop_height_; |
150 std::unique_ptr<ContentRectangle> rect(new ContentRectangle()); | 150 std::unique_ptr<ContentRectangle> rect(new ContentRectangle()); |
151 rect->id = kBrowserUiElementId; | 151 rect->id = kBrowserUiElementId; |
152 rect->size = {screen_width, screen_height, 1.0f}; | 152 rect->size = {screen_width, screen_height, 1.0f}; |
153 rect->translation = kDesktopPositionDefault; | 153 rect->translation = kDesktopPositionDefault; |
154 scene_.AddUiElement(rect); | 154 scene_.AddUiElement(rect); |
155 | 155 |
156 desktop_plane_ = scene_.GetUiElementById(kBrowserUiElementId); | 156 desktop_plane_ = scene_.GetUiElementById(kBrowserUiElementId); |
157 | 157 |
158 LoadUIContent(); | 158 LoadUIContent(); |
159 | |
160 webvr_head_pose_.resize(kPoseRingBufferSize); | |
dcheng
2016/10/05 07:34:44
resize() takes a second argument, so I think this
klausw
2016/10/05 17:02:10
Done.
| |
161 const gvr::Mat4f identity = {{{1.0f, 0.0f, 0.0f, 0.0f}, | |
dcheng
2016/10/05 07:34:44
Nit: prefer constexpr to const (also prefix with k
mthiesse
2016/10/05 15:40:01
Might as well re-use SetIdentityM in vr_math.cc
A
klausw
2016/10/05 17:02:10
Acknowledged, but it's no longer const (or constex
klausw
2016/10/05 17:02:10
I changed it to use SetIdentityM. Somehow I was un
dcheng
2016/10/05 17:35:21
Casting away const-ness would be a Bad Thing™ to d
| |
162 {0.0f, 1.0f, 0.0f, 0.0f}, | |
163 {0.0f, 0.0f, 1.0f, 0.0f}, | |
164 {0.0f, 0.0f, 0.0f, 1.0f}}}; | |
165 for (int i = 0; i < kPoseRingBufferSize; ++i) { | |
166 webvr_head_pose_[i] = identity; | |
167 } | |
159 } | 168 } |
160 | 169 |
161 void VrShell::UpdateCompositorLayers(JNIEnv* env, | 170 void VrShell::UpdateCompositorLayers(JNIEnv* env, |
162 const JavaParamRef<jobject>& obj) { | 171 const JavaParamRef<jobject>& obj) { |
163 content_compositor_->SetLayer(content_cvc_); | 172 content_compositor_->SetLayer(content_cvc_); |
164 ui_compositor_->SetLayer(ui_cvc_); | 173 ui_compositor_->SetLayer(ui_cvc_); |
165 } | 174 } |
166 | 175 |
167 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 176 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
168 delete this; | 177 delete this; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 bool is_inside = x >= 0.0f && x < 1.0f && y >= 0.0f && y < 1.0f; | 278 bool is_inside = x >= 0.0f && x < 1.0f && y >= 0.0f && y < 1.0f; |
270 if (is_inside) { | 279 if (is_inside) { |
271 closest_element = distance_to_plane; | 280 closest_element = distance_to_plane; |
272 target_point_ = plane_intersection_point; | 281 target_point_ = plane_intersection_point; |
273 target_element_ = &plane; | 282 target_element_ = &plane; |
274 } | 283 } |
275 } | 284 } |
276 } | 285 } |
277 } | 286 } |
278 | 287 |
288 void VrShell::SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) { | |
289 webvr_head_pose_[pose_num % kPoseRingBufferSize] = pose; | |
290 } | |
291 | |
292 uint32_t GetPixelEncodedPoseIndex() { | |
293 // Read the pose index encoded in a bottom left pixel as color values. | |
294 // See also third_party/WebKit/Source/modules/vr/VRDisplay.cpp which | |
295 // encodes the pose index, and device/vr/android/gvr/gvr_device.cc | |
296 // which tracks poses. | |
297 uint8_t pixels[4]; | |
298 // Assume we're reading from the frambebuffer we just wrote to. | |
299 // That's true currently, we may need to use glReadBuffer(GL_BACK) | |
300 // or equivalent if the rendering setup changes in the future. | |
301 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); | |
mthiesse
2016/10/05 13:14:06
After you start presenting, aren't the poses and f
mthiesse
2016/10/05 14:58:42
Acknowledged.
| |
302 return pixels[0] | (pixels[1] << 8) | (pixels[2] << 16); | |
303 } | |
304 | |
279 void VrShell::DrawFrame(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 305 void VrShell::DrawFrame(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
280 buffer_viewport_list_->SetToRecommendedBufferViewports(); | 306 buffer_viewport_list_->SetToRecommendedBufferViewports(); |
281 | 307 |
282 gvr::Frame frame = swap_chain_->AcquireFrame(); | 308 gvr::Frame frame = swap_chain_->AcquireFrame(); |
283 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); | 309 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); |
284 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; | 310 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; |
285 gvr::Mat4f head_pose = gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_tim e); | 311 gvr::Mat4f head_pose = gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_tim e); |
286 head_pose = gvr_api_->ApplyNeckModel(head_pose, 1.0f); | 312 head_pose = gvr_api_->ApplyNeckModel(head_pose, 1.0f); |
287 | 313 |
288 // Bind back to the default framebuffer. | 314 // Bind back to the default framebuffer. |
289 frame.BindBuffer(0); | 315 frame.BindBuffer(0); |
290 | 316 |
291 if (webvr_mode_) { | 317 if (webvr_mode_) { |
292 DrawWebVr(); | 318 DrawWebVr(); |
293 if (!webvr_secure_origin_) { | 319 if (!webvr_secure_origin_) { |
294 DrawWebVrOverlay(target_time.monotonic_system_time_nanos); | 320 DrawWebVrOverlay(target_time.monotonic_system_time_nanos); |
295 } | 321 } |
322 | |
323 // When using async reprojection, we need to know which pose was used in | |
324 // the WebVR app for drawing this frame. Due to unknown amounts of | |
325 // buffering in the compositor and SurfaceTexture, we read the pose number | |
326 // from a corner pixel. There's no point in doing this for legacy | |
327 // distortion rendering since that doesn't need a pose, and reading back | |
328 // pixels is an expensive operation. TODO(klausw): stop doing this once we | |
329 // have working no-compositor rendering for WebVR. | |
330 if (gvr_api_->GetAsyncReprojectionEnabled()) { | |
331 int32_t webvr_pose_frame = GetPixelEncodedPoseIndex(); | |
dcheng
2016/10/05 07:34:44
Nit: match types with uint32_t here as well.
klausw
2016/10/05 17:02:10
Done. I'm surprised the compiler didn't complain a
dcheng
2016/10/05 17:35:21
We suppress a lot of unsigned / signed conversion
| |
332 head_pose = webvr_head_pose_[webvr_pose_frame % kPoseRingBufferSize]; | |
333 } | |
296 } else { | 334 } else { |
297 DrawVrShell(head_pose); | 335 DrawVrShell(head_pose); |
298 } | 336 } |
299 | 337 |
300 frame.Unbind(); | 338 frame.Unbind(); |
301 frame.Submit(*buffer_viewport_list_, head_pose); | 339 frame.Submit(*buffer_viewport_list_, head_pose); |
302 } | 340 } |
303 | 341 |
304 void VrShell::DrawVrShell(const gvr::Mat4f& head_pose) { | 342 void VrShell::DrawVrShell(const gvr::Mat4f& head_pose) { |
305 float screen_tilt = desktop_screen_tilt_ * M_PI / 180.0f; | 343 float screen_tilt = desktop_screen_tilt_ * M_PI / 180.0f; |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
674 content::WebContents::FromJavaWebContents(content_web_contents)); | 712 content::WebContents::FromJavaWebContents(content_web_contents)); |
675 content::ContentViewCore* ui_core = content::ContentViewCore::FromWebContents( | 713 content::ContentViewCore* ui_core = content::ContentViewCore::FromWebContents( |
676 content::WebContents::FromJavaWebContents(ui_web_contents)); | 714 content::WebContents::FromJavaWebContents(ui_web_contents)); |
677 return reinterpret_cast<intptr_t>(new VrShell( | 715 return reinterpret_cast<intptr_t>(new VrShell( |
678 env, obj, c_core, | 716 env, obj, c_core, |
679 reinterpret_cast<ui::WindowAndroid*>(content_window_android), ui_core, | 717 reinterpret_cast<ui::WindowAndroid*>(content_window_android), ui_core, |
680 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); | 718 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); |
681 } | 719 } |
682 | 720 |
683 } // namespace vr_shell | 721 } // namespace vr_shell |
OLD | NEW |