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

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

Issue 2866853002: VR: Wire VrShell UI-related state to the scene manager. (Closed)
Patch Set: Rebase; remove now-unused source file. Created 3 years, 7 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>
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "jni/VrShellImpl_jni.h" 45 #include "jni/VrShellImpl_jni.h"
46 #include "third_party/WebKit/public/platform/WebInputEvent.h" 46 #include "third_party/WebKit/public/platform/WebInputEvent.h"
47 #include "ui/android/view_android.h" 47 #include "ui/android/view_android.h"
48 #include "ui/android/window_android.h" 48 #include "ui/android/window_android.h"
49 #include "ui/base/page_transition_types.h" 49 #include "ui/base/page_transition_types.h"
50 #include "ui/display/display.h" 50 #include "ui/display/display.h"
51 #include "ui/display/screen.h" 51 #include "ui/display/screen.h"
52 #include "ui/gfx/codec/png_codec.h" 52 #include "ui/gfx/codec/png_codec.h"
53 #include "ui/gfx/geometry/size.h" 53 #include "ui/gfx/geometry/size.h"
54 #include "ui/gfx/native_widget_types.h" 54 #include "ui/gfx/native_widget_types.h"
55 #include "url/gurl.h"
55 56
56 using base::android::JavaParamRef; 57 using base::android::JavaParamRef;
57 using base::android::JavaRef; 58 using base::android::JavaRef;
58 59
59 namespace vr_shell { 60 namespace vr_shell {
60 61
61 namespace { 62 namespace {
62 vr_shell::VrShell* g_instance; 63 vr_shell::VrShell* g_instance;
63 64
64 void SetIsInVR(content::WebContents* contents, bool is_in_vr) { 65 void SetIsInVR(content::WebContents* contents, bool is_in_vr) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 gvr_api_(gvr_api), 97 gvr_api_(gvr_api),
97 weak_ptr_factory_(this) { 98 weak_ptr_factory_(this) {
98 DVLOG(1) << __FUNCTION__ << "=" << this; 99 DVLOG(1) << __FUNCTION__ << "=" << this;
99 DCHECK(g_instance == nullptr); 100 DCHECK(g_instance == nullptr);
100 g_instance = this; 101 g_instance = this;
101 j_vr_shell_.Reset(env, obj); 102 j_vr_shell_.Reset(env, obj);
102 103
103 gl_thread_ = base::MakeUnique<VrGLThread>( 104 gl_thread_ = base::MakeUnique<VrGLThread>(
104 weak_ptr_factory_.GetWeakPtr(), main_thread_task_runner_, gvr_api, 105 weak_ptr_factory_.GetWeakPtr(), main_thread_task_runner_, gvr_api,
105 for_web_vr, in_cct, reprojected_rendering_); 106 for_web_vr, in_cct, reprojected_rendering_);
107 ui_ = gl_thread_.get();
106 108
107 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0); 109 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0);
108 options.priority = base::ThreadPriority::DISPLAY; 110 options.priority = base::ThreadPriority::DISPLAY;
109 gl_thread_->StartWithOptions(options); 111 gl_thread_->StartWithOptions(options);
110 112
111 ui_ = base::MakeUnique<UiInterface>(for_web_vr ? UiInterface::Mode::WEB_VR
112 : UiInterface::Mode::STANDARD);
113 113
114 content::BrowserThread::PostTask( 114 content::BrowserThread::PostTask(
115 content::BrowserThread::FILE, FROM_HERE, 115 content::BrowserThread::FILE, FROM_HERE,
116 base::Bind(LoadControllerModelTask, weak_ptr_factory_.GetWeakPtr(), 116 base::Bind(LoadControllerModelTask, weak_ptr_factory_.GetWeakPtr(),
117 main_thread_task_runner_)); 117 main_thread_task_runner_));
118 } 118 }
119 119
120 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { 120 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
121 delete this; 121 delete this;
122 } 122 }
(...skipping 21 matching lines...) Expand all
144 android_ui_gesture_target_ = base::MakeUnique<AndroidUiGestureTarget>( 144 android_ui_gesture_target_ = base::MakeUnique<AndroidUiGestureTarget>(
145 j_motion_event_synthesizer_.obj(), 145 j_motion_event_synthesizer_.obj(),
146 Java_VrShellImpl_getNativePageScrollRatio(env, j_vr_shell_.obj())); 146 Java_VrShellImpl_getNativePageScrollRatio(env, j_vr_shell_.obj()));
147 input_manager_ = nullptr; 147 input_manager_ = nullptr;
148 vr_web_contents_observer_ = nullptr; 148 vr_web_contents_observer_ = nullptr;
149 metrics_helper_ = nullptr; 149 metrics_helper_ = nullptr;
150 return; 150 return;
151 } 151 }
152 input_manager_ = base::MakeUnique<VrInputManager>(web_contents_); 152 input_manager_ = base::MakeUnique<VrInputManager>(web_contents_);
153 vr_web_contents_observer_ = 153 vr_web_contents_observer_ =
154 base::MakeUnique<VrWebContentsObserver>(web_contents_, ui_.get(), this); 154 base::MakeUnique<VrWebContentsObserver>(web_contents_, ui_, this);
155 // TODO(billorr): Make VrMetricsHelper tab-aware and able to track multiple 155 // TODO(billorr): Make VrMetricsHelper tab-aware and able to track multiple
156 // tabs. crbug.com/684661 156 // tabs. crbug.com/684661
157 metrics_helper_ = base::MakeUnique<VrMetricsHelper>(web_contents_); 157 metrics_helper_ = base::MakeUnique<VrMetricsHelper>(web_contents_);
158 metrics_helper_->SetVRActive(true); 158 metrics_helper_->SetVRActive(true);
159 metrics_helper_->SetWebVREnabled(webvr_mode_); 159 metrics_helper_->SetWebVREnabled(webvr_mode_);
160 } 160 }
161 161
162 void VrShell::SetUiState() { 162 void VrShell::SetUiState() {
163 if (!web_contents_) { 163 if (!web_contents_) {
164 // TODO(mthiesse): Properly handle native page URLs. 164 // TODO(mthiesse): Properly handle native page URLs.
165 ui_->SetURL(GURL()); 165 ui_->SetURL(GURL());
166 ui_->SetLoading(false); 166 ui_->SetLoading(false);
167 ui_->SetFullscreen(false); 167 ui_->SetFullscreen(false);
168 ui_->SetURL(GURL());
168 } else { 169 } else {
169 ui_->SetURL(web_contents_->GetVisibleURL()); 170 ui_->SetURL(web_contents_->GetVisibleURL());
170 ui_->SetLoading(web_contents_->IsLoading()); 171 ui_->SetLoading(web_contents_->IsLoading());
171 ui_->SetFullscreen(web_contents_->IsFullscreen()); 172 ui_->SetFullscreen(web_contents_->IsFullscreen());
172 } 173 }
173 } 174 }
174 175
175 bool RegisterVrShell(JNIEnv* env) { 176 bool RegisterVrShell(JNIEnv* env) {
176 return RegisterNativesImpl(env); 177 return RegisterNativesImpl(env);
177 } 178 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 } 262 }
262 263
263 void VrShell::SetWebVrMode(JNIEnv* env, 264 void VrShell::SetWebVrMode(JNIEnv* env,
264 const JavaParamRef<jobject>& obj, 265 const JavaParamRef<jobject>& obj,
265 bool enabled) { 266 bool enabled) {
266 webvr_mode_ = enabled; 267 webvr_mode_ = enabled;
267 if (metrics_helper_) 268 if (metrics_helper_)
268 metrics_helper_->SetWebVREnabled(enabled); 269 metrics_helper_->SetWebVREnabled(enabled);
269 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetWebVrMode, 270 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetWebVrMode,
270 gl_thread_->GetVrShellGl(), enabled)); 271 gl_thread_->GetVrShellGl(), enabled));
271 272 ui_->SetWebVrMode(enabled);
272 ui_->SetMode(enabled ? UiInterface::Mode::WEB_VR
273 : UiInterface::Mode::STANDARD);
274 PostToGlThreadWhenReady(base::Bind(&UiSceneManager::SetWebVRMode,
275 gl_thread_->GetSceneManager(), enabled));
276 } 273 }
277 274
278 void VrShell::OnFullscreenChanged(bool enabled) { 275 void VrShell::OnFullscreenChanged(bool enabled) {
279 JNIEnv* env = base::android::AttachCurrentThread(); 276 JNIEnv* env = base::android::AttachCurrentThread();
280 Java_VrShellImpl_onFullscreenChanged(env, j_vr_shell_.obj(), enabled); 277 Java_VrShellImpl_onFullscreenChanged(env, j_vr_shell_.obj(), enabled);
281 278 ui_->SetFullscreen(enabled);
282 PostToGlThreadWhenReady(base::Bind(&UiSceneManager::OnFullscreenChanged,
283 gl_thread_->GetSceneManager(), enabled));
284 } 279 }
285 280
286 bool VrShell::GetWebVrMode(JNIEnv* env, const JavaParamRef<jobject>& obj) { 281 bool VrShell::GetWebVrMode(JNIEnv* env, const JavaParamRef<jobject>& obj) {
287 return webvr_mode_; 282 return webvr_mode_;
288 } 283 }
289 284
290 void VrShell::OnLoadProgressChanged(JNIEnv* env, 285 void VrShell::OnLoadProgressChanged(JNIEnv* env,
291 const JavaParamRef<jobject>& obj, 286 const JavaParamRef<jobject>& obj,
292 double progress) { 287 double progress) {
293 ui_->SetLoadProgress(progress); 288 ui_->SetLoadProgress(progress);
294 } 289 }
295 290
296 void VrShell::OnTabListCreated(JNIEnv* env, 291 void VrShell::OnTabListCreated(JNIEnv* env,
297 const JavaParamRef<jobject>& obj, 292 const JavaParamRef<jobject>& obj,
298 jobjectArray tabs, 293 jobjectArray tabs,
299 jobjectArray incognito_tabs) { 294 jobjectArray incognito_tabs) {
300 ui_->InitTabList();
301 ProcessTabArray(env, tabs, false); 295 ProcessTabArray(env, tabs, false);
302 ProcessTabArray(env, incognito_tabs, true); 296 ProcessTabArray(env, incognito_tabs, true);
303 ui_->FlushTabList(); 297 ui_->FlushTabList();
304 } 298 }
305 299
306 void VrShell::ProcessTabArray(JNIEnv* env, jobjectArray tabs, bool incognito) { 300 void VrShell::ProcessTabArray(JNIEnv* env, jobjectArray tabs, bool incognito) {
307 size_t len = env->GetArrayLength(tabs); 301 size_t len = env->GetArrayLength(tabs);
308 for (size_t i = 0; i < len; ++i) { 302 for (size_t i = 0; i < len; ++i) {
309 jobject jtab = env->GetObjectArrayElement(tabs, i); 303 jobject jtab = env->GetObjectArrayElement(tabs, i);
310 TabAndroid* tab = 304 TabAndroid* tab =
(...skipping 13 matching lines...) Expand all
324 } 318 }
325 319
326 void VrShell::OnTabRemoved(JNIEnv* env, 320 void VrShell::OnTabRemoved(JNIEnv* env,
327 const JavaParamRef<jobject>& obj, 321 const JavaParamRef<jobject>& obj,
328 jboolean incognito, 322 jboolean incognito,
329 jint id) { 323 jint id) {
330 ui_->RemoveTab(incognito, id); 324 ui_->RemoveTab(incognito, id);
331 } 325 }
332 326
333 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { 327 void VrShell::SetWebVRSecureOrigin(bool secure_origin) {
334 PostToGlThreadWhenReady(base::Bind(&UiSceneManager::SetWebVRSecureOrigin, 328 ui_->SetWebVrSecureOrigin(secure_origin);
335 gl_thread_->GetSceneManager(),
336 secure_origin));
337 } 329 }
338 330
339 void VrShell::SubmitWebVRFrame(int16_t frame_index, 331 void VrShell::SubmitWebVRFrame(int16_t frame_index,
340 const gpu::MailboxHolder& mailbox) { 332 const gpu::MailboxHolder& mailbox) {
341 TRACE_EVENT1("gpu", "SubmitWebVRFrame", "frame", frame_index); 333 TRACE_EVENT1("gpu", "SubmitWebVRFrame", "frame", frame_index);
342 334
343 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SubmitWebVRFrame, 335 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SubmitWebVRFrame,
344 gl_thread_->GetVrShellGl(), frame_index, 336 gl_thread_->GetVrShellGl(), frame_index,
345 mailbox)); 337 mailbox));
346 } 338 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 content_surface_ = surface; 393 content_surface_ = surface;
402 compositor_->SurfaceChanged(surface); 394 compositor_->SurfaceChanged(surface);
403 JNIEnv* env = base::android::AttachCurrentThread(); 395 JNIEnv* env = base::android::AttachCurrentThread();
404 Java_VrShellImpl_contentSurfaceChanged(env, j_vr_shell_.obj()); 396 Java_VrShellImpl_contentSurfaceChanged(env, j_vr_shell_.obj());
405 } 397 }
406 398
407 void VrShell::GvrDelegateReady() { 399 void VrShell::GvrDelegateReady() {
408 delegate_provider_->SetPresentingDelegate(this, gvr_api_); 400 delegate_provider_->SetPresentingDelegate(this, gvr_api_);
409 } 401 }
410 402
411 void VrShell::AppButtonGesturePerformed(UiInterface::Direction direction) {
412 if (vr_shell_enabled_)
413 ui_->HandleAppButtonGesturePerformed(direction);
414 }
415
416 void VrShell::ContentPhysicalBoundsChanged(JNIEnv* env, 403 void VrShell::ContentPhysicalBoundsChanged(JNIEnv* env,
417 const JavaParamRef<jobject>& object, 404 const JavaParamRef<jobject>& object,
418 jint width, 405 jint width,
419 jint height, 406 jint height,
420 jfloat dpr) { 407 jfloat dpr) {
421 TRACE_EVENT0("gpu", "VrShell::ContentPhysicalBoundsChanged"); 408 TRACE_EVENT0("gpu", "VrShell::ContentPhysicalBoundsChanged");
422 // TODO(acondor): Set the device scale factor for font rendering on the 409 // TODO(acondor): Set the device scale factor for font rendering on the
423 // VR Shell textures. 410 // VR Shell textures.
424 PostToGlThreadWhenReady(base::Bind(&VrShellGl::ContentPhysicalBoundsChanged, 411 PostToGlThreadWhenReady(base::Bind(&VrShellGl::ContentPhysicalBoundsChanged,
425 gl_thread_->GetVrShellGl(), width, 412 gl_thread_->GetVrShellGl(), width,
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 jlong gvr_api, 556 jlong gvr_api,
570 jboolean reprojected_rendering) { 557 jboolean reprojected_rendering) {
571 return reinterpret_cast<intptr_t>(new VrShell( 558 return reinterpret_cast<intptr_t>(new VrShell(
572 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), 559 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android),
573 for_web_vr, in_cct, 560 for_web_vr, in_cct,
574 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), 561 VrShellDelegate::GetNativeVrShellDelegate(env, delegate),
575 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); 562 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering));
576 } 563 }
577 564
578 } // namespace vr_shell 565 } // 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.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698