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

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, 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_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;
23 static constexpr float kZFar = 1000.0f; 30 static constexpr float kZFar = 1000.0f;
24 31
25 static constexpr gvr::Vec3f kDesktopPositionDefault = {0.0f, 0.0f, -2.0f}; 32 static constexpr gvr::Vec3f kDesktopPositionDefault = {0.0f, 0.0f, -2.0f};
26 static constexpr float kDesktopHeightDefault = 1.6f; 33 static constexpr float kDesktopHeightDefault = 1.6f;
27 34
28 // Screen angle in degrees. 0 = vertical, positive = top closer. 35 // Screen angle in degrees. 0 = vertical, positive = top closer.
29 static constexpr float kDesktopScreenTiltDefault = 0; 36 static constexpr float kDesktopScreenTiltDefault = 0;
30 37
31 static constexpr float kScreenHeightMeters = 2.0f; 38 static constexpr float kScreenHeightRatio = 1.0f;
32 static constexpr float kScreenWidthMeters = 2.0f; 39 static constexpr float kScreenWidthRatio = 16.0f / 9.0f;
33 } // namespace 40 } // namespace
34 41
35 namespace vr_shell { 42 namespace vr_shell {
36 43
37 VrShell::VrShell(JNIEnv* env, jobject obj) 44 VrShell::VrShell(JNIEnv* env, jobject obj,
45 content::ContentViewCore* content_core,
46 ui::WindowAndroid* content_window)
38 : desktop_screen_tilt_(kDesktopScreenTiltDefault), 47 : desktop_screen_tilt_(kDesktopScreenTiltDefault),
39 desktop_height_(kDesktopHeightDefault), 48 desktop_height_(kDesktopHeightDefault),
40 desktop_position_(kDesktopPositionDefault) { 49 desktop_position_(kDesktopPositionDefault),
50 content_cvc_(content_core) {
41 j_vr_shell_.Reset(env, obj); 51 j_vr_shell_.Reset(env, obj);
52 content_compositor_view_.reset(new VrCompositor(content_window));
42 ui_rects_.emplace_back(new ContentRectangle()); 53 ui_rects_.emplace_back(new ContentRectangle());
43 desktop_plane_ = ui_rects_.back().get(); 54 desktop_plane_ = ui_rects_.back().get();
44 desktop_plane_->id = 0; 55 desktop_plane_->id = 0;
45 desktop_plane_->copy_rect = {0.0f, 0.0f, 1.0f, 1.0f}; 56 desktop_plane_->copy_rect = {0.0f, 0.0f, 1.0f, 1.0f};
46 // TODO(cjgrant): If we use the native path for content clicks, fix this. 57 // TODO(cjgrant): If we use the native path for content clicks, fix this.
47 desktop_plane_->window_rect = {0, 0, 0, 0}; 58 desktop_plane_->window_rect = {0, 0, 0, 0};
48 desktop_plane_->translation = {0.0f, 0.0f, 0.0f}; 59 desktop_plane_->translation = {0.0f, 0.0f, 0.0f};
49 desktop_plane_->x_anchoring = XNONE; 60 desktop_plane_->x_anchoring = XNONE;
50 desktop_plane_->y_anchoring = YNONE; 61 desktop_plane_->y_anchoring = YNONE;
51 desktop_plane_->anchor_z = false; 62 desktop_plane_->anchor_z = false;
52 desktop_plane_->orientation_axis_angle = {{1.0f, 0.0f, 0.0f, 0.0f}}; 63 desktop_plane_->orientation_axis_angle = {{1.0f, 0.0f, 0.0f, 0.0f}};
53 desktop_plane_->rotation_axis_angle = {{0.0f, 0.0f, 0.0f, 0.0f}}; 64 desktop_plane_->rotation_axis_angle = {{0.0f, 0.0f, 0.0f, 0.0f}};
65 content_cvc_->GetWebContents()->GetRenderWidgetHostView()
66 ->GetRenderWidgetHost()->WasResized();
67 }
68
69 void VrShell::UpdateCompositorLayers(JNIEnv* env,
70 const JavaParamRef<jobject>& obj) {
71 content_compositor_view_->SetLayer(content_cvc_);
54 } 72 }
55 73
56 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { 74 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
57 delete this; 75 delete this;
58 gl::init::ClearGLBindings(); 76 gl::init::ClearGLBindings();
59 } 77 }
60 78
61 bool RegisterVrShell(JNIEnv* env) { 79 bool RegisterVrShell(JNIEnv* env) {
62 return RegisterNativesImpl(env); 80 return RegisterNativesImpl(env);
63 } 81 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 DrawWebVr(); 155 DrawWebVr();
138 } else { 156 } else {
139 DrawVrShell(); 157 DrawVrShell();
140 } 158 }
141 159
142 frame.Unbind(); 160 frame.Unbind();
143 frame.Submit(*buffer_viewport_list_, head_pose_); 161 frame.Submit(*buffer_viewport_list_, head_pose_);
144 } 162 }
145 163
146 void VrShell::DrawVrShell() { 164 void VrShell::DrawVrShell() {
147 float screen_width = kScreenWidthMeters * desktop_height_; 165 float screen_width = kScreenWidthRatio * desktop_height_;
148 float screen_height = kScreenHeightMeters * desktop_height_; 166 float screen_height = kScreenHeightRatio * desktop_height_;
149 167
150 float screen_tilt = desktop_screen_tilt_ * M_PI / 180.0f; 168 float screen_tilt = desktop_screen_tilt_ * M_PI / 180.0f;
151 169
152 gvr::Vec3f headPos = getTranslation(head_pose_); 170 gvr::Vec3f headPos = getTranslation(head_pose_);
153 if (headPos.x == 0.0f && headPos.y == 0.0f && headPos.z == 0.0f) { 171 if (headPos.x == 0.0f && headPos.y == 0.0f && headPos.z == 0.0f) {
154 // This appears to be a 3DOF pose without a neck model. Add one. 172 // This appears to be a 3DOF pose without a neck model. Add one.
155 // The head pose has redundant data. Assume we're only using the 173 // The head pose has redundant data. Assume we're only using the
156 // object_from_reference_matrix, we're not updating position_external. 174 // object_from_reference_matrix, we're not updating position_external.
157 // TODO: Not sure what object_from_reference_matrix is. The new api removed 175 // TODO: Not sure what object_from_reference_matrix is. The new api removed
158 // it. For now, removing it seems working fine. 176 // it. For now, removing it seems working fine.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 void VrShell::UpdateWebVRTextureBounds( 283 void VrShell::UpdateWebVRTextureBounds(
266 int eye, float left, float top, float width, float height) { 284 int eye, float left, float top, float width, float height) {
267 gvr::Rectf bounds = { left, top, width, height }; 285 gvr::Rectf bounds = { left, top, width, height };
268 vr_shell_renderer_->GetWebVrRenderer()->UpdateTextureBounds(eye, bounds); 286 vr_shell_renderer_->GetWebVrRenderer()->UpdateTextureBounds(eye, bounds);
269 } 287 }
270 288
271 gvr::GvrApi* VrShell::gvr_api() { 289 gvr::GvrApi* VrShell::gvr_api() {
272 return gvr_api_.get(); 290 return gvr_api_.get();
273 } 291 }
274 292
293 void VrShell::ContentSurfaceDestroyed(JNIEnv* env,
294 const JavaParamRef<jobject>& object) {
295 content_compositor_view_->SurfaceDestroyed();
296 }
297
298 void VrShell::ContentSurfaceChanged(JNIEnv* env,
299 const JavaParamRef<jobject>& object,
300 jint width,
301 jint height,
302 const JavaParamRef<jobject>& surface) {
303 content_compositor_view_->SurfaceChanged((int)width, (int)height, surface);
304 }
305
275 void VrShell::UpdateTransforms(float screen_width_meters, 306 void VrShell::UpdateTransforms(float screen_width_meters,
276 float screen_height_meters, 307 float screen_height_meters,
277 float screen_tilt) { 308 float screen_tilt) {
278 for (std::unique_ptr<ContentRectangle>& rect : ui_rects_) { 309 for (std::unique_ptr<ContentRectangle>& rect : ui_rects_) {
279 rect->transform.MakeIdentity(); 310 rect->transform.MakeIdentity();
280 rect->transform.Scale(rect->size.x, rect->size.y, rect->size.z); 311 rect->transform.Scale(rect->size.x, rect->size.y, rect->size.z);
281 float x_anchor_translate; 312 float x_anchor_translate;
282 switch (rect->x_anchoring) { 313 switch (rect->x_anchoring) {
283 case XLEFT: 314 case XLEFT:
284 x_anchor_translate = desktop_position_.x - screen_width_meters * 0.5; 315 x_anchor_translate = desktop_position_.x - screen_width_meters * 0.5;
(...skipping 30 matching lines...) Expand all
315 // TODO(cjgrant): Establish which exact rotations we'll provide. 346 // TODO(cjgrant): Establish which exact rotations we'll provide.
316 // Adjust for screen tilt. 347 // Adjust for screen tilt.
317 rect->transform.Rotate(1.0f, 0.0f, 0.0f, screen_tilt); 348 rect->transform.Rotate(1.0f, 0.0f, 0.0f, screen_tilt);
318 } 349 }
319 } 350 }
320 351
321 // ---------------------------------------------------------------------------- 352 // ----------------------------------------------------------------------------
322 // Native JNI methods 353 // Native JNI methods
323 // ---------------------------------------------------------------------------- 354 // ----------------------------------------------------------------------------
324 355
325 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 356 jlong Init(JNIEnv* env,
326 return reinterpret_cast<intptr_t>(new VrShell(env, obj)); 357 const JavaParamRef<jobject>& obj,
358 const JavaParamRef<jobject>& content_web_contents,
359 jlong content_window_android) {
360 content::ContentViewCore* c_core = content::ContentViewCore::FromWebContents(
361 content::WebContents::FromJavaWebContents(content_web_contents));
362 return reinterpret_cast<intptr_t>(new VrShell(
363 env, obj, c_core,
364 reinterpret_cast<ui::WindowAndroid*>(content_window_android)));
327 } 365 }
328 366
329 } // namespace vr_shell 367 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698