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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 bool is_inside = x >= 0.0f && x < 1.0f && y >= 0.0f && y < 1.0f; | 267 bool is_inside = x >= 0.0f && x < 1.0f && y >= 0.0f && y < 1.0f; |
268 if (is_inside) { | 268 if (is_inside) { |
269 closest_element = distance_to_plane; | 269 closest_element = distance_to_plane; |
270 target_point_ = plane_intersection_point; | 270 target_point_ = plane_intersection_point; |
271 target_element_ = &plane; | 271 target_element_ = &plane; |
272 } | 272 } |
273 } | 273 } |
274 } | 274 } |
275 } | 275 } |
276 | 276 |
277 void VrShell::SetGvrPoseForWebVr(gvr::Mat4f pose, int32_t frameNumStarted) { | |
278 int mod = POSE_QUEUE_SIZE; | |
279 webvr_head_pose_[(frameNumStarted % mod + mod) % mod] = pose; | |
bajones
2016/10/02 20:55:23
Is there a reason this isn't simply frameNumStarte
klausw
2016/10/02 21:25:50
Yes, I've been using a signed int32_t where the mo
klausw
2016/10/04 00:40:41
Changed to use uint32_t which simplifies this.
| |
280 webvr_newest_pose_num_ = frameNumStarted; | |
281 } | |
282 | |
283 int32_t GetPixelEncodedFrameNumber() { | |
284 // Read the frame number encoded in a bottom left pixel as color values. | |
285 // See also third_party/WebKit/Source/modules/vr/VRDisplay.cpp which | |
286 // encodes the frame number, and device/vr/android/gvr/gvr_device.cc | |
287 // which tracks poses. | |
288 uint8_t pixels[4]; | |
289 //glReadBuffer(GL_BACK); // crashes, null function pointer?! | |
bajones
2016/10/02 20:55:23
This function is only available in OpenGL ES 3.0 a
klausw
2016/10/02 21:25:50
Good to know, and it does seem to work as expected
klausw
2016/10/04 00:40:41
Comment updated.
| |
290 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); | |
291 return pixels[0] | (pixels[1] << 8) | (pixels[2] << 16); | |
292 } | |
293 | |
277 void VrShell::DrawFrame(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 294 void VrShell::DrawFrame(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
278 buffer_viewport_list_->SetToRecommendedBufferViewports(); | 295 buffer_viewport_list_->SetToRecommendedBufferViewports(); |
279 | 296 |
280 gvr::Frame frame = swap_chain_->AcquireFrame(); | 297 gvr::Frame frame = swap_chain_->AcquireFrame(); |
281 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); | 298 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); |
282 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; | 299 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; |
283 gvr::Mat4f head_pose = gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_tim e); | 300 gvr::Mat4f head_pose = gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_tim e); |
284 head_pose = gvr_api_->ApplyNeckModel(head_pose, 1.0f); | 301 head_pose = gvr_api_->ApplyNeckModel(head_pose, 1.0f); |
285 | 302 |
286 // Bind back to the default framebuffer. | 303 // Bind back to the default framebuffer. |
287 frame.BindBuffer(0); | 304 frame.BindBuffer(0); |
288 | 305 |
289 if (webvr_mode_) { | 306 if (webvr_mode_) { |
290 DrawWebVr(); | 307 DrawWebVr(); |
291 if (!webvr_secure_origin_) { | 308 if (!webvr_secure_origin_) { |
292 DrawWebVrOverlay(target_time.monotonic_system_time_nanos); | 309 DrawWebVrOverlay(target_time.monotonic_system_time_nanos); |
293 } | 310 } |
311 | |
312 int32_t webvr_pose_frame = GetPixelEncodedFrameNumber(); | |
313 // LOG << "klausw: newest_pose=" << webvr_newest_pose_num_ << | |
314 // " pixel=" << webvr_pose_frame << | |
315 // "(" << webvr_pose_frame - webvr_newest_pose_num_ << ")"; | |
316 | |
317 int mod = POSE_QUEUE_SIZE; | |
318 head_pose = webvr_head_pose_[(webvr_pose_frame % mod + mod) % mod]; | |
294 } else { | 319 } else { |
295 DrawVrShell(head_pose); | 320 DrawVrShell(head_pose); |
296 } | 321 } |
297 | 322 |
298 frame.Unbind(); | 323 frame.Unbind(); |
299 frame.Submit(*buffer_viewport_list_, head_pose); | 324 frame.Submit(*buffer_viewport_list_, head_pose); |
300 } | 325 } |
301 | 326 |
302 void VrShell::DrawVrShell(const gvr::Mat4f& head_pose) { | 327 void VrShell::DrawVrShell(const gvr::Mat4f& head_pose) { |
303 float screen_tilt = desktop_screen_tilt_ * M_PI / 180.0f; | 328 float screen_tilt = desktop_screen_tilt_ * M_PI / 180.0f; |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
671 content::WebContents::FromJavaWebContents(content_web_contents)); | 696 content::WebContents::FromJavaWebContents(content_web_contents)); |
672 content::ContentViewCore* ui_core = content::ContentViewCore::FromWebContents( | 697 content::ContentViewCore* ui_core = content::ContentViewCore::FromWebContents( |
673 content::WebContents::FromJavaWebContents(ui_web_contents)); | 698 content::WebContents::FromJavaWebContents(ui_web_contents)); |
674 return reinterpret_cast<intptr_t>(new VrShell( | 699 return reinterpret_cast<intptr_t>(new VrShell( |
675 env, obj, c_core, | 700 env, obj, c_core, |
676 reinterpret_cast<ui::WindowAndroid*>(content_window_android), ui_core, | 701 reinterpret_cast<ui::WindowAndroid*>(content_window_android), ui_core, |
677 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); | 702 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); |
678 } | 703 } |
679 | 704 |
680 } // namespace vr_shell | 705 } // namespace vr_shell |
OLD | NEW |