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

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

Issue 2775283004: Rendering Daydream controller in a fixed position. (Closed)
Patch Set: Moving code to more appropriate locations. Created 3 years, 8 months 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 <android/native_window_jni.h> 7 #include <android/native_window_jni.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/android/jni_string.h" 12 #include "base/android/jni_string.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/platform_thread.h" 15 #include "base/threading/platform_thread.h"
16 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
17 #include "base/threading/thread_restrictions.h" 17 #include "base/threading/thread_restrictions.h"
18 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "chrome/browser/android/tab_android.h" 20 #include "chrome/browser/android/tab_android.h"
21 #include "chrome/browser/android/vr_shell/android_ui_gesture_target.h" 21 #include "chrome/browser/android/vr_shell/android_ui_gesture_target.h"
22 #include "chrome/browser/android/vr_shell/ui_interface.h"
22 #include "chrome/browser/android/vr_shell/vr_compositor.h" 23 #include "chrome/browser/android/vr_shell/vr_compositor.h"
24 #include "chrome/browser/android/vr_shell/vr_controller_model.h"
23 #include "chrome/browser/android/vr_shell/vr_gl_thread.h" 25 #include "chrome/browser/android/vr_shell/vr_gl_thread.h"
24 #include "chrome/browser/android/vr_shell/vr_input_manager.h" 26 #include "chrome/browser/android/vr_shell/vr_input_manager.h"
25 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" 27 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h"
26 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" 28 #include "chrome/browser/android/vr_shell/vr_shell_gl.h"
27 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" 29 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h"
28 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" 30 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h"
31 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/navigation_controller.h" 32 #include "content/public/browser/navigation_controller.h"
30 #include "content/public/browser/render_view_host.h" 33 #include "content/public/browser/render_view_host.h"
31 #include "content/public/browser/render_widget_host.h" 34 #include "content/public/browser/render_widget_host.h"
32 #include "content/public/browser/render_widget_host_view.h" 35 #include "content/public/browser/render_widget_host_view.h"
33 #include "content/public/browser/web_contents.h" 36 #include "content/public/browser/web_contents.h"
34 #include "content/public/common/content_features.h" 37 #include "content/public/common/content_features.h"
35 #include "content/public/common/referrer.h" 38 #include "content/public/common/referrer.h"
36 #include "device/vr/android/gvr/gvr_device.h" 39 #include "device/vr/android/gvr/gvr_device.h"
37 #include "device/vr/android/gvr/gvr_device_provider.h" 40 #include "device/vr/android/gvr/gvr_device_provider.h"
38 #include "device/vr/android/gvr/gvr_gamepad_data_fetcher.h" 41 #include "device/vr/android/gvr/gvr_gamepad_data_fetcher.h"
39 #include "gpu/command_buffer/common/mailbox.h" 42 #include "gpu/command_buffer/common/mailbox.h"
40 #include "jni/VrShellImpl_jni.h" 43 #include "jni/VrShellImpl_jni.h"
41 #include "third_party/WebKit/public/platform/WebInputEvent.h" 44 #include "third_party/WebKit/public/platform/WebInputEvent.h"
42 #include "ui/android/view_android.h" 45 #include "ui/android/view_android.h"
43 #include "ui/android/window_android.h" 46 #include "ui/android/window_android.h"
44 #include "ui/base/page_transition_types.h" 47 #include "ui/base/page_transition_types.h"
45 #include "ui/display/display.h" 48 #include "ui/display/display.h"
46 #include "ui/display/screen.h" 49 #include "ui/display/screen.h"
50 #include "ui/gfx/codec/png_codec.h"
47 #include "ui/gfx/transform.h" 51 #include "ui/gfx/transform.h"
48 #include "ui/gfx/transform_util.h" 52 #include "ui/gfx/transform_util.h"
49 53
50 using base::android::JavaParamRef; 54 using base::android::JavaParamRef;
51 using base::android::JavaRef; 55 using base::android::JavaRef;
52 56
53 namespace vr_shell { 57 namespace vr_shell {
54 58
55 namespace { 59 namespace {
56 vr_shell::VrShell* g_instance; 60 vr_shell::VrShell* g_instance;
57 61
58 static const char kVrShellUIURL[] = "chrome://vr-shell-ui"; 62 static const char kVrShellUIURL[] = "chrome://vr-shell-ui";
59 63
60 // Default downscale factor for computing the recommended WebVR 64 // Default downscale factor for computing the recommended WebVR
61 // renderWidth/Height from the 1:1 pixel mapped size. Using a rather 65 // renderWidth/Height from the 1:1 pixel mapped size. Using a rather
62 // aggressive downscale due to the high overhead of copying pixels 66 // aggressive downscale due to the high overhead of copying pixels
63 // twice before handing off to GVR. For comparison, the polyfill 67 // twice before handing off to GVR. For comparison, the polyfill
64 // uses approximately 0.55 on a Pixel XL. 68 // uses approximately 0.55 on a Pixel XL.
65 static constexpr float kWebVrRecommendedResolutionScale = 0.5; 69 static constexpr float kWebVrRecommendedResolutionScale = 0.5;
66 70
67 void SetIsInVR(content::WebContents* contents, bool is_in_vr) { 71 void SetIsInVR(content::WebContents* contents, bool is_in_vr) {
68 if (contents && contents->GetRenderWidgetHostView()) 72 if (contents && contents->GetRenderWidgetHostView())
69 contents->GetRenderWidgetHostView()->SetIsInVR(is_in_vr); 73 contents->GetRenderWidgetHostView()->SetIsInVR(is_in_vr);
70 } 74 }
71 75
76 void LoadControllerModelTask(
77 base::WeakPtr<VrShell> weak_vr_shell,
78 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) {
79 auto controller_model = VrControllerModel::LoadFromComponent();
80 if (controller_model) {
81 main_thread_task_runner->PostTask(
82 FROM_HERE, base::Bind(&VrShell::SubmitControllerModel, weak_vr_shell,
83 base::Passed(&controller_model)));
84 }
85 }
86
72 } // namespace 87 } // namespace
73 88
74 VrShell::VrShell(JNIEnv* env, 89 VrShell::VrShell(JNIEnv* env,
75 jobject obj, 90 jobject obj,
76 ui::WindowAndroid* content_window, 91 ui::WindowAndroid* content_window,
77 content::WebContents* ui_contents, 92 content::WebContents* ui_contents,
78 ui::WindowAndroid* ui_window, 93 ui::WindowAndroid* ui_window,
79 bool for_web_vr, 94 bool for_web_vr,
80 VrShellDelegate* delegate, 95 VrShellDelegate* delegate,
81 gvr_context* gvr_api, 96 gvr_context* gvr_api,
(...skipping 21 matching lines...) Expand all
103 gl_thread_ = base::MakeUnique<VrGLThread>(weak_ptr_factory_.GetWeakPtr(), 118 gl_thread_ = base::MakeUnique<VrGLThread>(weak_ptr_factory_.GetWeakPtr(),
104 main_thread_task_runner_, gvr_api, 119 main_thread_task_runner_, gvr_api,
105 for_web_vr, reprojected_rendering_); 120 for_web_vr, reprojected_rendering_);
106 121
107 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0); 122 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0);
108 options.priority = base::ThreadPriority::DISPLAY; 123 options.priority = base::ThreadPriority::DISPLAY;
109 gl_thread_->StartWithOptions(options); 124 gl_thread_->StartWithOptions(options);
110 125
111 html_interface_ = base::MakeUnique<UiInterface>( 126 html_interface_ = base::MakeUnique<UiInterface>(
112 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD); 127 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD);
128
129 content::BrowserThread::PostTask(
130 content::BrowserThread::FILE, FROM_HERE,
131 base::Bind(LoadControllerModelTask, weak_ptr_factory_.GetWeakPtr(),
132 main_thread_task_runner_));
113 } 133 }
114 134
115 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { 135 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
116 delete this; 136 delete this;
117 } 137 }
118 138
119 void VrShell::SwapContents( 139 void VrShell::SwapContents(
120 JNIEnv* env, 140 JNIEnv* env,
121 const JavaParamRef<jobject>& obj, 141 const JavaParamRef<jobject>& obj,
122 const JavaParamRef<jobject>& web_contents, 142 const JavaParamRef<jobject>& web_contents,
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 362
343 void VrShell::SubmitWebVRFrame(int16_t frame_index, 363 void VrShell::SubmitWebVRFrame(int16_t frame_index,
344 const gpu::MailboxHolder& mailbox) { 364 const gpu::MailboxHolder& mailbox) {
345 TRACE_EVENT1("gpu", "SubmitWebVRFrame", "frame", frame_index); 365 TRACE_EVENT1("gpu", "SubmitWebVRFrame", "frame", frame_index);
346 366
347 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SubmitWebVRFrame, 367 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SubmitWebVRFrame,
348 gl_thread_->GetVrShellGl(), frame_index, 368 gl_thread_->GetVrShellGl(), frame_index,
349 mailbox)); 369 mailbox));
350 } 370 }
351 371
372 void VrShell::SubmitControllerModel(std::unique_ptr<VrControllerModel> model) {
373 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetControllerModel,
374 gl_thread_->GetVrShellGl(),
375 base::Passed(&model)));
376 }
377
352 void VrShell::UpdateWebVRTextureBounds(int16_t frame_index, 378 void VrShell::UpdateWebVRTextureBounds(int16_t frame_index,
353 const gvr::Rectf& left_bounds, 379 const gvr::Rectf& left_bounds,
354 const gvr::Rectf& right_bounds, 380 const gvr::Rectf& right_bounds,
355 const gvr::Sizei& source_size) { 381 const gvr::Sizei& source_size) {
356 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateWebVRTextureBounds, 382 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateWebVRTextureBounds,
357 gl_thread_->GetVrShellGl(), frame_index, 383 gl_thread_->GetVrShellGl(), frame_index,
358 left_bounds, right_bounds, source_size)); 384 left_bounds, right_bounds, source_size));
359 } 385 }
360 386
361 bool VrShell::SupportsPresentation() { 387 bool VrShell::SupportsPresentation() {
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 jboolean reprojected_rendering) { 805 jboolean reprojected_rendering) {
780 return reinterpret_cast<intptr_t>(new VrShell( 806 return reinterpret_cast<intptr_t>(new VrShell(
781 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android), 807 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android),
782 content::WebContents::FromJavaWebContents(ui_web_contents), 808 content::WebContents::FromJavaWebContents(ui_web_contents),
783 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr, 809 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr,
784 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), 810 VrShellDelegate::GetNativeVrShellDelegate(env, delegate),
785 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); 811 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering));
786 } 812 }
787 813
788 } // namespace vr_shell 814 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell.h ('k') | chrome/browser/android/vr_shell/vr_shell_gl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698