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

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

Issue 2319863005: Implement new compositor and ContentViewCore reparenting for VR Shell. (Closed)
Patch Set: Rebase onto ToT 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
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_gl_util.h" 10 #include "chrome/browser/android/vr_shell/vr_gl_util.h"
10 #include "chrome/browser/android/vr_shell/vr_math.h" 11 #include "chrome/browser/android/vr_shell/vr_math.h"
11 #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"
14 #include "content/public/browser/render_widget_host.h"
15 #include "content/public/browser/render_widget_host_view.h"
16 #include "content/public/browser/web_contents.h"
12 #include "jni/VrShell_jni.h" 17 #include "jni/VrShell_jni.h"
18 #include "ui/android/view_android.h"
19 #include "ui/android/window_android.h"
13 #include "ui/gl/gl_bindings.h" 20 #include "ui/gl/gl_bindings.h"
14 #include "ui/gl/init/gl_factory.h" 21 #include "ui/gl/init/gl_factory.h"
15 22
16 using base::android::JavaParamRef; 23 using base::android::JavaParamRef;
17 24
18 namespace { 25 namespace {
19 // Constant taken from treasure_hunt demo. 26 // Constant taken from treasure_hunt demo.
20 static constexpr long kPredictionTimeWithoutVsyncNanos = 50000000; 27 static constexpr long kPredictionTimeWithoutVsyncNanos = 50000000;
21 28
22 static constexpr float kZNear = 0.1f; 29 static constexpr float kZNear = 0.1f;
(...skipping 22 matching lines...) Expand all
45 // In lieu of an elbow model, we assume a position for the user's hand. 52 // In lieu of an elbow model, we assume a position for the user's hand.
46 // TODO(mthiesse): Handedness options. 53 // TODO(mthiesse): Handedness options.
47 static constexpr gvr::Vec3f kHandPosition = {0.2f, -0.5f, -0.2f}; 54 static constexpr gvr::Vec3f kHandPosition = {0.2f, -0.5f, -0.2f};
48 55
49 static constexpr float kReticleZOffset = 0.01f; 56 static constexpr float kReticleZOffset = 0.01f;
50 57
51 } // namespace 58 } // namespace
52 59
53 namespace vr_shell { 60 namespace vr_shell {
54 61
55 VrShell::VrShell(JNIEnv* env, jobject obj) 62 VrShell::VrShell(JNIEnv* env, jobject obj,
63 content::ContentViewCore* content_core,
64 ui::WindowAndroid* content_window)
56 : desktop_screen_tilt_(kDesktopScreenTiltDefault), 65 : desktop_screen_tilt_(kDesktopScreenTiltDefault),
57 desktop_height_(kDesktopHeightDefault), 66 desktop_height_(kDesktopHeightDefault),
58 desktop_position_(kDesktopPositionDefault) { 67 desktop_position_(kDesktopPositionDefault),
68 content_cvc_(content_core) {
59 j_vr_shell_.Reset(env, obj); 69 j_vr_shell_.Reset(env, obj);
70 content_compositor_view_.reset(new VrCompositor(content_window));
60 ui_rects_.emplace_back(new ContentRectangle()); 71 ui_rects_.emplace_back(new ContentRectangle());
61 desktop_plane_ = ui_rects_.back().get(); 72 desktop_plane_ = ui_rects_.back().get();
62 desktop_plane_->id = 0; 73 desktop_plane_->id = 0;
63 desktop_plane_->copy_rect = {0.0f, 0.0f, 1.0f, 1.0f}; 74 desktop_plane_->copy_rect = {0.0f, 0.0f, 1.0f, 1.0f};
64 // TODO(cjgrant): If we use the native path for content clicks, fix this. 75 // TODO(cjgrant): If we use the native path for content clicks, fix this.
65 desktop_plane_->window_rect = {0, 0, 0, 0}; 76 desktop_plane_->window_rect = {0, 0, 0, 0};
66 desktop_plane_->translation = {0.0f, 0.0f, 0.0f}; 77 desktop_plane_->translation = {0.0f, 0.0f, 0.0f};
67 desktop_plane_->x_anchoring = XNONE; 78 desktop_plane_->x_anchoring = XNONE;
68 desktop_plane_->y_anchoring = YNONE; 79 desktop_plane_->y_anchoring = YNONE;
69 desktop_plane_->anchor_z = false; 80 desktop_plane_->anchor_z = false;
70 desktop_plane_->orientation_axis_angle = {{1.0f, 0.0f, 0.0f, 0.0f}}; 81 desktop_plane_->orientation_axis_angle = {{1.0f, 0.0f, 0.0f, 0.0f}};
71 desktop_plane_->rotation_axis_angle = {{0.0f, 0.0f, 0.0f, 0.0f}}; 82 desktop_plane_->rotation_axis_angle = {{0.0f, 0.0f, 0.0f, 0.0f}};
83 content_cvc_->GetWebContents()->GetRenderWidgetHostView()
84 ->GetRenderWidgetHost()->WasResized();
85 }
86
87 void VrShell::UpdateCompositorLayers(JNIEnv* env,
88 const JavaParamRef<jobject>& obj) {
89 content_compositor_view_->SetLayer(content_cvc_);
72 } 90 }
73 91
74 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { 92 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
75 delete this; 93 delete this;
76 gl::init::ClearGLBindings(); 94 gl::init::ClearGLBindings();
77 } 95 }
78 96
79 bool RegisterVrShell(JNIEnv* env) { 97 bool RegisterVrShell(JNIEnv* env) {
80 return RegisterNativesImpl(env); 98 return RegisterNativesImpl(env);
81 } 99 }
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 void VrShell::UpdateWebVRTextureBounds( 396 void VrShell::UpdateWebVRTextureBounds(
379 int eye, float left, float top, float width, float height) { 397 int eye, float left, float top, float width, float height) {
380 gvr::Rectf bounds = { left, top, width, height }; 398 gvr::Rectf bounds = { left, top, width, height };
381 vr_shell_renderer_->GetWebVrRenderer()->UpdateTextureBounds(eye, bounds); 399 vr_shell_renderer_->GetWebVrRenderer()->UpdateTextureBounds(eye, bounds);
382 } 400 }
383 401
384 gvr::GvrApi* VrShell::gvr_api() { 402 gvr::GvrApi* VrShell::gvr_api() {
385 return gvr_api_.get(); 403 return gvr_api_.get();
386 } 404 }
387 405
406 void VrShell::ContentSurfaceDestroyed(JNIEnv* env,
407 const JavaParamRef<jobject>& object) {
408 content_compositor_view_->SurfaceDestroyed();
409 }
410
411 void VrShell::ContentSurfaceChanged(JNIEnv* env,
412 const JavaParamRef<jobject>& object,
413 jint width,
414 jint height,
415 const JavaParamRef<jobject>& surface) {
416 content_compositor_view_->SurfaceChanged((int)width, (int)height, surface);
417 }
418
388 void VrShell::UpdateTransforms(float screen_width_meters, 419 void VrShell::UpdateTransforms(float screen_width_meters,
389 float screen_height_meters, 420 float screen_height_meters,
390 float screen_tilt) { 421 float screen_tilt) {
391 for (std::unique_ptr<ContentRectangle>& rect : ui_rects_) { 422 for (std::unique_ptr<ContentRectangle>& rect : ui_rects_) {
392 rect->transform.MakeIdentity(); 423 rect->transform.MakeIdentity();
393 rect->transform.Scale(rect->size.x, rect->size.y, rect->size.z); 424 rect->transform.Scale(rect->size.x, rect->size.y, rect->size.z);
394 float x_anchor_translate; 425 float x_anchor_translate;
395 switch (rect->x_anchoring) { 426 switch (rect->x_anchoring) {
396 case XLEFT: 427 case XLEFT:
397 x_anchor_translate = desktop_position_.x - screen_width_meters * 0.5; 428 x_anchor_translate = desktop_position_.x - screen_width_meters * 0.5;
(...skipping 30 matching lines...) Expand all
428 // TODO(cjgrant): Establish which exact rotations we'll provide. 459 // TODO(cjgrant): Establish which exact rotations we'll provide.
429 // Adjust for screen tilt. 460 // Adjust for screen tilt.
430 rect->transform.Rotate(1.0f, 0.0f, 0.0f, screen_tilt); 461 rect->transform.Rotate(1.0f, 0.0f, 0.0f, screen_tilt);
431 } 462 }
432 } 463 }
433 464
434 // ---------------------------------------------------------------------------- 465 // ----------------------------------------------------------------------------
435 // Native JNI methods 466 // Native JNI methods
436 // ---------------------------------------------------------------------------- 467 // ----------------------------------------------------------------------------
437 468
438 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 469 jlong Init(JNIEnv* env,
439 return reinterpret_cast<intptr_t>(new VrShell(env, obj)); 470 const JavaParamRef<jobject>& obj,
471 const JavaParamRef<jobject>& content_web_contents,
472 jlong content_window_android) {
473 content::ContentViewCore* c_core = content::ContentViewCore::FromWebContents(
474 content::WebContents::FromJavaWebContents(content_web_contents));
475 return reinterpret_cast<intptr_t>(new VrShell(
476 env, obj, c_core,
477 reinterpret_cast<ui::WindowAndroid*>(content_window_android)));
440 } 478 }
441 479
442 } // namespace vr_shell 480 } // namespace vr_shell
OLDNEW
« no previous file with comments | « 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