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

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

Issue 2354373002: Implement UI web contents for Vr Shell (Closed)
Patch Set: Addressed comments 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 <thread> 7 #include <thread>
8 8
9 #include "chrome/browser/android/vr_shell/vr_compositor.h" 9 #include "chrome/browser/android/vr_shell/vr_compositor.h"
10 #include "chrome/browser/android/vr_shell/vr_gl_util.h" 10 #include "chrome/browser/android/vr_shell/vr_gl_util.h"
11 #include "chrome/browser/android/vr_shell/vr_math.h" 11 #include "chrome/browser/android/vr_shell/vr_math.h"
12 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" 12 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h"
13 #include "content/public/browser/android/content_view_core.h" 13 #include "content/public/browser/android/content_view_core.h"
14 #include "content/public/browser/navigation_controller.h"
14 #include "content/public/browser/render_widget_host.h" 15 #include "content/public/browser/render_widget_host.h"
15 #include "content/public/browser/render_widget_host_view.h" 16 #include "content/public/browser/render_widget_host_view.h"
16 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
18 #include "content/public/common/referrer.h"
17 #include "jni/VrShell_jni.h" 19 #include "jni/VrShell_jni.h"
18 #include "ui/android/view_android.h" 20 #include "ui/android/view_android.h"
19 #include "ui/android/window_android.h" 21 #include "ui/android/window_android.h"
22 #include "ui/base/page_transition_types.h"
20 #include "ui/gl/gl_bindings.h" 23 #include "ui/gl/gl_bindings.h"
21 #include "ui/gl/init/gl_factory.h" 24 #include "ui/gl/init/gl_factory.h"
22 25
23 using base::android::JavaParamRef; 26 using base::android::JavaParamRef;
24 27
25 namespace { 28 namespace {
26 // Constant taken from treasure_hunt demo. 29 // Constant taken from treasure_hunt demo.
27 static constexpr long kPredictionTimeWithoutVsyncNanos = 50000000; 30 static constexpr long kPredictionTimeWithoutVsyncNanos = 50000000;
28 31
29 static constexpr float kZNear = 0.1f; 32 static constexpr float kZNear = 0.1f;
(...skipping 18 matching lines...) Expand all
48 // controller orientation is reset. This should match the yaw angle 51 // controller orientation is reset. This should match the yaw angle
49 // where the main screen is placed. 52 // where the main screen is placed.
50 static constexpr gvr::Vec3f kNeutralPose = {0.0f, 0.0f, -1.0f}; 53 static constexpr gvr::Vec3f kNeutralPose = {0.0f, 0.0f, -1.0f};
51 54
52 // In lieu of an elbow model, we assume a position for the user's hand. 55 // In lieu of an elbow model, we assume a position for the user's hand.
53 // TODO(mthiesse): Handedness options. 56 // TODO(mthiesse): Handedness options.
54 static constexpr gvr::Vec3f kHandPosition = {0.2f, -0.5f, -0.2f}; 57 static constexpr gvr::Vec3f kHandPosition = {0.2f, -0.5f, -0.2f};
55 58
56 static constexpr float kReticleZOffset = 0.01f; 59 static constexpr float kReticleZOffset = 0.01f;
57 60
61 static const char kVrShellUIURL[] = "chrome://vr-shell-ui";
62
58 } // namespace 63 } // namespace
59 64
60 namespace vr_shell { 65 namespace vr_shell {
61 66
62 VrShell::VrShell(JNIEnv* env, jobject obj, 67 VrShell::VrShell(JNIEnv* env,
63 content::ContentViewCore* content_core, 68 jobject obj,
64 ui::WindowAndroid* content_window) 69 content::ContentViewCore* content_cvc,
70 ui::WindowAndroid* content_window,
71 content::ContentViewCore* ui_cvc,
72 ui::WindowAndroid* ui_window)
65 : desktop_screen_tilt_(kDesktopScreenTiltDefault), 73 : desktop_screen_tilt_(kDesktopScreenTiltDefault),
66 desktop_height_(kDesktopHeightDefault), 74 desktop_height_(kDesktopHeightDefault),
67 desktop_position_(kDesktopPositionDefault), 75 desktop_position_(kDesktopPositionDefault),
68 content_cvc_(content_core) { 76 content_cvc_(content_cvc),
77 ui_cvc_(ui_cvc) {
69 j_vr_shell_.Reset(env, obj); 78 j_vr_shell_.Reset(env, obj);
70 content_compositor_view_.reset(new VrCompositor(content_window)); 79 content_compositor_.reset(new VrCompositor(content_window));
80 ui_compositor_.reset(new VrCompositor(ui_window));
81
71 ui_rects_.emplace_back(new ContentRectangle()); 82 ui_rects_.emplace_back(new ContentRectangle());
72 desktop_plane_ = ui_rects_.back().get(); 83 desktop_plane_ = ui_rects_.back().get();
73 desktop_plane_->id = 0; 84 desktop_plane_->id = 0;
74 desktop_plane_->copy_rect = {0.0f, 0.0f, 1.0f, 1.0f}; 85 desktop_plane_->copy_rect = {0.0f, 0.0f, 1.0f, 1.0f};
75 // TODO(cjgrant): If we use the native path for content clicks, fix this. 86 // TODO(cjgrant): If we use the native path for content clicks, fix this.
76 desktop_plane_->window_rect = {0, 0, 0, 0}; 87 desktop_plane_->window_rect = {0, 0, 0, 0};
77 desktop_plane_->translation = {0.0f, 0.0f, 0.0f}; 88 desktop_plane_->translation = {0.0f, 0.0f, 0.0f};
78 desktop_plane_->x_anchoring = XNONE; 89 desktop_plane_->x_anchoring = XNONE;
79 desktop_plane_->y_anchoring = YNONE; 90 desktop_plane_->y_anchoring = YNONE;
80 desktop_plane_->anchor_z = false; 91 desktop_plane_->anchor_z = false;
81 desktop_plane_->orientation_axis_angle = {{1.0f, 0.0f, 0.0f, 0.0f}}; 92 desktop_plane_->orientation_axis_angle = {{1.0f, 0.0f, 0.0f, 0.0f}};
82 desktop_plane_->rotation_axis_angle = {{0.0f, 0.0f, 0.0f, 0.0f}}; 93 desktop_plane_->rotation_axis_angle = {{0.0f, 0.0f, 0.0f, 0.0f}};
83 content_cvc_->GetWebContents()->GetRenderWidgetHostView() 94
84 ->GetRenderWidgetHost()->WasResized(); 95 LoadUIContent();
85 } 96 }
86 97
87 void VrShell::UpdateCompositorLayers(JNIEnv* env, 98 void VrShell::UpdateCompositorLayers(JNIEnv* env,
88 const JavaParamRef<jobject>& obj) { 99 const JavaParamRef<jobject>& obj) {
89 content_compositor_view_->SetLayer(content_cvc_); 100 content_compositor_->SetLayer(content_cvc_);
101 ui_compositor_->SetLayer(ui_cvc_);
90 } 102 }
91 103
92 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { 104 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
93 delete this; 105 delete this;
94 gl::init::ClearGLBindings(); 106 gl::init::ClearGLBindings();
95 } 107 }
96 108
109 void VrShell::LoadUIContent() {
110 GURL url(kVrShellUIURL);
111 ui_cvc_->GetWebContents()->GetController().LoadURL(
112 url, content::Referrer(),
113 ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string(""));
114 }
115
97 bool RegisterVrShell(JNIEnv* env) { 116 bool RegisterVrShell(JNIEnv* env) {
98 return RegisterNativesImpl(env); 117 return RegisterNativesImpl(env);
99 } 118 }
100 119
101 VrShell::~VrShell() { 120 VrShell::~VrShell() {
102 device::GvrDelegateManager::GetInstance()->Shutdown(); 121 device::GvrDelegateManager::GetInstance()->Shutdown();
103 } 122 }
104 123
105 void VrShell::GvrInit(JNIEnv* env, 124 void VrShell::GvrInit(JNIEnv* env,
106 const JavaParamRef<jobject>& obj, 125 const JavaParamRef<jobject>& obj,
107 jlong native_gvr_api) { 126 jlong native_gvr_api) {
108 gvr_api_ = 127 gvr_api_ =
109 gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(native_gvr_api)); 128 gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(native_gvr_api));
110 129
111 device::GvrDelegateManager::GetInstance()->Initialize(this); 130 device::GvrDelegateManager::GetInstance()->Initialize(this);
112 } 131 }
113 132
114 void VrShell::InitializeGl(JNIEnv* env, 133 void VrShell::InitializeGl(JNIEnv* env,
115 const JavaParamRef<jobject>& obj, 134 const JavaParamRef<jobject>& obj,
116 jint texture_data_handle) { 135 jint content_texture_handle,
136 jint ui_texture_handle) {
117 CHECK(gl::GetGLImplementation() != gl::kGLImplementationNone || 137 CHECK(gl::GetGLImplementation() != gl::kGLImplementationNone ||
118 gl::init::InitializeGLOneOff()); 138 gl::init::InitializeGLOneOff());
119 139
120 content_texture_id_ = texture_data_handle; 140 content_texture_id_ = content_texture_handle;
141 ui_texture_id_ = ui_texture_handle;
142
121 gvr_api_->InitializeGl(); 143 gvr_api_->InitializeGl();
122 std::vector<gvr::BufferSpec> specs; 144 std::vector<gvr::BufferSpec> specs;
123 specs.push_back(gvr_api_->CreateBufferSpec()); 145 specs.push_back(gvr_api_->CreateBufferSpec());
124 render_size_ = specs[0].GetSize(); 146 render_size_ = specs[0].GetSize();
125 swap_chain_.reset(new gvr::SwapChain(gvr_api_->CreateSwapchain(specs))); 147 swap_chain_.reset(new gvr::SwapChain(gvr_api_->CreateSwapchain(specs)));
126 148
127 desktop_plane_->content_texture_handle = content_texture_id_; 149 desktop_plane_->content_texture_handle = content_texture_id_;
128 150
129 vr_shell_renderer_.reset(new VrShellRenderer()); 151 vr_shell_renderer_.reset(new VrShellRenderer());
130 buffer_viewport_list_.reset( 152 buffer_viewport_list_.reset(
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 void VrShell::UpdateWebVRTextureBounds( 418 void VrShell::UpdateWebVRTextureBounds(
397 int eye, float left, float top, float width, float height) { 419 int eye, float left, float top, float width, float height) {
398 gvr::Rectf bounds = { left, top, width, height }; 420 gvr::Rectf bounds = { left, top, width, height };
399 vr_shell_renderer_->GetWebVrRenderer()->UpdateTextureBounds(eye, bounds); 421 vr_shell_renderer_->GetWebVrRenderer()->UpdateTextureBounds(eye, bounds);
400 } 422 }
401 423
402 gvr::GvrApi* VrShell::gvr_api() { 424 gvr::GvrApi* VrShell::gvr_api() {
403 return gvr_api_.get(); 425 return gvr_api_.get();
404 } 426 }
405 427
406 void VrShell::ContentSurfaceDestroyed(JNIEnv* env,
407 const JavaParamRef<jobject>& object) {
408 content_compositor_view_->SurfaceDestroyed();
409 }
410
411 void VrShell::ContentSurfaceChanged(JNIEnv* env, 428 void VrShell::ContentSurfaceChanged(JNIEnv* env,
412 const JavaParamRef<jobject>& object, 429 const JavaParamRef<jobject>& object,
413 jint width, 430 jint width,
414 jint height, 431 jint height,
415 const JavaParamRef<jobject>& surface) { 432 const JavaParamRef<jobject>& surface) {
416 content_compositor_view_->SurfaceChanged((int)width, (int)height, surface); 433 content_compositor_->SurfaceChanged((int)width, (int)height, surface);
434 }
435
436 void VrShell::UiSurfaceChanged(JNIEnv* env,
437 const JavaParamRef<jobject>& object,
438 jint width,
439 jint height,
440 const JavaParamRef<jobject>& surface) {
441 ui_compositor_->SurfaceChanged((int)width, (int)height, surface);
417 } 442 }
418 443
419 void VrShell::UpdateTransforms(float screen_width_meters, 444 void VrShell::UpdateTransforms(float screen_width_meters,
420 float screen_height_meters, 445 float screen_height_meters,
421 float screen_tilt) { 446 float screen_tilt) {
422 for (std::unique_ptr<ContentRectangle>& rect : ui_rects_) { 447 for (std::unique_ptr<ContentRectangle>& rect : ui_rects_) {
423 rect->transform.MakeIdentity(); 448 rect->transform.MakeIdentity();
424 rect->transform.Scale(rect->size.x, rect->size.y, rect->size.z); 449 rect->transform.Scale(rect->size.x, rect->size.y, rect->size.z);
425 float x_anchor_translate; 450 float x_anchor_translate;
426 switch (rect->x_anchoring) { 451 switch (rect->x_anchoring) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 } 487 }
463 } 488 }
464 489
465 // ---------------------------------------------------------------------------- 490 // ----------------------------------------------------------------------------
466 // Native JNI methods 491 // Native JNI methods
467 // ---------------------------------------------------------------------------- 492 // ----------------------------------------------------------------------------
468 493
469 jlong Init(JNIEnv* env, 494 jlong Init(JNIEnv* env,
470 const JavaParamRef<jobject>& obj, 495 const JavaParamRef<jobject>& obj,
471 const JavaParamRef<jobject>& content_web_contents, 496 const JavaParamRef<jobject>& content_web_contents,
472 jlong content_window_android) { 497 jlong content_window_android,
498 const JavaParamRef<jobject>& ui_web_contents,
499 jlong ui_window_android) {
473 content::ContentViewCore* c_core = content::ContentViewCore::FromWebContents( 500 content::ContentViewCore* c_core = content::ContentViewCore::FromWebContents(
474 content::WebContents::FromJavaWebContents(content_web_contents)); 501 content::WebContents::FromJavaWebContents(content_web_contents));
502 content::ContentViewCore* ui_core = content::ContentViewCore::FromWebContents(
503 content::WebContents::FromJavaWebContents(ui_web_contents));
475 return reinterpret_cast<intptr_t>(new VrShell( 504 return reinterpret_cast<intptr_t>(new VrShell(
476 env, obj, c_core, 505 env, obj, c_core,
477 reinterpret_cast<ui::WindowAndroid*>(content_window_android))); 506 reinterpret_cast<ui::WindowAndroid*>(content_window_android), ui_core,
507 reinterpret_cast<ui::WindowAndroid*>(ui_window_android)));
478 } 508 }
479 509
480 } // namespace vr_shell 510 } // namespace vr_shell
OLDNEW
« chrome/browser/android/vr_shell/vr_shell.h ('K') | « chrome/browser/android/vr_shell/vr_shell.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698