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

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: Refactoring for cleanup and to address comments. 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 bool VrShell::GetWebVrMode(JNIEnv* env, const JavaParamRef<jobject>& obj) { 275 bool VrShell::GetWebVrMode(JNIEnv* env, const JavaParamRef<jobject>& obj) {
279 return webvr_mode_; 276 return webvr_mode_;
280 } 277 }
281 278
282 void VrShell::OnLoadProgressChanged(JNIEnv* env, 279 void VrShell::OnLoadProgressChanged(JNIEnv* env,
283 const JavaParamRef<jobject>& obj, 280 const JavaParamRef<jobject>& obj,
284 double progress) { 281 double progress) {
285 ui_->SetLoadProgress(progress); 282 ui_->SetLoadProgress(progress);
286 } 283 }
287 284
288 void VrShell::OnTabListCreated(JNIEnv* env, 285 void VrShell::OnTabListCreated(JNIEnv* env,
289 const JavaParamRef<jobject>& obj, 286 const JavaParamRef<jobject>& obj,
290 jobjectArray tabs, 287 jobjectArray tabs,
291 jobjectArray incognito_tabs) { 288 jobjectArray incognito_tabs) {
292 ui_->InitTabList();
293 ProcessTabArray(env, tabs, false); 289 ProcessTabArray(env, tabs, false);
294 ProcessTabArray(env, incognito_tabs, true); 290 ProcessTabArray(env, incognito_tabs, true);
295 ui_->FlushTabList(); 291 ui_->FlushTabList();
296 } 292 }
297 293
298 void VrShell::ProcessTabArray(JNIEnv* env, jobjectArray tabs, bool incognito) { 294 void VrShell::ProcessTabArray(JNIEnv* env, jobjectArray tabs, bool incognito) {
299 size_t len = env->GetArrayLength(tabs); 295 size_t len = env->GetArrayLength(tabs);
300 for (size_t i = 0; i < len; ++i) { 296 for (size_t i = 0; i < len; ++i) {
301 jobject jtab = env->GetObjectArrayElement(tabs, i); 297 jobject jtab = env->GetObjectArrayElement(tabs, i);
302 TabAndroid* tab = 298 TabAndroid* tab =
(...skipping 13 matching lines...) Expand all
316 } 312 }
317 313
318 void VrShell::OnTabRemoved(JNIEnv* env, 314 void VrShell::OnTabRemoved(JNIEnv* env,
319 const JavaParamRef<jobject>& obj, 315 const JavaParamRef<jobject>& obj,
320 jboolean incognito, 316 jboolean incognito,
321 jint id) { 317 jint id) {
322 ui_->RemoveTab(incognito, id); 318 ui_->RemoveTab(incognito, id);
323 } 319 }
324 320
325 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { 321 void VrShell::SetWebVRSecureOrigin(bool secure_origin) {
326 PostToGlThreadWhenReady(base::Bind(&UiSceneManager::SetWebVRSecureOrigin, 322 ui_->SetWebVrSecureOrigin(secure_origin);
327 gl_thread_->GetSceneManager(),
328 secure_origin));
329 } 323 }
330 324
331 void VrShell::SubmitWebVRFrame(int16_t frame_index, 325 void VrShell::SubmitWebVRFrame(int16_t frame_index,
332 const gpu::MailboxHolder& mailbox) { 326 const gpu::MailboxHolder& mailbox) {
333 TRACE_EVENT1("gpu", "SubmitWebVRFrame", "frame", frame_index); 327 TRACE_EVENT1("gpu", "SubmitWebVRFrame", "frame", frame_index);
334 328
335 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SubmitWebVRFrame, 329 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SubmitWebVRFrame,
336 gl_thread_->GetVrShellGl(), frame_index, 330 gl_thread_->GetVrShellGl(), frame_index,
337 mailbox)); 331 mailbox));
338 } 332 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 content_surface_ = surface; 387 content_surface_ = surface;
394 compositor_->SurfaceChanged(surface); 388 compositor_->SurfaceChanged(surface);
395 JNIEnv* env = base::android::AttachCurrentThread(); 389 JNIEnv* env = base::android::AttachCurrentThread();
396 Java_VrShellImpl_contentSurfaceChanged(env, j_vr_shell_.obj()); 390 Java_VrShellImpl_contentSurfaceChanged(env, j_vr_shell_.obj());
397 } 391 }
398 392
399 void VrShell::GvrDelegateReady() { 393 void VrShell::GvrDelegateReady() {
400 delegate_provider_->SetPresentingDelegate(this, gvr_api_); 394 delegate_provider_->SetPresentingDelegate(this, gvr_api_);
401 } 395 }
402 396
403 void VrShell::AppButtonGesturePerformed(UiInterface::Direction direction) {
404 if (vr_shell_enabled_)
405 ui_->HandleAppButtonGesturePerformed(direction);
406 }
407
408 void VrShell::ContentPhysicalBoundsChanged(JNIEnv* env, 397 void VrShell::ContentPhysicalBoundsChanged(JNIEnv* env,
409 const JavaParamRef<jobject>& object, 398 const JavaParamRef<jobject>& object,
410 jint width, 399 jint width,
411 jint height, 400 jint height,
412 jfloat dpr) { 401 jfloat dpr) {
413 TRACE_EVENT0("gpu", "VrShell::ContentPhysicalBoundsChanged"); 402 TRACE_EVENT0("gpu", "VrShell::ContentPhysicalBoundsChanged");
414 // TODO(acondor): Set the device scale factor for font rendering on the 403 // TODO(acondor): Set the device scale factor for font rendering on the
415 // VR Shell textures. 404 // VR Shell textures.
416 PostToGlThreadWhenReady(base::Bind(&VrShellGl::ContentPhysicalBoundsChanged, 405 PostToGlThreadWhenReady(base::Bind(&VrShellGl::ContentPhysicalBoundsChanged,
417 gl_thread_->GetVrShellGl(), width, 406 gl_thread_->GetVrShellGl(), width,
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 jlong gvr_api, 550 jlong gvr_api,
562 jboolean reprojected_rendering) { 551 jboolean reprojected_rendering) {
563 return reinterpret_cast<intptr_t>(new VrShell( 552 return reinterpret_cast<intptr_t>(new VrShell(
564 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), 553 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android),
565 for_web_vr, in_cct, 554 for_web_vr, in_cct,
566 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), 555 VrShellDelegate::GetNativeVrShellDelegate(env, delegate),
567 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); 556 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering));
568 } 557 }
569 558
570 } // namespace vr_shell 559 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698