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

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

Powered by Google App Engine
This is Rietveld 408576698