Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell.cc

Issue 2471433002: Implement WebVR presentation pausing for VR Shell Menu Mode (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "chrome/browser/android/vr_shell/ui_elements.h" 8 #include "chrome/browser/android/vr_shell/ui_elements.h"
9 #include "chrome/browser/android/vr_shell/ui_interface.h" 9 #include "chrome/browser/android/vr_shell/ui_interface.h"
10 #include "chrome/browser/android/vr_shell/ui_scene.h" 10 #include "chrome/browser/android/vr_shell/ui_scene.h"
11 #include "chrome/browser/android/vr_shell/vr_compositor.h" 11 #include "chrome/browser/android/vr_shell/vr_compositor.h"
12 #include "chrome/browser/android/vr_shell/vr_controller.h" 12 #include "chrome/browser/android/vr_shell/vr_controller.h"
13 #include "chrome/browser/android/vr_shell/vr_gl_util.h" 13 #include "chrome/browser/android/vr_shell/vr_gl_util.h"
14 #include "chrome/browser/android/vr_shell/vr_input_manager.h" 14 #include "chrome/browser/android/vr_shell/vr_input_manager.h"
15 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" 15 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h"
16 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" 16 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h"
17 #include "content/public/browser/navigation_controller.h" 17 #include "content/public/browser/navigation_controller.h"
18 #include "content/public/browser/render_view_host.h" 18 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/render_widget_host.h" 19 #include "content/public/browser/render_widget_host.h"
20 #include "content/public/browser/render_widget_host_view.h" 20 #include "content/public/browser/render_widget_host_view.h"
21 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
22 #include "content/public/common/referrer.h" 22 #include "content/public/common/referrer.h"
23 #include "content/public/common/screen_info.h" 23 #include "content/public/common/screen_info.h"
24 #include "device/vr/android/gvr/gvr_device_provider.h"
24 #include "jni/VrShellImpl_jni.h" 25 #include "jni/VrShellImpl_jni.h"
25 #include "ui/android/view_android.h" 26 #include "ui/android/view_android.h"
26 #include "ui/android/window_android.h" 27 #include "ui/android/window_android.h"
27 #include "ui/base/page_transition_types.h" 28 #include "ui/base/page_transition_types.h"
28 #include "ui/gl/gl_bindings.h" 29 #include "ui/gl/gl_bindings.h"
29 #include "ui/gl/init/gl_factory.h" 30 #include "ui/gl/init/gl_factory.h"
30 31
31 using base::android::JavaParamRef; 32 using base::android::JavaParamRef;
32 33
33 namespace { 34 namespace {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 g_instance = nullptr; 177 g_instance = nullptr;
177 gl::init::ClearGLBindings(); 178 gl::init::ClearGLBindings();
178 } 179 }
179 180
180 void VrShell::SetDelegate(JNIEnv* env, 181 void VrShell::SetDelegate(JNIEnv* env,
181 const base::android::JavaParamRef<jobject>& obj, 182 const base::android::JavaParamRef<jobject>& obj,
182 const base::android::JavaParamRef<jobject>& delegate) { 183 const base::android::JavaParamRef<jobject>& delegate) {
183 delegate_ = VrShellDelegate::getNativeDelegate(env, delegate); 184 delegate_ = VrShellDelegate::getNativeDelegate(env, delegate);
184 } 185 }
185 186
186 enum class ViewerType 187 enum class ViewerType {
187 {
188 UNKNOWN_TYPE = 0, 188 UNKNOWN_TYPE = 0,
189 CARDBOARD = 1, 189 CARDBOARD = 1,
190 DAYDREAM = 2, 190 DAYDREAM = 2,
191 VIEWER_TYPE_MAX, 191 VIEWER_TYPE_MAX,
192 }; 192 };
193 193
194 void VrShell::GvrInit(JNIEnv* env, 194 void VrShell::GvrInit(JNIEnv* env,
195 const JavaParamRef<jobject>& obj, 195 const JavaParamRef<jobject>& obj,
196 jlong native_gvr_api) { 196 jlong native_gvr_api) {
197 gvr_api_ = 197 gvr_api_ =
198 gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(native_gvr_api)); 198 gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(native_gvr_api));
199 199
200 if (delegate_) 200 if (delegate_)
201 delegate_->OnVrShellReady(this); 201 delegate_->OnVrShellReady(this);
202 controller_.reset( 202 controller_.reset(
203 new VrController(reinterpret_cast<gvr_context*>(native_gvr_api))); 203 new VrController(reinterpret_cast<gvr_context*>(native_gvr_api)));
204 content_input_manager_ = new VrInputManager(main_contents_); 204 content_input_manager_ = new VrInputManager(main_contents_);
205 ui_input_manager_ = new VrInputManager(ui_contents_); 205 ui_input_manager_ = new VrInputManager(ui_contents_);
206 206
207 ViewerType viewerType; 207 ViewerType viewerType;
208 switch (gvr_api_->GetViewerType()) 208 switch (gvr_api_->GetViewerType()) {
209 {
210 case gvr::ViewerType::GVR_VIEWER_TYPE_DAYDREAM: 209 case gvr::ViewerType::GVR_VIEWER_TYPE_DAYDREAM:
211 viewerType = ViewerType::DAYDREAM; 210 viewerType = ViewerType::DAYDREAM;
212 break; 211 break;
213 case gvr::ViewerType::GVR_VIEWER_TYPE_CARDBOARD: 212 case gvr::ViewerType::GVR_VIEWER_TYPE_CARDBOARD:
214 viewerType = ViewerType::CARDBOARD; 213 viewerType = ViewerType::CARDBOARD;
215 break; 214 break;
216 default: 215 default:
217 NOTREACHED(); 216 NOTREACHED();
218 viewerType = ViewerType::UNKNOWN_TYPE; 217 viewerType = ViewerType::UNKNOWN_TYPE;
219 break; 218 break;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 new gvr::BufferViewport(gvr_api_->CreateBufferViewport())); 260 new gvr::BufferViewport(gvr_api_->CreateBufferViewport()));
262 buffer_viewport_list_->GetBufferViewport(GVR_RIGHT_EYE, 261 buffer_viewport_list_->GetBufferViewport(GVR_RIGHT_EYE,
263 headlocked_right_viewport_.get()); 262 headlocked_right_viewport_.get());
264 headlocked_right_viewport_->SetSourceBufferIndex(kFrameHeadlockedBuffer); 263 headlocked_right_viewport_->SetSourceBufferIndex(kFrameHeadlockedBuffer);
265 headlocked_right_viewport_->SetReprojection(GVR_REPROJECTION_NONE); 264 headlocked_right_viewport_->SetReprojection(GVR_REPROJECTION_NONE);
266 } 265 }
267 266
268 void VrShell::UpdateController(const gvr::Vec3f& forward_vector) { 267 void VrShell::UpdateController(const gvr::Vec3f& forward_vector) {
269 controller_->UpdateState(); 268 controller_->UpdateState();
270 std::unique_ptr<WebGestureEvent> gesture = controller_->DetectGesture(); 269 std::unique_ptr<WebGestureEvent> gesture = controller_->DetectGesture();
271 270 #if defined(ENABLE_VR_SHELL)
271 // Note that button up/down state is transient, so IsButtonUp only returns
272 // true for a single frame (and we're guaranteed not to miss it).
273 if (controller_->IsButtonUp(
274 gvr::ControllerButton::GVR_CONTROLLER_BUTTON_APP)) {
275 if (html_interface_->GetMode() == UiInterface::Mode::MENU) {
276 // Temporary: Hit app button a second time to exit menu mode.
277 if (webvr_mode_) {
278 html_interface_->SetMode(UiInterface::Mode::WEB_VR);
279 delegate_->GetDeviceProvider()->ResumePresent();
280 } else {
281 html_interface_->SetMode(UiInterface::Mode::STANDARD);
282 }
283 } else {
284 if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) {
285 delegate_->GetDeviceProvider()->PausePresent();
286 }
287 html_interface_->SetMode(UiInterface::Mode::MENU);
288 // TODO(mthiesse): Also pause tracking for all webvr pages.
bajones 2016/11/01 18:11:31 Is this comment accurate? Seems like we're already
mthiesse 2016/11/02 14:39:02 As discussed offline, we're going to ignore the no
bshe 2016/11/02 14:58:40 Does this mean magic window mode won't ship in nor
mthiesse 2016/11/02 15:03:32 It doesn't mean either of those things. It means w
289 }
290 }
291 #endif
292 if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) {
293 return;
294 }
272 // TODO(asimjour) for now, scroll is sent to the main content. 295 // TODO(asimjour) for now, scroll is sent to the main content.
273 if (gesture->type == WebInputEvent::GestureScrollBegin || 296 if (gesture->type == WebInputEvent::GestureScrollBegin ||
274 gesture->type == WebInputEvent::GestureScrollUpdate || 297 gesture->type == WebInputEvent::GestureScrollUpdate ||
275 gesture->type == WebInputEvent::GestureScrollEnd) { 298 gesture->type == WebInputEvent::GestureScrollEnd) {
276 content_input_manager_->ProcessUpdatedGesture(*gesture.get()); 299 content_input_manager_->ProcessUpdatedGesture(*gesture.get());
277 } 300 }
278 301
279 WebInputEvent::Type original_type = gesture->type; 302 WebInputEvent::Type original_type = gesture->type;
280 gvr::Vec3f ergo_neutral_pose; 303 gvr::Vec3f ergo_neutral_pose;
281 if (!controller_->IsConnected()) { 304 if (!controller_->IsConnected()) {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 void VrShell::SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) { 424 void VrShell::SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) {
402 webvr_head_pose_[pose_num % kPoseRingBufferSize] = pose; 425 webvr_head_pose_[pose_num % kPoseRingBufferSize] = pose;
403 } 426 }
404 427
405 uint32_t GetPixelEncodedPoseIndex() { 428 uint32_t GetPixelEncodedPoseIndex() {
406 // Read the pose index encoded in a bottom left pixel as color values. 429 // Read the pose index encoded in a bottom left pixel as color values.
407 // See also third_party/WebKit/Source/modules/vr/VRDisplay.cpp which 430 // See also third_party/WebKit/Source/modules/vr/VRDisplay.cpp which
408 // encodes the pose index, and device/vr/android/gvr/gvr_device.cc 431 // encodes the pose index, and device/vr/android/gvr/gvr_device.cc
409 // which tracks poses. 432 // which tracks poses.
410 uint8_t pixels[4]; 433 uint8_t pixels[4];
411 // Assume we're reading from the frambebuffer we just wrote to. 434 // Assume we're reading from the framebuffer we just wrote to.
412 // That's true currently, we may need to use glReadBuffer(GL_BACK) 435 // That's true currently, we may need to use glReadBuffer(GL_BACK)
413 // or equivalent if the rendering setup changes in the future. 436 // or equivalent if the rendering setup changes in the future.
414 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 437 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
415 return pixels[0] | (pixels[1] << 8) | (pixels[2] << 16); 438 return pixels[0] | (pixels[1] << 8) | (pixels[2] << 16);
416 } 439 }
417 440
418 void VrShell::DrawFrame(JNIEnv* env, const JavaParamRef<jobject>& obj) { 441 void VrShell::DrawFrame(JNIEnv* env, const JavaParamRef<jobject>& obj) {
419 buffer_viewport_list_->SetToRecommendedBufferViewports(); 442 buffer_viewport_list_->SetToRecommendedBufferViewports();
420 443
421 gvr::Frame frame = swap_chain_->AcquireFrame(); 444 gvr::Frame frame = swap_chain_->AcquireFrame();
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 const JavaParamRef<jobject>& ui_web_contents, 845 const JavaParamRef<jobject>& ui_web_contents,
823 jlong ui_window_android) { 846 jlong ui_window_android) {
824 return reinterpret_cast<intptr_t>(new VrShell( 847 return reinterpret_cast<intptr_t>(new VrShell(
825 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), 848 env, obj, content::WebContents::FromJavaWebContents(content_web_contents),
826 reinterpret_cast<ui::WindowAndroid*>(content_window_android), 849 reinterpret_cast<ui::WindowAndroid*>(content_window_android),
827 content::WebContents::FromJavaWebContents(ui_web_contents), 850 content::WebContents::FromJavaWebContents(ui_web_contents),
828 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); 851 reinterpret_cast<ui::WindowAndroid*>(ui_window_android)));
829 } 852 }
830 853
831 } // namespace vr_shell 854 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698