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

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: 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_shell_renderer.h" 9 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h"
10 #include "chrome/browser/android/vr_shell/vr_util.h" 10 #include "chrome/browser/android/vr_shell/vr_util.h"
11 #include "content/public/browser/android/content_view_core.h"
12 #include "content/public/browser/render_widget_host.h"
13 #include "content/public/browser/render_widget_host_view.h"
14 #include "content/public/browser/web_contents.h"
11 #include "jni/VrShell_jni.h" 15 #include "jni/VrShell_jni.h"
16 #include "ui/android/view_android.h"
17 #include "ui/android/window_android.h"
12 #include "ui/gl/gl_bindings.h" 18 #include "ui/gl/gl_bindings.h"
13 #include "ui/gl/init/gl_factory.h" 19 #include "ui/gl/init/gl_factory.h"
14 20
15 using base::android::JavaParamRef; 21 using base::android::JavaParamRef;
16 22
17 namespace { 23 namespace {
18 // Constant taken from treasure_hunt demo. 24 // Constant taken from treasure_hunt demo.
19 static constexpr long kPredictionTimeWithoutVsyncNanos = 50000000; 25 static constexpr long kPredictionTimeWithoutVsyncNanos = 50000000;
20 26
21 static constexpr float kZNear = 0.1f; 27 static constexpr float kZNear = 0.1f;
22 static constexpr float kZFar = 1000.0f; 28 static constexpr float kZFar = 1000.0f;
23 29
24 static constexpr gvr::Vec3f kDesktopPositionDefault = {0.0f, 0.0f, -2.0f}; 30 static constexpr gvr::Vec3f kDesktopPositionDefault = {0.0f, 0.0f, -2.0f};
25 static constexpr float kDesktopHeightDefault = 1.6f; 31 static constexpr float kDesktopHeightDefault = 1.6f;
26 32
27 // Screen angle in degrees. 0 = vertical, positive = top closer. 33 // Screen angle in degrees. 0 = vertical, positive = top closer.
28 static constexpr float kDesktopScreenTiltDefault = 0; 34 static constexpr float kDesktopScreenTiltDefault = 0;
29 35
30 static constexpr float kScreenHeightMeters = 2.0f; 36 static constexpr float kScreenHeightMeters = 1.0f;
31 static constexpr float kScreenWidthMeters = 2.0f; 37 static constexpr float kScreenWidthMeters = 16.0f / 9.0f;
cjgrant 2016/09/09 13:56:33 This constant looks misnamed (it appears to be a r
mthiesse 2016/09/09 14:45:25 Done.
32 } 38 }
33 39
34 namespace vr_shell { 40 namespace vr_shell {
35 41
36 VrShell::VrShell(JNIEnv* env, jobject obj) 42 VrShell::VrShell(JNIEnv* env, jobject obj,
43 content::ContentViewCore* content_core,
44 ui::WindowAndroid* content_window)
37 : desktop_screen_tilt_(kDesktopScreenTiltDefault), 45 : desktop_screen_tilt_(kDesktopScreenTiltDefault),
38 desktop_height_(kDesktopHeightDefault), 46 desktop_height_(kDesktopHeightDefault),
39 desktop_position_(kDesktopPositionDefault) { 47 desktop_position_(kDesktopPositionDefault),
48 content_core_(content_core) {
40 j_vr_shell_.Reset(env, obj); 49 j_vr_shell_.Reset(env, obj);
50 content_compositor_view_.reset(new SimpleCompositorView(content_window));
41 ui_rects_.emplace_back(new ContentRectangle()); 51 ui_rects_.emplace_back(new ContentRectangle());
42 desktop_plane_ = ui_rects_.back().get(); 52 desktop_plane_ = ui_rects_.back().get();
43 desktop_plane_->id = 0; 53 desktop_plane_->id = 0;
44 desktop_plane_->copy_rect = {0.0f, 0.0f, 1.0f, 1.0f}; 54 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. 55 // TODO(cjgrant): If we use the native path for content clicks, fix this.
46 desktop_plane_->window_rect = {0, 0, 0, 0}; 56 desktop_plane_->window_rect = {0, 0, 0, 0};
47 desktop_plane_->translation = {0.0f, 0.0f, 0.0f}; 57 desktop_plane_->translation = {0.0f, 0.0f, 0.0f};
48 desktop_plane_->x_anchoring = XNONE; 58 desktop_plane_->x_anchoring = XNONE;
49 desktop_plane_->y_anchoring = YNONE; 59 desktop_plane_->y_anchoring = YNONE;
50 desktop_plane_->anchor_z = false; 60 desktop_plane_->anchor_z = false;
51 desktop_plane_->orientation_axis_angle = {{1.0f, 0.0f, 0.0f, 0.0f}}; 61 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}}; 62 desktop_plane_->rotation_axis_angle = {{0.0f, 0.0f, 0.0f, 0.0f}};
63 content_core_->GetWebContents()
cjgrant 2016/09/09 13:56:32 Shouldn't this wrap on two lines rather than four?
mthiesse 2016/09/09 14:45:25 This is just what auto-format does. I'll make it t
64 ->GetRenderWidgetHostView()
65 ->GetRenderWidgetHost()
66 ->WasResized();
67 }
68
69 void VrShell::UpdateCompositorLayers(JNIEnv* env,
70 const JavaParamRef<jobject>& obj) {
71 content_compositor_view_->SetLayer(content_core_);
53 } 72 }
54 73
55 void VrShell::Destroy(JNIEnv* env, 74 void VrShell::Destroy(JNIEnv* env,
56 const base::android::JavaParamRef<jobject>& obj) { 75 const base::android::JavaParamRef<jobject>& obj) {
57 delete this; 76 delete this;
58 gl::init::ClearGLBindings(); 77 gl::init::ClearGLBindings();
59 } 78 }
60 79
61 bool RegisterVrShell(JNIEnv* env) { 80 bool RegisterVrShell(JNIEnv* env) {
62 return RegisterNativesImpl(env); 81 return RegisterNativesImpl(env);
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 236 }
218 237
219 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { 238 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) {
220 if (gvr_api_ == nullptr) 239 if (gvr_api_ == nullptr)
221 return; 240 return;
222 241
223 gvr_api_->RefreshViewerProfile(); 242 gvr_api_->RefreshViewerProfile();
224 gvr_api_->ResumeTracking(); 243 gvr_api_->ResumeTracking();
225 } 244 }
226 245
246 void VrShell::ContentSurfaceCreated(JNIEnv* env,
247 const JavaParamRef<jobject>& object) {
248 content_compositor_view_->SurfaceCreated();
249 }
250
251 void VrShell::ContentSurfaceDestroyed(JNIEnv* env,
252 const JavaParamRef<jobject>& object) {
253 content_compositor_view_->SurfaceDestroyed();
254 }
255
256 void VrShell::ContentSurfaceChanged(JNIEnv* env,
257 const JavaParamRef<jobject>& object,
258 jint format,
259 jint width,
260 jint height,
261 const JavaParamRef<jobject>& surface) {
262 content_compositor_view_->SurfaceChanged((int)format, (int)width, (int)height,
263 surface);
264 }
265
227 void VrShell::UpdateTransforms(float screen_width_meters, 266 void VrShell::UpdateTransforms(float screen_width_meters,
228 float screen_height_meters, 267 float screen_height_meters,
229 float screen_tilt) { 268 float screen_tilt) {
230 for (std::unique_ptr<ContentRectangle>& rect : ui_rects_) { 269 for (std::unique_ptr<ContentRectangle>& rect : ui_rects_) {
231 rect->transform_.MakeIdentity(); 270 rect->transform_.MakeIdentity();
232 rect->transform_.Scale(rect->size.x, rect->size.y, rect->size.z); 271 rect->transform_.Scale(rect->size.x, rect->size.y, rect->size.z);
233 float x_anchor_translate; 272 float x_anchor_translate;
234 switch (rect->x_anchoring) { 273 switch (rect->x_anchoring) {
235 case XLEFT: 274 case XLEFT:
236 x_anchor_translate = desktop_position_.x - screen_width_meters * 0.5; 275 x_anchor_translate = desktop_position_.x - screen_width_meters * 0.5;
(...skipping 30 matching lines...) Expand all
267 // TODO(cjgrant): Establish which exact rotations we'll provide. 306 // TODO(cjgrant): Establish which exact rotations we'll provide.
268 // Adjust for screen tilt. 307 // Adjust for screen tilt.
269 rect->transform_.Rotate(1.0f, 0.0f, 0.0f, screen_tilt); 308 rect->transform_.Rotate(1.0f, 0.0f, 0.0f, screen_tilt);
270 } 309 }
271 } 310 }
272 311
273 // ---------------------------------------------------------------------------- 312 // ----------------------------------------------------------------------------
274 // Native JNI methods 313 // Native JNI methods
275 // ---------------------------------------------------------------------------- 314 // ----------------------------------------------------------------------------
276 315
277 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 316 jlong Init(JNIEnv* env,
278 return reinterpret_cast<intptr_t>(new VrShell(env, obj)); 317 const JavaParamRef<jobject>& obj,
318 const JavaParamRef<jobject>& content_web_contents,
319 jlong content_window_android) {
320 content::ContentViewCore* c_core = content::ContentViewCore::FromWebContents(
321 content::WebContents::FromJavaWebContents(content_web_contents));
322 return reinterpret_cast<intptr_t>(new VrShell(
323 env, obj, c_core,
324 reinterpret_cast<ui::WindowAndroid*>(content_window_android)));
279 } 325 }
280 326
281 } // namespace vr_shell 327 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698