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

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

Issue 2434013002: Implement a means of letting native VR Shell control the HTML UI. (Closed)
Patch Set: Remove use of cr.define() Created 4 years, 2 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 "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_scene.h" 10 #include "chrome/browser/android/vr_shell/ui_scene.h"
10 #include "chrome/browser/android/vr_shell/vr_compositor.h" 11 #include "chrome/browser/android/vr_shell/vr_compositor.h"
11 #include "chrome/browser/android/vr_shell/vr_controller.h" 12 #include "chrome/browser/android/vr_shell/vr_controller.h"
12 #include "chrome/browser/android/vr_shell/vr_gesture.h" 13 #include "chrome/browser/android/vr_shell/vr_gesture.h"
13 #include "chrome/browser/android/vr_shell/vr_gl_util.h" 14 #include "chrome/browser/android/vr_shell/vr_gl_util.h"
14 #include "chrome/browser/android/vr_shell/vr_input_manager.h" 15 #include "chrome/browser/android/vr_shell/vr_input_manager.h"
15 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" 16 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h"
16 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" 17 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h"
17 #include "content/public/browser/navigation_controller.h" 18 #include "content/public/browser/navigation_controller.h"
18 #include "content/public/browser/render_widget_host.h" 19 #include "content/public/browser/render_widget_host.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 ui::WindowAndroid* ui_window) 136 ui::WindowAndroid* ui_window)
136 : desktop_screen_tilt_(kDesktopScreenTiltDefault), 137 : desktop_screen_tilt_(kDesktopScreenTiltDefault),
137 desktop_height_(kDesktopHeightDefault), 138 desktop_height_(kDesktopHeightDefault),
138 main_contents_(main_contents), 139 main_contents_(main_contents),
139 ui_contents_(ui_contents), 140 ui_contents_(ui_contents),
140 weak_ptr_factory_(this) { 141 weak_ptr_factory_(this) {
141 DCHECK(g_instance == nullptr); 142 DCHECK(g_instance == nullptr);
142 g_instance = this; 143 g_instance = this;
143 j_vr_shell_.Reset(env, obj); 144 j_vr_shell_.Reset(env, obj);
144 scene_.reset(new UiScene); 145 scene_.reset(new UiScene);
146 html_interface_.reset(new UiInterface);
145 content_compositor_.reset(new VrCompositor(content_window, false)); 147 content_compositor_.reset(new VrCompositor(content_window, false));
146 ui_compositor_.reset(new VrCompositor(ui_window, true)); 148 ui_compositor_.reset(new VrCompositor(ui_window, true));
147 149
148 float screen_width = kScreenWidthRatio * desktop_height_; 150 float screen_width = kScreenWidthRatio * desktop_height_;
149 float screen_height = kScreenHeightRatio * desktop_height_; 151 float screen_height = kScreenHeightRatio * desktop_height_;
150 std::unique_ptr<ContentRectangle> rect(new ContentRectangle()); 152 std::unique_ptr<ContentRectangle> rect(new ContentRectangle());
151 rect->id = kBrowserUiElementId; 153 rect->id = kBrowserUiElementId;
152 rect->size = {screen_width, screen_height, 1.0f}; 154 rect->size = {screen_width, screen_height, 1.0f};
153 rect->translation = kDesktopPositionDefault; 155 rect->translation = kDesktopPositionDefault;
154 scene_->AddUiElement(rect); 156 scene_->AddUiElement(rect);
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 void VrShell::OnDomContentsLoaded() { 744 void VrShell::OnDomContentsLoaded() {
743 // TODO(mthiesse): Setting the background to transparent after the DOM content 745 // TODO(mthiesse): Setting the background to transparent after the DOM content
744 // has loaded is a hack to work around the background not updating when we set 746 // has loaded is a hack to work around the background not updating when we set
745 // it to transparent unless we perform a very specific sequence of events. 747 // it to transparent unless we perform a very specific sequence of events.
746 // First the page background must load as not transparent, then we set the 748 // First the page background must load as not transparent, then we set the
747 // background of the renderer to transparent, then we update the page 749 // background of the renderer to transparent, then we update the page
748 // background to be transparent. This is probably a bug in blink that we 750 // background to be transparent. This is probably a bug in blink that we
749 // should fix. 751 // should fix.
750 ui_contents_->GetRenderWidgetHostView()->SetBackgroundColor( 752 ui_contents_->GetRenderWidgetHostView()->SetBackgroundColor(
751 SK_ColorTRANSPARENT); 753 SK_ColorTRANSPARENT);
754 html_interface_->OnDomContentsLoaded();
752 } 755 }
753 756
754 void VrShell::SetWebVrMode(JNIEnv* env, 757 void VrShell::SetWebVrMode(JNIEnv* env,
755 const base::android::JavaParamRef<jobject>& obj, 758 const base::android::JavaParamRef<jobject>& obj,
756 bool enabled) { 759 bool enabled) {
757 webvr_mode_ = enabled; 760 webvr_mode_ = enabled;
758 if (enabled) { 761 if (enabled) {
759 int64_t now = gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos; 762 int64_t now = gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos;
760 constexpr int64_t seconds_to_nanos = 1000 * 1000 * 1000; 763 constexpr int64_t seconds_to_nanos = 1000 * 1000 * 1000;
761 webvr_warning_end_nanos_ = now + kWebVrWarningSeconds * seconds_to_nanos; 764 webvr_warning_end_nanos_ = now + kWebVrWarningSeconds * seconds_to_nanos;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 ui_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost()->GetScreenInfo( 808 ui_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost()->GetScreenInfo(
806 &result); 809 &result);
807 ui_tex_width_ = width / result.device_scale_factor; 810 ui_tex_width_ = width / result.device_scale_factor;
808 ui_tex_height_ = height / result.device_scale_factor; 811 ui_tex_height_ = height / result.device_scale_factor;
809 } 812 }
810 813
811 UiScene* VrShell::GetScene() { 814 UiScene* VrShell::GetScene() {
812 return scene_.get(); 815 return scene_.get();
813 } 816 }
814 817
818 UiInterface* VrShell::GetUiInterface() {
819 return html_interface_.get();
820 }
821
815 void VrShell::QueueTask(base::Callback<void()>& callback) { 822 void VrShell::QueueTask(base::Callback<void()>& callback) {
816 base::AutoLock lock(task_queue_lock_); 823 base::AutoLock lock(task_queue_lock_);
817 task_queue_.push(callback); 824 task_queue_.push(callback);
818 } 825 }
819 826
820 void VrShell::HandleQueuedTasks() { 827 void VrShell::HandleQueuedTasks() {
821 // To protect a stream of tasks from blocking rendering indefinitely, 828 // To protect a stream of tasks from blocking rendering indefinitely,
822 // process only the number of tasks present when first checked. 829 // process only the number of tasks present when first checked.
823 std::vector<base::Callback<void()>> tasks; 830 std::vector<base::Callback<void()>> tasks;
824 { 831 {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 const JavaParamRef<jobject>& ui_web_contents, 874 const JavaParamRef<jobject>& ui_web_contents,
868 jlong ui_window_android) { 875 jlong ui_window_android) {
869 return reinterpret_cast<intptr_t>(new VrShell( 876 return reinterpret_cast<intptr_t>(new VrShell(
870 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), 877 env, obj, content::WebContents::FromJavaWebContents(content_web_contents),
871 reinterpret_cast<ui::WindowAndroid*>(content_window_android), 878 reinterpret_cast<ui::WindowAndroid*>(content_window_android),
872 content::WebContents::FromJavaWebContents(ui_web_contents), 879 content::WebContents::FromJavaWebContents(ui_web_contents),
873 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); 880 reinterpret_cast<ui::WindowAndroid*>(ui_window_android)));
874 } 881 }
875 882
876 } // namespace vr_shell 883 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell.h ('k') | chrome/browser/resources/vr_shell/vr_shell_ui.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698