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

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: 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 30 matching lines...) Expand all
95 gvr_api_(gvr_api), 96 gvr_api_(gvr_api),
96 weak_ptr_factory_(this) { 97 weak_ptr_factory_(this) {
97 DVLOG(1) << __FUNCTION__ << "=" << this; 98 DVLOG(1) << __FUNCTION__ << "=" << this;
98 DCHECK(g_instance == nullptr); 99 DCHECK(g_instance == nullptr);
99 g_instance = this; 100 g_instance = this;
100 j_vr_shell_.Reset(env, obj); 101 j_vr_shell_.Reset(env, obj);
101 102
102 gl_thread_ = base::MakeUnique<VrGLThread>(weak_ptr_factory_.GetWeakPtr(), 103 gl_thread_ = base::MakeUnique<VrGLThread>(weak_ptr_factory_.GetWeakPtr(),
103 main_thread_task_runner_, gvr_api, 104 main_thread_task_runner_, gvr_api,
104 for_web_vr, reprojected_rendering_); 105 for_web_vr, reprojected_rendering_);
106 ui_ = gl_thread_.get();
105 107
106 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0); 108 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0);
107 options.priority = base::ThreadPriority::DISPLAY; 109 options.priority = base::ThreadPriority::DISPLAY;
108 gl_thread_->StartWithOptions(options); 110 gl_thread_->StartWithOptions(options);
109 111
110 ui_ = base::MakeUnique<UiInterface>(for_web_vr ? UiInterface::Mode::WEB_VR
111 : UiInterface::Mode::STANDARD);
112 112
113 content::BrowserThread::PostTask( 113 content::BrowserThread::PostTask(
114 content::BrowserThread::FILE, FROM_HERE, 114 content::BrowserThread::FILE, FROM_HERE,
115 base::Bind(LoadControllerModelTask, weak_ptr_factory_.GetWeakPtr(), 115 base::Bind(LoadControllerModelTask, weak_ptr_factory_.GetWeakPtr(),
116 main_thread_task_runner_)); 116 main_thread_task_runner_));
117 } 117 }
118 118
119 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { 119 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
120 delete this; 120 delete this;
121 } 121 }
(...skipping 21 matching lines...) Expand all
143 android_ui_gesture_target_ = base::MakeUnique<AndroidUiGestureTarget>( 143 android_ui_gesture_target_ = base::MakeUnique<AndroidUiGestureTarget>(
144 j_motion_event_synthesizer_.obj(), 144 j_motion_event_synthesizer_.obj(),
145 Java_VrShellImpl_getNativePageScrollRatio(env, j_vr_shell_.obj())); 145 Java_VrShellImpl_getNativePageScrollRatio(env, j_vr_shell_.obj()));
146 input_manager_ = nullptr; 146 input_manager_ = nullptr;
147 vr_web_contents_observer_ = nullptr; 147 vr_web_contents_observer_ = nullptr;
148 metrics_helper_ = nullptr; 148 metrics_helper_ = nullptr;
149 return; 149 return;
150 } 150 }
151 input_manager_ = base::MakeUnique<VrInputManager>(web_contents_); 151 input_manager_ = base::MakeUnique<VrInputManager>(web_contents_);
152 vr_web_contents_observer_ = 152 vr_web_contents_observer_ =
153 base::MakeUnique<VrWebContentsObserver>(web_contents_, ui_.get(), this); 153 base::MakeUnique<VrWebContentsObserver>(web_contents_, ui_, this);
154 // TODO(billorr): Make VrMetricsHelper tab-aware and able to track multiple 154 // TODO(billorr): Make VrMetricsHelper tab-aware and able to track multiple
155 // tabs. crbug.com/684661 155 // tabs. crbug.com/684661
156 metrics_helper_ = base::MakeUnique<VrMetricsHelper>(web_contents_); 156 metrics_helper_ = base::MakeUnique<VrMetricsHelper>(web_contents_);
157 metrics_helper_->SetVRActive(true); 157 metrics_helper_->SetVRActive(true);
158 metrics_helper_->SetWebVREnabled(webvr_mode_); 158 metrics_helper_->SetWebVREnabled(webvr_mode_);
159 } 159 }
160 160
161 void VrShell::SetUiState() { 161 void VrShell::SetUiState() {
162 if (!web_contents_) { 162 if (!web_contents_) {
163 // TODO(mthiesse): Properly handle native page URLs. 163 // TODO(mthiesse): Properly handle native page URLs.
164 ui_->SetURL(GURL()); 164 ui_->SetURL(GURL());
165 ui_->SetLoading(false); 165 ui_->SetLoading(false);
166 ui_->SetFullscreen(false); 166 ui_->SetFullscreen(false);
167 ui_->SetURL(GURL());
167 } else { 168 } else {
168 ui_->SetURL(web_contents_->GetVisibleURL()); 169 ui_->SetURL(web_contents_->GetVisibleURL());
169 ui_->SetLoading(web_contents_->IsLoading()); 170 ui_->SetLoading(web_contents_->IsLoading());
170 ui_->SetFullscreen(web_contents_->IsFullscreen()); 171 ui_->SetFullscreen(web_contents_->IsFullscreen());
171 } 172 }
172 } 173 }
173 174
174 bool RegisterVrShell(JNIEnv* env) { 175 bool RegisterVrShell(JNIEnv* env) {
175 return RegisterNativesImpl(env); 176 return RegisterNativesImpl(env);
176 } 177 }
(...skipping 17 matching lines...) Expand all
194 // that IO is allowed to prevent jank, but there shouldn't be any concerns 195 // that IO is allowed to prevent jank, but there shouldn't be any concerns
195 // regarding jank in this case, because we're switching from 3D to 2D, 196 // regarding jank in this case, because we're switching from 3D to 2D,
196 // adding/removing a bunch of Java views, and probably changing device 197 // adding/removing a bunch of Java views, and probably changing device
197 // orientation here. 198 // orientation here.
198 base::ThreadRestrictions::ScopedAllowIO allow_io; 199 base::ThreadRestrictions::ScopedAllowIO allow_io;
199 gl_thread_.reset(); 200 gl_thread_.reset();
200 } 201 }
201 g_instance = nullptr; 202 g_instance = nullptr;
202 } 203 }
203 204
204 void VrShell::PostToGlThreadWhenReady(const base::Closure& task) { 205 void VrShell::PostToGlThreadWhenReady(const base::Closure& task) {
ymalik 2017/05/08 14:05:00 If we're encapsulating the calls between vr shell
cjgrant 2017/05/08 14:14:37 I thought about that, and didn't for the following
mthiesse 2017/05/08 16:04:55 A future CL should probably add another interface
amp 2017/05/08 18:30:11 +1, it was confusing to see VrShellGl as the imple
cjgrant 2017/05/08 19:17:22 We basically have 3 components - UI, Shell and GL.
amp 2017/05/08 20:30:06 I suppose we don't need to pull anything out, but
205 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't 206 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't
206 // finished starting? 207 // finished starting?
207 gl_thread_->WaitUntilThreadStarted(); 208 gl_thread_->WaitUntilThreadStarted();
208 gl_thread_->task_runner()->PostTask(FROM_HERE, task); 209 gl_thread_->task_runner()->PostTask(FROM_HERE, task);
209 } 210 }
210 211
211 void VrShell::OnContentPaused(bool paused) { 212 void VrShell::OnContentPaused(bool paused) {
212 if (!vr_shell_enabled_) 213 if (!vr_shell_enabled_)
213 return; 214 return;
214 215
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 } 261 }
261 262
262 void VrShell::SetWebVrMode(JNIEnv* env, 263 void VrShell::SetWebVrMode(JNIEnv* env,
263 const JavaParamRef<jobject>& obj, 264 const JavaParamRef<jobject>& obj,
264 bool enabled) { 265 bool enabled) {
265 webvr_mode_ = enabled; 266 webvr_mode_ = enabled;
266 if (metrics_helper_) 267 if (metrics_helper_)
267 metrics_helper_->SetWebVREnabled(enabled); 268 metrics_helper_->SetWebVREnabled(enabled);
268 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetWebVrMode, 269 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetWebVrMode,
269 gl_thread_->GetVrShellGl(), enabled)); 270 gl_thread_->GetVrShellGl(), enabled));
270 271 ui_->SetWebVr(enabled);
271 ui_->SetMode(enabled ? UiInterface::Mode::WEB_VR
272 : UiInterface::Mode::STANDARD);
273 PostToGlThreadWhenReady(base::Bind(&UiSceneManager::SetWebVRMode,
274 gl_thread_->GetSceneManager(), enabled));
275 } 272 }
276 273
277 bool VrShell::GetWebVrMode(JNIEnv* env, const JavaParamRef<jobject>& obj) { 274 bool VrShell::GetWebVrMode(JNIEnv* env, const JavaParamRef<jobject>& obj) {
278 return webvr_mode_; 275 return webvr_mode_;
279 } 276 }
280 277
281 void VrShell::OnLoadProgressChanged(JNIEnv* env, 278 void VrShell::OnLoadProgressChanged(JNIEnv* env,
282 const JavaParamRef<jobject>& obj, 279 const JavaParamRef<jobject>& obj,
283 double progress) { 280 double progress) {
284 ui_->SetLoadProgress(progress); 281 ui_->SetLoadProgress(progress);
285 } 282 }
286 283
287 void VrShell::OnTabListCreated(JNIEnv* env, 284 void VrShell::OnTabListCreated(JNIEnv* env,
288 const JavaParamRef<jobject>& obj, 285 const JavaParamRef<jobject>& obj,
289 jobjectArray tabs, 286 jobjectArray tabs,
290 jobjectArray incognito_tabs) { 287 jobjectArray incognito_tabs) {
291 ui_->InitTabList();
292 ProcessTabArray(env, tabs, false); 288 ProcessTabArray(env, tabs, false);
293 ProcessTabArray(env, incognito_tabs, true); 289 ProcessTabArray(env, incognito_tabs, true);
294 ui_->FlushTabList(); 290 ui_->FlushTabList();
295 } 291 }
296 292
297 void VrShell::ProcessTabArray(JNIEnv* env, jobjectArray tabs, bool incognito) { 293 void VrShell::ProcessTabArray(JNIEnv* env, jobjectArray tabs, bool incognito) {
298 size_t len = env->GetArrayLength(tabs); 294 size_t len = env->GetArrayLength(tabs);
299 for (size_t i = 0; i < len; ++i) { 295 for (size_t i = 0; i < len; ++i) {
300 jobject jtab = env->GetObjectArrayElement(tabs, i); 296 jobject jtab = env->GetObjectArrayElement(tabs, i);
301 TabAndroid* tab = 297 TabAndroid* tab =
(...skipping 13 matching lines...) Expand all
315 } 311 }
316 312
317 void VrShell::OnTabRemoved(JNIEnv* env, 313 void VrShell::OnTabRemoved(JNIEnv* env,
318 const JavaParamRef<jobject>& obj, 314 const JavaParamRef<jobject>& obj,
319 jboolean incognito, 315 jboolean incognito,
320 jint id) { 316 jint id) {
321 ui_->RemoveTab(incognito, id); 317 ui_->RemoveTab(incognito, id);
322 } 318 }
323 319
324 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { 320 void VrShell::SetWebVRSecureOrigin(bool secure_origin) {
325 PostToGlThreadWhenReady(base::Bind(&UiSceneManager::SetWebVRSecureOrigin, 321 ui_->SetWebVRSecureOrigin(secure_origin);
326 gl_thread_->GetSceneManager(),
327 secure_origin));
328 } 322 }
329 323
330 void VrShell::SubmitWebVRFrame(int16_t frame_index, 324 void VrShell::SubmitWebVRFrame(int16_t frame_index,
331 const gpu::MailboxHolder& mailbox) { 325 const gpu::MailboxHolder& mailbox) {
332 TRACE_EVENT1("gpu", "SubmitWebVRFrame", "frame", frame_index); 326 TRACE_EVENT1("gpu", "SubmitWebVRFrame", "frame", frame_index);
333 327
334 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SubmitWebVRFrame, 328 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SubmitWebVRFrame,
335 gl_thread_->GetVrShellGl(), frame_index, 329 gl_thread_->GetVrShellGl(), frame_index,
336 mailbox)); 330 mailbox));
337 } 331 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 content_surface_ = surface; 386 content_surface_ = surface;
393 compositor_->SurfaceChanged(surface); 387 compositor_->SurfaceChanged(surface);
394 JNIEnv* env = base::android::AttachCurrentThread(); 388 JNIEnv* env = base::android::AttachCurrentThread();
395 Java_VrShellImpl_contentSurfaceChanged(env, j_vr_shell_.obj()); 389 Java_VrShellImpl_contentSurfaceChanged(env, j_vr_shell_.obj());
396 } 390 }
397 391
398 void VrShell::GvrDelegateReady() { 392 void VrShell::GvrDelegateReady() {
399 delegate_provider_->SetPresentingDelegate(this, gvr_api_); 393 delegate_provider_->SetPresentingDelegate(this, gvr_api_);
400 } 394 }
401 395
402 void VrShell::AppButtonGesturePerformed(UiInterface::Direction direction) {
403 if (vr_shell_enabled_)
404 ui_->HandleAppButtonGesturePerformed(direction);
405 }
406
407 void VrShell::ContentPhysicalBoundsChanged(JNIEnv* env, 396 void VrShell::ContentPhysicalBoundsChanged(JNIEnv* env,
408 const JavaParamRef<jobject>& object, 397 const JavaParamRef<jobject>& object,
409 jint width, 398 jint width,
410 jint height, 399 jint height,
411 jfloat dpr) { 400 jfloat dpr) {
412 TRACE_EVENT0("gpu", "VrShell::ContentPhysicalBoundsChanged"); 401 TRACE_EVENT0("gpu", "VrShell::ContentPhysicalBoundsChanged");
413 // TODO(acondor): Set the device scale factor for font rendering on the 402 // TODO(acondor): Set the device scale factor for font rendering on the
414 // VR Shell textures. 403 // VR Shell textures.
415 PostToGlThreadWhenReady(base::Bind(&VrShellGl::ContentPhysicalBoundsChanged, 404 PostToGlThreadWhenReady(base::Bind(&VrShellGl::ContentPhysicalBoundsChanged,
416 gl_thread_->GetVrShellGl(), width, 405 gl_thread_->GetVrShellGl(), width,
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 jboolean for_web_vr, 547 jboolean for_web_vr,
559 jlong gvr_api, 548 jlong gvr_api,
560 jboolean reprojected_rendering) { 549 jboolean reprojected_rendering) {
561 return reinterpret_cast<intptr_t>(new VrShell( 550 return reinterpret_cast<intptr_t>(new VrShell(
562 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), 551 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android),
563 for_web_vr, VrShellDelegate::GetNativeVrShellDelegate(env, delegate), 552 for_web_vr, VrShellDelegate::GetNativeVrShellDelegate(env, delegate),
564 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); 553 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering));
565 } 554 }
566 555
567 } // namespace vr_shell 556 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698