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

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

Issue 2343023002: Switch WebVR to handle GvrApi management through VrShellDelegate (Closed)
Patch Set: Addressed tedchoc@'s last feedback Created 4 years, 3 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_delegate.h"
12 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" 13 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h"
13 #include "content/public/browser/android/content_view_core.h" 14 #include "content/public/browser/android/content_view_core.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"
17 #include "jni/VrShell_jni.h" 18 #include "jni/VrShell_jni.h"
18 #include "ui/android/view_android.h" 19 #include "ui/android/view_android.h"
19 #include "ui/android/window_android.h" 20 #include "ui/android/window_android.h"
20 #include "ui/gl/gl_bindings.h" 21 #include "ui/gl/gl_bindings.h"
21 #include "ui/gl/init/gl_factory.h" 22 #include "ui/gl/init/gl_factory.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } // namespace 59 } // namespace
59 60
60 namespace vr_shell { 61 namespace vr_shell {
61 62
62 VrShell::VrShell(JNIEnv* env, jobject obj, 63 VrShell::VrShell(JNIEnv* env, jobject obj,
63 content::ContentViewCore* content_core, 64 content::ContentViewCore* content_core,
64 ui::WindowAndroid* content_window) 65 ui::WindowAndroid* content_window)
65 : desktop_screen_tilt_(kDesktopScreenTiltDefault), 66 : desktop_screen_tilt_(kDesktopScreenTiltDefault),
66 desktop_height_(kDesktopHeightDefault), 67 desktop_height_(kDesktopHeightDefault),
67 desktop_position_(kDesktopPositionDefault), 68 desktop_position_(kDesktopPositionDefault),
68 content_cvc_(content_core) { 69 content_cvc_(content_core),
70 delegate_(nullptr) {
69 j_vr_shell_.Reset(env, obj); 71 j_vr_shell_.Reset(env, obj);
70 content_compositor_view_.reset(new VrCompositor(content_window)); 72 content_compositor_view_.reset(new VrCompositor(content_window));
71 ui_rects_.emplace_back(new ContentRectangle()); 73 ui_rects_.emplace_back(new ContentRectangle());
72 desktop_plane_ = ui_rects_.back().get(); 74 desktop_plane_ = ui_rects_.back().get();
73 desktop_plane_->id = 0; 75 desktop_plane_->id = 0;
74 desktop_plane_->copy_rect = {0.0f, 0.0f, 1.0f, 1.0f}; 76 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. 77 // TODO(cjgrant): If we use the native path for content clicks, fix this.
76 desktop_plane_->window_rect = {0, 0, 0, 0}; 78 desktop_plane_->window_rect = {0, 0, 0, 0};
77 desktop_plane_->translation = {0.0f, 0.0f, 0.0f}; 79 desktop_plane_->translation = {0.0f, 0.0f, 0.0f};
78 desktop_plane_->x_anchoring = XNONE; 80 desktop_plane_->x_anchoring = XNONE;
(...skipping 13 matching lines...) Expand all
92 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { 94 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
93 delete this; 95 delete this;
94 gl::init::ClearGLBindings(); 96 gl::init::ClearGLBindings();
95 } 97 }
96 98
97 bool RegisterVrShell(JNIEnv* env) { 99 bool RegisterVrShell(JNIEnv* env) {
98 return RegisterNativesImpl(env); 100 return RegisterNativesImpl(env);
99 } 101 }
100 102
101 VrShell::~VrShell() { 103 VrShell::~VrShell() {
102 device::GvrDelegateManager::GetInstance()->Shutdown(); 104 }
105
106 void VrShell::SetDelegate(JNIEnv* env,
107 const base::android::JavaParamRef<jobject>& obj,
108 const base::android::JavaParamRef<jobject>& delegate) {
109 delegate_ = VrShellDelegate::getNativePointer(env, delegate);
Ted C 2016/09/21 17:59:25 getNativeDelegate seems like a clearer name to me
103 } 110 }
104 111
105 void VrShell::GvrInit(JNIEnv* env, 112 void VrShell::GvrInit(JNIEnv* env,
106 const JavaParamRef<jobject>& obj, 113 const JavaParamRef<jobject>& obj,
107 jlong native_gvr_api) { 114 jlong native_gvr_api) {
108 gvr_api_ = 115 gvr_api_ =
109 gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(native_gvr_api)); 116 gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(native_gvr_api));
110 117
111 device::GvrDelegateManager::GetInstance()->Initialize(this); 118 if (delegate_)
119 delegate_->OnVrShellReady(this);
112 } 120 }
113 121
114 void VrShell::InitializeGl(JNIEnv* env, 122 void VrShell::InitializeGl(JNIEnv* env,
115 const JavaParamRef<jobject>& obj, 123 const JavaParamRef<jobject>& obj,
116 jint texture_data_handle) { 124 jint texture_data_handle) {
117 CHECK(gl::GetGLImplementation() != gl::kGLImplementationNone || 125 CHECK(gl::GetGLImplementation() != gl::kGLImplementationNone ||
118 gl::init::InitializeGLOneOff()); 126 gl::init::InitializeGLOneOff());
119 127
120 content_texture_id_ = texture_data_handle; 128 content_texture_id_ = texture_data_handle;
121 gvr_api_->InitializeGl(); 129 gvr_api_->InitializeGl();
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 } 383 }
376 384
377 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { 385 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) {
378 if (gvr_api_ == nullptr) 386 if (gvr_api_ == nullptr)
379 return; 387 return;
380 388
381 gvr_api_->RefreshViewerProfile(); 389 gvr_api_->RefreshViewerProfile();
382 gvr_api_->ResumeTracking(); 390 gvr_api_->ResumeTracking();
383 } 391 }
384 392
385 void VrShell::RequestWebVRPresent() { 393 void VrShell::SetWebVrMode(JNIEnv* env,
386 webvr_mode_ = true; 394 const base::android::JavaParamRef<jobject>& obj,
387 } 395 bool enabled) {
388 396 webvr_mode_ = enabled;
389 void VrShell::ExitWebVRPresent() {
390 webvr_mode_ = false;
391 } 397 }
392 398
393 void VrShell::SubmitWebVRFrame() { 399 void VrShell::SubmitWebVRFrame() {
394 } 400 }
395 401
396 void VrShell::UpdateWebVRTextureBounds( 402 void VrShell::UpdateWebVRTextureBounds(
397 int eye, float left, float top, float width, float height) { 403 int eye, float left, float top, float width, float height) {
398 gvr::Rectf bounds = { left, top, width, height }; 404 gvr::Rectf bounds = { left, top, width, height };
399 vr_shell_renderer_->GetWebVrRenderer()->UpdateTextureBounds(eye, bounds); 405 vr_shell_renderer_->GetWebVrRenderer()->UpdateTextureBounds(eye, bounds);
400 } 406 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 const JavaParamRef<jobject>& content_web_contents, 477 const JavaParamRef<jobject>& content_web_contents,
472 jlong content_window_android) { 478 jlong content_window_android) {
473 content::ContentViewCore* c_core = content::ContentViewCore::FromWebContents( 479 content::ContentViewCore* c_core = content::ContentViewCore::FromWebContents(
474 content::WebContents::FromJavaWebContents(content_web_contents)); 480 content::WebContents::FromJavaWebContents(content_web_contents));
475 return reinterpret_cast<intptr_t>(new VrShell( 481 return reinterpret_cast<intptr_t>(new VrShell(
476 env, obj, c_core, 482 env, obj, c_core,
477 reinterpret_cast<ui::WindowAndroid*>(content_window_android))); 483 reinterpret_cast<ui::WindowAndroid*>(content_window_android)));
478 } 484 }
479 485
480 } // namespace vr_shell 486 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698